[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-base-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-base-impl.h>
20
21 using namespace Dali;
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 // ScrollBase
34 ///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 ScrollBase::ScrollBase( ControlBehaviour behaviourFlags )
37 : Scrollable( behaviourFlags ),
38   mParent(NULL),
39   mDelay(0.0f)
40 {
41 }
42
43 void ScrollBase::SetParent(ScrollBase *parent)
44 {
45   mParent = parent;
46 }
47
48 void ScrollBase::BindActor(Actor child)
49 {
50   FindAndUnbindActor(child);
51
52   ActorInfoPtr actorInfo(new ActorInfo(child));
53   mBoundActors.push_back(actorInfo);
54
55   // Apply all our constraints to this new child.
56   ConstraintStack::iterator i;
57
58   for(i = mConstraintStack.begin();i!=mConstraintStack.end();i++)
59   {
60     actorInfo->ApplyConstraint(*i);
61   }
62 }
63
64 void ScrollBase::UnbindActor(Actor child)
65 {
66   // Find the child in mBoundActors, and unparent it
67   for (ActorInfoIter iter = mBoundActors.begin(); iter != mBoundActors.end(); ++iter)
68   {
69     ActorInfoPtr actorInfo = *iter;
70
71     if( actorInfo->mActor == child )
72     {
73       mBoundActors.erase(iter);
74       break;
75     }
76   }
77 }
78
79 void ScrollBase::FindAndUnbindActor(Actor child)
80 {
81   // Since we don't know if and where child may have been bound
82   // (as we cannot store such information inside the Actor), we
83   // perform a search on all associated ScrollBases
84   // This is done by recursively calling the parent of this ScrollBase
85   // until reaching the top (at which point implementation may be
86   // different as this is virtual)
87
88   if(mParent) // continuously ascend until reaches root ScrollBase.
89   {
90     mParent->FindAndUnbindActor(child);
91   }
92 }
93
94 void ScrollBase::ApplyConstraintToBoundActors(Constraint constraint)
95 {
96   mConstraintStack.push_back(constraint);
97
98   for(ActorInfoIter i = mBoundActors.begin();i != mBoundActors.end(); ++i)
99   {
100     (*i)->ApplyConstraint(constraint);
101   }
102 }
103
104 void ScrollBase::RemoveConstraintsFromBoundActors()
105 {
106   mConstraintStack.clear();
107
108   for(ActorInfoIter i = mBoundActors.begin();i != mBoundActors.end(); ++i)
109   {
110     (*i)->RemoveConstraints();
111   }
112 }
113
114 } // namespace Internal
115
116 } // namespace Toolkit
117
118 } // namespace Dali