Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: content/browser/accessibility/browser_accessibility_android.cc

Issue 25943003: Support accessible inline text boxes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/accessibility/browser_accessibility_android.h" 5 #include "content/browser/accessibility/browser_accessibility_android.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/accessibility/browser_accessibility_manager_android.h" 8 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
9 #include "content/common/accessibility_messages.h" 9 #include "content/common/accessibility_messages.h"
10 #include "content/common/accessibility_node_data.h" 10 #include "content/common/accessibility_node_data.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 // static 14 // static
15 BrowserAccessibility* BrowserAccessibility::Create() { 15 BrowserAccessibility* BrowserAccessibility::Create() {
16 return new BrowserAccessibilityAndroid(); 16 return new BrowserAccessibilityAndroid();
17 } 17 }
18 18
19 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() { 19 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() {
20 first_time_ = true; 20 first_time_ = true;
21 } 21 }
22 22
23 bool BrowserAccessibilityAndroid::IsNative() const { 23 bool BrowserAccessibilityAndroid::IsNative() const {
24 return true; 24 return true;
25 } 25 }
26 26
27 bool BrowserAccessibilityAndroid::IsLeaf() const { 27 bool BrowserAccessibilityAndroid::PlatformIsLeaf() const {
28 if (child_count() == 0) 28 if (child_count() == 0)
29 return true; 29 return true;
30 30
31 // Iframes are always allowed to contain children. 31 // Iframes are always allowed to contain children.
32 if (IsIframe() || 32 if (IsIframe() ||
33 role() == WebKit::WebAXRoleRootWebArea || 33 role() == WebKit::WebAXRoleRootWebArea ||
34 role() == WebKit::WebAXRoleWebArea) { 34 role() == WebKit::WebAXRoleWebArea) {
35 return false; 35 return false;
36 } 36 }
37 37
38 // If it has a focusable child, we definitely can't leave out children. 38 // If it has a focusable child, we definitely can't leave out children.
39 if (HasFocusableChild()) 39 if (HasFocusableChild())
40 return false; 40 return false;
41 41
42 // Headings with text can drop their children. 42 // Headings with text can drop their children.
43 string16 name = GetText(); 43 string16 name = GetText();
44 if (role() == WebKit::WebAXRoleHeading && !name.empty()) 44 if (role() == WebKit::WebAXRoleHeading && !name.empty())
45 return true; 45 return true;
46 46
47 // Focusable nodes with text can drop their children. 47 // Focusable nodes with text can drop their children.
48 if (HasState(WebKit::WebAXStateFocusable) && !name.empty()) 48 if (HasState(WebKit::WebAXStateFocusable) && !name.empty())
49 return true; 49 return true;
50 50
51 // Nodes with only static text as children can drop their children. 51 // Nodes with only static text as children can drop their children.
52 if (HasOnlyStaticTextChildren()) 52 if (HasOnlyStaticTextChildren())
53 return true; 53 return true;
54 54
55 return false; 55 return BrowserAccessibility::PlatformIsLeaf();
56 } 56 }
57 57
58 bool BrowserAccessibilityAndroid::IsCheckable() const { 58 bool BrowserAccessibilityAndroid::IsCheckable() const {
59 bool checkable = false; 59 bool checkable = false;
60 bool is_aria_pressed_defined; 60 bool is_aria_pressed_defined;
61 bool is_mixed; 61 bool is_mixed;
62 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); 62 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed);
63 if (role() == WebKit::WebAXRoleCheckBox || 63 if (role() == WebKit::WebAXRoleCheckBox ||
64 role() == WebKit::WebAXRoleRadioButton || 64 role() == WebKit::WebAXRoleRadioButton ||
65 is_aria_pressed_defined) { 65 is_aria_pressed_defined) {
66 checkable = true; 66 checkable = true;
67 } 67 }
68 if (HasState(WebKit::WebAXStateChecked)) 68 if (HasState(WebKit::WebAXStateChecked))
69 checkable = true; 69 checkable = true;
70 return checkable; 70 return checkable;
71 } 71 }
72 72
73 bool BrowserAccessibilityAndroid::IsChecked() const { 73 bool BrowserAccessibilityAndroid::IsChecked() const {
74 return HasState(WebKit::WebAXStateChecked); 74 return HasState(WebKit::WebAXStateChecked);
75 } 75 }
76 76
77 bool BrowserAccessibilityAndroid::IsClickable() const { 77 bool BrowserAccessibilityAndroid::IsClickable() const {
78 return (IsLeaf() && !GetText().empty()); 78 return (PlatformIsLeaf() && !GetText().empty());
79 } 79 }
80 80
81 bool BrowserAccessibilityAndroid::IsEnabled() const { 81 bool BrowserAccessibilityAndroid::IsEnabled() const {
82 return HasState(WebKit::WebAXStateEnabled); 82 return HasState(WebKit::WebAXStateEnabled);
83 } 83 }
84 84
85 bool BrowserAccessibilityAndroid::IsFocusable() const { 85 bool BrowserAccessibilityAndroid::IsFocusable() const {
86 bool focusable = HasState(WebKit::WebAXStateFocusable); 86 bool focusable = HasState(WebKit::WebAXStateFocusable);
87 if (IsIframe() || 87 if (IsIframe() ||
88 role() == WebKit::WebAXRoleWebArea) { 88 role() == WebKit::WebAXRoleWebArea) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 AccessibilityNodeData::ATTR_DESCRIPTION); 178 AccessibilityNodeData::ATTR_DESCRIPTION);
179 string16 text; 179 string16 text;
180 if (!name().empty()) 180 if (!name().empty())
181 text = base::UTF8ToUTF16(name()); 181 text = base::UTF8ToUTF16(name());
182 else if (!description.empty()) 182 else if (!description.empty())
183 text = description; 183 text = description;
184 else if (!value().empty()) 184 else if (!value().empty())
185 text = base::UTF8ToUTF16(value()); 185 text = base::UTF8ToUTF16(value());
186 186
187 if (text.empty() && HasOnlyStaticTextChildren()) { 187 if (text.empty() && HasOnlyStaticTextChildren()) {
188 for (uint32 i = 0; i < child_count(); i++) { 188 for (uint32 i = 0; i < PlatformChildCount(); i++) {
189 BrowserAccessibility* child = GetChild(i); 189 BrowserAccessibility* child = PlatformGetChild(i);
190 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); 190 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText();
191 } 191 }
192 } 192 }
193 193
194 switch(role()) { 194 switch(role()) {
195 case WebKit::WebAXRoleImageMapLink: 195 case WebKit::WebAXRoleImageMapLink:
196 case WebKit::WebAXRoleLink: 196 case WebKit::WebAXRoleLink:
197 if (!text.empty()) 197 if (!text.empty())
198 text += ASCIIToUTF16(" "); 198 text += ASCIIToUTF16(" ");
199 text += ASCIIToUTF16("Link"); 199 text += ASCIIToUTF16("Link");
(...skipping 26 matching lines...) Expand all
226 } 226 }
227 } 227 }
228 return index; 228 return index;
229 } 229 }
230 230
231 int BrowserAccessibilityAndroid::GetItemCount() const { 231 int BrowserAccessibilityAndroid::GetItemCount() const {
232 int count = 0; 232 int count = 0;
233 switch(role()) { 233 switch(role()) {
234 case WebKit::WebAXRoleList: 234 case WebKit::WebAXRoleList:
235 case WebKit::WebAXRoleListBox: 235 case WebKit::WebAXRoleListBox:
236 count = child_count(); 236 count = PlatformChildCount();
237 break; 237 break;
238 case WebKit::WebAXRoleSlider: 238 case WebKit::WebAXRoleSlider:
239 case WebKit::WebAXRoleProgressIndicator: { 239 case WebKit::WebAXRoleProgressIndicator: {
240 float max_value_for_range; 240 float max_value_for_range;
241 if (GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE, 241 if (GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE,
242 &max_value_for_range)) { 242 &max_value_for_range)) {
243 count = static_cast<int>(max_value_for_range); 243 count = static_cast<int>(max_value_for_range);
244 } 244 }
245 break; 245 break;
246 } 246 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 int sel_end = 0; 332 int sel_end = 0;
333 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &sel_end); 333 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &sel_end);
334 return sel_end; 334 return sel_end;
335 } 335 }
336 336
337 int BrowserAccessibilityAndroid::GetEditableTextLength() const { 337 int BrowserAccessibilityAndroid::GetEditableTextLength() const {
338 return value().length(); 338 return value().length();
339 } 339 }
340 340
341 bool BrowserAccessibilityAndroid::HasFocusableChild() const { 341 bool BrowserAccessibilityAndroid::HasFocusableChild() const {
342 for (uint32 i = 0; i < child_count(); i++) { 342 for (uint32 i = 0; i < PlatformChildCount(); i++) {
343 BrowserAccessibility* child = GetChild(i); 343 BrowserAccessibility* child = PlatformGetChild(i);
344 if (child->HasState(WebKit::WebAXStateFocusable)) 344 if (child->HasState(WebKit::WebAXStateFocusable))
345 return true; 345 return true;
346 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) 346 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild())
347 return true; 347 return true;
348 } 348 }
349 return false; 349 return false;
350 } 350 }
351 351
352 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { 352 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const {
353 for (uint32 i = 0; i < child_count(); i++) { 353 for (uint32 i = 0; i < PlatformChildCount(); i++) {
354 BrowserAccessibility* child = GetChild(i); 354 BrowserAccessibility* child = PlatformGetChild(i);
355 if (child->role() != WebKit::WebAXRoleStaticText) 355 if (child->role() != WebKit::WebAXRoleStaticText)
356 return false; 356 return false;
357 } 357 }
358 return true; 358 return true;
359 } 359 }
360 360
361 bool BrowserAccessibilityAndroid::IsIframe() const { 361 bool BrowserAccessibilityAndroid::IsIframe() const {
362 string16 html_tag = GetString16Attribute( 362 string16 html_tag = GetString16Attribute(
363 AccessibilityNodeData::ATTR_HTML_TAG); 363 AccessibilityNodeData::ATTR_HTML_TAG);
364 return html_tag == ASCIIToUTF16("iframe"); 364 return html_tag == ASCIIToUTF16("iframe");
(...skipping 30 matching lines...) Expand all
395 if (cached_text_ != text) { 395 if (cached_text_ != text) {
396 if (!text.empty()) { 396 if (!text.empty()) {
397 manager_->NotifyAccessibilityEvent(WebKit::WebAXEventShow, 397 manager_->NotifyAccessibilityEvent(WebKit::WebAXEventShow,
398 this); 398 this);
399 } 399 }
400 cached_text_ = text; 400 cached_text_ = text;
401 } 401 }
402 } 402 }
403 403
404 } // namespace content 404 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698