Support screen and client rotation
[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( 0 ),
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     SurfaceResized();
602
603     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
604
605     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
606
607     Dali::Window handle( this );
608     mResizeSignal.Emit( handle, newSize );
609
610     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
611   }
612
613   mSurface->SetFullSwapNextFrame();
614 }
615
616 Dali::Window::WindowSize Window::GetSize() const
617 {
618   PositionSize positionSize = mSurface->GetPositionSize();
619
620   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
621 }
622
623 void Window::SetPosition( Dali::Window::WindowPosition position )
624 {
625   if( !mResizeEnabled )
626   {
627     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
628     mResizeEnabled = true;
629   }
630
631   PositionSize oldRect = mSurface->GetPositionSize();
632
633   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
634
635   mSurface->SetFullSwapNextFrame();
636 }
637
638 Dali::Window::WindowPosition Window::GetPosition() const
639 {
640   PositionSize positionSize = mSurface->GetPositionSize();
641
642   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
643 }
644
645 void Window::SetPositionSize( PositionSize positionSize )
646 {
647   if( !mResizeEnabled )
648   {
649     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
650     mResizeEnabled = true;
651   }
652
653   PositionSize oldRect = mSurface->GetPositionSize();
654
655   mWindowSurface->MoveResize( positionSize );
656
657   PositionSize newRect = mSurface->GetPositionSize();
658
659   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
660   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
661   {
662     Uint16Pair newSize( newRect.width, newRect.height );
663
664     SurfaceResized();
665
666     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
667
668     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
669     Dali::Window handle( this );
670     mResizeSignal.Emit( handle, newSize );
671     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
672   }
673
674   mSurface->SetFullSwapNextFrame();
675 }
676
677 Dali::Layer Window::GetRootLayer() const
678 {
679   return mScene.GetRootLayer();
680 }
681
682 void Window::SetTransparency( bool transparent )
683 {
684   mWindowSurface->SetTransparency( transparent );
685 }
686
687 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
688 {
689   return mWindowBase->GrabKey( key, grabMode );
690 }
691
692 bool Window::UngrabKey( Dali::KEY key )
693 {
694   return mWindowBase->UngrabKey( key );
695 }
696
697 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
698 {
699   return mWindowBase->GrabKeyList( key, grabMode, result );
700 }
701
702 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
703 {
704   return mWindowBase->UngrabKeyList( key, result );
705 }
706
707 void Window::OnIconifyChanged( bool iconified )
708 {
709   if( iconified )
710   {
711     mIconified = true;
712
713     if( mVisible )
714     {
715       WindowVisibilityObserver* observer( mAdaptor );
716       observer->OnWindowHidden();
717
718       Dali::Window handle( this );
719       mVisibilityChangedSignal.Emit( handle, false );
720     }
721
722     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
723   }
724   else
725   {
726     mIconified = false;
727
728     if( mVisible )
729     {
730       WindowVisibilityObserver* observer( mAdaptor );
731       observer->OnWindowShown();
732
733       Dali::Window handle( this );
734       mVisibilityChangedSignal.Emit( handle, true );
735     }
736
737     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
738   }
739
740   mSurface->SetFullSwapNextFrame();
741 }
742
743 void Window::OnFocusChanged( bool focusIn )
744 {
745   Dali::Window handle( this );
746   mFocusChangeSignal.Emit( handle, focusIn );
747
748   mSurface->SetFullSwapNextFrame();
749
750   if (auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
751   {
752     if (focusIn)
753     {
754       b->ApplicationShown();
755     }
756     else
757     {
758       b->ApplicationHidden();
759     }
760   }
761 }
762
763 void Window::OnOutputTransformed()
764 {
765   PositionSize positionSize = mSurface->GetPositionSize();
766
767   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
768   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
769
770   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
771   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
772 }
773
774 void Window::OnDeleteRequest()
775 {
776   mDeleteRequestSignal.Emit();
777 }
778
779 void Window::OnTransitionEffectEvent( WindowEffectState state, WindowEffectType type )
780 {
781   Dali::Window handle( this );
782   mTransitionEffectEventSignal.Emit( handle, state, type );
783 }
784
785 void Window::OnKeyboardRepeatSettingsChanged()
786 {
787   Dali::Window handle( this );
788   mKeyboardRepeatSettingsChangedSignal.Emit();
789 }
790
791 void Window::OnWindowRedrawRequest()
792 {
793   mAdaptor->RenderOnce();
794 }
795
796 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
797 {
798   FeedTouchPoint( point, timeStamp );
799 }
800
801 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
802 {
803   FeedWheelEvent( wheelEvent );
804 }
805
806 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
807 {
808   FeedKeyEvent( keyEvent );
809 }
810
811 void Window::OnRotation(const RotationEvent& rotation)
812 {
813   mRotationAngle = rotation.angle;
814   mWindowWidth   = rotation.width;
815   mWindowHeight  = rotation.height;
816
817   // Notify that the orientation is changed
818   mOrientation->OnOrientationChange(rotation);
819
820   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
821
822   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
823   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
824
825   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
826
827   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
828   // Emit signal
829   Dali::Window handle(this);
830   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
831
832   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
833 }
834
835 void Window::OnPause()
836 {
837   if( mEventHandler )
838   {
839     mEventHandler->Pause();
840   }
841 }
842
843 void Window::OnResume()
844 {
845   if( mEventHandler )
846   {
847     mEventHandler->Resume();
848   }
849
850   mSurface->SetFullSwapNextFrame();
851 }
852
853 void Window::RecalculateTouchPosition( Integration::Point& point )
854 {
855   Vector2 position = point.GetScreenPosition();
856   Vector2 convertedPosition;
857
858   switch( mRotationAngle )
859   {
860     case 90:
861     {
862       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
863       convertedPosition.y = position.x;
864       break;
865     }
866     case 180:
867     {
868       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
869       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
870       break;
871     }
872     case 270:
873     {
874       convertedPosition.x = position.y;
875       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
876       break;
877     }
878     default:
879     {
880       convertedPosition = position;
881       break;
882     }
883   }
884
885   point.SetScreenPosition( convertedPosition );
886 }
887
888 Dali::Window Window::Get( Dali::Actor actor )
889 {
890   Internal::Adaptor::Window* windowImpl = nullptr;
891
892   if ( Internal::Adaptor::Adaptor::IsAvailable() )
893   {
894     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
895     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
896     if( windowImpl )
897     {
898       return Dali::Window( windowImpl );
899     }
900   }
901
902   return Dali::Window();
903 }
904
905 void Window::SetParent( Dali::Window& parent )
906 {
907   if ( DALI_UNLIKELY( parent ) )
908   {
909     mParentWindow = parent;
910     Dali::Window self = Dali::Window( this );
911     // check circular parent window setting
912     if ( Dali::DevelWindow::GetParent( parent ) == self )
913     {
914       Dali::DevelWindow::Unparent( parent );
915     }
916     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
917   }
918 }
919
920 void Window::Unparent()
921 {
922   mWindowBase->SetParent( nullptr );
923   mParentWindow.Reset();
924 }
925
926 Dali::Window Window::GetParent()
927 {
928   return mParentWindow;
929 }
930
931 WindowOrientation Window::GetCurrentOrientation() const
932 {
933   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
934   return ConvertToOrientation( mRotationAngle );
935 }
936
937 void Window::SetAvailableOrientations( const Dali::Vector<WindowOrientation>& orientations )
938 {
939   Dali::Vector<float>::SizeType count = orientations.Count();
940   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
941   {
942     if( IsOrientationAvailable( orientations[index] ) == false )
943     {
944       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
945       continue;
946     }
947
948     bool found = false;
949     int convertedAngle = ConvertToAngle( orientations[index] );
950
951     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
952     {
953       if( mAvailableAngles[i] == convertedAngle )
954       {
955         found = true;
956         break;
957       }
958     }
959
960     if( !found )
961     {
962       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
963       mAvailableAngles.push_back( convertedAngle );
964     }
965   }
966   SetAvailableAnlges( mAvailableAngles );
967 }
968
969 int32_t Window::GetNativeId() const
970 {
971   return mWindowBase->GetNativeWindowId();
972 }
973
974 } // Adaptor
975
976 } // Internal
977
978 } // Dali