Add input region APIs
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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/actors/layer.h>
23 #include <dali/public-api/adaptor-framework/window-enumerations.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-array.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
28
29 // INTERNAL INCLUDES
30 #include <dali/devel-api/adaptor-framework/window-devel.h>
31 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/window-system/common/event-handler.h>
34 #include <dali/public-api/adaptor-framework/key-grab.h>
35 #include <dali/public-api/adaptor-framework/window.h>
36
37 namespace Dali
38 {
39 class Adaptor;
40 class Actor;
41 class RenderSurfaceInterface;
42
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 class Orientation;
48 class WindowRenderSurface;
49 class WindowBase;
50
51 class Window;
52 using WindowPtr       = IntrusivePtr<Window>;
53 using OrientationPtr  = IntrusivePtr<Orientation>;
54 using EventHandlerPtr = IntrusivePtr<EventHandler>;
55
56 /**
57  * Window provides a surface to render onto with orientation & indicator properties.
58  */
59 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
60 {
61 public:
62   typedef Dali::Window::FocusChangeSignalType                        FocusChangeSignalType;
63   typedef Dali::Window::ResizeSignalType                             ResizeSignalType;
64   typedef Dali::DevelWindow::VisibilityChangedSignalType             VisibilityChangedSignalType;
65   typedef Dali::DevelWindow::TransitionEffectEventSignalType         TransitionEffectEventSignalType;
66   typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
67   typedef Signal<void()>                                             SignalType;
68
69   /**
70    * @brief Create a new Window. This should only be called once by the Application class
71    * @param[in] positionSize The position and size of the window
72    * @param[in] name The window title
73    * @param[in] className The window class name
74    * @param[in] type Window type.
75    * @param[in] isTransparent Whether window is transparent
76    * @return A newly allocated Window
77    */
78   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
79
80   /**
81    * @brief Create a new Window. This should only be called once by the Application class
82    * @param[in] surface The surface used to render on.
83    * @param[in] positionSize The position and size of the window
84    * @param[in] name The window title
85    * @param[in] className The window class name
86    * @param[in] type Window type.
87    * @param[in] isTransparent Whether window is transparent
88    * @return A newly allocated Window
89    */
90   static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className,  Dali::WindowType type, bool isTransparent = false);
91
92   /**
93    * @copydoc Dali::Window::SetClass()
94    */
95   void SetClass(std::string name, std::string className);
96
97   /**
98    * @brief Gets the window class name.
99    * @return The class of the window
100    */
101   std::string GetClassName() const;
102
103   /**
104    * @copydoc Dali::Window::Raise()
105    */
106   void Raise();
107
108   /**
109    * @copydoc Dali::Window::Lower()
110    */
111   void Lower();
112
113   /**
114    * @copydoc Dali::Window::Activate()
115    */
116   void Activate();
117
118   /**
119    * @copydoc Dali::Window::GetLayerCount()
120    */
121   uint32_t GetLayerCount() const;
122
123   /**
124    * @copydoc Dali::Window::GetLayer()
125    */
126   Dali::Layer GetLayer(uint32_t depth) const;
127
128   /**
129    * @copydoc Dali::DevelWindow::GetRenderTaskList()
130    */
131   Dali::RenderTaskList GetRenderTaskList() const;
132
133   /**
134    * @copydoc Dali::Window::AddAvailableOrientation()
135    */
136   void AddAvailableOrientation(WindowOrientation orientation);
137
138   /**
139    * @copydoc Dali::Window::RemoveAvailableOrientation()
140    */
141   void RemoveAvailableOrientation(WindowOrientation orientation);
142
143   /**
144    * @copydoc Dali::Window::SetPreferredOrientation()
145    */
146   void SetPreferredOrientation(WindowOrientation orientation);
147
148   /**
149    * @copydoc Dali::Window::GetPreferredOrientation()
150    */
151   WindowOrientation GetPreferredOrientation();
152
153   /**
154    * @copydoc Dali::Window::SetAcceptFocus()
155    */
156   void SetAcceptFocus(bool accept);
157
158   /**
159    * @copydoc Dali::Window::IsFocusAcceptable()
160    */
161   bool IsFocusAcceptable() const;
162
163   /**
164    * @copydoc Dali::Window::Show()
165    */
166   void Show();
167
168   /**
169    * @copydoc Dali::Window::Hide()
170    */
171   void Hide();
172
173   /**
174    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
175    */
176   unsigned int GetSupportedAuxiliaryHintCount() const;
177
178   /**
179    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
180    */
181   std::string GetSupportedAuxiliaryHint(unsigned int index) const;
182
183   /**
184    * @copydoc Dali::Window::AddAuxiliaryHint()
185    */
186   unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
187
188   /**
189    * @copydoc Dali::Window::RemoveAuxiliaryHint()
190    */
191   bool RemoveAuxiliaryHint(unsigned int id);
192
193   /**
194    * @copydoc Dali::Window::SetAuxiliaryHintValue()
195    */
196   bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
197
198   /**
199    * @copydoc Dali::Window::GetAuxiliaryHintValue()
200    */
201   std::string GetAuxiliaryHintValue(unsigned int id) const;
202
203   /**
204    * @copydoc Dali::Window::GetAuxiliaryHintId()
205    */
206   unsigned int GetAuxiliaryHintId(const std::string& hint) const;
207
208   /**
209    * @copydoc Dali::Window::SetInputRegion()
210    */
211   void SetInputRegion(const Rect<int>& inputRegion);
212
213   /**
214    * @copydoc Dali::Window::SetType()
215    */
216   void SetType(WindowType type);
217
218   /**
219    * @copydoc Dali::Window::GetType() const
220    */
221   WindowType GetType() const;
222
223   /**
224    * @copydoc Dali::Window::SetNotificationLevel()
225    */
226   WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
227
228   /**
229    * @copydoc Dali::Window::GetNotificationLevel()
230    */
231   WindowNotificationLevel GetNotificationLevel() const;
232
233   /**
234    * @copydoc Dali::Window::SetOpaqueState()
235    */
236   void SetOpaqueState(bool opaque);
237
238   /**
239    * @copydoc Dali::Window::IsOpaqueState()
240    */
241   bool IsOpaqueState() const;
242
243   /**
244    * @copydoc Dali::Window::SetScreenOffMode()
245    */
246   WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
247
248   /**
249    * @copydoc Dali::Window::GetScreenOffMode()
250    */
251   WindowScreenOffMode GetScreenOffMode() const;
252
253   /**
254    * @copydoc Dali::Window::SetBrightness()
255    */
256   WindowOperationResult SetBrightness(int brightness);
257
258   /**
259    * @copydoc Dali::Window::GetBrightness()
260    */
261   int GetBrightness() const;
262
263   /**
264    * @copydoc Dali::Window::SetSize()
265    */
266   void SetSize(Dali::Window::WindowSize size);
267
268   /**
269    * @copydoc Dali::Window::GetSize()
270    */
271   Dali::Window::WindowSize GetSize() const;
272
273   /**
274    * @copydoc Dali::Window::SetPosition()
275    */
276   void SetPosition(Dali::Window::WindowPosition position);
277
278   /**
279    * @copydoc Dali::Window::GetPosition()
280    */
281   Dali::Window::WindowPosition GetPosition() const;
282
283   /**
284    * @copydoc Dali::DevelWindow::SetPositionSize()
285    */
286   void SetPositionSize(PositionSize positionSize);
287
288   /**
289    * @copydoc Dali::DevelWindow::GetPositionSize()
290    */
291   PositionSize GetPositionSize() const;
292
293   /**
294    * @copydoc Dali::Window::GetRootLayer()
295    */
296   Dali::Layer GetRootLayer() const;
297
298   /**
299    * @copydoc Dali::Window::SetTransparency()
300    */
301   void SetTransparency(bool transparent);
302
303   /**
304    * @copydoc Dali::KeyGrab::GrabKey()
305    */
306   bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
307
308   /**
309    * @copydoc Dali::KeyGrab::UngrabKey()
310    */
311   bool UngrabKey(Dali::KEY key);
312
313   /**
314    * @copydoc Dali::KeyGrab::GrabKeyList()
315    */
316   bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
317
318   /**
319    * @copydoc Dali::KeyGrab::UngrabKeyList()
320    */
321   bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
322
323   /**
324    * @copydoc Dali::DevelWindow::Get()
325    */
326   static Dali::Window Get(Dali::Actor actor);
327
328   /**
329    * @copydoc Dali::DevelWindow::SetParent()
330    */
331   void SetParent(Dali::Window& parent);
332
333   /**
334    * @copydoc Dali::DevelWindow::Unparent()
335    */
336   void Unparent();
337
338   /**
339    * @copydoc Dali::DevelWindow::GetParent()
340    */
341   Dali::Window GetParent();
342
343   /**
344    * @copydoc Dali::DevelWindow::GetCurrentOrientation()
345    */
346   WindowOrientation GetCurrentOrientation() const;
347
348   /**
349    * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
350    */
351   int GetPhysicalOrientation() const;
352
353   /**
354    * @copydoc Dali::DevelWindow::SetAvailableOrientations()
355    */
356   void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
357
358   /**
359    * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
360    */
361   void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
362
363 public: // Dali::Internal::Adaptor::SceneHolder
364   /**
365    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
366    */
367   Dali::Any GetNativeHandle() const override;
368
369   /**
370    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
371    */
372   bool IsVisible() const override;
373
374   /**
375    * @copydoc Dali::DevelWindow::GetNativeId()
376    */
377   int32_t GetNativeId() const;
378
379   /**
380    * @copydoc Dali::DevelWindow::RequestMoveToServer()
381    */
382   void RequestMoveToServer();
383
384   /**
385    * @copydoc Dali::DevelWindow::RequestResizeToServer()
386    */
387   void RequestResizeToServer(WindowResizeDirection direction);
388
389   /**
390    * @copydoc Dali::DevelWindow::EnableFloatingMode()
391    */
392   void EnableFloatingMode(bool enable);
393
394   /**
395    * @copydoc Dali::DevelWindow::IncludeInputRegion()
396    */
397   void IncludeInputRegion(const Rect<int>& inputRegion);
398
399   /**
400    * @copydoc Dali::DevelWindow::ExcludeInputRegion()
401    */
402   void ExcludeInputRegion(const Rect<int>& inputRegion);
403
404 private:
405   /**
406    * @brief Enumeration for orietation mode.
407    * The Orientation Mode is related to screen size.
408    * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
409    * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
410    */
411   enum class OrientationMode
412   {
413     PORTRAIT = 0,
414     LANDSCAPE
415   };
416
417   /**
418    * Private constructor.
419    * @sa Window::New()
420    */
421   Window();
422
423   /**
424    * Destructor
425    */
426   ~Window() override;
427
428   /**
429    * Second stage initialization
430    */
431   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
432
433   /**
434    * Called when the window becomes iconified or deiconified.
435    */
436   void OnIconifyChanged(bool iconified);
437
438   /**
439    * Called when the window focus is changed.
440    */
441   void OnFocusChanged(bool focusIn);
442
443   /**
444    * Called when the output is transformed.
445    */
446   void OnOutputTransformed();
447
448   /**
449    * Called when the window receives a delete request.
450    */
451   void OnDeleteRequest();
452
453   /**
454    * Called when the window receives a Transition effect-start/end event.
455    */
456   void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
457
458   /**
459    * @brief Called when window receives a keyboard repeat event.
460    */
461   void OnKeyboardRepeatSettingsChanged();
462
463   /**
464    * @brief Called when the window redraw is requested.
465    */
466   void OnWindowRedrawRequest();
467
468   /**
469    * @brief Called when the window is resized or moved by display server.
470    *
471    * @param positionSize the updated window's position and size.
472    */
473   void OnUpdatePositionSize(Dali::PositionSize& positionSize);
474
475   /**
476    * @brief Set available orientation to window base.
477    */
478   void SetAvailableAnlges(const std::vector<int>& angles);
479
480   /**
481    * @brief Convert from window orientation to angle using OrientationMode.
482    */
483   int ConvertToAngle(WindowOrientation orientation);
484
485   /**
486    * @brief Convert from angle to window orientation using OrientationMode.
487    */
488   WindowOrientation ConvertToOrientation(int angle) const;
489
490   /**
491    * @brief Check available window orientation for Available orientation.
492    */
493   bool IsOrientationAvailable(WindowOrientation orientation) const;
494
495 private: // Dali::Internal::Adaptor::SceneHolder
496   /**
497    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
498    */
499   void OnAdaptorSet(Dali::Adaptor& adaptor) override;
500
501   /**
502    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
503    */
504   void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
505
506   /**
507    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
508    */
509   void OnPause() override;
510
511   /**
512    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
513    */
514   void OnResume() override;
515
516   /**
517    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
518    */
519   void RecalculateTouchPosition(Integration::Point& point) override;
520
521 private: // Dali::Internal::Adaptor::EventHandler::Observer
522   /**
523    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
524    */
525   void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
526
527   /**
528    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
529    */
530   void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
531
532   /**
533    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
534    */
535   void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
536
537   /**
538    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
539    */
540   void OnRotation(const RotationEvent& rotation) override;
541
542 public: // Signals
543   /**
544    * @copydoc Dali::Window::FocusChangeSignal()
545    */
546   FocusChangeSignalType& FocusChangeSignal()
547   {
548     return mFocusChangeSignal;
549   }
550
551   /**
552    * @copydoc Dali::Window::ResizedSignal()
553    */
554   ResizeSignalType& ResizeSignal()
555   {
556     return mResizeSignal;
557   }
558
559   /**
560    * This signal is emitted when the window is requesting to be deleted
561    */
562   SignalType& DeleteRequestSignal()
563   {
564     return mDeleteRequestSignal;
565   }
566
567   /**
568    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
569    */
570   VisibilityChangedSignalType& VisibilityChangedSignal()
571   {
572     return mVisibilityChangedSignal;
573   }
574
575   /**
576    * @copydoc Dali::Window::SignalEventProcessingFinished()
577    */
578   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
579   {
580     return mScene.EventProcessingFinishedSignal();
581   }
582
583   /**
584    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
585    */
586   TransitionEffectEventSignalType& TransitionEffectEventSignal()
587   {
588     return mTransitionEffectEventSignal;
589   }
590
591   /**
592    * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
593    */
594   KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
595   {
596     return mKeyboardRepeatSettingsChangedSignal;
597   }
598
599 private:
600   WindowRenderSurface* mWindowSurface; ///< The window rendering surface
601   WindowBase*          mWindowBase;
602   std::string          mName;
603   std::string          mClassName;
604   bool                 mIsTransparent : 1;
605   bool                 mIsFocusAcceptable : 1;
606   bool                 mIconified : 1;
607   bool                 mOpaqueState : 1;
608   Dali::Window         mParentWindow;
609
610   OrientationPtr   mOrientation;
611   std::vector<int> mAvailableAngles;
612   int              mPreferredAngle;
613
614   int mRotationAngle;                    ///< The angle of the rotation
615   int mWindowWidth;                      ///< The width of the window
616   int mWindowHeight;                     ///< The height of the window
617
618   EventHandlerPtr mEventHandler;         ///< The window events handler
619
620   OrientationMode mOrientationMode;      ///< The physical screen mode is portrait or landscape
621
622   int mNativeWindowId;                   ///< The Native Window Id
623
624   // Signals
625   SignalType                              mDeleteRequestSignal;
626   FocusChangeSignalType                   mFocusChangeSignal;
627   ResizeSignalType                        mResizeSignal;
628   VisibilityChangedSignalType             mVisibilityChangedSignal;
629   TransitionEffectEventSignalType         mTransitionEffectEventSignal;
630   KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
631 };
632
633 } // namespace Adaptor
634 } // namespace Internal
635
636 // Helpers for public-api forwarding methods
637
638 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
639 {
640   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
641   BaseObject& object = window.GetBaseObject();
642   return static_cast<Internal::Adaptor::Window&>(object);
643 }
644
645 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
646 {
647   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
648   const BaseObject& object = window.GetBaseObject();
649   return static_cast<const Internal::Adaptor::Window&>(object);
650 }
651
652 } // namespace Dali
653
654 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H