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/devel-api/object/property-helper-devel.h>
22 #include <dali/integration-api/scene.h>
23 #include <dali/public-api/dali-core.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);
98 namespace DevelTestCustomActor
104 TEST_PROPERTY1 = Test::TestCustomActor::Property::TEST_PROPERTY1,
105 TEST_PROPERTY2 = Test::TestCustomActor::Property::TEST_PROPERTY2,
106 DEVEL_TEST_PROPERTY3 = TEST_PROPERTY2 + 1,
107 DEVEL_TEST_PROPERTY4 = TEST_PROPERTY2 + 2,
108 DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2 + 3,
109 DEVEL_TEST_PROPERTY6 = TEST_PROPERTY2 + 4
112 } // Namespace Property
113 } // Namespace DevelTestCustomActor
115 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
118 struct TestCustomActor : public Dali::CustomActorImpl
125 TestCustomActor(bool nego);
126 virtual ~TestCustomActor();
127 void Initialize(const char* name = NULL);
128 virtual void OnInitialize(const char* name);
129 void ResetCallStack();
130 void AddToCallStacks(const char* method);
131 void OnSceneConnection(int depth) override;
132 void OnSceneDisconnection() override;
133 void OnChildAdd(Dali::Actor& child) override;
134 void OnChildRemove(Dali::Actor& child) override;
135 void OnPropertySet(Dali::Property::Index index, const Dali::Property::Value& propertyValue) override;
136 void OnSizeSet(const Dali::Vector3& targetSize) override;
137 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override;
138 virtual void OnKeyInputFocusGained();
139 virtual void OnKeyInputFocusLost();
140 Dali::Vector3 GetNaturalSize() override;
141 float GetHeightForWidth(float width) override;
142 float GetWidthForHeight(float height) override;
143 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override;
144 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override;
145 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override;
146 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override;
147 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override;
148 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override;
149 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
150 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index index);
152 void SetDaliProperty(std::string s);
153 void TestRelayoutRequest();
154 float TestGetHeightForWidthBase(float width);
155 float TestGetWidthForHeightBase(float height);
156 float TestCalculateChildSizeBase(const Dali::Actor& child, Dali::Dimension::Type dimension);
157 bool TestRelayoutDependentOnChildrenBase(Dali::Dimension::Type dimension);
160 Dali::Property::Index mDaliProperty;
161 std::vector<std::string> mMethodsCalled;
162 Dali::Vector3 mSizeSet;
163 Dali::Vector3 mTargetSize;
169 Dali::Vector4 develProp3;
175 inline TestCustomActor& GetImpl(Test::TestCustomActor& handle)
177 DALI_ASSERT_ALWAYS(handle);
178 Dali::RefObject& object = handle.GetImplementation();
179 return static_cast<TestCustomActor&>(object);
182 inline const TestCustomActor& GetImpl(const Test::TestCustomActor& handle)
184 DALI_ASSERT_ALWAYS(handle);
185 const Dali::RefObject& object = handle.GetImplementation();
186 return static_cast<const TestCustomActor&>(object);
190 * Variant which adds a new child during OnSceneConnection
192 struct TestCustomActorVariant1 : public TestCustomActor
197 TestCustomActorVariant1(Dali::Actor childToAdd)
198 : mChildToAdd(childToAdd)
202 // From CustomActorImpl
203 void OnSceneConnection(int depth) override
206 TestCustomActor::OnSceneConnection(depth);
209 Self().Add(mChildToAdd);
212 Dali::Actor mChildToAdd;
216 * Variant which removes children during OnSceneConnection
218 struct TestCustomActorVariant2 : public TestCustomActor
223 TestCustomActorVariant2()
227 // From CustomActorImpl
228 virtual void OnSceneConnection(int depth)
231 TestCustomActor::OnSceneConnection(depth);
233 // Remove all the children
234 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
236 Self().Remove(Self().GetChildAt(0));
242 * Variant which adds a new child during OnSceneDisconnection
244 struct TestCustomActorVariant3 : public TestCustomActor
249 TestCustomActorVariant3(Dali::Actor childToAdd)
250 : mChildToAdd(childToAdd)
254 // From CustomActorImpl
255 virtual void OnSceneDisconnection()
258 TestCustomActor::OnSceneDisconnection();
261 Self().Add(mChildToAdd);
264 Dali::Actor mChildToAdd;
268 * Variant which removes children during OnSceneDisconnection
270 struct TestCustomActorVariant4 : public TestCustomActor
275 TestCustomActorVariant4()
279 // From CustomActorImpl
280 virtual void OnSceneDisconnection()
283 TestCustomActor::OnSceneDisconnection();
285 // Remove all the children
286 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
288 Self().Remove(Self().GetChildAt(0));
294 * Variant which removes its parent from Stage during OnSceneConnection
296 struct TestCustomActorVariant5 : public TestCustomActor
301 TestCustomActorVariant5(Dali::Integration::Scene scene)
306 // From CustomActorImpl
307 virtual void OnSceneConnection(int depth)
310 TestCustomActor::OnSceneConnection(depth);
312 // Take parent off-stage
313 Dali::Actor parent = Self().GetParent();
316 mScene.Remove(parent);
321 Dali::Integration::Scene mScene;
325 * Variant which adds its parent to Stage during OnSceneDisconnection
327 struct TestCustomActorVariant6 : public TestCustomActor
332 TestCustomActorVariant6(Dali::Integration::Scene scene)
337 // From CustomActorImpl
338 virtual void OnSceneDisconnection()
341 TestCustomActor::OnSceneDisconnection();
343 // Put parent on-stage
344 Dali::Actor parent = Self().GetParent();
352 Dali::Integration::Scene mScene;
356 * Variant which reparents its children into a separate container
358 struct TestCustomActorVariant7 : public TestCustomActor
363 TestCustomActorVariant7()
367 virtual void OnInitialize(const char* name)
369 // We need to do this early, before the OnChildAdd is recorded
370 Self().SetProperty(Dali::Actor::Property::NAME, name);
372 mContainer = Dali::Actor::New();
373 mContainer.SetProperty(Dali::Actor::Property::NAME, "Container");
374 Self().Add(mContainer);
377 // From CustomActorImpl
378 virtual void OnChildAdd(Dali::Actor& child)
381 TestCustomActor::OnChildAdd(child);
384 if(child != mContainer)
386 mContainer.Add(child);
390 Dali::Actor mContainer;
394 * Variant which attempts to interfere with the reparenting of a child to another container
396 struct TestCustomActorVariant8 : public TestCustomActor
401 TestCustomActorVariant8(Dali::Actor rival)
402 : mRivalContainer(rival)
406 // From CustomActorImpl
407 virtual void OnChildRemove(Dali::Actor& child)
410 TestCustomActor::OnChildRemove(child);
412 mRivalContainer.Remove(child); // attempt to block reparenting to rival (should be a NOOP)
415 Dali::Actor mRivalContainer;
418 // Need a class that doesn't override virtual methods
419 class SimpleTestCustomActor : public Dali::CustomActorImpl
425 SimpleTestCustomActor()
426 : CustomActorImpl(ActorFlags(DISABLE_SIZE_NEGOTIATION))
433 virtual ~SimpleTestCustomActor()
437 // From CustomActorImpl
438 void OnSceneConnection(int depth) override
441 void OnSceneDisconnection() override
444 void OnChildAdd(Dali::Actor& child) override
447 void OnChildRemove(Dali::Actor& child) override
450 void OnSizeSet(const Dali::Vector3& targetSize) override
453 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override
456 virtual void OnKeyInputFocusGained()
459 virtual void OnKeyInputFocusLost()
462 Dali::Vector3 GetNaturalSize() override
464 return Dali::Vector3(0.0f, 0.0f, 0.0f);
467 float GetHeightForWidth(float width) override
472 float GetWidthForHeight(float height) override
477 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override
481 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override
485 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override
489 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override
494 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override
498 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override
507 #endif // TEST_CUSTOM_ACTOR_H