Action framework for visuals 59/160559/12
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 16 Nov 2017 19:36:03 +0000 (19:36 +0000)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 23 Nov 2017 17:05:53 +0000 (17:05 +0000)
Internal::Visual::Base has a DoAction API which calls the OnDoAction in derived Visual if they want
 to act on any Actions they have defined.

Control has a devel API to DoAction on any of it's registered visuals.

If a action is requested on a visual, if the visual does not implement it then
 nothing is done.

Action will be provided by Indexes,  in future may add an API for strings if
 builder requires but internal.
 Property::Key has an explict constructor hence not used.

DummyVisual added to test framework, can be used in Internal tests. Visuals creation not public.

Change-Id: Ib4590f5a76d4b45adcb2213eee70c1bbd91f88a2

13 files changed:
automated-tests/src/dali-toolkit-internal/CMakeLists.txt
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.h [new file with mode: 0644]
automated-tests/src/dali-toolkit-internal/utc-Dali-Control-internal.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h
dali-toolkit/devel-api/controls/control-devel.cpp
dali-toolkit/devel-api/controls/control-devel.h
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/control/control-data-impl.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h

index 366c44c..64f876b 100755 (executable)
@@ -9,6 +9,7 @@ SET(CAPI_LIB "dali-toolkit-internal")
 SET(TC_SOURCES
  utc-Dali-BidirectionalSupport.cpp
  utc-Dali-ColorConversion.cpp
+ utc-Dali-Control-internal.cpp
  utc-Dali-DebugRendering.cpp
  utc-Dali-ItemView-internal.cpp
  utc-Dali-LogicalModel.cpp
@@ -24,6 +25,7 @@ SET(TC_SOURCES
  utc-Dali-Text-Typesetter.cpp
  utc-Dali-Text-ViewModel.cpp
  utc-Dali-TextureManager.cpp
+ utc-Dali-Visuals-internal.cpp
  utc-Dali-VisualModel.cpp
  utc-Dali-VisualUrl.cpp
 )
@@ -59,6 +61,7 @@ LIST(APPEND TC_SOURCES
    ../dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.cpp
    ../dali-toolkit/dali-toolkit-test-utils/test-native-image.cpp
    dali-toolkit-test-utils/toolkit-text-utils.cpp
+   dali-toolkit-test-utils/dummy-visual.cpp
 )
 
 
diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.cpp b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.cpp
new file mode 100644 (file)
index 0000000..f5c5aeb
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2017 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 "dummy-visual.h"
+
+#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+typedef IntrusivePtr<VisualFactoryCache> VisualFactoryCachePtr;
+
+DummyVisualPtr DummyVisual::New( const Property::Map& properties )
+{
+  VisualFactoryCachePtr factoryCache = new VisualFactoryCache;
+
+  DummyVisualPtr dummyVisualPtr( new DummyVisual( *( factoryCache.Get() ) ) );
+
+  return dummyVisualPtr;
+}
+
+DummyVisual::DummyVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache ),
+  mActionCounter( 0 )
+{
+}
+
+void DummyVisual::DoCreatePropertyMap( Property::Map& map ) const
+{
+  // Implement if required
+}
+
+void DummyVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
+{
+  // Implement if required
+}
+
+void DummyVisual::DoSetProperties( const Property::Map& propertyMap )
+{
+  // Implement if required
+}
+
+void DummyVisual::OnSetTransform()
+{
+  // Implement if required
+}
+
+void DummyVisual::DoSetOnStage( Actor& actor )
+{
+  // Implement if required
+}
+
+void DummyVisual::OnDoAction( const Property::Index actionName, const Property::Value attributes )
+{
+  if ( DummyVisual::TEST_ACTION == actionName )
+  {
+    mActionCounter++;  // GetActionCounter can be used to test for this.
+  }
+  // Further Actions can be added here
+}
+
+unsigned int DummyVisual::GetActionCounter() const
+{
+  return mActionCounter;
+}
+
+void DummyVisual::ResetActionCounter()
+{
+  mActionCounter = 0;
+}
+
+} // Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.h b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.h
new file mode 100644 (file)
index 0000000..73e8185
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef __DALI_TOOLKIT_TEST_DUMMY_VISUAL_H__
+#define __DALI_TOOLKIT_TEST_DUMMY_VISUAL_H__
+
+/*
+ * Copyright (c) 2017 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
+
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/intrusive-ptr.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+class DummyVisual;
+
+typedef IntrusivePtr< DummyVisual > DummyVisualPtr;
+
+/**
+ * Dummy Visual that can be used for testing
+ * Cannot create an instance of an existing Visual, so use this dummy class for the implementation.
+ */
+class DummyVisual : public Visual::Base
+{
+public:
+
+  // Actions that the dummy visual can perform.  These actions are called through the Visual::Base::DoAction API.
+  enum Type
+  {
+    TEST_ACTION = 0,  ///< Updates the action counter
+  };
+
+public:
+
+  // Constructor for DummyVisual
+  static DummyVisualPtr New( const Property::Map& properties );
+
+  // Prevent default methods being used.
+  DummyVisual( const DummyVisual& dummyVisual ) = delete;
+  DummyVisual( const DummyVisual&& dummyVisual ) = delete;
+  DummyVisual& operator=( const DummyVisual& dummyVisual ) = delete;
+  DummyVisual& operator=( const DummyVisual&& dummyVisual ) = delete;
+
+  // Get the Action counter, action counter incremented with every successful Action
+  unsigned int GetActionCounter() const;
+  // Reset the Action counter to 0;
+  void ResetActionCounter();
+
+protected:
+
+  DummyVisual( VisualFactoryCache& factoryCache );
+
+  virtual void DoCreatePropertyMap( Property::Map& map ) const override;
+  virtual void DoCreateInstancePropertyMap( Property::Map& map ) const override;
+  virtual void DoSetProperties( const Property::Map& propertyMap ) override;
+  virtual void OnSetTransform() override;
+  virtual void DoSetOnStage( Actor& actor ) override;
+  virtual void OnDoAction( const Property::Index actionName, const Property::Value attributes );
+
+private:
+  unsigned int mActionCounter;
+
+};
+
+
+} // Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_TEST_DUMMY_VISUAL_H__
diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Control-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Control-internal.cpp
new file mode 100644 (file)
index 0000000..09e2873
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017 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 <dali-toolkit/dali-toolkit.h>
+#include <toolkit-text-utils.h>
+#include <dummy-visual.h>
+#include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+
+int UtcDaliControlActionOnVisual(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline( "Register an ImageVisual and perform image reload Action on it. Tests Actions are completed." );
+  Vector2 controlSize( 20.f, 30.f );
+
+  //Created DummyVisual
+  Property::Map settings;
+  Toolkit::Internal::DummyVisualPtr dummyVisualPtr = Toolkit::Internal::DummyVisual::New( settings );
+
+  DummyControl dummyControl = DummyControl::New( true );
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+
+  tet_infoline( "Register test visual and stage control" );
+
+  Toolkit::Visual::Base visualBaseHandle = Toolkit::Visual::Base( dummyVisualPtr.Get() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visualBaseHandle );
+  dummyControl.SetSize(200.f, 200.f);
+  Stage::GetCurrent().Add( dummyControl );
+
+  application.SendNotification();
+  application.Render();
+
+  tet_infoline( "Check action counter is 0 before DoAction" );
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
+
+  tet_infoline( "Perform TEST_ACTION action on registered test visual. Should increase the action counter" );
+
+  Property::Map attributes;
+  DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::Internal::DummyVisual::TEST_ACTION, attributes );
+
+  application.SendNotification();
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 1, TEST_LOCATION );
+
+  END_TEST;
+}
diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp
new file mode 100644 (file)
index 0000000..bbe1aa6
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2016 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 <dali-toolkit/dali-toolkit.h>
+#include <toolkit-text-utils.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dummy-visual.h>
+#include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+int UtcDaliVisualAction(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "Register an ImageVisual and and perform an Action on Visual directly" );
+  Vector2 controlSize( 20.f, 30.f );
+
+  //Created DummyVisual
+  Property::Map settings;
+  Toolkit::Internal::DummyVisualPtr dummyVisualPtr = Toolkit::Internal::DummyVisual::New( settings );
+
+  DummyControl dummyControl = DummyControl::New( true );
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+
+  tet_infoline( "Register visual and stage control" );
+
+  Toolkit::Visual::Base visualBaseHandle = Toolkit::Visual::Base( dummyVisualPtr.Get() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visualBaseHandle );
+  dummyControl.SetSize(200.f, 200.f);
+  Stage::GetCurrent().Add( dummyControl );
+
+  application.SendNotification();
+  application.Render();
+
+  tet_infoline( "Check action counter is 0 before DoAction" );
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
+
+  tet_infoline( "Perform TEST_ACTION action on Visual. Should increase the action counter" );
+
+  Property::Map attributes;
+  Toolkit::Internal::Visual::Base& internalVisualBase =  GetImplementation( visualBaseHandle );
+  internalVisualBase.DoAction( Dali::Toolkit::Internal::DummyVisual::TEST_ACTION, attributes );
+  application.SendNotification();
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliVisualActionNotImplemented(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "Register an ImageVisual and and perform an Action on a Visual which does not support any Actions" );
+  Vector2 controlSize( 20.f, 30.f );
+
+  //Created DummyVisual
+  Property::Map settings;
+  Toolkit::Internal::DummyVisualPtr dummyVisualPtr = Toolkit::Internal::DummyVisual::New( settings );
+
+  DummyControl dummyControl = DummyControl::New( true );
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+
+  tet_infoline( "Register visual and stage control" );
+
+  VisualFactory factory = VisualFactory::Get();
+  Property::Map propertyMap;
+  propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
+  propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
+  Visual::Base visual = factory.CreateVisual( propertyMap );
+
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+  dummyControl.SetSize(200.f, 200.f);
+  Stage::GetCurrent().Add( dummyControl );
+
+  application.SendNotification();
+  application.Render();
+
+  tet_infoline( "Check action counter is 0 before DoAction" );
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
+
+  tet_infoline( "Perform TEST_ACTION action on Color Visual which does not support it.. Should not increment the action counter" );
+  Property::Map attributes;
+  GetImplementation( visual ).DoAction( Dali::Toolkit::Internal::DummyVisual::TEST_ACTION, attributes );
+  application.SendNotification();
+  DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
+
+  END_TEST;
+}
index 3461f0d..5e843c2 100644 (file)
@@ -155,6 +155,12 @@ Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& tra
   return DevelControl::CreateTransition( *this, transition );
 }
 
+void DummyControlImpl::DoAction( Dali::Property::Index index, Dali::Property::Index action, const Dali::Property::Value attributes )
+{
+  DummyControl control( *this );
+  DevelControl::DoAction(  control, index, action, attributes);
+}
+
 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
 {
   Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
index d0387d9..69a5c88 100644 (file)
@@ -105,6 +105,7 @@ public:
   int GetVisualCount();
   Toolkit::Visual::Base GetVisual( Property::Index index );
   Animation CreateTransition( const Toolkit::TransitionData& transition );
+  void DoAction( Dali::Property::Index index, Dali::Property::Index action, const Dali::Property::Value attributes );
 
   static void SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
 
index 187e518..1ea20d2 100644 (file)
@@ -95,6 +95,12 @@ Dali::Animation CreateTransition( Internal::Control& control, const Toolkit::Tra
   return controlDataImpl.CreateTransition( handle );
 }
 
+void DoAction( Control& control, Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
+{
+  Internal::Control& controlInternal = Toolkit::Internal::GetImplementation( control );
+  Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlInternal );
+  controlDataImpl.DoAction( visualIndex, actionId, attributes );
+}
 
 } // namespace DevelControl
 
index 817efd0..9a824d3 100644 (file)
@@ -238,6 +238,18 @@ DALI_IMPORT_API Toolkit::Visual::ResourceStatus GetVisualResourceStatus( const I
  */
 DALI_IMPORT_API Dali::Animation CreateTransition( Internal::Control& control, const Toolkit::TransitionData& transitionData );
 
+/**
+ * @brief Perform an action on a visual registered to this control.
+ *
+ * Visuals will have actions, this API is used to perform one of these actions with the given attributes.
+ *
+ * @param[in] control The control.
+ * @param[in] visualIndex The Property index of the visual.
+ * @param[in] actionId The action to perform.  See Visual to find supported actions.
+ * @param[in] attributes Optional attributes for the action.
+ */
+DALI_IMPORT_API void DoAction( Control& control, Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
+
 } // namespace DevelControl
 
 } // namespace Toolkit
index 1630b92..187e62f 100644 (file)
@@ -783,6 +783,15 @@ Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData&
   return transition;
 }
 
+void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
+{
+  RegisteredVisualContainer::Iterator iter;
+  if ( FindVisual( visualIndex, mVisuals, iter ) )
+  {
+    Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
+  }
+}
+
 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
 {
   Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
index f6a3288..df661ef 100644 (file)
@@ -189,6 +189,11 @@ public:
   Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
 
   /**
+   * @copydoc Dali::Toolkit::DevelControl::DoAction()
+   */
+  void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
+
+  /**
    * @brief Function used to set control properties.
    * @param[in] object The object whose property to set
    * @param[in] index The index of the property to set
index f486a0f..3473509 100644 (file)
@@ -223,6 +223,11 @@ void Visual::Base::GetNaturalSize( Vector2& naturalSize )
   naturalSize = Vector2::ZERO;
 }
 
+void Visual::Base::DoAction( const Property::Index actionId, const Property::Value attributes )
+{
+  OnDoAction( actionId, attributes );
+}
+
 void Visual::Base::SetDepthIndex( int index )
 {
   mImpl->mDepthIndex = index;
@@ -337,6 +342,11 @@ bool Visual::Base::IsOnStage() const
   return mImpl->mFlags & Impl::IS_ON_STAGE;
 }
 
+void Visual::Base::OnDoAction( const Property::Index actionId, const Property::Value attributes )
+{
+  // May be overriden by derived class
+}
+
 void Visual::Base::RegisterMixColor()
 {
   // Only register if not already registered.
index f9534e4..996fa3c 100644 (file)
@@ -93,6 +93,14 @@ public:
   void SetTransformAndSize( const Property::Map& transform, Size controlSize );
 
   /**
+   * @brief Performs an action on the visual with the given action name and attributes.
+   *
+   * @param[in] actionName The name of the action to perform this API only takes an Index
+   * @param[in] attributes The list of attributes for the action. ( optional for this data structure to have content )
+   */
+  void DoAction( const Dali::Property::Index actionName, const Dali::Property::Value attributes );
+
+  /**
    * @copydoc Toolkit::Visual::Base::GetHeightForWidth
    */
   virtual float GetHeightForWidth( float width );
@@ -292,7 +300,7 @@ protected:
    *
    * @param[in] actor The actor applying this visual.
    */
-  virtual void DoSetOnStage( Actor& actor )=0;
+  virtual void DoSetOnStage( Actor& actor ) = 0;
 
   /**
    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
@@ -301,6 +309,14 @@ protected:
    */
   virtual void DoSetOffStage( Actor& actor );
 
+  /**
+   * @brief Called by DoAction() allowing sub classes to do the given action.
+   *
+   * @param[in] actionId The action to perform
+   * @param[in] attributes The list of attributes for the action. ( optional for this data structure to have content )
+   */
+  virtual void OnDoAction( const Property::Index actionId, const Property::Value attributes );
+
 protected:
 
   /**