1 #ifndef TEST_CUSTOM_ACTOR_H
2 #define TEST_CUSTOM_ACTOR_H
5 * Copyright (c) 2021 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);
92 void SetTransparent(bool transparent);
96 TestCustomActor(Impl::TestCustomActor& impl);
97 explicit TestCustomActor(Dali::Internal::CustomActor* internal);
100 namespace DevelTestCustomActor
106 TEST_PROPERTY1 = Test::TestCustomActor::Property::TEST_PROPERTY1,
107 TEST_PROPERTY2 = Test::TestCustomActor::Property::TEST_PROPERTY2,
108 DEVEL_TEST_PROPERTY3 = TEST_PROPERTY2 + 1,
109 DEVEL_TEST_PROPERTY4 = TEST_PROPERTY2 + 2,
110 DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2 + 3,
111 DEVEL_TEST_PROPERTY6 = TEST_PROPERTY2 + 4
114 } // Namespace Property
115 } // Namespace DevelTestCustomActor
117 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
120 struct TestCustomActor : public Dali::CustomActorImpl
127 TestCustomActor(bool nego);
128 virtual ~TestCustomActor();
129 void Initialize(const char* name = NULL);
130 virtual void OnInitialize(const char* name);
131 void ResetCallStack();
132 void AddToCallStacks(const char* method);
133 void OnSceneConnection(int depth) override;
134 void OnSceneDisconnection() override;
135 void OnChildAdd(Dali::Actor& child) override;
136 void OnChildRemove(Dali::Actor& child) override;
137 void OnPropertySet(Dali::Property::Index index, const Dali::Property::Value& propertyValue) override;
138 void OnSizeSet(const Dali::Vector3& targetSize) override;
139 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override;
140 virtual void OnKeyInputFocusGained();
141 virtual void OnKeyInputFocusLost();
142 Dali::Vector3 GetNaturalSize() override;
143 void SetNaturalSize(const Dali::Vector3& size);
144 void SetHeightForWidthFactor(float factor)
148 void SetWidthForHeightFactor(float factor)
152 float GetHeightForWidth(float width) override;
153 float GetWidthForHeight(float height) override;
154 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override;
155 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override;
156 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override;
157 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override;
158 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override;
159 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override;
160 void SetTransparent(bool transparent);
161 bool IsTransparent() const;
162 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
163 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index index);
165 void SetDaliProperty(std::string s);
166 void TestRelayoutRequest();
167 float TestGetHeightForWidthBase(float width);
168 float TestGetWidthForHeightBase(float height);
169 float TestCalculateChildSizeBase(const Dali::Actor& child, Dali::Dimension::Type dimension);
170 bool TestRelayoutDependentOnChildrenBase(Dali::Dimension::Type dimension);
173 Dali::Property::Index mDaliProperty;
174 std::vector<std::string> mMethodsCalled;
175 Dali::Vector3 mNaturalSize;
176 Dali::Vector3 mSizeSet;
177 Dali::Vector3 mTargetSize;
185 Dali::Vector4 develProp3;
191 inline TestCustomActor& GetImpl(Test::TestCustomActor& handle)
193 DALI_ASSERT_ALWAYS(handle);
194 Dali::RefObject& object = handle.GetImplementation();
195 return static_cast<TestCustomActor&>(object);
198 inline const TestCustomActor& GetImpl(const Test::TestCustomActor& handle)
200 DALI_ASSERT_ALWAYS(handle);
201 const Dali::RefObject& object = handle.GetImplementation();
202 return static_cast<const TestCustomActor&>(object);
206 * Variant which adds a new child during OnSceneConnection
208 struct TestCustomActorVariant1 : public TestCustomActor
213 TestCustomActorVariant1(Dali::Actor childToAdd)
214 : mChildToAdd(childToAdd)
218 // From CustomActorImpl
219 void OnSceneConnection(int depth) override
222 TestCustomActor::OnSceneConnection(depth);
225 Self().Add(mChildToAdd);
228 Dali::Actor mChildToAdd;
232 * Variant which removes children during OnSceneConnection
234 struct TestCustomActorVariant2 : public TestCustomActor
239 TestCustomActorVariant2()
243 // From CustomActorImpl
244 virtual void OnSceneConnection(int depth)
247 TestCustomActor::OnSceneConnection(depth);
249 // Remove all the children
250 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
252 Self().Remove(Self().GetChildAt(0));
258 * Variant which adds a new child during OnSceneDisconnection
260 struct TestCustomActorVariant3 : public TestCustomActor
265 TestCustomActorVariant3(Dali::Actor childToAdd)
266 : mChildToAdd(childToAdd)
270 // From CustomActorImpl
271 virtual void OnSceneDisconnection()
274 TestCustomActor::OnSceneDisconnection();
277 Self().Add(mChildToAdd);
280 Dali::Actor mChildToAdd;
284 * Variant which removes children during OnSceneDisconnection
286 struct TestCustomActorVariant4 : public TestCustomActor
291 TestCustomActorVariant4()
295 // From CustomActorImpl
296 virtual void OnSceneDisconnection()
299 TestCustomActor::OnSceneDisconnection();
301 // Remove all the children
302 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
304 Self().Remove(Self().GetChildAt(0));
310 * Variant which removes its parent from Stage during OnSceneConnection
312 struct TestCustomActorVariant5 : public TestCustomActor
317 TestCustomActorVariant5(Dali::Integration::Scene scene)
322 // From CustomActorImpl
323 virtual void OnSceneConnection(int depth)
326 TestCustomActor::OnSceneConnection(depth);
328 // Take parent off-stage
329 Dali::Actor parent = Self().GetParent();
332 mScene.Remove(parent);
337 Dali::Integration::Scene mScene;
341 * Variant which adds its parent to Stage during OnSceneDisconnection
343 struct TestCustomActorVariant6 : public TestCustomActor
348 TestCustomActorVariant6(Dali::Integration::Scene scene)
353 // From CustomActorImpl
354 virtual void OnSceneDisconnection()
357 TestCustomActor::OnSceneDisconnection();
359 // Put parent on-stage
360 Dali::Actor parent = Self().GetParent();
368 Dali::Integration::Scene mScene;
372 * Variant which reparents its children into a separate container
374 struct TestCustomActorVariant7 : public TestCustomActor
379 TestCustomActorVariant7()
383 virtual void OnInitialize(const char* name)
385 // We need to do this early, before the OnChildAdd is recorded
386 Self().SetProperty(Dali::Actor::Property::NAME, name);
388 mContainer = Dali::Actor::New();
389 mContainer.SetProperty(Dali::Actor::Property::NAME, "Container");
390 Self().Add(mContainer);
393 // From CustomActorImpl
394 virtual void OnChildAdd(Dali::Actor& child)
397 TestCustomActor::OnChildAdd(child);
400 if(child != mContainer)
402 mContainer.Add(child);
406 Dali::Actor mContainer;
410 * Variant which attempts to interfere with the reparenting of a child to another container
412 struct TestCustomActorVariant8 : public TestCustomActor
417 TestCustomActorVariant8(Dali::Actor rival)
418 : mRivalContainer(rival)
422 // From CustomActorImpl
423 virtual void OnChildRemove(Dali::Actor& child)
426 TestCustomActor::OnChildRemove(child);
428 mRivalContainer.Remove(child); // attempt to block reparenting to rival (should be a NOOP)
431 Dali::Actor mRivalContainer;
434 // Need a class that doesn't override virtual methods
435 class SimpleTestCustomActor : public Dali::CustomActorImpl
441 SimpleTestCustomActor()
442 : CustomActorImpl(ActorFlags(DISABLE_SIZE_NEGOTIATION))
449 virtual ~SimpleTestCustomActor()
453 // From CustomActorImpl
454 void OnSceneConnection(int depth) override
457 void OnSceneDisconnection() override
460 void OnChildAdd(Dali::Actor& child) override
463 void OnChildRemove(Dali::Actor& child) override
466 void OnSizeSet(const Dali::Vector3& targetSize) override
469 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override
472 virtual void OnKeyInputFocusGained()
475 virtual void OnKeyInputFocusLost()
478 Dali::Vector3 GetNaturalSize() override
480 return Dali::Vector3(0.0f, 0.0f, 0.0f);
483 float GetHeightForWidth(float width) override
488 float GetWidthForHeight(float height) override
493 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override
497 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override
501 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override
505 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override
510 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override
514 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override
523 #endif // TEST_CUSTOM_ACTOR_H