2 * Copyright (c) 2023 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/integration-api/debug.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
28 #include <dali/integration-api/events/key-event-integ.h>
29 #include <dali/integration-api/events/touch-event-integ.h>
30 #include <dali/integration-api/events/wheel-event-integ.h>
31 #include <dali/public-api/events/key-event.h>
32 #include <dali/public-api/events/wheel-event.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>
45 #if defined(DEBUG_ENABLED)
48 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
49 } // unnamed namespace
52 EventHandler::EventHandler(WindowBase* windowBase, DamageObserver& damageObserver)
53 : mStyleMonitor(StyleMonitor::Get()),
54 mDamageObserver(damageObserver),
55 mClipboardEventNotifier(),
61 windowBase->WindowDamagedSignal().Connect(this, &EventHandler::OnWindowDamaged);
62 windowBase->FocusChangedSignal().Connect(this, &EventHandler::OnFocusChanged);
63 windowBase->RotationSignal().Connect(this, &EventHandler::OnRotation);
64 windowBase->TouchEventSignal().Connect(this, &EventHandler::OnTouchEvent);
65 windowBase->WheelEventSignal().Connect(this, &EventHandler::OnWheelEvent);
66 windowBase->KeyEventSignal().Connect(this, &EventHandler::OnKeyEvent);
67 windowBase->SelectionDataSendSignal().Connect(this, &EventHandler::OnSelectionDataSend);
68 windowBase->SelectionDataReceivedSignal().Connect(this, &EventHandler::OnSelectionDataReceived);
69 windowBase->StyleChangedSignal().Connect(this, &EventHandler::OnStyleChanged);
73 DALI_LOG_ERROR("WindowBase is invalid!!!\n");
77 EventHandler::~EventHandler()
81 void EventHandler::SendEvent(StyleChange::Type styleChange)
83 DALI_ASSERT_DEBUG(mStyleMonitor && "StyleMonitor Not Available");
84 GetImplementation(mStyleMonitor).StyleChanged(styleChange);
87 void EventHandler::SendEvent(const DamageArea& area)
89 mDamageObserver.OnDamaged(area);
92 void EventHandler::Pause()
97 void EventHandler::Resume()
102 void EventHandler::OnTouchEvent(Integration::Point& point, uint32_t timeStamp)
104 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
106 (*iter)->OnTouchPoint(point, timeStamp);
110 void EventHandler::OnWheelEvent(Integration::WheelEvent& wheelEvent)
112 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
114 (*iter)->OnWheelEvent(wheelEvent);
118 void EventHandler::OnKeyEvent(Integration::KeyEvent& keyEvent)
120 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
122 (*iter)->OnKeyEvent(keyEvent);
126 void EventHandler::OnFocusChanged(bool focusIn)
128 // If the window gains focus and we hid the keyboard then show it again.
129 if(Clipboard::IsAvailable())
133 Dali::Clipboard clipboard = Clipboard::Get();
136 clipboard.HideClipboard();
141 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
142 Dali::Clipboard clipboard = Clipboard::Get();
145 Clipboard& clipBoardImpl(GetImplementation(clipboard));
146 clipBoardImpl.HideClipboard(true);
152 void EventHandler::OnRotation(const RotationEvent& event)
154 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
156 (*iter)->OnRotation(event);
160 void EventHandler::OnWindowDamaged(const DamageArea& area)
165 void EventHandler::OnSelectionDataSend(void* event)
167 Dali::Clipboard clipboard = Clipboard::Get();
170 Clipboard& clipBoardImpl(GetImplementation(clipboard));
171 clipBoardImpl.ExcuteSend(event);
175 void EventHandler::OnSelectionDataReceived(void* event)
177 // We have got the selected content, inform the clipboard event listener (if we have one).
178 Dali::Clipboard clipboard = Clipboard::Get();
179 char* selectionData = NULL;
180 int bufferLength = 0;
183 Clipboard& clipBoardImpl(GetImplementation(clipboard));
184 clipBoardImpl.ExcuteReceive(event, selectionData, bufferLength);
187 if(!mClipboardEventNotifier)
189 mClipboardEventNotifier = ClipboardEventNotifier::Get();
192 if(selectionData && mClipboardEventNotifier && bufferLength > 0)
194 ClipboardEventNotifier& clipboardEventNotifier(ClipboardEventNotifier::GetImplementation(mClipboardEventNotifier));
195 std::string content(selectionData, bufferLength - 1);
197 clipboardEventNotifier.SetContent(content);
198 clipboardEventNotifier.EmitContentSelectedSignal();
200 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%s) strlen(%d) buffer(%d)\n", selectionData, strlen(selectionData), bufferLength);
204 void EventHandler::OnStyleChanged(StyleChange::Type styleChange)
206 SendEvent(styleChange);
209 void EventHandler::AddObserver(Observer& observer)
211 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
213 if(match == mObservers.end())
215 mObservers.push_back(&observer);
219 void EventHandler::RemoveObserver(Observer& observer)
221 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
223 if(match != mObservers.end())
225 mObservers.erase(match);
229 } // namespace Adaptor
231 } // namespace Internal