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