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( Toolkit, Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
65 DALI_SIGNAL_REGISTRATION( Toolkit, 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::OnPropertySet( Property::Index index, Property::Value propertyValue )
177 if( index == mPropertyTitle )
179 SetTitle(propertyValue.Get<std::string>());
181 else if ( index == mPropertyState )
183 std::string value( propertyValue.Get<std::string>() );
184 if(value == "POPUP_SHOW")
186 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
188 else if( value == "POPUP_HIDE")
190 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
200 size_t Popup::GetButtonCount() const
202 return mButtons.size();
205 void Popup::SetBackgroundImage( Actor image )
207 // Removes any previous background.
208 if( mBackgroundImage && mPopupLayout )
210 mPopupLayout.Remove( mBackgroundImage );
213 // Adds new background to the dialog.
214 mBackgroundImage = image;
216 mBackgroundImage.SetName( "POPUP_BACKGROUND_IMAGE" );
218 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
219 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
221 mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
222 mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
223 mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
225 Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f );
226 mBackgroundImage.SetSizeModeFactor( border );
228 const bool prevAlter = mAlterAddedChild;
229 mAlterAddedChild = false;
230 Self().Add( mBackgroundImage );
231 mAlterAddedChild = prevAlter;
234 void Popup::SetButtonAreaImage( Actor image )
236 // Removes any previous area image.
237 if( mButtonAreaImage && mPopupLayout )
239 mPopupLayout.Remove( mButtonAreaImage );
242 // Adds new area image to the dialog.
243 mButtonAreaImage = image;
245 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
246 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
248 mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
249 mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER );
250 mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER );
252 if( GetButtonCount() > 0 )
254 mBottomBg.Add( mButtonAreaImage );
258 void Popup::SetTitle( const std::string& text )
260 // Replaces the current title actor.
263 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
266 mTitle = Toolkit::TextLabel::New( text );
267 mTitle.SetName( "POPUP_TITLE" );
268 mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
269 mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
273 mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
274 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
275 mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
276 mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
282 std::string Popup::GetTitle() const
286 return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
289 return std::string();
292 void Popup::CreateFooter()
296 // Adds bottom background
297 mBottomBg = Actor::New();
298 mBottomBg.SetName( "POPUP_BOTTOM_BG" );
299 mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
301 mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height ); // Buttons
302 mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) );
306 void Popup::AddButton( Toolkit::Button button )
308 mButtons.push_back( button );
309 button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); // Size will be assigned to it
311 // If this is the first button added
312 if( mButtons.size() == 1 )
316 if( mButtonAreaImage )
318 mBottomBg.Add( mButtonAreaImage );
322 mBottomBg.Add( button );
327 void Popup::SetState( Toolkit::Popup::PopupState state )
329 SetState( state, POPUP_ANIMATION_DURATION );
332 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
334 // default animation behaviour.
335 HandleStateChange(state, duration);
338 Toolkit::Popup::PopupState Popup::GetState() const
343 void Popup::ShowTail(const Vector3& position)
345 // Replaces the tail actor.
346 if(mTailImage && mTailImage.GetParent())
348 mTailImage.GetParent().Remove( mTailImage );
352 std::string image = "";
354 // depending on position of tail around ParentOrigin, a different tail image is used...
355 if(position.y < Math::MACHINE_EPSILON_1)
357 image = mPopupStyle->tailUpImage;
359 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
361 image = mPopupStyle->tailDownImage;
363 else if(position.x < Math::MACHINE_EPSILON_1)
365 image = mPopupStyle->tailLeftImage;
367 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
369 image = mPopupStyle->tailRightImage;
374 Image tail = ResourceImage::New( image );
375 mTailImage = ImageActor::New(tail);
376 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
378 mTailImage.SetParentOrigin(position);
379 mTailImage.SetAnchorPoint(anchorPoint);
383 mBottomBg.Add(mTailImage);
387 void Popup::HideTail()
389 ShowTail(ParentOrigin::CENTER);
392 void Popup::SetStyle(PopupStyle& style)
394 mPopupStyle = PopupStylePtr(&style);
398 PopupStylePtr Popup::GetStyle() const
403 void Popup::SetDefaultBackgroundImage()
405 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
406 ImageActor buttonBgImage = ImageActor::New( buttonBg );
407 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
408 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
410 SetBackgroundImage( ImageActor::New( ResourceImage::New( mPopupStyle->backgroundImage ) ) );
411 SetButtonAreaImage( buttonBgImage );
414 void Popup::CreateBacking()
416 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
417 mBacking.SetName( "POPUP_BACKING" );
419 mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
420 mBacking.SetSensitive(true);
422 mLayer.Add( mBacking );
423 mBacking.SetOpacity(0.0f);
424 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
425 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
428 void Popup::CreateDialog()
430 // Adds default background image.
431 SetDefaultBackgroundImage();
434 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
437 float targetBackingAlpha;
446 case Toolkit::Popup::POPUP_HIDE:
448 targetSize = Vector3(0.0f, 0.0f, 1.0f);
449 targetBackingAlpha = 0.0f;
451 ClearKeyInputFocus();
453 // Retore the keyboard focus when popup is hidden
454 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
456 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
457 if( keyboardFocusManager )
459 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
466 case Toolkit::Popup::POPUP_SHOW:
469 targetSize = Vector3(1.0f, 1.0f, 1.0f);
470 targetBackingAlpha = 1.0f;
473 // Add contents to stage for showing.
474 if( !mLayer.GetParent() )
476 Dali::Stage stage = Dali::Stage::GetCurrent();
481 Self().SetSensitive(true);
484 // Handle the keyboard focus when popup is shown
485 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
486 if( keyboardFocusManager )
488 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
490 if( mContent && mContent.IsKeyboardFocusable() )
492 // If content is focusable, move the focus to content
493 keyboardFocusManager.SetCurrentFocusActor(mContent);
495 else if( !mButtons.empty() )
497 // Otherwise, movethe focus to the first button
498 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
502 DALI_LOG_WARNING("There is no focusable in popup\n");
510 if(duration > Math::MACHINE_EPSILON_1)
518 mAnimation = Animation::New(duration);
522 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
523 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
527 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
528 mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
531 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
535 mBacking.SetOpacity( targetBackingAlpha );
536 self.SetScale( targetSize );
538 HandleStateChangeComplete();
542 void Popup::HandleStateChangeComplete()
544 // Remove contents from stage if completely hidden.
545 if( ( mState == Toolkit::Popup::POPUP_HIDE ) && mLayer.GetParent() )
548 Self().SetSensitive( false );
550 // Guard against destruction during signal emission
551 Toolkit::Popup handle( GetOwner() );
552 mHiddenSignal.Emit();
556 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
558 return mTouchedOutsideSignal;
561 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
563 return mHiddenSignal;
566 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
568 Dali::BaseHandle handle( object );
570 bool connected( true );
571 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
573 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
575 popup.OutsideTouchedSignal().Connect( tracker, functor );
577 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
579 popup.HiddenSignal().Connect( tracker, functor );
583 // signalName does not match any signal
590 void Popup::OnStateAnimationFinished( Animation& source )
592 HandleStateChangeComplete();
595 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
597 if(event.GetPointCount()>0)
599 const TouchPoint& point = event.GetPoint(0);
601 if(point.state == TouchPoint::Down)
603 // Guard against destruction during signal emission
604 Toolkit::Popup handle( GetOwner() );
606 mTouchedOutsideSignal.Emit();
613 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
615 // consume mouse wheel event in dimmed backing actor
619 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
621 // consume event (stops backing actor receiving touch events)
625 void Popup::OnControlChildAdd( Actor& child )
627 // reparent any children added by user to the body layer.
628 if( mAlterAddedChild )
630 // Removes previously added content.
633 mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) );
636 // keep a handle to the new content.
639 mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) );
643 void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
645 // Hide the background image
646 mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) );
648 // Relayout All buttons
649 if ( !mButtons.empty() )
651 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
652 Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ),
653 mPopupStyle->bottomSize.height - mPopupStyle->margin );
655 Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f );
657 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
659 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
661 Actor button = *iter;
663 // If there is only one button, it needs to be laid out on center.
664 if ( mButtons.size() == 1 )
666 buttonPosition.x = 0.0f;
667 button.SetAnchorPoint( AnchorPoint::CENTER );
668 button.SetParentOrigin( ParentOrigin::CENTER );
672 button.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
673 button.SetParentOrigin( ParentOrigin::CENTER_LEFT );
676 button.SetPosition( buttonPosition );
678 button.PropagateRelayoutFlags(); // Reset relayout flags for relayout
679 container.Add( button, buttonSize );
684 void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
688 if( policy == ResizePolicy::FIT_TO_CHILDREN )
690 mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension );
691 if( dimension & Dimension::HEIGHT )
693 mPopupLayout.SetFitHeight( 1 );
698 mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension );
699 // Make the content cell fill the whole of the available space
700 if( dimension & Dimension::HEIGHT )
702 mPopupLayout.SetRelativeHeight( 1, 1.0f );
708 bool Popup::OnKeyEvent(const KeyEvent& event)
710 bool consumed = false;
712 if(event.state == KeyEvent::Down)
714 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
716 SetState(Toolkit::Popup::POPUP_HIDE);
724 Vector3 Popup::GetNaturalSize()
726 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
727 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
729 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
733 Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize();
734 // Buffer to avoid errors. The width of the popup could potentially be the width of the title text.
735 // It was observed in this case that text wrapping was then inconsistent when seen on device
736 const float titleBuffer = 0.5f;
737 titleNaturalSize.width += titleBuffer;
739 // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
740 // to that of the stage
741 if( titleNaturalSize.width >= maxWidth)
743 naturalSize.width = maxWidth;
744 naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width );
748 naturalSize += titleNaturalSize;
751 naturalSize.height += mPopupStyle->margin;
756 Vector3 contentSize = mContent.GetNaturalSize();
757 // Choose the biggest width
758 naturalSize.width = std::max( naturalSize.width, contentSize.width );
759 if( naturalSize.width > maxWidth )
761 naturalSize.width = maxWidth;
762 contentSize.height = mContent.GetHeightForWidth( maxWidth );
764 naturalSize.height += contentSize.height + mPopupStyle->margin;
767 if( !mButtons.empty() )
769 naturalSize.height += mPopupStyle->bottomSize.height;
773 naturalSize.width += margin;
774 naturalSize.height += margin;
779 float Popup::GetHeightForWidth( float width )
781 float height( 0.0f );
782 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
786 height += mTitle.GetImplementation().GetHeightForWidth( popupWidth );
787 height += mPopupStyle->margin;
792 height += mContent.GetHeightForWidth( popupWidth ) + mPopupStyle->margin;
795 if( !mButtons.empty() )
797 height += mPopupStyle->bottomSize.height;
801 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
807 float Popup::GetWidthForHeight( float height )
809 return GetNaturalSize().width;
812 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
814 Actor nextFocusableActor( currentFocusedActor );
816 // TODO: Needs to be optimised
818 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
820 // The current focused actor is not within popup
821 if( mContent && mContent.IsKeyboardFocusable() )
823 // If content is focusable, move the focus to content
824 nextFocusableActor = mContent;
826 else if( !mButtons.empty() )
828 // Otherwise, movethe focus to the first button
829 nextFocusableActor = mButtons[0];
834 // Rebuild the focus chain because button or content can be added or removed dynamically
835 ActorContainer focusableActors;
836 if( mContent && mContent.IsKeyboardFocusable() )
838 focusableActors.push_back(mContent);
841 for(unsigned int i = 0; i < mButtons.size(); i++)
843 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
845 focusableActors.push_back(mButtons[i]);
849 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
851 if ( currentFocusedActor == *iter )
855 case Toolkit::Control::Left:
857 if ( iter == focusableActors.begin() )
859 nextFocusableActor = *( focusableActors.end() - 1 );
863 nextFocusableActor = *( iter - 1 );
867 case Toolkit::Control::Right:
869 if ( iter == focusableActors.end() - 1 )
871 nextFocusableActor = *( focusableActors.begin() );
875 nextFocusableActor = *( iter + 1 );
880 case Toolkit::Control::Up:
882 if ( *iter == mContent )
884 nextFocusableActor = *( focusableActors.end() - 1 );
888 if ( mContent && mContent.IsKeyboardFocusable() )
890 nextFocusableActor = mContent;
894 if ( iter == focusableActors.begin() )
896 nextFocusableActor = *( focusableActors.end() - 1 );
900 nextFocusableActor = *( iter - 1 );
907 case Toolkit::Control::Down:
909 if ( mContent && mContent.IsKeyboardFocusable() )
911 nextFocusableActor = mContent;
915 if ( iter == focusableActors.end() - 1 )
917 nextFocusableActor = *( focusableActors.begin() );
921 nextFocusableActor = *( iter + 1 );
925 if ( *iter == mContent && !mButtons.empty() )
927 nextFocusableActor = mButtons[0];
933 if(!nextFocusableActor)
935 DALI_LOG_WARNING("Can not decide next focusable actor\n");
943 return nextFocusableActor;
946 } // namespace Internal
948 } // namespace Toolkit