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 <dali/public-api/adaptor-framework/key.h>
23 #include <dali/public-api/adaptor-framework/physical-keyboard.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/public-api/events/touch-event.h>
28 #include <dali/public-api/images/resource-image.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/public-api/size-negotiation/relayout-container.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/controls/buttons/button.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
38 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
39 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
57 return Toolkit::Popup::New();
60 // Setup properties, signals and actions using the type-registry.
61 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
63 DALI_SIGNAL_REGISTRATION( Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
64 DALI_SIGNAL_REGISTRATION( Popup, "hidden", SIGNAL_HIDDEN )
66 DALI_TYPE_REGISTRATION_END()
69 const char* const PROPERTY_TITLE = "title";
70 const char* const PROPERTY_STATE = "state";
72 const float POPUP_ANIMATION_DURATION = 0.45f; ///< Duration of hide/show animations
74 const float POPUP_WIDTH = 720.0f; ///< Width of Popup
75 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
76 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
77 const float POPUP_TITLE_WIDTH = 648.0f; ///<Width of Popup Title
78 const float POPUP_BUTTON_BG_HEIGHT = 96.f; ///< Height of Button Background.
79 const Vector3 DEFAULT_DIALOG_SIZE = Vector3(POPUP_TITLE_WIDTH/POPUP_WIDTH, 0.5f, 0.0f);
80 const Vector3 DEFAULT_BOTTOM_SIZE = Vector3(1.0f, 0.2f, 0.0f);
82 } // unnamed namespace
84 ///////////////////////////////////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
88 Dali::Toolkit::Popup Popup::New()
90 PopupStylePtr style = PopupStyleDefault::New();
92 // Create the implementation
93 PopupPtr popup(new Popup(*style));
95 // Pass ownership to CustomActor via derived handle
96 Dali::Toolkit::Popup handle(*popup);
98 // Second-phase init of the implementation
99 // This can only be done after the CustomActor connection has been made...
105 Popup::Popup(PopupStyle& style)
106 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
108 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
109 mAlterAddedChild(false),
110 mPopupStyle(PopupStylePtr(&style)),
111 mPropertyTitle(Property::INVALID_INDEX),
112 mPropertyState(Property::INVALID_INDEX)
114 SetKeyboardNavigationSupport( true );
117 void Popup::OnInitialize()
119 Dali::Stage stage = Dali::Stage::GetCurrent();
122 self.SetSensitive(false);
123 // Reisize to fit the height of children
124 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
127 mLayer = Layer::New();
128 mLayer.SetName( "POPUP_LAYER" );
129 mLayer.SetParentOrigin(ParentOrigin::CENTER);
130 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
131 mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
132 mLayer.SetDrawMode( DrawMode::OVERLAY );
134 // Any content after this point which is added to Self() will be reparented to
136 mAlterAddedChild = true;
137 // Add Backing (Dim effect)
139 mAlterAddedChild = false;
141 // Add Dialog ( background image, title, content container, button container and tail )
146 mPopupLayout = Toolkit::TableView::New( 3, 1 );
147 mPopupLayout.SetName( "POPUP_LAYOUT_TABLE" );
148 mPopupLayout.SetParentOrigin(ParentOrigin::CENTER);
149 mPopupLayout.SetAnchorPoint(AnchorPoint::CENTER);
150 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
151 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
152 mPopupLayout.SetFitHeight( 0 ); // Set row to fit
153 mPopupLayout.SetFitHeight( 1 ); // Set row to fit
154 self.Add( mPopupLayout );
156 // Any content after this point which is added to Self() will be reparented to
158 mAlterAddedChild = true;
161 // ShowTail(ParentOrigin::BOTTOM_CENTER);
163 // Hide content by default.
164 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
166 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
167 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
169 // Make self as keyboard focusable and focus group
170 self.SetKeyboardFocusable(true);
171 SetAsKeyboardFocusGroup(true);
174 void Popup::MarkDirtyForRelayout()
176 // Flag all the popup controls for relayout as it is about to be hidden and miss the main flagging pass
177 mLayer.RelayoutRequestTree();
180 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
182 if( index == mPropertyTitle )
184 SetTitle(propertyValue.Get<std::string>());
186 else if ( index == mPropertyState )
188 std::string value( propertyValue.Get<std::string>() );
189 if(value == "POPUP_SHOW")
191 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
193 else if( value == "POPUP_HIDE")
195 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
205 size_t Popup::GetButtonCount() const
207 return mButtons.size();
210 void Popup::SetBackgroundImage( Actor image )
212 // Removes any previous background.
213 if( mBackgroundImage && mPopupLayout )
215 mPopupLayout.Remove( mBackgroundImage );
218 // Adds new background to the dialog.
219 mBackgroundImage = image;
221 mBackgroundImage.SetName( "POPUP_BACKGROUND_IMAGE" );
223 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
224 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
226 mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
227 mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
228 mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
230 Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f );
231 mBackgroundImage.SetSizeModeFactor( border );
233 const bool prevAlter = mAlterAddedChild;
234 mAlterAddedChild = false;
235 Self().Add( mBackgroundImage );
236 mAlterAddedChild = prevAlter;
239 void Popup::SetButtonAreaImage( Actor image )
241 // Removes any previous area image.
242 if( mButtonAreaImage && mPopupLayout )
244 mPopupLayout.Remove( mButtonAreaImage );
247 // Adds new area image to the dialog.
248 mButtonAreaImage = image;
250 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
251 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
253 mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
254 mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER );
255 mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER );
257 if( GetButtonCount() > 0 )
259 mBottomBg.Add( mButtonAreaImage );
263 void Popup::SetTitle( const std::string& text )
265 // Replaces the current title actor.
268 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
271 mTitle = Toolkit::TextLabel::New( text );
272 mTitle.SetName( "POPUP_TITLE" );
273 mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
274 mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
278 mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
279 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
280 mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
281 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
287 std::string Popup::GetTitle() const
291 return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
294 return std::string();
297 void Popup::CreateFooter()
301 // Adds bottom background
302 mBottomBg = Actor::New();
303 mBottomBg.SetName( "POPUP_BOTTOM_BG" );
304 mBottomBg.SetRelayoutEnabled( true );
305 mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
307 mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height ); // Buttons
308 mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) );
312 void Popup::AddButton( Toolkit::Button button )
314 mButtons.push_back( button );
315 button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); // Size will be assigned to it
317 // If this is the first button added
318 if( mButtons.size() == 1 )
322 if( mButtonAreaImage )
324 mBottomBg.Add( mButtonAreaImage );
328 mBottomBg.Add( button );
333 void Popup::SetState( Toolkit::Popup::PopupState state )
335 SetState( state, POPUP_ANIMATION_DURATION );
338 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
340 // default animation behaviour.
341 HandleStateChange(state, duration);
344 Toolkit::Popup::PopupState Popup::GetState() const
349 void Popup::ShowTail(const Vector3& position)
351 // Replaces the tail actor.
352 if(mTailImage && mTailImage.GetParent())
354 mTailImage.GetParent().Remove( mTailImage );
358 std::string image = "";
360 // depending on position of tail around ParentOrigin, a different tail image is used...
361 if(position.y < Math::MACHINE_EPSILON_1)
363 image = mPopupStyle->tailUpImage;
365 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
367 image = mPopupStyle->tailDownImage;
369 else if(position.x < Math::MACHINE_EPSILON_1)
371 image = mPopupStyle->tailLeftImage;
373 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
375 image = mPopupStyle->tailRightImage;
380 Image tail = ResourceImage::New( image );
381 mTailImage = ImageActor::New(tail);
382 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
384 mTailImage.SetParentOrigin(position);
385 mTailImage.SetAnchorPoint(anchorPoint);
389 mBottomBg.Add(mTailImage);
393 void Popup::HideTail()
395 ShowTail(ParentOrigin::CENTER);
398 void Popup::SetStyle(PopupStyle& style)
400 mPopupStyle = PopupStylePtr(&style);
404 PopupStylePtr Popup::GetStyle() const
409 void Popup::SetDefaultBackgroundImage()
411 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
412 ImageActor buttonBgImage = ImageActor::New( buttonBg );
413 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
414 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
416 SetBackgroundImage( ImageActor::New( ResourceImage::New( mPopupStyle->backgroundImage ) ) );
417 SetButtonAreaImage( buttonBgImage );
420 void Popup::CreateBacking()
422 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
423 mBacking.SetName( "POPUP_BACKING" );
425 mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
426 mBacking.SetSensitive(true);
428 mLayer.Add( mBacking );
429 mBacking.SetOpacity(0.0f);
430 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
431 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
434 void Popup::CreateDialog()
436 // Adds default background image.
437 SetDefaultBackgroundImage();
440 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
443 float targetBackingAlpha;
452 case Toolkit::Popup::POPUP_HIDE:
454 targetSize = Vector3(0.0f, 0.0f, 1.0f);
455 targetBackingAlpha = 0.0f;
457 ClearKeyInputFocus();
459 // Retore the keyboard focus when popup is hidden
460 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
462 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
463 if( keyboardFocusManager )
465 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
472 case Toolkit::Popup::POPUP_SHOW:
475 targetSize = Vector3(1.0f, 1.0f, 1.0f);
476 targetBackingAlpha = 1.0f;
479 // Add contents to stage for showing.
480 if( !mLayer.GetParent() )
482 Dali::Stage stage = Dali::Stage::GetCurrent();
487 Self().SetSensitive(true);
490 // Handle the keyboard focus when popup is shown
491 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
492 if( keyboardFocusManager )
494 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
496 if( mContent && mContent.IsKeyboardFocusable() )
498 // If content is focusable, move the focus to content
499 keyboardFocusManager.SetCurrentFocusActor(mContent);
501 else if( !mButtons.empty() )
503 // Otherwise, movethe focus to the first button
504 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
508 DALI_LOG_WARNING("There is no focusable in popup\n");
516 if(duration > Math::MACHINE_EPSILON_1)
524 mAnimation = Animation::New(duration);
528 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
529 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
533 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
534 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
537 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
541 mBacking.SetOpacity( targetBackingAlpha );
542 self.SetScale( targetSize );
544 HandleStateChangeComplete();
548 void Popup::HandleStateChangeComplete()
550 // Remove contents from stage if completely hidden.
551 if( ( mState == Toolkit::Popup::POPUP_HIDE ) && mLayer.GetParent() )
554 Self().SetSensitive( false );
556 // Guard against destruction during signal emission
557 Toolkit::Popup handle( GetOwner() );
558 mHiddenSignal.Emit();
562 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
564 return mTouchedOutsideSignal;
567 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
569 return mHiddenSignal;
572 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
574 Dali::BaseHandle handle( object );
576 bool connected( true );
577 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
579 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
581 popup.OutsideTouchedSignal().Connect( tracker, functor );
583 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
585 popup.HiddenSignal().Connect( tracker, functor );
589 // signalName does not match any signal
596 void Popup::OnStateAnimationFinished( Animation& source )
598 HandleStateChangeComplete();
601 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
603 if(event.GetPointCount()>0)
605 const TouchPoint& point = event.GetPoint(0);
607 if(point.state == TouchPoint::Down)
609 // Guard against destruction during signal emission
610 Toolkit::Popup handle( GetOwner() );
612 mTouchedOutsideSignal.Emit();
619 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
621 // consume mouse wheel event in dimmed backing actor
625 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
627 // consume event (stops backing actor receiving touch events)
631 void Popup::OnControlChildAdd( Actor& child )
633 // reparent any children added by user to the body layer.
634 if( mAlterAddedChild )
636 // Removes previously added content.
639 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
642 // keep a handle to the new content.
645 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
649 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
651 // Hide the background image
652 mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) );
654 // Relayout All buttons
655 if ( !mButtons.empty() )
657 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
658 Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ),
659 mPopupStyle->bottomSize.height - mPopupStyle->margin );
661 Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f );
663 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
665 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
667 Actor button = *iter;
669 // If there is only one button, it needs to be laid out on center.
670 if ( mButtons.size() == 1 )
672 buttonPosition.x = 0.0f;
673 button.SetAnchorPoint( AnchorPoint::CENTER );
674 button.SetParentOrigin( ParentOrigin::CENTER );
678 button.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
679 button.SetParentOrigin( ParentOrigin::CENTER_LEFT );
682 button.SetPosition( buttonPosition );
684 button.PropagateRelayoutFlags(); // Reset relayout flags for relayout
685 container.Add( button, buttonSize );
690 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
694 if( policy == ResizePolicy::FIT_TO_CHILDREN )
696 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension );
697 if( dimension & Dimension::HEIGHT )
699 mPopupLayout.SetFitHeight( 1 );
704 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension );
705 // Make the content cell fill the whole of the available space
706 if( dimension & Dimension::HEIGHT )
708 mPopupLayout.SetRelativeHeight( 1, 1.0f );
714 bool Popup::OnKeyEvent(const KeyEvent& event)
716 bool consumed = false;
718 if(event.state == KeyEvent::Down)
720 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
722 SetState(Toolkit::Popup::POPUP_HIDE);
730 Vector3 Popup::GetNaturalSize()
732 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
733 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
735 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
739 Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize();
740 // Buffer to avoid errors. The width of the popup could potentially be the width of the title text.
741 // It was observed in this case that text wrapping was then inconsistent when seen on device
742 const float titleBuffer = 0.5f;
743 titleNaturalSize.width += titleBuffer;
745 // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
746 // to that of the stage
747 if( titleNaturalSize.width >= maxWidth)
749 naturalSize.width = maxWidth;
750 naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width );
754 naturalSize += titleNaturalSize;
757 naturalSize.height += mPopupStyle->margin;
762 Vector3 contentSize = mContent.GetNaturalSize();
763 // Choose the biggest width
764 naturalSize.width = std::max( naturalSize.width, contentSize.width );
765 if( naturalSize.width > maxWidth )
767 naturalSize.width = maxWidth;
768 contentSize.height = mContent.GetHeightForWidth( maxWidth );
770 naturalSize.height += contentSize.height + mPopupStyle->margin;
773 if( !mButtons.empty() )
775 naturalSize.height += mPopupStyle->bottomSize.height;
779 naturalSize.width += margin;
780 naturalSize.height += margin;
785 float Popup::GetHeightForWidth( float width )
787 float height( 0.0f );
788 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
792 height += mTitle.GetImplementation().GetHeightForWidth( popupWidth );
793 height += mPopupStyle->margin;
798 height += mContent.GetHeightForWidth( popupWidth ) + mPopupStyle->margin;
801 if( !mButtons.empty() )
803 height += mPopupStyle->bottomSize.height;
807 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
813 float Popup::GetWidthForHeight( float height )
815 return GetNaturalSize().width;
818 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
820 Actor nextFocusableActor( currentFocusedActor );
822 // TODO: Needs to be optimised
824 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
826 // The current focused actor is not within popup
827 if( mContent && mContent.IsKeyboardFocusable() )
829 // If content is focusable, move the focus to content
830 nextFocusableActor = mContent;
832 else if( !mButtons.empty() )
834 // Otherwise, movethe focus to the first button
835 nextFocusableActor = mButtons[0];
840 // Rebuild the focus chain because button or content can be added or removed dynamically
841 ActorContainer focusableActors;
842 if( mContent && mContent.IsKeyboardFocusable() )
844 focusableActors.push_back(mContent);
847 for(unsigned int i = 0; i < mButtons.size(); i++)
849 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
851 focusableActors.push_back(mButtons[i]);
855 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
857 if ( currentFocusedActor == *iter )
861 case Toolkit::Control::Left:
863 if ( iter == focusableActors.begin() )
865 nextFocusableActor = *( focusableActors.end() - 1 );
869 nextFocusableActor = *( iter - 1 );
873 case Toolkit::Control::Right:
875 if ( iter == focusableActors.end() - 1 )
877 nextFocusableActor = *( focusableActors.begin() );
881 nextFocusableActor = *( iter + 1 );
886 case Toolkit::Control::Up:
888 if ( *iter == mContent )
890 nextFocusableActor = *( focusableActors.end() - 1 );
894 if ( mContent && mContent.IsKeyboardFocusable() )
896 nextFocusableActor = mContent;
900 if ( iter == focusableActors.begin() )
902 nextFocusableActor = *( focusableActors.end() - 1 );
906 nextFocusableActor = *( iter - 1 );
913 case Toolkit::Control::Down:
915 if ( mContent && mContent.IsKeyboardFocusable() )
917 nextFocusableActor = mContent;
921 if ( iter == focusableActors.end() - 1 )
923 nextFocusableActor = *( focusableActors.begin() );
927 nextFocusableActor = *( iter + 1 );
931 if ( *iter == mContent && !mButtons.empty() )
933 nextFocusableActor = mButtons[0];
939 if(!nextFocusableActor)
941 DALI_LOG_WARNING("Can not decide next focusable actor\n");
949 return nextFocusableActor;
952 } // namespace Internal
954 } // namespace Toolkit