Processor interface moved from core.h
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / layout-controller-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUT_CONTROLLER_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUT_CONTROLLER_H
3
4 /*
5  * Copyright (c) 2019 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 #include <list>
20 #include <dali/public-api/object/base-object.h>
21 #include <dali/integration-api/processor-interface.h>
22 #include <dali-toolkit/public-api/controls/control.h>
23 #include <dali-toolkit/devel-api/layouting/layout-controller.h>
24 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
25 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
26 #include <dali-toolkit/internal/layouting/layout-transition-data-impl.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34
35 /**
36  * @brief Layout controller handles measurement and layout of all
37  * controls that utilize Layouts.
38  */
39 class LayoutController : public Dali::BaseObject, public Integration::Processor
40 {
41 public:
42   /**
43    * Constructor
44    */
45   LayoutController();
46
47   /**
48    * Destructor
49    */
50   ~LayoutController();
51
52   /**
53    * Second stage initialization
54    */
55   void Initialize();
56
57   /**
58    * This marks the given layout and all its parents as dirty and triggers a transition if set.
59    */
60   void RequestLayout( LayoutItem& layout, int layoutTransitionType, Actor gainedChild, Actor lostChild );
61
62   /**
63    * Measures next level of layouts in the actor hierarchy.
64    */
65   void MeasureHierarchy( Actor root, MeasureSpec widthSpec, MeasureSpec heightSpec );
66
67   /**
68    * Perform layout of the hierarchy
69    */
70   void PerformLayout( Actor root, int left, int top, int right, int bottom );
71
72   /**
73    * Perform positioning of actors after layout update
74    */
75   void PerformLayoutPositioning( LayoutPositionDataArray& layoutPositionDataArray, bool all ) const;
76
77   /**
78    * Perform animation of actors properties after layout update
79    */
80   void PerformLayoutAnimation( LayoutTransition& layoutTransition, LayoutPositionDataArray& layoutPositionDataArray, LayoutDataArray& layoutDataArray, LayoutAnimatorArray& layoutAnimatorArray );
81
82   /**
83    * Focus change callback.
84    */
85   void KeyInputFocusChangedCallback( Control gainingActor, Control lostActor );
86
87 protected: // Implementation of Processor
88
89   /**
90    * @copydoc Dali::Integration::Processor::Process()
91    */
92   virtual void Process();
93
94 private:
95   struct ActorSizeSpec
96   {
97     ActorSizeSpec(Actor actor)
98     : actor( actor )
99     , widthSpec( actor.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ) )
100     , heightSpec( actor.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ) )
101     {
102     }
103
104     WeakHandle<Actor> actor;
105     int widthSpec;
106     int heightSpec;
107   };
108   std::vector<ActorSizeSpec> mActorSizeSpecs;
109
110   void UpdateMeasureHierarchyForAnimation( LayoutData& layoutData );
111
112   void UpdateMeasureHierarchyForAnimation( Actor root, LayoutData& layoutData );
113
114   void RestoreActorsSpecs();
115
116   std::list< LayoutTransition > mLayoutTransitions;
117   struct AnimationFinishedFunctor
118   {
119     AnimationFinishedFunctor( LayoutController& layoutController, LayoutTransition& layoutTransition, LayoutPositionDataArray& array )
120     : layoutController( layoutController ),
121       layoutDataPositionArray(),
122       layoutItem( layoutTransition.layoutItem ),
123       layoutTransitionType( layoutTransition.layoutTransitionType )
124     {
125       layoutDataPositionArray.swap( array );
126     }
127
128     void operator()( Animation& animation )
129     {
130       layoutController.PerformLayoutPositioning( layoutDataPositionArray, true );
131       layoutController.mAnimationFinishedFunctors.pop_front();
132       if( layoutTransitionType != -1 )
133       {
134         LayoutTransitionDataPtr layoutTransitionDataPtr = layoutItem->GetTransitionData( layoutTransitionType );
135         layoutTransitionDataPtr->EmitSignalFinish( layoutTransitionType );
136       }
137     }
138
139     LayoutController& layoutController;
140     LayoutPositionDataArray layoutDataPositionArray;
141     LayoutItemPtr layoutItem;
142     int layoutTransitionType;
143   };
144
145   bool mLayoutRequested;
146   Animation mAnimation;
147   std::list< AnimationFinishedFunctor > mAnimationFinishedFunctors;
148
149   struct FocusChangedFunctor
150   {
151     FocusChangedFunctor( LayoutController& layoutController )
152     : layoutController( layoutController )
153     {
154     }
155
156     void operator() ( Dali::Toolkit::Control gainingControl, Dali::Toolkit::Control lostActor );
157     LayoutController& layoutController;
158   };
159   FocusChangedFunctor mFocusChangedFunctor;
160
161   SlotDelegate<LayoutController> mSlotDelegate;
162 };
163
164 } // namespace Internal
165
166 inline Internal::LayoutController& GetImpl( Dali::Toolkit::LayoutController& handle )
167 {
168   DALI_ASSERT_ALWAYS(handle);
169   Dali::BaseObject& object = handle.GetBaseObject();
170   return static_cast<Internal::LayoutController&>(object);
171 }
172
173 inline const Internal::LayoutController& GetImpl( const Dali::Toolkit::LayoutController& handle )
174 {
175   DALI_ASSERT_ALWAYS(handle);
176   const Dali::BaseObject& object = handle.GetBaseObject();
177   return static_cast<const Internal::LayoutController&>(object);
178 }
179
180 } // namespace Toolkit
181 } // namespace Dali
182
183 #endif // DALI_TOOLKIT_INTERNAL_LAYOUT_CONTROLLER_H