2 * Copyright (c) 2014 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/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/adaptor-framework/physical-keyboard.h>
25 #include <dali/public-api/animation/constraints.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/events/key-event.h>
28 #include <dali/public-api/events/touch-event.h>
29 #include <dali/public-api/images/resource-image.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-api/size-negotiation/relayout-container.h>
33 #include <dali/integration-api/debug.h>
36 #include <dali-toolkit/public-api/controls/buttons/button.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
39 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
40 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
58 return Toolkit::Popup::New();
61 // Setup properties, signals and actions using the type-registry.
62 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
64 DALI_SIGNAL_REGISTRATION( Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
65 DALI_SIGNAL_REGISTRATION( Popup, "hidden", SIGNAL_HIDDEN )
67 DALI_TYPE_REGISTRATION_END()
70 const char* const PROPERTY_TITLE = "title";
71 const char* const PROPERTY_STATE = "state";
73 const float POPUP_ANIMATION_DURATION = 0.45f; ///< Duration of hide/show animations
75 const float POPUP_WIDTH = 720.0f; ///< Width of Popup
76 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
77 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
78 const float POPUP_TITLE_WIDTH = 648.0f; ///<Width of Popup Title
79 const float POPUP_BUTTON_BG_HEIGHT = 96.f; ///< Height of Button Background.
80 const Vector3 DEFAULT_DIALOG_SIZE = Vector3(POPUP_TITLE_WIDTH/POPUP_WIDTH, 0.5f, 0.0f);
81 const Vector3 DEFAULT_BOTTOM_SIZE = Vector3(1.0f, 0.2f, 0.0f);
83 } // unnamed namespace
85 ///////////////////////////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////////////////////////
89 Dali::Toolkit::Popup Popup::New()
91 PopupStylePtr style = PopupStyleDefault::New();
93 // Create the implementation
94 PopupPtr popup(new Popup(*style));
96 // Pass ownership to CustomActor via derived handle
97 Dali::Toolkit::Popup handle(*popup);
99 // Second-phase init of the implementation
100 // This can only be done after the CustomActor connection has been made...
106 Popup::Popup(PopupStyle& style)
107 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
109 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
110 mAlterAddedChild(false),
111 mPopupStyle(PopupStylePtr(&style)),
112 mPropertyTitle(Property::INVALID_INDEX),
113 mPropertyState(Property::INVALID_INDEX)
115 SetKeyboardNavigationSupport( true );
118 void Popup::OnInitialize()
120 Dali::Stage stage = Dali::Stage::GetCurrent();
123 self.SetSensitive(false);
124 // Reisize to fit the height of children
125 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
128 mLayer = Layer::New();
129 mLayer.SetName( "POPUP_LAYER" );
130 mLayer.SetParentOrigin(ParentOrigin::CENTER);
131 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
132 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
133 mLayer.SetDrawMode( DrawMode::OVERLAY );
135 // Any content after this point which is added to Self() will be reparented to
137 mAlterAddedChild = true;
138 // Add Backing (Dim effect)
140 mAlterAddedChild = false;
142 // Add Dialog ( background image, title, content container, button container and tail )
147 mPopupLayout = Toolkit::TableView::New( 3, 1 );
148 mPopupLayout.SetName( "POPUP_LAYOUT_TABLE" );
149 mPopupLayout.SetParentOrigin(ParentOrigin::CENTER);
150 mPopupLayout.SetAnchorPoint(AnchorPoint::CENTER);
151 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
152 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
153 mPopupLayout.SetFitHeight( 0 ); // Set row to fit
154 mPopupLayout.SetFitHeight( 1 ); // Set row to fit
155 self.Add( mPopupLayout );
157 // Any content after this point which is added to Self() will be reparented to
159 mAlterAddedChild = true;
162 // ShowTail(ParentOrigin::BOTTOM_CENTER);
164 // Hide content by default.
165 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
167 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
168 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
170 // Make self as keyboard focusable and focus group
171 self.SetKeyboardFocusable(true);
172 SetAsKeyboardFocusGroup(true);
175 void Popup::MarkDirtyForRelayout()
177 // Flag all the popup controls for relayout as it is about to be hidden and miss the main flagging pass
178 mLayer.RelayoutRequestTree();
181 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
183 if( index == mPropertyTitle )
185 SetTitle(propertyValue.Get<std::string>());
187 else if ( index == mPropertyState )
189 std::string value( propertyValue.Get<std::string>() );
190 if(value == "POPUP_SHOW")
192 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
194 else if( value == "POPUP_HIDE")
196 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
206 size_t Popup::GetButtonCount() const
208 return mButtons.size();
211 void Popup::SetBackgroundImage( Actor image )
213 // Removes any previous background.
214 if( mBackgroundImage && mPopupLayout )
216 mPopupLayout.Remove( mBackgroundImage );
219 // Adds new background to the dialog.
220 mBackgroundImage = image;
222 mBackgroundImage.SetName( "POPUP_BACKGROUND_IMAGE" );
224 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
225 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
227 mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
228 mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
229 mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
231 Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f );
232 mBackgroundImage.SetSizeModeFactor( border );
234 const bool prevAlter = mAlterAddedChild;
235 mAlterAddedChild = false;
236 Self().Add( mBackgroundImage );
237 mAlterAddedChild = prevAlter;
240 void Popup::SetButtonAreaImage( Actor image )
242 // Removes any previous area image.
243 if( mButtonAreaImage && mPopupLayout )
245 mPopupLayout.Remove( mButtonAreaImage );
248 // Adds new area image to the dialog.
249 mButtonAreaImage = image;
251 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
252 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
254 mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
255 mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER );
256 mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER );
258 if( GetButtonCount() > 0 )
260 mBottomBg.Add( mButtonAreaImage );
264 void Popup::SetTitle( const std::string& text )
266 // Replaces the current title actor.
269 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
272 mTitle = Toolkit::TextLabel::New( text );
273 mTitle.SetName( "POPUP_TITLE" );
274 mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
275 mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
279 mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
280 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
281 mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
282 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
288 std::string Popup::GetTitle() const
292 return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
295 return std::string();
298 void Popup::CreateFooter()
302 // Adds bottom background
303 mBottomBg = Actor::New();
304 mBottomBg.SetName( "POPUP_BOTTOM_BG" );
305 mBottomBg.SetRelayoutEnabled( true );
306 mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
308 mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height ); // Buttons
309 mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) );
313 void Popup::AddButton( Toolkit::Button button )
315 mButtons.push_back( button );
316 button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); // Size will be assigned to it
318 // If this is the first button added
319 if( mButtons.size() == 1 )
323 if( mButtonAreaImage )
325 mBottomBg.Add( mButtonAreaImage );
329 mBottomBg.Add( button );
334 void Popup::SetState( Toolkit::Popup::PopupState state )
336 SetState( state, POPUP_ANIMATION_DURATION );
339 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
341 // default animation behaviour.
342 HandleStateChange(state, duration);
345 Toolkit::Popup::PopupState Popup::GetState() const
350 void Popup::ShowTail(const Vector3& position)
352 // Replaces the tail actor.
353 if(mTailImage && mTailImage.GetParent())
355 mTailImage.GetParent().Remove( mTailImage );
359 std::string image = "";
361 // depending on position of tail around ParentOrigin, a different tail image is used...
362 if(position.y < Math::MACHINE_EPSILON_1)
364 image = mPopupStyle->tailUpImage;
366 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
368 image = mPopupStyle->tailDownImage;
370 else if(position.x < Math::MACHINE_EPSILON_1)
372 image = mPopupStyle->tailLeftImage;
374 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
376 image = mPopupStyle->tailRightImage;
381 Image tail = ResourceImage::New( image );
382 mTailImage = ImageActor::New(tail);
383 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
385 mTailImage.SetParentOrigin(position);
386 mTailImage.SetAnchorPoint(anchorPoint);
390 mBottomBg.Add(mTailImage);
394 void Popup::HideTail()
396 ShowTail(ParentOrigin::CENTER);
399 void Popup::SetStyle(PopupStyle& style)
401 mPopupStyle = PopupStylePtr(&style);
405 PopupStylePtr Popup::GetStyle() const
410 void Popup::SetDefaultBackgroundImage()
412 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
413 ImageActor buttonBgImage = ImageActor::New( buttonBg );
414 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
415 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
417 SetBackgroundImage( ImageActor::New( ResourceImage::New( mPopupStyle->backgroundImage ) ) );
418 SetButtonAreaImage( buttonBgImage );
421 void Popup::CreateBacking()
423 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
424 mBacking.SetName( "POPUP_BACKING" );
426 mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
427 mBacking.SetSensitive(true);
429 mLayer.Add( mBacking );
430 mBacking.SetOpacity(0.0f);
431 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
432 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
435 void Popup::CreateDialog()
437 // Adds default background image.
438 SetDefaultBackgroundImage();
441 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
444 float targetBackingAlpha;
453 case Toolkit::Popup::POPUP_HIDE:
455 targetSize = Vector3(0.0f, 0.0f, 1.0f);
456 targetBackingAlpha = 0.0f;
458 ClearKeyInputFocus();
460 // Retore the keyboard focus when popup is hidden
461 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
463 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
464 if( keyboardFocusManager )
466 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
473 case Toolkit::Popup::POPUP_SHOW:
476 targetSize = Vector3(1.0f, 1.0f, 1.0f);
477 targetBackingAlpha = 1.0f;
480 // Add contents to stage for showing.
481 if( !mLayer.GetParent() )
483 Dali::Stage stage = Dali::Stage::GetCurrent();
488 Self().SetSensitive(true);
491 // Handle the keyboard focus when popup is shown
492 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
493 if( keyboardFocusManager )
495 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
497 if( mContent && mContent.IsKeyboardFocusable() )
499 // If content is focusable, move the focus to content
500 keyboardFocusManager.SetCurrentFocusActor(mContent);
502 else if( !mButtons.empty() )
504 // Otherwise, movethe focus to the first button
505 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
509 DALI_LOG_WARNING("There is no focusable in popup\n");
517 if(duration > Math::MACHINE_EPSILON_1)
525 mAnimation = Animation::New(duration);
529 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
530 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
534 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
535 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
538 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
542 mBacking.SetOpacity( targetBackingAlpha );
543 self.SetScale( targetSize );
545 HandleStateChangeComplete();
549 void Popup::HandleStateChangeComplete()
551 // Remove contents from stage if completely hidden.
552 if( ( mState == Toolkit::Popup::POPUP_HIDE ) && mLayer.GetParent() )
555 Self().SetSensitive( false );
557 // Guard against destruction during signal emission
558 Toolkit::Popup handle( GetOwner() );
559 mHiddenSignal.Emit();
563 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
565 return mTouchedOutsideSignal;
568 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
570 return mHiddenSignal;
573 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
575 Dali::BaseHandle handle( object );
577 bool connected( true );
578 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
580 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
582 popup.OutsideTouchedSignal().Connect( tracker, functor );
584 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
586 popup.HiddenSignal().Connect( tracker, functor );
590 // signalName does not match any signal
597 void Popup::OnStateAnimationFinished( Animation& source )
599 HandleStateChangeComplete();
602 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
604 if(event.GetPointCount()>0)
606 const TouchPoint& point = event.GetPoint(0);
608 if(point.state == TouchPoint::Down)
610 // Guard against destruction during signal emission
611 Toolkit::Popup handle( GetOwner() );
613 mTouchedOutsideSignal.Emit();
620 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
622 // consume mouse wheel event in dimmed backing actor
626 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
628 // consume event (stops backing actor receiving touch events)
632 void Popup::OnControlChildAdd( Actor& child )
634 // reparent any children added by user to the body layer.
635 if( mAlterAddedChild )
637 // Removes previously added content.
640 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
643 // keep a handle to the new content.
646 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
650 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
652 // Hide the background image
653 mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) );
655 // Relayout All buttons
656 if ( !mButtons.empty() )
658 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
659 Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ),
660 mPopupStyle->bottomSize.height - mPopupStyle->margin );
662 Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f );
664 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
666 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
668 Actor button = *iter;
670 // If there is only one button, it needs to be laid out on center.
671 if ( mButtons.size() == 1 )
673 buttonPosition.x = 0.0f;
674 button.SetAnchorPoint( AnchorPoint::CENTER );
675 button.SetParentOrigin( ParentOrigin::CENTER );
679 button.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
680 button.SetParentOrigin( ParentOrigin::CENTER_LEFT );
683 button.SetPosition( buttonPosition );
685 button.PropagateRelayoutFlags(); // Reset relayout flags for relayout
686 container.Add( button, buttonSize );
691 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
695 if( policy == ResizePolicy::FIT_TO_CHILDREN )
697 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension );
698 if( dimension & Dimension::HEIGHT )
700 mPopupLayout.SetFitHeight( 1 );
705 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension );
706 // Make the content cell fill the whole of the available space
707 if( dimension & Dimension::HEIGHT )
709 mPopupLayout.SetRelativeHeight( 1, 1.0f );
715 bool Popup::OnKeyEvent(const KeyEvent& event)
717 bool consumed = false;
719 if(event.state == KeyEvent::Down)
721 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
723 SetState(Toolkit::Popup::POPUP_HIDE);
731 Vector3 Popup::GetNaturalSize()
733 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
734 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
736 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
740 Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize();
741 // Buffer to avoid errors. The width of the popup could potentially be the width of the title text.
742 // It was observed in this case that text wrapping was then inconsistent when seen on device
743 const float titleBuffer = 0.5f;
744 titleNaturalSize.width += titleBuffer;
746 // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
747 // to that of the stage
748 if( titleNaturalSize.width >= maxWidth)
750 naturalSize.width = maxWidth;
751 naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width );
755 naturalSize += titleNaturalSize;
758 naturalSize.height += mPopupStyle->margin;
763 Vector3 contentSize = mContent.GetNaturalSize();
764 // Choose the biggest width
765 naturalSize.width = std::max( naturalSize.width, contentSize.width );
766 if( naturalSize.width > maxWidth )
768 naturalSize.width = maxWidth;
769 contentSize.height = mContent.GetHeightForWidth( maxWidth );
771 naturalSize.height += contentSize.height + mPopupStyle->margin;
774 if( !mButtons.empty() )
776 naturalSize.height += mPopupStyle->bottomSize.height;
780 naturalSize.width += margin;
781 naturalSize.height += margin;
786 float Popup::GetHeightForWidth( float width )
788 float height( 0.0f );
789 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
793 height += mTitle.GetImplementation().GetHeightForWidth( popupWidth );
794 height += mPopupStyle->margin;
799 height += mContent.GetHeightForWidth( popupWidth ) + mPopupStyle->margin;
802 if( !mButtons.empty() )
804 height += mPopupStyle->bottomSize.height;
808 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
814 float Popup::GetWidthForHeight( float height )
816 return GetNaturalSize().width;
819 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
821 Actor nextFocusableActor( currentFocusedActor );
823 // TODO: Needs to be optimised
825 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
827 // The current focused actor is not within popup
828 if( mContent && mContent.IsKeyboardFocusable() )
830 // If content is focusable, move the focus to content
831 nextFocusableActor = mContent;
833 else if( !mButtons.empty() )
835 // Otherwise, movethe focus to the first button
836 nextFocusableActor = mButtons[0];
841 // Rebuild the focus chain because button or content can be added or removed dynamically
842 ActorContainer focusableActors;
843 if( mContent && mContent.IsKeyboardFocusable() )
845 focusableActors.push_back(mContent);
848 for(unsigned int i = 0; i < mButtons.size(); i++)
850 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
852 focusableActors.push_back(mButtons[i]);
856 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
858 if ( currentFocusedActor == *iter )
862 case Toolkit::Control::Left:
864 if ( iter == focusableActors.begin() )
866 nextFocusableActor = *( focusableActors.end() - 1 );
870 nextFocusableActor = *( iter - 1 );
874 case Toolkit::Control::Right:
876 if ( iter == focusableActors.end() - 1 )
878 nextFocusableActor = *( focusableActors.begin() );
882 nextFocusableActor = *( iter + 1 );
887 case Toolkit::Control::Up:
889 if ( *iter == mContent )
891 nextFocusableActor = *( focusableActors.end() - 1 );
895 if ( mContent && mContent.IsKeyboardFocusable() )
897 nextFocusableActor = mContent;
901 if ( iter == focusableActors.begin() )
903 nextFocusableActor = *( focusableActors.end() - 1 );
907 nextFocusableActor = *( iter - 1 );
914 case Toolkit::Control::Down:
916 if ( mContent && mContent.IsKeyboardFocusable() )
918 nextFocusableActor = mContent;
922 if ( iter == focusableActors.end() - 1 )
924 nextFocusableActor = *( focusableActors.begin() );
928 nextFocusableActor = *( iter + 1 );
932 if ( *iter == mContent && !mButtons.empty() )
934 nextFocusableActor = mButtons[0];
940 if(!nextFocusableActor)
942 DALI_LOG_WARNING("Can not decide next focusable actor\n");
950 return nextFocusableActor;
953 } // namespace Internal
955 } // namespace Toolkit