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/object/type-registry.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/public-api/images/resource-image.h>
33 #include <dali-toolkit/public-api/controls/buttons/button.h>
34 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/internal/controls/relayout-helper.h>
37 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
38 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
44 const float CONTENT_DEPTH = 1.0f; ///< 3D Effect of buttons/title etc. appearing off the popup.
45 const float POPUP_ANIMATION_DURATION = 0.5f; ///< Duration of hide/show animations
46 const float BACKING_DEPTH = -1.0f; ///< Depth of backing (positioned just behind dialog, so dialog catches hit events first)
48 const float POPUP_WIDTH = 720.0f; ///< Width of Popup
49 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
50 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
51 const float POPUP_TITLE_WIDTH = 648.0f; ///<Width of Popup Title
52 const float POPUP_BUTTON_BG_HEIGHT = 96.f; ///< Height of Button Background.
53 const Vector3 DEFAULT_DIALOG_SIZE = Vector3(POPUP_TITLE_WIDTH/POPUP_WIDTH, 0.5f, 0.0f);
54 const Vector3 DEFAULT_BOTTOM_SIZE = Vector3(1.0f, 0.2f, 0.0f);
58 const char* const SIGNAL_TOUCHED_OUTSIDE = "touched-outside";
59 const char* const SIGNAL_HIDDEN = "hidden";
63 const char* const PROPERTY_TITLE = "title";
64 const char* const PROPERTY_STATE = "state";
67 * The background size should be at least as big as the Dialog.
68 * In some cases a background may have graphics which are visible
69 * outside of the Dialog, e.g. A Shadow. For this we need to alter
70 * the size of Background.
72 * @param[in] outerBorder The border to extend beyond parent's Size.
73 * @param[in] parentSize The parent's size
75 Vector3 BackgroundSize(const Vector4& outerBoarder, const Vector3& parentSize)
77 Vector3 size( parentSize );
78 size.width += outerBoarder.x + outerBoarder.y;
79 size.height += outerBoarder.z + outerBoarder.w;
85 * sets button area size to parent's size plus a border.
87 * @param[in] outerBorder The border to extend beyond parent's Size.
88 * @param[in] parentSize The parent's size
90 Vector3 ButtonAreaSize( const Vector4& outBoarder, const Vector3& parentSize )
92 Vector3 size( parentSize );
93 size.width += outBoarder.x + outBoarder.y;
94 size.width -= (POPUP_OUT_MARGIN_WIDTH + POPUP_OUT_MARGIN_WIDTH);
95 size.height = POPUP_BUTTON_BG_HEIGHT;
100 } // unnamed namespace
116 return Toolkit::Popup::New();
119 TypeRegistration typeRegistration( typeid( Toolkit::Popup ), typeid( Toolkit::Control ), Create );
121 SignalConnectorType signalConnector1( typeRegistration, SIGNAL_TOUCHED_OUTSIDE, &Popup::DoConnectSignal );
122 SignalConnectorType signalConnector2( typeRegistration, SIGNAL_HIDDEN, &Popup::DoConnectSignal );
128 ///////////////////////////////////////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////////////////////////////////
132 Dali::Toolkit::Popup Popup::New()
134 PopupStylePtr style = PopupStyleDefault::New();
136 // Create the implementation
137 PopupPtr popup(new Popup(*style));
139 // Pass ownership to CustomActor via derived handle
140 Dali::Toolkit::Popup handle(*popup);
142 // Second-phase init of the implementation
143 // This can only be done after the CustomActor connection has been made...
149 Popup::Popup(PopupStyle& style)
150 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
152 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
153 mAlterAddedChild(false),
154 mPopupStyle(PopupStylePtr(&style)),
155 mPropertyTitle(Property::INVALID_INDEX),
156 mPropertyState(Property::INVALID_INDEX)
158 SetKeyboardNavigationSupport( true );
161 void Popup::OnInitialize()
164 self.SetSensitive(false);
167 mLayer = Layer::New();
168 mLayer.SetParentOrigin(ParentOrigin::CENTER);
169 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
173 mPopupBg = Actor::New();
174 mPopupBg.SetParentOrigin(ParentOrigin::CENTER);
175 mPopupBg.SetAnchorPoint(AnchorPoint::CENTER);
176 mLayer.Add(mPopupBg);
178 // Any content after this point which is added to Self() will be reparented to
180 mAlterAddedChild = true;
182 // Add Backing (Dim effect)
185 // Add Dialog ( background image, title, content container, button container and tail )
189 ShowTail(ParentOrigin::BOTTOM_CENTER);
191 // Hide content by default.
192 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
194 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
195 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
197 // Make self as keyboard focusable and focus group
198 self.SetKeyboardFocusable(true);
199 SetAsKeyboardFocusGroup(true);
202 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
204 if( index == mPropertyTitle )
206 SetTitle(propertyValue.Get<std::string>());
208 else if ( index == mPropertyState )
210 std::string value( propertyValue.Get<std::string>() );
211 if(value == "POPUP_SHOW")
213 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
215 else if( value == "POPUP_HIDE")
217 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
226 size_t Popup::GetButtonCount() const
228 return mButtons.size();
231 void Popup::SetBackgroundImage( Actor image )
233 // Removes any previous background.
234 if( mBackgroundImage && mPopupBg )
236 mPopupBg.Remove( mBackgroundImage );
239 // Adds new background to the dialog.
240 mBackgroundImage = image;
242 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
243 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
245 mPopupBg.Add( mBackgroundImage );
248 void Popup::SetButtonAreaImage( Actor image )
250 // Removes any previous area image.
251 if( mButtonAreaImage && mPopupBg )
253 mPopupBg.Remove( mButtonAreaImage );
256 // Adds new area image to the dialog.
257 mButtonAreaImage = image;
259 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
260 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
262 mPopupBg.Add( mButtonAreaImage );
265 void Popup::SetTitle( const std::string& text )
269 const std::string& Popup::GetTitle() const
271 static std::string temp("");
275 void Popup::AddButton( Toolkit::Button button )
277 mButtons.push_back( button );
278 mBottomBg.Add( button );
283 void Popup::SetState( Toolkit::Popup::PopupState state )
285 SetState( state, POPUP_ANIMATION_DURATION );
288 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
290 // default animation behaviour.
291 HandleStateChange(state, duration);
294 Toolkit::Popup::PopupState Popup::GetState() const
299 void Popup::ShowTail(const Vector3& position)
301 // Replaces the tail actor.
302 if(mTailImage && mTailImage.GetParent())
304 mTailImage.GetParent().Remove( mTailImage );
308 std::string image = "";
310 // depending on position of tail around ParentOrigin, a different tail image is used...
311 if(position.y < Math::MACHINE_EPSILON_1)
313 image = mPopupStyle->tailUpImage;
315 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
317 image = mPopupStyle->tailDownImage;
319 else if(position.x < Math::MACHINE_EPSILON_1)
321 image = mPopupStyle->tailLeftImage;
323 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
325 image = mPopupStyle->tailRightImage;
330 Image tail = ResourceImage::New( image );
331 mTailImage = ImageActor::New(tail);
332 const Vector3 anchorPoint = AnchorPoint::FRONT_BOTTOM_RIGHT - position;
334 mTailImage.SetParentOrigin(position);
335 mTailImage.SetAnchorPoint(anchorPoint);
337 mBottomBg.Add(mTailImage);
341 void Popup::HideTail()
343 ShowTail(ParentOrigin::CENTER);
346 void Popup::SetStyle(PopupStyle& style)
348 mPopupStyle = PopupStylePtr(&style);
352 PopupStylePtr Popup::GetStyle() const
357 void Popup::SetDefaultBackgroundImage()
359 Image bg = ResourceImage::New( mPopupStyle->backgroundImage );
360 ImageActor bgImage = ImageActor::New( bg );
361 bgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
362 bgImage.SetNinePatchBorder( mPopupStyle->backgroundScale9Border );
364 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
365 ImageActor buttonBgImage = ImageActor::New( buttonBg );
366 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
367 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
369 SetBackgroundImage( bgImage );
370 SetButtonAreaImage( buttonBgImage );
373 void Popup::CreateBacking()
375 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
377 mBacking.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
378 mBacking.SetSensitive(true);
380 mLayer.Add(mBacking);
381 mBacking.SetOpacity(0.0f);
382 mBacking.SetPosition(0.0f, 0.0f, BACKING_DEPTH);
383 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
384 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
387 void Popup::CreateDialog()
389 // Adds default background image.
390 SetDefaultBackgroundImage();
392 // Adds bottom background
393 mBottomBg = Actor::New();
394 mPopupBg.Add( mBottomBg );
397 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
399 const Vector2& stageSize( Stage::GetCurrent().GetSize() );
402 float targetBackingAlpha;
403 Vector3 targetBackingSize;
412 case Toolkit::Popup::POPUP_HIDE:
414 targetSize = Vector3(0.0f, 0.0f, 1.0f);
415 targetBackingAlpha = 0.0f;
416 targetBackingSize = Vector3(0.0f, 0.0f, 1.0f);
418 ClearKeyInputFocus();
420 // Retore the keyboard focus when popup is hidden
421 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
423 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
424 if( keyboardFocusManager )
426 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
433 case Toolkit::Popup::POPUP_SHOW:
436 targetSize = Vector3(1.0f, 1.0f, 1.0f);
437 targetBackingAlpha = 1.0f;
438 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
439 targetBackingSize = Vector3( length, length, 1.0f );
442 // Add contents to stage for showing.
443 if( !mLayer.GetParent() )
445 mAlterAddedChild = false;
447 mAlterAddedChild = true;
449 Self().SetSensitive(true);
452 // Handle the keyboard focus when popup is shown
453 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
454 if( keyboardFocusManager )
456 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
458 if( mContent && mContent.IsKeyboardFocusable() )
460 // If content is focusable, move the focus to content
461 keyboardFocusManager.SetCurrentFocusActor(mContent);
463 else if( !mButtons.empty() )
465 // Otherwise, movethe focus to the first button
466 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
470 DALI_LOG_WARNING("There is no focusable in popup\n");
477 mBacking.SetSize( targetBackingSize );
479 if(duration > Math::MACHINE_EPSILON_1)
487 mAnimation = Animation::New(duration);
491 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
492 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
496 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
497 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
500 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
504 mBacking.SetOpacity( targetBackingAlpha );
505 mPopupBg.SetScale( targetSize );
507 HandleStateChangeComplete();
511 void Popup::HandleStateChangeComplete()
513 // Remove contents from stage if completely hidden.
514 if( (mState == Toolkit::Popup::POPUP_HIDE) && (mLayer.GetParent()) )
516 Self().Remove(mLayer);
517 Self().SetSensitive( false );
519 // Guard against destruction during signal emission
520 Toolkit::Popup handle( GetOwner() );
521 mHiddenSignal.Emit();
525 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
527 return mTouchedOutsideSignal;
530 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
532 return mHiddenSignal;
535 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
537 Dali::BaseHandle handle( object );
539 bool connected( true );
540 Toolkit::Popup popup = Toolkit::Popup::DownCast( handle );
542 if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) )
544 popup.OutsideTouchedSignal().Connect( tracker, functor );
546 else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) )
548 popup.HiddenSignal().Connect( tracker, functor );
552 // signalName does not match any signal
559 void Popup::OnStateAnimationFinished( Animation& source )
561 HandleStateChangeComplete();
564 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
566 if(event.GetPointCount()>0)
568 const TouchPoint& point = event.GetPoint(0);
570 if(point.state == TouchPoint::Down)
572 // Guard against destruction during signal emission
573 Toolkit::Popup handle( GetOwner() );
575 mTouchedOutsideSignal.Emit();
582 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
584 // consume mouse wheel event in dimmed backing actor
588 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
590 // consume event (stops backing actor receiving touch events)
594 void Popup::OnControlChildAdd( Actor& child )
596 // reparent any children added by user to the body layer.
597 if( mAlterAddedChild )
599 // Removes previously added content.
602 mPopupBg.Remove( mContent );
605 // Reparent new content.
606 Self().Remove( child );
608 // keep a handle to the new content.
611 mPopupBg.Add( mContent );
615 void Popup::OnControlSizeSet( const Vector3& targetSize )
617 mLayer.SetSize( targetSize );
618 mPopupBg.SetSize( targetSize );
620 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
621 if( mBackgroundImage )
623 mBackgroundImage.SetSize( BackgroundSize( outerBorder,targetSize ) );
625 if( mButtonAreaImage )
627 mButtonAreaImage.SetSize( ButtonAreaSize( outerBorder, targetSize ) );
632 void Popup::OnRelayout( const Vector2& size, ActorSizeContainer& container )
634 // Set the popup size
636 popupSize.width = size.width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
637 popupSize.height = size.height - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
639 // Update sizes of all popup's components.
641 // Relayout background image.
642 // Adjust background position and size relative to parent to cater to outer Border.
643 // Some backgrounds are intended to over-spill. That is some content
644 // should appear outside the Dialog on all sides i.e. Shadows, glow effects.
645 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
647 if( mBackgroundImage )
649 mBackgroundImage.SetSize(BackgroundSize(outerBorder, Vector3(size)));
650 mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
651 mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
652 mBackgroundImage.SetPosition( -outerBorder.x, -outerBorder.y, 0.0f );
655 if( mPopupBg && mButtonAreaImage )
657 // If there are no buttons, button background is also removed.
658 if ( mButtons.size() == 0 )
660 mPopupBg.Remove( mButtonAreaImage );
664 mButtonAreaImage.SetSize( ButtonAreaSize(outerBorder, Vector3(size)) );
665 mButtonAreaImage.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
666 mButtonAreaImage.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
667 mButtonAreaImage.SetY( -outerBorder.z - POPUP_OUT_MARGIN_HEIGHT );
669 mPopupBg.Add( mButtonAreaImage );
674 Vector3 positionOffset( 0.0f, mPopupStyle->margin + POPUP_OUT_MARGIN_WIDTH, CONTENT_DEPTH );
680 // If the content width is greater than popup width then scale it down/wrap text as needed
681 Vector2 contentSize( RelayoutHelper::GetNaturalSize( mContent ) );
682 if( contentSize.width > popupSize.width )
684 contentSize.width = popupSize.width;
685 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, contentSize.width );
688 mContent.SetSize( contentSize );
689 Relayout( mContent, contentSize, container );
691 mContent.SetParentOrigin(ParentOrigin::TOP_CENTER);
692 mContent.SetAnchorPoint(AnchorPoint::TOP_CENTER);
694 mContent.SetPosition( positionOffset );
696 positionOffset.y += contentSize.height + mPopupStyle->margin;
699 // Relayout Button Area
702 mBottomBg.SetSize( popupSize.width, mPopupStyle->bottomSize.height );
704 mBottomBg.SetParentOrigin(ParentOrigin::TOP_CENTER);
705 mBottomBg.SetAnchorPoint(AnchorPoint::TOP_CENTER);
707 mBottomBg.SetPosition( positionOffset );
710 // Relayout All buttons
711 if ( !mButtons.empty() )
713 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
714 Vector2 buttonSize( ( ( popupSize.width - mPopupStyle->buttonSpacing * ( mButtons.size() - 1 ) ) / mButtons.size() ),
715 mPopupStyle->bottomSize.height - mPopupStyle->margin );
717 Vector3 buttonPosition;
719 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
721 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
723 iter->SetPosition( buttonPosition );
725 // If there is only one button, it needs to be laid out on center.
726 if ( mButtons.size() == 1 )
728 iter->SetAnchorPoint( AnchorPoint::CENTER );
729 iter->SetParentOrigin( ParentOrigin::CENTER );
733 iter->SetAnchorPoint( AnchorPoint::CENTER_LEFT );
734 iter->SetParentOrigin( ParentOrigin::CENTER_LEFT );
737 Relayout( *iter, buttonSize, container );
741 if( mShowing && mBacking )
743 Vector2 stageSize = Stage::GetCurrent().GetSize();
744 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
745 Vector3 targetBackingSize = Vector3( length, length, 1.0f );
747 mBacking.SetSize( targetBackingSize );
751 bool Popup::OnKeyEvent(const KeyEvent& event)
753 bool consumed = false;
755 if(event.state == KeyEvent::Down)
757 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
759 SetState(Toolkit::Popup::POPUP_HIDE);
767 Vector3 Popup::GetNaturalSize()
769 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
770 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
772 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
776 Vector3 contentSize = RelayoutHelper::GetNaturalSize( mContent );
777 // Choose the biggest width
778 naturalSize.width = std::max( naturalSize.width, contentSize.width );
779 if( naturalSize.width > maxWidth )
781 naturalSize.width = maxWidth;
782 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, maxWidth );
784 naturalSize.height += contentSize.height + mPopupStyle->margin;
787 if( !mButtons.empty() )
789 naturalSize.height += mPopupStyle->bottomSize.height;
793 naturalSize.width += margin;
794 naturalSize.height += margin;
799 float Popup::GetHeightForWidth( float width )
801 float height( 0.0f );
802 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
806 height += RelayoutHelper::GetHeightForWidth( mContent, popupWidth ) + mPopupStyle->margin;
809 if( !mButtons.empty() )
811 height += mPopupStyle->bottomSize.height;
815 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
821 float Popup::GetWidthForHeight( float height )
823 return GetNaturalSize().width;
826 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
828 Actor nextFocusableActor( currentFocusedActor );
830 // TODO: Needs to be optimised
832 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
834 // The current focused actor is not within popup
835 if( mContent && mContent.IsKeyboardFocusable() )
837 // If content is focusable, move the focus to content
838 nextFocusableActor = mContent;
840 else if( !mButtons.empty() )
842 // Otherwise, movethe focus to the first button
843 nextFocusableActor = mButtons[0];
848 // Rebuild the focus chain because button or content can be added or removed dynamically
849 ActorContainer focusableActors;
850 if( mContent && mContent.IsKeyboardFocusable() )
852 focusableActors.push_back(mContent);
855 for(unsigned int i = 0; i < mButtons.size(); i++)
857 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
859 focusableActors.push_back(mButtons[i]);
863 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
865 if ( currentFocusedActor == *iter )
869 case Toolkit::Control::Left:
871 if ( iter == focusableActors.begin() )
873 nextFocusableActor = *( focusableActors.end() - 1 );
877 nextFocusableActor = *( iter - 1 );
881 case Toolkit::Control::Right:
883 if ( iter == focusableActors.end() - 1 )
885 nextFocusableActor = *( focusableActors.begin() );
889 nextFocusableActor = *( iter + 1 );
894 case Toolkit::Control::Up:
896 if ( *iter == mContent )
898 nextFocusableActor = *( focusableActors.end() - 1 );
902 if ( mContent && mContent.IsKeyboardFocusable() )
904 nextFocusableActor = mContent;
908 if ( iter == focusableActors.begin() )
910 nextFocusableActor = *( focusableActors.end() - 1 );
914 nextFocusableActor = *( iter - 1 );
921 case Toolkit::Control::Down:
923 if ( mContent && mContent.IsKeyboardFocusable() )
925 nextFocusableActor = mContent;
929 if ( iter == focusableActors.end() - 1 )
931 nextFocusableActor = *( focusableActors.begin() );
935 nextFocusableActor = *( iter + 1 );
939 if ( *iter == mContent && !mButtons.empty() )
941 nextFocusableActor = mButtons[0];
947 if(!nextFocusableActor)
949 DALI_LOG_WARNING("Can not decide next focusable actor\n");
957 return nextFocusableActor;
960 } // namespace Internal
962 } // namespace Toolkit