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);
56 const char* const PROPERTY_TITLE = "title";
57 const char* const PROPERTY_STATE = "state";
60 * The background size should be at least as big as the Dialog.
61 * In some cases a background may have graphics which are visible
62 * outside of the Dialog, e.g. A Shadow. For this we need to alter
63 * the size of Background.
65 * @param[in] outerBorder The border to extend beyond parent's Size.
66 * @param[in] parentSize The parent's size
68 Vector3 BackgroundSize(const Vector4& outerBoarder, const Vector3& parentSize)
70 Vector3 size( parentSize );
71 size.width += outerBoarder.x + outerBoarder.y;
72 size.height += outerBoarder.z + outerBoarder.w;
78 * sets button area size to parent's size plus a border.
80 * @param[in] outerBorder The border to extend beyond parent's Size.
81 * @param[in] parentSize The parent's size
83 Vector3 ButtonAreaSize( const Vector4& outBoarder, const Vector3& parentSize )
85 Vector3 size( parentSize );
86 size.width += outBoarder.x + outBoarder.y;
87 size.width -= (POPUP_OUT_MARGIN_WIDTH + POPUP_OUT_MARGIN_WIDTH);
88 size.height = POPUP_BUTTON_BG_HEIGHT;
93 } // unnamed namespace
109 return Toolkit::Popup::New();
112 TypeRegistration typeRegistration( typeid(Toolkit::Popup), typeid(Toolkit::Control), Create );
114 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Popup::SIGNAL_TOUCHED_OUTSIDE, &Popup::DoConnectSignal );
115 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Popup::SIGNAL_HIDDEN, &Popup::DoConnectSignal );
121 ///////////////////////////////////////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////////////////////////////////////
125 Dali::Toolkit::Popup Popup::New()
127 PopupStylePtr style = PopupStyleDefault::New();
129 // Create the implementation
130 PopupPtr popup(new Popup(*style));
132 // Pass ownership to CustomActor via derived handle
133 Dali::Toolkit::Popup handle(*popup);
135 // Second-phase init of the implementation
136 // This can only be done after the CustomActor connection has been made...
142 Popup::Popup(PopupStyle& style)
143 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
145 mState(Toolkit::Popup::POPUP_NONE), // Initially, the popup state should not be set, it's set in OnInitialize
146 mAlterAddedChild(false),
147 mPopupStyle(PopupStylePtr(&style)),
148 mPropertyTitle(Property::INVALID_INDEX),
149 mPropertyState(Property::INVALID_INDEX)
151 SetKeyboardNavigationSupport( true );
154 void Popup::OnInitialize()
157 self.SetSensitive(false);
160 mLayer = Layer::New();
161 mLayer.SetParentOrigin(ParentOrigin::CENTER);
162 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
166 mPopupBg = Actor::New();
167 mPopupBg.SetParentOrigin(ParentOrigin::CENTER);
168 mPopupBg.SetAnchorPoint(AnchorPoint::CENTER);
169 mLayer.Add(mPopupBg);
171 // Any content after this point which is added to Self() will be reparented to
173 mAlterAddedChild = true;
175 // Add Backing (Dim effect)
178 // Add Dialog ( background image, title, content container, button container and tail )
182 ShowTail(ParentOrigin::BOTTOM_CENTER);
184 // Hide content by default.
185 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
187 mPropertyTitle = self.RegisterProperty( PROPERTY_TITLE, "", Property::READ_WRITE );
188 mPropertyState = self.RegisterProperty( PROPERTY_STATE, "POPUP_HIDE", Property::READ_WRITE );
190 // Make self as keyboard focusable and focus group
191 self.SetKeyboardFocusable(true);
192 SetAsKeyboardFocusGroup(true);
195 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
197 if( index == mPropertyTitle )
199 SetTitle(propertyValue.Get<std::string>());
201 else if ( index == mPropertyState )
203 std::string value( propertyValue.Get<std::string>() );
204 if(value == "POPUP_SHOW")
206 SetState( Toolkit::Popup::POPUP_SHOW, 0.0f );
208 else if( value == "POPUP_HIDE")
210 SetState( Toolkit::Popup::POPUP_HIDE, 0.0f );
219 size_t Popup::GetButtonCount() const
221 return mButtons.size();
224 void Popup::SetBackgroundImage( Actor image )
226 // Removes any previous background.
227 if( mBackgroundImage && mPopupBg )
229 mPopupBg.Remove( mBackgroundImage );
232 // Adds new background to the dialog.
233 mBackgroundImage = image;
235 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
236 mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
238 mPopupBg.Add( mBackgroundImage );
241 void Popup::SetButtonAreaImage( Actor image )
243 // Removes any previous area image.
244 if( mButtonAreaImage && mPopupBg )
246 mPopupBg.Remove( mButtonAreaImage );
249 // Adds new area image to the dialog.
250 mButtonAreaImage = image;
252 // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
253 mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
255 mPopupBg.Add( mButtonAreaImage );
258 void Popup::SetTitle( const std::string& text )
260 Toolkit::TextView titleActor = Toolkit::TextView::New();
261 titleActor.SetText( text );
262 titleActor.SetColor( Color::BLACK );
263 titleActor.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
264 titleActor.SetWidthExceedPolicy( Toolkit::TextView::Split );
265 titleActor.SetLineJustification( Toolkit::TextView::Center );
267 SetTitle( titleActor );
270 void Popup::SetTitle( Toolkit::TextView titleActor )
272 // Replaces the current title actor.
273 if( mTitle && mPopupBg )
275 mPopupBg.Remove( mTitle );
279 mPopupBg.Add( mTitle );
284 Toolkit::TextView Popup::GetTitle() const
289 void Popup::AddButton( Toolkit::Button button )
291 mButtons.push_back( button );
292 mBottomBg.Add( button );
297 void Popup::SetState( Toolkit::Popup::PopupState state )
299 SetState( state, POPUP_ANIMATION_DURATION );
302 void Popup::SetState( Toolkit::Popup::PopupState state, float duration )
304 // default animation behaviour.
305 HandleStateChange(state, duration);
308 Toolkit::Popup::PopupState Popup::GetState() const
313 void Popup::ShowTail(const Vector3& position)
315 // Replaces the tail actor.
316 if(mTailImage && mTailImage.GetParent())
318 mTailImage.GetParent().Remove( mTailImage );
322 std::string image = "";
324 // depending on position of tail around ParentOrigin, a different tail image is used...
325 if(position.y < Math::MACHINE_EPSILON_1)
327 image = mPopupStyle->tailUpImage;
329 else if(position.y > 1.0f - Math::MACHINE_EPSILON_1)
331 image = mPopupStyle->tailDownImage;
333 else if(position.x < Math::MACHINE_EPSILON_1)
335 image = mPopupStyle->tailLeftImage;
337 else if(position.x > 1.0f - Math::MACHINE_EPSILON_1)
339 image = mPopupStyle->tailRightImage;
344 Image tail = ResourceImage::New( image );
345 mTailImage = ImageActor::New(tail);
346 const Vector3 anchorPoint = AnchorPoint::FRONT_BOTTOM_RIGHT - position;
348 mTailImage.SetParentOrigin(position);
349 mTailImage.SetAnchorPoint(anchorPoint);
351 mBottomBg.Add(mTailImage);
355 void Popup::HideTail()
357 ShowTail(ParentOrigin::CENTER);
360 void Popup::SetStyle(PopupStyle& style)
362 mPopupStyle = PopupStylePtr(&style);
366 PopupStylePtr Popup::GetStyle() const
371 void Popup::SetDefaultBackgroundImage()
373 Image bg = ResourceImage::New( mPopupStyle->backgroundImage );
374 ImageActor bgImage = ImageActor::New( bg );
375 bgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
376 bgImage.SetNinePatchBorder( mPopupStyle->backgroundScale9Border );
378 Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage );
379 ImageActor buttonBgImage = ImageActor::New( buttonBg );
380 buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH );
381 buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder );
383 SetBackgroundImage( bgImage );
384 SetButtonAreaImage( buttonBgImage );
387 void Popup::CreateBacking()
389 mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
391 mBacking.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
392 mBacking.SetSensitive(true);
394 mLayer.Add(mBacking);
395 mBacking.SetOpacity(0.0f);
396 mBacking.SetPosition(0.0f, 0.0f, BACKING_DEPTH);
397 mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
398 mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
401 void Popup::CreateDialog()
403 // Adds default background image.
404 SetDefaultBackgroundImage();
406 // Adds bottom background
407 mBottomBg = Actor::New();
408 mPopupBg.Add( mBottomBg );
411 void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration )
413 const Vector2& stageSize( Stage::GetCurrent().GetSize() );
416 float targetBackingAlpha;
417 Vector3 targetBackingSize;
426 case Toolkit::Popup::POPUP_HIDE:
428 targetSize = Vector3(0.0f, 0.0f, 1.0f);
429 targetBackingAlpha = 0.0f;
430 targetBackingSize = Vector3(0.0f, 0.0f, 1.0f);
432 ClearKeyInputFocus();
434 // Retore the keyboard focus when popup is hidden
435 if(mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
437 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
438 if( keyboardFocusManager )
440 keyboardFocusManager.SetCurrentFocusActor(mPreviousFocusedActor);
447 case Toolkit::Popup::POPUP_SHOW:
450 targetSize = Vector3(1.0f, 1.0f, 1.0f);
451 targetBackingAlpha = 1.0f;
452 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
453 targetBackingSize = Vector3( length, length, 1.0f );
456 // Add contents to stage for showing.
457 if( !mLayer.GetParent() )
459 mAlterAddedChild = false;
461 mAlterAddedChild = true;
463 Self().SetSensitive(true);
466 // Handle the keyboard focus when popup is shown
467 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
468 if( keyboardFocusManager )
470 mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
472 if( mContent && mContent.IsKeyboardFocusable() )
474 // If content is focusable, move the focus to content
475 keyboardFocusManager.SetCurrentFocusActor(mContent);
477 else if( !mButtons.empty() )
479 // Otherwise, movethe focus to the first button
480 keyboardFocusManager.SetCurrentFocusActor(mButtons[0]);
484 DALI_LOG_WARNING("There is no focusable in popup\n");
491 mBacking.SetSize( targetBackingSize );
493 if(duration > Math::MACHINE_EPSILON_1)
501 mAnimation = Animation::New(duration);
505 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
506 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
510 mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
511 mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
514 mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
518 mBacking.SetOpacity( targetBackingAlpha );
519 mPopupBg.SetScale( targetSize );
521 HandleStateChangeComplete();
525 void Popup::HandleStateChangeComplete()
527 // Remove contents from stage if completely hidden.
528 if( (mState == Toolkit::Popup::POPUP_HIDE) && (mLayer.GetParent()) )
530 Self().Remove(mLayer);
531 Self().SetSensitive( false );
533 // Guard against destruction during signal emission
534 Toolkit::Popup handle( GetOwner() );
535 mHiddenSignal.Emit();
539 Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
541 return mTouchedOutsideSignal;
544 Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal()
546 return mHiddenSignal;
549 bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
551 Dali::BaseHandle handle( object );
553 bool connected( true );
554 Toolkit::Popup popup = Toolkit::Popup::DownCast(handle);
556 if( Dali::Toolkit::Popup::SIGNAL_TOUCHED_OUTSIDE == signalName )
558 popup.OutsideTouchedSignal().Connect( tracker, functor );
560 else if( Dali::Toolkit::Popup::SIGNAL_HIDDEN == signalName )
562 popup.HiddenSignal().Connect( tracker, functor );
566 // signalName does not match any signal
573 void Popup::OnStateAnimationFinished( Animation& source )
575 HandleStateChangeComplete();
578 bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
580 if(event.GetPointCount()>0)
582 const TouchPoint& point = event.GetPoint(0);
584 if(point.state == TouchPoint::Down)
586 // Guard against destruction during signal emission
587 Toolkit::Popup handle( GetOwner() );
589 mTouchedOutsideSignal.Emit();
596 bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
598 // consume mouse wheel event in dimmed backing actor
602 bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
604 // consume event (stops backing actor receiving touch events)
608 void Popup::OnControlChildAdd( Actor& child )
610 // reparent any children added by user to the body layer.
611 if( mAlterAddedChild )
613 // Removes previously added content.
616 mPopupBg.Remove( mContent );
619 // Reparent new content.
620 Self().Remove( child );
622 // keep a handle to the new content.
625 mPopupBg.Add( mContent );
629 void Popup::OnControlSizeSet( const Vector3& targetSize )
631 mLayer.SetSize( targetSize );
632 mPopupBg.SetSize( targetSize );
634 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
635 if( mBackgroundImage )
637 mBackgroundImage.SetSize( BackgroundSize( outerBorder,targetSize ) );
639 if( mButtonAreaImage )
641 mButtonAreaImage.SetSize( ButtonAreaSize( outerBorder, targetSize ) );
646 void Popup::OnRelayout( const Vector2& size, ActorSizeContainer& container )
648 // Set the popup size
650 popupSize.width = size.width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
651 popupSize.height = size.height - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
653 // Update sizes of all popup's components.
655 // Relayout background image.
656 // Adjust background position and size relative to parent to cater to outer Border.
657 // Some backgrounds are intended to over-spill. That is some content
658 // should appear outside the Dialog on all sides i.e. Shadows, glow effects.
659 const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder;
661 if( mBackgroundImage )
663 mBackgroundImage.SetSize(BackgroundSize(outerBorder, Vector3(size)));
664 mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
665 mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
666 mBackgroundImage.SetPosition( -outerBorder.x, -outerBorder.y, 0.0f );
669 if( mPopupBg && mButtonAreaImage )
671 // If there are no buttons, button background is also removed.
672 if ( mButtons.size() == 0 )
674 mPopupBg.Remove( mButtonAreaImage );
678 mButtonAreaImage.SetSize( ButtonAreaSize(outerBorder, Vector3(size)) );
679 mButtonAreaImage.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
680 mButtonAreaImage.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
681 mButtonAreaImage.SetY( -outerBorder.z - POPUP_OUT_MARGIN_HEIGHT );
683 mPopupBg.Add( mButtonAreaImage );
688 Vector3 positionOffset( 0.0f, mPopupStyle->margin + POPUP_OUT_MARGIN_WIDTH, CONTENT_DEPTH );
692 titleSize.width = popupSize.width;
693 titleSize.height = mTitle.GetHeightForWidth( titleSize.width );
695 // As the default size policy for text-view is Fixed & Fixed, a size needs to be set.
696 // Otherwise size-negotiation algorithm uses the GetNaturalSize() with doesn't take
697 // into account the multiline and exceed policies, giving as result a wrong size.
698 mTitle.SetSize( titleSize );
699 Relayout( mTitle, titleSize, container );
701 mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
702 mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER );
703 mTitle.SetPosition( positionOffset );
705 positionOffset.y += titleSize.height + mPopupStyle->margin;
711 // If the content width is greater than popup width then scale it down/wrap text as needed
712 Vector2 contentSize( RelayoutHelper::GetNaturalSize( mContent ) );
713 if( contentSize.width > popupSize.width )
715 contentSize.width = popupSize.width;
716 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, contentSize.width );
719 mContent.SetSize( contentSize );
720 Relayout( mContent, contentSize, container );
722 mContent.SetParentOrigin(ParentOrigin::TOP_CENTER);
723 mContent.SetAnchorPoint(AnchorPoint::TOP_CENTER);
725 mContent.SetPosition( positionOffset );
727 positionOffset.y += contentSize.height + mPopupStyle->margin;
730 // Relayout Button Area
733 mBottomBg.SetSize( popupSize.width, mPopupStyle->bottomSize.height );
735 mBottomBg.SetParentOrigin(ParentOrigin::TOP_CENTER);
736 mBottomBg.SetAnchorPoint(AnchorPoint::TOP_CENTER);
738 mBottomBg.SetPosition( positionOffset );
741 // Relayout All buttons
742 if ( !mButtons.empty() )
744 // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
745 Vector2 buttonSize( ( ( popupSize.width - mPopupStyle->buttonSpacing * ( mButtons.size() - 1 ) ) / mButtons.size() ),
746 mPopupStyle->bottomSize.height - mPopupStyle->margin );
748 Vector3 buttonPosition;
750 for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
752 ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
754 iter->SetPosition( buttonPosition );
756 // If there is only one button, it needs to be laid out on center.
757 if ( mButtons.size() == 1 )
759 iter->SetAnchorPoint( AnchorPoint::CENTER );
760 iter->SetParentOrigin( ParentOrigin::CENTER );
764 iter->SetAnchorPoint( AnchorPoint::CENTER_LEFT );
765 iter->SetParentOrigin( ParentOrigin::CENTER_LEFT );
768 Relayout( *iter, buttonSize, container );
772 if( mShowing && mBacking )
774 Vector2 stageSize = Stage::GetCurrent().GetSize();
775 float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height;
776 Vector3 targetBackingSize = Vector3( length, length, 1.0f );
778 mBacking.SetSize( targetBackingSize );
782 bool Popup::OnKeyEvent(const KeyEvent& event)
784 bool consumed = false;
786 if(event.state == KeyEvent::Down)
788 if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
790 SetState(Toolkit::Popup::POPUP_HIDE);
798 Vector3 Popup::GetNaturalSize()
800 float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin );
801 const float maxWidth = Stage::GetCurrent().GetSize().width - margin;
803 Vector3 naturalSize( 0.0f, 0.0f, 0.0f );
807 Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize();
808 // Buffer to avoid errors. The width of the popup could potentially be the width of the title text.
809 // It was observed in this case that text wrapping was then inconsistent when seen on device
810 const float titleBuffer = 0.5f;
811 titleNaturalSize.width += titleBuffer;
813 // As TextView GetNaturalSize does not take wrapping into account, limit the width
814 // to that of the stage
815 if( titleNaturalSize.width >= maxWidth)
817 naturalSize.width = maxWidth;
818 naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width );
822 naturalSize += titleNaturalSize;
825 naturalSize.height += mPopupStyle->margin;
830 Vector3 contentSize = RelayoutHelper::GetNaturalSize( mContent );
831 // Choose the biggest width
832 naturalSize.width = std::max( naturalSize.width, contentSize.width );
833 if( naturalSize.width > maxWidth )
835 naturalSize.width = maxWidth;
836 contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, maxWidth );
838 naturalSize.height += contentSize.height + mPopupStyle->margin;
841 if( !mButtons.empty() )
843 naturalSize.height += mPopupStyle->bottomSize.height;
847 naturalSize.width += margin;
848 naturalSize.height += margin;
853 float Popup::GetHeightForWidth( float width )
855 float height( 0.0f );
856 float popupWidth( width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
860 height += mTitle.GetImplementation().GetHeightForWidth( popupWidth );
861 height += mPopupStyle->margin;
866 height += RelayoutHelper::GetHeightForWidth( mContent, popupWidth ) + mPopupStyle->margin;
869 if( !mButtons.empty() )
871 height += mPopupStyle->bottomSize.height;
875 float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) );
881 float Popup::GetWidthForHeight( float height )
883 return GetNaturalSize().width;
886 Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
888 Actor nextFocusableActor( currentFocusedActor );
890 // TODO: Needs to be optimised
892 if ( !currentFocusedActor || ( currentFocusedActor && KeyboardFocusManager::Get().GetFocusGroup(currentFocusedActor) != Self() ) )
894 // The current focused actor is not within popup
895 if( mContent && mContent.IsKeyboardFocusable() )
897 // If content is focusable, move the focus to content
898 nextFocusableActor = mContent;
900 else if( !mButtons.empty() )
902 // Otherwise, movethe focus to the first button
903 nextFocusableActor = mButtons[0];
908 // Rebuild the focus chain because button or content can be added or removed dynamically
909 ActorContainer focusableActors;
910 if( mContent && mContent.IsKeyboardFocusable() )
912 focusableActors.push_back(mContent);
915 for(unsigned int i = 0; i < mButtons.size(); i++)
917 if( mButtons[i] && mButtons[i].IsKeyboardFocusable() )
919 focusableActors.push_back(mButtons[i]);
923 for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
925 if ( currentFocusedActor == *iter )
929 case Toolkit::Control::Left:
931 if ( iter == focusableActors.begin() )
933 nextFocusableActor = *( focusableActors.end() - 1 );
937 nextFocusableActor = *( iter - 1 );
941 case Toolkit::Control::Right:
943 if ( iter == focusableActors.end() - 1 )
945 nextFocusableActor = *( focusableActors.begin() );
949 nextFocusableActor = *( iter + 1 );
954 case Toolkit::Control::Up:
956 if ( *iter == mContent )
958 nextFocusableActor = *( focusableActors.end() - 1 );
962 if ( mContent && mContent.IsKeyboardFocusable() )
964 nextFocusableActor = mContent;
968 if ( iter == focusableActors.begin() )
970 nextFocusableActor = *( focusableActors.end() - 1 );
974 nextFocusableActor = *( iter - 1 );
981 case Toolkit::Control::Down:
983 if ( mContent && mContent.IsKeyboardFocusable() )
985 nextFocusableActor = mContent;
989 if ( iter == focusableActors.end() - 1 )
991 nextFocusableActor = *( focusableActors.begin() );
995 nextFocusableActor = *( iter + 1 );
999 if ( *iter == mContent && !mButtons.empty() )
1001 nextFocusableActor = mButtons[0];
1007 if(!nextFocusableActor)
1009 DALI_LOG_WARNING("Can not decide next focusable actor\n");
1017 return nextFocusableActor;
1020 } // namespace Internal
1022 } // namespace Toolkit