[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2020 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 <thread>
23 #include <dali/integration-api/core.h>
24 #include <dali/public-api/actors/actor.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/render-tasks/render-task.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <dali/public-api/rendering/frame-buffer.h>
30 #include <dali/public-api/adaptor-framework/window-enumerations.h>
31 #include <dali/devel-api/adaptor-framework/orientation.h>
32 #include <dali/integration-api/events/touch-event-integ.h>
33
34 // INTERNAL HEADERS
35 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
36 #include <dali/internal/graphics/gles/egl-graphics.h>
37 #include <dali/internal/window-system/common/event-handler.h>
38 #include <dali/internal/window-system/common/orientation-impl.h>
39 #include <dali/internal/window-system/common/render-surface-factory.h>
40 #include <dali/internal/window-system/common/window-factory.h>
41 #include <dali/internal/window-system/common/window-base.h>
42 #include <dali/internal/window-system/common/window-system.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
44 #include <dali/internal/window-system/common/window-visibility-observer.h>
45 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
46
47 namespace Dali
48 {
49 namespace Internal
50 {
51 namespace Adaptor
52 {
53
54 namespace
55 {
56
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
59 #endif
60
61 } // unnamed namespace
62
63 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
64 {
65   Any surface;
66   return Window::New(surface, positionSize, name, className, isTransparent);
67 }
68
69 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
70 {
71   Window* window = new Window();
72   window->mIsTransparent = isTransparent;
73   window->Initialize(surface, positionSize, name, className);
74   return window;
75 }
76
77 Window::Window()
78 : mWindowSurface( nullptr ),
79   mWindowBase(),
80   mIsTransparent( false ),
81   mIsFocusAcceptable( true ),
82   mIconified( false ),
83   mOpaqueState( false ),
84   mResizeEnabled( false ),
85   mType( WindowType::NORMAL ),
86   mParentWindow( NULL ),
87   mPreferredAngle( static_cast< int >( WindowOrientation::NO_ORIENTATION_PREFERENCE ) ),
88   mRotationAngle( -1 ),
89   mWindowWidth( 0 ),
90   mWindowHeight( 0 ),
91   mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
92   mNativeWindowId( -1 ),
93   mDeleteRequestSignal(),
94   mFocusChangeSignal(),
95   mResizeSignal(),
96   mVisibilityChangedSignal(),
97   mTransitionEffectEventSignal(),
98   mKeyboardRepeatSettingsChangedSignal()
99 {
100 }
101
102 Window::~Window()
103 {
104   if ( mAdaptor )
105   {
106     auto bridge = Accessibility::Bridge::GetCurrentBridge();
107     auto accessible2 = mScene.GetRootLayer();
108     auto accessible = Accessibility::Accessible::Get( accessible2 );
109     bridge->RemoveTopLevelWindow( accessible );
110
111     mAdaptor->RemoveWindow( this );
112   }
113
114   if ( mEventHandler )
115   {
116     mEventHandler->RemoveObserver( *this );
117   }
118 }
119
120 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
121 {
122   // Create a window render surface
123   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
124   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
125   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
126
127   // Get a window base
128   mWindowBase = mWindowSurface->GetWindowBase();
129
130   // Connect signals
131   mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
132   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
133   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
134   mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
135   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect( this, &Window::OnKeyboardRepeatSettingsChanged );
136   mWindowBase->WindowRedrawRequestSignal().Connect( this, &Window::OnWindowRedrawRequest );
137
138   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
139
140   if( !positionSize.IsEmpty() )
141   {
142     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
143     mResizeEnabled = true;
144   }
145
146   SetClass( name, className );
147
148   mWindowSurface->Map();
149
150   mOrientation = Orientation::New( this );
151
152   // Get OrientationMode
153   int screenWidth, screenHeight;
154   WindowSystem::GetScreenSize( screenWidth, screenHeight );
155   if( screenWidth > screenHeight )
156   {
157     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
158   }
159   else
160   {
161     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
162   }
163   // For Debugging
164   mNativeWindowId = mWindowBase->GetNativeWindowId();
165 }
166
167 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
168 {
169   mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface->GetWindowBase(), *mAdaptor ) );
170   mEventHandler->AddObserver( *this );
171
172   auto bridge = Accessibility::Bridge::GetCurrentBridge();
173   auto v = mScene.GetRootLayer();
174   auto accessible = Accessibility::Accessible::Get( v, true );
175   bridge->AddTopLevelWindow( accessible );
176
177   //FIXME: line below is temporary solution for missing "activate" signal and should be removed
178   Show();
179 }
180
181 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
182 {
183   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
184 }
185
186 void Window::SetClass( std::string name, std::string className )
187 {
188   mName = name;
189   mClassName = className;
190   mWindowBase->SetClass( name, className );
191 }
192
193 std::string Window::GetClassName() const
194 {
195   return mClassName;
196 }
197
198 void Window::Raise()
199 {
200   mWindowBase->Raise();
201
202   mSurface->SetFullSwapNextFrame();
203
204   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId );
205 }
206
207 void Window::Lower()
208 {
209   mWindowBase->Lower();
210
211   mSurface->SetFullSwapNextFrame();
212
213   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId );
214 }
215
216 void Window::Activate()
217 {
218   mWindowBase->Activate();
219
220   mSurface->SetFullSwapNextFrame();
221
222   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId );
223 }
224
225 uint32_t Window::GetLayerCount() const
226 {
227   return mScene.GetLayerCount();
228 }
229
230 Dali::Layer Window::GetLayer( uint32_t depth ) const
231 {
232   return mScene.GetLayer( depth );
233 }
234
235 Dali::RenderTaskList Window::GetRenderTaskList() const
236 {
237   return mScene.GetRenderTaskList();
238 }
239
240 void Window::AddAvailableOrientation( WindowOrientation orientation )
241 {
242   if( IsOrientationAvailable( orientation ) == false )
243   {
244     return;
245   }
246
247   bool found = false;
248   int convertedAngle = ConvertToAngle( orientation );
249   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
250   for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
251   {
252     if( mAvailableAngles[i] == convertedAngle )
253     {
254       found = true;
255       break;
256     }
257   }
258
259   if( !found )
260   {
261     mAvailableAngles.push_back( convertedAngle );
262     SetAvailableAnlges( mAvailableAngles );
263   }
264 }
265
266 void Window::RemoveAvailableOrientation( WindowOrientation orientation )
267 {
268   if( IsOrientationAvailable( orientation ) == false )
269   {
270     return;
271   }
272
273   int convertedAngle = ConvertToAngle( orientation );
274   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
275   for( std::vector< int >::iterator iter = mAvailableAngles.begin();
276        iter != mAvailableAngles.end(); ++iter )
277   {
278     if( *iter == convertedAngle )
279     {
280       mAvailableAngles.erase( iter );
281       break;
282     }
283   }
284
285   SetAvailableAnlges( mAvailableAngles );
286 }
287
288 void Window::SetPreferredOrientation( WindowOrientation orientation )
289 {
290   if( orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE )
291   {
292     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation );
293     return;
294   }
295   mPreferredAngle = ConvertToAngle( orientation );
296   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
297   mWindowBase->SetPreferredAngle( mPreferredAngle );
298 }
299
300 WindowOrientation Window::GetPreferredOrientation()
301 {
302   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
303   WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
304   return preferredOrientation;
305 }
306
307 void Window::SetAvailableAnlges( const std::vector< int >& angles )
308 {
309   if( angles.size() > 4 )
310   {
311     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
312     return;
313   }
314
315   mWindowBase->SetAvailableAnlges( angles );
316 }
317
318 int Window::ConvertToAngle( WindowOrientation orientation )
319 {
320   int convertAngle = static_cast< int >( orientation );
321   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
322   {
323     switch( orientation )
324     {
325       case WindowOrientation::LANDSCAPE:
326       {
327         convertAngle = 0;
328         break;
329       }
330       case WindowOrientation::PORTRAIT:
331       {
332         convertAngle = 90;
333         break;
334       }
335       case WindowOrientation::LANDSCAPE_INVERSE:
336       {
337         convertAngle = 180;
338         break;
339       }
340       case WindowOrientation::PORTRAIT_INVERSE:
341       {
342         convertAngle = 270;
343         break;
344       }
345       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
346       {
347         convertAngle = -1;
348         break;
349       }
350     }
351   }
352   return convertAngle;
353 }
354
355 WindowOrientation Window::ConvertToOrientation( int angle ) const
356 {
357   WindowOrientation orientation = static_cast< WindowOrientation >( angle );
358   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
359   {
360     switch( angle )
361     {
362       case 0:
363       {
364         orientation = WindowOrientation::LANDSCAPE;
365         break;
366       }
367       case 90:
368       {
369         orientation = WindowOrientation::PORTRAIT;
370         break;
371       }
372       case 180:
373       {
374         orientation = WindowOrientation::LANDSCAPE_INVERSE;
375         break;
376       }
377       case 270:
378       {
379         orientation = WindowOrientation::PORTRAIT_INVERSE;
380         break;
381       }
382       case -1:
383       {
384         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
385         break;
386       }
387     }
388   }
389   return orientation;
390 }
391
392 bool Window::IsOrientationAvailable( WindowOrientation orientation ) const
393 {
394   if( orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE )
395   {
396     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
397     return false;
398   }
399   return true;
400 }
401
402 Dali::Any Window::GetNativeHandle() const
403 {
404   return mWindowSurface->GetNativeWindow();
405 }
406
407 void Window::SetAcceptFocus( bool accept )
408 {
409   mIsFocusAcceptable = accept;
410
411   mWindowBase->SetAcceptFocus( accept );
412 }
413
414 bool Window::IsFocusAcceptable() const
415 {
416   return mIsFocusAcceptable;
417 }
418
419 void Window::Show()
420 {
421   mVisible = true;
422
423   mWindowBase->Show();
424
425   if( !mIconified )
426   {
427     WindowVisibilityObserver* observer( mAdaptor );
428     observer->OnWindowShown();
429
430     Dali::Window handle( this );
431     mVisibilityChangedSignal.Emit( handle, true );
432   }
433
434   mSurface->SetFullSwapNextFrame();
435
436   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
437 }
438
439 void Window::Hide()
440 {
441   mVisible = false;
442
443   mWindowBase->Hide();
444
445   if( !mIconified )
446   {
447     WindowVisibilityObserver* observer( mAdaptor );
448     observer->OnWindowHidden();
449
450     Dali::Window handle( this );
451     mVisibilityChangedSignal.Emit( handle, false );
452   }
453
454   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
455 }
456
457 bool Window::IsVisible() const
458 {
459   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
460   return mVisible && !mIconified;
461 }
462
463 unsigned int Window::GetSupportedAuxiliaryHintCount() const
464 {
465   return mWindowBase->GetSupportedAuxiliaryHintCount();
466 }
467
468 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
469 {
470   return mWindowBase->GetSupportedAuxiliaryHint( index );
471 }
472
473 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
474 {
475   return mWindowBase->AddAuxiliaryHint( hint, value );
476 }
477
478 bool Window::RemoveAuxiliaryHint( unsigned int id )
479 {
480   return mWindowBase->RemoveAuxiliaryHint( id );
481 }
482
483 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
484 {
485   return mWindowBase->SetAuxiliaryHintValue( id, value );
486 }
487
488 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
489 {
490   return mWindowBase->GetAuxiliaryHintValue( id );
491 }
492
493 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
494 {
495   return mWindowBase->GetAuxiliaryHintId( hint );
496 }
497
498 void Window::SetInputRegion( const Rect< int >& inputRegion )
499 {
500   mWindowBase->SetInputRegion( inputRegion );
501
502   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
503 }
504
505 void Window::SetType( WindowType type )
506 {
507   if( type != mType )
508   {
509     mWindowBase->SetType( type );
510
511     mType = type;
512   }
513 }
514
515 WindowType Window::GetType() const
516 {
517   return mType;
518 }
519
520 bool Window::SetNotificationLevel( WindowNotificationLevel level )
521 {
522   if( mType != WindowType::NOTIFICATION )
523   {
524     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
525     return false;
526   }
527
528   return mWindowBase->SetNotificationLevel( level );
529 }
530
531 WindowNotificationLevel Window::GetNotificationLevel() const
532 {
533   if( mType != WindowType::NOTIFICATION )
534   {
535     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
536     return WindowNotificationLevel::NONE;
537   }
538
539   return mWindowBase->GetNotificationLevel();
540 }
541
542 void Window::SetOpaqueState( bool opaque )
543 {
544   mOpaqueState = opaque;
545
546   mWindowBase->SetOpaqueState( opaque );
547
548   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
549 }
550
551 bool Window::IsOpaqueState() const
552 {
553   return mOpaqueState;
554 }
555
556 bool Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
557 {
558   return mWindowBase->SetScreenOffMode( screenOffMode );
559 }
560
561 WindowScreenOffMode Window::GetScreenOffMode() const
562 {
563   return mWindowBase->GetScreenOffMode();
564 }
565
566 bool Window::SetBrightness( int brightness )
567 {
568   if( brightness < 0 || brightness > 100 )
569   {
570     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
571     return false;
572   }
573
574   return mWindowBase->SetBrightness( brightness );
575 }
576
577 int Window::GetBrightness() const
578 {
579   return mWindowBase->GetBrightness();
580 }
581
582 void Window::SetSize( Dali::Window::WindowSize size )
583 {
584   if( !mResizeEnabled )
585   {
586     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
587     mResizeEnabled = true;
588   }
589
590   PositionSize oldRect = mSurface->GetPositionSize();
591
592   mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
593
594   PositionSize newRect = mSurface->GetPositionSize();
595
596   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
597   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
598   {
599     Uint16Pair newSize( newRect.width, newRect.height );
600
601     bool forceUpdate = false;
602     if( mWindowBase->IsEglWindowRotationSupported() )
603     {
604       forceUpdate = true;
605     }
606
607     SurfaceResized( forceUpdate );
608
609     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
610
611     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
612
613     Dali::Window handle( this );
614     mResizeSignal.Emit( handle, newSize );
615
616     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
617   }
618
619   mSurface->SetFullSwapNextFrame();
620 }
621
622 Dali::Window::WindowSize Window::GetSize() const
623 {
624   PositionSize positionSize = mSurface->GetPositionSize();
625
626   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
627 }
628
629 void Window::SetPosition( Dali::Window::WindowPosition position )
630 {
631   if( !mResizeEnabled )
632   {
633     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
634     mResizeEnabled = true;
635   }
636
637   PositionSize oldRect = mSurface->GetPositionSize();
638
639   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
640
641   mSurface->SetFullSwapNextFrame();
642 }
643
644 Dali::Window::WindowPosition Window::GetPosition() const
645 {
646   PositionSize positionSize = mSurface->GetPositionSize();
647
648   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
649 }
650
651 void Window::SetPositionSize( PositionSize positionSize )
652 {
653   if( !mResizeEnabled )
654   {
655     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
656     mResizeEnabled = true;
657   }
658
659   PositionSize oldRect = mSurface->GetPositionSize();
660
661   mWindowSurface->MoveResize( positionSize );
662
663   PositionSize newRect = mSurface->GetPositionSize();
664
665   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
666   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
667   {
668     Uint16Pair newSize( newRect.width, newRect.height );
669
670     bool forceUpdate = false;
671     if( mWindowBase->IsEglWindowRotationSupported() )
672     {
673       forceUpdate = true;
674     }
675
676     SurfaceResized( forceUpdate );
677
678     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
679
680     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
681     Dali::Window handle( this );
682     mResizeSignal.Emit( handle, newSize );
683     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
684   }
685
686   mSurface->SetFullSwapNextFrame();
687 }
688
689 Dali::Layer Window::GetRootLayer() const
690 {
691   return mScene.GetRootLayer();
692 }
693
694 void Window::SetTransparency( bool transparent )
695 {
696   mWindowSurface->SetTransparency( transparent );
697 }
698
699 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
700 {
701   return mWindowBase->GrabKey( key, grabMode );
702 }
703
704 bool Window::UngrabKey( Dali::KEY key )
705 {
706   return mWindowBase->UngrabKey( key );
707 }
708
709 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
710 {
711   return mWindowBase->GrabKeyList( key, grabMode, result );
712 }
713
714 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
715 {
716   return mWindowBase->UngrabKeyList( key, result );
717 }
718
719 void Window::OnIconifyChanged( bool iconified )
720 {
721   if( iconified )
722   {
723     mIconified = true;
724
725     if( mVisible )
726     {
727       WindowVisibilityObserver* observer( mAdaptor );
728       observer->OnWindowHidden();
729
730       Dali::Window handle( this );
731       mVisibilityChangedSignal.Emit( handle, false );
732     }
733
734     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
735   }
736   else
737   {
738     mIconified = false;
739
740     if( mVisible )
741     {
742       WindowVisibilityObserver* observer( mAdaptor );
743       observer->OnWindowShown();
744
745       Dali::Window handle( this );
746       mVisibilityChangedSignal.Emit( handle, true );
747     }
748
749     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
750   }
751
752   mSurface->SetFullSwapNextFrame();
753 }
754
755 void Window::OnFocusChanged( bool focusIn )
756 {
757   Dali::Window handle( this );
758   mFocusChangeSignal.Emit( handle, focusIn );
759
760   mSurface->SetFullSwapNextFrame();
761
762   if (auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
763   {
764     if (focusIn)
765     {
766       b->ApplicationShown();
767     }
768     else
769     {
770       b->ApplicationHidden();
771     }
772   }
773 }
774
775 void Window::OnOutputTransformed()
776 {
777   bool forceUpdate = false;
778   if( mWindowBase->IsEglWindowRotationSupported() )
779   {
780     forceUpdate = true;
781   }
782   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnOutputTransformed()\n", this, mNativeWindowId );
783   SurfaceResized( forceUpdate );
784
785   PositionSize positionSize = mSurface->GetPositionSize();
786   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
787   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
788 }
789
790 void Window::OnDeleteRequest()
791 {
792   mDeleteRequestSignal.Emit();
793 }
794
795 void Window::OnTransitionEffectEvent( WindowEffectState state, WindowEffectType type )
796 {
797   Dali::Window handle( this );
798   mTransitionEffectEventSignal.Emit( handle, state, type );
799 }
800
801 void Window::OnKeyboardRepeatSettingsChanged()
802 {
803   Dali::Window handle( this );
804   mKeyboardRepeatSettingsChangedSignal.Emit();
805 }
806
807 void Window::OnWindowRedrawRequest()
808 {
809   mAdaptor->RenderOnce();
810 }
811
812 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
813 {
814   FeedTouchPoint( point, timeStamp );
815 }
816
817 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
818 {
819   FeedWheelEvent( wheelEvent );
820 }
821
822 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
823 {
824   FeedKeyEvent( keyEvent );
825 }
826
827 void Window::OnRotation( const RotationEvent& rotation )
828 {
829   mRotationAngle = rotation.angle;
830   mWindowWidth = rotation.width;
831   mWindowHeight = rotation.height;
832
833   // Notify that the orientation is changed
834   mOrientation->OnOrientationChange( rotation );
835
836   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
837
838   bool forceUpdate = false;
839   if( mWindowBase->IsEglWindowRotationSupported() )
840   {
841     forceUpdate = true;
842   }
843
844   SurfaceResized( forceUpdate );
845
846   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
847
848   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
849   // Emit signal
850   Dali::Window handle( this );
851   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
852
853   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
854 }
855
856 void Window::OnPause()
857 {
858   if( mEventHandler )
859   {
860     mEventHandler->Pause();
861   }
862 }
863
864 void Window::OnResume()
865 {
866   if( mEventHandler )
867   {
868     mEventHandler->Resume();
869   }
870
871   mSurface->SetFullSwapNextFrame();
872 }
873
874 void Window::RecalculateTouchPosition( Integration::Point& point )
875 {
876   Vector2 position = point.GetScreenPosition();
877   Vector2 convertedPosition;
878
879   switch( mRotationAngle )
880   {
881     case 90:
882     {
883       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
884       convertedPosition.y = position.x;
885       break;
886     }
887     case 180:
888     {
889       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
890       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
891       break;
892     }
893     case 270:
894     {
895       convertedPosition.x = position.y;
896       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
897       break;
898     }
899     default:
900     {
901       convertedPosition = position;
902       break;
903     }
904   }
905
906   point.SetScreenPosition( convertedPosition );
907 }
908
909 Dali::Window Window::Get( Dali::Actor actor )
910 {
911   Internal::Adaptor::Window* windowImpl = nullptr;
912
913   if ( Internal::Adaptor::Adaptor::IsAvailable() )
914   {
915     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
916     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
917     if( windowImpl )
918     {
919       return Dali::Window( windowImpl );
920     }
921   }
922
923   return Dali::Window();
924 }
925
926 void Window::SetParent( Dali::Window& parent )
927 {
928   if ( DALI_UNLIKELY( parent ) )
929   {
930     mParentWindow = parent;
931     Dali::Window self = Dali::Window( this );
932     // check circular parent window setting
933     if ( Dali::DevelWindow::GetParent( parent ) == self )
934     {
935       Dali::DevelWindow::Unparent( parent );
936     }
937     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
938   }
939 }
940
941 void Window::Unparent()
942 {
943   mWindowBase->SetParent( nullptr );
944   mParentWindow.Reset();
945 }
946
947 Dali::Window Window::GetParent()
948 {
949   return mParentWindow;
950 }
951
952 WindowOrientation Window::GetCurrentOrientation() const
953 {
954   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
955   return ConvertToOrientation( mRotationAngle );
956 }
957
958 void Window::SetAvailableOrientations( const Dali::Vector<WindowOrientation>& orientations )
959 {
960   Dali::Vector<float>::SizeType count = orientations.Count();
961   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
962   {
963     if( IsOrientationAvailable( orientations[index] ) == false )
964     {
965       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
966       continue;
967     }
968
969     bool found = false;
970     int convertedAngle = ConvertToAngle( orientations[index] );
971
972     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
973     {
974       if( mAvailableAngles[i] == convertedAngle )
975       {
976         found = true;
977         break;
978       }
979     }
980
981     if( !found )
982     {
983       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
984       mAvailableAngles.push_back( convertedAngle );
985     }
986   }
987   SetAvailableAnlges( mAvailableAngles );
988 }
989
990 int32_t Window::GetNativeId() const
991 {
992   return mWindowBase->GetNativeWindowId();
993 }
994
995 } // Adaptor
996
997 } // Internal
998
999 } // Dali