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/integration-api/debug.h>
34 #include <dali-toolkit/public-api/controls/buttons/button.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
37 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
38 #include <dali-toolkit/internal/controls/relayout-helper.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 CONTENT_DEPTH = 1.0f; ///< 3D Effect of buttons/title etc. appearing off the popup.
73 const float POPUP_ANIMATION_DURATION = 0.5f; ///< Duration of hide/show animations
74 const float BACKING_DEPTH = -1.0f; ///< Depth of backing (positioned just behind dialog, so dialog catches hit events first)
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);
85 * The background size should be at least as big as the Dialog.
86 * In some cases a background may have graphics which are visible
87 * outside of the Dialog, e.g. A Shadow. For this we need to alter
88 * the size of Background.
90 * @param[in] outerBorder The border to extend beyond parent's Size.
91 * @param[in] parentSize The parent's size
93 Vector3 BackgroundSize(const Vector4& outerBoarder, const Vector3& parentSize)
95 Vector3 size( parentSize );
96 size.width += outerBoarder.x + outerBoarder.y;
97 size.height += outerBoarder.z + outerBoarder.w;
103 * sets button area size to parent's size plus a border.
105 * @param[in] outerBorder The border to extend beyond parent's Size.
106 * @param[in] parentSize The parent's size
108 Vector3 ButtonAreaSize( const Vector4& outBoarder, const Vector3& parentSize )
110 Vector3 size( parentSize );
111 size.width += outBoarder.x + outBoarder.y;
112 size.width -= (POPUP_OUT_MARGIN_WIDTH + POPUP_OUT_MARGIN_WIDTH);
113 size.height = POPUP_BUTTON_BG_HEIGHT;
118 } // unnamed namespace
120 ///////////////////////////////////////////////////////////////////////////////////////////////////
122 ///////////////////////////////////////////////////////////////////////////////////////////////////
124 Dali::Toolkit::Popup Popup::New()
126 PopupStylePtr style = PopupStyleDefault::New();
128 // Create the implementation
129 PopupPtr popup(new Popup(*style));
131 // Pass ownership to CustomActor via derived handle
132 Dali::Toolkit::Popup handle(*popup);
134 // Second-phase init of the implementation
135 // This can only be done after the CustomActor connection has been made...
141 Popup::Popup(PopupStyle& style)
142 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
144 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
145 mAlterAddedChild(false),
146 mPopupStyle(PopupStylePtr(&style)),
147 mPropertyTitle(Property::INVALID_INDEX),
148 mPropertyState(Property::INVALID_INDEX)
150 SetKeyboardNavigationSupport( true );
153 void Popup::OnInitialize()
156 self.SetSensitive(false);
159 mLayer = Layer::New();
160 mLayer.SetParentOrigin(ParentOrigin::CENTER);
161 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
165 mPopupBg = Actor::New();
166 mPopupBg.SetParentOrigin(ParentOrigin::CENTER);
167 mPopupBg.SetAnchorPoint(AnchorPoint::CENTER);
168 mLayer.Add(mPopupBg);
170 // Any content after this point which is added to Self() will be reparented to
172 mAlterAddedChild = true;
174 // Add Backing (Dim effect)
177 // Add Dialog ( background image, title, content container, button container and tail )
181 ShowTail(ParentOrigin::BOTTOM_CENTER);
183 // Hide content by default.
184 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
186 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
187 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
189 // Make self as keyboard focusable and focus group
190 self.SetKeyboardFocusable(true);
191 SetAsKeyboardFocusGroup(true);
194 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
196 if( index == mPropertyTitle )
198 SetTitle(propertyValue.Get<std::string>());
200 else if ( index == mPropertyState )
202 std::string value( propertyValue.Get<std::string>() );
203 if(value == "POPUP_SHOW")
205 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
207 else if( value == "POPUP_HIDE")
209 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
218 size_t Popup::GetButtonCount() const
220 return mButtons.size();
223 void Popup::SetBackgroundImage( Actor image )
225 // Removes any previous background.
226 if( mBackgroundImage && mPopupBg )
228 mPopupBg.Remove( mBackgroundImage );
231 // Adds new background to the dialog.
232 mBackgroundImage = image;
234 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
235 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
237 mPopupBg.Add( mBackgroundImage );
240 void Popup::SetButtonAreaImage( Actor image )
242 // Removes any previous area image.
243 if( mButtonAreaImage && mPopupBg )
245 mPopupBg.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 mPopupBg.Add( mButtonAreaImage );
257 void Popup::SetTitle( const std::string& text )
261 const std::string& Popup::GetTitle() const
263 static std::string temp("");
267 void Popup::AddButton( Toolkit::Button button )
269 mButtons.push_back( button );
270 mBottomBg.Add( button );
275 void Popup::SetState( Toolkit::Popup::PopupState state )
277 SetState( state, POPUP_ANIMATION_DURATION );
280 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
282 // default animation behaviour.
283 HandleStateChange(state, duration);
286 Toolkit::Popup::PopupState Popup::GetState() const
291 void Popup::ShowTail(const Vector3& position)
293 // Replaces the tail actor.
294 if(mTailImage && mTailImage.GetParent())
296 mTailImage.GetParent().Remove( mTailImage );
300 std::string image = "";
302 // depending on position of tail around ParentOrigin, a different tail image is used...
303 if(position.y < Math::MACHINE_EPSILON_1)
305 image = mPopupStyle->tailUpImage;
307 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
309 image = mPopupStyle->tailDownImage;
311 else if(position.x < Math::MACHINE_EPSILON_1)
313 image = mPopupStyle->tailLeftImage;
315 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
317 image = mPopupStyle->tailRightImage;
322 Image tail = ResourceImage::New( image );
323 mTailImage = ImageActor::New(tail);
324 const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
326 mTailImage.SetParentOrigin(position);
327 mTailImage.SetAnchorPoint(anchorPoint);
329 mBottomBg.Add(mTailImage);
333 void Popup::HideTail()
335 ShowTail(ParentOrigin::CENTER);
338 void Popup::SetStyle(PopupStyle& style)
340 mPopupStyle = PopupStylePtr(&style);
344 PopupStylePtr Popup::GetStyle() const
349 void Popup::SetDefaultBackgroundImage()
351 Image bg = ResourceImage::New( mPopupStyle->backgroundImage );
352 ImageActor bgImage = ImageActor::New( bg );
353 bgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
354 bgImage.SetNinePatchBorder( mPopupStyle->backgroundScale9Border );
356 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
357 ImageActor buttonBgImage = ImageActor::New( buttonBg );
358 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
359 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
361 SetBackgroundImage( bgImage );
362 SetButtonAreaImage( buttonBgImage );
365 void Popup::CreateBacking()
367 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
369 mBacking.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
370 mBacking.SetSensitive(true);
372 mLayer.Add(mBacking);
373 mBacking.SetOpacity(0.0f);
374 mBacking.SetPosition(0.0f, 0.0f, BACKING_DEPTH);
375 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
376 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
379 void Popup::CreateDialog()
381 // Adds default background image.
382 SetDefaultBackgroundImage();
384 // Adds bottom background
385 mBottomBg = Actor::New();
386 mPopupBg.Add( mBottomBg );
389 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
391 const Vector2& stageSize( Stage::GetCurrent().GetSize() );
394 float targetBackingAlpha;
395 Vector3 targetBackingSize;
404 case Toolkit::Popup::POPUP_HIDE:
406 targetSize = Vector3(0.0f, 0.0f, 1.0f);
407 targetBackingAlpha = 0.0f;
408 targetBackingSize = Vector3(0.0f, 0.0f, 1.0f);
410 ClearKeyInputFocus();
412 // Retore the keyboard focus when popup is hidden
413 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
415 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
416 if( keyboardFocusManager )
418 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
425 case Toolkit::Popup::POPUP_SHOW:
428 targetSize = Vector3(1.0f, 1.0f, 1.0f);
429 targetBackingAlpha = 1.0f;
430 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
431 targetBackingSize = Vector3( length, length, 1.0f );
434 // Add contents to stage for showing.
435 if( !mLayer.GetParent() )
437 mAlterAddedChild = false;
439 mAlterAddedChild = true;
441 Self().SetSensitive(true);
444 // Handle the keyboard focus when popup is shown
445 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
446 if( keyboardFocusManager )
448 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
450 if( mContent && mContent.IsKeyboardFocusable() )
452 // If content is focusable, move the focus to content
453 keyboardFocusManager.SetCurrentFocusActor(mContent);
455 else if( !mButtons.empty() )
457 // Otherwise, movethe focus to the first button
458 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
462 DALI_LOG_WARNING("There is no focusable in popup\n");
469 mBacking.SetSize( targetBackingSize );
471 if(duration > Math::MACHINE_EPSILON_1)
479 mAnimation = Animation::New(duration);
483 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
484 mAnimation.AnimateTo( Property(mPopupBg, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
488 mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
489 mAnimation.AnimateTo( Property(mPopupBg, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
492 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
496 mBacking.SetOpacity( targetBackingAlpha );
497 mPopupBg.SetScale( targetSize );
499 HandleStateChangeComplete();
503 void Popup::HandleStateChangeComplete()
505 // Remove contents from stage if completely hidden.
506 if( (mState == Toolkit::Popup::POPUP_HIDE) && (mLayer.GetParent()) )
508 Self().Remove(mLayer);
509 Self().SetSensitive( false );
511 // Guard against destruction during signal emission
512 Toolkit::Popup handle( GetOwner() );
513 mHiddenSignal.Emit();
517 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
519 return mTouchedOutsideSignal;
522 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
524 return mHiddenSignal;
527 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
529 Dali::BaseHandle handle( object );
531 bool connected( true );
532 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
534 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
536 popup.OutsideTouchedSignal().Connect( tracker, functor );
538 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
540 popup.HiddenSignal().Connect( tracker, functor );
544 // signalName does not match any signal
551 void Popup::OnStateAnimationFinished( Animation& source )
553 HandleStateChangeComplete();
556 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
558 if(event.GetPointCount()>0)
560 const TouchPoint& point = event.GetPoint(0);
562 if(point.state == TouchPoint::Down)
564 // Guard against destruction during signal emission
565 Toolkit::Popup handle( GetOwner() );
567 mTouchedOutsideSignal.Emit();
574 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
576 // consume mouse wheel event in dimmed backing actor
580 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
582 // consume event (stops backing actor receiving touch events)
586 void Popup::OnControlChildAdd( Actor& child )
588 // reparent any children added by user to the body layer.
589 if( mAlterAddedChild )
591 // Removes previously added content.
594 mPopupBg.Remove( mContent );
597 // Reparent new content.
598 Self().Remove( child );
600 // keep a handle to the new content.
603 mPopupBg.Add( mContent );
607 void Popup::OnControlSizeSet( const Vector3& targetSize )
609 mLayer.SetSize( targetSize );
610 mPopupBg.SetSize( targetSize );
612 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
613 if( mBackgroundImage )
615 mBackgroundImage.SetSize( BackgroundSize( outerBorder,targetSize ) );
617 if( mButtonAreaImage )
619 mButtonAreaImage.SetSize( ButtonAreaSize( outerBorder, targetSize ) );
624 void Popup::OnRelayout( const Vector2& size, ActorSizeContainer& container )
626 // Set the popup size
628 popupSize.width = size.width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
629 popupSize.height = size.height - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
631 // Update sizes of all popup's components.
633 // Relayout background image.
634 // Adjust background position and size relative to parent to cater to outer Border.
635 // Some backgrounds are intended to over-spill. That is some content
636 // should appear outside the Dialog on all sides i.e. Shadows, glow effects.
637 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
639 if( mBackgroundImage )
641 mBackgroundImage.SetSize(BackgroundSize(outerBorder, Vector3(size)));
642 mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
643 mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
644 mBackgroundImage.SetPosition( -outerBorder.x, -outerBorder.y, 0.0f );
647 if( mPopupBg && mButtonAreaImage )
649 // If there are no buttons, button background is also removed.
650 if ( mButtons.size() == 0 )
652 mPopupBg.Remove( mButtonAreaImage );
656 mButtonAreaImage.SetSize( ButtonAreaSize(outerBorder, Vector3(size)) );
657 mButtonAreaImage.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
658 mButtonAreaImage.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
659 mButtonAreaImage.SetY( -outerBorder.z - POPUP_OUT_MARGIN_HEIGHT );
661 mPopupBg.Add( mButtonAreaImage );
666 Vector3 positionOffset( 0.0f, mPopupStyle->margin + POPUP_OUT_MARGIN_WIDTH, CONTENT_DEPTH );
672 // If the content width is greater than popup width then scale it down/wrap text as needed
673 Vector2 contentSize( RelayoutHelper::GetNaturalSize( mContent ) );
674 if( contentSize.width > popupSize.width )
676 contentSize.width = popupSize.width;
677 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, contentSize.width );
680 mContent.SetSize( contentSize );
681 Relayout( mContent, contentSize, container );
683 mContent.SetParentOrigin(ParentOrigin::TOP_CENTER);
684 mContent.SetAnchorPoint(AnchorPoint::TOP_CENTER);
686 mContent.SetPosition( positionOffset );
688 positionOffset.y += contentSize.height + mPopupStyle->margin;
691 // Relayout Button Area
694 mBottomBg.SetSize( popupSize.width, mPopupStyle->bottomSize.height );
696 mBottomBg.SetParentOrigin(ParentOrigin::TOP_CENTER);
697 mBottomBg.SetAnchorPoint(AnchorPoint::TOP_CENTER);
699 mBottomBg.SetPosition( positionOffset );
702 // Relayout All buttons
703 if ( !mButtons.empty() )
705 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
706 Vector2 buttonSize( ( ( popupSize.width - mPopupStyle->buttonSpacing * ( mButtons.size() - 1 ) ) / mButtons.size() ),
707 mPopupStyle->bottomSize.height - mPopupStyle->margin );
709 Vector3 buttonPosition;
711 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
713 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
715 iter->SetPosition( buttonPosition );
717 // If there is only one button, it needs to be laid out on center.
718 if ( mButtons.size() == 1 )
720 iter->SetAnchorPoint( AnchorPoint::CENTER );
721 iter->SetParentOrigin( ParentOrigin::CENTER );
725 iter->SetAnchorPoint( AnchorPoint::CENTER_LEFT );
726 iter->SetParentOrigin( ParentOrigin::CENTER_LEFT );
729 Relayout( *iter, buttonSize, container );
733 if( mShowing && mBacking )
735 Vector2 stageSize = Stage::GetCurrent().GetSize();
736 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
737 Vector3 targetBackingSize = Vector3( length, length, 1.0f );
739 mBacking.SetSize( targetBackingSize );
743 bool Popup::OnKeyEvent(const KeyEvent& event)
745 bool consumed = false;
747 if(event.state == KeyEvent::Down)
749 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
751 SetState(Toolkit::Popup::POPUP_HIDE);
759 Vector3 Popup::GetNaturalSize()
761 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
762 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
764 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
768 Vector3 contentSize = RelayoutHelper::GetNaturalSize( mContent );
769 // Choose the biggest width
770 naturalSize.width = std::max( naturalSize.width, contentSize.width );
771 if( naturalSize.width > maxWidth )
773 naturalSize.width = maxWidth;
774 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, maxWidth );
776 naturalSize.height += contentSize.height + mPopupStyle->margin;
779 if( !mButtons.empty() )
781 naturalSize.height += mPopupStyle->bottomSize.height;
785 naturalSize.width += margin;
786 naturalSize.height += margin;
791 float Popup::GetHeightForWidth( float width )
793 float height( 0.0f );
794 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
798 height += RelayoutHelper::GetHeightForWidth( mContent, 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