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, "popupBackgroundBorder", RECTANGLE, POPUP_BACKGROUND_BORDER )
133 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE )
136 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE )
139 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE )
140 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING )
141 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN )
142 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING )
143 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
145 DALI_TYPE_REGISTRATION_END()
147 // Named type registration.
149 // Toast Popup: Non-modal popup that displays information at the bottom of the screen.
150 TypeRegistration typeRegistrationToast( "PopupToast", typeid( Toolkit::Popup ), CreateToast );
152 // Enumeration to / from string conversion tables
154 const Scripting::StringEnum DisplayStateTable[] = {
155 { "SHOWING", Toolkit::Popup::SHOWING },
156 { "SHOWN", Toolkit::Popup::SHOWN },
157 { "HIDING", Toolkit::Popup::HIDING },
158 { "HIDDEN", Toolkit::Popup::HIDDEN },
159 }; const unsigned int DisplayStateTableCount = sizeof( DisplayStateTable ) / sizeof( DisplayStateTable[0] );
161 const Scripting::StringEnum AnimationModeTable[] = {
162 { "NONE", Toolkit::Popup::NONE },
163 { "ZOOM", Toolkit::Popup::ZOOM },
164 { "FADE", Toolkit::Popup::FADE },
165 { "CUSTOM", Toolkit::Popup::CUSTOM },
166 }; const unsigned int AnimationModeTableCount = sizeof( AnimationModeTable ) / sizeof( AnimationModeTable[0] );
168 const Scripting::StringEnum ContextualModeTable[] = {
169 { "NON_CONTEXTUAL", Toolkit::Popup::NON_CONTEXTUAL },
170 { "ABOVE", Toolkit::Popup::ABOVE },
171 { "RIGHT", Toolkit::Popup::RIGHT },
172 { "BELOW", Toolkit::Popup::BELOW },
173 { "LEFT", Toolkit::Popup::LEFT },
174 }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] );
177 const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent.
178 const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations.
179 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
180 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
181 const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position.
183 // Contextual defaults.
184 const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent.
185 const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges.
187 // Popup style defaults.
188 const char* DEFAULT_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "00_popup_bg.9.png"; ///< Background image.
189 const char* DEFAULT_TAIL_UP_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_up.png"; ///< Tail up image.
190 const char* DEFAULT_TAIL_DOWN_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_down.png"; ///< Tail down image.
191 const char* DEFAULT_TAIL_LEFT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_left.png"; ///< Tail left image.
192 const char* DEFAULT_TAIL_RIGHT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_right.png"; ///< Tail right image.
194 const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing.
195 const Rect<int> DEFAULT_BACKGROUND_BORDER( 17, 17, 13, 13 ); ///< Default border of the background.
196 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).
197 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).
198 const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area.
199 const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default.
201 } // Unnamed namespace
207 Dali::Toolkit::Popup Popup::New()
209 // Create the implementation
210 PopupPtr popup( new Popup() );
212 // Pass ownership to CustomActor via derived handle.
213 Dali::Toolkit::Popup handle( *popup );
215 // Second-phase initialisation of the implementation.
216 // This can only be done after the CustomActor connection has been made.
223 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
224 mTouchedOutsideSignal(),
232 mPreviousFocusedActor(),
236 mAlterAddedChild( false ),
237 mLayoutDirty( true ),
239 mTouchTransparent( false ),
243 mDisplayState( Toolkit::Popup::HIDDEN ), // Hidden until shown with SetDisplayState()
244 mTailVisible( false ),
245 mTailPosition( DEFAULT_TAIL_POSITION ),
246 mContextualMode( Toolkit::Popup::NON_CONTEXTUAL ),
247 mAnimationDuration( DEFAULT_POPUP_ANIMATION_DURATION ),
248 mAnimationMode( Toolkit::Popup::FADE ),
249 mEntryAnimationData(),
250 mExitAnimationData(),
252 mBackingEnabled( true ),
253 mBackingColor( DEFAULT_BACKING_COLOR ),
254 mPopupBackgroundImage(),
255 mBackgroundBorder( DEFAULT_BACKGROUND_BORDER ),
257 mTailUpImage( DEFAULT_TAIL_UP_IMAGE_PATH ),
258 mTailDownImage( DEFAULT_TAIL_DOWN_IMAGE_PATH ),
259 mTailLeftImage( DEFAULT_TAIL_LEFT_IMAGE_PATH ),
260 mTailRightImage( DEFAULT_TAIL_RIGHT_IMAGE_PATH )
262 SetKeyboardNavigationSupport( true );
265 void Popup::OnInitialize()
268 self.SetName( "popup" );
270 // Apply some default resizing rules.
271 self.SetParentOrigin( ParentOrigin::CENTER );
272 self.SetAnchorPoint( AnchorPoint::CENTER );
274 self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
275 self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
276 self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
278 // Create a new layer so all Popup components can appear above all other actors.
279 mLayer = Layer::New();
280 mLayer.SetName( "popupLayer" );
282 mLayer.SetParentOrigin( ParentOrigin::CENTER );
283 mLayer.SetAnchorPoint( AnchorPoint::CENTER );
284 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
286 // Important to set as invisible as otherwise, if the popup is parented,
287 // but not shown yet it will appear statically on the screen.
288 mLayer.SetVisible( false );
290 // Add the layer to the hierarchy.
293 // Add Backing (Dimmed effect).
294 mBacking = CreateBacking();
295 mLayer.Add( mBacking );
297 mPopupContainer = Actor::New();
298 mPopupContainer.SetName( "popupContainer" );
299 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
300 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
301 mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
302 mLayer.Add( mPopupContainer );
304 // Create the Popup layout to contain all main content.
305 mPopupLayout = Toolkit::TableView::New( 3, 1 );
307 // Adds the default background image.
308 SetPopupBackgroundImage( Toolkit::ImageView::New( DEFAULT_BACKGROUND_IMAGE_PATH ) );
310 mPopupLayout.SetName( "popupLayoutTable" );
311 mPopupLayout.SetParentOrigin( ParentOrigin::CENTER );
312 mPopupLayout.SetAnchorPoint( AnchorPoint::CENTER );
314 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
315 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
316 mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f );
318 mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
319 mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
321 mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
323 mPopupContainer.Add( mPopupLayout );
325 // Any content after this point which is added to Self() will be re-parented to mContent.
326 mAlterAddedChild = true;
328 SetAsKeyboardFocusGroup( true );
333 mEntryAnimationData.Clear();
334 mExitAnimationData.Clear();
337 void Popup::LayoutAnimation()
339 // Perform setup based on the currently selected animation.
340 switch( mAnimationMode )
342 case Toolkit::Popup::ZOOM:
344 // Zoom animations start fully zoomed out.
345 mPopupContainer.SetScale( Vector3::ZERO );
349 case Toolkit::Popup::FADE:
351 // Fade animations start transparent.
352 mPopupContainer.SetOpacity( 0.0f );
356 case Toolkit::Popup::CUSTOM:
358 // Initialise the custom animation by playing to the end of it's exit animation instantly.
359 // EG. If it was zooming in, then we zoom out fully instantly so the zoom in works.
360 StartTransitionAnimation( false, true );
364 case Toolkit::Popup::NONE:
371 void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* false */ )
373 // Stop and recreate animation.
380 float duration = GetAnimationDuration();
382 // Setup variables ready to start the animations.
383 // If we are performing the animation instantaneously, we do not want to emit a signal.
388 // Setup variables and signal that we are starting the transition.
389 // Note: We signal even if the transition is instant so signal order is consistent.
390 mShowingSignal.Emit();
394 mHidingSignal.Emit();
398 // Perform chosen animation for the Popup.
399 switch( mAnimationMode )
401 case Toolkit::Popup::NONE:
403 mAnimation = Animation::New( 0.0f );
407 case Toolkit::Popup::ZOOM:
409 mAnimation = Animation::New( duration );
410 if( duration > Math::MACHINE_EPSILON_0 )
414 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( duration * 0.25f, duration * 0.75f ) );
418 // Zoom out animation is twice the speed. Modify the duration variable so the backing animation speed is modified also.
420 mAnimation.SetDuration( duration );
421 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ZERO, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration ) );
426 mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO );
431 case Toolkit::Popup::FADE:
433 mAnimation = Animation::New( duration );
434 if( duration > Math::MACHINE_EPSILON_0 )
438 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
442 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
447 mPopupContainer.SetOpacity( transitionIn ? 1.0f : 0.0f );
452 case Toolkit::Popup::CUSTOM:
454 // Use a user specified animation for in and out.
455 // Read the correct animation depending on entry or exit.
456 // Attempt to use animation data defined from script data.
457 Dali::AnimationData* animationData = transitionIn ? &mEntryAnimationData : &mExitAnimationData;
459 // Create a new animation from the pre-defined data in the AnimationData class.
460 // If there is no data, mAnimation is invalidated.
461 mAnimation = animationData->CreateAnimation( mPopupContainer, duration );
463 // If we don't have a valid animation, provide a blank one so play() can still function generically.
466 // No animation was configured (even though custom mode was specified). Create a dummy animation to avoid an exception.
467 mAnimation = Animation::New( 0.0f );
474 // Animate the backing, if enabled.
475 // This is set up last so that different animation modes can have an effect on the backing animation speed.
476 if( mBackingEnabled )
478 // Use the alpha from the user-specified color.
479 float targetAlpha = mBackingColor.a;
480 if( duration > Math::MACHINE_EPSILON_0 )
484 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), targetAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
488 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
493 mBacking.SetProperty( Actor::Property::COLOR_ALPHA, transitionIn ? targetAlpha : 0.0f );
497 // If we are performing the animation instantaneously, jump to the position directly and do not signal.
500 mAnimation.SetCurrentProgress( 1.0f );
503 else if( duration > Math::MACHINE_EPSILON_0 )
505 // Run the animation.
506 mAnimation.FinishedSignal().Connect( this, &Popup::OnDisplayChangeAnimationFinished );
511 // We did not use an animation to achive the transition.
512 // Trigger the state change directly.
513 DisplayStateChangeComplete();
517 void Popup::OnDisplayChangeAnimationFinished( Animation& source )
519 DisplayStateChangeComplete();
522 void Popup::DisplayStateChangeComplete()
524 // Remove contents from stage if completely hidden.
525 if( mDisplayState == Toolkit::Popup::HIDING )
527 mDisplayState = Toolkit::Popup::HIDDEN;
529 mLayer.SetVisible( false );
530 mPopupLayout.SetSensitive( false );
532 // Guard against destruction during signal emission.
533 Toolkit::Popup handle( GetOwner() );
534 mHiddenSignal.Emit();
536 else if( mDisplayState == Toolkit::Popup::SHOWING )
538 mDisplayState = Toolkit::Popup::SHOWN;
539 Toolkit::Popup handle( GetOwner() );
542 // Start a timer to auto-hide if enabled.
543 if( mAutoHideDelay > 0u )
545 mAutoHideTimer = Timer::New( mAutoHideDelay );
546 mAutoHideTimer.TickSignal().Connect( this, &Popup::OnAutoHideTimeReached );
547 mAutoHideTimer.Start();
552 bool Popup::OnAutoHideTimeReached()
554 // Display timer has expired, auto hide the popup exactly as if the user had clicked outside.
555 SetDisplayState( Toolkit::Popup::HIDDEN );
559 mAutoHideTimer.Stop();
560 mAutoHideTimer.TickSignal().Disconnect( this, &Popup::OnAutoHideTimeReached );
561 mAutoHideTimer.Reset();
566 void Popup::SetPopupBackgroundImage( Actor image )
568 // Removes any previous background.
569 if( mPopupBackgroundImage )
571 mPopupBackgroundImage.Unparent();
574 mTailImage.Unparent();
578 // Adds new background to the dialog.
579 mPopupBackgroundImage = image;
580 mPopupBackgroundImage.SetName( "popupBackgroundImage" );
581 mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
582 mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
584 // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
585 mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
587 // Set the popup border to be slightly larger than the layout contents.
588 UpdateBackgroundPositionAndSize();
590 const bool prevAlter = mAlterAddedChild;
591 mAlterAddedChild = false;
592 mPopupContainer.Add( mPopupBackgroundImage );
593 mAlterAddedChild = prevAlter;
597 mPopupBackgroundImage.Add( mTailImage );
603 Actor Popup::GetPopupBackgroundImage() const
605 return mPopupBackgroundImage;
608 void Popup::SetTitle( Actor titleActor )
610 // Replaces the current title actor.
618 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
624 // Set up padding to give sensible default behaviour
625 // (an application developer can later override this if they wish).
626 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
628 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
635 Actor Popup::GetTitle() const
640 void Popup::SetContent( Actor content )
642 // Remove previous content actor.
645 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
647 // Keep a handle to the new content.
652 mContent.SetName( "popupContent" );
654 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
661 Actor Popup::GetContent() const
666 void Popup::SetFooter( Actor footer )
668 // Remove previous content actor.
671 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
674 // Keep a handle to the new content.
679 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
681 // The control container has a fixed height.
682 mPopupLayout.SetFitHeight( 2u );
683 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
690 Actor Popup::GetFooter() const
695 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
697 // Convert the 4-way state to a bool, true for show, false for hide.
698 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
700 // Ignore if we are already at the target display state.
701 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
706 // Convert the bool state to the actual display state to use.
707 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
711 // Update the state to indicate the current intent.
712 mDisplayState = Toolkit::Popup::SHOWING;
714 // We want the popup to have key input focus when it is displayed
717 // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
719 mLayer.SetVisible( true );
721 // Set up the layout if this is the first display or the layout has become dirty.
724 // Bake-in any style and layout options to create the Popup layout.
728 // Allow the popup to catch events.
729 mPopupLayout.SetSensitive( true );
731 // Handle the keyboard focus when popup is shown.
732 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
733 if( keyboardFocusManager )
735 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
737 if( Self().IsKeyboardFocusable() )
739 // Setup the actgor to start focus from.
741 if( mContent && mContent.IsKeyboardFocusable() )
743 // If the content is focusable, move the focus to the content.
744 focusActor = mContent;
746 else if( mFooter && mFooter.IsKeyboardFocusable() )
748 // If the footer is focusable, move the focus to the footer.
749 focusActor = mFooter;
753 DALI_LOG_WARNING( "There is no focusable in popup\n" );
758 keyboardFocusManager.SetCurrentFocusActor( focusActor );
765 mDisplayState = Toolkit::Popup::HIDING;
766 ClearKeyInputFocus();
768 // Restore the keyboard focus when popup is hidden.
769 if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
771 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
772 if( keyboardFocusManager )
774 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
779 // Perform animation.
780 StartTransitionAnimation( display );
783 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
785 return mDisplayState;
788 void Popup::LayoutPopup()
790 mLayoutDirty = false;
792 /* When animating in, we want to respect the origin applied to Self().
793 * For example, if zooming, not only will the final result be anchored to the
794 * selected point, but the zoom will originate from this point also.
796 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
805 mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
806 mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
808 // If there is only a title, use less padding.
811 if( !mContent && !mFooter )
813 mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
817 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
821 // Allow derived classes to perform any layout they may need to do.
824 // Update background visibility.
825 mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
827 // Create / destroy / position the tail as needed.
830 // Setup any layout and initialisation required for the selected animation.
836 void Popup::LayoutTail()
838 // Removes the tail actor.
839 if( mTailImage && mTailImage.GetParent() )
841 mTailImage.GetParent().Remove( mTailImage );
850 const Vector3& parentOrigin = GetTailPosition();
855 // depending on position of tail around ParentOrigin, a different tail image is used...
856 if( parentOrigin.y < Math::MACHINE_EPSILON_1 )
858 image = mTailUpImage;
859 anchorPoint = AnchorPoint::BOTTOM_CENTER;
860 position.y = mBackgroundBorder.top;
862 else if( parentOrigin.y > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
864 image = mTailDownImage;
865 anchorPoint = AnchorPoint::TOP_CENTER;
866 position.y = - mBackgroundBorder.bottom;
868 else if( parentOrigin.x < Math::MACHINE_EPSILON_1 )
870 image = mTailLeftImage;
871 anchorPoint = AnchorPoint::CENTER_RIGHT;
872 position.x = mBackgroundBorder.left;
874 else if( parentOrigin.x > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
876 image = mTailRightImage;
877 anchorPoint = AnchorPoint::CENTER_LEFT;
878 position.x = - mBackgroundBorder.right;
883 // Adds the tail actor.
884 mTailImage = Toolkit::ImageView::New( image );
885 mTailImage.SetName( "tailImage" );
886 mTailImage.SetParentOrigin( parentOrigin );
887 mTailImage.SetAnchorPoint( anchorPoint );
888 mTailImage.SetPosition( position );
890 if( mPopupBackgroundImage )
892 mPopupBackgroundImage.Add( mTailImage );
897 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
899 mContextualMode = mode;
903 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
905 return mContextualMode;
908 Toolkit::Control Popup::CreateBacking()
910 Toolkit::Control backing = Control::New();
911 backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
912 backing.SetName( "popupBacking" );
914 // Must always be positioned top-left of stage, regardless of parent.
915 backing.SetInheritPosition(false);
916 backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
918 // Always the full size of the stage.
919 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
920 backing.SetSize( Stage::GetCurrent().GetSize() );
923 backing.SetSensitive( true );
925 // Default to being transparent.
926 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
927 backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
928 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
932 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
934 return mTouchedOutsideSignal;
937 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
939 return mShowingSignal;
942 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
947 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
949 return mHidingSignal;
952 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
954 return mHiddenSignal;
957 void Popup::SetTailVisibility( bool visible )
959 mTailVisible = visible;
963 const bool Popup::IsTailVisible() const
968 void Popup::SetTailPosition( Vector3 position )
970 mTailPosition = position;
974 const Vector3& Popup::GetTailPosition() const
976 return mTailPosition;
979 void Popup::SetAnimationDuration( float duration )
981 mAnimationDuration = duration;
985 float Popup::GetAnimationDuration() const
987 return mAnimationDuration;
990 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
992 mAnimationMode = animationMode;
996 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
998 return mAnimationMode;
1001 void Popup::SetEntryAnimationData( const Property::Map& map )
1003 mEntryAnimationData.Clear();
1004 Scripting::NewAnimation( map, mEntryAnimationData );
1007 void Popup::SetExitAnimationData( const Property::Map& map )
1009 mExitAnimationData.Clear();
1010 Scripting::NewAnimation( map, mExitAnimationData );
1013 void Popup::UpdateBackgroundPositionAndSize()
1015 if( mPopupBackgroundImage )
1017 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
1018 mPopupBackgroundImage.SetSizeModeFactor( Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) );
1020 // Adjust the position of the background so the transparent areas are set appropriately
1021 mPopupBackgroundImage.SetPosition( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f );
1025 void Popup::SetAutoHideDelay( int delay )
1027 mAutoHideDelay = delay;
1030 int Popup::GetAutoHideDelay() const
1032 return mAutoHideDelay;
1035 void Popup::SetBackingEnabled( bool enabled )
1037 mBackingEnabled = enabled;
1038 mLayoutDirty = true;
1041 const bool Popup::IsBackingEnabled() const
1043 return mBackingEnabled;
1046 void Popup::SetBackingColor( Vector4 color )
1048 mBackingColor = color;
1049 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1050 mLayoutDirty = true;
1053 const Vector4& Popup::GetBackingColor() const
1055 return mBackingColor;
1058 void Popup::SetTailUpImage( std::string image )
1060 mTailUpImage = image;
1061 mLayoutDirty = true;
1065 const std::string& Popup::GetTailUpImage() const
1067 return mTailUpImage;
1070 void Popup::SetTailDownImage( std::string image )
1072 mTailDownImage = image;
1073 mLayoutDirty = true;
1077 const std::string& Popup::GetTailDownImage() const
1079 return mTailDownImage;
1082 void Popup::SetTailLeftImage( std::string image )
1084 mTailLeftImage = image;
1085 mLayoutDirty = true;
1089 const std::string& Popup::GetTailLeftImage() const
1091 return mTailLeftImage;
1094 void Popup::SetTailRightImage( std::string image )
1096 mTailRightImage = image;
1097 mLayoutDirty = true;
1101 const std::string& Popup::GetTailRightImage() const
1103 return mTailRightImage;
1106 void Popup::SetTouchTransparent( bool enabled )
1108 mTouchTransparent = enabled;
1111 const bool Popup::IsTouchTransparent() const
1113 return mTouchTransparent;
1116 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1118 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1122 Popup& popupImpl( GetImpl( popup ) );
1124 switch ( propertyIndex )
1126 case Toolkit::Popup::Property::TITLE:
1128 Property::Map valueMap;
1129 if( value.Get( valueMap ) )
1131 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1135 case Toolkit::Popup::Property::CONTENT:
1137 Property::Map valueMap;
1138 if( value.Get( valueMap ) )
1140 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1144 case Toolkit::Popup::Property::FOOTER:
1146 Property::Map valueMap;
1147 if( value.Get( valueMap ) )
1149 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1153 case Toolkit::Popup::Property::DISPLAY_STATE:
1155 std::string valueString;
1156 if( value.Get( valueString ) )
1158 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1159 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1161 popupImpl.SetDisplayState( displayState );
1166 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1169 if( value.Get( valueBool ) )
1171 popupImpl.SetTouchTransparent( valueBool );
1175 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1178 if( value.Get( valueBool ) )
1180 popupImpl.SetTailVisibility( valueBool );
1184 case Toolkit::Popup::Property::TAIL_POSITION:
1186 Vector3 valueVector3;
1187 if( value.Get( valueVector3 ) )
1189 popupImpl.SetTailPosition( valueVector3 );
1193 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1195 std::string valueString;
1196 if( value.Get( valueString ) )
1198 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1199 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1201 popupImpl.SetContextualMode( contextualMode );
1206 case Toolkit::Popup::Property::ANIMATION_DURATION:
1209 if( value.Get( valueFloat ) )
1211 popupImpl.SetAnimationDuration( valueFloat );
1215 case Toolkit::Popup::Property::ANIMATION_MODE:
1217 std::string valueString;
1218 if( value.Get( valueString ) )
1220 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1221 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1223 popupImpl.SetAnimationMode( animationMode );
1228 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1230 Property::Map valueMap;
1231 if( value.Get( valueMap ) )
1233 popupImpl.SetEntryAnimationData( valueMap );
1237 case Toolkit::Popup::Property::EXIT_ANIMATION:
1239 Property::Map valueMap;
1240 if( value.Get( valueMap ) )
1242 popupImpl.SetExitAnimationData( valueMap );
1246 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1249 if( value.Get( valueInt ) )
1251 popupImpl.SetAutoHideDelay( valueInt );
1255 case Toolkit::Popup::Property::BACKING_ENABLED:
1258 if( value.Get( valueBool ) )
1260 popupImpl.SetBackingEnabled( valueBool );
1264 case Toolkit::Popup::Property::BACKING_COLOR:
1266 Vector4 valueVector4;
1267 if( value.Get( valueVector4 ) )
1269 popupImpl.SetBackingColor( valueVector4 );
1273 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1275 std::string valueString;
1276 if( value.Get( valueString ) )
1278 Toolkit::ImageView actor = Toolkit::ImageView::New( valueString );
1279 popupImpl.SetPopupBackgroundImage( actor );
1283 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1285 bool valueUpdated = false;
1287 Vector4 valueVector4;
1288 if( value.Get( popupImpl.mBackgroundBorder ) )
1290 valueUpdated = true;
1292 else if( value.Get( valueVector4 ) )
1294 popupImpl.mBackgroundBorder.left = valueVector4.x;
1295 popupImpl.mBackgroundBorder.right = valueVector4.y;
1296 popupImpl.mBackgroundBorder.bottom = valueVector4.z;
1297 popupImpl.mBackgroundBorder.top = valueVector4.w;
1298 valueUpdated = true;
1303 popupImpl.LayoutTail(); // Update the tail if required
1304 popupImpl.UpdateBackgroundPositionAndSize(); // Update the background's size and position
1308 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1310 std::string valueString;
1311 if( value.Get( valueString ) )
1313 popupImpl.SetTailUpImage( valueString );
1317 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1319 std::string valueString;
1320 if( value.Get( valueString ) )
1322 popupImpl.SetTailDownImage( valueString );
1326 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1328 std::string valueString;
1329 if( value.Get( valueString ) )
1331 popupImpl.SetTailLeftImage( valueString );
1335 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1337 std::string valueString;
1338 if( value.Get( valueString ) )
1340 popupImpl.SetTailRightImage( valueString );
1348 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1350 Property::Value value;
1352 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1356 Popup& popupImpl( GetImpl( popup ) );
1358 switch ( propertyIndex )
1360 case Toolkit::Popup::Property::TITLE:
1363 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1367 case Toolkit::Popup::Property::CONTENT:
1370 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1374 case Toolkit::Popup::Property::FOOTER:
1377 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1381 case Toolkit::Popup::Property::DISPLAY_STATE:
1383 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1386 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1388 value = popupImpl.IsTouchTransparent();
1391 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1393 value = popupImpl.IsTailVisible();
1396 case Toolkit::Popup::Property::TAIL_POSITION:
1398 value = popupImpl.GetTailPosition();
1401 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1403 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1406 case Toolkit::Popup::Property::ANIMATION_DURATION:
1408 value = popupImpl.GetAnimationDuration();
1411 case Toolkit::Popup::Property::ANIMATION_MODE:
1413 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1416 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1418 // Note: Cannot retrieve property map from animation.
1423 case Toolkit::Popup::Property::EXIT_ANIMATION:
1425 // Note: Cannot retrieve property map from animation.
1430 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1432 value = popupImpl.GetAutoHideDelay();
1435 case Toolkit::Popup::Property::BACKING_ENABLED:
1437 value = popupImpl.IsBackingEnabled();
1440 case Toolkit::Popup::Property::BACKING_COLOR:
1442 value = popupImpl.GetBackingColor();
1445 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1447 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() );
1450 value = imageView.GetProperty( Toolkit::ImageView::Property::IMAGE );
1454 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1456 value = popupImpl.mBackgroundBorder;
1459 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1461 value = popupImpl.GetTailUpImage();
1464 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1466 value = popupImpl.GetTailDownImage();
1469 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1471 value = popupImpl.GetTailLeftImage();
1474 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1476 value = popupImpl.GetTailRightImage();
1485 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1487 Dali::BaseHandle handle( object );
1489 bool connected( true );
1490 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1492 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1494 popup.OutsideTouchedSignal().Connect( tracker, functor );
1496 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1498 popup.ShowingSignal().Connect( tracker, functor );
1500 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1502 popup.ShownSignal().Connect( tracker, functor );
1504 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1506 popup.HidingSignal().Connect( tracker, functor );
1508 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1510 popup.HiddenSignal().Connect( tracker, functor );
1514 // signalName does not match any signal
1521 bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
1523 // Allow events to pass through if touch transparency is enabled.
1524 if( mTouchTransparent )
1529 if( touch.GetPointCount() > 0 )
1531 if( touch.GetState( 0 ) == PointState::DOWN )
1533 // Guard against destruction during signal emission.
1534 Toolkit::Popup handle( GetOwner() );
1536 mTouchedOutsideSignal.Emit();
1540 // Block anything behind backing becoming touched.
1541 mLayer.SetTouchConsumed( true );
1545 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1547 // Allow events to pass through if touch transparency is enabled.
1548 if( mTouchTransparent )
1553 // Consume wheel event in dimmed backing actor.
1554 mLayer.SetTouchConsumed( true );
1558 bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
1560 // Allow events to pass through if touch transparency is enabled.
1561 if( mTouchTransparent )
1566 // Consume event (stops backing actor receiving touch events)
1567 mLayer.SetTouchConsumed( true );
1571 void Popup::OnStageConnection( int depth )
1573 Control::OnStageConnection( depth );
1575 mLayoutDirty = true;
1579 void Popup::OnChildAdd( Actor& child )
1581 Control::OnChildAdd( child );
1583 // Re-parent any children added by user to the body layer.
1584 if( mAlterAddedChild )
1586 SetContent( child );
1590 mLayoutDirty = true;
1595 void Popup::LayoutContext( const Vector2& size )
1597 // Do nothing if not in a contextual mode (or there is no parent context).
1598 Actor self = Self();
1599 Actor parent = self.GetParent();
1600 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1605 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
1606 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1607 // mode to allow code-reuse of the bound checking code (for maintainability).
1608 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
1610 // Setup with some pre-calculations for speed.
1611 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1612 Vector3 parentPosition( parent.GetCurrentPosition() );
1613 Vector2 halfSize( size / 2.0f );
1614 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1615 Vector3 newPosition( Vector3::ZERO );
1617 // Perform different positioning based on the specified contextual layout mode.
1618 switch( mContextualMode )
1620 case Toolkit::Popup::BELOW:
1622 newPosition.x += halfSize.x - halfParentSize.x;
1623 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1626 case Toolkit::Popup::ABOVE:
1628 newPosition.x += halfSize.x - halfParentSize.x;
1629 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1632 case Toolkit::Popup::RIGHT:
1634 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1635 newPosition.y += halfSize.y - halfParentSize.y;
1638 case Toolkit::Popup::LEFT:
1640 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1641 newPosition.y += halfSize.y - halfParentSize.y;
1644 case Toolkit::Popup::NON_CONTEXTUAL:
1646 // Code won't reach here (caught earlier).
1651 // On-screen position checking.
1652 // Check new position is not too far right. If so, correct it.
1653 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1654 // the right check and we at least see the left portion of the popup (as this is more useful).
1655 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1657 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1659 // Check new position is not too far left. If so, correct it.
1660 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1662 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1664 // Check new position is not too far down. If so, correct it.
1665 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1667 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1669 // Check new position is not too far up. If so, correct it.
1670 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1672 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1675 // Set the final position.
1676 mPopupContainer.SetPosition( newPosition );
1679 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1681 Vector2 useSize( size );
1683 // Use the Popup layouts size, unless requested to use a fixed size.
1684 // In which case take the size set for the Popup itself.
1685 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1686 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1688 // Width calculations:
1689 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1691 // If we using a child-based policy, take the size from the popup layout.
1692 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1693 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1695 mPopupLayout.SetFitWidth( 0u );
1699 // If we using a parent-based policy, take the size from the popup object itself (self).
1700 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1702 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1705 // Height calculations:
1706 // Title: Let the title be as high as it needs to be.
1707 mPopupLayout.SetFitHeight( 0u );
1709 // Footer: Convert the footer's resize policy to a TableView row policy.
1712 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1713 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1714 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1716 mPopupLayout.SetFitHeight( 2u );
1718 else if( footerHeightPolicy == ResizePolicy::FIXED )
1720 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1724 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1729 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1732 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1733 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1735 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1737 // Let both the contents expand as necessary.
1738 mPopupLayout.SetFitHeight( 1u );
1739 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1743 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1745 // Let the content expand to fill the remaining space.
1746 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1747 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1750 // Relayout the popup-layout to give it it's new size this frame.
1751 container.Add( mPopupLayout, useSize );
1755 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1758 // Perform contextual layout setup if required.
1759 // This is done each time in case the parent moves.
1760 // This will have no effect if no contextual mode is selected.
1761 LayoutContext( useSize );
1764 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1766 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1767 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1769 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1772 mLayoutDirty = true;
1776 Vector3 Popup::GetNaturalSize()
1778 return mPopupLayout.GetNaturalSize();
1781 float Popup::GetHeightForWidth( float width )
1783 return mPopupLayout.GetHeightForWidth( width );
1786 float Popup::GetWidthForHeight( float height )
1788 return mPopupLayout.GetWidthForHeight( height );
1791 bool Popup::OnKeyEvent( const KeyEvent& event )
1793 // Allow events to pass through if touch transparency is enabled.
1794 if( mTouchTransparent )
1799 bool consumed = false;
1801 if( event.state == KeyEvent::Down )
1803 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
1805 SetDisplayState( Toolkit::Popup::HIDDEN );
1813 void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors )
1817 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1818 bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
1820 if( parent.IsKeyboardFocusable() || layoutControl )
1822 focusableActors.push_back( parent );
1824 if( !layoutControl )
1826 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1828 Actor child( parent.GetChildAt( i ) );
1829 AddFocusableChildrenRecursive( child, focusableActors );
1836 void Popup::AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors )
1840 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1841 if( !GetImplementation( control ).IsKeyboardNavigationSupported() )
1843 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1845 Actor child( parent.GetChildAt( i ) );
1846 AddFocusableChildrenRecursive( child, focusableActors );
1851 focusableActors.push_back( parent );
1856 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1858 std::string currentStr;
1859 if( currentFocusedActor )
1861 currentStr = currentFocusedActor.GetName();
1864 Actor nextFocusableActor( currentFocusedActor );
1865 Actor currentFocusGroup;
1866 if( currentFocusedActor )
1868 currentFocusGroup = KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor );
1871 // TODO: Needs to be optimised
1872 // The following statement checks that if we have a current focused actor, then the current focus group is not the popup content or footer.
1873 // This is to detect if the focus is currently outside the popup, and if so, move it inside.
1874 if( !currentFocusedActor ||
1875 ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
1877 // The current focused actor is not within popup.
1878 if( mContent && mContent.IsKeyboardFocusable() )
1880 // If the content is focusable, move the focus to the content.
1881 nextFocusableActor = mContent;
1883 else if( mFooter && mFooter.IsKeyboardFocusable() )
1885 // If the footer is focusable, move the focus to the footer.
1886 nextFocusableActor = mFooter;
1891 // Rebuild the focus chain because controls or content can be added or removed dynamically
1892 std::vector< Actor > focusableActors;
1894 AddFocusableChildren( mContent, focusableActors );
1895 AddFocusableChildren( mFooter, focusableActors );
1897 std::vector< Actor >::iterator endIterator = focusableActors.end();
1898 std::vector< Actor >::iterator currentIterator = focusableActors.begin();
1899 for( std::vector< Actor >::iterator iterator = focusableActors.begin(); iterator != endIterator; ++iterator )
1901 if( currentFocusedActor == *iterator )
1903 currentIterator = iterator;
1907 if( currentIterator != endIterator )
1911 case Toolkit::Control::KeyboardFocus::LEFT:
1913 if( currentIterator == focusableActors.begin() )
1915 nextFocusableActor = *( endIterator - 1 );
1919 nextFocusableActor = *( currentIterator - 1 );
1923 case Toolkit::Control::KeyboardFocus::RIGHT:
1925 if( currentIterator == endIterator - 1 )
1927 nextFocusableActor = *( focusableActors.begin() );
1931 nextFocusableActor = *( currentIterator + 1 );
1936 case Toolkit::Control::KeyboardFocus::UP:
1938 nextFocusableActor = *( focusableActors.begin() );
1942 case Toolkit::Control::KeyboardFocus::DOWN:
1944 nextFocusableActor = *( endIterator - 1 );
1949 if( !nextFocusableActor )
1951 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1956 return nextFocusableActor;
1960 } // namespace Internal
1962 } // namespace Toolkit