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

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

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
(...skipping 12 matching lines...) Expand all
23 bool BrowserAccessibilityAndroid::IsNative() const { 23 bool BrowserAccessibilityAndroid::IsNative() const {
24 return true; 24 return true;
25 } 25 }
26 26
27 bool BrowserAccessibilityAndroid::PlatformIsLeaf() 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() == blink::WebAXRoleRootWebArea ||
34 role() == WebKit::WebAXRoleWebArea) { 34 role() == blink::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() == blink::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(blink::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 BrowserAccessibility::PlatformIsLeaf(); 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() == blink::WebAXRoleCheckBox ||
64 role() == WebKit::WebAXRoleRadioButton || 64 role() == blink::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(blink::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(blink::WebAXStateChecked);
75 } 75 }
76 76
77 bool BrowserAccessibilityAndroid::IsClickable() const { 77 bool BrowserAccessibilityAndroid::IsClickable() const {
78 return (PlatformIsLeaf() && !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(blink::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(blink::WebAXStateFocusable);
87 if (IsIframe() || 87 if (IsIframe() ||
88 role() == WebKit::WebAXRoleWebArea) { 88 role() == blink::WebAXRoleWebArea) {
89 focusable = false; 89 focusable = false;
90 } 90 }
91 return focusable; 91 return focusable;
92 } 92 }
93 93
94 bool BrowserAccessibilityAndroid::IsFocused() const { 94 bool BrowserAccessibilityAndroid::IsFocused() const {
95 return manager()->GetFocus(manager()->GetRoot()) == this; 95 return manager()->GetFocus(manager()->GetRoot()) == this;
96 } 96 }
97 97
98 bool BrowserAccessibilityAndroid::IsPassword() const { 98 bool BrowserAccessibilityAndroid::IsPassword() const {
99 return HasState(WebKit::WebAXStateProtected); 99 return HasState(blink::WebAXStateProtected);
100 } 100 }
101 101
102 bool BrowserAccessibilityAndroid::IsScrollable() const { 102 bool BrowserAccessibilityAndroid::IsScrollable() const {
103 int dummy; 103 int dummy;
104 return GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &dummy); 104 return GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &dummy);
105 } 105 }
106 106
107 bool BrowserAccessibilityAndroid::IsSelected() const { 107 bool BrowserAccessibilityAndroid::IsSelected() const {
108 return HasState(WebKit::WebAXStateSelected); 108 return HasState(blink::WebAXStateSelected);
109 } 109 }
110 110
111 bool BrowserAccessibilityAndroid::IsVisibleToUser() const { 111 bool BrowserAccessibilityAndroid::IsVisibleToUser() const {
112 return !HasState(WebKit::WebAXStateInvisible); 112 return !HasState(blink::WebAXStateInvisible);
113 } 113 }
114 114
115 const char* BrowserAccessibilityAndroid::GetClassName() const { 115 const char* BrowserAccessibilityAndroid::GetClassName() const {
116 const char* class_name = NULL; 116 const char* class_name = NULL;
117 117
118 switch(role()) { 118 switch(role()) {
119 case WebKit::WebAXRoleEditableText: 119 case blink::WebAXRoleEditableText:
120 case WebKit::WebAXRoleSpinButton: 120 case blink::WebAXRoleSpinButton:
121 case WebKit::WebAXRoleTextArea: 121 case blink::WebAXRoleTextArea:
122 case WebKit::WebAXRoleTextField: 122 case blink::WebAXRoleTextField:
123 class_name = "android.widget.EditText"; 123 class_name = "android.widget.EditText";
124 break; 124 break;
125 case WebKit::WebAXRoleSlider: 125 case blink::WebAXRoleSlider:
126 class_name = "android.widget.SeekBar"; 126 class_name = "android.widget.SeekBar";
127 break; 127 break;
128 case WebKit::WebAXRoleComboBox: 128 case blink::WebAXRoleComboBox:
129 class_name = "android.widget.Spinner"; 129 class_name = "android.widget.Spinner";
130 break; 130 break;
131 case WebKit::WebAXRoleButton: 131 case blink::WebAXRoleButton:
132 case WebKit::WebAXRoleMenuButton: 132 case blink::WebAXRoleMenuButton:
133 case WebKit::WebAXRolePopUpButton: 133 case blink::WebAXRolePopUpButton:
134 class_name = "android.widget.Button"; 134 class_name = "android.widget.Button";
135 break; 135 break;
136 case WebKit::WebAXRoleCheckBox: 136 case blink::WebAXRoleCheckBox:
137 class_name = "android.widget.CheckBox"; 137 class_name = "android.widget.CheckBox";
138 break; 138 break;
139 case WebKit::WebAXRoleRadioButton: 139 case blink::WebAXRoleRadioButton:
140 class_name = "android.widget.RadioButton"; 140 class_name = "android.widget.RadioButton";
141 break; 141 break;
142 case WebKit::WebAXRoleToggleButton: 142 case blink::WebAXRoleToggleButton:
143 class_name = "android.widget.ToggleButton"; 143 class_name = "android.widget.ToggleButton";
144 break; 144 break;
145 case WebKit::WebAXRoleCanvas: 145 case blink::WebAXRoleCanvas:
146 case WebKit::WebAXRoleImage: 146 case blink::WebAXRoleImage:
147 class_name = "android.widget.Image"; 147 class_name = "android.widget.Image";
148 break; 148 break;
149 case WebKit::WebAXRoleProgressIndicator: 149 case blink::WebAXRoleProgressIndicator:
150 class_name = "android.widget.ProgressBar"; 150 class_name = "android.widget.ProgressBar";
151 break; 151 break;
152 case WebKit::WebAXRoleTabList: 152 case blink::WebAXRoleTabList:
153 class_name = "android.widget.TabWidget"; 153 class_name = "android.widget.TabWidget";
154 break; 154 break;
155 case WebKit::WebAXRoleGrid: 155 case blink::WebAXRoleGrid:
156 case WebKit::WebAXRoleTable: 156 case blink::WebAXRoleTable:
157 class_name = "android.widget.GridView"; 157 class_name = "android.widget.GridView";
158 break; 158 break;
159 case WebKit::WebAXRoleList: 159 case blink::WebAXRoleList:
160 case WebKit::WebAXRoleListBox: 160 case blink::WebAXRoleListBox:
161 class_name = "android.widget.ListView"; 161 class_name = "android.widget.ListView";
162 break; 162 break;
163 default: 163 default:
164 class_name = "android.view.View"; 164 class_name = "android.view.View";
165 break; 165 break;
166 } 166 }
167 167
168 return class_name; 168 return class_name;
169 } 169 }
170 170
171 string16 BrowserAccessibilityAndroid::GetText() const { 171 string16 BrowserAccessibilityAndroid::GetText() const {
172 if (IsIframe() || 172 if (IsIframe() ||
173 role() == WebKit::WebAXRoleWebArea) { 173 role() == blink::WebAXRoleWebArea) {
174 return string16(); 174 return string16();
175 } 175 }
176 176
177 string16 description = GetString16Attribute( 177 string16 description = GetString16Attribute(
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 < PlatformChildCount(); i++) { 188 for (uint32 i = 0; i < PlatformChildCount(); i++) {
189 BrowserAccessibility* child = PlatformGetChild(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 blink::WebAXRoleImageMapLink:
196 case WebKit::WebAXRoleLink: 196 case blink::WebAXRoleLink:
197 if (!text.empty()) 197 if (!text.empty())
198 text += ASCIIToUTF16(" "); 198 text += ASCIIToUTF16(" ");
199 text += ASCIIToUTF16("Link"); 199 text += ASCIIToUTF16("Link");
200 break; 200 break;
201 case WebKit::WebAXRoleHeading: 201 case blink::WebAXRoleHeading:
202 // Only append "heading" if this node already has text. 202 // Only append "heading" if this node already has text.
203 if (!text.empty()) 203 if (!text.empty())
204 text += ASCIIToUTF16(" Heading"); 204 text += ASCIIToUTF16(" Heading");
205 break; 205 break;
206 } 206 }
207 207
208 return text; 208 return text;
209 } 209 }
210 210
211 int BrowserAccessibilityAndroid::GetItemIndex() const { 211 int BrowserAccessibilityAndroid::GetItemIndex() const {
212 int index = 0; 212 int index = 0;
213 switch(role()) { 213 switch(role()) {
214 case WebKit::WebAXRoleListItem: 214 case blink::WebAXRoleListItem:
215 case WebKit::WebAXRoleListBoxOption: 215 case blink::WebAXRoleListBoxOption:
216 index = index_in_parent(); 216 index = index_in_parent();
217 break; 217 break;
218 case WebKit::WebAXRoleSlider: 218 case blink::WebAXRoleSlider:
219 case WebKit::WebAXRoleProgressIndicator: { 219 case blink::WebAXRoleProgressIndicator: {
220 float value_for_range; 220 float value_for_range;
221 if (GetFloatAttribute( 221 if (GetFloatAttribute(
222 AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &value_for_range)) { 222 AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &value_for_range)) {
223 index = static_cast<int>(value_for_range); 223 index = static_cast<int>(value_for_range);
224 } 224 }
225 break; 225 break;
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 blink::WebAXRoleList:
235 case WebKit::WebAXRoleListBox: 235 case blink::WebAXRoleListBox:
236 count = PlatformChildCount(); 236 count = PlatformChildCount();
237 break; 237 break;
238 case WebKit::WebAXRoleSlider: 238 case blink::WebAXRoleSlider:
239 case WebKit::WebAXRoleProgressIndicator: { 239 case blink::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 }
247 } 247 }
248 return count; 248 return count;
249 } 249 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 < PlatformChildCount(); i++) { 342 for (uint32 i = 0; i < PlatformChildCount(); i++) {
343 BrowserAccessibility* child = PlatformGetChild(i); 343 BrowserAccessibility* child = PlatformGetChild(i);
344 if (child->HasState(WebKit::WebAXStateFocusable)) 344 if (child->HasState(blink::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 < PlatformChildCount(); i++) { 353 for (uint32 i = 0; i < PlatformChildCount(); i++) {
354 BrowserAccessibility* child = PlatformGetChild(i); 354 BrowserAccessibility* child = PlatformGetChild(i);
355 if (child->role() != WebKit::WebAXRoleStaticText) 355 if (child->role() != blink::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");
365 } 365 }
366 366
367 void BrowserAccessibilityAndroid::PostInitialize() { 367 void BrowserAccessibilityAndroid::PostInitialize() {
368 BrowserAccessibility::PostInitialize(); 368 BrowserAccessibility::PostInitialize();
369 369
370 if (IsEditableText()) { 370 if (IsEditableText()) {
371 if (base::UTF8ToUTF16(value_) != new_value_) { 371 if (base::UTF8ToUTF16(value_) != new_value_) {
372 old_value_ = new_value_; 372 old_value_ = new_value_;
373 new_value_ = base::UTF8ToUTF16(value_); 373 new_value_ = base::UTF8ToUTF16(value_);
374 } 374 }
375 } 375 }
376 376
377 if (role_ == WebKit::WebAXRoleAlert && first_time_) 377 if (role_ == blink::WebAXRoleAlert && first_time_)
378 manager_->NotifyAccessibilityEvent(WebKit::WebAXEventAlert, this); 378 manager_->NotifyAccessibilityEvent(blink::WebAXEventAlert, this);
379 379
380 string16 live; 380 string16 live;
381 if (GetString16Attribute( 381 if (GetString16Attribute(
382 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) { 382 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) {
383 NotifyLiveRegionUpdate(live); 383 NotifyLiveRegionUpdate(live);
384 } 384 }
385 385
386 first_time_ = false; 386 first_time_ = false;
387 } 387 }
388 388
389 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { 389 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) {
390 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && 390 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) &&
391 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) 391 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive))
392 return; 392 return;
393 393
394 string16 text = GetText(); 394 string16 text = GetText();
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(blink::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
« no previous file with comments | « content/browser/accessibility/browser_accessibility.cc ('k') | content/browser/accessibility/browser_accessibility_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698