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