2 * Copyright (c) 2015 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/devel-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-event.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/default-controls/solid-color-actor.h>
40 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
41 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
42 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
59 * Creation function for main Popup type.
60 * @return Handle to the new popup object.
64 return Toolkit::Popup::New();
67 // Toast style defaults.
68 const int DEFAULT_TOAST_AUTO_HIDE_DELAY = 3000; ///< Toast will auto-hide after 3000ms (3 seconds)
69 const float DEFAULT_TOAST_TRANSITION_TIME = 0.65f; ///< Default time the toast Popup will take to show and hide.
70 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.
71 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.
74 * Creation function for named type "popupToast".
75 * @return Handle to the new toast popup object.
77 BaseHandle CreateToast()
79 Toolkit::Popup popup = Toolkit::Popup::New();
81 // Setup for Toast Popup type.
82 popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
83 popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
84 popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
85 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
86 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, DEFAULT_TOAST_TRANSITION_TIME );
87 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
89 // Disable the dimmed backing.
90 popup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false );
92 // The toast popup should fade in (not zoom).
93 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, Toolkit::Popup::FADE );
95 // The toast popup should auto-hide.
96 popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY );
98 // Align to the bottom of the screen.
99 popup.SetParentOrigin( DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN );
100 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
102 // Let events pass through the toast popup.
103 popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true );
108 // Setup properties, signals and actions using the type-registry.
109 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
111 // Main content related properties.
112 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER )
115 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT )
118 // Contextual related properties.
119 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY )
120 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION )
121 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE )
123 // Animation related properties.
124 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION )
125 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION )
127 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION )
128 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY )
130 // Style related properties.
131 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED )
132 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR )
133 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE )
136 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE )
137 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE )
140 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE )
141 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING )
142 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN )
143 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING )
144 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
146 DALI_TYPE_REGISTRATION_END()
148 // Named type registration.
150 // Toast Popup: Non-modal popup that displays information at the bottom of the screen.
151 TypeRegistration typeRegistrationToast( "PopupToast", typeid( Toolkit::Popup ), CreateToast );
153 // Enumeration to / from string conversion tables
155 const Scripting::StringEnum DisplayStateTable[] = {
156 { "SHOWING", Toolkit::Popup::SHOWING },
157 { "SHOWN", Toolkit::Popup::SHOWN },
158 { "HIDING", Toolkit::Popup::HIDING },
159 { "HIDDEN", Toolkit::Popup::HIDDEN },
160 }; const unsigned int DisplayStateTableCount = sizeof( DisplayStateTable ) / sizeof( DisplayStateTable[0] );
162 const Scripting::StringEnum AnimationModeTable[] = {
163 { "NONE", Toolkit::Popup::NONE },
164 { "ZOOM", Toolkit::Popup::ZOOM },
165 { "FADE", Toolkit::Popup::FADE },
166 { "CUSTOM", Toolkit::Popup::CUSTOM },
167 }; const unsigned int AnimationModeTableCount = sizeof( AnimationModeTable ) / sizeof( AnimationModeTable[0] );
169 const Scripting::StringEnum ContextualModeTable[] = {
170 { "NON_CONTEXTUAL", Toolkit::Popup::NON_CONTEXTUAL },
171 { "ABOVE", Toolkit::Popup::ABOVE },
172 { "RIGHT", Toolkit::Popup::RIGHT },
173 { "BELOW", Toolkit::Popup::BELOW },
174 { "LEFT", Toolkit::Popup::LEFT },
175 }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] );
178 const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent.
179 const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations.
180 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
181 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
182 const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position.
184 // Contextual defaults.
185 const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent.
186 const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges.
188 // Popup style defaults.
189 const char* DEFAULT_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "00_popup_bg.9.png"; ///< Background image.
190 const char* DEFAULT_TAIL_UP_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_up.png"; ///< Tail up image.
191 const char* DEFAULT_TAIL_DOWN_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_down.png"; ///< Tail down image.
192 const char* DEFAULT_TAIL_LEFT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_left.png"; ///< Tail left image.
193 const char* DEFAULT_TAIL_RIGHT_IMAGE_PATH = DALI_IMAGE_DIR "popup_tail_right.png"; ///< Tail right image.
195 const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing.
196 const Vector3 BACKGROUND_OUTER_BORDER( 40.0f, 30.0f, 0.0f ); ///< External border.
197 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).
198 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).
199 const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area.
200 const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default.
202 } // Unnamed namespace
208 Dali::Toolkit::Popup Popup::New()
210 // Create the implementation
211 PopupPtr popup( new Popup() );
213 // Pass ownership to CustomActor via derived handle.
214 Dali::Toolkit::Popup handle( *popup );
216 // Second-phase initialisation of the implementation.
217 // This can only be done after the CustomActor connection has been made.
224 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
225 mTouchedOutsideSignal(),
233 mPreviousFocusedActor(),
237 mAlterAddedChild( false ),
238 mLayoutDirty( true ),
240 mTouchTransparent( false ),
244 mDisplayState( Toolkit::Popup::HIDDEN ), // Hidden until shown with SetDisplayState()
245 mTailVisible( false ),
246 mTailPosition( DEFAULT_TAIL_POSITION ),
247 mContextualMode( Toolkit::Popup::NON_CONTEXTUAL ),
248 mAnimationDuration( DEFAULT_POPUP_ANIMATION_DURATION ),
249 mAnimationMode( Toolkit::Popup::FADE ),
250 mEntryAnimationData(),
251 mExitAnimationData(),
253 mBackingEnabled( true ),
254 mBackingColor( DEFAULT_BACKING_COLOR ),
255 mPopupBackgroundImage(),
256 mBackgroundOuterBorder(),
258 mTailUpImage( DEFAULT_TAIL_UP_IMAGE_PATH ),
259 mTailDownImage( DEFAULT_TAIL_DOWN_IMAGE_PATH ),
260 mTailLeftImage( DEFAULT_TAIL_LEFT_IMAGE_PATH ),
261 mTailRightImage( DEFAULT_TAIL_RIGHT_IMAGE_PATH )
263 SetKeyboardNavigationSupport( true );
266 void Popup::OnInitialize()
269 self.SetName( "popup" );
271 // Apply some default resizing rules.
272 self.SetParentOrigin( ParentOrigin::CENTER );
273 self.SetAnchorPoint( AnchorPoint::CENTER );
275 self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
276 self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
277 self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
279 // Create a new layer so all Popup components can appear above all other actors.
280 mLayer = Layer::New();
281 mLayer.SetName( "popupLayer" );
283 mLayer.SetParentOrigin( ParentOrigin::CENTER );
284 mLayer.SetAnchorPoint( AnchorPoint::CENTER );
285 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
287 // Important to set as invisible as otherwise, if the popup is parented,
288 // but not shown yet it will appear statically on the screen.
289 mLayer.SetVisible( false );
291 // Add the layer to the hierarchy.
294 // Add Backing (Dimmed effect).
295 mBacking = CreateBacking();
296 mLayer.Add( mBacking );
298 mPopupContainer = Actor::New();
299 mPopupContainer.SetName( "popupContainer" );
300 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
301 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
302 mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
303 mLayer.Add( mPopupContainer );
305 // Create the Popup layout to contain all main content.
306 mPopupLayout = Toolkit::TableView::New( 3, 1 );
308 // Adds the default background image.
309 SetPopupBackgroundImage( Toolkit::ImageView::New( ResourceImage::New( DEFAULT_BACKGROUND_IMAGE_PATH ) ) );
311 mPopupLayout.SetName( "popupLayoutTable" );
312 mPopupLayout.SetParentOrigin( ParentOrigin::CENTER );
313 mPopupLayout.SetAnchorPoint( AnchorPoint::CENTER );
315 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
316 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
317 mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f );
319 mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
320 mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
322 mPopupLayout.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
324 mPopupContainer.Add( mPopupLayout );
326 // Any content after this point which is added to Self() will be re-parented to mContent.
327 mAlterAddedChild = true;
329 // Make self keyboard focusable and a focus group.
330 self.SetKeyboardFocusable( true );
331 SetAsKeyboardFocusGroup( true );
336 mEntryAnimationData.Clear();
337 mExitAnimationData.Clear();
340 void Popup::LayoutAnimation()
342 // Perform setup based on the currently selected animation.
343 switch( mAnimationMode )
345 case Toolkit::Popup::ZOOM:
347 // Zoom animations start fully zoomed out.
348 mPopupContainer.SetScale( Vector3::ZERO );
352 case Toolkit::Popup::FADE:
354 // Fade animations start transparent.
355 mPopupContainer.SetOpacity( 0.0f );
359 case Toolkit::Popup::CUSTOM:
361 // Initialise the custom animation by playing to the end of it's exit animation instantly.
362 // EG. If it was zooming in, then we zoom out fully instantly so the zoom in works.
363 StartTransitionAnimation( false, true );
367 case Toolkit::Popup::NONE:
374 void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* false */ )
376 // Stop and recreate animation.
383 float duration = GetAnimationDuration();
385 // Setup variables ready to start the animations.
386 // If we are performing the animation instantaneously, we do not want to emit a signal.
391 // Setup variables and signal that we are starting the transition.
392 // Note: We signal even if the transition is instant so signal order is consistent.
393 mShowingSignal.Emit();
397 mHidingSignal.Emit();
401 // Perform chosen animation for the Popup.
402 switch( mAnimationMode )
404 case Toolkit::Popup::NONE:
406 mAnimation = Animation::New( 0.0f );
410 case Toolkit::Popup::ZOOM:
412 mAnimation = Animation::New( duration );
413 if( duration > Math::MACHINE_EPSILON_0 )
417 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( duration * 0.25f, duration * 0.75f ) );
421 // Zoom out animation is twice the speed. Modify the duration variable so the backing animation speed is modified also.
423 mAnimation.SetDuration( duration );
424 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ZERO, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration ) );
429 mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO );
434 case Toolkit::Popup::FADE:
436 mAnimation = Animation::New( duration );
437 if( duration > Math::MACHINE_EPSILON_0 )
441 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
445 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
450 mPopupContainer.SetOpacity( transitionIn ? 1.0f : 0.0f );
455 case Toolkit::Popup::CUSTOM:
457 // Use a user specified animation for in and out.
458 // Read the correct animation depending on entry or exit.
459 // Attempt to use animation data defined from script data.
460 Dali::AnimationData* animationData = transitionIn ? &mEntryAnimationData : &mExitAnimationData;
462 // Create a new animation from the pre-defined data in the AnimationData class.
463 // If there is no data, mAnimation is invalidated.
464 mAnimation = animationData->CreateAnimation( mPopupContainer, duration );
466 // If we don't have a valid animation, provide a blank one so play() can still function generically.
469 // No animation was configured (even though custom mode was specified). Create a dummy animation to avoid an exception.
470 mAnimation = Animation::New( 0.0f );
477 // Animate the backing, if enabled.
478 // This is set up last so that different animation modes can have an effect on the backing animation speed.
479 if( mBackingEnabled )
481 // Use the alpha from the user-specified color.
482 float targetAlpha = mBackingColor.a;
483 if( duration > Math::MACHINE_EPSILON_0 )
487 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), targetAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
491 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
496 mBacking.SetProperty( Actor::Property::COLOR_ALPHA, transitionIn ? targetAlpha : 0.0f );
500 // If we are performing the animation instantaneously, jump to the position directly and do not signal.
503 mAnimation.SetCurrentProgress( 1.0f );
506 else if( duration > Math::MACHINE_EPSILON_0 )
508 // Run the animation.
509 mAnimation.FinishedSignal().Connect( this, &Popup::OnDisplayChangeAnimationFinished );
514 // We did not use an animation to achive the transition.
515 // Trigger the state change directly.
516 DisplayStateChangeComplete();
520 void Popup::OnDisplayChangeAnimationFinished( Animation& source )
522 DisplayStateChangeComplete();
525 void Popup::DisplayStateChangeComplete()
527 // Remove contents from stage if completely hidden.
528 if( mDisplayState == Toolkit::Popup::HIDING )
530 mDisplayState = Toolkit::Popup::HIDDEN;
532 mLayer.SetVisible( false );
533 mPopupLayout.SetSensitive( false );
535 // Guard against destruction during signal emission.
536 Toolkit::Popup handle( GetOwner() );
537 mHiddenSignal.Emit();
539 else if( mDisplayState == Toolkit::Popup::SHOWING )
541 mDisplayState = Toolkit::Popup::SHOWN;
542 Toolkit::Popup handle( GetOwner() );
545 // Start a timer to auto-hide if enabled.
546 if( mAutoHideDelay > 0u )
548 mAutoHideTimer = Timer::New( mAutoHideDelay );
549 mAutoHideTimer.TickSignal().Connect( this, &Popup::OnAutoHideTimeReached );
550 mAutoHideTimer.Start();
555 bool Popup::OnAutoHideTimeReached()
557 // Display timer has expired, auto hide the popup exactly as if the user had clicked outside.
558 SetDisplayState( Toolkit::Popup::HIDDEN );
562 mAutoHideTimer.Stop();
563 mAutoHideTimer.TickSignal().Disconnect( this, &Popup::OnAutoHideTimeReached );
564 mAutoHideTimer.Reset();
569 void Popup::SetPopupBackgroundImage( Actor image )
571 // Removes any previous background.
572 if( mPopupBackgroundImage )
574 mPopupContainer.Remove( mPopupBackgroundImage );
577 // Adds new background to the dialog.
578 mPopupBackgroundImage = image;
579 mPopupBackgroundImage.SetName( "popupBackgroundImage" );
580 mPopupBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
581 mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
583 // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
584 mPopupBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
586 // Set the popup border to be slightly larger than the layout contents.
587 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
588 mPopupBackgroundImage.SetSizeModeFactor( BACKGROUND_OUTER_BORDER );
590 const bool prevAlter = mAlterAddedChild;
591 mAlterAddedChild = false;
592 mPopupContainer.Add( mPopupBackgroundImage );
593 mAlterAddedChild = prevAlter;
598 Actor Popup::GetPopupBackgroundImage() const
600 return mPopupBackgroundImage;
603 void Popup::SetTitle( Actor titleActor )
605 // Replaces the current title actor.
613 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
619 // Set up padding to give sensible default behaviour
620 // (an application developer can later override this if they wish).
621 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
623 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
630 Actor Popup::GetTitle() const
635 void Popup::SetContent( Actor content )
637 // Remove previous content actor.
640 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
642 // Keep a handle to the new content.
647 mContent.SetName( "popupContent" );
649 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
656 Actor Popup::GetContent() const
661 void Popup::SetFooter( Actor footer )
663 // Remove previous content actor.
666 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
669 // Keep a handle to the new content.
674 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
676 // The control container has a fixed height.
677 mPopupLayout.SetFitHeight( 2u );
678 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
685 Actor Popup::GetFooter() const
690 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
692 // Convert the 4-way state to a bool, true for show, false for hide.
693 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
695 // Ignore if we are already at the target display state.
696 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
701 // Convert the bool state to the actual display state to use.
702 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
706 // Update the state to indicate the current intent.
707 mDisplayState = Toolkit::Popup::SHOWING;
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 );
724 // Handle the keyboard focus when popup is shown.
725 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
726 if( keyboardFocusManager )
728 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
730 if( mContent && mContent.IsKeyboardFocusable() )
732 // If content is focusable, move the focus to content.
733 keyboardFocusManager.SetCurrentFocusActor( mContent );
737 DALI_LOG_WARNING( "There is no focusable in popup\n" );
743 mDisplayState = Toolkit::Popup::HIDING;
744 ClearKeyInputFocus();
746 // Restore the keyboard focus when popup is hidden.
747 if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
749 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
750 if( keyboardFocusManager )
752 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
757 // Perform animation.
758 StartTransitionAnimation( display );
761 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
763 return mDisplayState;
766 void Popup::LayoutPopup()
768 mLayoutDirty = false;
770 /* When animating in, we want to respect the origin applied to Self().
771 * For example, if zooming, not only will the final result be anchored to the
772 * selected point, but the zoom will originate from this point also.
774 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
783 mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
784 mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
786 // If there is only a title, use less padding.
789 if( !mContent && !mFooter )
791 mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
795 mTitle.SetPadding( DEFAULT_TITLE_PADDING );
799 // Allow derived classes to perform any layout they may need to do.
802 // Update background visibility.
803 mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
805 // Create / destroy / position the tail as needed.
808 // Setup any layout and initialisation required for the selected animation.
814 void Popup::LayoutTail()
816 // Removes the tail actor.
817 if( mTailImage && mTailImage.GetParent() )
819 mTailImage.GetParent().Remove( mTailImage );
828 const Vector3& position = GetTailPosition();
831 // depending on position of tail around ParentOrigin, a different tail image is used...
832 if( position.y < Math::MACHINE_EPSILON_1 )
834 image = mTailUpImage;
836 else if( position.y > 1.0f - Math::MACHINE_EPSILON_1 )
838 image = mTailDownImage;
840 else if( position.x < Math::MACHINE_EPSILON_1 )
842 image = mTailLeftImage;
844 else if( position.x > 1.0f - Math::MACHINE_EPSILON_1 )
846 image = mTailRightImage;
851 // Adds the tail actor.
852 Image tail = ResourceImage::New( image );
853 mTailImage = Toolkit::ImageView::New( tail );
854 mTailImage.SetName( "tailImage" );
855 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
856 mTailImage.SetParentOrigin( position );
857 mTailImage.SetAnchorPoint( anchorPoint );
859 mPopupContainer.Add( mTailImage );
863 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
865 mContextualMode = mode;
869 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
871 return mContextualMode;
874 Toolkit::Control Popup::CreateBacking()
876 Toolkit::Control backing = Control::New();
877 backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
878 backing.SetName( "popupBacking" );
880 // Must always be positioned top-left of stage, regardless of parent.
881 backing.SetPositionInheritanceMode( DONT_INHERIT_POSITION );
882 backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
884 // Always the full size of the stage.
885 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
886 backing.SetSize( Stage::GetCurrent().GetSize() );
889 backing.SetSensitive( true );
891 // Default to being transparent.
892 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
893 backing.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
894 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
898 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
900 return mTouchedOutsideSignal;
903 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
905 return mShowingSignal;
908 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
913 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
915 return mHidingSignal;
918 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
920 return mHiddenSignal;
923 void Popup::SetTailVisibility( bool visible )
925 mTailVisible = visible;
929 const bool Popup::IsTailVisible() const
934 void Popup::SetTailPosition( Vector3 position )
936 mTailPosition = position;
940 const Vector3& Popup::GetTailPosition() const
942 return mTailPosition;
945 void Popup::SetAnimationDuration( float duration )
947 mAnimationDuration = duration;
951 float Popup::GetAnimationDuration() const
953 return mAnimationDuration;
956 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
958 mAnimationMode = animationMode;
962 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
964 return mAnimationMode;
967 void Popup::SetEntryAnimationData( const Property::Map& map )
969 mEntryAnimationData.Clear();
970 Scripting::NewAnimation( map, mEntryAnimationData );
973 void Popup::SetExitAnimationData( const Property::Map& map )
975 mExitAnimationData.Clear();
976 Scripting::NewAnimation( map, mExitAnimationData );
979 void Popup::SetAutoHideDelay( int delay )
981 mAutoHideDelay = delay;
984 int Popup::GetAutoHideDelay() const
986 return mAutoHideDelay;
989 void Popup::SetBackingEnabled( bool enabled )
991 mBackingEnabled = enabled;
995 const bool Popup::IsBackingEnabled() const
997 return mBackingEnabled;
1000 void Popup::SetBackingColor( Vector4 color )
1002 mBackingColor = color;
1003 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1004 mLayoutDirty = true;
1007 const Vector4& Popup::GetBackingColor() const
1009 return mBackingColor;
1012 void Popup::SetTailUpImage( std::string image )
1014 mTailUpImage = image;
1015 mLayoutDirty = true;
1018 const std::string& Popup::GetTailUpImage() const
1020 return mTailUpImage;
1023 void Popup::SetTailDownImage( std::string image )
1025 mTailDownImage = image;
1026 mLayoutDirty = true;
1029 const std::string& Popup::GetTailDownImage() const
1031 return mTailDownImage;
1034 void Popup::SetTailLeftImage( std::string image )
1036 mTailLeftImage = image;
1037 mLayoutDirty = true;
1040 const std::string& Popup::GetTailLeftImage() const
1042 return mTailLeftImage;
1045 void Popup::SetTailRightImage( std::string image )
1047 mTailRightImage = image;
1048 mLayoutDirty = true;
1051 const std::string& Popup::GetTailRightImage() const
1053 return mTailRightImage;
1056 void Popup::SetTouchTransparent( bool enabled )
1058 mTouchTransparent = enabled;
1061 const bool Popup::IsTouchTransparent() const
1063 return mTouchTransparent;
1066 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1068 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1072 Popup& popupImpl( GetImpl( popup ) );
1074 switch ( propertyIndex )
1076 case Toolkit::Popup::Property::TITLE:
1078 Property::Map valueMap;
1079 if( value.Get( valueMap ) )
1081 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1085 case Toolkit::Popup::Property::CONTENT:
1087 Property::Map valueMap;
1088 if( value.Get( valueMap ) )
1090 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1094 case Toolkit::Popup::Property::FOOTER:
1096 Property::Map valueMap;
1097 if( value.Get( valueMap ) )
1099 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1103 case Toolkit::Popup::Property::DISPLAY_STATE:
1105 std::string valueString;
1106 if( value.Get( valueString ) )
1108 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1109 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1111 popupImpl.SetDisplayState( displayState );
1116 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1119 if( value.Get( valueBool ) )
1121 popupImpl.SetTouchTransparent( valueBool );
1125 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1128 if( value.Get( valueBool ) )
1130 popupImpl.SetTailVisibility( valueBool );
1134 case Toolkit::Popup::Property::TAIL_POSITION:
1136 Vector3 valueVector3;
1137 if( value.Get( valueVector3 ) )
1139 popupImpl.SetTailPosition( valueVector3 );
1143 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1145 std::string valueString;
1146 if( value.Get( valueString ) )
1148 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1149 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1151 popupImpl.SetContextualMode( contextualMode );
1156 case Toolkit::Popup::Property::ANIMATION_DURATION:
1159 if( value.Get( valueFloat ) )
1161 popupImpl.SetAnimationDuration( valueFloat );
1165 case Toolkit::Popup::Property::ANIMATION_MODE:
1167 std::string valueString;
1168 if( value.Get( valueString ) )
1170 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1171 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1173 popupImpl.SetAnimationMode( animationMode );
1178 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1180 Property::Map valueMap;
1181 if( value.Get( valueMap ) )
1183 popupImpl.SetEntryAnimationData( valueMap );
1187 case Toolkit::Popup::Property::EXIT_ANIMATION:
1189 Property::Map valueMap;
1190 if( value.Get( valueMap ) )
1192 popupImpl.SetExitAnimationData( valueMap );
1196 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1199 if( value.Get( valueInt ) )
1201 popupImpl.SetAutoHideDelay( valueInt );
1205 case Toolkit::Popup::Property::BACKING_ENABLED:
1208 if( value.Get( valueBool ) )
1210 popupImpl.SetBackingEnabled( valueBool );
1214 case Toolkit::Popup::Property::BACKING_COLOR:
1216 Vector4 valueVector4;
1217 if( value.Get( valueVector4 ) )
1219 popupImpl.SetBackingColor( valueVector4 );
1223 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1225 std::string valueString;
1226 if( value.Get( valueString ) )
1228 Image image = ResourceImage::New( valueString );
1231 Toolkit::ImageView actor = Toolkit::ImageView::New( image );
1232 popupImpl.SetPopupBackgroundImage( actor );
1237 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1239 std::string valueString;
1240 if( value.Get( valueString ) )
1242 popupImpl.SetTailUpImage( valueString );
1246 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1248 std::string valueString;
1249 if( value.Get( valueString ) )
1251 popupImpl.SetTailDownImage( valueString );
1255 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1257 std::string valueString;
1258 if( value.Get( valueString ) )
1260 popupImpl.SetTailLeftImage( valueString );
1264 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1266 std::string valueString;
1267 if( value.Get( valueString ) )
1269 popupImpl.SetTailRightImage( valueString );
1277 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1279 Property::Value value;
1281 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1285 Popup& popupImpl( GetImpl( popup ) );
1287 switch ( propertyIndex )
1289 case Toolkit::Popup::Property::TITLE:
1292 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1296 case Toolkit::Popup::Property::CONTENT:
1299 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1303 case Toolkit::Popup::Property::FOOTER:
1306 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1310 case Toolkit::Popup::Property::DISPLAY_STATE:
1312 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1315 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1317 value = popupImpl.IsTouchTransparent();
1320 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1322 value = popupImpl.IsTailVisible();
1325 case Toolkit::Popup::Property::TAIL_POSITION:
1327 value = popupImpl.GetTailPosition();
1330 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1332 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1335 case Toolkit::Popup::Property::ANIMATION_DURATION:
1337 value = popupImpl.GetAnimationDuration();
1340 case Toolkit::Popup::Property::ANIMATION_MODE:
1342 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1345 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1347 // Note: Cannot retrieve property map from animation.
1352 case Toolkit::Popup::Property::EXIT_ANIMATION:
1354 // Note: Cannot retrieve property map from animation.
1359 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1361 value = popupImpl.GetAutoHideDelay();
1364 case Toolkit::Popup::Property::BACKING_ENABLED:
1366 value = popupImpl.IsBackingEnabled();
1369 case Toolkit::Popup::Property::BACKING_COLOR:
1371 value = popupImpl.GetBackingColor();
1374 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1376 ResourceImage image = ResourceImage::DownCast( popupImpl.GetPopupBackgroundImage() );
1379 value = image.GetUrl();
1383 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1385 value = popupImpl.GetTailUpImage();
1388 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1390 value = popupImpl.GetTailDownImage();
1393 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1395 value = popupImpl.GetTailLeftImage();
1398 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1400 value = popupImpl.GetTailRightImage();
1409 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1411 Dali::BaseHandle handle( object );
1413 bool connected( true );
1414 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1416 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1418 popup.OutsideTouchedSignal().Connect( tracker, functor );
1420 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1422 popup.ShowingSignal().Connect( tracker, functor );
1424 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1426 popup.ShownSignal().Connect( tracker, functor );
1428 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1430 popup.HidingSignal().Connect( tracker, functor );
1432 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1434 popup.HiddenSignal().Connect( tracker, functor );
1438 // signalName does not match any signal
1445 bool Popup::OnBackingTouched( Actor actor, const TouchEvent& event )
1447 // Allow events to pass through if touch transparency is enabled.
1448 if( mTouchTransparent )
1453 if( event.GetPointCount() > 0 )
1455 const TouchPoint& point = event.GetPoint( 0 );
1457 if( point.state == TouchPoint::Down )
1459 // Guard against destruction during signal emission.
1460 Toolkit::Popup handle( GetOwner() );
1462 mTouchedOutsideSignal.Emit();
1466 // Block anything behind backing becoming touched.
1467 mLayer.SetTouchConsumed( true );
1471 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1473 // Allow events to pass through if touch transparency is enabled.
1474 if( mTouchTransparent )
1479 // Consume wheel event in dimmed backing actor.
1480 mLayer.SetTouchConsumed( true );
1484 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
1486 // Allow events to pass through if touch transparency is enabled.
1487 if( mTouchTransparent )
1492 // Consume event (stops backing actor receiving touch events)
1493 mLayer.SetTouchConsumed( true );
1497 void Popup::OnControlStageConnection()
1499 mLayoutDirty = true;
1503 void Popup::OnControlChildAdd( Actor& child )
1505 // Re-parent any children added by user to the body layer.
1506 if( mAlterAddedChild )
1508 SetContent( child );
1512 mLayoutDirty = true;
1517 void Popup::LayoutContext( const Vector2& size )
1519 // Do nothing if not in a contextual mode (or there is no parent context).
1520 Actor self = Self();
1521 Actor parent = self.GetParent();
1522 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1527 mPopupContainer.SetParentOrigin( ParentOrigin::CENTER );
1528 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1529 // mode to allow code-reuse of the bound checking code (for maintainability).
1530 mPopupContainer.SetAnchorPoint( AnchorPoint::CENTER );
1532 // Setup with some pre-calculations for speed.
1533 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1534 Vector3 parentPosition( parent.GetCurrentPosition() );
1535 Vector2 halfSize( size / 2.0f );
1536 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1537 Vector3 newPosition( Vector3::ZERO );
1539 // Perform different positioning based on the specified contextual layout mode.
1540 switch( mContextualMode )
1542 case Toolkit::Popup::BELOW:
1544 newPosition.x += halfSize.x - halfParentSize.x;
1545 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1548 case Toolkit::Popup::ABOVE:
1550 newPosition.x += halfSize.x - halfParentSize.x;
1551 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1554 case Toolkit::Popup::RIGHT:
1556 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1557 newPosition.y += halfSize.y - halfParentSize.y;
1560 case Toolkit::Popup::LEFT:
1562 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1563 newPosition.y += halfSize.y - halfParentSize.y;
1566 case Toolkit::Popup::NON_CONTEXTUAL:
1568 // Code won't reach here (caught earlier).
1573 // On-screen position checking.
1574 // Check new position is not too far right. If so, correct it.
1575 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1576 // the right check and we at least see the left portion of the popup (as this is more useful).
1577 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1579 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1581 // Check new position is not too far left. If so, correct it.
1582 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1584 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1586 // Check new position is not too far down. If so, correct it.
1587 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1589 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1591 // Check new position is not too far up. If so, correct it.
1592 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1594 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1597 // Set the final position.
1598 mPopupContainer.SetPosition( newPosition );
1601 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1603 Vector2 useSize( size );
1605 // Use the Popup layouts size, unless requested to use a fixed size.
1606 // In which case take the size set for the Popup itself.
1607 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1608 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1610 // Width calculations:
1611 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1613 // If we using a child-based policy, take the size from the popup layout.
1614 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1615 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1617 mPopupLayout.SetFitWidth( 0u );
1621 // If we using a parent-based policy, take the size from the popup object itself (self).
1622 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1624 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1627 // Height calculations:
1628 // Title: Let the title be as high as it needs to be.
1629 mPopupLayout.SetFitHeight( 0u );
1631 // Footer: Convert the footer's resize policy to a TableView row policy.
1634 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1635 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1636 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1638 mPopupLayout.SetFitHeight( 2u );
1640 else if( footerHeightPolicy == ResizePolicy::FIXED )
1642 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1646 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1651 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1654 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1655 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1657 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1659 // Let both the contents expand as necessary.
1660 mPopupLayout.SetFitHeight( 1u );
1661 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1665 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1667 // Let the content expand to fill the remaining space.
1668 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1669 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1672 // Relayout the popup-layout to give it it's new size this frame.
1673 container.Add( mPopupLayout, useSize );
1677 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1680 // Perform contextual layout setup if required.
1681 // This is done each time in case the parent moves.
1682 // This will have no effect if no contextual mode is selected.
1683 LayoutContext( useSize );
1686 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1688 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1689 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1691 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1694 mLayoutDirty = true;
1698 Vector3 Popup::GetNaturalSize()
1700 return mPopupLayout.GetNaturalSize();
1703 float Popup::GetHeightForWidth( float width )
1705 return mPopupLayout.GetHeightForWidth( width );
1708 float Popup::GetWidthForHeight( float height )
1710 return mPopupLayout.GetWidthForHeight( height );
1713 bool Popup::OnKeyEvent( const KeyEvent& event )
1715 // Allow events to pass through if touch transparency is enabled.
1716 if( mTouchTransparent )
1721 bool consumed = false;
1723 if( event.state == KeyEvent::Down )
1725 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
1727 SetDisplayState( Toolkit::Popup::HIDDEN );
1735 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1737 Actor nextFocusableActor( currentFocusedActor );
1739 // TODO: Needs to be optimised
1740 if( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor ) != Self() ) )
1742 // The current focused actor is not within popup
1743 if( mContent && mContent.IsKeyboardFocusable() )
1745 // If content is focusable, move the focus to content
1746 nextFocusableActor = mContent;
1751 // Rebuild the focus chain because controls or content can be added or removed dynamically
1752 std::vector< Actor > focusableActors;
1753 if( mContent && mContent.IsKeyboardFocusable() )
1755 focusableActors.push_back( mContent );
1758 for( std::vector< Actor >::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
1760 if( currentFocusedActor == *iter )
1764 case Toolkit::Control::KeyboardFocus::LEFT:
1766 if( iter == focusableActors.begin() )
1768 nextFocusableActor = *( focusableActors.end() - 1 );
1772 nextFocusableActor = *( iter - 1 );
1776 case Toolkit::Control::KeyboardFocus::RIGHT:
1778 if( iter == focusableActors.end() - 1 )
1780 nextFocusableActor = *( focusableActors.begin() );
1784 nextFocusableActor = *( iter + 1 );
1789 case Toolkit::Control::KeyboardFocus::UP:
1791 if( mContent && *iter == mContent )
1793 nextFocusableActor = *( focusableActors.end() - 1 );
1797 if( mContent && mContent.IsKeyboardFocusable() )
1799 nextFocusableActor = mContent;
1803 if ( iter == focusableActors.begin() )
1805 nextFocusableActor = *( focusableActors.end() - 1 );
1809 nextFocusableActor = *( iter - 1 );
1816 case Toolkit::Control::KeyboardFocus::DOWN:
1818 if( mContent && mContent.IsKeyboardFocusable() )
1820 nextFocusableActor = mContent;
1824 if( iter == focusableActors.end() - 1 )
1826 nextFocusableActor = *( focusableActors.begin() );
1830 nextFocusableActor = *( iter + 1 );
1837 if( !nextFocusableActor )
1839 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1847 return nextFocusableActor;
1850 } // namespace Internal
1852 } // namespace Toolkit