2 * Copyright (c) 2020 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/actors/actor-devel.h>
25 #include <dali/public-api/object/type-registry-helper.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/adaptor-framework/key.h>
28 #include <dali/public-api/animation/constraints.h>
29 #include <dali/devel-api/common/stage.h>
30 #include <dali/public-api/events/key-event.h>
31 #include <dali/public-api/events/touch-event.h>
32 #include <dali/public-api/object/type-registry.h>
33 #include <dali/devel-api/scripting/scripting.h>
34 #include <dali/devel-api/actors/actor-devel.h>
35 #include <dali/public-api/size-negotiation/relayout-container.h>
38 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
39 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
40 #include <dali-toolkit/public-api/controls/control-impl.h>
41 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
42 #include <dali-toolkit/devel-api/accessibility-manager/accessibility-manager.h>
43 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
44 #include <dali-toolkit/public-api/visuals/visual-properties.h>
45 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
62 * Creation function for main Popup type.
63 * @return Handle to the new popup object.
67 return Toolkit::Popup::New();
70 // Toast style defaults.
71 const int DEFAULT_TOAST_AUTO_HIDE_DELAY = 3000; ///< Toast will auto-hide after 3000ms (3 seconds)
72 const float DEFAULT_TOAST_TRANSITION_TIME = 0.65f; ///< Default time the toast Popup will take to show and hide.
73 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.
74 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.
77 * Creation function for named type "popupToast".
78 * @return Handle to the new toast popup object.
80 BaseHandle CreateToast()
82 Toolkit::Popup popup = Toolkit::Popup::New();
84 // Setup for Toast Popup type.
85 popup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
86 popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
87 popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
88 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
89 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, DEFAULT_TOAST_TRANSITION_TIME );
90 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
92 // Disable the dimmed backing.
93 popup.SetProperty( Toolkit::Popup::Property::BACKING_ENABLED, false );
95 // The toast popup should fade in (not zoom).
96 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, Toolkit::Popup::FADE );
98 // The toast popup should auto-hide.
99 popup.SetProperty( Toolkit::Popup::Property::AUTO_HIDE_DELAY, DEFAULT_TOAST_AUTO_HIDE_DELAY );
101 // Align to the bottom of the screen.
102 popup.SetProperty( Actor::Property::PARENT_ORIGIN, DEFAULT_TOAST_BOTTOM_PARENT_ORIGIN );
103 popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
105 // Let events pass through the toast popup.
106 popup.SetProperty( Toolkit::Popup::Property::TOUCH_TRANSPARENT, true );
111 // Setup properties, signals and actions using the type-registry.
112 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
114 // Main content related properties.
115 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "title", MAP, TITLE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "content", MAP, CONTENT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "footer", MAP, FOOTER )
118 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "displayState", STRING, DISPLAY_STATE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "touchTransparent", BOOLEAN, TOUCH_TRANSPARENT )
121 // Contextual related properties.
122 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailVisibility", BOOLEAN, TAIL_VISIBILITY )
123 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailPosition", VECTOR3, TAIL_POSITION )
124 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "contextualMode", STRING, CONTEXTUAL_MODE )
126 // Animation related properties.
127 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationDuration", FLOAT, ANIMATION_DURATION )
128 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "animationMode", STRING, ANIMATION_MODE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "entryAnimation", MAP, ENTRY_ANIMATION )
130 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "exitAnimation", MAP, EXIT_ANIMATION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "autoHideDelay", INTEGER, AUTO_HIDE_DELAY )
133 // Style related properties.
134 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingEnabled", BOOLEAN, BACKING_ENABLED )
135 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "backingColor", VECTOR4, BACKING_COLOR )
136 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundImage", STRING, POPUP_BACKGROUND_IMAGE )
137 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "popupBackgroundBorder", RECTANGLE, POPUP_BACKGROUND_BORDER )
138 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailUpImage", STRING, TAIL_UP_IMAGE )
139 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailDownImage", STRING, TAIL_DOWN_IMAGE )
140 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailLeftImage", STRING, TAIL_LEFT_IMAGE )
141 DALI_PROPERTY_REGISTRATION( Toolkit, Popup, "tailRightImage", STRING, TAIL_RIGHT_IMAGE )
144 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touchedOutside", SIGNAL_TOUCHED_OUTSIDE )
145 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "showing", SIGNAL_SHOWING )
146 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "shown", SIGNAL_SHOWN )
147 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hiding", SIGNAL_HIDING )
148 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
150 DALI_TYPE_REGISTRATION_END()
152 // Named type registration.
154 // Toast Popup: Non-modal popup that displays information at the bottom of the screen.
155 TypeRegistration typeRegistrationToast( "PopupToast", typeid( Toolkit::Popup ), CreateToast );
157 // Enumeration to / from string conversion tables
159 const Scripting::StringEnum DisplayStateTable[] = {
160 { "SHOWING", Toolkit::Popup::SHOWING },
161 { "SHOWN", Toolkit::Popup::SHOWN },
162 { "HIDING", Toolkit::Popup::HIDING },
163 { "HIDDEN", Toolkit::Popup::HIDDEN },
164 }; const unsigned int DisplayStateTableCount = sizeof( DisplayStateTable ) / sizeof( DisplayStateTable[0] );
166 const Scripting::StringEnum AnimationModeTable[] = {
167 { "NONE", Toolkit::Popup::NONE },
168 { "ZOOM", Toolkit::Popup::ZOOM },
169 { "FADE", Toolkit::Popup::FADE },
170 { "CUSTOM", Toolkit::Popup::CUSTOM },
171 }; const unsigned int AnimationModeTableCount = sizeof( AnimationModeTable ) / sizeof( AnimationModeTable[0] );
173 const Scripting::StringEnum ContextualModeTable[] = {
174 { "NON_CONTEXTUAL", Toolkit::Popup::NON_CONTEXTUAL },
175 { "ABOVE", Toolkit::Popup::ABOVE },
176 { "RIGHT", Toolkit::Popup::RIGHT },
177 { "BELOW", Toolkit::Popup::BELOW },
178 { "LEFT", Toolkit::Popup::LEFT },
179 }; const unsigned int ContextualModeTableCount = sizeof( ContextualModeTable ) / sizeof( ContextualModeTable[0] );
182 const Vector3 DEFAULT_POPUP_PARENT_RELATIVE_SIZE( 0.75f, 1.0f, 1.0f ); ///< Default size percentage of parent.
183 const float DEFAULT_POPUP_ANIMATION_DURATION = 0.6f; ///< Duration of hide/show animations.
184 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
185 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
186 const Vector3 DEFAULT_TAIL_POSITION( 0.5f, 1.0f, 0.0f ); ///< Position the tail will be displayed when enabled without setting the position.
188 // Contextual defaults.
189 const Vector2 DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN( 10.0f, 10.0f ); ///< How close the Popup will be to it's contextual parent.
190 const Vector2 DEFAULT_CONTEXTUAL_STAGE_BORDER( 15.0f, 15.0f ); ///< How close the Popup can be to the stage edges.
192 // Popup style defaults.
193 const char* DEFAULT_BACKGROUND_IMAGE_FILE_NAME = "00_popup_bg.9.png"; ///< Background image.
194 const char* DEFAULT_TAIL_UP_IMAGE_FILE_NAME = "popup_tail_up.png"; ///< Tail up image.
195 const char* DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME = "popup_tail_down.png"; ///< Tail down image.
196 const char* DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME = "popup_tail_left.png"; ///< Tail left image.
197 const char* DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME = "popup_tail_right.png"; ///< Tail right image.
199 const Vector4 DEFAULT_BACKING_COLOR( 0.0f, 0.0f, 0.0f, 0.5f ); ///< Color of the dimmed backing.
200 const Rect<int> DEFAULT_BACKGROUND_BORDER( 17, 17, 13, 13 ); ///< Default border of the background.
201 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).
202 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).
203 const Vector3 FOOTER_SIZE( 620.0f, 96.0f,0.0f ); ///< Default size of the bottom control area.
204 const float DEFAULT_RELATIVE_PARENT_WIDTH = 0.75f; ///< If width is not fixed, relative size to parent is used by default.
206 } // Unnamed namespace
212 Dali::Toolkit::Popup Popup::New()
214 // Create the implementation
215 PopupPtr popup( new Popup() );
217 // Pass ownership to CustomActor via derived handle.
218 Dali::Toolkit::Popup handle( *popup );
220 // Second-phase initialisation of the implementation.
221 // This can only be done after the CustomActor connection has been made.
228 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
229 mTouchedOutsideSignal(),
237 mPreviousFocusedActor(),
241 mAlterAddedChild( false ),
242 mLayoutDirty( true ),
244 mTouchTransparent( false ),
248 mDisplayState( Toolkit::Popup::HIDDEN ), // Hidden until shown with SetDisplayState()
249 mTailVisible( false ),
250 mTailPosition( DEFAULT_TAIL_POSITION ),
251 mContextualMode( Toolkit::Popup::NON_CONTEXTUAL ),
252 mAnimationDuration( DEFAULT_POPUP_ANIMATION_DURATION ),
253 mAnimationMode( Toolkit::Popup::FADE ),
254 mEntryAnimationData(),
255 mExitAnimationData(),
257 mBackingEnabled( true ),
258 mBackingColor( DEFAULT_BACKING_COLOR ),
259 mPopupBackgroundImage(),
260 mBackgroundBorder( DEFAULT_BACKGROUND_BORDER ),
267 SetKeyboardNavigationSupport( true );
269 const std::string imageDirPath = AssetManager::GetDaliImagePath();
270 mTailUpImage = imageDirPath + DEFAULT_TAIL_UP_IMAGE_FILE_NAME;
271 mTailDownImage = imageDirPath + DEFAULT_TAIL_DOWN_IMAGE_FILE_NAME;
272 mTailLeftImage = imageDirPath + DEFAULT_TAIL_LEFT_IMAGE_FILE_NAME;
273 mTailRightImage = imageDirPath + DEFAULT_TAIL_RIGHT_IMAGE_FILE_NAME;
276 void Popup::OnInitialize()
279 self.SetProperty( Dali::Actor::Property::NAME, "popup" );
281 // Apply some default resizing rules.
282 self.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
283 self.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
285 self.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
286 self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
287 self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
289 // Create a new layer so all Popup components can appear above all other actors.
290 mLayer = Layer::New();
291 mLayer.SetProperty( Dali::Actor::Property::NAME, "popupLayer" );
293 mLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
294 mLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
295 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
297 // Important to set as invisible as otherwise, if the popup is parented,
298 // but not shown yet it will appear statically on the screen.
299 mLayer.SetProperty( Actor::Property::VISIBLE, false );
301 // Add the layer to the hierarchy.
304 // Add Backing (Dimmed effect).
305 mBacking = CreateBacking();
306 mLayer.Add( mBacking );
308 mPopupContainer = Actor::New();
309 mPopupContainer.SetProperty( Dali::Actor::Property::NAME, "popupContainer" );
310 mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
311 mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
312 mPopupContainer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
313 mLayer.Add( mPopupContainer );
315 // Create the Popup layout to contain all main content.
316 mPopupLayout = Toolkit::TableView::New( 3, 1 );
318 // Adds the default background image.
319 const std::string imageDirPath = AssetManager::GetDaliImagePath();
320 SetPopupBackgroundImage( Toolkit::ImageView::New( imageDirPath + DEFAULT_BACKGROUND_IMAGE_FILE_NAME ) );
322 mPopupLayout.SetProperty( Dali::Actor::Property::NAME, "popupLayoutTable" );
323 mPopupLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
324 mPopupLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
326 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
327 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
328 mPopupLayout.SetProperty( Actor::Property::SIZE, Vector2( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f ) );
330 mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
331 mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
333 mPopupContainer.Add( mPopupLayout );
335 // Any content after this point which is added to Self() will be re-parented to mContent.
336 mAlterAddedChild = true;
338 SetAsKeyboardFocusGroup( true );
345 mEntryAnimationData.Clear();
346 mExitAnimationData.Clear();
349 void Popup::LayoutAnimation()
351 // Perform setup based on the currently selected animation.
352 switch( mAnimationMode )
354 case Toolkit::Popup::ZOOM:
356 // Zoom animations start fully zoomed out.
357 mPopupContainer.SetProperty( Actor::Property::SCALE, Vector3::ZERO );
361 case Toolkit::Popup::FADE:
363 // Fade animations start transparent.
364 mPopupContainer.SetProperty( Actor::Property::OPACITY, 0.0f );
368 case Toolkit::Popup::CUSTOM:
370 // Initialise the custom animation by playing to the end of it's exit animation instantly.
371 // EG. If it was zooming in, then we zoom out fully instantly so the zoom in works.
372 StartTransitionAnimation( false, true );
376 case Toolkit::Popup::NONE:
383 void Popup::StartTransitionAnimation( bool transitionIn, bool instantaneous /* false */ )
385 // Stop and recreate animation.
392 float duration = GetAnimationDuration();
394 // Setup variables ready to start the animations.
395 // If we are performing the animation instantaneously, we do not want to emit a signal.
400 // Setup variables and signal that we are starting the transition.
401 // Note: We signal even if the transition is instant so signal order is consistent.
402 mShowingSignal.Emit();
406 mHidingSignal.Emit();
410 // Perform chosen animation for the Popup.
411 switch( mAnimationMode )
413 case Toolkit::Popup::NONE:
415 mAnimation = Animation::New( 0.0f );
419 case Toolkit::Popup::ZOOM:
421 mAnimation = Animation::New( duration );
422 if( duration > Math::MACHINE_EPSILON_0 )
426 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod( duration * 0.25f, duration * 0.75f ) );
430 // Zoom out animation is twice the speed. Modify the duration variable so the backing animation speed is modified also.
432 mAnimation.SetDuration( duration );
433 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::SCALE ), Vector3::ZERO, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration ) );
438 mPopupContainer.SetProperty( Actor::Property::SCALE, transitionIn ? Vector3::ONE : Vector3::ZERO );
443 case Toolkit::Popup::FADE:
445 mAnimation = Animation::New( duration );
446 if( duration > Math::MACHINE_EPSILON_0 )
450 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
454 mAnimation.AnimateTo( Property( mPopupContainer, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
459 mPopupContainer.SetProperty( Actor::Property::OPACITY, transitionIn ? 1.0f : 0.0f );
464 case Toolkit::Popup::CUSTOM:
466 // Use a user specified animation for in and out.
467 // Read the correct animation depending on entry or exit.
468 // Attempt to use animation data defined from script data.
469 Dali::AnimationData* animationData = transitionIn ? &mEntryAnimationData : &mExitAnimationData;
471 // Create a new animation from the pre-defined data in the AnimationData class.
472 // If there is no data, mAnimation is invalidated.
473 mAnimation = animationData->CreateAnimation( mPopupContainer, duration );
475 // If we don't have a valid animation, provide a blank one so play() can still function generically.
478 // No animation was configured (even though custom mode was specified). Create a dummy animation to avoid an exception.
479 mAnimation = Animation::New( 0.0f );
486 // Animate the backing, if enabled.
487 // This is set up last so that different animation modes can have an effect on the backing animation speed.
488 if( mBackingEnabled )
490 // Use the alpha from the user-specified color.
491 float targetAlpha = mBackingColor.a;
492 if( duration > Math::MACHINE_EPSILON_0 )
496 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), targetAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration * 0.70f ) );
500 mAnimation.AnimateTo( Property( mBacking, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN_OUT, TimePeriod( 0.30f, duration * 0.70f ) );
505 mBacking.SetProperty( Actor::Property::COLOR_ALPHA, transitionIn ? targetAlpha : 0.0f );
509 // If we are performing the animation instantaneously, jump to the position directly and do not signal.
512 mAnimation.SetCurrentProgress( 1.0f );
515 else if( duration > Math::MACHINE_EPSILON_0 )
517 // Run the animation.
518 mAnimation.FinishedSignal().Connect( this, &Popup::OnDisplayChangeAnimationFinished );
523 // We did not use an animation to achive the transition.
524 // Trigger the state change directly.
525 DisplayStateChangeComplete();
529 void Popup::OnDisplayChangeAnimationFinished( Animation& source )
531 DisplayStateChangeComplete();
534 void Popup::DisplayStateChangeComplete()
536 // Remove contents from stage if completely hidden.
537 if( mDisplayState == Toolkit::Popup::HIDING )
539 mDisplayState = Toolkit::Popup::HIDDEN;
541 mLayer.SetProperty( Actor::Property::VISIBLE, false );
542 mPopupLayout.SetProperty( Actor::Property::SENSITIVE, false );
544 // Guard against destruction during signal emission.
545 Toolkit::Popup handle( GetOwner() );
546 mHiddenSignal.Emit();
548 else if( mDisplayState == Toolkit::Popup::SHOWING )
550 mDisplayState = Toolkit::Popup::SHOWN;
551 Toolkit::Popup handle( GetOwner() );
554 // Start a timer to auto-hide if enabled.
555 if( mAutoHideDelay > 0u )
557 mAutoHideTimer = Timer::New( mAutoHideDelay );
558 mAutoHideTimer.TickSignal().Connect( this, &Popup::OnAutoHideTimeReached );
559 mAutoHideTimer.Start();
564 bool Popup::OnAutoHideTimeReached()
566 // Display timer has expired, auto hide the popup exactly as if the user had clicked outside.
567 SetDisplayState( Toolkit::Popup::HIDDEN );
571 mAutoHideTimer.Stop();
572 mAutoHideTimer.TickSignal().Disconnect( this, &Popup::OnAutoHideTimeReached );
573 mAutoHideTimer.Reset();
578 void Popup::SetPopupBackgroundImage( Actor image )
580 // Removes any previous background.
581 if( mPopupBackgroundImage )
583 mPopupBackgroundImage.Unparent();
586 mTailImage.Unparent();
590 // Adds new background to the dialog.
591 mPopupBackgroundImage = image;
592 mPopupBackgroundImage.SetProperty( Dali::Actor::Property::NAME, "popupBackgroundImage" );
593 mPopupBackgroundImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
594 mPopupBackgroundImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
596 // Set the popup border to be slightly larger than the layout contents.
597 UpdateBackgroundPositionAndSize();
599 const bool prevAlter = mAlterAddedChild;
600 mAlterAddedChild = false;
601 mPopupContainer.Add( mPopupBackgroundImage );
602 mPopupBackgroundImage.LowerToBottom();
603 mAlterAddedChild = prevAlter;
607 mPopupBackgroundImage.Add( mTailImage );
613 Actor Popup::GetPopupBackgroundImage() const
615 return mPopupBackgroundImage;
618 void Popup::SetTitle( Actor titleActor )
620 // Replaces the current title actor.
628 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0) );
634 // Set up padding to give sensible default behaviour
635 // (an application developer can later override this if they wish).
636 mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING );
638 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
645 Actor Popup::GetTitle() const
650 void Popup::SetContent( Actor content )
652 // Remove previous content actor.
655 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
657 // Keep a handle to the new content.
662 mContent.SetProperty( Dali::Actor::Property::NAME, "popupContent" );
664 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
671 Actor Popup::GetContent() const
676 void Popup::SetFooter( Actor footer )
678 // Remove previous content actor.
681 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 2, 0 ) );
684 // Keep a handle to the new content.
689 mFooter.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
691 // The control container has a fixed height.
692 mPopupLayout.SetFitHeight( 2u );
693 mPopupLayout.AddChild( footer, Toolkit::TableView::CellPosition( 2, 0 ) );
700 Actor Popup::GetFooter() const
705 void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
707 // Convert the 4-way state to a bool, true for show, false for hide.
708 bool display = ( displayState == Toolkit::Popup::SHOWING ) || ( displayState == Toolkit::Popup::SHOWN );
710 // Ignore if we are already at the target display state.
711 if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
716 // Convert the bool state to the actual display state to use.
717 mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
721 // Update the state to indicate the current intent.
722 mDisplayState = Toolkit::Popup::SHOWING;
724 // We want the popup to have key input focus when it is displayed
727 // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
729 mLayer.SetProperty( Actor::Property::VISIBLE, true );
731 // Set up the layout if this is the first display or the layout has become dirty.
734 // Bake-in any style and layout options to create the Popup layout.
738 // Allow the popup to catch events.
739 mPopupLayout.SetProperty( Actor::Property::SENSITIVE, true );
741 // Handle the keyboard focus when popup is shown.
742 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
743 if( keyboardFocusManager )
745 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
747 if( Self().GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
749 // Setup the actgor to start focus from.
751 if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
753 // If the content is focusable, move the focus to the content.
754 focusActor = mContent;
756 else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
758 // If the footer is focusable, move the focus to the footer.
759 focusActor = mFooter;
763 DALI_LOG_WARNING( "There is no focusable in popup\n" );
768 keyboardFocusManager.SetCurrentFocusActor( focusActor );
775 mDisplayState = Toolkit::Popup::HIDING;
776 ClearKeyInputFocus();
778 // Restore the keyboard focus when popup is hidden.
779 if( mPreviousFocusedActor && mPreviousFocusedActor.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
781 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
782 if( keyboardFocusManager )
784 keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
789 // Perform animation.
790 StartTransitionAnimation( display );
793 Toolkit::Popup::DisplayState Popup::GetDisplayState() const
795 return mDisplayState;
798 void Popup::LayoutPopup()
800 mLayoutDirty = false;
802 /* When animating in, we want to respect the origin applied to Self().
803 * For example, if zooming, not only will the final result be anchored to the
804 * selected point, but the zoom will originate from this point also.
806 * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
815 mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, Self().GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ) );
816 mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, Self().GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) );
818 // If there is only a title, use less padding.
821 if( !mContent && !mFooter )
823 mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_ONLY_PADDING );
827 mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING );
831 // Allow derived classes to perform any layout they may need to do.
834 // Update background visibility.
835 mPopupContainer.SetProperty( Actor::Property::VISIBLE, !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
837 // Create / destroy / position the tail as needed.
840 // Setup any layout and initialisation required for the selected animation.
846 void Popup::LayoutTail()
848 // Removes the tail actor.
849 if( mTailImage && mTailImage.GetParent() )
851 mTailImage.GetParent().Remove( mTailImage );
860 const Vector3& parentOrigin = GetTailPosition();
865 // depending on position of tail around ParentOrigin, a different tail image is used...
866 if( parentOrigin.y < Math::MACHINE_EPSILON_1 )
868 image = mTailUpImage;
869 anchorPoint = AnchorPoint::BOTTOM_CENTER;
870 position.y = mBackgroundBorder.top;
872 else if( parentOrigin.y > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
874 image = mTailDownImage;
875 anchorPoint = AnchorPoint::TOP_CENTER;
876 position.y = - mBackgroundBorder.bottom;
878 else if( parentOrigin.x < Math::MACHINE_EPSILON_1 )
880 image = mTailLeftImage;
881 anchorPoint = AnchorPoint::CENTER_RIGHT;
882 position.x = mBackgroundBorder.left;
884 else if( parentOrigin.x > ( 1.0f - Math::MACHINE_EPSILON_1 ) )
886 image = mTailRightImage;
887 anchorPoint = AnchorPoint::CENTER_LEFT;
888 position.x = - mBackgroundBorder.right;
893 // Adds the tail actor.
894 mTailImage = Toolkit::ImageView::New( image );
895 mTailImage.SetProperty( Dali::Actor::Property::NAME, "tailImage" );
896 mTailImage.SetProperty( Actor::Property::PARENT_ORIGIN, parentOrigin );
897 mTailImage.SetProperty( Actor::Property::ANCHOR_POINT, anchorPoint );
898 mTailImage.SetProperty( Actor::Property::POSITION, position );
900 if( mPopupBackgroundImage )
902 mPopupBackgroundImage.Add( mTailImage );
907 void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
909 mContextualMode = mode;
913 Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
915 return mContextualMode;
918 Toolkit::Control Popup::CreateBacking()
920 Toolkit::Control backing = Control::New();
921 backing.SetProperty( Toolkit::Control::Property::BACKGROUND,
922 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR )
923 .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) ) );
924 backing.SetProperty( Dali::Actor::Property::NAME, "popupBacking" );
926 // Must always be positioned top-left of stage, regardless of parent.
927 backing.SetProperty( Actor::Property::INHERIT_POSITION, false );
929 // Always the full size of the stage.
930 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
931 backing.SetProperty( Actor::Property::SIZE, Stage::GetCurrent().GetSize() );
934 backing.SetProperty( Actor::Property::SENSITIVE, true );
936 // Default to being transparent.
937 backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
938 backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
942 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
944 return mTouchedOutsideSignal;
947 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
949 return mShowingSignal;
952 Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
957 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
959 return mHidingSignal;
962 Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
964 return mHiddenSignal;
967 void Popup::SetTailVisibility( bool visible )
969 mTailVisible = visible;
973 const bool Popup::IsTailVisible() const
978 void Popup::SetTailPosition( Vector3 position )
980 mTailPosition = position;
984 const Vector3& Popup::GetTailPosition() const
986 return mTailPosition;
989 void Popup::SetAnimationDuration( float duration )
991 mAnimationDuration = duration;
995 float Popup::GetAnimationDuration() const
997 return mAnimationDuration;
1000 void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
1002 mAnimationMode = animationMode;
1003 mLayoutDirty = true;
1006 Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
1008 return mAnimationMode;
1011 void Popup::SetEntryAnimationData( const Property::Map& map )
1013 mEntryAnimationData.Clear();
1014 Scripting::NewAnimation( map, mEntryAnimationData );
1017 void Popup::SetExitAnimationData( const Property::Map& map )
1019 mExitAnimationData.Clear();
1020 Scripting::NewAnimation( map, mExitAnimationData );
1023 void Popup::UpdateBackgroundPositionAndSize()
1025 if( mPopupBackgroundImage )
1027 mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
1028 mPopupBackgroundImage.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) );
1030 // Adjust the position of the background so the transparent areas are set appropriately
1031 mPopupBackgroundImage.SetProperty( Actor::Property::POSITION, Vector2( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f ));
1035 void Popup::SetAutoHideDelay( int delay )
1037 mAutoHideDelay = delay;
1040 int Popup::GetAutoHideDelay() const
1042 return mAutoHideDelay;
1045 void Popup::SetBackingEnabled( bool enabled )
1047 mBackingEnabled = enabled;
1048 mLayoutDirty = true;
1051 const bool Popup::IsBackingEnabled() const
1053 return mBackingEnabled;
1056 void Popup::SetBackingColor( Vector4 color )
1058 mBackingColor = color;
1059 mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
1060 mLayoutDirty = true;
1063 const Vector4& Popup::GetBackingColor() const
1065 return mBackingColor;
1068 void Popup::SetTailUpImage( std::string image )
1070 mTailUpImage = image;
1071 mLayoutDirty = true;
1075 const std::string& Popup::GetTailUpImage() const
1077 return mTailUpImage;
1080 void Popup::SetTailDownImage( std::string image )
1082 mTailDownImage = image;
1083 mLayoutDirty = true;
1087 const std::string& Popup::GetTailDownImage() const
1089 return mTailDownImage;
1092 void Popup::SetTailLeftImage( std::string image )
1094 mTailLeftImage = image;
1095 mLayoutDirty = true;
1099 const std::string& Popup::GetTailLeftImage() const
1101 return mTailLeftImage;
1104 void Popup::SetTailRightImage( std::string image )
1106 mTailRightImage = image;
1107 mLayoutDirty = true;
1111 const std::string& Popup::GetTailRightImage() const
1113 return mTailRightImage;
1116 void Popup::SetTouchTransparent( bool enabled )
1118 if( mTouchTransparent != enabled )
1120 mTouchTransparent = enabled;
1125 const bool Popup::IsTouchTransparent() const
1127 return mTouchTransparent;
1130 void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1132 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1136 Popup& popupImpl( GetImpl( popup ) );
1138 switch ( propertyIndex )
1140 case Toolkit::Popup::Property::TITLE:
1142 Property::Map valueMap;
1143 if( value.Get( valueMap ) )
1145 popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
1149 case Toolkit::Popup::Property::CONTENT:
1151 Property::Map valueMap;
1152 if( value.Get( valueMap ) )
1154 popupImpl.SetContent( Scripting::NewActor( valueMap ) );
1158 case Toolkit::Popup::Property::FOOTER:
1160 Property::Map valueMap;
1161 if( value.Get( valueMap ) )
1163 popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
1167 case Toolkit::Popup::Property::DISPLAY_STATE:
1169 std::string valueString;
1170 if( value.Get( valueString ) )
1172 Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
1173 if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
1175 popupImpl.SetDisplayState( displayState );
1180 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1183 if( value.Get( valueBool ) )
1185 popupImpl.SetTouchTransparent( valueBool );
1189 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1192 if( value.Get( valueBool ) )
1194 popupImpl.SetTailVisibility( valueBool );
1198 case Toolkit::Popup::Property::TAIL_POSITION:
1200 Vector3 valueVector3;
1201 if( value.Get( valueVector3 ) )
1203 popupImpl.SetTailPosition( valueVector3 );
1207 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1209 std::string valueString;
1210 if( value.Get( valueString ) )
1212 Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
1213 if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
1215 popupImpl.SetContextualMode( contextualMode );
1220 case Toolkit::Popup::Property::ANIMATION_DURATION:
1223 if( value.Get( valueFloat ) )
1225 popupImpl.SetAnimationDuration( valueFloat );
1229 case Toolkit::Popup::Property::ANIMATION_MODE:
1231 std::string valueString;
1232 if( value.Get( valueString ) )
1234 Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
1235 if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
1237 popupImpl.SetAnimationMode( animationMode );
1242 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1244 Property::Map valueMap;
1245 if( value.Get( valueMap ) )
1247 popupImpl.SetEntryAnimationData( valueMap );
1251 case Toolkit::Popup::Property::EXIT_ANIMATION:
1253 Property::Map valueMap;
1254 if( value.Get( valueMap ) )
1256 popupImpl.SetExitAnimationData( valueMap );
1260 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1263 if( value.Get( valueInt ) )
1265 popupImpl.SetAutoHideDelay( valueInt );
1269 case Toolkit::Popup::Property::BACKING_ENABLED:
1272 if( value.Get( valueBool ) )
1274 popupImpl.SetBackingEnabled( valueBool );
1278 case Toolkit::Popup::Property::BACKING_COLOR:
1280 Vector4 valueVector4;
1281 if( value.Get( valueVector4 ) )
1283 popupImpl.SetBackingColor( valueVector4 );
1287 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1289 std::string valueString;
1290 if( value.Get( valueString ) )
1292 Toolkit::ImageView actor = Toolkit::ImageView::New( valueString );
1293 popupImpl.SetPopupBackgroundImage( actor );
1297 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1299 bool valueUpdated = false;
1301 Vector4 valueVector4;
1302 if( value.Get( popupImpl.mBackgroundBorder ) )
1304 valueUpdated = true;
1306 else if( value.Get( valueVector4 ) )
1308 popupImpl.mBackgroundBorder.left = valueVector4.x;
1309 popupImpl.mBackgroundBorder.right = valueVector4.y;
1310 popupImpl.mBackgroundBorder.bottom = valueVector4.z;
1311 popupImpl.mBackgroundBorder.top = valueVector4.w;
1312 valueUpdated = true;
1317 popupImpl.LayoutTail(); // Update the tail if required
1318 popupImpl.UpdateBackgroundPositionAndSize(); // Update the background's size and position
1322 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1324 std::string valueString;
1325 if( value.Get( valueString ) )
1327 popupImpl.SetTailUpImage( valueString );
1331 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1333 std::string valueString;
1334 if( value.Get( valueString ) )
1336 popupImpl.SetTailDownImage( valueString );
1340 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1342 std::string valueString;
1343 if( value.Get( valueString ) )
1345 popupImpl.SetTailLeftImage( valueString );
1349 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1351 std::string valueString;
1352 if( value.Get( valueString ) )
1354 popupImpl.SetTailRightImage( valueString );
1362 Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
1364 Property::Value value;
1366 Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
1370 Popup& popupImpl( GetImpl( popup ) );
1372 switch ( propertyIndex )
1374 case Toolkit::Popup::Property::TITLE:
1377 Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
1381 case Toolkit::Popup::Property::CONTENT:
1384 Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
1388 case Toolkit::Popup::Property::FOOTER:
1391 Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
1395 case Toolkit::Popup::Property::DISPLAY_STATE:
1397 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
1400 case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
1402 value = popupImpl.IsTouchTransparent();
1405 case Toolkit::Popup::Property::TAIL_VISIBILITY:
1407 value = popupImpl.IsTailVisible();
1410 case Toolkit::Popup::Property::TAIL_POSITION:
1412 value = popupImpl.GetTailPosition();
1415 case Toolkit::Popup::Property::CONTEXTUAL_MODE:
1417 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
1420 case Toolkit::Popup::Property::ANIMATION_DURATION:
1422 value = popupImpl.GetAnimationDuration();
1425 case Toolkit::Popup::Property::ANIMATION_MODE:
1427 value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
1430 case Toolkit::Popup::Property::ENTRY_ANIMATION:
1432 // Note: Cannot retrieve property map from animation.
1437 case Toolkit::Popup::Property::EXIT_ANIMATION:
1439 // Note: Cannot retrieve property map from animation.
1444 case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
1446 value = popupImpl.GetAutoHideDelay();
1449 case Toolkit::Popup::Property::BACKING_ENABLED:
1451 value = popupImpl.IsBackingEnabled();
1454 case Toolkit::Popup::Property::BACKING_COLOR:
1456 value = popupImpl.GetBackingColor();
1459 case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
1461 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( popupImpl.GetPopupBackgroundImage() );
1464 value = imageView.GetProperty( Toolkit::ImageView::Property::IMAGE );
1468 case Toolkit::Popup::Property::POPUP_BACKGROUND_BORDER:
1470 value = popupImpl.mBackgroundBorder;
1473 case Toolkit::Popup::Property::TAIL_UP_IMAGE:
1475 value = popupImpl.GetTailUpImage();
1478 case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
1480 value = popupImpl.GetTailDownImage();
1483 case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
1485 value = popupImpl.GetTailLeftImage();
1488 case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
1490 value = popupImpl.GetTailRightImage();
1499 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1501 Dali::BaseHandle handle( object );
1503 bool connected( true );
1504 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
1506 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
1508 popup.OutsideTouchedSignal().Connect( tracker, functor );
1510 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWING ) )
1512 popup.ShowingSignal().Connect( tracker, functor );
1514 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SHOWN ) )
1516 popup.ShownSignal().Connect( tracker, functor );
1518 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDING ) )
1520 popup.HidingSignal().Connect( tracker, functor );
1522 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
1524 popup.HiddenSignal().Connect( tracker, functor );
1528 // signalName does not match any signal
1535 bool Popup::OnBackingTouched( Actor actor, const TouchEvent& touch )
1537 // Allow events to pass through if the backing isn't the hit-actor
1538 if( (touch.GetHitActor(0) == actor) &&
1539 (touch.GetPointCount() > 0) &&
1540 (touch.GetState( 0 ) == PointState::DOWN))
1542 // Guard against destruction during signal emission.
1543 Toolkit::Popup handle( GetOwner() );
1545 mTouchedOutsideSignal.Emit();
1551 bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
1553 // Allow events to pass through if touch transparency is enabled.
1554 if( mTouchTransparent )
1562 bool Popup::OnDialogTouched( Actor actor, const TouchEvent& touch )
1564 // Only connecting this so the backing does not become the default hit-actor and inadvertently closes the popup
1568 void Popup::OnSceneConnection( int depth )
1570 mLayoutDirty = true;
1573 Control::OnSceneConnection( depth );
1576 void Popup::OnChildAdd( Actor& child )
1578 // Re-parent any children added by user to the body layer.
1579 if( mAlterAddedChild )
1581 SetContent( child );
1585 mLayoutDirty = true;
1589 Control::OnChildAdd( child );
1592 void Popup::LayoutContext( const Vector2& size )
1594 // Do nothing if not in a contextual mode (or there is no parent context).
1595 Actor self = Self();
1596 Actor parent = self.GetParent();
1597 if( ( mContextualMode == Toolkit::Popup::NON_CONTEXTUAL ) || !parent )
1602 mPopupContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
1603 // We always anchor to the CENTER, rather than a different anchor point for each contextual
1604 // mode to allow code-reuse of the bound checking code (for maintainability).
1605 mPopupContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
1607 // Setup with some pre-calculations for speed.
1608 Vector3 halfStageSize( Stage().GetCurrent().GetSize() / 2.0f );
1609 Vector3 parentPosition( parent.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) );
1610 Vector2 halfSize( size / 2.0f );
1611 Vector2 halfParentSize( parent.GetRelayoutSize( Dimension::WIDTH ) / 2.0f, parent.GetRelayoutSize( Dimension::HEIGHT ) / 2.0f );
1612 Vector3 newPosition( Vector3::ZERO );
1614 // Perform different positioning based on the specified contextual layout mode.
1615 switch( mContextualMode )
1617 case Toolkit::Popup::BELOW:
1619 newPosition.x += halfSize.x - halfParentSize.x;
1620 newPosition.y += halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1623 case Toolkit::Popup::ABOVE:
1625 newPosition.x += halfSize.x - halfParentSize.x;
1626 newPosition.y -= halfSize.y + halfParentSize.y + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.y;
1629 case Toolkit::Popup::RIGHT:
1631 newPosition.x += halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1632 newPosition.y += halfSize.y - halfParentSize.y;
1635 case Toolkit::Popup::LEFT:
1637 newPosition.x -= halfSize.x + halfParentSize.x + DEFAULT_CONTEXTUAL_ADJACENCY_MARGIN.x;
1638 newPosition.y += halfSize.y - halfParentSize.y;
1641 case Toolkit::Popup::NON_CONTEXTUAL:
1643 // Code won't reach here (caught earlier).
1648 // On-screen position checking.
1649 // Check new position is not too far right. If so, correct it.
1650 // Note: Check for right rather than left first, so if popup is too wide, the left check overrides
1651 // the right check and we at least see the left portion of the popup (as this is more useful).
1652 if( newPosition.x >= ( halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x ) )
1654 newPosition.x = halfStageSize.x - parentPosition.x - halfSize.x - DEFAULT_CONTEXTUAL_STAGE_BORDER.x;
1656 // Check new position is not too far left. If so, correct it.
1657 if( newPosition.x < halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x )
1659 newPosition.x = halfSize.x - ( parentPosition.x + halfStageSize.x ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.x;// - parentSize.x;
1661 // Check new position is not too far down. If so, correct it.
1662 if( newPosition.y >= ( halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y ) )
1664 newPosition.y = halfStageSize.y - parentPosition.y - halfSize.y - DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1666 // Check new position is not too far up. If so, correct it.
1667 if( newPosition.y < halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y )
1669 newPosition.y = halfSize.y - ( parentPosition.y + halfStageSize.y ) + DEFAULT_CONTEXTUAL_STAGE_BORDER.y;
1672 // Set the final position.
1673 mPopupContainer.SetProperty( Actor::Property::POSITION, newPosition );
1676 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
1678 Vector2 useSize( size );
1680 // Use the Popup layouts size, unless requested to use a fixed size.
1681 // In which case take the size set for the Popup itself.
1682 ResizePolicy::Type widthPolicy = Self().GetResizePolicy( Dimension::WIDTH );
1683 ResizePolicy::Type heightPolicy = Self().GetResizePolicy( Dimension::HEIGHT );
1685 // Width calculations:
1686 if( widthPolicy == ResizePolicy::USE_NATURAL_SIZE || widthPolicy == ResizePolicy::FIT_TO_CHILDREN )
1688 // If we using a child-based policy, take the size from the popup layout.
1689 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
1690 useSize.width = mPopupLayout.GetRelayoutSize( Dimension::WIDTH );
1692 mPopupLayout.SetFitWidth( 0u );
1696 // If we using a parent-based policy, take the size from the popup object itself (self).
1697 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
1699 mPopupLayout.SetFixedWidth( 0u, useSize.width );
1702 // Height calculations:
1703 // Title: Let the title be as high as it needs to be.
1704 mPopupLayout.SetFitHeight( 0u );
1706 // Footer: Convert the footer's resize policy to a TableView row policy.
1709 ResizePolicy::Type footerHeightPolicy = mFooter.GetResizePolicy( Dimension::HEIGHT );
1710 if( ( footerHeightPolicy == ResizePolicy::USE_NATURAL_SIZE ) ||
1711 ( footerHeightPolicy == ResizePolicy::FIT_TO_CHILDREN ) )
1713 mPopupLayout.SetFitHeight( 2u );
1715 else if( footerHeightPolicy == ResizePolicy::FIXED )
1717 mPopupLayout.SetFixedHeight( 2u, mFooter.GetRelayoutSize( Dimension::HEIGHT) );
1721 mPopupLayout.SetRelativeHeight( 2u, 1.0f );
1726 mPopupLayout.SetFixedHeight( 2u, 0.0f );
1729 // Popup contents: Adjust the tableview's policies based on the popup's policies.
1730 if( heightPolicy == ResizePolicy::USE_NATURAL_SIZE || heightPolicy == ResizePolicy::FIT_TO_CHILDREN )
1732 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1734 // Let both the contents expand as necessary.
1735 mPopupLayout.SetFitHeight( 1u );
1736 useSize.height = mPopupLayout.GetRelayoutSize( Dimension::HEIGHT );
1740 mPopupLayout.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
1742 // Let the content expand to fill the remaining space.
1743 mPopupLayout.SetRelativeHeight( 1u, 1.0f );
1744 mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT );
1747 // Relayout the popup-layout to give it it's new size this frame.
1748 container.Add( mPopupLayout, useSize );
1752 container.Add( mContent, Vector2( mContent.GetRelayoutSize( Dimension::WIDTH ), mContent.GetRelayoutSize( Dimension::HEIGHT ) ) );
1755 // Perform contextual layout setup if required.
1756 // This is done each time in case the parent moves.
1757 // This will have no effect if no contextual mode is selected.
1758 LayoutContext( useSize );
1761 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1763 // To get the popup to emulate fit-to-children, we need to actually set use-natural-size.
1764 if( ( dimension & Dimension::HEIGHT ) && ( policy == ResizePolicy::FIT_TO_CHILDREN ) )
1766 Self().SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
1769 mLayoutDirty = true;
1773 Vector3 Popup::GetNaturalSize()
1775 return mPopupLayout.GetNaturalSize();
1778 float Popup::GetHeightForWidth( float width )
1780 return mPopupLayout.GetHeightForWidth( width );
1783 float Popup::GetWidthForHeight( float height )
1785 return mPopupLayout.GetWidthForHeight( height );
1788 bool Popup::OnKeyEvent( const KeyEvent& event )
1790 // Allow events to pass through if touch transparency is enabled.
1791 if( mTouchTransparent )
1796 bool consumed = false;
1798 if( event.GetState() == KeyEvent::DOWN )
1800 if (event.GetKeyCode() == Dali::DALI_KEY_ESCAPE || event.GetKeyCode() == Dali::DALI_KEY_BACK)
1802 SetDisplayState( Toolkit::Popup::HIDDEN );
1810 void Popup::AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors )
1814 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1815 bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
1817 if( parent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) || layoutControl )
1819 focusableActors.push_back( parent );
1821 if( !layoutControl )
1823 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1825 Actor child( parent.GetChildAt( i ) );
1826 AddFocusableChildrenRecursive( child, focusableActors );
1833 void Popup::AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors )
1837 Toolkit::Control control = Toolkit::Control::DownCast( parent );
1838 if( !GetImplementation( control ).IsKeyboardNavigationSupported() )
1840 for( unsigned int i = 0, numberChildren = parent.GetChildCount(); i < numberChildren; ++i )
1842 Actor child( parent.GetChildAt( i ) );
1843 AddFocusableChildrenRecursive( child, focusableActors );
1848 focusableActors.push_back( parent );
1853 Actor Popup::GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled )
1855 std::string currentStr;
1856 if( currentFocusedActor )
1858 currentStr = currentFocusedActor.GetProperty< std::string >( Dali::Actor::Property::NAME );
1861 Actor nextFocusableActor( currentFocusedActor );
1862 Actor currentFocusGroup;
1863 if( currentFocusedActor )
1865 currentFocusGroup = KeyboardFocusManager::Get().GetFocusGroup( currentFocusedActor );
1868 // TODO: Needs to be optimised
1869 // The following statement checks that if we have a current focused actor, then the current focus group is not the popup content or footer.
1870 // This is to detect if the focus is currently outside the popup, and if so, move it inside.
1871 if( !currentFocusedActor ||
1872 ( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
1874 // The current focused actor is not within popup.
1875 if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
1877 // If the content is focusable, move the focus to the content.
1878 nextFocusableActor = mContent;
1880 else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
1882 // If the footer is focusable, move the focus to the footer.
1883 nextFocusableActor = mFooter;
1888 // Rebuild the focus chain because controls or content can be added or removed dynamically
1889 std::vector< Actor > focusableActors;
1891 AddFocusableChildren( mContent, focusableActors );
1892 AddFocusableChildren( mFooter, focusableActors );
1894 std::vector< Actor >::iterator endIterator = focusableActors.end();
1895 std::vector< Actor >::iterator currentIterator = focusableActors.begin();
1896 for( std::vector< Actor >::iterator iterator = focusableActors.begin(); iterator != endIterator; ++iterator )
1898 if( currentFocusedActor == *iterator )
1900 currentIterator = iterator;
1904 if( currentIterator != endIterator )
1908 case Toolkit::Control::KeyboardFocus::LEFT:
1910 if( currentIterator == focusableActors.begin() )
1912 nextFocusableActor = *( endIterator - 1 );
1916 nextFocusableActor = *( currentIterator - 1 );
1920 case Toolkit::Control::KeyboardFocus::RIGHT:
1922 if( currentIterator == endIterator - 1 )
1924 nextFocusableActor = *( focusableActors.begin() );
1928 nextFocusableActor = *( currentIterator + 1 );
1933 case Toolkit::Control::KeyboardFocus::UP:
1935 nextFocusableActor = *( focusableActors.begin() );
1939 case Toolkit::Control::KeyboardFocus::DOWN:
1941 nextFocusableActor = *( endIterator - 1 );
1951 if( !nextFocusableActor )
1953 DALI_LOG_WARNING( "Can not decide next focusable actor\n" );
1958 return nextFocusableActor;
1961 void Popup::SetupTouch()
1963 if( ! mTouchTransparent )
1965 // Connect all the signals and set us up to consume all touch events
1966 mBacking.TouchSignal().Connect( this, &Popup::OnBackingTouched );
1967 mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
1968 mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
1969 mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1973 // We are touch transparent so disconnect all signals and ensure our layer does not consumed all touch events
1974 mBacking.TouchSignal().Disconnect( this, &Popup::OnBackingTouched );
1975 mPopupBackgroundImage.TouchSignal().Disconnect( this, &Popup::OnDialogTouched );
1976 mPopupLayout.TouchSignal().Disconnect( this, &Popup::OnDialogTouched );
1977 mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, false );
1981 } // namespace Internal
1983 } // namespace Toolkit