Support to get the rect value to recalulate with the default system coordinates.
[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(Window window, Window parent)
330    */
331   void SetParent(Dali::Window& parent);
332
333   /**
334    * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
335    */
336   void SetParent(Dali::Window& parent, bool belowParent);
337
338   /**
339    * @copydoc Dali::DevelWindow::Unparent()
340    */
341   void Unparent();
342
343   /**
344    * @copydoc Dali::DevelWindow::GetParent()
345    */
346   Dali::Window GetParent();
347
348   /**
349    * @copydoc Dali::DevelWindow::GetCurrentOrientation()
350    */
351   WindowOrientation GetCurrentOrientation() const;
352
353   /**
354    * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
355    */
356   int GetPhysicalOrientation() const;
357
358   /**
359    * @copydoc Dali::DevelWindow::SetAvailableOrientations()
360    */
361   void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
362
363   /**
364    * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
365    */
366   void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
367
368 public: // Dali::Internal::Adaptor::SceneHolder
369   /**
370    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
371    */
372   Dali::Any GetNativeHandle() const override;
373
374   /**
375    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
376    */
377   bool IsVisible() const override;
378
379   /**
380    * @copydoc Dali::DevelWindow::GetNativeId()
381    */
382   int32_t GetNativeId() const;
383
384   /**
385    * @copydoc Dali::DevelWindow::RequestMoveToServer()
386    */
387   void RequestMoveToServer();
388
389   /**
390    * @copydoc Dali::DevelWindow::RequestResizeToServer()
391    */
392   void RequestResizeToServer(WindowResizeDirection direction);
393
394   /**
395    * @copydoc Dali::DevelWindow::EnableFloatingMode()
396    */
397   void EnableFloatingMode(bool enable);
398
399   /**
400    * @copydoc Dali::DevelWindow::IncludeInputRegion()
401    */
402   void IncludeInputRegion(const Rect<int>& inputRegion);
403
404   /**
405    * @copydoc Dali::DevelWindow::ExcludeInputRegion()
406    */
407   void ExcludeInputRegion(const Rect<int>& inputRegion);
408
409   /**
410    * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
411    */
412   void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
413
414   /**
415    * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
416    */
417   void SendRotationCompletedAcknowledgement();
418
419 private:
420   /**
421    * @brief Enumeration for orietation mode.
422    * The Orientation Mode is related to screen size.
423    * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
424    * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
425    */
426   enum class OrientationMode
427   {
428     PORTRAIT = 0,
429     LANDSCAPE
430   };
431
432   /**
433    * Private constructor.
434    * @sa Window::New()
435    */
436   Window();
437
438   /**
439    * Destructor
440    */
441   ~Window() override;
442
443   /**
444    * Second stage initialization
445    */
446   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
447
448   /**
449    * Called when the window becomes iconified or deiconified.
450    */
451   void OnIconifyChanged(bool iconified);
452
453   /**
454    * Called when the window focus is changed.
455    */
456   void OnFocusChanged(bool focusIn);
457
458   /**
459    * Called when the output is transformed.
460    */
461   void OnOutputTransformed();
462
463   /**
464    * Called when the window receives a delete request.
465    */
466   void OnDeleteRequest();
467
468   /**
469    * Called when the window receives a Transition effect-start/end event.
470    */
471   void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
472
473   /**
474    * @brief Called when window receives a keyboard repeat event.
475    */
476   void OnKeyboardRepeatSettingsChanged();
477
478   /**
479    * @brief Called when the window redraw is requested.
480    */
481   void OnWindowRedrawRequest();
482
483   /**
484    * @brief Called when the window is resized or moved by display server.
485    *
486    * @param[in] positionSize the updated window's position and size.
487    */
488   void OnUpdatePositionSize(Dali::PositionSize& positionSize);
489
490   /**
491    * @brief Set available orientation to window base.
492    */
493   void SetAvailableAnlges(const std::vector<int>& angles);
494
495   /**
496    * @brief Convert from window orientation to angle using OrientationMode.
497    */
498   int ConvertToAngle(WindowOrientation orientation);
499
500   /**
501    * @brief Convert from angle to window orientation using OrientationMode.
502    */
503   WindowOrientation ConvertToOrientation(int angle) const;
504
505   /**
506    * @brief Check available window orientation for Available orientation.
507    */
508   bool IsOrientationAvailable(WindowOrientation orientation) const;
509
510   /**
511    * @brief Return the rect value to recalulate with the default system coordinates.
512    *
513    * Some native window APIs work the geometry value based on the default system coordinates.
514    * IncludeInputRegion() and ExcludeInputRegion() are one of them.
515    * When the window is rotated, current window's geometry already were set with the rotated angle.
516    * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
517    * the rect's area should be re-calcuated on the default system coordinates.
518    *
519    * @param[in] rect the window's current position and size with current window rotation angle.
520    * @return the re-calculated rect on the default system coordinates.
521    */
522   Rect<int> RecalculateRect(const Rect<int>& rect);
523
524 private: // Dali::Internal::Adaptor::SceneHolder
525   /**
526    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
527    */
528   void OnAdaptorSet(Dali::Adaptor& adaptor) override;
529
530   /**
531    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
532    */
533   void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
534
535   /**
536    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
537    */
538   void OnPause() override;
539
540   /**
541    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
542    */
543   void OnResume() override;
544
545   /**
546    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
547    */
548   void RecalculateTouchPosition(Integration::Point& point) override;
549
550 private: // Dali::Internal::Adaptor::EventHandler::Observer
551   /**
552    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
553    */
554   void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
555
556   /**
557    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
558    */
559   void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
560
561   /**
562    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
563    */
564   void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
565
566   /**
567    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
568    */
569   void OnRotation(const RotationEvent& rotation) override;
570
571 public: // Signals
572   /**
573    * @copydoc Dali::Window::FocusChangeSignal()
574    */
575   FocusChangeSignalType& FocusChangeSignal()
576   {
577     return mFocusChangeSignal;
578   }
579
580   /**
581    * @copydoc Dali::Window::ResizedSignal()
582    */
583   ResizeSignalType& ResizeSignal()
584   {
585     return mResizeSignal;
586   }
587
588   /**
589    * This signal is emitted when the window is requesting to be deleted
590    */
591   SignalType& DeleteRequestSignal()
592   {
593     return mDeleteRequestSignal;
594   }
595
596   /**
597    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
598    */
599   VisibilityChangedSignalType& VisibilityChangedSignal()
600   {
601     return mVisibilityChangedSignal;
602   }
603
604   /**
605    * @copydoc Dali::Window::SignalEventProcessingFinished()
606    */
607   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
608   {
609     return mScene.EventProcessingFinishedSignal();
610   }
611
612   /**
613    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
614    */
615   TransitionEffectEventSignalType& TransitionEffectEventSignal()
616   {
617     return mTransitionEffectEventSignal;
618   }
619
620   /**
621    * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
622    */
623   KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
624   {
625     return mKeyboardRepeatSettingsChangedSignal;
626   }
627
628 private:
629   WindowRenderSurface* mWindowSurface; ///< The window rendering surface
630   WindowBase*          mWindowBase;
631   std::string          mName;
632   std::string          mClassName;
633   bool                 mIsTransparent : 1;
634   bool                 mIsFocusAcceptable : 1;
635   bool                 mIconified : 1;
636   bool                 mOpaqueState : 1;
637   bool                 mWindowRotationAcknowledgement : 1;
638   Dali::Window         mParentWindow;
639
640   OrientationPtr   mOrientation;
641   std::vector<int> mAvailableAngles;
642   int              mPreferredAngle;
643
644   int mRotationAngle;                    ///< The angle of the rotation
645   int mWindowWidth;                      ///< The width of the window
646   int mWindowHeight;                     ///< The height of the window
647
648   EventHandlerPtr mEventHandler;         ///< The window events handler
649
650   OrientationMode mOrientationMode;      ///< The physical screen mode is portrait or landscape
651
652   int mNativeWindowId;                   ///< The Native Window Id
653
654   // Signals
655   SignalType                              mDeleteRequestSignal;
656   FocusChangeSignalType                   mFocusChangeSignal;
657   ResizeSignalType                        mResizeSignal;
658   VisibilityChangedSignalType             mVisibilityChangedSignal;
659   TransitionEffectEventSignalType         mTransitionEffectEventSignal;
660   KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
661 };
662
663 } // namespace Adaptor
664 } // namespace Internal
665
666 // Helpers for public-api forwarding methods
667
668 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
669 {
670   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
671   BaseObject& object = window.GetBaseObject();
672   return static_cast<Internal::Adaptor::Window&>(object);
673 }
674
675 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
676 {
677   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
678   const BaseObject& object = window.GetBaseObject();
679   return static_cast<const Internal::Adaptor::Window&>(object);
680 }
681
682 } // namespace Dali
683
684 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H