9ad49d10d4b06dcdfc24af84c8675d4006ea8157
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / event-handler.h
1 #ifndef DALI_INTERNAL_EVENT_HANDLER_H
2 #define DALI_INTERNAL_EVENT_HANDLER_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <cstdint> // uint32_t
24
25 #include <dali/devel-api/adaptor-framework/text-clipboard.h>
26 #include <dali/devel-api/adaptor-framework/style-monitor.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/text-clipboard/common/text-clipboard-event-notifier-impl.h>
30 #include <dali/internal/window-system/common/damage-observer.h>
31 #include <dali/internal/window-system/common/window-base.h>
32
33 namespace Dali
34 {
35 namespace Integration
36 {
37 struct Point;
38 struct KeyEvent;
39 struct WheelEvent;
40
41 } // namespace Integration
42
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 class StyleMonitor;
48 class WindowRenderSurface;
49
50 /**
51  * The Event Handler class is responsible for setting up receiving of Ecore events and then converts them
52  * to TouchEvents when it does receive them.
53  *
54  * These TouchEvents are then passed on to Core.
55  */
56 class EventHandler : public ConnectionTracker, public Dali::RefObject
57 {
58 public:
59   /**
60    * The observer can be overridden in order to listen to the events.
61    */
62   class Observer
63   {
64   public:
65     /**
66      * Deriving classes should override this to be notified when we receive a touch point event.
67      * @param[in] point The touch point
68      * @param[in] timeStamp The time stamp
69      */
70     virtual void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) = 0;
71
72     /**
73      * Deriving classes should override this to be notified when we receive a wheel event.
74      * @param[in] wheelEvent The wheel event
75      */
76     virtual void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) = 0;
77
78     /**
79      * Deriving classes should override this to be notified when we receive a key event.
80      * @param[in] keyEvent The key event holding the key information.
81      */
82     virtual void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) = 0;
83
84     /**
85      * Deriving classes should override this to be notified when the window is rotated.
86      * @param[in] rotation The rotation event.
87      */
88     virtual void OnRotation(const RotationEvent& rotation) = 0;
89
90   protected:
91     /**
92      * Protected Constructor.
93      */
94     Observer()
95     {
96     }
97
98     /**
99      * Protected virtual destructor.
100      */
101     virtual ~Observer()
102     {
103     }
104   };
105
106 public:
107   /**
108    * Constructor.
109    * @param[in]  windowBase               The window base to be handled
110    * @param[in]  damageObserver           The damage observer (to pass damage events to).
111    */
112   EventHandler(WindowBase* windowBase, DamageObserver& damageObserver);
113
114   /**
115    * Destructor.
116    */
117   ~EventHandler() override;
118
119   /**
120    * Called when the adaptor is paused.
121    */
122   void Pause();
123
124   /**
125    * Called when the adaptor is resumed (from pause).
126    */
127   void Resume();
128
129   /**
130    * Adds an observer so that we can observe the events.
131    * @param[in] observer The observer.
132    */
133   void AddObserver(Observer& observer);
134
135   /**
136    * Removes the observer from the EventHandler.
137    * @param[in] observer The observer to remove.
138    * @note Observers should remove themselves when they are destroyed.
139    */
140   void RemoveObserver(Observer& observer);
141
142 private:
143   /**
144    * Send a style change event to the style monitor.
145    * @param[in]  styleChange  The style that has changed.
146    */
147   void SendEvent(StyleChange::Type styleChange);
148
149   /**
150    * Send a window damage event to the observer.
151    * @param[in]  area  Damaged area.
152    */
153   void SendEvent(const DamageArea& area);
154
155   /**
156    * Called when a touch event is received.
157    */
158   void OnTouchEvent(Integration::Point& point, uint32_t timeStamp);
159
160   /**
161    * Called when a mouse wheel is received.
162    */
163   void OnWheelEvent(Integration::WheelEvent& wheelEvent);
164
165   /**
166    * Called when a key event is received.
167    */
168   void OnKeyEvent(Integration::KeyEvent& keyEvent);
169
170   /**
171    * Called when the window focus is changed.
172    */
173   void OnFocusChanged(bool focusIn);
174
175   /**
176    * Called when the window is rotated.
177    * @param[in] event The rotation event
178    */
179   void OnRotation(const RotationEvent& event);
180
181   /**
182    * Called when the window is damaged.
183    */
184   void OnWindowDamaged(const DamageArea& area);
185
186   /**
187    * Called when the source window notifies us the content in clipboard is selected.
188    */
189   void OnSelectionDataSend(void* event);
190
191   /**
192    * Called when the source window sends us about the selected content.
193    */
194   void OnSelectionDataReceived(void* event);
195
196   /**
197    * Called when the style is changed.
198    */
199   void OnStyleChanged(StyleChange::Type styleChange);
200
201 private:
202   // Undefined
203   EventHandler(const EventHandler& eventHandler);
204
205   // Undefined
206   EventHandler& operator=(const EventHandler& eventHandler);
207
208 private:
209   Dali::StyleMonitor mStyleMonitor;   ///< Handle to the style monitor, set on construction, to send font size and font change events to.
210   DamageObserver&    mDamageObserver; ///< Reference to the DamageObserver, set on construction, to sent damage events to.
211
212   Dali::TextClipboardEventNotifier mClipboardEventNotifier; ///< Pointer to the clipboard event notifier
213
214   using ObserverContainer = std::vector<Observer*>;
215   ObserverContainer mObservers; ///< A list of event observer pointers
216
217   bool mPaused; ///< The paused state of the adaptor.
218 };
219
220 } // namespace Adaptor
221
222 } // namespace Internal
223
224 } // namespace Dali
225
226 #endif // DALI_INTERNAL_EVENT_HANDLER_H