Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / FUi_AccessibilityElement.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FBaseString.h>
19 #include <FUiAccessibilityTypes.h>
20 #include <FUiIAccessibilityListener.h>
21 #include <FBaseSysLog.h>
22 #include "FUi_AccessibilityContainer.h"
23 #include "FUi_AccessibilityElementImpl.h"
24 #include "FUi_AccessibilityElement.h"
25 #include "FUi_AccessibilityManager.h"
26 #include "FUi_Control.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30
31 namespace Tizen { namespace Ui {
32
33 const wchar_t* _traitString[] =
34 {
35         L"",//ACCESSIBILITY_TRAITS_NONE,
36         L"TITLE",//ACCESSIBILITY_TRAITS_TITLE,
37         L"OPTION HEADER",//ACCESSIBILITY_TRAITS_OPTION_HEADER,
38         L"PICTURE",//ACCESSIBILITY_TRAITS_PICTURE,
39         L"STATUS BAR",//ACCESSIBILITY_TRAITS_STATUS_BAR,
40         L"TEXT FIELD",//ACCESSIBILITY_TRAITS_TEXT_FIELD,
41         L"RATING",//ACCESSIBILITY_TRAITS_RATING,
42         L"ACTION BAR",//ACCESSIBILITY_TRAITS_ACTION_BAR,
43         L"ACTION BAR MENU",//ACCESSIBILITY_TRAITS_ACTION_BAR_MENU,
44         L"BACK BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
45         L"BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
46         L"LABEL",//ACCESSIBILITY_TRAITS_LABEL,
47         L"LIST",//ACCESSIBILITY_TRAITS_LIST,
48         L"SELECTOR",//ACCESSIBILITY_TRAITS_DATA_SELECTOR,
49         L"SCROLL",//ACCESSIBILITY_TRAITS_DRAG_SCROLL,
50         L"EXPAND BUTTON",//ACCESSIBILITY_TRAITS_EXPAND_BUTTON,
51         L"FUNCTION PANEL",//ACCESSIBILITY_TRAITS_FUNCTION_PANEL,
52         L"IN DEPTH BUTTON",//ACCESSIBILITY_TRAITS_IN_DEPTH_BUTTON,
53         L"INDEX SCROLL",//ACCESSIBILITY_TRAITS_INDEX_SCROLL,
54         L"IMAGE",//ACCESSIBILITY_TRAITS_IMAGE
55         L"INDICATOR",//ACCESSIBILITY_TRAITS_INDICATOR,
56         L"NOTIFICATION",//ACCESSIBILITY_TRAITS_NOTIFICATION,
57         L"RADIO BUTTON",//ACCESSIBILITY_TRAITS_RADIO_BUTTON,
58         L"SCROLL BAR",//ACCESSIBILITY_TRAITS_SCROLL_BAR,
59         L"SEARCH FIELD",//ACCESSIBILITY_TRAITS_SEARCH_FIELD,
60         L"SEGMENT",//ACCESSIBILITY_TRAITS_SEGMENT,
61         L"SLIDER",//ACCESSIBILITY_TRAITS_SLIDER,
62         L"SOFT KEY",//ACCESSIBILITY_TRAITS_SOFT_KEY,
63         L"SUB MENU TITLE",//ACCESSIBILITY_TRAITS_SUB_MENU_TITLE,
64         L"TAB",//ACCESSIBILITY_TRAITS_TAB,
65         L"TICK BOX",//ACCESSIBILITY_TRAITS_TICKBOX,
66         L"TIME SELECTOR",//ACCESSIBILITY_TRAITS_TIME_SELECTOR,
67         L"VOLUME SLIDER",//ACCESSIBILITY_TRAITS_VOLUME_SLIDER,
68         L"HOUR",//ACCESSIBILITY_TRAITS_HOUR,
69         L"MINUTE",//ACCESSIBILITY_TRAITS_MINUTE,
70         L"SECOND",//ACCESSIBILITY_TRAITS_SECOND,
71         L"YEAR",//ACCESSIBILITY_TRAITS_YEAR,
72         L"MONTH",//ACCESSIBILITY_TRAITS_MONTH,
73         L"DAY",//ACCESSIBILITY_TRAITS_DAY,
74         L"END",//ACCESSIBILITY_TRAITS_END = 0xff
75 };
76
77
78 _AccessibilityElement::_AccessibilityElement(bool systemElement)
79         : __name(L"")
80         , __bounds(0,0,0,0)
81         , __absBounds(0,0,0,0)
82         , __label(L"")
83         , __hint(L"")
84         , __status(L"")
85         , __traitString(L"")
86         , __trait(ACCESSIBILITY_TRAITS_NONE)
87         , __value(L"")
88         , __pParent(null)
89         , __pUserData(null)
90         , __systemElement(systemElement)
91         , __activated(true)
92         , __supportOperatingGesture(true)
93         , __setHintByUser(false)
94         , __disabledHint(false)
95         , __updateContents(false)
96 {
97 }
98 _AccessibilityElement::~_AccessibilityElement(void)
99 {
100         if (__pUserData)
101         {
102                 static_cast<_AccessibilityElementImpl*>(__pUserData)->SetCore(null);
103                 __pUserData = null;
104         }
105 }
106 result
107 _AccessibilityElement::Construct(const String& name, const FloatRectangle& bounds)
108 {
109         __name = name;
110         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
111         return E_SUCCESS;
112 }
113 result
114 _AccessibilityElement::Construct(const String& name, const Rectangle& bounds)
115 {
116         __name = name;
117         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
118         return E_SUCCESS;
119 }
120 void
121 _AccessibilityElement::SetName(const String& name)
122 {
123         __name = name;
124 }
125 void
126 _AccessibilityElement::SetLabel(const String& label)
127 {
128         __label = label;
129         __updateContents = true;
130 }
131 void
132 _AccessibilityElement::SetHint(const String& hint, bool setHintByUser)
133 {
134         if(__setHintByUser && !setHintByUser)
135         {
136                 return;
137         }
138         __hint = hint;
139         __setHintByUser = setHintByUser;
140         __updateContents = true;
141 }
142 void
143 _AccessibilityElement::SetStatus(const String& status)
144 {
145         __status = status;
146         __updateContents = true;
147 }
148 void
149 _AccessibilityElement::SetTrait(AccessibilityTraits trait)
150 {
151         __trait = trait;
152         __traitString = (_traitString[__trait]);
153         __updateContents = true;
154 }
155 void
156 _AccessibilityElement::SetTrait(const Tizen::Base::String& trait)
157 {
158         __traitString = trait;
159         __updateContents = true;
160 }
161 void
162 _AccessibilityElement::SetParent(const _AccessibilityContainer& parent)
163 {
164         __pParent = &const_cast<_AccessibilityContainer&>(parent);
165 }
166 void
167 _AccessibilityElement::SetValue(const String& value)
168 {
169         __value = value;
170         __updateContents = true;
171 }
172 _AccessibilityContainer*
173 _AccessibilityElement::GetParent(void) const
174 {
175         return __pParent;
176 }
177 String
178 _AccessibilityElement::GetName(void) const
179 {
180         return __name;
181 }
182 FloatRectangle
183 _AccessibilityElement::GetBounds(void) const
184 {
185         return __bounds;
186 }
187 String
188 _AccessibilityElement::GetLabel(void) const
189 {
190         return __label;
191 }
192 String
193 _AccessibilityElement::GetHint(void) const
194 {
195         return __hint;
196 }
197 String
198 _AccessibilityElement::GetStatus(void) const
199 {
200         return __status;
201 }
202 AccessibilityTraits
203 _AccessibilityElement::GetTrait(void) const
204 {
205         return __trait;
206 }
207 String
208 _AccessibilityElement::GetTraitString(void) const
209 {
210         return __traitString;
211 }
212 String
213 _AccessibilityElement::GetValue(void) const
214 {
215         return __value;
216 }
217 void
218 _AccessibilityElement::SetHintDisabled(bool enable)
219 {
220         __disabledHint = enable;
221 }
222 void
223 _AccessibilityElement::Activate(bool enable)
224 {
225         __activated = enable;
226         if(!enable)
227         {
228         //      __pParent->RemoveElement(*this);
229                 __pUserData = null;
230         }
231 }
232 bool
233 _AccessibilityElement::IsActivated(void) const
234 {
235         return __activated;
236 }
237 String
238 _AccessibilityElement::GetReadingContents(void) const
239 {
240         String out = L"";
241         if(__label.GetLength() > 0)
242         {
243                 out += __label;
244         }
245
246         if(__traitString.GetLength() > 0)
247         {
248                 out += L", ";
249                 out += __traitString;
250         }
251
252         if(__value.GetLength() > 0)
253         {
254                 out += L", ";
255                 out += __value;
256         }
257         if(__status.GetLength() > 0)
258         {
259                 out += L", ";
260                 out += __status;
261         }
262         if(__hint.GetLength() > 0 && !__disabledHint && __pParent->GetEnableState())
263         {
264                 out += L", ";
265                 out += __hint;
266         }
267         if(__pParent->GetEnableState() == false)
268         {
269                 out += L", ";
270                 out += L"disable";
271         }
272         const_cast<_AccessibilityElement*>(this)->__updateContents = false;
273         return out;
274 }
275 void
276 _AccessibilityElement::SetBounds(const FloatRectangle& bounds)
277 {
278         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
279         if(__pParent && this == __pParent->GetCurrentFocusedElement())
280         {
281                 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
282         }
283 }
284
285 void
286 _AccessibilityElement::SetBounds(const Tizen::Graphics::Rectangle& bounds)
287 {
288         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
289         if(__pParent && this == __pParent->GetCurrentFocusedElement())
290         {
291                 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
292         }
293 }
294
295 FloatRectangle
296 _AccessibilityElement::GetAbsoluteBounds(void) const
297 {
298         FloatRectangle controlAbsBounds = GetParent()->GetOwner().GetAbsoluteBoundsF();
299         FloatRectangle rect(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
300         const_cast<FloatRectangle&>(__absBounds).SetBounds(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
301         return rect;
302 }
303 void
304 _AccessibilityElement::SetSupportOperatingGesture(bool set)
305 {
306         __supportOperatingGesture = set;
307 }
308 bool
309 _AccessibilityElement::GetSupportOperatingGesture(void)
310 {
311         return __supportOperatingGesture;
312 }
313 void*
314 _AccessibilityElement::GetUserData(void) const
315 {
316         return __pUserData;
317 }
318
319 void
320 _AccessibilityElement::SetUserData(void* pUserData)
321 {
322         __pUserData = pUserData;
323 }
324 bool
325 _AccessibilityElement::IsSystemElement(void)
326 {
327         return __systemElement;
328 }
329 bool
330 _AccessibilityElement::IsUpdated(void)
331 {
332         return __updateContents;
333 }
334 }}