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/devel-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/devel-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>
41 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
59 return Toolkit::Popup::New();
62 // Setup properties, signals and actions using the type-registry.
63 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
65 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
66 DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden", SIGNAL_HIDDEN )
68 DALI_TYPE_REGISTRATION_END()
71 const char* const PROPERTY_TITLE = "title";
72 const char* const PROPERTY_STATE = "state";
74 const float POPUP_ANIMATION_DURATION = 0.45f; ///< Duration of hide/show animations
76 const float POPUP_WIDTH = 720.0f; ///< Width of Popup
77 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
78 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
79 const float POPUP_TITLE_WIDTH = 648.0f; ///<Width of Popup Title
80 const float POPUP_BUTTON_BG_HEIGHT = 96.f; ///< Height of Button Background.
81 const Vector3 DEFAULT_DIALOG_SIZE = Vector3(POPUP_TITLE_WIDTH/POPUP_WIDTH, 0.5f, 0.0f);
82 const Vector3 DEFAULT_BOTTOM_SIZE = Vector3(1.0f, 0.2f, 0.0f);
84 } // unnamed namespace
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
88 ///////////////////////////////////////////////////////////////////////////////////////////////////
90 Dali::Toolkit::Popup Popup::New()
92 PopupStylePtr style = PopupStyleDefault::New();
94 // Create the implementation
95 PopupPtr popup(new Popup(*style));
97 // Pass ownership to CustomActor via derived handle
98 Dali::Toolkit::Popup handle(*popup);
100 // Second-phase init of the implementation
101 // This can only be done after the CustomActor connection has been made...
107 Popup::Popup(PopupStyle& style)
108 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
110 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
111 mAlterAddedChild(false),
112 mPopupStyle(PopupStylePtr(&style)),
113 mPropertyTitle(Property::INVALID_INDEX),
114 mPropertyState(Property::INVALID_INDEX)
116 SetKeyboardNavigationSupport( true );
119 void Popup::OnInitialize()
121 Dali::Stage stage = Dali::Stage::GetCurrent();
124 self.SetSensitive(false);
125 // Reisize to fit the height of children
126 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
129 mLayer = Layer::New();
130 mLayer.SetName( "POPUP_LAYER" );
131 mLayer.SetParentOrigin(ParentOrigin::CENTER);
132 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
133 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
134 mLayer.SetDrawMode( DrawMode::OVERLAY );
136 // Any content after this point which is added to Self() will be reparented to
138 mAlterAddedChild = true;
139 // Add Backing (Dim effect)
141 mAlterAddedChild = false;
143 // Add Dialog ( background image, title, content container, button container and tail )
148 mPopupLayout = Toolkit::TableView::New( 3, 1 );
149 mPopupLayout.SetName( "POPUP_LAYOUT_TABLE" );
150 mPopupLayout.SetParentOrigin(ParentOrigin::CENTER);
151 mPopupLayout.SetAnchorPoint(AnchorPoint::CENTER);
152 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
153 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
154 mPopupLayout.SetFitHeight( 0 ); // Set row to fit
155 mPopupLayout.SetFitHeight( 1 ); // Set row to fit
156 self.Add( mPopupLayout );
158 // Any content after this point which is added to Self() will be reparented to
160 mAlterAddedChild = true;
163 // ShowTail(ParentOrigin::BOTTOM_CENTER);
165 // Hide content by default.
166 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
168 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
169 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
171 // Make self as keyboard focusable and focus group
172 self.SetKeyboardFocusable(true);
173 SetAsKeyboardFocusGroup(true);
176 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
178 if( index == mPropertyTitle )
180 SetTitle(propertyValue.Get<std::string>());
182 else if ( index == mPropertyState )
184 std::string value( propertyValue.Get<std::string>() );
185 if(value == "POPUP_SHOW")
187 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
189 else if( value == "POPUP_HIDE")
191 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
201 size_t Popup::GetButtonCount() const
203 return mButtons.size();
206 void Popup::SetBackgroundImage( Actor image )
208 // Removes any previous background.
209 if( mBackgroundImage && mPopupLayout )
211 mPopupLayout.Remove( mBackgroundImage );
214 // Adds new background to the dialog.
215 mBackgroundImage = image;
217 mBackgroundImage.SetName( "POPUP_BACKGROUND_IMAGE" );
219 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
220 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
222 mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
223 mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
224 mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
226 Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f );
227 mBackgroundImage.SetSizeModeFactor( border );
229 const bool prevAlter = mAlterAddedChild;
230 mAlterAddedChild = false;
231 Self().Add( mBackgroundImage );
232 mAlterAddedChild = prevAlter;
235 void Popup::SetButtonAreaImage( Actor image )
237 // Removes any previous area image.
238 if( mButtonAreaImage && mPopupLayout )
240 mPopupLayout.Remove( mButtonAreaImage );
243 // Adds new area image to the dialog.
244 mButtonAreaImage = image;
246 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
247 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
249 mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
250 mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER );
251 mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER );
253 if( GetButtonCount() > 0 )
255 mBottomBg.Add( mButtonAreaImage );
259 void Popup::SetTitle( const std::string& text )
261 // Replaces the current title actor.
264 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
267 mTitle = Toolkit::TextLabel::New( text );
268 mTitle.SetName( "POPUP_TITLE" );
269 mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
270 mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
274 mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
275 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
276 mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
277 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
283 std::string Popup::GetTitle() const
287 return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
290 return std::string();
293 void Popup::CreateFooter()
297 // Adds bottom background
298 mBottomBg = Actor::New();
299 mBottomBg.SetName( "POPUP_BOTTOM_BG" );
300 mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
302 mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height ); // Buttons
303 mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) );
307 void Popup::AddButton( Toolkit::Button button )
309 mButtons.push_back( button );
310 button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); // Size will be assigned to it
312 // If this is the first button added
313 if( mButtons.size() == 1 )
317 if( mButtonAreaImage )
319 mBottomBg.Add( mButtonAreaImage );
323 mBottomBg.Add( button );
328 void Popup::SetState( Toolkit::Popup::PopupState state )
330 SetState( state, POPUP_ANIMATION_DURATION );
333 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
335 // default animation behaviour.
336 HandleStateChange(state, duration);
339 Toolkit::Popup::PopupState Popup::GetState() const
344 void Popup::ShowTail(const Vector3& position)
346 // Replaces the tail actor.
347 if(mTailImage && mTailImage.GetParent())
349 mTailImage.GetParent().Remove( mTailImage );
353 std::string image = "";
355 // depending on position of tail around ParentOrigin, a different tail image is used...
356 if(position.y < Math::MACHINE_EPSILON_1)
358 image = mPopupStyle->tailUpImage;
360 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
362 image = mPopupStyle->tailDownImage;
364 else if(position.x < Math::MACHINE_EPSILON_1)
366 image = mPopupStyle->tailLeftImage;
368 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
370 image = mPopupStyle->tailRightImage;
375 Image tail = ResourceImage::New( image );
376 mTailImage = ImageActor::New(tail);
377 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
379 mTailImage.SetParentOrigin(position);
380 mTailImage.SetAnchorPoint(anchorPoint);
384 mBottomBg.Add(mTailImage);
388 void Popup::HideTail()
390 ShowTail(ParentOrigin::CENTER);
393 void Popup::SetStyle(PopupStyle& style)
395 mPopupStyle = PopupStylePtr(&style);
399 PopupStylePtr Popup::GetStyle() const
404 void Popup::SetDefaultBackgroundImage()
406 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
407 ImageActor buttonBgImage = ImageActor::New( buttonBg );
408 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
409 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
411 SetBackgroundImage( ImageActor::New( ResourceImage::New( mPopupStyle->backgroundImage ) ) );
412 SetButtonAreaImage( buttonBgImage );
415 void Popup::CreateBacking()
417 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
418 mBacking.SetName( "POPUP_BACKING" );
420 mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
421 mBacking.SetSensitive(true);
423 mLayer.Add( mBacking );
424 mBacking.SetOpacity(0.0f);
425 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
426 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
429 void Popup::CreateDialog()
431 // Adds default background image.
432 SetDefaultBackgroundImage();
435 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
438 float targetBackingAlpha;
447 case Toolkit::Popup::POPUP_HIDE:
449 targetSize = Vector3(0.0f, 0.0f, 1.0f);
450 targetBackingAlpha = 0.0f;
452 ClearKeyInputFocus();
454 // Retore the keyboard focus when popup is hidden
455 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
457 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
458 if( keyboardFocusManager )
460 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
467 case Toolkit::Popup::POPUP_SHOW:
470 targetSize = Vector3(1.0f, 1.0f, 1.0f);
471 targetBackingAlpha = 1.0f;
474 // Add contents to stage for showing.
475 if( !mLayer.GetParent() )
477 Dali::Stage stage = Dali::Stage::GetCurrent();
482 Self().SetSensitive(true);
485 // Handle the keyboard focus when popup is shown
486 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
487 if( keyboardFocusManager )
489 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
491 if( mContent && mContent.IsKeyboardFocusable() )
493 // If content is focusable, move the focus to content
494 keyboardFocusManager.SetCurrentFocusActor(mContent);
496 else if( !mButtons.empty() )
498 // Otherwise, movethe focus to the first button
499 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
503 DALI_LOG_WARNING("There is no focusable in popup\n");
511 if(duration > Math::MACHINE_EPSILON_1)
519 mAnimation = Animation::New(duration);
523 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
524 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(duration * 0.5f, duration * 0.5f) );
528 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
529 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
532 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
536 mBacking.SetOpacity( targetBackingAlpha );
537 self.SetScale( targetSize );
539 HandleStateChangeComplete();
543 void Popup::HandleStateChangeComplete()
545 // Remove contents from stage if completely hidden.
546 if( ( mState == Toolkit::Popup::POPUP_HIDE ) && mLayer.GetParent() )
549 Self().SetSensitive( false );
551 // Guard against destruction during signal emission
552 Toolkit::Popup handle( GetOwner() );
553 mHiddenSignal.Emit();
557 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
559 return mTouchedOutsideSignal;
562 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
564 return mHiddenSignal;
567 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
569 Dali::BaseHandle handle( object );
571 bool connected( true );
572 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
574 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
576 popup.OutsideTouchedSignal().Connect( tracker, functor );
578 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
580 popup.HiddenSignal().Connect( tracker, functor );
584 // signalName does not match any signal
591 void Popup::OnStateAnimationFinished( Animation& source )
593 HandleStateChangeComplete();
596 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
598 if(event.GetPointCount()>0)
600 const TouchPoint& point = event.GetPoint(0);
602 if(point.state == TouchPoint::Down)
604 // Guard against destruction during signal emission
605 Toolkit::Popup handle( GetOwner() );
607 mTouchedOutsideSignal.Emit();
614 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
616 // consume mouse wheel event in dimmed backing actor
620 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
622 // consume event (stops backing actor receiving touch events)
626 void Popup::OnControlChildAdd( Actor& child )
628 // reparent any children added by user to the body layer.
629 if( mAlterAddedChild )
631 // Removes previously added content.
634 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
637 // keep a handle to the new content.
640 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
644 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
646 // Hide the background image
647 mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) );
649 // Relayout All buttons
650 if( !mButtons.empty() )
652 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
653 Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ),
654 mPopupStyle->bottomSize.height - mPopupStyle->margin );
656 Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f );
658 for( std::vector< Actor >::iterator iter = mButtons.begin(), endIter = mButtons.end();
660 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
662 Actor button = *iter;
664 // If there is only one button, it needs to be laid out on center.
665 if ( mButtons.size() == 1 )
667 buttonPosition.x = 0.0f;
668 button.SetAnchorPoint( AnchorPoint::CENTER );
669 button.SetParentOrigin( ParentOrigin::CENTER );
673 button.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
674 button.SetParentOrigin( ParentOrigin::CENTER_LEFT );
677 button.SetPosition( buttonPosition );
679 //Todo: Use the size negotiation pass instead of SetSize directly
680 button.SetSize( buttonSize );
685 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
689 if( policy == ResizePolicy::FIT_TO_CHILDREN )
691 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension );
692 if( dimension & Dimension::HEIGHT )
694 mPopupLayout.SetFitHeight( 1 );
699 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension );
700 // Make the content cell fill the whole of the available space
701 if( dimension & Dimension::HEIGHT )
703 mPopupLayout.SetRelativeHeight( 1, 1.0f );
709 bool Popup::OnKeyEvent(const KeyEvent& event)
711 bool consumed = false;
713 if(event.state == KeyEvent::Down)
715 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
717 SetState(Toolkit::Popup::POPUP_HIDE);
725 Vector3 Popup::GetNaturalSize()
727 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
728 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
730 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
734 Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize();
735 // Buffer to avoid errors. The width of the popup could potentially be the width of the title text.
736 // It was observed in this case that text wrapping was then inconsistent when seen on device
737 const float titleBuffer = 0.5f;
738 titleNaturalSize.width += titleBuffer;
740 // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
741 // to that of the stage
742 if( titleNaturalSize.width >= maxWidth)
744 naturalSize.width = maxWidth;
745 naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width );
749 naturalSize += titleNaturalSize;
752 naturalSize.height += mPopupStyle->margin;
757 Vector3 contentSize = mContent.GetNaturalSize();
758 // Choose the biggest width
759 naturalSize.width = std::max( naturalSize.width, contentSize.width );
760 if( naturalSize.width > maxWidth )
762 naturalSize.width = maxWidth;
763 contentSize.height = mContent.GetHeightForWidth( maxWidth );
765 naturalSize.height += contentSize.height + mPopupStyle->margin;
768 if( !mButtons.empty() )
770 naturalSize.height += mPopupStyle->bottomSize.height;
774 naturalSize.width += margin;
775 naturalSize.height += margin;
780 float Popup::GetHeightForWidth( float width )
782 float height( 0.0f );
783 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
787 height += mTitle.GetImplementation().GetHeightForWidth( popupWidth );
788 height += mPopupStyle->margin;
793 height += mContent.GetHeightForWidth( popupWidth ) + mPopupStyle->margin;
796 if( !mButtons.empty() )
798 height += mPopupStyle->bottomSize.height;
802 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
808 float Popup::GetWidthForHeight( float height )
810 return GetNaturalSize().width;
813 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
815 Actor nextFocusableActor( currentFocusedActor );
817 // TODO: Needs to be optimised
819 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
821 // The current focused actor is not within popup
822 if( mContent && mContent.IsKeyboardFocusable() )
824 // If content is focusable, move the focus to content
825 nextFocusableActor = mContent;
827 else if( !mButtons.empty() )
829 // Otherwise, movethe focus to the first button
830 nextFocusableActor = mButtons[0];
835 // Rebuild the focus chain because button or content can be added or removed dynamically
836 std::vector< Actor > focusableActors;
837 if( mContent && mContent.IsKeyboardFocusable() )
839 focusableActors.push_back(mContent);
842 for(unsigned int i = 0; i < mButtons.size(); i++)
844 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
846 focusableActors.push_back(mButtons[i]);
850 for( std::vector< Actor >::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
852 if ( currentFocusedActor == *iter )
856 case Toolkit::Control::Left:
858 if ( iter == focusableActors.begin() )
860 nextFocusableActor = *( focusableActors.end() - 1 );
864 nextFocusableActor = *( iter - 1 );
868 case Toolkit::Control::Right:
870 if ( iter == focusableActors.end() - 1 )
872 nextFocusableActor = *( focusableActors.begin() );
876 nextFocusableActor = *( iter + 1 );
881 case Toolkit::Control::Up:
883 if ( *iter == mContent )
885 nextFocusableActor = *( focusableActors.end() - 1 );
889 if ( mContent && mContent.IsKeyboardFocusable() )
891 nextFocusableActor = mContent;
895 if ( iter == focusableActors.begin() )
897 nextFocusableActor = *( focusableActors.end() - 1 );
901 nextFocusableActor = *( iter - 1 );
908 case Toolkit::Control::Down:
910 if ( mContent && mContent.IsKeyboardFocusable() )
912 nextFocusableActor = mContent;
916 if ( iter == focusableActors.end() - 1 )
918 nextFocusableActor = *( focusableActors.begin() );
922 nextFocusableActor = *( iter + 1 );
926 if ( *iter == mContent && !mButtons.empty() )
928 nextFocusableActor = mButtons[0];
934 if(!nextFocusableActor)
936 DALI_LOG_WARNING("Can not decide next focusable actor\n");
944 return nextFocusableActor;
947 } // namespace Internal
949 } // namespace Toolkit