[AT-SPI] Window: add highlight signal
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/integration-api/core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/window-enumerations.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
32 #include <thread>
33
34 // INTERNAL HEADERS
35 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
36 #include <dali/devel-api/atspi-interfaces/accessible.h>
37 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
38 #include <dali/internal/graphics/gles/egl-graphics.h>
39 #include <dali/internal/window-system/common/event-handler.h>
40 #include <dali/internal/window-system/common/orientation-impl.h>
41 #include <dali/internal/window-system/common/render-surface-factory.h>
42 #include <dali/internal/window-system/common/window-base.h>
43 #include <dali/internal/window-system/common/window-factory.h>
44 #include <dali/internal/window-system/common/window-render-surface.h>
45 #include <dali/internal/window-system/common/window-system.h>
46 #include <dali/internal/window-system/common/window-visibility-observer.h>
47
48 namespace Dali
49 {
50 namespace Internal
51 {
52 namespace Adaptor
53 {
54 namespace
55 {
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
58 #endif
59
60 } // unnamed namespace
61
62 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
63 {
64   Any surface;
65   return Window::New(surface, positionSize, name, className, type, isTransparent);
66 }
67
68 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
69 {
70   Window* window         = new Window();
71   window->mIsTransparent = isTransparent;
72   window->Initialize(surface, positionSize, name, className, type);
73   return window;
74 }
75
76 Window::Window()
77 : mWindowSurface(nullptr),
78   mWindowBase(),
79   mIsTransparent(false),
80   mIsFocusAcceptable(true),
81   mIconified(false),
82   mOpaqueState(false),
83   mWindowRotationAcknowledgement(false),
84   mFocused(false),
85   mParentWindow(NULL),
86   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
87   mRotationAngle(0),
88   mWindowWidth(0),
89   mWindowHeight(0),
90   mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
91   mNativeWindowId(-1),
92   mDeleteRequestSignal(),
93   mFocusChangeSignal(),
94   mResizeSignal(),
95   mVisibilityChangedSignal(),
96   mTransitionEffectEventSignal(),
97   mKeyboardRepeatSettingsChangedSignal(),
98   mAuxiliaryMessageSignal()
99 {
100 }
101
102 Window::~Window()
103 {
104   if(mScene)
105   {
106     auto bridge     = Accessibility::Bridge::GetCurrentBridge();
107     auto rootLayer  = mScene.GetRootLayer();
108     auto accessible = Accessibility::Accessible::Get(rootLayer, true);
109     bridge->RemoveTopLevelWindow(accessible);
110   }
111
112   if(mAdaptor)
113   {
114     mAdaptor->RemoveWindow(this);
115   }
116
117   if(mEventHandler)
118   {
119     mEventHandler->RemoveObserver(*this);
120   }
121 }
122
123 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
124 {
125   // Create a window render surface
126   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
127   mSurface                  = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
128   mWindowSurface            = static_cast<WindowRenderSurface*>(mSurface.get());
129
130   // Get a window base
131   mWindowBase = mWindowSurface->GetWindowBase();
132
133   // Set Window Type
134   mWindowBase->SetType(type);
135
136   // Initialize for Ime window type
137   if(type == WindowType::IME)
138   {
139     mWindowBase->InitializeIme();
140     mWindowSurface->InitializeImeSurface();
141   }
142
143   // Connect signals
144   mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
145   mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
146   mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
147   mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
148   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
149   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
150   mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
151   mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
152
153   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
154
155   AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
156
157   SetClass(name, className);
158
159   mOrientation = Orientation::New(this);
160
161   // Get OrientationMode
162   int screenWidth, screenHeight;
163   WindowSystem::GetScreenSize(screenWidth, screenHeight);
164   if(screenWidth > screenHeight)
165   {
166     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
167   }
168   else
169   {
170     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
171   }
172   // For Debugging
173   mNativeWindowId = mWindowBase->GetNativeWindowId();
174 }
175
176 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
177 {
178   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
179   mEventHandler->AddObserver(*this);
180
181   // Add Window to bridge for ATSPI
182   auto bridge = Accessibility::Bridge::GetCurrentBridge();
183   if (bridge->IsUp())
184   {
185     auto rootLayer  = mScene.GetRootLayer();
186     auto accessible = Accessibility::Accessible::Get(rootLayer, true);
187     bridge->AddTopLevelWindow(accessible);
188   }
189
190   bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
191   bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
192
193   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
194   // The show must be called after the adaptor is initialized.
195   Show();
196 }
197
198 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
199 {
200   mWindowSurface = static_cast<WindowRenderSurface*>(surface);
201 }
202
203 void Window::SetClass(std::string name, std::string className)
204 {
205   mName      = name;
206   mClassName = className;
207   mWindowBase->SetClass(name, className);
208 }
209
210 std::string Window::GetClassName() const
211 {
212   return mClassName;
213 }
214
215 void Window::Raise()
216 {
217   mWindowBase->Raise();
218
219   mSurface->SetFullSwapNextFrame();
220
221   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
222 }
223
224 void Window::Lower()
225 {
226   mWindowBase->Lower();
227
228   mSurface->SetFullSwapNextFrame();
229
230   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
231 }
232
233 void Window::Activate()
234 {
235   mWindowBase->Activate();
236
237   mSurface->SetFullSwapNextFrame();
238
239   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
240 }
241
242 void Window::Maximize(bool maximize)
243 {
244   mWindowBase->Maximize(maximize);
245
246   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
247 }
248
249 bool Window::IsMaximized() const
250 {
251   return mWindowBase->IsMaximized();
252 }
253
254 void Window::Minimize(bool minimize)
255 {
256   mWindowBase->Minimize(minimize);
257
258   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
259 }
260
261 bool Window::IsMinimized() const
262 {
263   return mWindowBase->IsMinimized();
264 }
265
266 uint32_t Window::GetLayerCount() const
267 {
268   return mScene.GetLayerCount();
269 }
270
271 Dali::Layer Window::GetLayer(uint32_t depth) const
272 {
273   return mScene.GetLayer(depth);
274 }
275
276 Dali::RenderTaskList Window::GetRenderTaskList() const
277 {
278   return mScene.GetRenderTaskList();
279 }
280
281 std::string Window::GetNativeResourceId() const
282 {
283   return mWindowBase->GetNativeWindowResourceId();
284 }
285
286 void Window::AddAvailableOrientation(WindowOrientation orientation)
287 {
288   if(IsOrientationAvailable(orientation) == false)
289   {
290     return;
291   }
292
293   bool found          = false;
294   int  convertedAngle = ConvertToAngle(orientation);
295   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
296   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
297   {
298     if(mAvailableAngles[i] == convertedAngle)
299     {
300       found = true;
301       break;
302     }
303   }
304
305   if(!found)
306   {
307     mAvailableAngles.push_back(convertedAngle);
308     SetAvailableAnlges(mAvailableAngles);
309   }
310 }
311
312 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
313 {
314   if(IsOrientationAvailable(orientation) == false)
315   {
316     return;
317   }
318
319   int convertedAngle = ConvertToAngle(orientation);
320   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
321   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
322       iter != mAvailableAngles.end();
323       ++iter)
324   {
325     if(*iter == convertedAngle)
326     {
327       mAvailableAngles.erase(iter);
328       break;
329     }
330   }
331
332   SetAvailableAnlges(mAvailableAngles);
333 }
334
335 void Window::SetPreferredOrientation(WindowOrientation orientation)
336 {
337   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
338   {
339     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
340     return;
341   }
342   mPreferredAngle = ConvertToAngle(orientation);
343   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
344   mWindowBase->SetPreferredAngle(mPreferredAngle);
345 }
346
347 WindowOrientation Window::GetPreferredOrientation()
348 {
349   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
350   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
351   return preferredOrientation;
352 }
353
354 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
355 {
356   int angle = ConvertToAngle(orientation);
357   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
358 }
359
360 void Window::EmitAccessibilityHighlightSignal(bool highlight)
361 {
362   Dali::Window handle(this);
363   mAccessibilityHighlightSignal.Emit(handle, highlight);
364 }
365
366 void Window::SetAvailableAnlges(const std::vector<int>& angles)
367 {
368   if(angles.size() > 4)
369   {
370     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
371     return;
372   }
373
374   mWindowBase->SetAvailableAnlges(angles);
375 }
376
377 int Window::ConvertToAngle(WindowOrientation orientation)
378 {
379   int convertAngle = static_cast<int>(orientation);
380   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
381   {
382     switch(orientation)
383     {
384       case WindowOrientation::LANDSCAPE:
385       {
386         convertAngle = 0;
387         break;
388       }
389       case WindowOrientation::PORTRAIT:
390       {
391         convertAngle = 90;
392         break;
393       }
394       case WindowOrientation::LANDSCAPE_INVERSE:
395       {
396         convertAngle = 180;
397         break;
398       }
399       case WindowOrientation::PORTRAIT_INVERSE:
400       {
401         convertAngle = 270;
402         break;
403       }
404       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
405       {
406         convertAngle = -1;
407         break;
408       }
409     }
410   }
411   return convertAngle;
412 }
413
414 WindowOrientation Window::ConvertToOrientation(int angle) const
415 {
416   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
417   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
418   {
419     switch(angle)
420     {
421       case 0:
422       {
423         orientation = WindowOrientation::LANDSCAPE;
424         break;
425       }
426       case 90:
427       {
428         orientation = WindowOrientation::PORTRAIT;
429         break;
430       }
431       case 180:
432       {
433         orientation = WindowOrientation::LANDSCAPE_INVERSE;
434         break;
435       }
436       case 270:
437       {
438         orientation = WindowOrientation::PORTRAIT_INVERSE;
439         break;
440       }
441       case -1:
442       {
443         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
444         break;
445       }
446     }
447   }
448   return orientation;
449 }
450
451 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
452 {
453   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
454   {
455     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
456     return false;
457   }
458   return true;
459 }
460
461 Dali::Any Window::GetNativeHandle() const
462 {
463   return mWindowSurface->GetNativeWindow();
464 }
465
466 void Window::SetAcceptFocus(bool accept)
467 {
468   mIsFocusAcceptable = accept;
469
470   mWindowBase->SetAcceptFocus(accept);
471 }
472
473 bool Window::IsFocusAcceptable() const
474 {
475   return mIsFocusAcceptable;
476 }
477
478 void Window::Show()
479 {
480   mVisible = true;
481
482   mWindowBase->Show();
483
484   if(!mIconified)
485   {
486     Dali::Window handle(this);
487     mVisibilityChangedSignal.Emit(handle, true);
488     Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
489
490     WindowVisibilityObserver* observer(mAdaptor);
491     observer->OnWindowShown();
492   }
493
494   mSurface->SetFullSwapNextFrame();
495
496   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
497 }
498
499 void Window::Hide()
500 {
501   mVisible = false;
502
503   mWindowBase->Hide();
504
505   if(!mIconified)
506   {
507     Dali::Window handle(this);
508     mVisibilityChangedSignal.Emit(handle, false);
509     Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
510
511     WindowVisibilityObserver* observer(mAdaptor);
512     observer->OnWindowHidden();
513   }
514
515   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
516 }
517
518 bool Window::IsVisible() const
519 {
520   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
521   return mVisible && !mIconified;
522 }
523
524 unsigned int Window::GetSupportedAuxiliaryHintCount() const
525 {
526   return mWindowBase->GetSupportedAuxiliaryHintCount();
527 }
528
529 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
530 {
531   return mWindowBase->GetSupportedAuxiliaryHint(index);
532 }
533
534 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
535 {
536   return mWindowBase->AddAuxiliaryHint(hint, value);
537 }
538
539 bool Window::RemoveAuxiliaryHint(unsigned int id)
540 {
541   return mWindowBase->RemoveAuxiliaryHint(id);
542 }
543
544 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
545 {
546   return mWindowBase->SetAuxiliaryHintValue(id, value);
547 }
548
549 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
550 {
551   return mWindowBase->GetAuxiliaryHintValue(id);
552 }
553
554 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
555 {
556   return mWindowBase->GetAuxiliaryHintId(hint);
557 }
558
559 void Window::SetInputRegion(const Rect<int>& inputRegion)
560 {
561   Rect<int> convertRegion = RecalculateRect(inputRegion);
562
563   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window (%p), WinId (%d), SetInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
564
565   mWindowBase->SetInputRegion(convertRegion);
566 }
567
568 void Window::SetType(WindowType type)
569 {
570   mWindowBase->SetType(type);
571 }
572
573 WindowType Window::GetType() const
574 {
575   return mWindowBase->GetType();
576 }
577
578 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
579 {
580   WindowType type = mWindowBase->GetType();
581   if(type != WindowType::NOTIFICATION)
582   {
583     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
584     return WindowOperationResult::INVALID_OPERATION;
585   }
586
587   return mWindowBase->SetNotificationLevel(level);
588 }
589
590 WindowNotificationLevel Window::GetNotificationLevel() const
591 {
592   WindowType type = mWindowBase->GetType();
593   if(type != WindowType::NOTIFICATION)
594   {
595     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
596     return WindowNotificationLevel::NONE;
597   }
598
599   return mWindowBase->GetNotificationLevel();
600 }
601
602 void Window::SetOpaqueState(bool opaque)
603 {
604   mOpaqueState = opaque;
605
606   mWindowBase->SetOpaqueState(opaque);
607
608   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
609 }
610
611 bool Window::IsOpaqueState() const
612 {
613   return mOpaqueState;
614 }
615
616 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
617 {
618   return mWindowBase->SetScreenOffMode(screenOffMode);
619 }
620
621 WindowScreenOffMode Window::GetScreenOffMode() const
622 {
623   return mWindowBase->GetScreenOffMode();
624 }
625
626 WindowOperationResult Window::SetBrightness(int brightness)
627 {
628   if(brightness < 0 || brightness > 100)
629   {
630     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
631     return WindowOperationResult::INVALID_OPERATION;
632   }
633
634   return mWindowBase->SetBrightness(brightness);
635 }
636
637 int Window::GetBrightness() const
638 {
639   return mWindowBase->GetBrightness();
640 }
641
642 void Window::SetSize(Dali::Window::WindowSize size)
643 {
644   PositionSize oldRect = mSurface->GetPositionSize();
645
646   mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
647
648   PositionSize newRect = mSurface->GetPositionSize();
649
650   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
651   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
652   {
653     Uint16Pair newSize(newRect.width, newRect.height);
654
655     SurfaceResized();
656
657     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
658
659     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
660
661     Dali::Window handle(this);
662     mResizeSignal.Emit(handle, newSize);
663
664     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
665   }
666
667   mSurface->SetFullSwapNextFrame();
668
669   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
670 }
671
672 Dali::Window::WindowSize Window::GetSize() const
673 {
674   PositionSize positionSize = mSurface->GetPositionSize();
675
676   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
677 }
678
679 void Window::SetPosition(Dali::Window::WindowPosition position)
680 {
681   PositionSize oldRect = mSurface->GetPositionSize();
682
683   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
684
685   mSurface->SetFullSwapNextFrame();
686
687   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
688 }
689
690 Dali::Window::WindowPosition Window::GetPosition() const
691 {
692   PositionSize positionSize = mSurface->GetPositionSize();
693
694   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
695 }
696
697 PositionSize Window::GetPositionSize() const
698 {
699   return mSurface->GetPositionSize();
700 }
701
702 void Window::SetPositionSize(PositionSize positionSize)
703 {
704   PositionSize oldRect = mSurface->GetPositionSize();
705
706   mWindowSurface->MoveResize(positionSize);
707
708   PositionSize newRect = mSurface->GetPositionSize();
709
710   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
711   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
712   {
713     Uint16Pair newSize(newRect.width, newRect.height);
714
715     SurfaceResized();
716
717     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
718
719     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
720     Dali::Window handle(this);
721     mResizeSignal.Emit(handle, newSize);
722     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
723   }
724
725   mSurface->SetFullSwapNextFrame();
726
727   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
728 }
729
730 Dali::Layer Window::GetRootLayer() const
731 {
732   return mScene.GetRootLayer();
733 }
734
735 void Window::SetTransparency(bool transparent)
736 {
737   mWindowSurface->SetTransparency(transparent);
738 }
739
740 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
741 {
742   return mWindowBase->GrabKey(key, grabMode);
743 }
744
745 bool Window::UngrabKey(Dali::KEY key)
746 {
747   return mWindowBase->UngrabKey(key);
748 }
749
750 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
751 {
752   return mWindowBase->GrabKeyList(key, grabMode, result);
753 }
754
755 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
756 {
757   return mWindowBase->UngrabKeyList(key, result);
758 }
759
760 void Window::OnIconifyChanged(bool iconified)
761 {
762   if(iconified)
763   {
764     mIconified = true;
765
766     if(mVisible)
767     {
768       Dali::Window handle(this);
769       mVisibilityChangedSignal.Emit(handle, false);
770       Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
771
772       WindowVisibilityObserver* observer(mAdaptor);
773       observer->OnWindowHidden();
774     }
775
776     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
777   }
778   else
779   {
780     mIconified = false;
781
782     if(mVisible)
783     {
784       Dali::Window handle(this);
785       mVisibilityChangedSignal.Emit(handle, true);
786       Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
787
788       WindowVisibilityObserver* observer(mAdaptor);
789       observer->OnWindowShown();
790     }
791
792     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
793   }
794
795   mSurface->SetFullSwapNextFrame();
796 }
797
798 void Window::OnFocusChanged(bool focusIn)
799 {
800   Dali::Window handle(this);
801   mFocusChangeSignal.Emit(handle, focusIn);
802
803   mSurface->SetFullSwapNextFrame();
804
805   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
806   {
807     if(focusIn)
808     {
809       bridge->WindowFocused(handle);
810     }
811     else
812     {
813       bridge->WindowUnfocused(handle);
814     }
815   }
816   mFocused = focusIn;
817 }
818
819 void Window::OnOutputTransformed()
820 {
821   PositionSize positionSize = mSurface->GetPositionSize();
822
823   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
824   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
825
826   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
827   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
828 }
829
830 void Window::OnDeleteRequest()
831 {
832   mDeleteRequestSignal.Emit();
833 }
834
835 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
836 {
837   Dali::Window handle(this);
838   mTransitionEffectEventSignal.Emit(handle, state, type);
839 }
840
841 void Window::OnKeyboardRepeatSettingsChanged()
842 {
843   Dali::Window handle(this);
844   mKeyboardRepeatSettingsChangedSignal.Emit();
845 }
846
847 void Window::OnWindowRedrawRequest()
848 {
849   mAdaptor->RenderOnce();
850 }
851
852 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
853 {
854   PositionSize oldRect = mSurface->GetPositionSize();
855
856   mWindowSurface->UpdatePositionSize(positionSize);
857
858   PositionSize newRect = positionSize;
859
860   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
861   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
862   {
863     Uint16Pair newSize(newRect.width, newRect.height);
864
865     SurfaceResized();
866
867     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
868
869     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
870     Dali::Window handle(this);
871     mResizeSignal.Emit(handle, newSize);
872     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
873   }
874
875   mSurface->SetFullSwapNextFrame();
876
877   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
878 }
879
880 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
881 {
882   FeedTouchPoint(point, timeStamp);
883 }
884
885 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
886 {
887   FeedWheelEvent(wheelEvent);
888 }
889
890 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
891 {
892   FeedKeyEvent(keyEvent);
893 }
894
895 void Window::OnRotation(const RotationEvent& rotation)
896 {
897   mRotationAngle = rotation.angle;
898   mWindowWidth   = rotation.width;
899   mWindowHeight  = rotation.height;
900
901   // Notify that the orientation is changed
902   mOrientation->OnOrientationChange(rotation);
903
904   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
905
906   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
907   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
908
909   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
910
911   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
912   // Emit signal
913   Dali::Window handle(this);
914   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
915
916   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
917 }
918
919 void Window::OnPause()
920 {
921   if(mEventHandler)
922   {
923     mEventHandler->Pause();
924   }
925 }
926
927 void Window::OnResume()
928 {
929   if(mEventHandler)
930   {
931     mEventHandler->Resume();
932   }
933
934   mSurface->SetFullSwapNextFrame();
935 }
936
937 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
938 {
939   mAuxiliaryMessageSignal.Emit(key, value, options);
940 }
941
942 void Window::OnAccessibilityEnabled()
943 {
944   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
945   auto rootLayer  = mScene.GetRootLayer();
946   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
947   bridge->AddTopLevelWindow(accessible);
948
949   if(mFocused)
950   {
951     Dali::Window handle(this);
952     bridge->WindowFocused(handle);
953   }
954 }
955
956 void Window::OnAccessibilityDisabled()
957 {
958   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
959   auto rootLayer  = mScene.GetRootLayer();
960   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
961   bridge->RemoveTopLevelWindow(accessible);
962 }
963
964 void Window::RecalculateTouchPosition(Integration::Point& point)
965 {
966   Vector2 position = point.GetScreenPosition();
967   Vector2 convertedPosition;
968
969   switch(mRotationAngle)
970   {
971     case 90:
972     {
973       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
974       convertedPosition.y = position.x;
975       break;
976     }
977     case 180:
978     {
979       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
980       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
981       break;
982     }
983     case 270:
984     {
985       convertedPosition.x = position.y;
986       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
987       break;
988     }
989     default:
990     {
991       convertedPosition = position;
992       break;
993     }
994   }
995
996   point.SetScreenPosition(convertedPosition);
997 }
998
999 Dali::Window Window::Get(Dali::Actor actor)
1000 {
1001   Internal::Adaptor::Window* windowImpl = nullptr;
1002
1003   if(Internal::Adaptor::Adaptor::IsAvailable())
1004   {
1005     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1006     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1007     if(windowImpl)
1008     {
1009       return Dali::Window(windowImpl);
1010     }
1011   }
1012
1013   return Dali::Window();
1014 }
1015
1016 void Window::SetParent(Dali::Window& parent)
1017 {
1018   if(DALI_UNLIKELY(parent))
1019   {
1020     mParentWindow     = parent;
1021     Dali::Window self = Dali::Window(this);
1022     // check circular parent window setting
1023     if(Dali::DevelWindow::GetParent(parent) == self)
1024     {
1025       Dali::DevelWindow::Unparent(parent);
1026     }
1027     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1028   }
1029 }
1030
1031 void Window::SetParent(Dali::Window& parent, bool belowParent)
1032 {
1033   if(DALI_UNLIKELY(parent))
1034   {
1035     mParentWindow     = parent;
1036     Dali::Window self = Dali::Window(this);
1037     // check circular parent window setting
1038     if(Dali::DevelWindow::GetParent(parent) == self)
1039     {
1040       Dali::DevelWindow::Unparent(parent);
1041     }
1042     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1043   }
1044 }
1045
1046 void Window::Unparent()
1047 {
1048   mWindowBase->SetParent(nullptr, false);
1049   mParentWindow.Reset();
1050 }
1051
1052 Dali::Window Window::GetParent()
1053 {
1054   return mParentWindow;
1055 }
1056
1057 WindowOrientation Window::GetCurrentOrientation() const
1058 {
1059   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1060   return ConvertToOrientation(mRotationAngle);
1061 }
1062
1063 int Window::GetPhysicalOrientation() const
1064 {
1065   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1066 }
1067
1068 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1069 {
1070   Dali::Vector<float>::SizeType count = orientations.Count();
1071   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1072   {
1073     if(IsOrientationAvailable(orientations[index]) == false)
1074     {
1075       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1076       continue;
1077     }
1078
1079     bool found          = false;
1080     int  convertedAngle = ConvertToAngle(orientations[index]);
1081
1082     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1083     {
1084       if(mAvailableAngles[i] == convertedAngle)
1085       {
1086         found = true;
1087         break;
1088       }
1089     }
1090
1091     if(!found)
1092     {
1093       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1094       mAvailableAngles.push_back(convertedAngle);
1095     }
1096   }
1097   SetAvailableAnlges(mAvailableAngles);
1098 }
1099
1100 int32_t Window::GetNativeId() const
1101 {
1102   return mWindowBase->GetNativeWindowId();
1103 }
1104
1105 void Window::RequestMoveToServer()
1106 {
1107   mWindowBase->RequestMoveToServer();
1108 }
1109
1110 void Window::RequestResizeToServer(WindowResizeDirection direction)
1111 {
1112   mWindowBase->RequestResizeToServer(direction);
1113 }
1114
1115 void Window::EnableFloatingMode(bool enable)
1116 {
1117   mWindowBase->EnableFloatingMode(enable);
1118 }
1119
1120 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1121 {
1122   Rect<int> newRect;
1123   int screenWidth, screenHeight;
1124
1125   WindowSystem::GetScreenSize(screenWidth, screenHeight);
1126
1127   if(mRotationAngle == 90)
1128   {
1129     newRect.x      = rect.y;
1130     newRect.y      = screenHeight - (rect.x + rect.width);
1131     newRect.width  = rect.height;
1132     newRect.height = rect.width;
1133   }
1134   else if(mRotationAngle == 180)
1135   {
1136     newRect.x      = screenWidth - (rect.x + rect.width);
1137     newRect.y      = screenHeight - (rect.y + rect.height);
1138     newRect.width  = rect.width;
1139     newRect.height = rect.height;
1140   }
1141   else if(mRotationAngle == 270)
1142   {
1143     newRect.x      = screenWidth - (rect.y + rect.height);
1144     newRect.y      = rect.x;
1145     newRect.width  = rect.height;
1146     newRect.height = rect.width;
1147   }
1148   else
1149   {
1150     newRect.x      = rect.x;
1151     newRect.y      = rect.y;
1152     newRect.width  = rect.width;
1153     newRect.height = rect.height;
1154   }
1155   return newRect;
1156 }
1157
1158 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1159 {
1160   Rect<int> convertRegion = RecalculateRect(inputRegion);
1161
1162   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1163   mWindowBase->IncludeInputRegion(convertRegion);
1164 }
1165
1166 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1167 {
1168   Rect<int> convertRegion = RecalculateRect(inputRegion);
1169
1170   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1171   mWindowBase->ExcludeInputRegion(convertRegion);
1172 }
1173
1174 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1175 {
1176   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1177   mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1178   mWindowRotationAcknowledgement = needAcknowledgement;
1179 }
1180
1181 void Window::SendRotationCompletedAcknowledgement()
1182 {
1183   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1184   if(mWindowRotationAcknowledgement)
1185   {
1186     SetRotationCompletedAcknowledgement();
1187   }
1188 }
1189
1190 } // namespace Adaptor
1191
1192 } // namespace Internal
1193
1194 } // namespace Dali