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