Tizen 2.1 base
[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 <FGrpRectangle.h>
20 #include <FUiAccessibilityTypes.h>
21 #include <FUiIAccessibilityListener.h>
22 #include <FBaseSysLog.h>
23 #include "FUi_AccessibilityContainer.h"
24 #include "FUi_AccessibilityElementImpl.h"
25 #include "FUi_AccessibilityElement.h"
26 #include "FUi_AccessibilityManager.h"
27 #include "FUi_Control.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui {
33
34 const wchar_t* _traitString[] =
35 {
36         L"",//ACCESSIBILITY_TRAITS_NONE,
37         L"TITLE",//ACCESSIBILITY_TRAITS_TITLE,
38         L"OPTION HEADER",//ACCESSIBILITY_TRAITS_OPTION_HEADER,
39         L"PICTURE",//ACCESSIBILITY_TRAITS_PICTURE,
40         L"STATUS BAR",//ACCESSIBILITY_TRAITS_STATUS_BAR,
41         L"TEXT FIELD",//ACCESSIBILITY_TRAITS_TEXT_FIELD,
42         L"RATING",//ACCESSIBILITY_TRAITS_RATING,
43         L"ACTION BAR",//ACCESSIBILITY_TRAITS_ACTION_BAR,
44         L"ACTION BAR MENU",//ACCESSIBILITY_TRAITS_ACTION_BAR_MENU,
45         L"BACK BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
46         L"BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
47         L"LABEL",//ACCESSIBILITY_TRAITS_LABEL,
48         L"LIST",//ACCESSIBILITY_TRAITS_LIST,
49         L"SELECTOR",//ACCESSIBILITY_TRAITS_DATA_SELECTOR,
50         L"SCROLL",//ACCESSIBILITY_TRAITS_DRAG_SCROLL,
51         L"EXPAND BUTTON",//ACCESSIBILITY_TRAITS_EXPAND_BUTTON,
52         L"FUNCTION PANEL",//ACCESSIBILITY_TRAITS_FUNCTION_PANEL,
53         L"IN DEPTH BUTTON",//ACCESSIBILITY_TRAITS_IN_DEPTH_BUTTON,
54         L"INDEX SCROLL",//ACCESSIBILITY_TRAITS_INDEX_SCROLL,
55         L"IMAGE",//ACCESSIBILITY_TRAITS_IMAGE
56         L"INDICATOR",//ACCESSIBILITY_TRAITS_INDICATOR,
57         L"NOTIFICATION",//ACCESSIBILITY_TRAITS_NOTIFICATION,
58         L"RADIO BUTTON",//ACCESSIBILITY_TRAITS_RADIO_BUTTON,
59         L"SCROLL BAR",//ACCESSIBILITY_TRAITS_SCROLL_BAR,
60         L"SEARCH FIELD",//ACCESSIBILITY_TRAITS_SEARCH_FIELD,
61         L"SEGMENT",//ACCESSIBILITY_TRAITS_SEGMENT,
62         L"SLIDER",//ACCESSIBILITY_TRAITS_SLIDER,
63         L"SOFT KEY",//ACCESSIBILITY_TRAITS_SOFT_KEY,
64         L"SUB MENU TITLE",//ACCESSIBILITY_TRAITS_SUB_MENU_TITLE,
65         L"TAB",//ACCESSIBILITY_TRAITS_TAB,
66         L"TICK BOX",//ACCESSIBILITY_TRAITS_TICKBOX,
67         L"TIME SELECTOR",//ACCESSIBILITY_TRAITS_TIME_SELECTOR,
68         L"VOLUME SLIDER",//ACCESSIBILITY_TRAITS_VOLUME_SLIDER,
69         L"HOUR",//ACCESSIBILITY_TRAITS_HOUR,
70         L"MINUTE",//ACCESSIBILITY_TRAITS_MINUTE,
71         L"SECOND",//ACCESSIBILITY_TRAITS_SECOND,
72         L"YEAR",//ACCESSIBILITY_TRAITS_YEAR,
73         L"MONTH",//ACCESSIBILITY_TRAITS_MONTH,
74         L"DAY",//ACCESSIBILITY_TRAITS_DAY,
75         L"END",//ACCESSIBILITY_TRAITS_END = 0xff
76 };
77
78
79 _AccessibilityElement::_AccessibilityElement(bool systemElement)
80         : __name(L"")
81         , __bounds(0,0,0,0)
82         , __absBounds(0,0,0,0)
83         , __label(L"")
84         , __hint(L"")
85         , __status(L"")
86         , __traitString(L"")
87         , __trait(ACCESSIBILITY_TRAITS_NONE)
88         , __value(L"")
89         , __pParent(null)
90         , __pUserData(null)
91         , __systemElement(systemElement)
92         , __activated(true)
93         , __supportOperatingGesture(true)
94 {
95 }
96 _AccessibilityElement::~_AccessibilityElement(void)
97 {
98         if (__pUserData)
99         {
100                 static_cast<_AccessibilityElementImpl*>(__pUserData)->SetCore(null);
101                 __pUserData = null;
102         }
103 }
104 result
105 _AccessibilityElement::Construct(const String& name, const Rectangle& bounds)
106 {
107         __name = name;
108         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
109         return E_SUCCESS;
110 }
111 void
112 _AccessibilityElement::SetName(const String& name)
113 {
114         __name = name;
115 }
116 void
117 _AccessibilityElement::SetLabel(const String& label)
118 {
119         __label = label;
120 }
121 void
122 _AccessibilityElement::SetHint(const String& hint)
123 {
124         __hint = hint;
125 }
126 void
127 _AccessibilityElement::SetStatus(const String& status)
128 {
129         __status = status;
130 }
131 void
132 _AccessibilityElement::SetTrait(AccessibilityTraits trait)
133 {
134         __trait = trait;
135         __traitString = (_traitString[__trait]);
136 }
137 void
138 _AccessibilityElement::SetTrait(const Tizen::Base::String& trait)
139 {
140         __traitString = trait;
141 }
142 void
143 _AccessibilityElement::SetParent(const _AccessibilityContainer& parent)
144 {
145         __pParent = &const_cast<_AccessibilityContainer&>(parent);
146 }
147 void
148 _AccessibilityElement::SetValue(const String& value)
149 {
150         __value = value;
151 }
152 _AccessibilityContainer*
153 _AccessibilityElement::GetParent(void) const
154 {
155         return __pParent;
156 }
157 String
158 _AccessibilityElement::GetName(void) const
159 {
160         return __name;
161 }
162 Rectangle
163 _AccessibilityElement::GetBounds(void) const
164 {
165         return __bounds;
166 }
167 String
168 _AccessibilityElement::GetLabel(void) const
169 {
170         return __label;
171 }
172 String
173 _AccessibilityElement::GetHint(void) const
174 {
175         return __hint;
176 }
177 String
178 _AccessibilityElement::GetStatus(void) const
179 {
180         return __status;
181 }
182 AccessibilityTraits
183 _AccessibilityElement::GetTrait(void) const
184 {
185         return __trait;
186 }
187 String
188 _AccessibilityElement::GetTraitString(void) const
189 {
190         return __traitString;
191 }
192 String
193 _AccessibilityElement::GetValue(void) const
194 {
195         return __value;
196 }
197 void
198 _AccessibilityElement::Activate(bool enable)
199 {
200         __activated = enable;
201         if(!enable)
202         {
203                 //__pParent->RemoveElement(*this);
204                 __pUserData = null;
205         }
206 }
207 bool
208 _AccessibilityElement::IsActivated(void) const
209 {
210         return __activated;
211 }
212 String
213 _AccessibilityElement::GetReadingContents(void) const
214 {
215         String out = L"";
216         if(__label.GetLength() > 0)
217         {
218                 out += __label;
219         }
220
221         if(__traitString.GetLength() > 0)
222         {
223                 out += L", ";
224                 out += __traitString;
225         }
226
227         if(__value.GetLength() > 0)
228         {
229                 out += L", ";
230                 out += __value;
231         }
232         if(__status.GetLength() > 0)
233         {
234                 out += L", ";
235                 out += __status;
236         }
237         if(__hint.GetLength() > 0)
238         {
239                 out += L", ";
240                 out += __hint;
241         }
242         if( __pParent->GetEnableState() == false)
243         {
244                 out += L", ";
245                 out += L"unavailable";
246         }
247
248         return out;
249 }
250 void
251 _AccessibilityElement::SetBounds(const Rectangle& bounds)
252 {
253         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
254         if(__pParent && this == __pParent->GetCurrentFocusedElement())
255         {
256                 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
257         }
258 }
259 Rectangle
260 _AccessibilityElement::GetAbsoluteBounds(void) const
261 {
262         Rectangle controlAbsBounds = GetParent()->GetOwner().GetAbsoluteBounds();
263         Rectangle rect(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
264         const_cast<Rectangle&>(__absBounds).SetBounds(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
265         return rect;
266 }
267 void
268 _AccessibilityElement::SetSupportOperatingGesture(bool set)
269 {
270         __supportOperatingGesture = set;
271 }
272 bool
273 _AccessibilityElement::GetSupportOperatingGesture(void)
274 {
275         return __supportOperatingGesture;
276 }
277 void*
278 _AccessibilityElement::GetUserData(void) const
279 {
280         return __pUserData;
281 }
282
283 void
284 _AccessibilityElement::SetUserData(void* pUserData)
285 {
286         __pUserData = pUserData;
287 }
288 bool
289 _AccessibilityElement::IsSystemElement(void)
290 {
291         return __systemElement;
292 }
293 }}