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/images/resource-image.h>
32 #include <dali/public-api/object/type-registry.h>
33 #include <dali/devel-api/scripting/scripting.h>
34 #include <dali/public-api/size-negotiation/relayout-container.h>
37 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
38 #include <dali-toolkit/public-api/controls/control-impl.h>
39 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
40 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
41 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
58 * Creation function for main Popup type.
59 * @return Handle to the new popup object.
63 return Toolkit::Popup::New();
66 // Toast style defaults.
67 const int DEFAULT_TOAST_AUTO_HIDE_DELAY = 3000; ///< Toast will auto-hide after 3000ms (3 seconds)
68 const float DEFAULT_TOAST_TRANSITION_TIME = 0.65f; ///< Default time the toast Popup will take to show and hide.
69 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.
70 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.
73 * Creation function for named type "popupToast".
74 * @return Handle to the new toast popup object.
76 BaseHandle CreateToast()
78 Toolkit::Popup popup = Toolkit::Popup::New();
80 // Setup for Toast Popup type.
81 popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
82 popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
83 popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
84 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
85 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, DEFAULT_TOAST_TRANSITION_TIME );
86 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
88 // Disable the dimmed backing.
89 popup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false );
91 // The toast popup should fade in (not zoom).
92 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, Toolkit::Popup::FADE );
94 // The toast popup should auto-hide.
95 popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY );
97 // Align to the bottom of the screen.
98 popup.SetParentOrigin( DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN );
99 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
101 // Let events pass through the toast popup.
102 popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true );
107 // Setup properties, signals and actions using the type-registry.
108 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
110 // Main content related properties.
111 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER )
114 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT )
117 // Contextual related properties.
118 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY )
119 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION )
120 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE )
122 // Animation related properties.
123 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION )
124 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION )
126 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION )
127 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY )
129 // Style related properties.
130 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED )
131 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR )
132 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE )
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 Vector3 BACKGROUND_OUTER_BORDER( 40.0f, 30.0f, 0.0f ); ///< External border.
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( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
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 mBackgroundOuterBorder(),
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( ResourceImage::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 mPopupContainer.Remove( mPopupBackgroundImage );
574 // Adds new background to the dialog.
575 mPopupBackgroundImage = image;
576 mPopupBackgroundImage.SetName( "popupBackgroundImage" );
577 mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
578 mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
580 // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
581 mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
583 // Set the popup border to be slightly larger than the layout contents.
584 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
585 mPopupBackgroundImage.SetSizeModeFactor( BACKGROUND_OUTER_BORDER );
587 const bool prevAlter = mAlterAddedChild;
588 mAlterAddedChild = false;
589 mPopupContainer.Add( mPopupBackgroundImage );
590 mAlterAddedChild = prevAlter;
595 Actor Popup::GetPopupBackgroundImage() const
597 return mPopupBackgroundImage;
600 void Popup::SetTitle( Actor titleActor )
602 // Replaces the current title actor.
610 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
616 // Set up padding to give sensible default behaviour
617 // (an application developer can later override this if they wish).
618 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
620 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
627 Actor Popup::GetTitle() const
632 void Popup::SetContent( Actor content )
634 // Remove previous content actor.
637 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
639 // Keep a handle to the new content.
644 mContent.SetName( "popupContent" );
646 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
653 Actor Popup::GetContent() const
658 void Popup::SetFooter( Actor footer )
660 // Remove previous content actor.
663 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
666 // Keep a handle to the new content.
671 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
673 // The control container has a fixed height.
674 mPopupLayout.SetFitHeight( 2u );
675 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
682 Actor Popup::GetFooter() const
687 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
689 // Convert the 4-way state to a bool, true for show, false for hide.
690 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
692 // Ignore if we are already at the target display state.
693 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
698 // Convert the bool state to the actual display state to use.
699 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
703 // Update the state to indicate the current intent.
704 mDisplayState = Toolkit::Popup::SHOWING;
706 // We want the popup to have key input focus when it is displayed
709 // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
711 mLayer.SetVisible( true );
713 // Set up the layout if this is the first display or the layout has become dirty.
716 // Bake-in any style and layout options to create the Popup layout.
720 // Allow the popup to catch events.
721 mPopupLayout.SetSensitive( true );
723 // Handle the keyboard focus when popup is shown.
724 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
725 if( keyboardFocusManager )
727 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
729 if( Self().IsKeyboardFocusable() )
731 // Setup the actgor to start focus from.
733 if( mContent && mContent.IsKeyboardFocusable() )
735 // If the content is focusable, move the focus to the content.
736 focusActor = mContent;
738 else if( mFooter && mFooter.IsKeyboardFocusable() )
740 // If the footer is focusable, move the focus to the footer.
741 focusActor = mFooter;
745 DALI_LOG_WARNING( "There is no focusable in popup\n" );
750 keyboardFocusManager.SetCurrentFocusActor( focusActor );
757 mDisplayState = Toolkit::Popup::HIDING;
758 ClearKeyInputFocus();
760 // Restore the keyboard focus when popup is hidden.
761 if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
763 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
764 if( keyboardFocusManager )
766 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
771 // Perform animation.
772 StartTransitionAnimation( display );
775 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
777 return mDisplayState;
780 void Popup::LayoutPopup()
782 mLayoutDirty = false;
784 /* When animating in, we want to respect the origin applied to Self().
785 * For example, if zooming, not only will the final result be anchored to the
786 * selected point, but the zoom will originate from this point also.
788 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
797 mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
798 mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
800 // If there is only a title, use less padding.
803 if( !mContent && !mFooter )
805 mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
809 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
813 // Allow derived classes to perform any layout they may need to do.
816 // Update background visibility.
817 mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
819 // Create / destroy / position the tail as needed.
822 // Setup any layout and initialisation required for the selected animation.
828 void Popup::LayoutTail()
830 // Removes the tail actor.
831 if( mTailImage && mTailImage.GetParent() )
833 mTailImage.GetParent().Remove( mTailImage );
842 const Vector3& position = GetTailPosition();
845 // depending on position of tail around ParentOrigin, a different tail image is used...
846 if( position.y < Math::MACHINE_EPSILON_1 )
848 image = mTailUpImage;
850 else if( position.y > 1.0f - Math::MACHINE_EPSILON_1 )
852 image = mTailDownImage;
854 else if( position.x < Math::MACHINE_EPSILON_1 )
856 image = mTailLeftImage;
858 else if( position.x > 1.0f - Math::MACHINE_EPSILON_1 )
860 image = mTailRightImage;
865 // Adds the tail actor.
866 Image tail = ResourceImage::New( image );
867 mTailImage = Toolkit::ImageView::New( tail );
868 mTailImage.SetName( "tailImage" );
869 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
870 mTailImage.SetParentOrigin( position );
871 mTailImage.SetAnchorPoint( anchorPoint );
873 mPopupContainer.Add( mTailImage );
877 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
879 mContextualMode = mode;
883 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
885 return mContextualMode;
888 Toolkit::Control Popup::CreateBacking()
890 Toolkit::Control backing = Control::New();
891 backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
892 backing.SetName( "popupBacking" );
894 // Must always be positioned top-left of stage, regardless of parent.
895 backing.SetInheritPosition(false);
896 backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
898 // Always the full size of the stage.
899 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
900 backing.SetSize( Stage::GetCurrent().GetSize() );
903 backing.SetSensitive( true );
905 // Default to being transparent.
906 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
907 backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
908 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
912 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
914 return mTouchedOutsideSignal;
917 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
919 return mShowingSignal;
922 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
927 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
929 return mHidingSignal;
932 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
934 return mHiddenSignal;
937 void Popup::SetTailVisibility( bool visible )
939 mTailVisible = visible;
943 const bool Popup::IsTailVisible() const
948 void Popup::SetTailPosition( Vector3 position )
950 mTailPosition = position;
954 const Vector3& Popup::GetTailPosition() const
956 return mTailPosition;
959 void Popup::SetAnimationDuration( float duration )
961 mAnimationDuration = duration;
965 float Popup::GetAnimationDuration() const
967 return mAnimationDuration;
970 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
972 mAnimationMode = animationMode;
976 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
978 return mAnimationMode;
981 void Popup::SetEntryAnimationData( const Property::Map& map )
983 mEntryAnimationData.Clear();
984 Scripting::NewAnimation( map, mEntryAnimationData );
987 void Popup::SetExitAnimationData( const Property::Map& map )
989 mExitAnimationData.Clear();
990 Scripting::NewAnimation( map, mExitAnimationData );
993 void Popup::SetAutoHideDelay( int delay )
995 mAutoHideDelay = delay;
998 int Popup::GetAutoHideDelay() const
1000 return mAutoHideDelay;
1003 void Popup::SetBackingEnabled( bool enabled )
1005 mBackingEnabled = enabled;
1006 mLayoutDirty = true;
1009 const bool Popup::IsBackingEnabled() const
1011 return mBackingEnabled;
1014 void Popup::SetBackingColor( Vector4 color )
1016 mBackingColor = color;
1017 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1018 mLayoutDirty = true;
1021 const Vector4& Popup::GetBackingColor() const
1023 return mBackingColor;
1026 void Popup::SetTailUpImage( std::string image )
1028 mTailUpImage = image;
1029 mLayoutDirty = true;
1032 const std::string& Popup::GetTailUpImage() const
1034 return mTailUpImage;
1037 void Popup::SetTailDownImage( std::string image )
1039 mTailDownImage = image;
1040 mLayoutDirty = true;
1043 const std::string& Popup::GetTailDownImage() const
1045 return mTailDownImage;
1048 void Popup::SetTailLeftImage( std::string image )
1050 mTailLeftImage = image;
1051 mLayoutDirty = true;
1054 const std::string& Popup::GetTailLeftImage() const
1056 return mTailLeftImage;
1059 void Popup::SetTailRightImage( std::string image )
1061 mTailRightImage = image;
1062 mLayoutDirty = true;
1065 const std::string& Popup::GetTailRightImage() const
1067 return mTailRightImage;
1070 void Popup::SetTouchTransparent( bool enabled )
1072 mTouchTransparent = enabled;
1075 const bool Popup::IsTouchTransparent() const
1077 return mTouchTransparent;
1080 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1082 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1086 Popup& popupImpl( GetImpl( popup ) );
1088 switch ( propertyIndex )
1090 case Toolkit::Popup::Property::TITLE:
1092 Property::Map valueMap;
1093 if( value.Get( valueMap ) )
1095 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1099 case Toolkit::Popup::Property::CONTENT:
1101 Property::Map valueMap;
1102 if( value.Get( valueMap ) )
1104 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1108 case Toolkit::Popup::Property::FOOTER:
1110 Property::Map valueMap;
1111 if( value.Get( valueMap ) )
1113 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1117 case Toolkit::Popup::Property::DISPLAY_STATE:
1119 std::string valueString;
1120 if( value.Get( valueString ) )
1122 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1123 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1125 popupImpl.SetDisplayState( displayState );
1130 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1133 if( value.Get( valueBool ) )
1135 popupImpl.SetTouchTransparent( valueBool );
1139 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1142 if( value.Get( valueBool ) )
1144 popupImpl.SetTailVisibility( valueBool );
1148 case Toolkit::Popup::Property::TAIL_POSITION:
1150 Vector3 valueVector3;
1151 if( value.Get( valueVector3 ) )
1153 popupImpl.SetTailPosition( valueVector3 );
1157 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1159 std::string valueString;
1160 if( value.Get( valueString ) )
1162 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1163 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1165 popupImpl.SetContextualMode( contextualMode );
1170 case Toolkit::Popup::Property::ANIMATION_DURATION:
1173 if( value.Get( valueFloat ) )
1175 popupImpl.SetAnimationDuration( valueFloat );
1179 case Toolkit::Popup::Property::ANIMATION_MODE:
1181 std::string valueString;
1182 if( value.Get( valueString ) )
1184 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1185 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1187 popupImpl.SetAnimationMode( animationMode );
1192 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1194 Property::Map valueMap;
1195 if( value.Get( valueMap ) )
1197 popupImpl.SetEntryAnimationData( valueMap );
1201 case Toolkit::Popup::Property::EXIT_ANIMATION:
1203 Property::Map valueMap;
1204 if( value.Get( valueMap ) )
1206 popupImpl.SetExitAnimationData( valueMap );
1210 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1213 if( value.Get( valueInt ) )
1215 popupImpl.SetAutoHideDelay( valueInt );
1219 case Toolkit::Popup::Property::BACKING_ENABLED:
1222 if( value.Get( valueBool ) )
1224 popupImpl.SetBackingEnabled( valueBool );
1228 case Toolkit::Popup::Property::BACKING_COLOR:
1230 Vector4 valueVector4;
1231 if( value.Get( valueVector4 ) )
1233 popupImpl.SetBackingColor( valueVector4 );
1237 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1239 std::string valueString;
1240 if( value.Get( valueString ) )
1242 Image image = ResourceImage::New( valueString );
1245 Toolkit::ImageView actor = Toolkit::ImageView::New( image );
1246 popupImpl.SetPopupBackgroundImage( actor );
1251 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1253 std::string valueString;
1254 if( value.Get( valueString ) )
1256 popupImpl.SetTailUpImage( valueString );
1260 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1262 std::string valueString;
1263 if( value.Get( valueString ) )
1265 popupImpl.SetTailDownImage( valueString );
1269 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1271 std::string valueString;
1272 if( value.Get( valueString ) )
1274 popupImpl.SetTailLeftImage( valueString );
1278 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1280 std::string valueString;
1281 if( value.Get( valueString ) )
1283 popupImpl.SetTailRightImage( valueString );
1291 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1293 Property::Value value;
1295 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1299 Popup& popupImpl( GetImpl( popup ) );
1301 switch ( propertyIndex )
1303 case Toolkit::Popup::Property::TITLE:
1306 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1310 case Toolkit::Popup::Property::CONTENT:
1313 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1317 case Toolkit::Popup::Property::FOOTER:
1320 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1324 case Toolkit::Popup::Property::DISPLAY_STATE:
1326 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1329 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1331 value = popupImpl.IsTouchTransparent();
1334 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1336 value = popupImpl.IsTailVisible();
1339 case Toolkit::Popup::Property::TAIL_POSITION:
1341 value = popupImpl.GetTailPosition();
1344 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1346 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1349 case Toolkit::Popup::Property::ANIMATION_DURATION:
1351 value = popupImpl.GetAnimationDuration();
1354 case Toolkit::Popup::Property::ANIMATION_MODE:
1356 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1359 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1361 // Note: Cannot retrieve property map from animation.
1366 case Toolkit::Popup::Property::EXIT_ANIMATION:
1368 // Note: Cannot retrieve property map from animation.
1373 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1375 value = popupImpl.GetAutoHideDelay();
1378 case Toolkit::Popup::Property::BACKING_ENABLED:
1380 value = popupImpl.IsBackingEnabled();
1383 case Toolkit::Popup::Property::BACKING_COLOR:
1385 value = popupImpl.GetBackingColor();
1388 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1390 ResourceImage image = ResourceImage::DownCast( popupImpl.GetPopupBackgroundImage() );
1393 value = image.GetUrl();
1397 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1399 value = popupImpl.GetTailUpImage();
1402 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1404 value = popupImpl.GetTailDownImage();
1407 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1409 value = popupImpl.GetTailLeftImage();
1412 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1414 value = popupImpl.GetTailRightImage();
1423 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1425 Dali::BaseHandle handle( object );
1427 bool connected( true );
1428 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1430 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1432 popup.OutsideTouchedSignal().Connect( tracker, functor );
1434 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1436 popup.ShowingSignal().Connect( tracker, functor );
1438 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1440 popup.ShownSignal().Connect( tracker, functor );
1442 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1444 popup.HidingSignal().Connect( tracker, functor );
1446 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1448 popup.HiddenSignal().Connect( tracker, functor );
1452 // signalName does not match any signal
1459 bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
1461 // Allow events to pass through if touch transparency is enabled.
1462 if( mTouchTransparent )
1467 if( touch.GetPointCount() > 0 )
1469 if( touch.GetState( 0 ) == PointState::DOWN )
1471 // Guard against destruction during signal emission.
1472 Toolkit::Popup handle( GetOwner() );
1474 mTouchedOutsideSignal.Emit();
1478 // Block anything behind backing becoming touched.
1479 mLayer.SetTouchConsumed( true );
1483 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1485 // Allow events to pass through if touch transparency is enabled.
1486 if( mTouchTransparent )
1491 // Consume wheel event in dimmed backing actor.
1492 mLayer.SetTouchConsumed( true );
1496 bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
1498 // Allow events to pass through if touch transparency is enabled.
1499 if( mTouchTransparent )
1504 // Consume event (stops backing actor receiving touch events)
1505 mLayer.SetTouchConsumed( true );
1509 void Popup::OnStageConnection( int depth )
1511 Control::OnStageConnection( depth );
1513 mLayoutDirty = true;
1517 void Popup::OnChildAdd( Actor& child )
1519 Control::OnChildAdd( child );
1521 // Re-parent any children added by user to the body layer.
1522 if( mAlterAddedChild )
1524 SetContent( child );
1528 mLayoutDirty = true;
1533 void Popup::LayoutContext( const Vector2& size )
1535 // Do nothing if not in a contextual mode (or there is no parent context).
1536 Actor self = Self();
1537 Actor parent = self.GetParent();
1538 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1543 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
1544 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1545 // mode to allow code-reuse of the bound checking code (for maintainability).
1546 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
1548 // Setup with some pre-calculations for speed.
1549 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1550 Vector3 parentPosition( parent.GetCurrentPosition() );
1551 Vector2 halfSize( size / 2.0f );
1552 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1553 Vector3 newPosition( Vector3::ZERO );
1555 // Perform different positioning based on the specified contextual layout mode.
1556 switch( mContextualMode )
1558 case Toolkit::Popup::BELOW:
1560 newPosition.x += halfSize.x - halfParentSize.x;
1561 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1564 case Toolkit::Popup::ABOVE:
1566 newPosition.x += halfSize.x - halfParentSize.x;
1567 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1570 case Toolkit::Popup::RIGHT:
1572 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1573 newPosition.y += halfSize.y - halfParentSize.y;
1576 case Toolkit::Popup::LEFT:
1578 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1579 newPosition.y += halfSize.y - halfParentSize.y;
1582 case Toolkit::Popup::NON_CONTEXTUAL:
1584 // Code won't reach here (caught earlier).
1589 // On-screen position checking.
1590 // Check new position is not too far right. If so, correct it.
1591 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1592 // the right check and we at least see the left portion of the popup (as this is more useful).
1593 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1595 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1597 // Check new position is not too far left. If so, correct it.
1598 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1600 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1602 // Check new position is not too far down. If so, correct it.
1603 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1605 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1607 // Check new position is not too far up. If so, correct it.
1608 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1610 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1613 // Set the final position.
1614 mPopupContainer.SetPosition( newPosition );
1617 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1619 Vector2 useSize( size );
1621 // Use the Popup layouts size, unless requested to use a fixed size.
1622 // In which case take the size set for the Popup itself.
1623 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1624 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1626 // Width calculations:
1627 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1629 // If we using a child-based policy, take the size from the popup layout.
1630 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1631 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1633 mPopupLayout.SetFitWidth( 0u );
1637 // If we using a parent-based policy, take the size from the popup object itself (self).
1638 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1640 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1643 // Height calculations:
1644 // Title: Let the title be as high as it needs to be.
1645 mPopupLayout.SetFitHeight( 0u );
1647 // Footer: Convert the footer's resize policy to a TableView row policy.
1650 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1651 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1652 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1654 mPopupLayout.SetFitHeight( 2u );
1656 else if( footerHeightPolicy == ResizePolicy::FIXED )
1658 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1662 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1667 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1670 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1671 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1673 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1675 // Let both the contents expand as necessary.
1676 mPopupLayout.SetFitHeight( 1u );
1677 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1681 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1683 // Let the content expand to fill the remaining space.
1684 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1685 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1688 // Relayout the popup-layout to give it it's new size this frame.
1689 container.Add( mPopupLayout, useSize );
1693 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1696 // Perform contextual layout setup if required.
1697 // This is done each time in case the parent moves.
1698 // This will have no effect if no contextual mode is selected.
1699 LayoutContext( useSize );
1702 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1704 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1705 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1707 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1710 mLayoutDirty = true;
1714 Vector3 Popup::GetNaturalSize()
1716 return mPopupLayout.GetNaturalSize();
1719 float Popup::GetHeightForWidth( float width )
1721 return mPopupLayout.GetHeightForWidth( width );
1724 float Popup::GetWidthForHeight( float height )
1726 return mPopupLayout.GetWidthForHeight( height );
1729 bool Popup::OnKeyEvent( const KeyEvent& event )
1731 // Allow events to pass through if touch transparency is enabled.
1732 if( mTouchTransparent )
1737 bool consumed = false;
1739 if( event.state == KeyEvent::Down )
1741 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
1743 SetDisplayState( Toolkit::Popup::HIDDEN );
1751 void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors )
1755 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1756 bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
1758 if( parent.IsKeyboardFocusable() || layoutControl )
1760 focusableActors.push_back( parent );
1762 if( !layoutControl )
1764 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1766 Actor child( parent.GetChildAt( i ) );
1767 AddFocusableChildrenRecursive( child, focusableActors );
1774 void Popup::AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors )
1778 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1779 if( !GetImplementation( control ).IsKeyboardNavigationSupported() )
1781 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1783 Actor child( parent.GetChildAt( i ) );
1784 AddFocusableChildrenRecursive( child, focusableActors );
1789 focusableActors.push_back( parent );
1794 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1796 std::string currentStr;
1797 if( currentFocusedActor )
1799 currentStr = currentFocusedActor.GetName();
1802 Actor nextFocusableActor( currentFocusedActor );
1803 Actor currentFocusGroup;
1804 if( currentFocusedActor )
1806 currentFocusGroup = KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor );
1809 // TODO: Needs to be optimised
1810 // The following statement checks that if we have a current focused actor, then the current focus group is not the popup content or footer.
1811 // This is to detect if the focus is currently outside the popup, and if so, move it inside.
1812 if( !currentFocusedActor ||
1813 ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
1815 // The current focused actor is not within popup.
1816 if( mContent && mContent.IsKeyboardFocusable() )
1818 // If the content is focusable, move the focus to the content.
1819 nextFocusableActor = mContent;
1821 else if( mFooter && mFooter.IsKeyboardFocusable() )
1823 // If the footer is focusable, move the focus to the footer.
1824 nextFocusableActor = mFooter;
1829 // Rebuild the focus chain because controls or content can be added or removed dynamically
1830 std::vector< Actor > focusableActors;
1832 AddFocusableChildren( mContent, focusableActors );
1833 AddFocusableChildren( mFooter, focusableActors );
1835 std::vector< Actor >::iterator endIterator = focusableActors.end();
1836 std::vector< Actor >::iterator currentIterator = focusableActors.begin();
1837 for( std::vector< Actor >::iterator iterator = focusableActors.begin(); iterator != endIterator; ++iterator )
1839 if( currentFocusedActor == *iterator )
1841 currentIterator = iterator;
1845 if( currentIterator != endIterator )
1849 case Toolkit::Control::KeyboardFocus::LEFT:
1851 if( currentIterator == focusableActors.begin() )
1853 nextFocusableActor = *( endIterator - 1 );
1857 nextFocusableActor = *( currentIterator - 1 );
1861 case Toolkit::Control::KeyboardFocus::RIGHT:
1863 if( currentIterator == endIterator - 1 )
1865 nextFocusableActor = *( focusableActors.begin() );
1869 nextFocusableActor = *( currentIterator + 1 );
1874 case Toolkit::Control::KeyboardFocus::UP:
1876 nextFocusableActor = *( focusableActors.begin() );
1880 case Toolkit::Control::KeyboardFocus::DOWN:
1882 nextFocusableActor = *( endIterator - 1 );
1887 if( !nextFocusableActor )
1889 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1894 return nextFocusableActor;
1898 } // namespace Internal
1900 } // namespace Toolkit