--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <iostream>
+#include <stdlib.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <toolkit-event-thread-callback.h>
+
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/layouting/absolute-layout.h>
+#include <dali-toolkit/devel-api/layouting/bin-layout.h>
+#include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
+#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+#include <dali-toolkit/devel-api/layouting/linear-layout.h>
+
+#include <../custom-layout.h>
+
+#include <layout-utils.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+namespace
+{
+// Turns the given control into a Root layout control and adds it to the stage.
+void SetupRootLayoutControl( Control& rootControl )
+{
+ rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "RootAbsoluteLayout" );
+ Stage stage = Stage::GetCurrent();
+ stage.Add( rootControl );
+}
+
+void CreateDefaultBinContainer( Control& binContainer )
+{
+ binContainer = Control::New();
+ binContainer.SetName( "binContainer" );
+ DevelControl::SetLayout( binContainer, BinLayout::New() );
+ binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+}
+
+} // namespace
+
+void utc_dali_toolkit_bin_layouting_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void utc_dali_toolkit_bin_layouting_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+int UtcDaliLayouting_BinLayoutDownCast(void)
+{
+ TestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayoutDownCast - Testing Downcast");
+
+ BinLayout binLayout = BinLayout::New();
+
+ LayoutGroup layoutGroup( binLayout );
+
+ BinLayout binLayoutCandidate = BinLayout::DownCast( layoutGroup );
+ DALI_TEST_CHECK( binLayoutCandidate );
+
+ END_TEST;
+}
+
+int UtcDaliLayouting_BinLayoutAssignment(void)
+{
+ TestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayoutAssignment - Testing operator=");
+
+ BinLayout binLayout = BinLayout::New();
+ BinLayout binLayout2;
+
+ binLayout2 = binLayout;
+
+ DALI_TEST_EQUALS( binLayout2, binLayout, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLayouting_BinLayoutCopyConstructor(void)
+{
+ TestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayoutCopyConstructor - Testing copy constructor");
+
+ BinLayout binLayout1 = BinLayout::New();
+ BinLayout binLayout2( binLayout1 );
+
+ DALI_TEST_EQUALS( binLayout1, binLayout2, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliLayouting_BinLayout01(void)
+{
+ const auto NUMBER_OF_ITEMS = 4;
+
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayout01 BinLayout WRAP_CONTENT");
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
+
+ auto binContainer = Control::New();
+ auto binLayout = BinLayout::New();
+ binContainer.SetName( "BinLayout");
+ DevelControl::SetLayout( binContainer, binLayout );
+ binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
+ {
+ controls.push_back( CreateLeafControl( 100, 100 ) );
+ }
+
+ for( auto&& iter : controls )
+ {
+ binContainer.Add( iter );
+ }
+
+ rootControl.Add( binContainer );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ // Items will be laid out at the same position
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // Item sizes will not be changed
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // BinLayout size to be that of greatest child dimensions
+ DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLayouting_BinLayout02(void)
+{
+ const auto NUMBER_OF_ITEMS = 4;
+
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayout02 BinLayout MATCH_PARENT");
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
+
+ auto binContainer = Control::New();
+ auto binLayout = BinLayout::New();
+ binContainer.SetName( "BinLayout");
+ DevelControl::SetLayout( binContainer, binLayout );
+ binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
+ {
+ controls.push_back( CreateLeafControl( 100, 100 ) );
+ }
+
+ for( auto&& iter : controls )
+ {
+ binContainer.Add( iter );
+ }
+
+ rootControl.Add( binContainer );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ // Items will be laid out at the same position
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // Item sizes will not be changed
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // BinLayout size to be that of greatest child dimensions
+ DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLayouting_BinLayout03(void)
+{
+ const auto NUMBER_OF_ITEMS = 4;
+
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_BinLayout03 Explicit child Positioning when Bin layout MATCH_PARENT");
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
+
+ auto binContainer = Control::New();
+ auto binLayout = BinLayout::New();
+ binContainer.SetName( "BinLayout");
+ DevelControl::SetLayout( binContainer, binLayout );
+ binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
+ {
+ controls.push_back( CreateLeafControl( 100, 100 ) );
+ }
+
+ for( auto&& iter : controls )
+ {
+ binContainer.Add( iter );
+ }
+
+ tet_infoline("Position child explicitly from top left");
+ controls[0].SetProperty(Actor::Property::POSITION_X, 50.0f );
+
+ tet_infoline("Position child explicitly from top left");
+ controls[2].SetProperty(Actor::Property::POSITION_Y, 50.0f );
+
+ rootControl.Add( binContainer );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ // Items will be laid out at the same position
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // Item sizes will not be changed
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ // BinLayout size to be that of parent
+ DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLayoutingBinLayoutResizePolicy_01(void)
+{
+ /*
+ Root
+ |
+ Control (LinearLayout Horizontal)
+ |
+ Control (BinLayout)
+ |
+ Control (ResizePolicy::FILL_TO_PARENT)
+ |
+ LeafControl
+ */
+
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_01 - Test ResizePolicy mapping with FILL_TO_PARENT on BinLayout child");
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ SetupRootLayoutControl( rootControl );
+
+ auto hbox = Control::New();
+ auto hboxLayout = LinearLayout::New();
+ hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
+ DevelControl::SetLayout( hbox, hboxLayout );
+ hbox.SetName( "hBox" );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+
+ auto binContainer = Control::New();
+ CreateDefaultBinContainer( binContainer );
+ hbox.Add( binContainer );
+
+ auto control = Control::New();
+ control.SetName( "fillToParentControl" );
+ DevelControl::SetLayoutingRequired( control, true );
+ control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ binContainer.Add( control );
+
+ std::vector< Control > controls;
+ controls.push_back( CreateLeafControl( 40, 40 ) );
+
+ for( auto&& iter : controls )
+ {
+ control.Add( iter );
+ }
+
+ rootControl.Add( hbox );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline("Testing child of BinLayout is size of parent");
+ DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ tet_infoline("Testing BinLayout's child control has not altered it's children's sizes ");
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ tet_infoline("Testing BinLayout is size of parent");
+ DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), hbox.GetProperty<Vector3>( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLayoutingBinLayoutResizePolicy_02(void)
+{
+ /*
+ Root
+ |
+ Control (LinearLayout Horizontal)
+ |
+ Control (BinLayout)
+ |
+ Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
+ |
+ LeafControl
+ */
+
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_02 - Set ResizePolicy SIZE_RELATIVE_TO_PARENT on BinLayout child");
+
+ const auto NUMBER_OF_ITEMS = 4;
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ SetupRootLayoutControl( rootControl );
+
+ auto hbox = Control::New();
+ auto hboxLayout = LinearLayout::New();
+ hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
+ DevelControl::SetLayout( hbox, hboxLayout );
+ hbox.SetName( "hBox" );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+
+ auto binContainer = Control::New();
+ CreateDefaultBinContainer( binContainer );
+ hbox.Add( binContainer );
+
+ auto control = Control::New();
+ control.SetName( "fitToChildrenControl" );
+ DevelControl::SetLayoutingRequired( control, true );
+ control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ control.SetSizeModeFactor( Vector3( 0.50f, 1.0f, 1.0f ) );
+ binContainer.Add( control );
+
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
+ {
+ controls.push_back( CreateLeafControl( 40, 40 ) );
+ }
+
+ for( auto&& iter : controls )
+ {
+ control.Add( iter );
+ }
+
+ rootControl.Add( hbox );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline("Testing child of BinLayout is the defined relative size of parent");
+ DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 240.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ tet_infoline("Testing BinLayout's child control has not altered it's children's sizes ");
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ tet_infoline("Testing BinLayout is size of parent");
+ DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), hbox.GetProperty<Vector3>( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliBinLayoutResizePolicy_03(void)
+{
+ /*
+ Root
+ |
+ Control (LinearLayout Horizontal)
+ |
+ Control (LayoutingRequired)
+ |
+ Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
+ |
+ LeafControl
+ */
+
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliBinLayoutResizePolicy_03 - Set ResizePolicy SIZE_FIXED_OFFSET_FROM_PARENT on BinLayout child");
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ SetupRootLayoutControl( rootControl );
+
+ auto hbox = Control::New();
+ auto hboxLayout = LinearLayout::New();
+ hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
+ DevelControl::SetLayout( hbox, hboxLayout );
+ hbox.SetName( "hBox" );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+ hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
+
+ auto binContainer = Control::New();
+ CreateDefaultBinContainer( binContainer );
+ hbox.Add( binContainer );
+
+ hbox.Add( binContainer );
+
+ auto control = Control::New();
+ control.SetName( "fitToChildrenControl" );
+ DevelControl::SetLayoutingRequired( control, true );
+ control.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
+ control.SetSizeModeFactor( Vector3( -100.0f, 10.0f, 0.0f ) );
+ binContainer.Add( control );
+
+ std::vector< Control > controls;
+ controls.push_back( CreateLeafControl( 40, 40 ) );
+
+ for( auto&& iter : controls )
+ {
+ control.Add( iter );
+ }
+
+ rootControl.Add( hbox );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 380.0f, 810.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ END_TEST;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//CLASS HEADER
+#include <dali-toolkit/internal/layouting/bin-layout-impl.h>
+
+//INTERNAL HEADERS
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/common/extents.h>
+#include <dali/public-api/actors/actor.h>
+#include <dali-toolkit/devel-api/layouting/layout-item.h>
+#include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/layouting/size-negotiation-mapper.h>
+
+namespace
+{
+#if defined(DEBUG_ENABLED)
+static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" );
+#endif
+}
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+BinLayoutPtr BinLayout::New()
+{
+ BinLayoutPtr layout( new BinLayout() );
+ return layout;
+}
+
+BinLayout::BinLayout()
+: LayoutGroup()
+{
+}
+
+BinLayout::~BinLayout()
+{
+}
+
+void BinLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
+{
+#if defined(DEBUG_ENABLED)
+ auto actor = Actor::DownCast(GetOwner());
+
+ std::ostringstream oss;
+ oss << "BinLayout::OnMeasure ";
+ if( actor )
+ {
+ oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " ";
+ }
+ oss << "widthMeasureSpec:" << widthMeasureSpec << " heightMeasureSpec:" << heightMeasureSpec << std::endl;
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() );
+#endif
+
+ auto childCount = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose,
+ "BinLayout::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() <<
+ " Owner:" << Actor::DownCast(GetOwner()).GetName() <<
+ " Child Count:" << childCount <<
+ " MeasureSpecs( width:"<<widthMeasureSpec<<", height:"<<heightMeasureSpec );
+
+ auto widthMode = widthMeasureSpec.GetMode();
+ auto heightMode = heightMeasureSpec.GetMode();
+ LayoutLength widthSpecSize = widthMeasureSpec.GetSize();
+ LayoutLength heightSpecSize = heightMeasureSpec.GetSize();
+
+ bool exactWidth ( false );
+ bool exactHeight ( false );
+
+ // Layouting behaviour
+ // EXACT, width and height as provided.
+ // MATCH_PARENT, width and height that of parent
+ // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit)
+ // UNSPECIFIED, take width of widest child and height size of longest child.
+
+ LayoutLength layoutWidth( 0 );
+ LayoutLength layoutHeight( 0 );
+
+ // If BinLayout has children then measure children to get max dimensions
+ if ( childCount > 0 )
+ {
+ for( unsigned int i=0; i<childCount; ++i )
+ {
+ auto childLayout = GetChildAt( i );
+ if( childLayout )
+ {
+ auto childControl = Toolkit::Control::DownCast(childLayout->GetOwner());
+
+ // If child control has children check if a ResizePolicy is set on it. A LayoutItem could be a legacy container.
+ // A legacy container would need it's ResizePolicy to be applied as a MeasureSpec.
+
+ // Check below will be true for legacy containers and for controls with the layout flag required set.
+ // Other layouts will have their own OnMeasure (a requirement) hence not execute BinLayout::OnMeasure.
+ // Controls which have set the layout required flag will not be legacy controls hence should not have a ResizePolicy set.
+ if( childControl.GetChildCount() > 0 )
+ {
+ // First pass, Static mappings that are not dependant on parent
+ SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::WIDTH );
+ SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::HEIGHT );
+ }
+
+ // Second pass, if any mappings were not possible due to parent size dependencies then calculate an exact desired size for child
+ if( true == childLayout->IsResizePolicyRequired() ) // No need to test child count as this flag would only be set if control had children.
+ {
+ // Get last stored width and height specifications for the child
+ LayoutLength desiredWidth = childControl.GetProperty<float>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ LayoutLength desiredHeight = childControl.GetProperty<float>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+
+ DALI_LOG_INFO( gLogFilter, Debug::General, "BinLayout::MeasureChild Initial desired size pre ResizePolicy(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() );
+
+ childLayout->SetResizePolicyRequired( false ); // clear flag incase in case of changes before next Measure
+ SizeNegotiationMapper::GetSizeofChildForParentDependentResizePolicy( childControl, widthMeasureSpec, heightMeasureSpec, desiredWidth, desiredHeight );
+
+ // Parent dependant ResizePolicies become exact sizes so are now set on the child before it's measured.
+ childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, desiredWidth.AsInteger() );
+ childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, desiredHeight.AsInteger() );
+
+ DALI_LOG_INFO( gLogFilter, Debug::General, " BinLayout::OnMeasure ResizePolicy Required resulting size(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() );
+ }
+
+ // Get size of child
+ MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
+ LayoutLength childWidth = childLayout->GetMeasuredWidth();
+ LayoutLength childHeight = childLayout->GetMeasuredHeight();
+
+ Extents childMargin = childLayout->GetMargin();
+
+ // BinLayout width is that of it's widest child and it's height of the tallest child.
+ // MeasureSpec::Mode::UNSPECIFIED will use these sizes
+ layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end );
+ layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom );
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure calculated current BinLayout width[" << layoutWidth << "] height[" << layoutHeight << "]\n" );
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure Not a layout\n" );
+ }
+ }
+
+ Extents padding = GetPadding();
+ layoutWidth += padding.start + padding.end;
+ layoutHeight += padding.top + padding.bottom;
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnMeasure Getting default size as a leaf\n" );
+ // BinLayout does not contain any children so must be a leaf
+ layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec );
+ layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec );
+ }
+
+ // Can't exceed specified width
+ if( widthMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactWidth = true;
+ }
+ else if ( widthMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutWidth = std::min( layoutWidth, widthSpecSize );
+ }
+
+ // Can't exceed specified height
+ if( heightMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactHeight = true;
+ }
+ else if ( heightMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutHeight = std::min( layoutHeight, heightSpecSize );
+ }
+
+ layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() );
+ layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() );
+
+ if( exactWidth )
+ {
+ layoutWidth = widthSpecSize;
+ }
+
+ if( exactHeight )
+ {
+ layoutHeight = heightSpecSize;
+ }
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "BinLayout::OnMeasure Measured size(" << layoutWidth << "," << layoutHeight << ") for : " << Actor::DownCast(GetOwner()).GetName() << " \n" );
+ SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) );
+
+}
+
+void BinLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
+{
+ auto count = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "BinLayout OnLayout owner:" << ( ( Toolkit::Control::DownCast(GetOwner())) ? Toolkit::Control::DownCast(GetOwner()).GetName() : "invalid" ) << " childCount:" << count );
+
+ for( unsigned int childIndex = 0; childIndex < count; childIndex++)
+ {
+ LayoutItemPtr childLayout = GetChildAt( childIndex );
+ if( childLayout != nullptr )
+ {
+
+ auto childOwner = childLayout->GetOwner();
+ LayoutLength childWidth = childLayout->GetMeasuredWidth();
+ LayoutLength childHeight = childLayout->GetMeasuredHeight();
+ Extents childMargin = childLayout->GetMargin();
+ auto control = Toolkit::Control::DownCast( childOwner );
+ Extents padding = GetPadding();
+
+ auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION );
+ auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT );
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "BinLayout::OnLayout child[" << control.GetName() <<
+ "] position(" << childPosition << ") child width[" << childWidth << "] height[" << childHeight << "]\n" );
+
+ // Margin and Padding only supported when child anchor point is TOP_LEFT.
+ int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0;
+ int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0;
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "BinLayout::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY );
+
+ LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX;
+ LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY;
+
+ childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
+ }
+ }
+}
+
+} // namespace Internal
+} // namespace Toolkit
+} // namespace Dali