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