2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/event-handler.h>
25 #include <dali/devel-api/events/touch-point.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/public-api/events/wheel-event.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31 #include <dali/integration-api/events/hover-event-integ.h>
32 #include <dali/integration-api/events/wheel-event-integ.h>
35 #include <dali/internal/clipboard/common/clipboard-impl.h>
36 #include <dali/internal/styling/common/style-monitor-impl.h>
37 #include <dali/internal/window-system/common/window-render-surface.h>
48 #if defined(DEBUG_ENABLED)
51 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
52 } // unnamed namespace
55 EventHandler::EventHandler( WindowBase* windowBase, DamageObserver& damageObserver )
56 : mStyleMonitor( StyleMonitor::Get() ),
57 mDamageObserver( damageObserver ),
58 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
59 mClipboard( Clipboard::Get() ),
65 windowBase->WindowDamagedSignal().Connect( this, &EventHandler::OnWindowDamaged );
66 windowBase->FocusChangedSignal().Connect( this, &EventHandler::OnFocusChanged );
67 windowBase->RotationSignal().Connect( this, &EventHandler::OnRotation );
68 windowBase->TouchEventSignal().Connect( this, &EventHandler::OnTouchEvent );
69 windowBase->WheelEventSignal().Connect( this, &EventHandler::OnWheelEvent );
70 windowBase->KeyEventSignal().Connect( this, &EventHandler::OnKeyEvent );
71 windowBase->SelectionDataSendSignal().Connect( this, &EventHandler::OnSelectionDataSend );
72 windowBase->SelectionDataReceivedSignal().Connect( this, &EventHandler::OnSelectionDataReceived );
73 windowBase->StyleChangedSignal().Connect( this, &EventHandler::OnStyleChanged );
77 DALI_LOG_ERROR("WindowBase is invalid!!!\n");
81 EventHandler::~EventHandler()
85 void EventHandler::SendEvent( StyleChange::Type styleChange )
87 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
88 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
91 void EventHandler::SendEvent( const DamageArea& area )
93 mDamageObserver.OnDamaged( area );
96 void EventHandler::Pause()
101 void EventHandler::Resume()
106 void EventHandler::OnTouchEvent( Integration::Point& point, uint32_t timeStamp )
108 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
110 (*iter)->OnTouchPoint( point, timeStamp );
114 void EventHandler::OnWheelEvent( Integration::WheelEvent& wheelEvent )
116 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
118 (*iter)->OnWheelEvent( wheelEvent );
122 void EventHandler::OnKeyEvent( Integration::KeyEvent& keyEvent )
124 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
126 (*iter)->OnKeyEvent( keyEvent );
130 void EventHandler::OnFocusChanged( bool focusIn )
132 // If the window gains focus and we hid the keyboard then show it again.
135 Dali::Clipboard clipboard = Clipboard::Get();
138 clipboard.HideClipboard();
143 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
144 Dali::Clipboard clipboard = Clipboard::Get();
147 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
148 clipBoardImpl.HideClipboard(true);
153 void EventHandler::OnRotation( const RotationEvent& event )
155 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
157 (*iter)->OnRotation( event );
161 void EventHandler::OnWindowDamaged( const DamageArea& area )
166 void EventHandler::OnSelectionDataSend( void* event )
168 Dali::Clipboard clipboard = Clipboard::Get();
171 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
172 clipBoardImpl.ExcuteBuffered( true, event );
176 void EventHandler::OnSelectionDataReceived( void* event )
178 // We have got the selected content, inform the clipboard event listener (if we have one).
179 Dali::Clipboard clipboard = Clipboard::Get();
180 char* selectionData = NULL;
183 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
184 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
187 if( selectionData && mClipboardEventNotifier )
189 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( mClipboardEventNotifier ) );
190 std::string content( selectionData, strlen( selectionData ) );
192 clipboardEventNotifier.SetContent( content );
193 clipboardEventNotifier.EmitContentSelectedSignal();
195 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d): %s\n" , strlen(selectionData), selectionData );
199 void EventHandler::OnStyleChanged( StyleChange::Type styleChange )
201 SendEvent( styleChange );
204 void EventHandler::AddObserver( Observer& observer )
206 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
208 if ( match == mObservers.end() )
210 mObservers.push_back( &observer );
214 void EventHandler::RemoveObserver( Observer& observer )
216 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
218 if ( match != mObservers.end() )
220 mObservers.erase( match );
224 } // namespace Adaptor
226 } // namespace Internal