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 float GetHeightForWidth(float width) override;
144 float GetWidthForHeight(float height) override;
145 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override;
146 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override;
147 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override;
148 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override;
149 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override;
150 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override;
151 void SetTransparent(bool transparent);
152 bool IsTransparent() const;
153 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
154 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index index);
156 void SetDaliProperty(std::string s);
157 void TestRelayoutRequest();
158 float TestGetHeightForWidthBase(float width);
159 float TestGetWidthForHeightBase(float height);
160 float TestCalculateChildSizeBase(const Dali::Actor& child, Dali::Dimension::Type dimension);
161 bool TestRelayoutDependentOnChildrenBase(Dali::Dimension::Type dimension);
164 Dali::Property::Index mDaliProperty;
165 std::vector<std::string> mMethodsCalled;
166 Dali::Vector3 mSizeSet;
167 Dali::Vector3 mTargetSize;
173 Dali::Vector4 develProp3;
179 inline TestCustomActor& GetImpl(Test::TestCustomActor& handle)
181 DALI_ASSERT_ALWAYS(handle);
182 Dali::RefObject& object = handle.GetImplementation();
183 return static_cast<TestCustomActor&>(object);
186 inline const TestCustomActor& GetImpl(const Test::TestCustomActor& handle)
188 DALI_ASSERT_ALWAYS(handle);
189 const Dali::RefObject& object = handle.GetImplementation();
190 return static_cast<const TestCustomActor&>(object);
194 * Variant which adds a new child during OnSceneConnection
196 struct TestCustomActorVariant1 : public TestCustomActor
201 TestCustomActorVariant1(Dali::Actor childToAdd)
202 : mChildToAdd(childToAdd)
206 // From CustomActorImpl
207 void OnSceneConnection(int depth) override
210 TestCustomActor::OnSceneConnection(depth);
213 Self().Add(mChildToAdd);
216 Dali::Actor mChildToAdd;
220 * Variant which removes children during OnSceneConnection
222 struct TestCustomActorVariant2 : public TestCustomActor
227 TestCustomActorVariant2()
231 // From CustomActorImpl
232 virtual void OnSceneConnection(int depth)
235 TestCustomActor::OnSceneConnection(depth);
237 // Remove all the children
238 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
240 Self().Remove(Self().GetChildAt(0));
246 * Variant which adds a new child during OnSceneDisconnection
248 struct TestCustomActorVariant3 : public TestCustomActor
253 TestCustomActorVariant3(Dali::Actor childToAdd)
254 : mChildToAdd(childToAdd)
258 // From CustomActorImpl
259 virtual void OnSceneDisconnection()
262 TestCustomActor::OnSceneDisconnection();
265 Self().Add(mChildToAdd);
268 Dali::Actor mChildToAdd;
272 * Variant which removes children during OnSceneDisconnection
274 struct TestCustomActorVariant4 : public TestCustomActor
279 TestCustomActorVariant4()
283 // From CustomActorImpl
284 virtual void OnSceneDisconnection()
287 TestCustomActor::OnSceneDisconnection();
289 // Remove all the children
290 for(uint32_t i = 0, num = Self().GetChildCount(); i < num; ++i)
292 Self().Remove(Self().GetChildAt(0));
298 * Variant which removes its parent from Stage during OnSceneConnection
300 struct TestCustomActorVariant5 : public TestCustomActor
305 TestCustomActorVariant5(Dali::Integration::Scene scene)
310 // From CustomActorImpl
311 virtual void OnSceneConnection(int depth)
314 TestCustomActor::OnSceneConnection(depth);
316 // Take parent off-stage
317 Dali::Actor parent = Self().GetParent();
320 mScene.Remove(parent);
325 Dali::Integration::Scene mScene;
329 * Variant which adds its parent to Stage during OnSceneDisconnection
331 struct TestCustomActorVariant6 : public TestCustomActor
336 TestCustomActorVariant6(Dali::Integration::Scene scene)
341 // From CustomActorImpl
342 virtual void OnSceneDisconnection()
345 TestCustomActor::OnSceneDisconnection();
347 // Put parent on-stage
348 Dali::Actor parent = Self().GetParent();
356 Dali::Integration::Scene mScene;
360 * Variant which reparents its children into a separate container
362 struct TestCustomActorVariant7 : public TestCustomActor
367 TestCustomActorVariant7()
371 virtual void OnInitialize(const char* name)
373 // We need to do this early, before the OnChildAdd is recorded
374 Self().SetProperty(Dali::Actor::Property::NAME, name);
376 mContainer = Dali::Actor::New();
377 mContainer.SetProperty(Dali::Actor::Property::NAME, "Container");
378 Self().Add(mContainer);
381 // From CustomActorImpl
382 virtual void OnChildAdd(Dali::Actor& child)
385 TestCustomActor::OnChildAdd(child);
388 if(child != mContainer)
390 mContainer.Add(child);
394 Dali::Actor mContainer;
398 * Variant which attempts to interfere with the reparenting of a child to another container
400 struct TestCustomActorVariant8 : public TestCustomActor
405 TestCustomActorVariant8(Dali::Actor rival)
406 : mRivalContainer(rival)
410 // From CustomActorImpl
411 virtual void OnChildRemove(Dali::Actor& child)
414 TestCustomActor::OnChildRemove(child);
416 mRivalContainer.Remove(child); // attempt to block reparenting to rival (should be a NOOP)
419 Dali::Actor mRivalContainer;
422 // Need a class that doesn't override virtual methods
423 class SimpleTestCustomActor : public Dali::CustomActorImpl
429 SimpleTestCustomActor()
430 : CustomActorImpl(ActorFlags(DISABLE_SIZE_NEGOTIATION))
437 virtual ~SimpleTestCustomActor()
441 // From CustomActorImpl
442 void OnSceneConnection(int depth) override
445 void OnSceneDisconnection() override
448 void OnChildAdd(Dali::Actor& child) override
451 void OnChildRemove(Dali::Actor& child) override
454 void OnSizeSet(const Dali::Vector3& targetSize) override
457 void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize) override
460 virtual void OnKeyInputFocusGained()
463 virtual void OnKeyInputFocusLost()
466 Dali::Vector3 GetNaturalSize() override
468 return Dali::Vector3(0.0f, 0.0f, 0.0f);
471 float GetHeightForWidth(float width) override
476 float GetWidthForHeight(float height) override
481 void OnRelayout(const Dali::Vector2& size, Dali::RelayoutContainer& container) override
485 void OnSetResizePolicy(Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension) override
489 void OnCalculateRelayoutSize(Dali::Dimension::Type dimension) override
493 float CalculateChildSize(const Dali::Actor& child, Dali::Dimension::Type dimension) override
498 void OnLayoutNegotiated(float size, Dali::Dimension::Type dimension) override
502 bool RelayoutDependentOnChildren(Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS) override
511 #endif // TEST_CUSTOM_ACTOR_H