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 virtual void OnSceneConnection( int depth );
135 virtual void OnSceneDisconnection();
136 virtual void OnChildAdd(Dali::Actor& child);
137 virtual void OnChildRemove(Dali::Actor& child);
138 virtual void OnPropertySet( Dali::Property::Index index, Dali::Property::Value propertyValue );
139 virtual void OnSizeSet(const Dali::Vector3& targetSize);
140 virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize);
141 virtual bool OnTouchEvent(const Dali::TouchEvent& event);
142 virtual bool OnHoverEvent(const Dali::HoverEvent& event);
143 virtual bool OnWheelEvent(const Dali::WheelEvent& event);
144 virtual bool OnKeyEvent(const Dali::KeyEvent& event);
145 virtual void OnKeyInputFocusGained();
146 virtual void OnKeyInputFocusLost();
147 virtual Dali::Vector3 GetNaturalSize();
148 virtual float GetHeightForWidth( float width );
149 virtual float GetWidthForHeight( float height );
150 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container );
151 virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension );
152 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension );
153 virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension );
154 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension );
155 virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS );
156 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
157 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index index );
159 void SetDaliProperty(std::string s);
160 void TestRelayoutRequest();
161 float TestGetHeightForWidthBase( float width );
162 float TestGetWidthForHeightBase( float height );
163 float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension );
164 bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension );
167 Dali::Property::Index mDaliProperty;
168 std::vector< std::string > mMethodsCalled;
169 Dali::Vector3 mSizeSet;
170 Dali::Vector3 mTargetSize;
176 Dali::Vector4 develProp3;
182 inline TestCustomActor& GetImpl( Test::TestCustomActor& handle )
184 DALI_ASSERT_ALWAYS( handle );
185 Dali::RefObject& object = handle.GetImplementation();
186 return static_cast<TestCustomActor&>( object );
189 inline const TestCustomActor& GetImpl( const Test::TestCustomActor& handle )
191 DALI_ASSERT_ALWAYS( handle );
192 const Dali::RefObject& object = handle.GetImplementation();
193 return static_cast<const TestCustomActor&>( object );
198 * Variant which adds a new child during OnSceneConnection
200 struct TestCustomActorVariant1 : public TestCustomActor
205 TestCustomActorVariant1( Dali::Actor childToAdd )
206 : mChildToAdd( childToAdd )
210 // From CustomActorImpl
211 virtual void OnSceneConnection( int depth )
214 TestCustomActor::OnSceneConnection( depth );
217 Self().Add( mChildToAdd );
220 Dali::Actor mChildToAdd;
224 * Variant which removes children during OnSceneConnection
226 struct TestCustomActorVariant2 : public TestCustomActor
231 TestCustomActorVariant2()
235 // From CustomActorImpl
236 virtual void OnSceneConnection( int depth )
239 TestCustomActor::OnSceneConnection( depth );
241 // Remove all the children
242 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
244 Self().Remove( Self().GetChildAt(0) );
250 * Variant which adds a new child during OnSceneDisconnection
252 struct TestCustomActorVariant3 : public TestCustomActor
257 TestCustomActorVariant3( Dali::Actor childToAdd )
258 : mChildToAdd( childToAdd )
262 // From CustomActorImpl
263 virtual void OnSceneDisconnection()
266 TestCustomActor::OnSceneDisconnection();
269 Self().Add( mChildToAdd );
272 Dali::Actor mChildToAdd;
276 * Variant which removes children during OnSceneDisconnection
278 struct TestCustomActorVariant4 : public TestCustomActor
283 TestCustomActorVariant4()
287 // From CustomActorImpl
288 virtual void OnSceneDisconnection()
291 TestCustomActor::OnSceneDisconnection();
293 // Remove all the children
294 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
296 Self().Remove( Self().GetChildAt(0) );
302 * Variant which removes its parent from Stage during OnSceneConnection
304 struct TestCustomActorVariant5 : public TestCustomActor
309 TestCustomActorVariant5(Dali::Integration::Scene scene)
314 // From CustomActorImpl
315 virtual void OnSceneConnection( int depth )
318 TestCustomActor::OnSceneConnection( depth );
320 // Take parent off-stage
321 Dali::Actor parent = Self().GetParent();
324 mScene.Remove( parent );
329 Dali::Integration::Scene mScene;
333 * Variant which adds its parent to Stage during OnSceneDisconnection
335 struct TestCustomActorVariant6 : public TestCustomActor
340 TestCustomActorVariant6(Dali::Integration::Scene scene)
345 // From CustomActorImpl
346 virtual void OnSceneDisconnection()
349 TestCustomActor::OnSceneDisconnection();
351 // Put parent on-stage
352 Dali::Actor parent = Self().GetParent();
355 mScene.Add( parent );
360 Dali::Integration::Scene mScene;
364 * Variant which reparents its children into a separate container
366 struct TestCustomActorVariant7 : public TestCustomActor
371 TestCustomActorVariant7()
375 virtual void OnInitialize( const char* name )
377 // We need to do this early, before the OnChildAdd is recorded
378 Self().SetProperty( Dali::Actor::Property::NAME, name );
380 mContainer = Dali::Actor::New();
381 mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" );
382 Self().Add( mContainer );
385 // From CustomActorImpl
386 virtual void OnChildAdd(Dali::Actor& child)
389 TestCustomActor::OnChildAdd(child);
392 if ( child != mContainer )
394 mContainer.Add( child );
398 Dali::Actor mContainer;
402 * Variant which attempts to interfere with the reparenting of a child to another container
404 struct TestCustomActorVariant8 : public TestCustomActor
409 TestCustomActorVariant8( Dali::Actor rival )
410 : mRivalContainer( rival )
414 // From CustomActorImpl
415 virtual void OnChildRemove(Dali::Actor& child)
418 TestCustomActor::OnChildRemove(child);
420 mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
423 Dali::Actor mRivalContainer;
426 // Need a class that doesn't override virtual methods
427 class SimpleTestCustomActor : public Dali::CustomActorImpl
434 SimpleTestCustomActor()
435 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
442 virtual ~SimpleTestCustomActor()
446 // From CustomActorImpl
447 virtual void OnSceneConnection( int depth )
450 virtual void OnSceneDisconnection()
453 virtual void OnChildAdd(Dali::Actor& child)
456 virtual void OnChildRemove(Dali::Actor& child)
459 virtual void OnSizeSet(const Dali::Vector3& targetSize)
462 virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize)
465 virtual bool OnTouchEvent(const Dali::TouchEvent& event)
469 virtual bool OnHoverEvent(const Dali::HoverEvent& event)
473 virtual bool OnWheelEvent(const Dali::WheelEvent& event)
477 virtual bool OnKeyEvent(const Dali::KeyEvent& event)
481 virtual void OnKeyInputFocusGained()
484 virtual void OnKeyInputFocusLost()
488 virtual Dali::Vector3 GetNaturalSize()
490 return Dali::Vector3( 0.0f, 0.0f, 0.0f );
493 virtual float GetHeightForWidth( float width )
498 virtual float GetWidthForHeight( float height )
503 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container )
507 virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension )
511 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension )
515 virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension )
520 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension )
524 virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS )
533 #endif // TEST_CUSTOM_ACTOR_H