2 * Copyright (c) 2017 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/devel-api/actors/actor-devel.h>
34 #include <dali/public-api/size-negotiation/relayout-container.h>
37 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
38 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
39 #include <dali-toolkit/public-api/controls/control-impl.h>
40 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
41 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
42 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
43 #include <dali-toolkit/public-api/visuals/visual-properties.h>
44 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
61 * Creation function for main Popup type.
62 * @return Handle to the new popup object.
66 return Toolkit::Popup::New();
69 // Toast style defaults.
70 const int DEFAULT_TOAST_AUTO_HIDE_DELAY = 3000; ///< Toast will auto-hide after 3000ms (3 seconds)
71 const float DEFAULT_TOAST_TRANSITION_TIME = 0.65f; ///< Default time the toast Popup will take to show and hide.
72 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.
73 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.
76 * Creation function for named type "popupToast".
77 * @return Handle to the new toast popup object.
79 BaseHandle CreateToast()
81 Toolkit::Popup popup = Toolkit::Popup::New();
83 // Setup for Toast Popup type.
84 popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
85 popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
86 popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
87 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
88 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, DEFAULT_TOAST_TRANSITION_TIME );
89 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
91 // Disable the dimmed backing.
92 popup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false );
94 // The toast popup should fade in (not zoom).
95 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, Toolkit::Popup::FADE );
97 // The toast popup should auto-hide.
98 popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY );
100 // Align to the bottom of the screen.
101 popup.SetParentOrigin( DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN );
102 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
104 // Let events pass through the toast popup.
105 popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true );
110 // Setup properties, signals and actions using the type-registry.
111 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
113 // Main content related properties.
114 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER )
117 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT )
120 // Contextual related properties.
121 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY )
122 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION )
123 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE )
125 // Animation related properties.
126 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION )
127 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION )
130 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY )
132 // Style related properties.
133 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED )
134 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR )
135 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE )
136 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundBorder", RECTANGLE, POPUP_BACKGROUND_BORDER )
137 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE )
138 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE )
139 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE )
140 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE )
143 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE )
144 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING )
145 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN )
146 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING )
147 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
149 DALI_TYPE_REGISTRATION_END()
151 // Named type registration.
153 // Toast Popup: Non-modal popup that displays information at the bottom of the screen.
154 TypeRegistration typeRegistrationToast( "PopupToast", typeid( Toolkit::Popup ), CreateToast );
156 // Enumeration to / from string conversion tables
158 const Scripting::StringEnum DisplayStateTable[] = {
159 { "SHOWING", Toolkit::Popup::SHOWING },
160 { "SHOWN", Toolkit::Popup::SHOWN },
161 { "HIDING", Toolkit::Popup::HIDING },
162 { "HIDDEN", Toolkit::Popup::HIDDEN },
163 }; const unsigned int DisplayStateTableCount = sizeof( DisplayStateTable ) / sizeof( DisplayStateTable[0] );
165 const Scripting::StringEnum AnimationModeTable[] = {
166 { "NONE", Toolkit::Popup::NONE },
167 { "ZOOM", Toolkit::Popup::ZOOM },
168 { "FADE", Toolkit::Popup::FADE },
169 { "CUSTOM", Toolkit::Popup::CUSTOM },
170 }; const unsigned int AnimationModeTableCount = sizeof( AnimationModeTable ) / sizeof( AnimationModeTable[0] );
172 const Scripting::StringEnum ContextualModeTable[] = {
173 { "NON_CONTEXTUAL", Toolkit::Popup::NON_CONTEXTUAL },
174 { "ABOVE", Toolkit::Popup::ABOVE },
175 { "RIGHT", Toolkit::Popup::RIGHT },
176 { "BELOW", Toolkit::Popup::BELOW },
177 { "LEFT", Toolkit::Popup::LEFT },
178 }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] );
181 const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent.
182 const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations.
183 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
184 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
185 const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position.
187 // Contextual defaults.
188 const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent.
189 const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges.
191 // Popup style defaults.
192 const char* DEFAULT_BACKGROUND_IMAGE_FILE_NAME = "00_popup_bg.9.png"; ///< Background image.
193 const char* DEFAULT_TAIL_UP_IMAGE_FILE_NAME = "popup_tail_up.png"; ///< Tail up image.
194 const char* DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME = "popup_tail_down.png"; ///< Tail down image.
195 const char* DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME = "popup_tail_left.png"; ///< Tail left image.
196 const char* DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME = "popup_tail_right.png"; ///< Tail right image.
198 const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing.
199 const Rect<int> DEFAULT_BACKGROUND_BORDER( 17, 17, 13, 13 ); ///< Default border of the background.
200 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).
201 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).
202 const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area.
203 const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default.
205 } // Unnamed namespace
211 Dali::Toolkit::Popup Popup::New()
213 // Create the implementation
214 PopupPtr popup( new Popup() );
216 // Pass ownership to CustomActor via derived handle.
217 Dali::Toolkit::Popup handle( *popup );
219 // Second-phase initialisation of the implementation.
220 // This can only be done after the CustomActor connection has been made.
227 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
228 mTouchedOutsideSignal(),
236 mPreviousFocusedActor(),
240 mAlterAddedChild( false ),
241 mLayoutDirty( true ),
243 mTouchTransparent( false ),
247 mDisplayState( Toolkit::Popup::HIDDEN ), // Hidden until shown with SetDisplayState()
248 mTailVisible( false ),
249 mTailPosition( DEFAULT_TAIL_POSITION ),
250 mContextualMode( Toolkit::Popup::NON_CONTEXTUAL ),
251 mAnimationDuration( DEFAULT_POPUP_ANIMATION_DURATION ),
252 mAnimationMode( Toolkit::Popup::FADE ),
253 mEntryAnimationData(),
254 mExitAnimationData(),
256 mBackingEnabled( true ),
257 mBackingColor( DEFAULT_BACKING_COLOR ),
258 mPopupBackgroundImage(),
259 mBackgroundBorder( DEFAULT_BACKGROUND_BORDER ),
266 SetKeyboardNavigationSupport( true );
268 const std::string imageDirPath = AssetManager::GetDaliImagePath();
269 mTailUpImage = imageDirPath + DEFAULT_TAIL_UP_IMAGE_FILE_NAME;
270 mTailDownImage = imageDirPath + DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME;
271 mTailLeftImage = imageDirPath + DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME;
272 mTailRightImage = imageDirPath + DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME;
275 void Popup::OnInitialize()
278 self.SetName( "popup" );
280 // Apply some default resizing rules.
281 self.SetParentOrigin( ParentOrigin::CENTER );
282 self.SetAnchorPoint( AnchorPoint::CENTER );
284 self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
285 self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
286 self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
288 // Create a new layer so all Popup components can appear above all other actors.
289 mLayer = Layer::New();
290 mLayer.SetName( "popupLayer" );
292 mLayer.SetParentOrigin( ParentOrigin::CENTER );
293 mLayer.SetAnchorPoint( AnchorPoint::CENTER );
294 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
296 // Important to set as invisible as otherwise, if the popup is parented,
297 // but not shown yet it will appear statically on the screen.
298 mLayer.SetVisible( false );
300 // Add the layer to the hierarchy.
303 // Add Backing (Dimmed effect).
304 mBacking = CreateBacking();
305 mLayer.Add( mBacking );
307 mPopupContainer = Actor::New();
308 mPopupContainer.SetName( "popupContainer" );
309 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
310 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
311 mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
312 mLayer.Add( mPopupContainer );
314 // Create the Popup layout to contain all main content.
315 mPopupLayout = Toolkit::TableView::New( 3, 1 );
317 // Adds the default background image.
318 const std::string imageDirPath = AssetManager::GetDaliImagePath();
319 SetPopupBackgroundImage( Toolkit::ImageView::New( imageDirPath + DEFAULT_BACKGROUND_IMAGE_FILE_NAME ) );
321 mPopupLayout.SetName( "popupLayoutTable" );
322 mPopupLayout.SetParentOrigin( ParentOrigin::CENTER );
323 mPopupLayout.SetAnchorPoint( AnchorPoint::CENTER );
325 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
326 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
327 mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f );
329 mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
330 mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
332 mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
334 mPopupContainer.Add( mPopupLayout );
336 // Any content after this point which is added to Self() will be re-parented to mContent.
337 mAlterAddedChild = true;
339 SetAsKeyboardFocusGroup( true );
344 mEntryAnimationData.Clear();
345 mExitAnimationData.Clear();
348 void Popup::LayoutAnimation()
350 // Perform setup based on the currently selected animation.
351 switch( mAnimationMode )
353 case Toolkit::Popup::ZOOM:
355 // Zoom animations start fully zoomed out.
356 mPopupContainer.SetScale( Vector3::ZERO );
360 case Toolkit::Popup::FADE:
362 // Fade animations start transparent.
363 mPopupContainer.SetOpacity( 0.0f );
367 case Toolkit::Popup::CUSTOM:
369 // Initialise the custom animation by playing to the end of it's exit animation instantly.
370 // EG. If it was zooming in, then we zoom out fully instantly so the zoom in works.
371 StartTransitionAnimation( false, true );
375 case Toolkit::Popup::NONE:
382 void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* false */ )
384 // Stop and recreate animation.
391 float duration = GetAnimationDuration();
393 // Setup variables ready to start the animations.
394 // If we are performing the animation instantaneously, we do not want to emit a signal.
399 // Setup variables and signal that we are starting the transition.
400 // Note: We signal even if the transition is instant so signal order is consistent.
401 mShowingSignal.Emit();
405 mHidingSignal.Emit();
409 // Perform chosen animation for the Popup.
410 switch( mAnimationMode )
412 case Toolkit::Popup::NONE:
414 mAnimation = Animation::New( 0.0f );
418 case Toolkit::Popup::ZOOM:
420 mAnimation = Animation::New( duration );
421 if( duration > Math::MACHINE_EPSILON_0 )
425 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( duration * 0.25f, duration * 0.75f ) );
429 // Zoom out animation is twice the speed. Modify the duration variable so the backing animation speed is modified also.
431 mAnimation.SetDuration( duration );
432 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ZERO, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration ) );
437 mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO );
442 case Toolkit::Popup::FADE:
444 mAnimation = Animation::New( duration );
445 if( duration > Math::MACHINE_EPSILON_0 )
449 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
453 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
458 mPopupContainer.SetOpacity( transitionIn ? 1.0f : 0.0f );
463 case Toolkit::Popup::CUSTOM:
465 // Use a user specified animation for in and out.
466 // Read the correct animation depending on entry or exit.
467 // Attempt to use animation data defined from script data.
468 Dali::AnimationData* animationData = transitionIn ? &mEntryAnimationData : &mExitAnimationData;
470 // Create a new animation from the pre-defined data in the AnimationData class.
471 // If there is no data, mAnimation is invalidated.
472 mAnimation = animationData->CreateAnimation( mPopupContainer, duration );
474 // If we don't have a valid animation, provide a blank one so play() can still function generically.
477 // No animation was configured (even though custom mode was specified). Create a dummy animation to avoid an exception.
478 mAnimation = Animation::New( 0.0f );
485 // Animate the backing, if enabled.
486 // This is set up last so that different animation modes can have an effect on the backing animation speed.
487 if( mBackingEnabled )
489 // Use the alpha from the user-specified color.
490 float targetAlpha = mBackingColor.a;
491 if( duration > Math::MACHINE_EPSILON_0 )
495 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), targetAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
499 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
504 mBacking.SetProperty( Actor::Property::COLOR_ALPHA, transitionIn ? targetAlpha : 0.0f );
508 // If we are performing the animation instantaneously, jump to the position directly and do not signal.
511 mAnimation.SetCurrentProgress( 1.0f );
514 else if( duration > Math::MACHINE_EPSILON_0 )
516 // Run the animation.
517 mAnimation.FinishedSignal().Connect( this, &Popup::OnDisplayChangeAnimationFinished );
522 // We did not use an animation to achive the transition.
523 // Trigger the state change directly.
524 DisplayStateChangeComplete();
528 void Popup::OnDisplayChangeAnimationFinished( Animation& source )
530 DisplayStateChangeComplete();
533 void Popup::DisplayStateChangeComplete()
535 // Remove contents from stage if completely hidden.
536 if( mDisplayState == Toolkit::Popup::HIDING )
538 mDisplayState = Toolkit::Popup::HIDDEN;
540 mLayer.SetVisible( false );
541 mPopupLayout.SetSensitive( false );
543 // Guard against destruction during signal emission.
544 Toolkit::Popup handle( GetOwner() );
545 mHiddenSignal.Emit();
547 else if( mDisplayState == Toolkit::Popup::SHOWING )
549 mDisplayState = Toolkit::Popup::SHOWN;
550 Toolkit::Popup handle( GetOwner() );
553 // Start a timer to auto-hide if enabled.
554 if( mAutoHideDelay > 0u )
556 mAutoHideTimer = Timer::New( mAutoHideDelay );
557 mAutoHideTimer.TickSignal().Connect( this, &Popup::OnAutoHideTimeReached );
558 mAutoHideTimer.Start();
563 bool Popup::OnAutoHideTimeReached()
565 // Display timer has expired, auto hide the popup exactly as if the user had clicked outside.
566 SetDisplayState( Toolkit::Popup::HIDDEN );
570 mAutoHideTimer.Stop();
571 mAutoHideTimer.TickSignal().Disconnect( this, &Popup::OnAutoHideTimeReached );
572 mAutoHideTimer.Reset();
577 void Popup::SetPopupBackgroundImage( Actor image )
579 // Removes any previous background.
580 if( mPopupBackgroundImage )
582 mPopupBackgroundImage.Unparent();
585 mTailImage.Unparent();
589 // Adds new background to the dialog.
590 mPopupBackgroundImage = image;
591 mPopupBackgroundImage.SetName( "popupBackgroundImage" );
592 mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
593 mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
595 // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
596 mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
598 // Set the popup border to be slightly larger than the layout contents.
599 UpdateBackgroundPositionAndSize();
601 const bool prevAlter = mAlterAddedChild;
602 mAlterAddedChild = false;
603 mPopupContainer.Add( mPopupBackgroundImage );
604 mPopupBackgroundImage.LowerToBottom();
605 mAlterAddedChild = prevAlter;
609 mPopupBackgroundImage.Add( mTailImage );
615 Actor Popup::GetPopupBackgroundImage() const
617 return mPopupBackgroundImage;
620 void Popup::SetTitle( Actor titleActor )
622 // Replaces the current title actor.
630 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
636 // Set up padding to give sensible default behaviour
637 // (an application developer can later override this if they wish).
638 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
640 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
647 Actor Popup::GetTitle() const
652 void Popup::SetContent( Actor content )
654 // Remove previous content actor.
657 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
659 // Keep a handle to the new content.
664 mContent.SetName( "popupContent" );
666 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
673 Actor Popup::GetContent() const
678 void Popup::SetFooter( Actor footer )
680 // Remove previous content actor.
683 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
686 // Keep a handle to the new content.
691 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
693 // The control container has a fixed height.
694 mPopupLayout.SetFitHeight( 2u );
695 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
702 Actor Popup::GetFooter() const
707 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
709 // Convert the 4-way state to a bool, true for show, false for hide.
710 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
712 // Ignore if we are already at the target display state.
713 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
718 // Convert the bool state to the actual display state to use.
719 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
723 // Update the state to indicate the current intent.
724 mDisplayState = Toolkit::Popup::SHOWING;
726 // We want the popup to have key input focus when it is displayed
729 // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
731 mLayer.SetVisible( true );
733 // Set up the layout if this is the first display or the layout has become dirty.
736 // Bake-in any style and layout options to create the Popup layout.
740 // Allow the popup to catch events.
741 mPopupLayout.SetSensitive( true );
743 // Handle the keyboard focus when popup is shown.
744 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
745 if( keyboardFocusManager )
747 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
749 if( Self().IsKeyboardFocusable() )
751 // Setup the actgor to start focus from.
753 if( mContent && mContent.IsKeyboardFocusable() )
755 // If the content is focusable, move the focus to the content.
756 focusActor = mContent;
758 else if( mFooter && mFooter.IsKeyboardFocusable() )
760 // If the footer is focusable, move the focus to the footer.
761 focusActor = mFooter;
765 DALI_LOG_WARNING( "There is no focusable in popup\n" );
770 keyboardFocusManager.SetCurrentFocusActor( focusActor );
777 mDisplayState = Toolkit::Popup::HIDING;
778 ClearKeyInputFocus();
780 // Restore the keyboard focus when popup is hidden.
781 if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
783 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
784 if( keyboardFocusManager )
786 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
791 // Perform animation.
792 StartTransitionAnimation( display );
795 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
797 return mDisplayState;
800 void Popup::LayoutPopup()
802 mLayoutDirty = false;
804 /* When animating in, we want to respect the origin applied to Self().
805 * For example, if zooming, not only will the final result be anchored to the
806 * selected point, but the zoom will originate from this point also.
808 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
817 mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
818 mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
820 // If there is only a title, use less padding.
823 if( !mContent && !mFooter )
825 mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
829 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
833 // Allow derived classes to perform any layout they may need to do.
836 // Update background visibility.
837 mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
839 // Create / destroy / position the tail as needed.
842 // Setup any layout and initialisation required for the selected animation.
848 void Popup::LayoutTail()
850 // Removes the tail actor.
851 if( mTailImage && mTailImage.GetParent() )
853 mTailImage.GetParent().Remove( mTailImage );
862 const Vector3& parentOrigin = GetTailPosition();
867 // depending on position of tail around ParentOrigin, a different tail image is used...
868 if( parentOrigin.y < Math::MACHINE_EPSILON_1 )
870 image = mTailUpImage;
871 anchorPoint = AnchorPoint::BOTTOM_CENTER;
872 position.y = mBackgroundBorder.top;
874 else if( parentOrigin.y > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
876 image = mTailDownImage;
877 anchorPoint = AnchorPoint::TOP_CENTER;
878 position.y = - mBackgroundBorder.bottom;
880 else if( parentOrigin.x < Math::MACHINE_EPSILON_1 )
882 image = mTailLeftImage;
883 anchorPoint = AnchorPoint::CENTER_RIGHT;
884 position.x = mBackgroundBorder.left;
886 else if( parentOrigin.x > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
888 image = mTailRightImage;
889 anchorPoint = AnchorPoint::CENTER_LEFT;
890 position.x = - mBackgroundBorder.right;
895 // Adds the tail actor.
896 mTailImage = Toolkit::ImageView::New( image );
897 mTailImage.SetName( "tailImage" );
898 mTailImage.SetParentOrigin( parentOrigin );
899 mTailImage.SetAnchorPoint( anchorPoint );
900 mTailImage.SetPosition( position );
902 if( mPopupBackgroundImage )
904 mPopupBackgroundImage.Add( mTailImage );
909 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
911 mContextualMode = mode;
915 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
917 return mContextualMode;
920 Toolkit::Control Popup::CreateBacking()
922 Toolkit::Control backing = Control::New();
923 backing.SetProperty( Toolkit::Control::Property::BACKGROUND,
924 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR )
925 .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) ) );
926 backing.SetName( "popupBacking" );
928 // Must always be positioned top-left of stage, regardless of parent.
929 backing.SetInheritPosition(false);
931 // Always the full size of the stage.
932 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
933 backing.SetSize( Stage::GetCurrent().GetSize() );
936 backing.SetSensitive( true );
938 // Default to being transparent.
939 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
940 backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
941 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
945 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
947 return mTouchedOutsideSignal;
950 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
952 return mShowingSignal;
955 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
960 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
962 return mHidingSignal;
965 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
967 return mHiddenSignal;
970 void Popup::SetTailVisibility( bool visible )
972 mTailVisible = visible;
976 const bool Popup::IsTailVisible() const
981 void Popup::SetTailPosition( Vector3 position )
983 mTailPosition = position;
987 const Vector3& Popup::GetTailPosition() const
989 return mTailPosition;
992 void Popup::SetAnimationDuration( float duration )
994 mAnimationDuration = duration;
998 float Popup::GetAnimationDuration() const
1000 return mAnimationDuration;
1003 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
1005 mAnimationMode = animationMode;
1006 mLayoutDirty = true;
1009 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
1011 return mAnimationMode;
1014 void Popup::SetEntryAnimationData( const Property::Map& map )
1016 mEntryAnimationData.Clear();
1017 Scripting::NewAnimation( map, mEntryAnimationData );
1020 void Popup::SetExitAnimationData( const Property::Map& map )
1022 mExitAnimationData.Clear();
1023 Scripting::NewAnimation( map, mExitAnimationData );
1026 void Popup::UpdateBackgroundPositionAndSize()
1028 if( mPopupBackgroundImage )
1030 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
1031 mPopupBackgroundImage.SetSizeModeFactor( Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) );
1033 // Adjust the position of the background so the transparent areas are set appropriately
1034 mPopupBackgroundImage.SetPosition( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f );
1038 void Popup::SetAutoHideDelay( int delay )
1040 mAutoHideDelay = delay;
1043 int Popup::GetAutoHideDelay() const
1045 return mAutoHideDelay;
1048 void Popup::SetBackingEnabled( bool enabled )
1050 mBackingEnabled = enabled;
1051 mLayoutDirty = true;
1054 const bool Popup::IsBackingEnabled() const
1056 return mBackingEnabled;
1059 void Popup::SetBackingColor( Vector4 color )
1061 mBackingColor = color;
1062 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1063 mLayoutDirty = true;
1066 const Vector4& Popup::GetBackingColor() const
1068 return mBackingColor;
1071 void Popup::SetTailUpImage( std::string image )
1073 mTailUpImage = image;
1074 mLayoutDirty = true;
1078 const std::string& Popup::GetTailUpImage() const
1080 return mTailUpImage;
1083 void Popup::SetTailDownImage( std::string image )
1085 mTailDownImage = image;
1086 mLayoutDirty = true;
1090 const std::string& Popup::GetTailDownImage() const
1092 return mTailDownImage;
1095 void Popup::SetTailLeftImage( std::string image )
1097 mTailLeftImage = image;
1098 mLayoutDirty = true;
1102 const std::string& Popup::GetTailLeftImage() const
1104 return mTailLeftImage;
1107 void Popup::SetTailRightImage( std::string image )
1109 mTailRightImage = image;
1110 mLayoutDirty = true;
1114 const std::string& Popup::GetTailRightImage() const
1116 return mTailRightImage;
1119 void Popup::SetTouchTransparent( bool enabled )
1121 mTouchTransparent = enabled;
1124 const bool Popup::IsTouchTransparent() const
1126 return mTouchTransparent;
1129 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1131 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1135 Popup& popupImpl( GetImpl( popup ) );
1137 switch ( propertyIndex )
1139 case Toolkit::Popup::Property::TITLE:
1141 Property::Map valueMap;
1142 if( value.Get( valueMap ) )
1144 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1148 case Toolkit::Popup::Property::CONTENT:
1150 Property::Map valueMap;
1151 if( value.Get( valueMap ) )
1153 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1157 case Toolkit::Popup::Property::FOOTER:
1159 Property::Map valueMap;
1160 if( value.Get( valueMap ) )
1162 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1166 case Toolkit::Popup::Property::DISPLAY_STATE:
1168 std::string valueString;
1169 if( value.Get( valueString ) )
1171 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1172 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1174 popupImpl.SetDisplayState( displayState );
1179 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1182 if( value.Get( valueBool ) )
1184 popupImpl.SetTouchTransparent( valueBool );
1188 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1191 if( value.Get( valueBool ) )
1193 popupImpl.SetTailVisibility( valueBool );
1197 case Toolkit::Popup::Property::TAIL_POSITION:
1199 Vector3 valueVector3;
1200 if( value.Get( valueVector3 ) )
1202 popupImpl.SetTailPosition( valueVector3 );
1206 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1208 std::string valueString;
1209 if( value.Get( valueString ) )
1211 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1212 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1214 popupImpl.SetContextualMode( contextualMode );
1219 case Toolkit::Popup::Property::ANIMATION_DURATION:
1222 if( value.Get( valueFloat ) )
1224 popupImpl.SetAnimationDuration( valueFloat );
1228 case Toolkit::Popup::Property::ANIMATION_MODE:
1230 std::string valueString;
1231 if( value.Get( valueString ) )
1233 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1234 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1236 popupImpl.SetAnimationMode( animationMode );
1241 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1243 Property::Map valueMap;
1244 if( value.Get( valueMap ) )
1246 popupImpl.SetEntryAnimationData( valueMap );
1250 case Toolkit::Popup::Property::EXIT_ANIMATION:
1252 Property::Map valueMap;
1253 if( value.Get( valueMap ) )
1255 popupImpl.SetExitAnimationData( valueMap );
1259 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1262 if( value.Get( valueInt ) )
1264 popupImpl.SetAutoHideDelay( valueInt );
1268 case Toolkit::Popup::Property::BACKING_ENABLED:
1271 if( value.Get( valueBool ) )
1273 popupImpl.SetBackingEnabled( valueBool );
1277 case Toolkit::Popup::Property::BACKING_COLOR:
1279 Vector4 valueVector4;
1280 if( value.Get( valueVector4 ) )
1282 popupImpl.SetBackingColor( valueVector4 );
1286 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1288 std::string valueString;
1289 if( value.Get( valueString ) )
1291 Toolkit::ImageView actor = Toolkit::ImageView::New( valueString );
1292 popupImpl.SetPopupBackgroundImage( actor );
1296 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1298 bool valueUpdated = false;
1300 Vector4 valueVector4;
1301 if( value.Get( popupImpl.mBackgroundBorder ) )
1303 valueUpdated = true;
1305 else if( value.Get( valueVector4 ) )
1307 popupImpl.mBackgroundBorder.left = valueVector4.x;
1308 popupImpl.mBackgroundBorder.right = valueVector4.y;
1309 popupImpl.mBackgroundBorder.bottom = valueVector4.z;
1310 popupImpl.mBackgroundBorder.top = valueVector4.w;
1311 valueUpdated = true;
1316 popupImpl.LayoutTail(); // Update the tail if required
1317 popupImpl.UpdateBackgroundPositionAndSize(); // Update the background's size and position
1321 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1323 std::string valueString;
1324 if( value.Get( valueString ) )
1326 popupImpl.SetTailUpImage( valueString );
1330 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1332 std::string valueString;
1333 if( value.Get( valueString ) )
1335 popupImpl.SetTailDownImage( valueString );
1339 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1341 std::string valueString;
1342 if( value.Get( valueString ) )
1344 popupImpl.SetTailLeftImage( valueString );
1348 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1350 std::string valueString;
1351 if( value.Get( valueString ) )
1353 popupImpl.SetTailRightImage( valueString );
1361 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1363 Property::Value value;
1365 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1369 Popup& popupImpl( GetImpl( popup ) );
1371 switch ( propertyIndex )
1373 case Toolkit::Popup::Property::TITLE:
1376 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1380 case Toolkit::Popup::Property::CONTENT:
1383 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1387 case Toolkit::Popup::Property::FOOTER:
1390 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1394 case Toolkit::Popup::Property::DISPLAY_STATE:
1396 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1399 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1401 value = popupImpl.IsTouchTransparent();
1404 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1406 value = popupImpl.IsTailVisible();
1409 case Toolkit::Popup::Property::TAIL_POSITION:
1411 value = popupImpl.GetTailPosition();
1414 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1416 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1419 case Toolkit::Popup::Property::ANIMATION_DURATION:
1421 value = popupImpl.GetAnimationDuration();
1424 case Toolkit::Popup::Property::ANIMATION_MODE:
1426 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1429 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1431 // Note: Cannot retrieve property map from animation.
1436 case Toolkit::Popup::Property::EXIT_ANIMATION:
1438 // Note: Cannot retrieve property map from animation.
1443 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1445 value = popupImpl.GetAutoHideDelay();
1448 case Toolkit::Popup::Property::BACKING_ENABLED:
1450 value = popupImpl.IsBackingEnabled();
1453 case Toolkit::Popup::Property::BACKING_COLOR:
1455 value = popupImpl.GetBackingColor();
1458 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1460 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() );
1463 value = imageView.GetProperty( Toolkit::ImageView::Property::IMAGE );
1467 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1469 value = popupImpl.mBackgroundBorder;
1472 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1474 value = popupImpl.GetTailUpImage();
1477 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1479 value = popupImpl.GetTailDownImage();
1482 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1484 value = popupImpl.GetTailLeftImage();
1487 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1489 value = popupImpl.GetTailRightImage();
1498 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1500 Dali::BaseHandle handle( object );
1502 bool connected( true );
1503 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1505 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1507 popup.OutsideTouchedSignal().Connect( tracker, functor );
1509 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1511 popup.ShowingSignal().Connect( tracker, functor );
1513 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1515 popup.ShownSignal().Connect( tracker, functor );
1517 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1519 popup.HidingSignal().Connect( tracker, functor );
1521 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1523 popup.HiddenSignal().Connect( tracker, functor );
1527 // signalName does not match any signal
1534 bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
1536 // Allow events to pass through if touch transparency is enabled.
1537 if( mTouchTransparent )
1542 if( touch.GetPointCount() > 0 )
1544 if( touch.GetState( 0 ) == PointState::DOWN )
1546 // Guard against destruction during signal emission.
1547 Toolkit::Popup handle( GetOwner() );
1549 mTouchedOutsideSignal.Emit();
1553 // Block anything behind backing becoming touched.
1554 mLayer.SetTouchConsumed( true );
1558 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1560 // Allow events to pass through if touch transparency is enabled.
1561 if( mTouchTransparent )
1566 // Consume wheel event in dimmed backing actor.
1567 mLayer.SetTouchConsumed( true );
1571 bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
1573 // Allow events to pass through if touch transparency is enabled.
1574 if( mTouchTransparent )
1579 // Consume event (stops backing actor receiving touch events)
1580 mLayer.SetTouchConsumed( true );
1584 void Popup::OnStageConnection( int depth )
1586 mLayoutDirty = true;
1589 Control::OnStageConnection( depth );
1592 void Popup::OnChildAdd( Actor& child )
1594 // Re-parent any children added by user to the body layer.
1595 if( mAlterAddedChild )
1597 SetContent( child );
1601 mLayoutDirty = true;
1605 Control::OnChildAdd( child );
1608 void Popup::LayoutContext( const Vector2& size )
1610 // Do nothing if not in a contextual mode (or there is no parent context).
1611 Actor self = Self();
1612 Actor parent = self.GetParent();
1613 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1618 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
1619 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1620 // mode to allow code-reuse of the bound checking code (for maintainability).
1621 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
1623 // Setup with some pre-calculations for speed.
1624 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1625 Vector3 parentPosition( parent.GetCurrentPosition() );
1626 Vector2 halfSize( size / 2.0f );
1627 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1628 Vector3 newPosition( Vector3::ZERO );
1630 // Perform different positioning based on the specified contextual layout mode.
1631 switch( mContextualMode )
1633 case Toolkit::Popup::BELOW:
1635 newPosition.x += halfSize.x - halfParentSize.x;
1636 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1639 case Toolkit::Popup::ABOVE:
1641 newPosition.x += halfSize.x - halfParentSize.x;
1642 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1645 case Toolkit::Popup::RIGHT:
1647 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1648 newPosition.y += halfSize.y - halfParentSize.y;
1651 case Toolkit::Popup::LEFT:
1653 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1654 newPosition.y += halfSize.y - halfParentSize.y;
1657 case Toolkit::Popup::NON_CONTEXTUAL:
1659 // Code won't reach here (caught earlier).
1664 // On-screen position checking.
1665 // Check new position is not too far right. If so, correct it.
1666 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1667 // the right check and we at least see the left portion of the popup (as this is more useful).
1668 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1670 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1672 // Check new position is not too far left. If so, correct it.
1673 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1675 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1677 // Check new position is not too far down. If so, correct it.
1678 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1680 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1682 // Check new position is not too far up. If so, correct it.
1683 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1685 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1688 // Set the final position.
1689 mPopupContainer.SetPosition( newPosition );
1692 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1694 Vector2 useSize( size );
1696 // Use the Popup layouts size, unless requested to use a fixed size.
1697 // In which case take the size set for the Popup itself.
1698 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1699 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1701 // Width calculations:
1702 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1704 // If we using a child-based policy, take the size from the popup layout.
1705 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1706 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1708 mPopupLayout.SetFitWidth( 0u );
1712 // If we using a parent-based policy, take the size from the popup object itself (self).
1713 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1715 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1718 // Height calculations:
1719 // Title: Let the title be as high as it needs to be.
1720 mPopupLayout.SetFitHeight( 0u );
1722 // Footer: Convert the footer's resize policy to a TableView row policy.
1725 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1726 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1727 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1729 mPopupLayout.SetFitHeight( 2u );
1731 else if( footerHeightPolicy == ResizePolicy::FIXED )
1733 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1737 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1742 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1745 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1746 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1748 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1750 // Let both the contents expand as necessary.
1751 mPopupLayout.SetFitHeight( 1u );
1752 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1756 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1758 // Let the content expand to fill the remaining space.
1759 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1760 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1763 // Relayout the popup-layout to give it it's new size this frame.
1764 container.Add( mPopupLayout, useSize );
1768 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1771 // Perform contextual layout setup if required.
1772 // This is done each time in case the parent moves.
1773 // This will have no effect if no contextual mode is selected.
1774 LayoutContext( useSize );
1777 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1779 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1780 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1782 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1785 mLayoutDirty = true;
1789 Vector3 Popup::GetNaturalSize()
1791 return mPopupLayout.GetNaturalSize();
1794 float Popup::GetHeightForWidth( float width )
1796 return mPopupLayout.GetHeightForWidth( width );
1799 float Popup::GetWidthForHeight( float height )
1801 return mPopupLayout.GetWidthForHeight( height );
1804 bool Popup::OnKeyEvent( const KeyEvent& event )
1806 // Allow events to pass through if touch transparency is enabled.
1807 if( mTouchTransparent )
1812 bool consumed = false;
1814 if( event.state == KeyEvent::Down )
1816 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
1818 SetDisplayState( Toolkit::Popup::HIDDEN );
1826 void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors )
1830 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1831 bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
1833 if( parent.IsKeyboardFocusable() || layoutControl )
1835 focusableActors.push_back( parent );
1837 if( !layoutControl )
1839 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1841 Actor child( parent.GetChildAt( i ) );
1842 AddFocusableChildrenRecursive( child, focusableActors );
1849 void Popup::AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors )
1853 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1854 if( !GetImplementation( control ).IsKeyboardNavigationSupported() )
1856 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1858 Actor child( parent.GetChildAt( i ) );
1859 AddFocusableChildrenRecursive( child, focusableActors );
1864 focusableActors.push_back( parent );
1869 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1871 std::string currentStr;
1872 if( currentFocusedActor )
1874 currentStr = currentFocusedActor.GetName();
1877 Actor nextFocusableActor( currentFocusedActor );
1878 Actor currentFocusGroup;
1879 if( currentFocusedActor )
1881 currentFocusGroup = KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor );
1884 // TODO: Needs to be optimised
1885 // The following statement checks that if we have a current focused actor, then the current focus group is not the popup content or footer.
1886 // This is to detect if the focus is currently outside the popup, and if so, move it inside.
1887 if( !currentFocusedActor ||
1888 ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
1890 // The current focused actor is not within popup.
1891 if( mContent && mContent.IsKeyboardFocusable() )
1893 // If the content is focusable, move the focus to the content.
1894 nextFocusableActor = mContent;
1896 else if( mFooter && mFooter.IsKeyboardFocusable() )
1898 // If the footer is focusable, move the focus to the footer.
1899 nextFocusableActor = mFooter;
1904 // Rebuild the focus chain because controls or content can be added or removed dynamically
1905 std::vector< Actor > focusableActors;
1907 AddFocusableChildren( mContent, focusableActors );
1908 AddFocusableChildren( mFooter, focusableActors );
1910 std::vector< Actor >::iterator endIterator = focusableActors.end();
1911 std::vector< Actor >::iterator currentIterator = focusableActors.begin();
1912 for( std::vector< Actor >::iterator iterator = focusableActors.begin(); iterator != endIterator; ++iterator )
1914 if( currentFocusedActor == *iterator )
1916 currentIterator = iterator;
1920 if( currentIterator != endIterator )
1924 case Toolkit::Control::KeyboardFocus::LEFT:
1926 if( currentIterator == focusableActors.begin() )
1928 nextFocusableActor = *( endIterator - 1 );
1932 nextFocusableActor = *( currentIterator - 1 );
1936 case Toolkit::Control::KeyboardFocus::RIGHT:
1938 if( currentIterator == endIterator - 1 )
1940 nextFocusableActor = *( focusableActors.begin() );
1944 nextFocusableActor = *( currentIterator + 1 );
1949 case Toolkit::Control::KeyboardFocus::UP:
1951 nextFocusableActor = *( focusableActors.begin() );
1955 case Toolkit::Control::KeyboardFocus::DOWN:
1957 nextFocusableActor = *( endIterator - 1 );
1967 if( !nextFocusableActor )
1969 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1974 return nextFocusableActor;
1978 } // namespace Internal
1980 } // namespace Toolkit