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