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>
32 #include <dali-toolkit/public-api/controls/buttons/button.h>
33 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali-toolkit/internal/controls/relayout-helper.h>
36 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
37 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
43 const float CONTENT_DEPTH = 1.0f; ///< 3D Effect of buttons/title etc. appearing off the popup.
44 const float POPUP_ANIMATION_DURATION = 0.5f; ///< Duration of hide/show animations
45 const float BACKING_DEPTH = -1.0f; ///< Depth of backing (positioned just behind dialog, so dialog catches hit events first)
47 const float POPUP_WIDTH = 720.0f; ///< Width of Popup
48 const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension.
49 const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension.
50 const float POPUP_TITLE_WIDTH = 648.0f; ///<Width of Popup Title
51 const float POPUP_BUTTON_BG_HEIGHT = 96.f; ///< Height of Button Background.
52 const Vector3 DEFAULT_DIALOG_SIZE = Vector3(POPUP_TITLE_WIDTH/POPUP_WIDTH, 0.5f, 0.0f);
53 const Vector3 DEFAULT_BOTTOM_SIZE = Vector3(1.0f, 0.2f, 0.0f);
55 const char* const PROPERTY_TITLE = "title";
56 const char* const PROPERTY_STATE = "state";
58 // Constraints ///////////////////////////////////////////////////////////////////////////
61 * BackgroundSizeConstraint
63 * The background size should be at least as big as the Dialog.
64 * In some cases a background may have graphics which are visible
65 * outside of the Dialog, e.g. A Shadow. For this we need to alter
66 * the size of Background.
68 struct BackgroundSizeConstraint
71 * Constraint that sets size to parent's size plus a border.
73 * @param[in] outerBorder The border to extend beyond parent's Size.
75 BackgroundSizeConstraint( Vector4 outerBorder )
76 : mOuterBorder( outerBorder )
81 * (render thread code)
82 * @param[in] current The current size.
83 * @param[in] parentSizeProperty The parent's size
85 Vector3 operator()( const Vector3& current,
86 const PropertyInput& parentSizeProperty )
88 Vector3 size = parentSizeProperty.GetVector3();
90 size.width += mOuterBorder.x + mOuterBorder.y;
91 size.height += mOuterBorder.z + mOuterBorder.w;
96 const Vector4 mOuterBorder; ///< The size of the outer-border (Set to 0.0, 0.0f, 0.0f, 0.0f if doesn't exist).
99 struct ButtonAreaSizeConstraint
102 * Constraint that sets size to parent's size plus a border.
104 * @param[in] outerBorder The border to extend beyond parent's Size.
106 ButtonAreaSizeConstraint( Vector4 outerBorder )
107 : mOuterBorder( outerBorder )
112 * (render thread code)
113 * @param[in] current The current size.
114 * @param[in] parentSizeProperty The parent's size
116 Vector3 operator()( const Vector3& current,
117 const PropertyInput& parentSizeProperty )
119 Vector3 size = parentSizeProperty.GetVector3();
121 size.width += mOuterBorder.x + mOuterBorder.y;
122 size.width -= (POPUP_OUT_MARGIN_WIDTH + POPUP_OUT_MARGIN_WIDTH);
123 size.height = POPUP_BUTTON_BG_HEIGHT;
128 const Vector4 mOuterBorder; ///< The size of the outer-border (Set to 0.0, 0.0f, 0.0f, 0.0f if doesn't exist).
131 } // unnamed namespace
147 return Toolkit::Popup::New();
150 TypeRegistration typeRegistration( typeid(Toolkit::Popup), typeid(Toolkit::Control), Create );
152 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Popup::SIGNAL_TOUCHED_OUTSIDE, &Popup::DoConnectSignal );
153 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Popup::SIGNAL_HIDDEN, &Popup::DoConnectSignal );
159 ///////////////////////////////////////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////////////////////////////////////
163 Dali::Toolkit::Popup Popup::New()
165 PopupStylePtr style = PopupStyleDefault::New();
167 // Create the implementation
168 PopupPtr popup(new Popup(*style));
170 // Pass ownership to CustomActor via derived handle
171 Dali::Toolkit::Popup handle(*popup);
173 // Second-phase init of the implementation
174 // This can only be done after the CustomActor connection has been made...
180 Popup::Popup(PopupStyle& style)
181 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
183 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
184 mAlterAddedChild(false),
185 mPopupStyle(PopupStylePtr(&style)),
186 mPropertyTitle(Property::INVALID_INDEX),
187 mPropertyState(Property::INVALID_INDEX)
189 SetKeyboardNavigationSupport( true );
192 void Popup::OnInitialize()
195 self.SetSensitive(false);
198 mLayer = Layer::New();
199 mLayer.SetParentOrigin(ParentOrigin::CENTER);
200 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
202 mLayer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
205 mPopupBg = Actor::New();
206 mPopupBg.SetParentOrigin(ParentOrigin::CENTER);
207 mPopupBg.SetAnchorPoint(AnchorPoint::CENTER);
208 mPopupBg.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
209 mLayer.Add(mPopupBg);
211 // Any content after this point which is added to Self() will be reparented to
213 mAlterAddedChild = true;
215 // Add Backing (Dim effect)
218 // Add Dialog ( background image, title, content container, button container and tail )
222 ShowTail(ParentOrigin::BOTTOM_CENTER);
224 // Hide content by default.
225 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
227 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
228 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
230 // Make self as keyboard focusable and focus group
231 self.SetKeyboardFocusable(true);
232 SetAsKeyboardFocusGroup(true);
235 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
237 if( index == mPropertyTitle )
239 SetTitle(propertyValue.Get<std::string>());
241 else if ( index == mPropertyState )
243 std::string value( propertyValue.Get<std::string>() );
244 if(value == "POPUP_SHOW")
246 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
248 else if( value == "POPUP_HIDE")
250 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
259 size_t Popup::GetButtonCount() const
261 return mButtons.size();
264 void Popup::SetBackgroundImage( Actor image )
266 // Removes any previous background.
267 if( mBackgroundImage && mPopupBg )
269 mPopupBg.Remove( mBackgroundImage );
272 // Adds new background to the dialog.
273 mBackgroundImage = image;
275 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
276 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
278 mPopupBg.Add( mBackgroundImage );
281 void Popup::SetButtonAreaImage( Actor image )
283 // Removes any previous area image.
284 if( mButtonAreaImage && mPopupBg )
286 mPopupBg.Remove( mButtonAreaImage );
289 // Adds new area image to the dialog.
290 mButtonAreaImage = image;
292 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
293 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
295 mPopupBg.Add( mButtonAreaImage );
298 void Popup::SetTitle( const std::string& text )
302 const std::string& Popup::GetTitle() const
304 static std::string temp("");
308 void Popup::AddButton( Toolkit::Button button )
310 mButtons.push_back( button );
311 mBottomBg.Add( button );
316 void Popup::SetState( Toolkit::Popup::PopupState state )
318 SetState( state, POPUP_ANIMATION_DURATION );
321 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
323 // default animation behaviour.
324 HandleStateChange(state, duration);
327 Toolkit::Popup::PopupState Popup::GetState() const
332 void Popup::ShowTail(const Vector3& position)
334 // Replaces the tail actor.
335 if(mTailImage && mTailImage.GetParent())
337 mTailImage.GetParent().Remove( mTailImage );
341 std::string image = "";
343 // depending on position of tail around ParentOrigin, a different tail image is used...
344 if(position.y < Math::MACHINE_EPSILON_1)
346 image = mPopupStyle->tailUpImage;
348 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
350 image = mPopupStyle->tailDownImage;
352 else if(position.x < Math::MACHINE_EPSILON_1)
354 image = mPopupStyle->tailLeftImage;
356 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
358 image = mPopupStyle->tailRightImage;
363 Image tail = Image::New( image );
364 mTailImage = ImageActor::New(tail);
365 const Vector3 anchorPoint = AnchorPoint::FRONT_BOTTOM_RIGHT - position;
367 mTailImage.SetParentOrigin(position);
368 mTailImage.SetAnchorPoint(anchorPoint);
370 mBottomBg.Add(mTailImage);
374 void Popup::HideTail()
376 ShowTail(ParentOrigin::CENTER);
379 void Popup::SetStyle(PopupStyle& style)
381 mPopupStyle = PopupStylePtr(&style);
385 PopupStylePtr Popup::GetStyle() const
390 void Popup::SetDefaultBackgroundImage()
392 Image bg = Image::New( mPopupStyle->backgroundImage );
393 ImageActor bgImage = ImageActor::New( bg );
394 bgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
395 bgImage.SetNinePatchBorder( mPopupStyle->backgroundScale9Border );
397 Image buttonBg = Image::New( mPopupStyle->buttonAreaImage );
398 ImageActor buttonBgImage = ImageActor::New( buttonBg );
399 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
400 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
402 SetBackgroundImage( bgImage );
403 SetButtonAreaImage( buttonBgImage );
406 void Popup::CreateBacking()
408 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
410 mBacking.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
411 mBacking.SetSensitive(true);
413 mLayer.Add(mBacking);
414 mBacking.SetOpacity(0.0f);
415 mBacking.SetPosition(0.0f, 0.0f, BACKING_DEPTH);
416 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
417 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
420 void Popup::CreateDialog()
422 // Adds default background image.
423 SetDefaultBackgroundImage();
425 // Adds bottom background
426 mBottomBg = Actor::New();
427 mPopupBg.Add( mBottomBg );
430 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
432 const Vector2& stageSize( Stage::GetCurrent().GetSize() );
435 float targetBackingAlpha;
436 Vector3 targetBackingSize;
445 case Toolkit::Popup::POPUP_HIDE:
447 targetSize = Vector3(0.0f, 0.0f, 1.0f);
448 targetBackingAlpha = 0.0f;
449 targetBackingSize = Vector3(0.0f, 0.0f, 1.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;
471 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
472 targetBackingSize = Vector3( length, length, 1.0f );
475 // Add contents to stage for showing.
476 if( !mLayer.GetParent() )
478 mAlterAddedChild = false;
480 mAlterAddedChild = true;
482 Self().SetSensitive(true);
485 // Handle the keyboard focus when popup is shown
486 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
487 if( keyboardFocusManager )
489 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
491 if( mContent && mContent.IsKeyboardFocusable() )
493 // If content is focusable, move the focus to content
494 keyboardFocusManager.SetCurrentFocusActor(mContent);
496 else if( !mButtons.empty() )
498 // Otherwise, movethe focus to the first button
499 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
503 DALI_LOG_WARNING("There is no focusable in popup\n");
510 mBacking.SetSize( targetBackingSize );
512 if(duration > Math::MACHINE_EPSILON_1)
520 mAnimation = Animation::New(duration);
524 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
525 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
529 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
530 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
533 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
537 mBacking.SetOpacity( targetBackingAlpha );
538 mPopupBg.SetScale( targetSize );
540 HandleStateChangeComplete();
544 void Popup::HandleStateChangeComplete()
546 // Remove contents from stage if completely hidden.
547 if( (mState == Toolkit::Popup::POPUP_HIDE) && (mLayer.GetParent()) )
549 Self().Remove(mLayer);
550 Self().SetSensitive( false );
552 // Guard against destruction during signal emission
553 Toolkit::Popup handle( GetOwner() );
554 mHiddenSignalV2.Emit();
558 Toolkit::Popup::TouchedOutsideSignalV2& Popup::OutsideTouchedSignal()
560 return mTouchedOutsideSignalV2;
563 Toolkit::Popup::HiddenSignalV2& Popup::HiddenSignal()
565 return mHiddenSignalV2;
568 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
570 Dali::BaseHandle handle( object );
572 bool connected( true );
573 Toolkit::Popup popup = Toolkit::Popup::DownCast(handle);
575 if( Dali::Toolkit::Popup::SIGNAL_TOUCHED_OUTSIDE == signalName )
577 popup.OutsideTouchedSignal().Connect( tracker, functor );
579 else if( Dali::Toolkit::Popup::SIGNAL_HIDDEN == signalName )
581 popup.HiddenSignal().Connect( tracker, functor );
585 // signalName does not match any signal
592 void Popup::OnStateAnimationFinished( Animation& source )
594 HandleStateChangeComplete();
597 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
599 if(event.GetPointCount()>0)
601 const TouchPoint& point = event.GetPoint(0);
603 if(point.state == TouchPoint::Down)
605 // Guard against destruction during signal emission
606 Toolkit::Popup handle( GetOwner() );
608 mTouchedOutsideSignalV2.Emit();
615 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
617 // consume mouse wheel event in dimmed backing actor
621 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
623 // consume event (stops backing actor receiving touch events)
627 void Popup::OnControlChildAdd( Actor& child )
629 // reparent any children added by user to the body layer.
630 if( mAlterAddedChild )
632 // Removes previously added content.
635 mPopupBg.Remove( mContent );
638 // Reparent new content.
639 Self().Remove( child );
641 // keep a handle to the new content.
644 mPopupBg.Add( mContent );
648 void Popup::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
650 // Set the popup size
652 popupSize.width = size.width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
653 popupSize.height = size.height - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
655 // Update sizes of all popup's components.
657 // Relayout background image.
658 // Adjust background position and size relative to parent to cater to outer Border.
659 // Some backgrounds are intended to over-spill. That is some content
660 // should appear outside the Dialog on all sides i.e. Shadows, glow effects.
661 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
663 if( mBackgroundImage )
665 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
666 ParentSource( Actor::SIZE ),
667 BackgroundSizeConstraint(outerBorder) );
669 mBackgroundImage.RemoveConstraints();
670 mBackgroundImage.ApplyConstraint( constraint );
672 mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
673 mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
674 mBackgroundImage.SetPosition( -outerBorder.x, -outerBorder.y, 0.0f );
677 if( mPopupBg && mButtonAreaImage )
679 // If there are no buttons, button background is also removed.
680 if ( mButtons.size() == 0 )
682 mPopupBg.Remove( mButtonAreaImage );
686 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
687 ParentSource( Actor::SIZE ),
688 ButtonAreaSizeConstraint(outerBorder) );
690 mButtonAreaImage.RemoveConstraints();
691 mButtonAreaImage.ApplyConstraint( constraint );
693 mButtonAreaImage.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
694 mButtonAreaImage.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
695 mButtonAreaImage.SetY( -outerBorder.z - POPUP_OUT_MARGIN_HEIGHT );
697 mPopupBg.Add( mButtonAreaImage );
702 Vector3 positionOffset( 0.0f, mPopupStyle->margin + POPUP_OUT_MARGIN_WIDTH, CONTENT_DEPTH );
708 // If the content width is greater than popup width then scale it down/wrap text as needed
709 Vector2 contentSize( RelayoutHelper::GetNaturalSize( mContent ) );
710 if( contentSize.width > popupSize.width )
712 contentSize.width = popupSize.width;
713 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, contentSize.width );
716 mContent.SetSize( contentSize );
717 Relayout( mContent, contentSize, container );
719 mContent.SetParentOrigin(ParentOrigin::TOP_CENTER);
720 mContent.SetAnchorPoint(AnchorPoint::TOP_CENTER);
722 mContent.SetPosition( positionOffset );
724 positionOffset.y += contentSize.height + mPopupStyle->margin;
727 // Relayout Button Area
730 mBottomBg.SetSize( popupSize.width, mPopupStyle->bottomSize.height );
732 mBottomBg.SetParentOrigin(ParentOrigin::TOP_CENTER);
733 mBottomBg.SetAnchorPoint(AnchorPoint::TOP_CENTER);
735 mBottomBg.SetPosition( positionOffset );
738 // Relayout All buttons
739 if ( !mButtons.empty() )
741 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
742 Vector2 buttonSize( ( ( popupSize.width - mPopupStyle->buttonSpacing * ( mButtons.size() - 1 ) ) / mButtons.size() ),
743 mPopupStyle->bottomSize.height - mPopupStyle->margin );
745 Vector3 buttonPosition;
747 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
749 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
751 iter->SetPosition( buttonPosition );
753 // If there is only one button, it needs to be laid out on center.
754 if ( mButtons.size() == 1 )
756 iter->SetAnchorPoint( AnchorPoint::CENTER );
757 iter->SetParentOrigin( ParentOrigin::CENTER );
761 iter->SetAnchorPoint( AnchorPoint::CENTER_LEFT );
762 iter->SetParentOrigin( ParentOrigin::CENTER_LEFT );
765 Relayout( *iter, buttonSize, container );
769 if( mShowing && mBacking )
771 Vector2 stageSize = Stage::GetCurrent().GetSize();
772 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
773 Vector3 targetBackingSize = Vector3( length, length, 1.0f );
775 mBacking.SetSize( targetBackingSize );
779 bool Popup::OnKeyEvent(const KeyEvent& event)
781 bool consumed = false;
783 if(event.state == KeyEvent::Down)
785 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
787 SetState(Toolkit::Popup::POPUP_HIDE);
795 Vector3 Popup::GetNaturalSize()
797 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
799 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
803 Vector3 contentSize = RelayoutHelper::GetNaturalSize( mContent );
804 // Choose the biggest width
805 naturalSize.width = std::max( naturalSize.width, contentSize.width );
806 naturalSize.height += contentSize.height + mPopupStyle->margin;
809 if( !mButtons.empty() )
811 naturalSize.height += mPopupStyle->bottomSize.height;
815 naturalSize.width += margin;
816 naturalSize.height += margin;
821 float Popup::GetHeightForWidth( float width )
823 float height( 0.0f );
824 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
828 height += RelayoutHelper::GetHeightForWidth( mContent, popupWidth ) + mPopupStyle->margin;
831 if( !mButtons.empty() )
833 height += mPopupStyle->bottomSize.height;
837 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
843 float Popup::GetWidthForHeight( float height )
845 return GetNaturalSize().width;
848 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
850 Actor nextFocusableActor( currentFocusedActor );
852 // TODO: Needs to be optimised
854 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
856 // The current focused actor is not within popup
857 if( mContent && mContent.IsKeyboardFocusable() )
859 // If content is focusable, move the focus to content
860 nextFocusableActor = mContent;
862 else if( !mButtons.empty() )
864 // Otherwise, movethe focus to the first button
865 nextFocusableActor = mButtons[0];
870 // Rebuild the focus chain because button or content can be added or removed dynamically
871 ActorContainer focusableActors;
872 if( mContent && mContent.IsKeyboardFocusable() )
874 focusableActors.push_back(mContent);
877 for(unsigned int i = 0; i < mButtons.size(); i++)
879 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
881 focusableActors.push_back(mButtons[i]);
885 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
887 if ( currentFocusedActor == *iter )
891 case Toolkit::Control::Left:
893 if ( iter == focusableActors.begin() )
895 nextFocusableActor = *( focusableActors.end() - 1 );
899 nextFocusableActor = *( iter - 1 );
903 case Toolkit::Control::Right:
905 if ( iter == focusableActors.end() - 1 )
907 nextFocusableActor = *( focusableActors.begin() );
911 nextFocusableActor = *( iter + 1 );
916 case Toolkit::Control::Up:
918 if ( *iter == mContent )
920 nextFocusableActor = *( focusableActors.end() - 1 );
924 if ( mContent && mContent.IsKeyboardFocusable() )
926 nextFocusableActor = mContent;
930 if ( iter == focusableActors.begin() )
932 nextFocusableActor = *( focusableActors.end() - 1 );
936 nextFocusableActor = *( iter - 1 );
943 case Toolkit::Control::Down:
945 if ( mContent && mContent.IsKeyboardFocusable() )
947 nextFocusableActor = mContent;
951 if ( iter == focusableActors.end() - 1 )
953 nextFocusableActor = *( focusableActors.begin() );
957 nextFocusableActor = *( iter + 1 );
961 if ( *iter == mContent && !mButtons.empty() )
963 nextFocusableActor = mButtons[0];
969 if(!nextFocusableActor)
971 DALI_LOG_WARNING("Can not decide next focusable actor\n");
979 return nextFocusableActor;
982 } // namespace Internal
984 } // namespace Toolkit