From: Kimmo Hoikka Date: Mon, 18 May 2015 17:04:43 +0000 (+0100) Subject: Cleaning up size negotiation X-Git-Tag: accepted/tizen/common/20150529.134100~26 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=f17aee578d095c3a7c53355fbff3259070883de3 Cleaning up size negotiation - Remove unnecassary data from control - Make control use its background for natural size - Use base helpers for width for height and height for width Change-Id: I690406eac2e51ca696e61d23d7117aaef10b3022 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Alignment.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Alignment.cpp index 0f62a2a..2d9d8cc 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Alignment.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Alignment.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -924,7 +924,7 @@ int UtcDaliAlignmentChildAddAndRemove(void) END_TEST; } -int UtcDaliAlignmentOnSizeSet(void) +int UtcDaliAlignmentSizeSetP(void) { ToolkitTestApplication application; @@ -942,7 +942,7 @@ int UtcDaliAlignmentOnSizeSet(void) application.Render(); application.SendNotification(); - DALI_TEST_EQUALS(size, alignment.GetImplementation().GetControlSize().GetVectorXY(), TEST_LOCATION); + DALI_TEST_EQUALS(size, alignment.GetTargetSize().GetVectorXY(), TEST_LOCATION); Stage::GetCurrent().Remove(alignment); END_TEST; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 17e8456..47a13ec 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -345,7 +345,8 @@ int UtcDaliControlTestParameters(void) float width = 640.0f; float height = test.GetHeightForWidth( width ); - DALI_TEST_CHECK( test.GetWidthForHeight( height ) == width ); + DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION ); + DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION ); test.KeyEventSignal(); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp index 8f363af..49a9b0b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -437,7 +437,7 @@ int UtcDaliControlImplStageConnection(void) END_TEST; } -int UtcDaliControlImplSizeSet(void) +int UtcDaliControlImplSizeSetP(void) { ToolkitTestApplication application; @@ -449,22 +449,28 @@ int UtcDaliControlImplSizeSet(void) application.Render(); application.SendNotification(); - DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, true, TEST_LOCATION ); // Called from size negotiation + DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, false, TEST_LOCATION ); // Size not set, no onSizeSet called Vector2 size(100.0f, 200.0f); - dummy.SetSize(size); + dummy.SetSize( size ); + + DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, false, TEST_LOCATION ); // Size is going to get negotiated, no onSizeSet called - application.Render(); application.SendNotification(); application.Render(); - application.SendNotification(); - DALI_TEST_EQUALS(size, dummy.GetCurrentSize().GetVectorXY(), TEST_LOCATION); + DALI_TEST_EQUALS( size, dummy.GetCurrentSize().GetVectorXY(), TEST_LOCATION ); DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, true, TEST_LOCATION ); Stage::GetCurrent().Remove(dummy); } - // Ensure full code coverage + END_TEST; +} + +int UtcDaliControlImplSizeSet2P(void) +{ + ToolkitTestApplication application; + { DummyControl dummy = DummyControl::New(); Stage::GetCurrent().Add(dummy); @@ -472,15 +478,13 @@ int UtcDaliControlImplSizeSet(void) Vector2 size(100.0f, 200.0f); DALI_TEST_CHECK( size != dummy.GetCurrentSize().GetVectorXY() ); - application.Render(); application.SendNotification(); + application.Render(); dummy.SetSize(size); - application.Render(); application.SendNotification(); application.Render(); - application.SendNotification(); DALI_TEST_EQUALS(size, dummy.GetCurrentSize().GetVectorXY(), TEST_LOCATION); @@ -489,6 +493,7 @@ int UtcDaliControlImplSizeSet(void) END_TEST; } + int UtcDaliControlImplSizeAnimation(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp index 0f5400a..b55b757 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -455,8 +455,6 @@ void PageTurnView::OnControlStageDisconnection() void PageTurnView::OnControlSizeSet( const Vector3& size ) { - // disable the SetSize of the control from the application - Self().SetSize( mControlSize ); } void PageTurnView::SetSpineShadowParameter( const Vector2& spineShadowParameter ) diff --git a/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp b/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp index 4c2770b..7ff84ab 100644 --- a/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp +++ b/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -654,8 +654,7 @@ void ScrollView::OnInitialize() self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, mCanScrollVertical); self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL, mCanScrollHorizontal); - Vector3 size = GetControlSize(); - UpdatePropertyDomain(size); + UpdatePropertyDomain(); SetInternalConstraints(); } @@ -813,8 +812,7 @@ void ScrollView::SetRulerX(RulerPtr ruler) { mRulerX = ruler; - Vector3 size = GetControlSize(); - UpdatePropertyDomain(size); + UpdatePropertyDomain(); UpdateMainInternalConstraint(); } @@ -822,14 +820,14 @@ void ScrollView::SetRulerY(RulerPtr ruler) { mRulerY = ruler; - Vector3 size = GetControlSize(); - UpdatePropertyDomain(size); + UpdatePropertyDomain(); UpdateMainInternalConstraint(); } -void ScrollView::UpdatePropertyDomain(const Vector3& size) +void ScrollView::UpdatePropertyDomain() { Actor self = Self(); + Vector3 size = self.GetTargetSize(); Vector2 min = mMinScroll; Vector2 max = mMaxScroll; bool scrollPositionChanged = false; @@ -1872,7 +1870,7 @@ bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface void ScrollView::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { // need to update domain properties for new size - UpdatePropertyDomain(targetSize); + UpdatePropertyDomain(); } void ScrollView::OnControlSizeSet( const Vector3& size ) @@ -1887,7 +1885,7 @@ void ScrollView::OnControlSizeSet( const Vector3& size ) mMaxOvershoot = mUserMaxOvershoot; } } - UpdatePropertyDomain(size); + UpdatePropertyDomain(); UpdateMainInternalConstraint(); if( IsOvershootEnabled() ) { diff --git a/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h b/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h index aa9073f..eb45876 100644 --- a/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h +++ b/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -660,10 +660,8 @@ private: * This is called internally whenever the Scroll Rulers are * modified. This will update the properties: 'scroll-position-min' * and 'scroll-position-max' to reflect the changes. - * - * @param[in] size size of the visible scroll area (ScrollView control size) */ - void UpdatePropertyDomain(const Vector3& size); + void UpdatePropertyDomain(); /** * Called when the gesture starts. diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 2e8570f..7329790 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -754,7 +754,7 @@ struct Decorator::Impl : public ConnectionTracker mHandleScrolling = type; StartScrollTimer(); } - else if( x > mTextControlParent.GetControlSize().width - mScrollThreshold ) + else if( x > mTextControlParent.Self().GetTargetSize().width - mScrollThreshold ) { mScrollDirection = SCROLL_LEFT; mHandleScrolling = type; diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index ff0a2bc..11347da 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -49,12 +49,6 @@ namespace Toolkit namespace { -#if defined(DEBUG_ENABLED) -Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL"); -#endif - -const float MAX_FLOAT_VALUE( std::numeric_limits::max() ); -const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ); const float BACKGROUND_ACTOR_Z_POSITION( -0.1f ); BaseHandle Create() @@ -173,16 +167,6 @@ class Control::Impl : public ConnectionTracker { public: - /** - * Size indices for mMinMaxSize array - */ - enum - { - MIN_SIZE_INDEX = 0, - MAX_SIZE_INDEX = 1 - }; - -public: // Construction & Destruction Impl(Control& controlImpl) : mControlImpl( controlImpl ), @@ -194,8 +178,6 @@ public: mPanGestureDetector(), mTapGestureDetector(), mLongPressGestureDetector(), - mCurrentSize(), - mNaturalSize(), mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), mIsKeyboardNavigationSupported( false ), mIsKeyboardFocusGroup( false ), @@ -390,9 +372,6 @@ public: PanGestureDetector mPanGestureDetector; TapGestureDetector mTapGestureDetector; LongPressGestureDetector mLongPressGestureDetector; - // @todo change all these to Vector2 when we have a chance to sanitize the public API as well - Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size - Vector3 mNaturalSize; ///< Stores the size set through the Actor's API. This is size the actor wants to be. Useful when reset to the initial size is needed. ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor. bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control. @@ -434,51 +413,41 @@ Control::~Control() Vector3 Control::GetNaturalSize() { - // could be overridden in derived classes. - return mImpl->mNaturalSize; -} - -float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) -{ - // Could be overridden in derived classes. - return CalculateChildSizeBase( child, dimension ); -} - -bool Control::RelayoutDependentOnChildren( Dimension::Type dimension ) -{ - return RelayoutDependentOnChildrenBase( dimension ); + if( mImpl->mBackground ) + { + Actor actor = mImpl->mBackground->actor; + if( actor ) + { + return actor.GetNaturalSize(); + } + } + return Vector3(); } float Control::GetHeightForWidth( float width ) { - // could be overridden in derived classes. - float height( 0.0f ); - if ( mImpl->mNaturalSize.width > 0.0f ) + if( mImpl->mBackground ) { - height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width; + Actor actor = mImpl->mBackground->actor; + if( actor ) + { + return actor.GetHeightForWidth( width ); + } } - return height; + return GetHeightForWidthBase( width ); } float Control::GetWidthForHeight( float height ) { - // could be overridden in derived classes. - float width( 0.0f ); - if ( mImpl->mNaturalSize.height > 0.0f ) + if( mImpl->mBackground ) { - width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height; + Actor actor = mImpl->mBackground->actor; + if( actor ) + { + return actor.GetWidthForHeight( height ); + } } - return width; -} - -const Vector3& Control::GetControlSize() const -{ - return mImpl->mCurrentSize; -} - -const Vector3& Control::GetSizeSet() const -{ - return mImpl->mNaturalSize; + return GetWidthForHeightBase( height ); } void Control::SetKeyInputFocus() @@ -951,6 +920,16 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime { } +float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) +{ + return CalculateChildSizeBase( child, dimension ); +} + +bool Control::RelayoutDependentOnChildren( Dimension::Type dimension ) +{ + return RelayoutDependentOnChildrenBase( dimension ); +} + void Control::EmitKeyInputFocusSignal( bool focusGained ) { Dali::Toolkit::Control handle( GetOwner() ); @@ -1046,20 +1025,10 @@ void Control::OnChildRemove(Actor& child) void Control::OnSizeSet(const Vector3& targetSize) { - if( targetSize != mImpl->mNaturalSize ) - { - // Only updates size if set through Actor's API - mImpl->mNaturalSize = targetSize; - } - - if( targetSize != mImpl->mCurrentSize ) - { - // Update control size. - mImpl->mCurrentSize = targetSize; + // Background is resized through size negotiation - // Notify derived classes. - OnControlSizeSet( targetSize ); - } + // Notify derived classes. + OnControlSizeSet( targetSize ); } void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback ) diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index 1cbf04f..249fed5 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -85,24 +85,10 @@ public: virtual float GetWidthForHeight( float height ); /** - * @copydoc Toolkit::Control::GetNaturalSize() + * @copydoc Toolkit::CustomActorImpl::GetNaturalSize() */ virtual Vector3 GetNaturalSize(); - /** - * @brief Retrieves the current Control's size. - * - * @return The control's size. - */ - const Vector3& GetControlSize() const; - - /** - * @brief Retrieves the Control's size set by the Application / Control. - * - * @return The control's size. - */ - const Vector3& GetSizeSet() const; - // Key Input /** @@ -605,51 +591,22 @@ private: virtual void OnStageConnection(); /** - * @brief Calls OnControlStageDisconnection() to notify derived classed. - * - * @see Dali::CustomActorImpl::OnStageDisconnection() + * @copydoc Dali::CustomActorImpl::OnStageDisconnection() */ virtual void OnStageDisconnection(); /** - * @brief Sends a request to relayout this control. - * - * The control will be relaid out after the - * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It - * calls OnControlChildAdd() to notify derived classes. - * - * @note This method shouldn't be overridden by derived classes. - * - * @param[in] child The added actor. - * - * @see Dali::CustomActorImpl::OnChildAdd(Actor&) + * @copydoc Dali::CustomActorImpl::OnChildAdd(Actor&) */ virtual void OnChildAdd(Actor& child); /** - * @brief Sends a request to relayout this control. - * - * The control will be relaid out after the - * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It - * calls OnControlChildRemove() to notify derived classes. - * - * @note This method shouldn't be overridden by derived classes. - * - * @param[in] child The removed actor. - * - * @see Dali::CustomActorImpl::OnChildRemove(Actor&) + * @copydoc Dali::CustomActorImpl::OnChildRemove(Actor&) */ virtual void OnChildRemove(Actor& child); /** - * @brief It stores the size set by size negotiation and relayout. - * - * It also keeps a backup of the size set through the Actor's API used in the size negotiation. - * It calls the OnControlSizeSet() to notify derived classes. - * - * @param[in] targetSize The new size. - * - * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&) + * @copydoc Dali::CustomActorImpl::OnSizeSet(const Vector3&) */ virtual void OnSizeSet(const Vector3& targetSize);