2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/popup/popup-impl.h>
22 #include <cstring> // for strcmp
23 #include <dali/devel-api/adaptor-framework/physical-keyboard.h>
24 #include <dali/public-api/object/type-registry-helper.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/adaptor-framework/key.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/common/stage.h>
29 #include <dali/public-api/events/key-event.h>
30 #include <dali/public-api/events/touch-data.h>
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/public-api/size-negotiation/relayout-container.h>
36 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
39 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
40 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
57 * Creation function for main Popup type.
58 * @return Handle to the new popup object.
62 return Toolkit::Popup::New();
65 // Toast style defaults.
66 const int DEFAULT_TOAST_AUTO_HIDE_DELAY = 3000; ///< Toast will auto-hide after 3000ms (3 seconds)
67 const float DEFAULT_TOAST_TRANSITION_TIME = 0.65f; ///< Default time the toast Popup will take to show and hide.
68 const Vector3 DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN( 0.5f, 0.94f, 0.5f ); ///< This is similar to BOTTOM_CENTER, but vertically higher up, as a ratio of parent height.
69 const Vector3 DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO( 0.75f, 0.75f, 0.75f ); ///< Amount of the stage's width that the toast popup will take up.
72 * Creation function for named type "popupToast".
73 * @return Handle to the new toast popup object.
75 BaseHandle CreateToast()
77 Toolkit::Popup popup = Toolkit::Popup::New();
79 // Setup for Toast Popup type.
80 popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
81 popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
82 popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
83 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
84 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, DEFAULT_TOAST_TRANSITION_TIME );
85 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
87 // Disable the dimmed backing.
88 popup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false );
90 // The toast popup should fade in (not zoom).
91 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, Toolkit::Popup::FADE );
93 // The toast popup should auto-hide.
94 popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY );
96 // Align to the bottom of the screen.
97 popup.SetParentOrigin( DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN );
98 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
100 // Let events pass through the toast popup.
101 popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true );
106 // Setup properties, signals and actions using the type-registry.
107 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
109 // Main content related properties.
110 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER )
113 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT )
116 // Contextual related properties.
117 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION )
119 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE )
121 // Animation related properties.
122 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION )
123 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION )
125 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION )
126 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY )
128 // Style related properties.
129 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED )
130 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR )
131 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE )
138 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE )
139 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING )
140 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN )
141 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING )
142 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
144 DALI_TYPE_REGISTRATION_END()
146 // Named type registration.
148 // Toast Popup: Non-modal popup that displays information at the bottom of the screen.
149 TypeRegistration typeRegistrationToast( "PopupToast", typeid( Toolkit::Popup ), CreateToast );
151 // Enumeration to / from string conversion tables
153 const Scripting::StringEnum DisplayStateTable[] = {
154 { "SHOWING", Toolkit::Popup::SHOWING },
155 { "SHOWN", Toolkit::Popup::SHOWN },
156 { "HIDING", Toolkit::Popup::HIDING },
157 { "HIDDEN", Toolkit::Popup::HIDDEN },
158 }; const unsigned int DisplayStateTableCount = sizeof( DisplayStateTable ) / sizeof( DisplayStateTable[0] );
160 const Scripting::StringEnum AnimationModeTable[] = {
161 { "NONE", Toolkit::Popup::NONE },
162 { "ZOOM", Toolkit::Popup::ZOOM },
163 { "FADE", Toolkit::Popup::FADE },
164 { "CUSTOM", Toolkit::Popup::CUSTOM },
165 }; const unsigned int AnimationModeTableCount = sizeof( AnimationModeTable ) / sizeof( AnimationModeTable[0] );
167 const Scripting::StringEnum ContextualModeTable[] = {
168 { "NON_CONTEXTUAL", Toolkit::Popup::NON_CONTEXTUAL },
169 { "ABOVE", Toolkit::Popup::ABOVE },
170 { "RIGHT", Toolkit::Popup::RIGHT },
171 { "BELOW", Toolkit::Popup::BELOW },
172 { "LEFT", Toolkit::Popup::LEFT },
173 }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] );
176 const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent.
177 const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations.
178 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
179 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
180 const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position.
182 // Contextual defaults.
183 const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent.
184 const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges.
186 // Popup style defaults.
187 const char* DEFAULT_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "00_popup_bg.9.png"; ///< Background image.
188 const char* DEFAULT_TAIL_UP_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_up.png"; ///< Tail up image.
189 const char* DEFAULT_TAIL_DOWN_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_down.png"; ///< Tail down image.
190 const char* DEFAULT_TAIL_LEFT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_left.png"; ///< Tail left image.
191 const char* DEFAULT_TAIL_RIGHT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_right.png"; ///< Tail right image.
193 const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing.
194 const Vector3 BACKGROUND_OUTER_BORDER( 40.0f, 30.0f, 0.0f ); ///< External border.
195 const Rect<float> DEFAULT_TITLE_PADDING( 20.0f, 20.0f, 20.0f, 20.0f ); ///< Title padding used on popups with content and/or controls (from Tizen GUI UX).
196 const Rect<float> DEFAULT_TITLE_ONLY_PADDING( 8.0f, 8.0f, 8.0f, 8.0f ); ///< Title padding used on popups with a title only (like toast popups).
197 const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area.
198 const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default.
200 } // Unnamed namespace
206 Dali::Toolkit::Popup Popup::New()
208 // Create the implementation
209 PopupPtr popup( new Popup() );
211 // Pass ownership to CustomActor via derived handle.
212 Dali::Toolkit::Popup handle( *popup );
214 // Second-phase initialisation of the implementation.
215 // This can only be done after the CustomActor connection has been made.
222 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
223 mTouchedOutsideSignal(),
231 mPreviousFocusedActor(),
235 mAlterAddedChild( false ),
236 mLayoutDirty( true ),
238 mTouchTransparent( false ),
242 mDisplayState( Toolkit::Popup::HIDDEN ), // Hidden until shown with SetDisplayState()
243 mTailVisible( false ),
244 mTailPosition( DEFAULT_TAIL_POSITION ),
245 mContextualMode( Toolkit::Popup::NON_CONTEXTUAL ),
246 mAnimationDuration( DEFAULT_POPUP_ANIMATION_DURATION ),
247 mAnimationMode( Toolkit::Popup::FADE ),
248 mEntryAnimationData(),
249 mExitAnimationData(),
251 mBackingEnabled( true ),
252 mBackingColor( DEFAULT_BACKING_COLOR ),
253 mPopupBackgroundImage(),
254 mBackgroundOuterBorder(),
256 mTailUpImage( DEFAULT_TAIL_UP_IMAGE_PATH ),
257 mTailDownImage( DEFAULT_TAIL_DOWN_IMAGE_PATH ),
258 mTailLeftImage( DEFAULT_TAIL_LEFT_IMAGE_PATH ),
259 mTailRightImage( DEFAULT_TAIL_RIGHT_IMAGE_PATH )
261 SetKeyboardNavigationSupport( true );
264 void Popup::OnInitialize()
267 self.SetName( "popup" );
269 // Apply some default resizing rules.
270 self.SetParentOrigin( ParentOrigin::CENTER );
271 self.SetAnchorPoint( AnchorPoint::CENTER );
273 self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
274 self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
275 self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
277 // Create a new layer so all Popup components can appear above all other actors.
278 mLayer = Layer::New();
279 mLayer.SetName( "popupLayer" );
281 mLayer.SetParentOrigin( ParentOrigin::CENTER );
282 mLayer.SetAnchorPoint( AnchorPoint::CENTER );
283 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
285 // Important to set as invisible as otherwise, if the popup is parented,
286 // but not shown yet it will appear statically on the screen.
287 mLayer.SetVisible( false );
289 // Add the layer to the hierarchy.
292 // Add Backing (Dimmed effect).
293 mBacking = CreateBacking();
294 mLayer.Add( mBacking );
296 mPopupContainer = Actor::New();
297 mPopupContainer.SetName( "popupContainer" );
298 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
299 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
300 mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
301 mLayer.Add( mPopupContainer );
303 // Create the Popup layout to contain all main content.
304 mPopupLayout = Toolkit::TableView::New( 3, 1 );
306 // Adds the default background image.
307 SetPopupBackgroundImage( Toolkit::ImageView::New( DEFAULT_BACKGROUND_IMAGE_PATH ) );
309 mPopupLayout.SetName( "popupLayoutTable" );
310 mPopupLayout.SetParentOrigin( ParentOrigin::CENTER );
311 mPopupLayout.SetAnchorPoint( AnchorPoint::CENTER );
313 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
314 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
315 mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f );
317 mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
318 mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
320 mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
322 mPopupContainer.Add( mPopupLayout );
324 // Any content after this point which is added to Self() will be re-parented to mContent.
325 mAlterAddedChild = true;
327 SetAsKeyboardFocusGroup( true );
332 mEntryAnimationData.Clear();
333 mExitAnimationData.Clear();
336 void Popup::LayoutAnimation()
338 // Perform setup based on the currently selected animation.
339 switch( mAnimationMode )
341 case Toolkit::Popup::ZOOM:
343 // Zoom animations start fully zoomed out.
344 mPopupContainer.SetScale( Vector3::ZERO );
348 case Toolkit::Popup::FADE:
350 // Fade animations start transparent.
351 mPopupContainer.SetOpacity( 0.0f );
355 case Toolkit::Popup::CUSTOM:
357 // Initialise the custom animation by playing to the end of it's exit animation instantly.
358 // EG. If it was zooming in, then we zoom out fully instantly so the zoom in works.
359 StartTransitionAnimation( false, true );
363 case Toolkit::Popup::NONE:
370 void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* false */ )
372 // Stop and recreate animation.
379 float duration = GetAnimationDuration();
381 // Setup variables ready to start the animations.
382 // If we are performing the animation instantaneously, we do not want to emit a signal.
387 // Setup variables and signal that we are starting the transition.
388 // Note: We signal even if the transition is instant so signal order is consistent.
389 mShowingSignal.Emit();
393 mHidingSignal.Emit();
397 // Perform chosen animation for the Popup.
398 switch( mAnimationMode )
400 case Toolkit::Popup::NONE:
402 mAnimation = Animation::New( 0.0f );
406 case Toolkit::Popup::ZOOM:
408 mAnimation = Animation::New( duration );
409 if( duration > Math::MACHINE_EPSILON_0 )
413 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( duration * 0.25f, duration * 0.75f ) );
417 // Zoom out animation is twice the speed. Modify the duration variable so the backing animation speed is modified also.
419 mAnimation.SetDuration( duration );
420 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ZERO, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration ) );
425 mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO );
430 case Toolkit::Popup::FADE:
432 mAnimation = Animation::New( duration );
433 if( duration > Math::MACHINE_EPSILON_0 )
437 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
441 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
446 mPopupContainer.SetOpacity( transitionIn ? 1.0f : 0.0f );
451 case Toolkit::Popup::CUSTOM:
453 // Use a user specified animation for in and out.
454 // Read the correct animation depending on entry or exit.
455 // Attempt to use animation data defined from script data.
456 Dali::AnimationData* animationData = transitionIn ? &mEntryAnimationData : &mExitAnimationData;
458 // Create a new animation from the pre-defined data in the AnimationData class.
459 // If there is no data, mAnimation is invalidated.
460 mAnimation = animationData->CreateAnimation( mPopupContainer, duration );
462 // If we don't have a valid animation, provide a blank one so play() can still function generically.
465 // No animation was configured (even though custom mode was specified). Create a dummy animation to avoid an exception.
466 mAnimation = Animation::New( 0.0f );
473 // Animate the backing, if enabled.
474 // This is set up last so that different animation modes can have an effect on the backing animation speed.
475 if( mBackingEnabled )
477 // Use the alpha from the user-specified color.
478 float targetAlpha = mBackingColor.a;
479 if( duration > Math::MACHINE_EPSILON_0 )
483 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), targetAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
487 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
492 mBacking.SetProperty( Actor::Property::COLOR_ALPHA, transitionIn ? targetAlpha : 0.0f );
496 // If we are performing the animation instantaneously, jump to the position directly and do not signal.
499 mAnimation.SetCurrentProgress( 1.0f );
502 else if( duration > Math::MACHINE_EPSILON_0 )
504 // Run the animation.
505 mAnimation.FinishedSignal().Connect( this, &Popup::OnDisplayChangeAnimationFinished );
510 // We did not use an animation to achive the transition.
511 // Trigger the state change directly.
512 DisplayStateChangeComplete();
516 void Popup::OnDisplayChangeAnimationFinished( Animation& source )
518 DisplayStateChangeComplete();
521 void Popup::DisplayStateChangeComplete()
523 // Remove contents from stage if completely hidden.
524 if( mDisplayState == Toolkit::Popup::HIDING )
526 mDisplayState = Toolkit::Popup::HIDDEN;
528 mLayer.SetVisible( false );
529 mPopupLayout.SetSensitive( false );
531 // Guard against destruction during signal emission.
532 Toolkit::Popup handle( GetOwner() );
533 mHiddenSignal.Emit();
535 else if( mDisplayState == Toolkit::Popup::SHOWING )
537 mDisplayState = Toolkit::Popup::SHOWN;
538 Toolkit::Popup handle( GetOwner() );
541 // Start a timer to auto-hide if enabled.
542 if( mAutoHideDelay > 0u )
544 mAutoHideTimer = Timer::New( mAutoHideDelay );
545 mAutoHideTimer.TickSignal().Connect( this, &Popup::OnAutoHideTimeReached );
546 mAutoHideTimer.Start();
551 bool Popup::OnAutoHideTimeReached()
553 // Display timer has expired, auto hide the popup exactly as if the user had clicked outside.
554 SetDisplayState( Toolkit::Popup::HIDDEN );
558 mAutoHideTimer.Stop();
559 mAutoHideTimer.TickSignal().Disconnect( this, &Popup::OnAutoHideTimeReached );
560 mAutoHideTimer.Reset();
565 void Popup::SetPopupBackgroundImage( Actor image )
567 // Removes any previous background.
568 if( mPopupBackgroundImage )
570 mPopupContainer.Remove( mPopupBackgroundImage );
573 // Adds new background to the dialog.
574 mPopupBackgroundImage = image;
575 mPopupBackgroundImage.SetName( "popupBackgroundImage" );
576 mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
577 mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
579 // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
580 mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
582 // Set the popup border to be slightly larger than the layout contents.
583 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
584 mPopupBackgroundImage.SetSizeModeFactor( BACKGROUND_OUTER_BORDER );
586 const bool prevAlter = mAlterAddedChild;
587 mAlterAddedChild = false;
588 mPopupContainer.Add( mPopupBackgroundImage );
589 mAlterAddedChild = prevAlter;
594 Actor Popup::GetPopupBackgroundImage() const
596 return mPopupBackgroundImage;
599 void Popup::SetTitle( Actor titleActor )
601 // Replaces the current title actor.
609 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
615 // Set up padding to give sensible default behaviour
616 // (an application developer can later override this if they wish).
617 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
619 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
626 Actor Popup::GetTitle() const
631 void Popup::SetContent( Actor content )
633 // Remove previous content actor.
636 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
638 // Keep a handle to the new content.
643 mContent.SetName( "popupContent" );
645 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
652 Actor Popup::GetContent() const
657 void Popup::SetFooter( Actor footer )
659 // Remove previous content actor.
662 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
665 // Keep a handle to the new content.
670 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
672 // The control container has a fixed height.
673 mPopupLayout.SetFitHeight( 2u );
674 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
681 Actor Popup::GetFooter() const
686 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
688 // Convert the 4-way state to a bool, true for show, false for hide.
689 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
691 // Ignore if we are already at the target display state.
692 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
697 // Convert the bool state to the actual display state to use.
698 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
702 // Update the state to indicate the current intent.
703 mDisplayState = Toolkit::Popup::SHOWING;
705 // We want the popup to have key input focus when it is displayed
708 // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
710 mLayer.SetVisible( true );
712 // Set up the layout if this is the first display or the layout has become dirty.
715 // Bake-in any style and layout options to create the Popup layout.
719 // Allow the popup to catch events.
720 mPopupLayout.SetSensitive( true );
722 // Handle the keyboard focus when popup is shown.
723 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
724 if( keyboardFocusManager )
726 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
728 if( Self().IsKeyboardFocusable() )
730 // Setup the actgor to start focus from.
732 if( mContent && mContent.IsKeyboardFocusable() )
734 // If the content is focusable, move the focus to the content.
735 focusActor = mContent;
737 else if( mFooter && mFooter.IsKeyboardFocusable() )
739 // If the footer is focusable, move the focus to the footer.
740 focusActor = mFooter;
744 DALI_LOG_WARNING( "There is no focusable in popup\n" );
749 keyboardFocusManager.SetCurrentFocusActor( focusActor );
756 mDisplayState = Toolkit::Popup::HIDING;
757 ClearKeyInputFocus();
759 // Restore the keyboard focus when popup is hidden.
760 if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
762 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
763 if( keyboardFocusManager )
765 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
770 // Perform animation.
771 StartTransitionAnimation( display );
774 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
776 return mDisplayState;
779 void Popup::LayoutPopup()
781 mLayoutDirty = false;
783 /* When animating in, we want to respect the origin applied to Self().
784 * For example, if zooming, not only will the final result be anchored to the
785 * selected point, but the zoom will originate from this point also.
787 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
796 mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
797 mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
799 // If there is only a title, use less padding.
802 if( !mContent && !mFooter )
804 mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
808 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
812 // Allow derived classes to perform any layout they may need to do.
815 // Update background visibility.
816 mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
818 // Create / destroy / position the tail as needed.
821 // Setup any layout and initialisation required for the selected animation.
827 void Popup::LayoutTail()
829 // Removes the tail actor.
830 if( mTailImage && mTailImage.GetParent() )
832 mTailImage.GetParent().Remove( mTailImage );
841 const Vector3& position = GetTailPosition();
844 // depending on position of tail around ParentOrigin, a different tail image is used...
845 if( position.y < Math::MACHINE_EPSILON_1 )
847 image = mTailUpImage;
849 else if( position.y > 1.0f - Math::MACHINE_EPSILON_1 )
851 image = mTailDownImage;
853 else if( position.x < Math::MACHINE_EPSILON_1 )
855 image = mTailLeftImage;
857 else if( position.x > 1.0f - Math::MACHINE_EPSILON_1 )
859 image = mTailRightImage;
864 // Adds the tail actor.
865 mTailImage = Toolkit::ImageView::New( image );
866 mTailImage.SetName( "tailImage" );
867 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
868 mTailImage.SetParentOrigin( position );
869 mTailImage.SetAnchorPoint( anchorPoint );
871 mPopupContainer.Add( mTailImage );
875 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
877 mContextualMode = mode;
881 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
883 return mContextualMode;
886 Toolkit::Control Popup::CreateBacking()
888 Toolkit::Control backing = Control::New();
889 backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
890 backing.SetName( "popupBacking" );
892 // Must always be positioned top-left of stage, regardless of parent.
893 backing.SetInheritPosition(false);
894 backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
896 // Always the full size of the stage.
897 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
898 backing.SetSize( Stage::GetCurrent().GetSize() );
901 backing.SetSensitive( true );
903 // Default to being transparent.
904 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
905 backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
906 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
910 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
912 return mTouchedOutsideSignal;
915 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
917 return mShowingSignal;
920 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
925 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
927 return mHidingSignal;
930 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
932 return mHiddenSignal;
935 void Popup::SetTailVisibility( bool visible )
937 mTailVisible = visible;
941 const bool Popup::IsTailVisible() const
946 void Popup::SetTailPosition( Vector3 position )
948 mTailPosition = position;
952 const Vector3& Popup::GetTailPosition() const
954 return mTailPosition;
957 void Popup::SetAnimationDuration( float duration )
959 mAnimationDuration = duration;
963 float Popup::GetAnimationDuration() const
965 return mAnimationDuration;
968 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
970 mAnimationMode = animationMode;
974 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
976 return mAnimationMode;
979 void Popup::SetEntryAnimationData( const Property::Map& map )
981 mEntryAnimationData.Clear();
982 Scripting::NewAnimation( map, mEntryAnimationData );
985 void Popup::SetExitAnimationData( const Property::Map& map )
987 mExitAnimationData.Clear();
988 Scripting::NewAnimation( map, mExitAnimationData );
991 void Popup::SetAutoHideDelay( int delay )
993 mAutoHideDelay = delay;
996 int Popup::GetAutoHideDelay() const
998 return mAutoHideDelay;
1001 void Popup::SetBackingEnabled( bool enabled )
1003 mBackingEnabled = enabled;
1004 mLayoutDirty = true;
1007 const bool Popup::IsBackingEnabled() const
1009 return mBackingEnabled;
1012 void Popup::SetBackingColor( Vector4 color )
1014 mBackingColor = color;
1015 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1016 mLayoutDirty = true;
1019 const Vector4& Popup::GetBackingColor() const
1021 return mBackingColor;
1024 void Popup::SetTailUpImage( std::string image )
1026 mTailUpImage = image;
1027 mLayoutDirty = true;
1030 const std::string& Popup::GetTailUpImage() const
1032 return mTailUpImage;
1035 void Popup::SetTailDownImage( std::string image )
1037 mTailDownImage = image;
1038 mLayoutDirty = true;
1041 const std::string& Popup::GetTailDownImage() const
1043 return mTailDownImage;
1046 void Popup::SetTailLeftImage( std::string image )
1048 mTailLeftImage = image;
1049 mLayoutDirty = true;
1052 const std::string& Popup::GetTailLeftImage() const
1054 return mTailLeftImage;
1057 void Popup::SetTailRightImage( std::string image )
1059 mTailRightImage = image;
1060 mLayoutDirty = true;
1063 const std::string& Popup::GetTailRightImage() const
1065 return mTailRightImage;
1068 void Popup::SetTouchTransparent( bool enabled )
1070 mTouchTransparent = enabled;
1073 const bool Popup::IsTouchTransparent() const
1075 return mTouchTransparent;
1078 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1080 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1084 Popup& popupImpl( GetImpl( popup ) );
1086 switch ( propertyIndex )
1088 case Toolkit::Popup::Property::TITLE:
1090 Property::Map valueMap;
1091 if( value.Get( valueMap ) )
1093 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1097 case Toolkit::Popup::Property::CONTENT:
1099 Property::Map valueMap;
1100 if( value.Get( valueMap ) )
1102 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1106 case Toolkit::Popup::Property::FOOTER:
1108 Property::Map valueMap;
1109 if( value.Get( valueMap ) )
1111 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1115 case Toolkit::Popup::Property::DISPLAY_STATE:
1117 std::string valueString;
1118 if( value.Get( valueString ) )
1120 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1121 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1123 popupImpl.SetDisplayState( displayState );
1128 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1131 if( value.Get( valueBool ) )
1133 popupImpl.SetTouchTransparent( valueBool );
1137 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1140 if( value.Get( valueBool ) )
1142 popupImpl.SetTailVisibility( valueBool );
1146 case Toolkit::Popup::Property::TAIL_POSITION:
1148 Vector3 valueVector3;
1149 if( value.Get( valueVector3 ) )
1151 popupImpl.SetTailPosition( valueVector3 );
1155 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1157 std::string valueString;
1158 if( value.Get( valueString ) )
1160 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1161 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1163 popupImpl.SetContextualMode( contextualMode );
1168 case Toolkit::Popup::Property::ANIMATION_DURATION:
1171 if( value.Get( valueFloat ) )
1173 popupImpl.SetAnimationDuration( valueFloat );
1177 case Toolkit::Popup::Property::ANIMATION_MODE:
1179 std::string valueString;
1180 if( value.Get( valueString ) )
1182 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1183 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1185 popupImpl.SetAnimationMode( animationMode );
1190 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1192 Property::Map valueMap;
1193 if( value.Get( valueMap ) )
1195 popupImpl.SetEntryAnimationData( valueMap );
1199 case Toolkit::Popup::Property::EXIT_ANIMATION:
1201 Property::Map valueMap;
1202 if( value.Get( valueMap ) )
1204 popupImpl.SetExitAnimationData( valueMap );
1208 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1211 if( value.Get( valueInt ) )
1213 popupImpl.SetAutoHideDelay( valueInt );
1217 case Toolkit::Popup::Property::BACKING_ENABLED:
1220 if( value.Get( valueBool ) )
1222 popupImpl.SetBackingEnabled( valueBool );
1226 case Toolkit::Popup::Property::BACKING_COLOR:
1228 Vector4 valueVector4;
1229 if( value.Get( valueVector4 ) )
1231 popupImpl.SetBackingColor( valueVector4 );
1235 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1237 std::string valueString;
1238 if( value.Get( valueString ) )
1240 Toolkit::ImageView actor = Toolkit::ImageView::New( valueString );
1241 popupImpl.SetPopupBackgroundImage( actor );
1245 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1247 std::string valueString;
1248 if( value.Get( valueString ) )
1250 popupImpl.SetTailUpImage( valueString );
1254 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1256 std::string valueString;
1257 if( value.Get( valueString ) )
1259 popupImpl.SetTailDownImage( valueString );
1263 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1265 std::string valueString;
1266 if( value.Get( valueString ) )
1268 popupImpl.SetTailLeftImage( valueString );
1272 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1274 std::string valueString;
1275 if( value.Get( valueString ) )
1277 popupImpl.SetTailRightImage( valueString );
1285 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1287 Property::Value value;
1289 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1293 Popup& popupImpl( GetImpl( popup ) );
1295 switch ( propertyIndex )
1297 case Toolkit::Popup::Property::TITLE:
1300 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1304 case Toolkit::Popup::Property::CONTENT:
1307 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1311 case Toolkit::Popup::Property::FOOTER:
1314 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1318 case Toolkit::Popup::Property::DISPLAY_STATE:
1320 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1323 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1325 value = popupImpl.IsTouchTransparent();
1328 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1330 value = popupImpl.IsTailVisible();
1333 case Toolkit::Popup::Property::TAIL_POSITION:
1335 value = popupImpl.GetTailPosition();
1338 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1340 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1343 case Toolkit::Popup::Property::ANIMATION_DURATION:
1345 value = popupImpl.GetAnimationDuration();
1348 case Toolkit::Popup::Property::ANIMATION_MODE:
1350 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1353 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1355 // Note: Cannot retrieve property map from animation.
1360 case Toolkit::Popup::Property::EXIT_ANIMATION:
1362 // Note: Cannot retrieve property map from animation.
1367 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1369 value = popupImpl.GetAutoHideDelay();
1372 case Toolkit::Popup::Property::BACKING_ENABLED:
1374 value = popupImpl.IsBackingEnabled();
1377 case Toolkit::Popup::Property::BACKING_COLOR:
1379 value = popupImpl.GetBackingColor();
1382 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1384 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() );
1387 value = imageView.GetProperty( Toolkit::ImageView::Property::IMAGE );
1391 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1393 value = popupImpl.GetTailUpImage();
1396 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1398 value = popupImpl.GetTailDownImage();
1401 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1403 value = popupImpl.GetTailLeftImage();
1406 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1408 value = popupImpl.GetTailRightImage();
1417 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1419 Dali::BaseHandle handle( object );
1421 bool connected( true );
1422 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1424 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1426 popup.OutsideTouchedSignal().Connect( tracker, functor );
1428 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1430 popup.ShowingSignal().Connect( tracker, functor );
1432 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1434 popup.ShownSignal().Connect( tracker, functor );
1436 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1438 popup.HidingSignal().Connect( tracker, functor );
1440 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1442 popup.HiddenSignal().Connect( tracker, functor );
1446 // signalName does not match any signal
1453 bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
1455 // Allow events to pass through if touch transparency is enabled.
1456 if( mTouchTransparent )
1461 if( touch.GetPointCount() > 0 )
1463 if( touch.GetState( 0 ) == PointState::DOWN )
1465 // Guard against destruction during signal emission.
1466 Toolkit::Popup handle( GetOwner() );
1468 mTouchedOutsideSignal.Emit();
1472 // Block anything behind backing becoming touched.
1473 mLayer.SetTouchConsumed( true );
1477 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1479 // Allow events to pass through if touch transparency is enabled.
1480 if( mTouchTransparent )
1485 // Consume wheel event in dimmed backing actor.
1486 mLayer.SetTouchConsumed( true );
1490 bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
1492 // Allow events to pass through if touch transparency is enabled.
1493 if( mTouchTransparent )
1498 // Consume event (stops backing actor receiving touch events)
1499 mLayer.SetTouchConsumed( true );
1503 void Popup::OnStageConnection( int depth )
1505 Control::OnStageConnection( depth );
1507 mLayoutDirty = true;
1511 void Popup::OnChildAdd( Actor& child )
1513 Control::OnChildAdd( child );
1515 // Re-parent any children added by user to the body layer.
1516 if( mAlterAddedChild )
1518 SetContent( child );
1522 mLayoutDirty = true;
1527 void Popup::LayoutContext( const Vector2& size )
1529 // Do nothing if not in a contextual mode (or there is no parent context).
1530 Actor self = Self();
1531 Actor parent = self.GetParent();
1532 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1537 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
1538 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1539 // mode to allow code-reuse of the bound checking code (for maintainability).
1540 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
1542 // Setup with some pre-calculations for speed.
1543 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1544 Vector3 parentPosition( parent.GetCurrentPosition() );
1545 Vector2 halfSize( size / 2.0f );
1546 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1547 Vector3 newPosition( Vector3::ZERO );
1549 // Perform different positioning based on the specified contextual layout mode.
1550 switch( mContextualMode )
1552 case Toolkit::Popup::BELOW:
1554 newPosition.x += halfSize.x - halfParentSize.x;
1555 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1558 case Toolkit::Popup::ABOVE:
1560 newPosition.x += halfSize.x - halfParentSize.x;
1561 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1564 case Toolkit::Popup::RIGHT:
1566 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1567 newPosition.y += halfSize.y - halfParentSize.y;
1570 case Toolkit::Popup::LEFT:
1572 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1573 newPosition.y += halfSize.y - halfParentSize.y;
1576 case Toolkit::Popup::NON_CONTEXTUAL:
1578 // Code won't reach here (caught earlier).
1583 // On-screen position checking.
1584 // Check new position is not too far right. If so, correct it.
1585 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1586 // the right check and we at least see the left portion of the popup (as this is more useful).
1587 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1589 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1591 // Check new position is not too far left. If so, correct it.
1592 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1594 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1596 // Check new position is not too far down. If so, correct it.
1597 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1599 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1601 // Check new position is not too far up. If so, correct it.
1602 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1604 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1607 // Set the final position.
1608 mPopupContainer.SetPosition( newPosition );
1611 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1613 Vector2 useSize( size );
1615 // Use the Popup layouts size, unless requested to use a fixed size.
1616 // In which case take the size set for the Popup itself.
1617 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1618 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1620 // Width calculations:
1621 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1623 // If we using a child-based policy, take the size from the popup layout.
1624 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1625 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1627 mPopupLayout.SetFitWidth( 0u );
1631 // If we using a parent-based policy, take the size from the popup object itself (self).
1632 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1634 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1637 // Height calculations:
1638 // Title: Let the title be as high as it needs to be.
1639 mPopupLayout.SetFitHeight( 0u );
1641 // Footer: Convert the footer's resize policy to a TableView row policy.
1644 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1645 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1646 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1648 mPopupLayout.SetFitHeight( 2u );
1650 else if( footerHeightPolicy == ResizePolicy::FIXED )
1652 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1656 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1661 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1664 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1665 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1667 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1669 // Let both the contents expand as necessary.
1670 mPopupLayout.SetFitHeight( 1u );
1671 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1675 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1677 // Let the content expand to fill the remaining space.
1678 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1679 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1682 // Relayout the popup-layout to give it it's new size this frame.
1683 container.Add( mPopupLayout, useSize );
1687 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1690 // Perform contextual layout setup if required.
1691 // This is done each time in case the parent moves.
1692 // This will have no effect if no contextual mode is selected.
1693 LayoutContext( useSize );
1696 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1698 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1699 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1701 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1704 mLayoutDirty = true;
1708 Vector3 Popup::GetNaturalSize()
1710 return mPopupLayout.GetNaturalSize();
1713 float Popup::GetHeightForWidth( float width )
1715 return mPopupLayout.GetHeightForWidth( width );
1718 float Popup::GetWidthForHeight( float height )
1720 return mPopupLayout.GetWidthForHeight( height );
1723 bool Popup::OnKeyEvent( const KeyEvent& event )
1725 // Allow events to pass through if touch transparency is enabled.
1726 if( mTouchTransparent )
1731 bool consumed = false;
1733 if( event.state == KeyEvent::Down )
1735 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
1737 SetDisplayState( Toolkit::Popup::HIDDEN );
1745 void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors )
1749 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1750 bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
1752 if( parent.IsKeyboardFocusable() || layoutControl )
1754 focusableActors.push_back( parent );
1756 if( !layoutControl )
1758 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1760 Actor child( parent.GetChildAt( i ) );
1761 AddFocusableChildrenRecursive( child, focusableActors );
1768 void Popup::AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors )
1772 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1773 if( !GetImplementation( control ).IsKeyboardNavigationSupported() )
1775 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1777 Actor child( parent.GetChildAt( i ) );
1778 AddFocusableChildrenRecursive( child, focusableActors );
1783 focusableActors.push_back( parent );
1788 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1790 std::string currentStr;
1791 if( currentFocusedActor )
1793 currentStr = currentFocusedActor.GetName();
1796 Actor nextFocusableActor( currentFocusedActor );
1797 Actor currentFocusGroup;
1798 if( currentFocusedActor )
1800 currentFocusGroup = KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor );
1803 // TODO: Needs to be optimised
1804 // The following statement checks that if we have a current focused actor, then the current focus group is not the popup content or footer.
1805 // This is to detect if the focus is currently outside the popup, and if so, move it inside.
1806 if( !currentFocusedActor ||
1807 ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
1809 // The current focused actor is not within popup.
1810 if( mContent && mContent.IsKeyboardFocusable() )
1812 // If the content is focusable, move the focus to the content.
1813 nextFocusableActor = mContent;
1815 else if( mFooter && mFooter.IsKeyboardFocusable() )
1817 // If the footer is focusable, move the focus to the footer.
1818 nextFocusableActor = mFooter;
1823 // Rebuild the focus chain because controls or content can be added or removed dynamically
1824 std::vector< Actor > focusableActors;
1826 AddFocusableChildren( mContent, focusableActors );
1827 AddFocusableChildren( mFooter, focusableActors );
1829 std::vector< Actor >::iterator endIterator = focusableActors.end();
1830 std::vector< Actor >::iterator currentIterator = focusableActors.begin();
1831 for( std::vector< Actor >::iterator iterator = focusableActors.begin(); iterator != endIterator; ++iterator )
1833 if( currentFocusedActor == *iterator )
1835 currentIterator = iterator;
1839 if( currentIterator != endIterator )
1843 case Toolkit::Control::KeyboardFocus::LEFT:
1845 if( currentIterator == focusableActors.begin() )
1847 nextFocusableActor = *( endIterator - 1 );
1851 nextFocusableActor = *( currentIterator - 1 );
1855 case Toolkit::Control::KeyboardFocus::RIGHT:
1857 if( currentIterator == endIterator - 1 )
1859 nextFocusableActor = *( focusableActors.begin() );
1863 nextFocusableActor = *( currentIterator + 1 );
1868 case Toolkit::Control::KeyboardFocus::UP:
1870 nextFocusableActor = *( focusableActors.begin() );
1874 case Toolkit::Control::KeyboardFocus::DOWN:
1876 nextFocusableActor = *( endIterator - 1 );
1881 if( !nextFocusableActor )
1883 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1888 return nextFocusableActor;
1892 } // namespace Internal
1894 } // namespace Toolkit