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