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