2 * Copyright (c) 2019 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/public-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 #if 0 and defined DALI_ELDBUS_AVAILABLE
59 // Copied from x server
60 static uint32_t GetCurrentMilliSeconds(void)
65 static clockid_t clockid;
69 #ifdef CLOCK_MONOTONIC_COARSE
70 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
71 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
73 clockid = CLOCK_MONOTONIC_COARSE;
77 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
79 clockid = CLOCK_MONOTONIC;
86 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
88 return static_cast<uint32_t>( (tp.tv_sec * 1000 ) + (tp.tv_nsec / 1000000L) );
91 gettimeofday(&tv, NULL);
92 return static_cast<uint32_t>( (tv.tv_sec * 1000 ) + (tv.tv_usec / 1000) );
95 } // unnamed namespace
98 EventHandler::EventHandler( WindowRenderSurface* surface, DamageObserver& damageObserver )
99 : mStyleMonitor( StyleMonitor::Get() ),
100 mDamageObserver( damageObserver ),
101 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
102 mClipboard( Clipboard::Get() ),
107 WindowBase* windowBase = surface->GetWindowBase();
110 windowBase->WindowDamagedSignal().Connect( this, &EventHandler::OnWindowDamaged );
111 windowBase->FocusChangedSignal().Connect( this, &EventHandler::OnFocusChanged );
112 windowBase->RotationSignal().Connect( this, &EventHandler::OnRotation );
113 windowBase->TouchEventSignal().Connect( this, &EventHandler::OnTouchEvent );
114 windowBase->WheelEventSignal().Connect( this, &EventHandler::OnWheelEvent );
115 windowBase->KeyEventSignal().Connect( this, &EventHandler::OnKeyEvent );
116 windowBase->SelectionDataSendSignal().Connect( this, &EventHandler::OnSelectionDataSend );
117 windowBase->SelectionDataReceivedSignal().Connect( this, &EventHandler::OnSelectionDataReceived );
118 windowBase->StyleChangedSignal().Connect( this, &EventHandler::OnStyleChanged );
122 EventHandler::~EventHandler()
126 void EventHandler::SendEvent( StyleChange::Type styleChange )
128 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
129 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
132 void EventHandler::SendEvent( const DamageArea& area )
134 mDamageObserver.OnDamaged( area );
137 void EventHandler::Pause()
142 void EventHandler::Resume()
147 void EventHandler::OnTouchEvent( Integration::Point& point, uint32_t timeStamp )
149 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
151 (*iter)->OnTouchPoint( point, timeStamp );
155 void EventHandler::OnWheelEvent( WheelEvent& wheelEvent )
157 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
159 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
161 (*iter)->OnWheelEvent( event );
165 void EventHandler::OnKeyEvent( Integration::KeyEvent& keyEvent )
167 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
169 (*iter)->OnKeyEvent( keyEvent );
173 void EventHandler::OnFocusChanged( bool focusIn )
175 // If the window gains focus and we hid the keyboard then show it again.
178 Dali::Clipboard clipboard = Clipboard::Get();
181 clipboard.HideClipboard();
186 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
187 Dali::Clipboard clipboard = Clipboard::Get();
190 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
191 clipBoardImpl.HideClipboard(true);
196 void EventHandler::OnRotation( const RotationEvent& event )
198 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
200 (*iter)->OnRotation( event );
204 void EventHandler::OnWindowDamaged( const DamageArea& area )
209 void EventHandler::OnSelectionDataSend( void* event )
211 Dali::Clipboard clipboard = Clipboard::Get();
214 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
215 clipBoardImpl.ExcuteBuffered( true, event );
219 void EventHandler::OnSelectionDataReceived( void* event )
221 // We have got the selected content, inform the clipboard event listener (if we have one).
222 Dali::Clipboard clipboard = Clipboard::Get();
223 char* selectionData = NULL;
226 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
227 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
230 if( selectionData && mClipboardEventNotifier )
232 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( mClipboardEventNotifier ) );
233 std::string content( selectionData, strlen( selectionData ) );
235 clipboardEventNotifier.SetContent( content );
236 clipboardEventNotifier.EmitContentSelectedSignal();
238 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d): %s\n" , strlen(selectionData), selectionData );
242 void EventHandler::OnStyleChanged( StyleChange::Type styleChange )
244 SendEvent( styleChange );
247 void EventHandler::AddObserver( Observer& observer )
249 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
251 if ( match == mObservers.end() )
253 mObservers.push_back( &observer );
257 void EventHandler::RemoveObserver( Observer& observer )
259 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
261 if ( match != mObservers.end() )
263 mObservers.erase( match );
267 } // namespace Adaptor
269 } // namespace Internal