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