1 #ifndef TEST_CUSTOM_ACTOR_H
2 #define TEST_CUSTOM_ACTOR_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/object/property-helper-devel.h>
23 #include <dali/integration-api/scene.h>
25 extern std::vector< std::string > MasterCallStack;
26 extern bool gOnRelayout;
32 struct TestCustomActor;
36 * Test custom actor handle
38 class TestCustomActor : public Dali::CustomActor
43 PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX,
44 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000
51 TEST_PROPERTY1 = PROPERTY_START_INDEX,
57 static TestCustomActor New();
58 static TestCustomActor NewNegoSize();
59 static TestCustomActor NewVariant1( Actor childToAdd );
60 static TestCustomActor NewVariant2();
61 static TestCustomActor NewVariant3( Actor childToAdd );
62 static TestCustomActor NewVariant4();
63 static TestCustomActor NewVariant5( Dali::Integration::Scene scene );
64 static TestCustomActor NewVariant6( Dali::Integration::Scene scene );
65 static TestCustomActor NewVariant7( const char* name );
66 static TestCustomActor NewVariant8( Actor rival );
67 static TestCustomActor DownCast( Dali::BaseHandle handle );
69 virtual ~TestCustomActor();
70 Impl::TestCustomActor& GetImpl();
72 TestCustomActor( TestCustomActor&& rhs ) = default;
73 TestCustomActor& operator=( TestCustomActor&& rhs ) = default;
75 std::vector< std::string >& GetMethodsCalled();
76 void ResetCallStack();
77 void SetDaliProperty(std::string s);
78 Dali::Vector3 GetSize();
79 Dali::Vector3 GetTargetSize();
80 virtual Dali::Vector3 GetNaturalSize();
81 virtual float GetHeightForWidth( float width );
82 virtual float GetWidthForHeight( float height );
83 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container );
84 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension );
85 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension );
86 void TestRelayoutRequest();
87 float TestGetHeightForWidthBase( float width );
88 float TestGetWidthForHeightBase( float height );
89 float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension );
90 bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension );
94 TestCustomActor( Impl::TestCustomActor& impl );
95 explicit TestCustomActor(Dali::Internal::CustomActor* internal);
99 namespace DevelTestCustomActor
105 TEST_PROPERTY1 = Test::TestCustomActor::Property::TEST_PROPERTY1,
106 TEST_PROPERTY2 = Test::TestCustomActor::Property::TEST_PROPERTY2,
107 DEVEL_TEST_PROPERTY3 = TEST_PROPERTY2+1,
108 DEVEL_TEST_PROPERTY4 = TEST_PROPERTY2+2,
109 DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2+3,
110 DEVEL_TEST_PROPERTY6 = TEST_PROPERTY2+4
113 } // Namespace Property
114 } // Namespace DevelTestCustomActor
117 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
121 struct TestCustomActor : public Dali::CustomActorImpl
128 TestCustomActor(bool nego);
129 virtual ~TestCustomActor();
130 void Initialize( const char* name = NULL );
131 virtual void OnInitialize( const char* name );
132 void ResetCallStack();
133 void AddToCallStacks( const char* method );
134 void OnSceneConnection( int depth ) override;
135 void OnSceneDisconnection() override;
136 void OnChildAdd(Dali::Actor& child) override;
137 void OnChildRemove(Dali::Actor& child) override;
138 void OnPropertySet( Dali::Property::Index index, Dali::Property::Value propertyValue ) override;
139 void OnSizeSet(const Dali::Vector3& targetSize) override;
140 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override;
141 bool OnHoverEvent(const Dali::HoverEvent& event) override;
142 bool OnWheelEvent(const Dali::WheelEvent& event) override;
143 bool OnKeyEvent(const Dali::KeyEvent& event) override;
144 virtual void OnKeyInputFocusGained();
145 virtual void OnKeyInputFocusLost();
146 Dali::Vector3 GetNaturalSize() override;
147 float GetHeightForWidth( float width ) override;
148 float GetWidthForHeight( float height ) override;
149 void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container ) override;
150 void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension ) override;
151 void OnCalculateRelayoutSize( Dali::Dimension::Type dimension ) override;
152 float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension ) override;
153 void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension ) override;
154 bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS ) override;
155 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
156 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index index );
158 void SetDaliProperty(std::string s);
159 void TestRelayoutRequest();
160 float TestGetHeightForWidthBase( float width );
161 float TestGetWidthForHeightBase( float height );
162 float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension );
163 bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension );
166 Dali::Property::Index mDaliProperty;
167 std::vector< std::string > mMethodsCalled;
168 Dali::Vector3 mSizeSet;
169 Dali::Vector3 mTargetSize;
175 Dali::Vector4 develProp3;
181 inline TestCustomActor& GetImpl( Test::TestCustomActor& handle )
183 DALI_ASSERT_ALWAYS( handle );
184 Dali::RefObject& object = handle.GetImplementation();
185 return static_cast<TestCustomActor&>( object );
188 inline const TestCustomActor& GetImpl( const Test::TestCustomActor& handle )
190 DALI_ASSERT_ALWAYS( handle );
191 const Dali::RefObject& object = handle.GetImplementation();
192 return static_cast<const TestCustomActor&>( object );
197 * Variant which adds a new child during OnSceneConnection
199 struct TestCustomActorVariant1 : public TestCustomActor
204 TestCustomActorVariant1( Dali::Actor childToAdd )
205 : mChildToAdd( childToAdd )
209 // From CustomActorImpl
210 void OnSceneConnection( int depth ) override
213 TestCustomActor::OnSceneConnection( depth );
216 Self().Add( mChildToAdd );
219 Dali::Actor mChildToAdd;
223 * Variant which removes children during OnSceneConnection
225 struct TestCustomActorVariant2 : public TestCustomActor
230 TestCustomActorVariant2()
234 // From CustomActorImpl
235 virtual void OnSceneConnection( int depth )
238 TestCustomActor::OnSceneConnection( depth );
240 // Remove all the children
241 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
243 Self().Remove( Self().GetChildAt(0) );
249 * Variant which adds a new child during OnSceneDisconnection
251 struct TestCustomActorVariant3 : public TestCustomActor
256 TestCustomActorVariant3( Dali::Actor childToAdd )
257 : mChildToAdd( childToAdd )
261 // From CustomActorImpl
262 virtual void OnSceneDisconnection()
265 TestCustomActor::OnSceneDisconnection();
268 Self().Add( mChildToAdd );
271 Dali::Actor mChildToAdd;
275 * Variant which removes children during OnSceneDisconnection
277 struct TestCustomActorVariant4 : public TestCustomActor
282 TestCustomActorVariant4()
286 // From CustomActorImpl
287 virtual void OnSceneDisconnection()
290 TestCustomActor::OnSceneDisconnection();
292 // Remove all the children
293 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
295 Self().Remove( Self().GetChildAt(0) );
301 * Variant which removes its parent from Stage during OnSceneConnection
303 struct TestCustomActorVariant5 : public TestCustomActor
308 TestCustomActorVariant5(Dali::Integration::Scene scene)
313 // From CustomActorImpl
314 virtual void OnSceneConnection( int depth )
317 TestCustomActor::OnSceneConnection( depth );
319 // Take parent off-stage
320 Dali::Actor parent = Self().GetParent();
323 mScene.Remove( parent );
328 Dali::Integration::Scene mScene;
332 * Variant which adds its parent to Stage during OnSceneDisconnection
334 struct TestCustomActorVariant6 : public TestCustomActor
339 TestCustomActorVariant6(Dali::Integration::Scene scene)
344 // From CustomActorImpl
345 virtual void OnSceneDisconnection()
348 TestCustomActor::OnSceneDisconnection();
350 // Put parent on-stage
351 Dali::Actor parent = Self().GetParent();
354 mScene.Add( parent );
359 Dali::Integration::Scene mScene;
363 * Variant which reparents its children into a separate container
365 struct TestCustomActorVariant7 : public TestCustomActor
370 TestCustomActorVariant7()
374 virtual void OnInitialize( const char* name )
376 // We need to do this early, before the OnChildAdd is recorded
377 Self().SetProperty( Dali::Actor::Property::NAME, name );
379 mContainer = Dali::Actor::New();
380 mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" );
381 Self().Add( mContainer );
384 // From CustomActorImpl
385 virtual void OnChildAdd(Dali::Actor& child)
388 TestCustomActor::OnChildAdd(child);
391 if ( child != mContainer )
393 mContainer.Add( child );
397 Dali::Actor mContainer;
401 * Variant which attempts to interfere with the reparenting of a child to another container
403 struct TestCustomActorVariant8 : public TestCustomActor
408 TestCustomActorVariant8( Dali::Actor rival )
409 : mRivalContainer( rival )
413 // From CustomActorImpl
414 virtual void OnChildRemove(Dali::Actor& child)
417 TestCustomActor::OnChildRemove(child);
419 mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
422 Dali::Actor mRivalContainer;
425 // Need a class that doesn't override virtual methods
426 class SimpleTestCustomActor : public Dali::CustomActorImpl
433 SimpleTestCustomActor()
434 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
441 virtual ~SimpleTestCustomActor()
445 // From CustomActorImpl
446 void OnSceneConnection( int depth ) override
449 void OnSceneDisconnection() override
452 void OnChildAdd(Dali::Actor& child) override
455 void OnChildRemove(Dali::Actor& child) override
458 void OnSizeSet(const Dali::Vector3& targetSize) override
461 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override
464 bool OnHoverEvent(const Dali::HoverEvent& event) override
468 bool OnWheelEvent(const Dali::WheelEvent& event) override
472 bool OnKeyEvent(const Dali::KeyEvent& event) override
476 virtual void OnKeyInputFocusGained()
479 virtual void OnKeyInputFocusLost()
483 Dali::Vector3 GetNaturalSize() override
485 return Dali::Vector3( 0.0f, 0.0f, 0.0f );
488 float GetHeightForWidth( float width ) override
493 float GetWidthForHeight( float height ) override
498 void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container ) override
502 void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension ) override
506 void OnCalculateRelayoutSize( Dali::Dimension::Type dimension ) override
510 float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension ) override
515 void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension ) override
519 bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS ) override
528 #endif // TEST_CUSTOM_ACTOR_H