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