[AT-SPI] Rename AccessibleImpl to <Control>Accessible
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scrollable-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 // EXTERNAL INCLUDES
19 #include <dali/public-api/object/type-registry-helper.h>
20 #include <dali/public-api/object/type-registry.h>
21 #include <cstring> // for strcmp
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
25 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
26
27 using namespace Dali;
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 namespace
36 {
37 BaseHandle Create()
38 {
39   // empty handle as we cannot create Scrollable (but type registered for scroll signal)
40   return BaseHandle();
41 }
42
43 // Setup properties, signals and actions using the type-registry.
44 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::Scrollable, Toolkit::Control, Create);
45
46 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootEffectColor", VECTOR4, OVERSHOOT_EFFECT_COLOR)
47 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootAnimationSpeed", FLOAT, OVERSHOOT_ANIMATION_SPEED)
48 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootEnabled", BOOLEAN, OVERSHOOT_ENABLED)
49 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootSize", VECTOR2, OVERSHOOT_SIZE)
50 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollToAlphaFunction", INTEGER, SCROLL_TO_ALPHA_FUNCTION)
51
52 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollRelativePosition", VECTOR2, SCROLL_RELATIVE_POSITION)
53 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollPositionMin", VECTOR2, SCROLL_POSITION_MIN)
54 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMinX", SCROLL_POSITION_MIN_X, SCROLL_POSITION_MIN, 0)
55 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMinY", SCROLL_POSITION_MIN_Y, SCROLL_POSITION_MIN, 1)
56 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollPositionMax", VECTOR2, SCROLL_POSITION_MAX)
57 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMaxX", SCROLL_POSITION_MAX_X, SCROLL_POSITION_MAX, 0)
58 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMaxY", SCROLL_POSITION_MAX_Y, SCROLL_POSITION_MAX, 1)
59 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "canScrollVertical", BOOLEAN, CAN_SCROLL_VERTICAL)
60 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "canScrollHorizontal", BOOLEAN, CAN_SCROLL_HORIZONTAL)
61
62 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollStarted", SIGNAL_SCROLL_STARTED)
63 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollCompleted", SIGNAL_SCROLL_COMPLETED)
64 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollUpdated", SIGNAL_SCROLL_UPDATED)
65
66 DALI_TYPE_REGISTRATION_END()
67
68 const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
69 const float   DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
70 const Vector2 OVERSHOOT_DEFAULT_SIZE(720.0f, 42.0f);
71
72 } // namespace
73
74 ///////////////////////////////////////////////////////////////////////////////////////////////////
75 // Scrollable
76 ///////////////////////////////////////////////////////////////////////////////////////////////////
77
78 Scrollable::Scrollable(ControlBehaviour behaviourFlags)
79 : Control(ControlBehaviour(behaviourFlags)),
80   mOvershootEffectColor(DEFAULT_OVERSHOOT_COLOUR),
81   mOvershootAnimationSpeed(DEFAULT_OVERSHOOT_ANIMATION_SPEED),
82   mOvershootSize(OVERSHOOT_DEFAULT_SIZE),
83   mScrollToAlphaFunction(AlphaFunction::EASE_OUT),
84   mScrollStartedSignal(),
85   mScrollUpdatedSignal(),
86   mScrollCompletedSignal(),
87   mOvershootEnabled(true)
88 {
89 }
90
91 Scrollable::~Scrollable()
92 {
93 }
94
95 bool Scrollable::ScrollableAccessible::IsScrollable() const
96 {
97   return true;
98 }
99
100 void Scrollable::OnInitialize()
101 {
102   DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
103     return std::make_unique<ScrollableAccessible>(actor, Dali::Accessibility::Role::SCROLL_PANE);
104   });
105 }
106
107 bool Scrollable::IsOvershootEnabled() const
108 {
109   return mOvershootEnabled;
110 }
111
112 void Scrollable::SetOvershootEnabled(bool enable)
113 {
114   EnableScrollOvershoot(enable);
115   mOvershootEnabled = enable;
116 }
117
118 Vector4 Scrollable::GetOvershootEffectColor() const
119 {
120   return mOvershootEffectColor;
121 };
122
123 void Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
124 {
125   mOvershootAnimationSpeed = pixelsPerSecond;
126 }
127
128 float Scrollable::GetOvershootAnimationSpeed() const
129 {
130   return mOvershootAnimationSpeed;
131 };
132
133 const Vector2& Scrollable::GetOvershootSize() const
134 {
135   return mOvershootSize;
136 }
137
138 Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
139 {
140   return mScrollStartedSignal;
141 }
142
143 Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
144 {
145   return mScrollUpdatedSignal;
146 }
147
148 Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
149 {
150   return mScrollCompletedSignal;
151 }
152
153 bool Scrollable::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
154 {
155   Dali::BaseHandle handle(object);
156
157   bool                connected(true);
158   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(handle);
159
160   if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_STARTED))
161   {
162     scrollable.ScrollStartedSignal().Connect(tracker, functor);
163   }
164   else if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_UPDATED))
165   {
166     scrollable.ScrollUpdatedSignal().Connect(tracker, functor);
167   }
168   else if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_COMPLETED))
169   {
170     scrollable.ScrollCompletedSignal().Connect(tracker, functor);
171   }
172   else
173   {
174     // signalName does not match any signal
175     connected = false;
176   }
177
178   return connected;
179 }
180
181 void Scrollable::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
182 {
183   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Dali::BaseHandle(object));
184
185   if(scrollable)
186   {
187     Scrollable& scrollableImpl(GetImpl(scrollable));
188     switch(index)
189     {
190       case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
191       {
192         scrollableImpl.SetOvershootEffectColor(value.Get<Vector4>());
193         break;
194       }
195       case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
196       {
197         scrollableImpl.SetOvershootAnimationSpeed(value.Get<float>());
198         break;
199       }
200       case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
201       {
202         scrollableImpl.SetOvershootEnabled(value.Get<bool>());
203         break;
204       }
205       case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
206       {
207         scrollableImpl.SetOvershootSize(value.Get<Vector2>());
208         break;
209       }
210       case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
211       {
212         int alphaFunction = value.Get<int>();
213
214         if(alphaFunction >= AlphaFunction::DEFAULT &&
215            alphaFunction < AlphaFunction::COUNT)
216         {
217           scrollableImpl.mScrollToAlphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaFunction);
218         }
219         break;
220       }
221     }
222   }
223 }
224
225 Property::Value Scrollable::GetProperty(BaseObject* object, Property::Index index)
226 {
227   Property::Value value;
228
229   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Dali::BaseHandle(object));
230
231   if(scrollable)
232   {
233     Scrollable& scrollableImpl(GetImpl(scrollable));
234     switch(index)
235     {
236       case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
237       {
238         value = scrollableImpl.GetOvershootEffectColor();
239         break;
240       }
241       case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
242       {
243         value = scrollableImpl.GetOvershootAnimationSpeed();
244         break;
245       }
246       case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
247       {
248         value = scrollableImpl.IsOvershootEnabled();
249         break;
250       }
251       case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
252       {
253         value = scrollableImpl.mOvershootSize;
254         break;
255       }
256       case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
257       {
258         value = static_cast<int>(scrollableImpl.mScrollToAlphaFunction);
259         break;
260       }
261     }
262   }
263
264   return value;
265 }
266
267 } // namespace Internal
268
269 } // namespace Toolkit
270
271 } // namespace Dali