Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.h
1 #ifndef __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
2 #define __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/size-negotiation/relayout-container.h>
25 #include <dali/internal/common/memory-pool-object-allocator.h>
26 #include <dali/internal/event/size-negotiation/memory-pool-relayout-container.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 /**
35  * @brief The relayout controller is responsible for taking request from actors to relayout their sizes.
36  * The requests are actioned on at the end of the frame where all actors that have made a request are
37  * resized.
38  */
39 class RelayoutController : public Dali::BaseObject
40 {
41 public:
42
43   /**
44    * @brief Constructor.
45    * We should only create a unique instance.
46    */
47   RelayoutController();
48
49   /**
50    * Destructor
51    */
52   virtual ~RelayoutController();
53
54   /**
55    * @brief Get the singleton of RelayoutController object.
56    *
57    * @return A handle to the RelayoutController control.
58    */
59   static RelayoutController* Get();
60
61   /**
62    * @brief Request to relayout the given actor and all sub-actors of it.
63    *
64    * This flags the actor and all actors dependent on it for relayout. The actual
65    * relayout is performed at the end of the frame. This means that multiple calls to relayout
66    * will not cause multiple relayouts to occur.
67    *
68    * @param[in] actor The actor to request relayout on
69    * @param[in] dimension The dimension(s) to request the relayout on. Defaults to all dimensions
70    */
71   void RequestRelayout( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
72
73   /**
74    * @brief Request to relayout of all actors in the sub-tree below the given actor.
75    *
76    * This flags the actor and all actors below it for relayout. The actual
77    * relayout is performed at the end of the frame. This means that multiple calls to relayout
78    * will not cause multiple relayouts to occur.
79    *
80    * @param[in] actor The actor to request relayout on
81    */
82   void RequestRelayoutTree( Dali::Actor& actor );
83
84   /**
85    * @brief Force propagate relayout flags through the tree. This is similiar to Request Relayout
86    * except all dependencies have their flags reset in spite of whether they are all ready set.
87    *
88    * This is useful for resetting layout flags during the layout process.
89    *
90    * @param[in] actor The actor to propagate from
91    * @param[in] dimension The dimension to propagate on
92    */
93   void PropagateFlags( Dali::Actor& actor, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
94
95   /**
96    * @brief Relayouts all actors that have been marked as dirty
97    */
98   void Relayout();
99
100   /**
101    * @brief Enable/disable the controller
102    *
103    * @param[in] enabled Flag to indicate whether the controller should be enabled or disabled
104    */
105   void SetEnabled( bool enabled );
106
107   /**
108    * @brief Return true if the relayout controller is currently performing a relayout
109    *
110    * @return Return true if the relayout controller is currently performing a relayout
111    */
112   bool IsPerformingRelayout() const;
113
114 public: // CALLBACKS
115
116   /**
117    * @brief Callback raised after the application creates the scene
118    */
119   void OnApplicationSceneCreated();
120
121   /**
122    * @brief Callback for when an object is destroyed
123    *
124    * @param[in] object The object being destroyed
125    */
126   void OnObjectDestroyed( const Dali::RefObject* object );
127
128 private:
129
130   typedef Dali::Vector< BaseObject* > RawActorList;
131
132   /**
133    * @brief Request for relayout. Relays out whole scene.
134    */
135   void Request();
136
137   /**
138    * @brief Add actor to request list
139    *
140    * @param[in] actor The root of the sub tree to add
141    */
142   void AddRequest( Dali::Actor& actor );
143
144   /**
145    * @brief Remove actor from request list
146    *
147    * @param[in] actor The root of the sub tree to remove
148    */
149   void RemoveRequest( Dali::Actor& actor );
150
151   /**
152    * @brief Disconnect the Relayout() method from the Stage::EventProcessingFinishedSignal().
153    */
154   void Disconnect();
155
156   /**
157    * @brief Propagate dirty layout flags to actor and all sub-actors. This will stop propagating when a dirty actor
158    * is found.
159    *
160    * @param[in] actor The actor to propagate on
161    * @param[in] dimension The dimension to propagate on
162    * @param[in] topOfSubTreeStack The top of the sub tree that this actor is in
163    * @param[in] potentialRedundantSubRoots Actors collected as potentially already being included in relayout
164    */
165   void PropagateAll( Dali::Actor& actor, Dimension::Type dimension, std::vector< Dali::Actor >& topOfSubTreeStack, std::vector< Dali::Actor >& potentialRedundantSubRoots );
166
167   /**
168    * Queue an actor on the relayout container
169    *
170    * @param[in] actor The actor to be queued
171    * @param[in] actors The container to add the actor to
172    * @param[in] size The size that this actor should be
173    */
174   void QueueActor( Dali::Actor& actor, RelayoutContainer& actors, Vector2 size );
175
176   /**
177    * @brief Find the given object in the list and null it out
178    *
179    * @param[in] list The list to search
180    * @param[in] object The object to search for
181    */
182   void FindAndZero( const RawActorList& list, const Dali::RefObject* object );
183
184   // Undefined
185   RelayoutController(const RelayoutController&);
186   RelayoutController& operator=(const RelayoutController&);
187
188 private:
189
190   MemoryPoolObjectAllocator< MemoryPoolRelayoutContainer::RelayoutInfo > mRelayoutInfoAllocator;
191
192   SlotDelegate< RelayoutController > mSlotDelegate;
193
194   RawActorList mDirtyLayoutSubTrees;    ///< List of roots of sub trees that are dirty
195   MemoryPoolRelayoutContainer* mRelayoutStack;  ///< Stack for relayouting
196   bool mRelayoutConnection : 1;         ///< Whether EventProcessingFinishedSignal signal is connected.
197   bool mRelayoutFlag : 1;               ///< Relayout flag to avoid unnecessary calls
198   bool mEnabled : 1;                    ///< Initially disabled. Must be enabled at some point.
199   bool mPerformingRelayout : 1;         ///< The relayout controller is currently performing a relayout
200
201 };
202
203 } // namespace Internal
204
205 } // namespace Dali
206
207 #endif // __DALI_INTERNAL_RELAYOUT_CONTROLLER_IMPL_H__