RTL support of FlexContainer 82/151882/35
authortaeyoon0.lee <taeyoon0.lee@samsung.com>
Fri, 22 Sep 2017 08:12:25 +0000 (17:12 +0900)
committeradun <xiaohui.fang@samsung.com>
Tue, 21 Nov 2017 17:06:27 +0000 (01:06 +0800)
Change-Id: Ibc703d749415cf2b58615ddcb2619284784d4119

automated-tests/src/dali-toolkit/utc-Dali-FlexContainer.cpp [changed mode: 0644->0755]
dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp [changed mode: 0644->0755]
dali-toolkit/internal/controls/flex-container/flex-container-impl.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index f602079..26e9585
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali/devel-api/actors/actor-devel.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -494,3 +495,66 @@ int UtcDaliToolkitFlexContainerMoveFocus(void)
 
   END_TEST;
 }
+
+int UtcDaliToolkitFlexContainerRTLSupportP(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitFlexContainerRTLSupportP");
+  FlexContainer flexContainer = FlexContainer::New();
+  DALI_TEST_CHECK( flexContainer );
+
+  Actor actor0 = Actor::New();
+
+  Stage::GetCurrent().Add( actor0 );
+  actor0.Add( flexContainer );
+
+  // Create two actors and add them to the container
+  Actor actor1 = Actor::New();
+  Actor actor2 = Actor::New();
+  DALI_TEST_CHECK( actor1 );
+  DALI_TEST_CHECK( actor2 );
+
+  flexContainer.Add(actor1);
+  flexContainer.Add(actor2);
+
+  // Check flex direction property.
+  flexContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, "row" );
+  DALI_TEST_EQUALS( (FlexContainer::FlexDirection)flexContainer.GetProperty<int>( FlexContainer::Property::FLEX_DIRECTION ), FlexContainer::ROW, TEST_LOCATION );
+
+  // Check content direction property.
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::INHERIT, TEST_LOCATION );
+
+  actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION );
+
+  actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION );
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "RTL" );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION );
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "LTR" );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION );
+
+  actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION );
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "inherit" );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION );
+
+  actor0.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION );
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "inherit" );
+  DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty<int>( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION );
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "LTR" );
+  application.SendNotification();
+  application.Render();
+
+  flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "RTL" );
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
old mode 100644 (file)
new mode 100755 (executable)
index 650e5cf..e1849bf
@@ -176,7 +176,6 @@ bool IsNodeDirty( void *itemNodes )
   // style properties are changed. So should always return true here.
   return true;
 }
-
 } // Unnamed namespace
 
 Toolkit::FlexContainer FlexContainer::New()
@@ -206,12 +205,42 @@ FlexContainer::~FlexContainer()
   mChildrenNodes.clear();
 }
 
-void FlexContainer::SetContentDirection( Toolkit::FlexContainer::ContentDirection contentDirection )
+void FlexContainer::SetContentDirection( Toolkit::FlexContainer::ContentDirection contentDirection)
 {
   if( mContentDirection != contentDirection )
   {
-    mContentDirection = contentDirection;
-    mRootNode.node->style.direction = static_cast<css_direction_t>( mContentDirection );
+    Dali::CustomActor ownerActor(GetOwner());
+
+    if( Toolkit::FlexContainer::INHERIT != contentDirection )
+    {
+      mContentDirection = contentDirection;
+
+      ownerActor.SetProperty( Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION, false );
+
+      if( Toolkit::FlexContainer::LTR == contentDirection )
+      {
+        ownerActor.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
+      }
+      else
+      {
+        ownerActor.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
+      }
+    }
+    else
+    {
+      ownerActor.SetProperty( Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION, true );
+
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( ownerActor.GetParent().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+
+      if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
+      {
+        mContentDirection = Toolkit::FlexContainer::RTL;
+      }
+      else
+      {
+        mContentDirection = Toolkit::FlexContainer::LTR;
+      }
+    }
 
     RelayoutRequest();
   }
@@ -570,6 +599,31 @@ void FlexContainer::OnSizeSet( const Vector3& size )
   Control::OnSizeSet( size );
 }
 
+void FlexContainer::OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type )
+{
+  Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast(actor);
+  Toolkit::FlexContainer::ContentDirection direction;
+
+  if( type == Dali::LayoutDirection::RIGHT_TO_LEFT )
+  {
+    direction = Toolkit::FlexContainer::RTL;
+  }
+  else
+  {
+    direction = Toolkit::FlexContainer::LTR;
+  }
+
+  Toolkit::Internal::FlexContainer &flexContainerImpl = GetImpl( flexContainer );
+
+  if( flexContainerImpl.mContentDirection != direction )
+  {
+    Dali::CustomActor ownerActor(flexContainerImpl.GetOwner());
+    flexContainerImpl.mContentDirection = direction;
+
+    flexContainerImpl.RelayoutRequest();
+  }
+}
+
 void FlexContainer::ComputeLayout()
 {
   if( mRootNode.node )
@@ -641,7 +695,29 @@ void FlexContainer::ComputeLayout()
     }
 
     // Calculate the layout
-    layoutNode( mRootNode.node, Self().GetMaximumSize().x, Self().GetMaximumSize().y, mRootNode.node->style.direction );
+    css_direction_t nodeLayoutDirection = CSS_DIRECTION_INHERIT;
+    switch( mContentDirection )
+    {
+    case Dali::Toolkit::FlexContainer::LTR:
+    {
+      nodeLayoutDirection = CSS_DIRECTION_LTR;
+      break;
+    }
+
+    case Dali::Toolkit::FlexContainer::RTL:
+    {
+      nodeLayoutDirection = CSS_DIRECTION_RTL;
+      break;
+    }
+
+    case Dali::Toolkit::FlexContainer::INHERIT:
+    {
+      nodeLayoutDirection = CSS_DIRECTION_INHERIT;
+      break;
+    }
+    }
+
+    layoutNode( mRootNode.node, Self().GetMaximumSize().x, Self().GetMaximumSize().y, nodeLayoutDirection);
   }
 }
 
@@ -779,6 +855,8 @@ void FlexContainer::OnInitialize()
 {
   // Initialize the node for the flex container itself
   Dali::Actor self = Self();
+  self.LayoutDirectionChangedSignal().Connect( this, &FlexContainer::OnLayoutDirectionChanged );
+
   mRootNode.actor = self;
   mRootNode.node = new_css_node();
   mRootNode.node->context = &mChildrenNodes;
old mode 100644 (file)
new mode 100755 (executable)
index c56a3ca..71fec8e
@@ -205,6 +205,13 @@ private: // From Control
    */
   virtual void OnSizeSet( const Vector3& size );
 
+  /**
+  * @copydoc OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type )
+  * @param[in] actor The actor whose layoutDirection is changed.
+  * @param[in] type  The layoutDirection.
+  */
+  void OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type );
+
 private: // Implementation
 
   /**