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
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
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
)
../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
)
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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__
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+}
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 ) );
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 );
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
*/
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
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 ) );
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
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;
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.
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 );
*
* @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
*/
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:
/**