Merge "[ATSPI] make NotifyAccessibilityStateChange work" 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) 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 private:
421   /**
422    * @brief Enumeration for orietation mode.
423    * The Orientation Mode is related to screen size.
424    * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
425    * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
426    */
427   enum class OrientationMode
428   {
429     PORTRAIT = 0,
430     LANDSCAPE
431   };
432
433   /**
434    * Private constructor.
435    * @sa Window::New()
436    */
437   Window();
438
439   /**
440    * Destructor
441    */
442   ~Window() override;
443
444   /**
445    * Second stage initialization
446    */
447   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
448
449   /**
450    * Called when the window becomes iconified or deiconified.
451    */
452   void OnIconifyChanged(bool iconified);
453
454   /**
455    * Called when the window focus is changed.
456    */
457   void OnFocusChanged(bool focusIn);
458
459   /**
460    * Called when the output is transformed.
461    */
462   void OnOutputTransformed();
463
464   /**
465    * Called when the window receives a delete request.
466    */
467   void OnDeleteRequest();
468
469   /**
470    * Called when the window receives a Transition effect-start/end event.
471    */
472   void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
473
474   /**
475    * @brief Called when window receives a keyboard repeat event.
476    */
477   void OnKeyboardRepeatSettingsChanged();
478
479   /**
480    * @brief Called when the window redraw is requested.
481    */
482   void OnWindowRedrawRequest();
483
484   /**
485    * @brief Called when the window is resized or moved by display server.
486    *
487    * @param[in] positionSize the updated window's position and size.
488    */
489   void OnUpdatePositionSize(Dali::PositionSize& positionSize);
490
491   /**
492    * @brief Called when display server sent the auxiliary message.
493    *
494    * @param[in] key the auxiliary message's key.
495    * @param[in] value the auxiliary message's value.
496    * @param[in] options the auxiliary message's options. This is the list of string.
497    */
498   void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
499
500   /**
501    * @brief Set available orientation to window base.
502    */
503   void SetAvailableAnlges(const std::vector<int>& angles);
504
505   /**
506    * @brief Convert from window orientation to angle using OrientationMode.
507    */
508   int ConvertToAngle(WindowOrientation orientation);
509
510   /**
511    * @brief Convert from angle to window orientation using OrientationMode.
512    */
513   WindowOrientation ConvertToOrientation(int angle) const;
514
515   /**
516    * @brief Check available window orientation for Available orientation.
517    */
518   bool IsOrientationAvailable(WindowOrientation orientation) const;
519
520   /**
521    * @brief Return the rect value to recalulate with the default system coordinates.
522    *
523    * Some native window APIs work the geometry value based on the default system coordinates.
524    * IncludeInputRegion() and ExcludeInputRegion() are one of them.
525    * When the window is rotated, current window's geometry already were set with the rotated angle.
526    * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
527    * the rect's area should be re-calcuated on the default system coordinates.
528    *
529    * @param[in] rect the window's current position and size with current window rotation angle.
530    * @return the re-calculated rect on the default system coordinates.
531    */
532   Rect<int> RecalculateRect(const Rect<int>& rect);
533
534 private: // Dali::Internal::Adaptor::SceneHolder
535   /**
536    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
537    */
538   void OnAdaptorSet(Dali::Adaptor& adaptor) override;
539
540   /**
541    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
542    */
543   void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
544
545   /**
546    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
547    */
548   void OnPause() override;
549
550   /**
551    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
552    */
553   void OnResume() override;
554
555   /**
556    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
557    */
558   void RecalculateTouchPosition(Integration::Point& point) override;
559
560 private: // Dali::Internal::Adaptor::EventHandler::Observer
561   /**
562    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
563    */
564   void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
565
566   /**
567    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
568    */
569   void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
570
571   /**
572    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
573    */
574   void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
575
576   /**
577    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
578    */
579   void OnRotation(const RotationEvent& rotation) override;
580
581 public: // Signals
582   /**
583    * @copydoc Dali::Window::FocusChangeSignal()
584    */
585   FocusChangeSignalType& FocusChangeSignal()
586   {
587     return mFocusChangeSignal;
588   }
589
590   /**
591    * @copydoc Dali::Window::ResizedSignal()
592    */
593   ResizeSignalType& ResizeSignal()
594   {
595     return mResizeSignal;
596   }
597
598   /**
599    * This signal is emitted when the window is requesting to be deleted
600    */
601   SignalType& DeleteRequestSignal()
602   {
603     return mDeleteRequestSignal;
604   }
605
606   /**
607    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
608    */
609   VisibilityChangedSignalType& VisibilityChangedSignal()
610   {
611     return mVisibilityChangedSignal;
612   }
613
614   /**
615    * @copydoc Dali::Window::SignalEventProcessingFinished()
616    */
617   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
618   {
619     return mScene.EventProcessingFinishedSignal();
620   }
621
622   /**
623    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
624    */
625   TransitionEffectEventSignalType& TransitionEffectEventSignal()
626   {
627     return mTransitionEffectEventSignal;
628   }
629
630   /**
631    * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
632    */
633   KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
634   {
635     return mKeyboardRepeatSettingsChangedSignal;
636   }
637
638   /**
639    * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
640    */
641   AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
642   {
643     return mAuxiliaryMessageSignal;
644   }
645
646 private:
647   WindowRenderSurface* mWindowSurface; ///< The window rendering surface
648   WindowBase*          mWindowBase;
649   std::string          mName;
650   std::string          mClassName;
651   bool                 mIsTransparent : 1;
652   bool                 mIsFocusAcceptable : 1;
653   bool                 mIconified : 1;
654   bool                 mOpaqueState : 1;
655   bool                 mWindowRotationAcknowledgement : 1;
656   Dali::Window         mParentWindow;
657
658   OrientationPtr   mOrientation;
659   std::vector<int> mAvailableAngles;
660   int              mPreferredAngle;
661
662   int mRotationAngle;                    ///< The angle of the rotation
663   int mWindowWidth;                      ///< The width of the window
664   int mWindowHeight;                     ///< The height of the window
665
666   EventHandlerPtr mEventHandler;         ///< The window events handler
667
668   OrientationMode mOrientationMode;      ///< The physical screen mode is portrait or landscape
669
670   int mNativeWindowId;                   ///< The Native Window Id
671
672   // Signals
673   SignalType                              mDeleteRequestSignal;
674   FocusChangeSignalType                   mFocusChangeSignal;
675   ResizeSignalType                        mResizeSignal;
676   VisibilityChangedSignalType             mVisibilityChangedSignal;
677   TransitionEffectEventSignalType         mTransitionEffectEventSignal;
678   KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
679   AuxiliaryMessageSignalType              mAuxiliaryMessageSignal;
680 };
681
682 } // namespace Adaptor
683 } // namespace Internal
684
685 // Helpers for public-api forwarding methods
686
687 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
688 {
689   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
690   BaseObject& object = window.GetBaseObject();
691   return static_cast<Internal::Adaptor::Window&>(object);
692 }
693
694 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
695 {
696   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
697   const BaseObject& object = window.GetBaseObject();
698   return static_cast<const Internal::Adaptor::Window&>(object);
699 }
700
701 } // namespace Dali
702
703 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H