Merge "Use existing callback ID for recurring callbacks" into devel/master
[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) 2020 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 <cstdint> // uint32_t
23 #include <dali/public-api/common/intrusive-ptr.h>
24
25 #include <dali/devel-api/adaptor-framework/clipboard.h>
26 #include <dali/devel-api/adaptor-framework/style-monitor.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/clipboard/common/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
36 namespace Integration
37 {
38
39 struct Point;
40 struct KeyEvent;
41 struct WheelEvent;
42
43 }
44
45 namespace Internal
46 {
47
48 namespace Adaptor
49 {
50
51 class StyleMonitor;
52 class WindowRenderSurface;
53
54 /**
55  * The Event Handler class is responsible for setting up receiving of Ecore events and then converts them
56  * to TouchEvents when it does receive them.
57  *
58  * These TouchEvents are then passed on to Core.
59  */
60 class EventHandler : public ConnectionTracker, public Dali::RefObject
61 {
62 public:
63
64   /**
65    * The observer can be overridden in order to listen to the events.
66    */
67   class Observer
68   {
69   public:
70
71     /**
72      * Deriving classes should override this to be notified when we receive a touch point event.
73      * @param[in] point The touch point
74      * @param[in] timeStamp The time stamp
75      */
76     virtual void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) = 0;
77
78     /**
79      * Deriving classes should override this to be notified when we receive a wheel event.
80      * @param[in] wheelEvent The wheel event
81      */
82     virtual void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) = 0;
83
84     /**
85      * Deriving classes should override this to be notified when we receive a key event.
86      * @param[in] keyEvent The key event holding the key information.
87      */
88     virtual void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) = 0;
89
90     /**
91      * Deriving classes should override this to be notified when the window is rotated.
92      * @param[in] rotation The rotation event.
93      */
94     virtual void OnRotation( const RotationEvent& rotation ) = 0;
95
96   protected:
97
98     /**
99      * Protected Constructor.
100      */
101     Observer() {}
102
103     /**
104      * Protected virtual destructor.
105      */
106     virtual ~Observer() {}
107   };
108
109 public:
110
111   /**
112    * Constructor.
113    * @param[in]  windowBase               The window base to be handled
114    * @param[in]  damageObserver           The damage observer (to pass damage events to).
115    */
116   EventHandler( WindowBase* windowBase, DamageObserver& damageObserver );
117
118   /**
119    * Destructor.
120    */
121   ~EventHandler() override;
122
123   /**
124    * Called when the adaptor is paused.
125    */
126   void Pause();
127
128   /**
129    * Called when the adaptor is resumed (from pause).
130    */
131   void Resume();
132
133   /**
134    * Adds an observer so that we can observe the events.
135    * @param[in] observer The observer.
136    */
137   void AddObserver( Observer& observer );
138
139   /**
140    * Removes the observer from the EventHandler.
141    * @param[in] observer The observer to remove.
142    * @note Observers should remove themselves when they are destroyed.
143    */
144   void RemoveObserver( Observer& observer );
145
146 private:
147
148   /**
149    * Send a style change event to the style monitor.
150    * @param[in]  styleChange  The style that has changed.
151    */
152   void SendEvent( StyleChange::Type styleChange );
153
154   /**
155    * Send a window damage event to the observer.
156    * @param[in]  area  Damaged area.
157    */
158   void SendEvent( const DamageArea& area );
159
160   /**
161    * Called when a touch event is received.
162    */
163   void OnTouchEvent( Integration::Point& point, uint32_t timeStamp );
164
165   /**
166    * Called when a mouse wheel is received.
167    */
168   void OnWheelEvent( Integration::WheelEvent& wheelEvent );
169
170   /**
171    * Called when a key event is received.
172    */
173   void OnKeyEvent( Integration::KeyEvent& keyEvent );
174
175   /**
176    * Called when the window focus is changed.
177    */
178   void OnFocusChanged( bool focusIn );
179
180   /**
181    * Called when the window is rotated.
182    * @param[in] event The rotation event
183    */
184   void OnRotation( const RotationEvent& event );
185
186   /**
187    * Called when the window is damaged.
188    */
189   void OnWindowDamaged( const DamageArea& area );
190
191   /**
192    * Called when the source window notifies us the content in clipboard is selected.
193    */
194   void OnSelectionDataSend( void* event );
195
196   /**
197    * Called when the source window sends us about the selected content.
198    */
199   void OnSelectionDataReceived( void* event );
200
201   /**
202    * Called when the style is changed.
203    */
204   void OnStyleChanged( StyleChange::Type styleChange );
205
206 private:
207
208   // Undefined
209   EventHandler( const EventHandler& eventHandler );
210
211   // Undefined
212   EventHandler& operator=( const EventHandler& eventHandler );
213
214 private:
215
216   Dali::StyleMonitor mStyleMonitor; ///< Handle to the style monitor, set on construction, to send font size and font change events to.
217   DamageObserver& mDamageObserver; ///< Reference to the DamageObserver, set on construction, to sent damage events to.
218
219   Dali::ClipboardEventNotifier mClipboardEventNotifier; ///< Pointer to the clipboard event notifier
220   Dali::Clipboard mClipboard;///< Pointer to the clipboard
221
222   using ObserverContainer = std::vector<Observer*>;
223   ObserverContainer mObservers;   ///< A list of event observer pointers
224
225   bool mPaused; ///< The paused state of the adaptor.
226 };
227
228 } // namespace Adaptor
229
230 } // namespace Internal
231
232 } // namespace Dali
233
234 #endif // DALI_INTERNAL_EVENT_HANDLER_H