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
3 // found in the LICENSE file.
5 #include "content/browser/accessibility/browser_accessibility_android.h"
7 #include "base/i18n/break_iterator.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
12 #include "content/common/accessibility_messages.h"
16 // These are enums from android.text.InputType in Java:
18 ANDROID_TEXT_INPUTTYPE_TYPE_NULL
= 0,
19 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME
= 0x4,
20 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE
= 0x14,
21 ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME
= 0x24,
22 ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER
= 0x2,
23 ANDROID_TEXT_INPUTTYPE_TYPE_PHONE
= 0x3,
24 ANDROID_TEXT_INPUTTYPE_TYPE_TEXT
= 0x1,
25 ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI
= 0x11,
26 ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EDIT_TEXT
= 0xa1,
27 ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL
= 0xd1,
28 ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_PASSWORD
= 0xe1
31 // These are enums from android.view.View in Java:
33 ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE
= 0,
34 ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE
= 1,
35 ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE
= 2
38 // These are enums from
39 // android.view.accessibility.AccessibilityNodeInfo.RangeInfo in Java:
41 ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT
= 1
49 BrowserAccessibility
* BrowserAccessibility::Create() {
50 return new BrowserAccessibilityAndroid();
53 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() {
57 bool BrowserAccessibilityAndroid::IsNative() const {
61 void BrowserAccessibilityAndroid::OnLocationChanged() {
62 manager()->NotifyAccessibilityEvent(ui::AX_EVENT_LOCATION_CHANGED
, this);
65 bool BrowserAccessibilityAndroid::PlatformIsLeaf() const {
66 if (InternalChildCount() == 0)
69 // Iframes are always allowed to contain children.
71 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA
||
72 GetRole() == ui::AX_ROLE_WEB_AREA
) {
76 // If it has a focusable child, we definitely can't leave out children.
77 if (HasFocusableChild())
80 // Date and time controls should drop their children.
81 if (GetRole() == ui::AX_ROLE_DATE
|| GetRole() == ui::AX_ROLE_TIME
)
84 // Headings with text can drop their children.
85 base::string16 name
= GetText();
86 if (GetRole() == ui::AX_ROLE_HEADING
&& !name
.empty())
89 // Focusable nodes with text can drop their children.
90 if (HasState(ui::AX_STATE_FOCUSABLE
) && !name
.empty())
93 // Nodes with only static text as children can drop their children.
94 if (HasOnlyStaticTextChildren())
97 return BrowserAccessibility::PlatformIsLeaf();
100 bool BrowserAccessibilityAndroid::CanScrollForward() const {
104 float value
= GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
);
105 float max
= GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
);
109 bool BrowserAccessibilityAndroid::CanScrollBackward() const {
113 float value
= GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
);
114 float min
= GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
);
118 bool BrowserAccessibilityAndroid::IsCheckable() const {
119 bool checkable
= false;
120 bool is_aria_pressed_defined
;
122 GetAriaTristate("aria-pressed", &is_aria_pressed_defined
, &is_mixed
);
123 if (GetRole() == ui::AX_ROLE_CHECK_BOX
||
124 GetRole() == ui::AX_ROLE_RADIO_BUTTON
||
125 GetRole() == ui::AX_ROLE_MENU_ITEM_CHECK_BOX
||
126 GetRole() == ui::AX_ROLE_MENU_ITEM_RADIO
||
127 is_aria_pressed_defined
) {
130 if (HasState(ui::AX_STATE_CHECKED
))
135 bool BrowserAccessibilityAndroid::IsChecked() const {
136 return (HasState(ui::AX_STATE_CHECKED
) || HasState(ui::AX_STATE_PRESSED
));
139 bool BrowserAccessibilityAndroid::IsClickable() const {
140 if (!PlatformIsLeaf())
143 return IsFocusable() || !GetText().empty();
146 bool BrowserAccessibilityAndroid::IsCollection() const {
147 return (GetRole() == ui::AX_ROLE_GRID
||
148 GetRole() == ui::AX_ROLE_LIST
||
149 GetRole() == ui::AX_ROLE_LIST_BOX
||
150 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST
||
151 GetRole() == ui::AX_ROLE_TABLE
||
152 GetRole() == ui::AX_ROLE_TREE
);
155 bool BrowserAccessibilityAndroid::IsCollectionItem() const {
156 return (GetRole() == ui::AX_ROLE_CELL
||
157 GetRole() == ui::AX_ROLE_COLUMN_HEADER
||
158 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST_TERM
||
159 GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
||
160 GetRole() == ui::AX_ROLE_LIST_ITEM
||
161 GetRole() == ui::AX_ROLE_ROW_HEADER
||
162 GetRole() == ui::AX_ROLE_TREE_ITEM
);
165 bool BrowserAccessibilityAndroid::IsContentInvalid() const {
167 return GetHtmlAttribute("aria-invalid", &invalid
);
170 bool BrowserAccessibilityAndroid::IsDismissable() const {
171 return false; // No concept of "dismissable" on the web currently.
174 bool BrowserAccessibilityAndroid::IsEditableText() const {
175 return GetRole() == ui::AX_ROLE_TEXT_FIELD
;
178 bool BrowserAccessibilityAndroid::IsEnabled() const {
179 return HasState(ui::AX_STATE_ENABLED
);
182 bool BrowserAccessibilityAndroid::IsFocusable() const {
183 bool focusable
= HasState(ui::AX_STATE_FOCUSABLE
);
185 GetRole() == ui::AX_ROLE_WEB_AREA
) {
191 bool BrowserAccessibilityAndroid::IsFocused() const {
192 return manager()->GetFocus(manager()->GetRoot()) == this;
195 bool BrowserAccessibilityAndroid::IsHeading() const {
196 BrowserAccessibilityAndroid
* parent
=
197 static_cast<BrowserAccessibilityAndroid
*>(GetParent());
198 if (parent
&& parent
->IsHeading())
201 return (GetRole() == ui::AX_ROLE_COLUMN_HEADER
||
202 GetRole() == ui::AX_ROLE_HEADING
||
203 GetRole() == ui::AX_ROLE_ROW_HEADER
);
206 bool BrowserAccessibilityAndroid::IsHierarchical() const {
207 return (GetRole() == ui::AX_ROLE_LIST
||
208 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST
||
209 GetRole() == ui::AX_ROLE_TREE
);
212 bool BrowserAccessibilityAndroid::IsLink() const {
213 return (GetRole() == ui::AX_ROLE_LINK
||
214 GetRole() == ui::AX_ROLE_IMAGE_MAP_LINK
);
217 bool BrowserAccessibilityAndroid::IsMultiLine() const {
218 return HasState(ui::AX_STATE_MULTILINE
);
221 bool BrowserAccessibilityAndroid::IsPassword() const {
222 return HasState(ui::AX_STATE_PROTECTED
);
225 bool BrowserAccessibilityAndroid::IsRangeType() const {
226 return (GetRole() == ui::AX_ROLE_PROGRESS_INDICATOR
||
227 GetRole() == ui::AX_ROLE_METER
||
228 GetRole() == ui::AX_ROLE_SCROLL_BAR
||
229 GetRole() == ui::AX_ROLE_SLIDER
);
232 bool BrowserAccessibilityAndroid::IsScrollable() const {
234 return GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX
, &dummy
);
237 bool BrowserAccessibilityAndroid::IsSelected() const {
238 return HasState(ui::AX_STATE_SELECTED
);
241 bool BrowserAccessibilityAndroid::IsSlider() const {
242 return GetRole() == ui::AX_ROLE_SLIDER
;
245 bool BrowserAccessibilityAndroid::IsVisibleToUser() const {
246 return !HasState(ui::AX_STATE_INVISIBLE
);
249 bool BrowserAccessibilityAndroid::CanOpenPopup() const {
250 return HasState(ui::AX_STATE_HASPOPUP
);
253 const char* BrowserAccessibilityAndroid::GetClassName() const {
254 const char* class_name
= NULL
;
257 case ui::AX_ROLE_SEARCH_BOX
:
258 case ui::AX_ROLE_SPIN_BUTTON
:
259 case ui::AX_ROLE_TEXT_FIELD
:
260 class_name
= "android.widget.EditText";
262 case ui::AX_ROLE_SLIDER
:
263 class_name
= "android.widget.SeekBar";
265 case ui::AX_ROLE_COLOR_WELL
:
266 case ui::AX_ROLE_COMBO_BOX
:
267 case ui::AX_ROLE_DATE
:
268 case ui::AX_ROLE_POP_UP_BUTTON
:
269 case ui::AX_ROLE_TIME
:
270 class_name
= "android.widget.Spinner";
272 case ui::AX_ROLE_BUTTON
:
273 case ui::AX_ROLE_MENU_BUTTON
:
274 class_name
= "android.widget.Button";
276 case ui::AX_ROLE_CHECK_BOX
:
277 case ui::AX_ROLE_SWITCH
:
278 class_name
= "android.widget.CheckBox";
280 case ui::AX_ROLE_RADIO_BUTTON
:
281 class_name
= "android.widget.RadioButton";
283 case ui::AX_ROLE_TOGGLE_BUTTON
:
284 class_name
= "android.widget.ToggleButton";
286 case ui::AX_ROLE_CANVAS
:
287 case ui::AX_ROLE_IMAGE
:
288 case ui::AX_ROLE_SVG_ROOT
:
289 class_name
= "android.widget.Image";
291 case ui::AX_ROLE_METER
:
292 case ui::AX_ROLE_PROGRESS_INDICATOR
:
293 class_name
= "android.widget.ProgressBar";
295 case ui::AX_ROLE_TAB_LIST
:
296 class_name
= "android.widget.TabWidget";
298 case ui::AX_ROLE_GRID
:
299 case ui::AX_ROLE_TABLE
:
300 class_name
= "android.widget.GridView";
302 case ui::AX_ROLE_LIST
:
303 case ui::AX_ROLE_LIST_BOX
:
304 case ui::AX_ROLE_DESCRIPTION_LIST
:
305 class_name
= "android.widget.ListView";
307 case ui::AX_ROLE_DIALOG
:
308 class_name
= "android.app.Dialog";
310 case ui::AX_ROLE_ROOT_WEB_AREA
:
311 class_name
= "android.webkit.WebView";
313 case ui::AX_ROLE_MENU_ITEM
:
314 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX
:
315 case ui::AX_ROLE_MENU_ITEM_RADIO
:
316 class_name
= "android.view.MenuItem";
319 class_name
= "android.view.View";
326 base::string16
BrowserAccessibilityAndroid::GetText() const {
328 GetRole() == ui::AX_ROLE_WEB_AREA
) {
329 return base::string16();
332 // See comment in browser_accessibility_win.cc for details.
333 // The difference here is that we can only expose one accessible
334 // name on Android, not 2 or 3 like on Windows or Mac.
336 // First, always return the |value| attribute if this is an
338 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
339 if (!value
.empty()) {
340 if (HasState(ui::AX_STATE_EDITABLE
))
344 case ui::AX_ROLE_COMBO_BOX
:
345 case ui::AX_ROLE_POP_UP_BUTTON
:
346 case ui::AX_ROLE_TEXT_FIELD
:
351 // For color wells, the color is stored in separate attributes.
352 // Perhaps we could return color names in the future?
353 if (GetRole() == ui::AX_ROLE_COLOR_WELL
) {
354 int red
= GetIntAttribute(ui::AX_ATTR_COLOR_VALUE_RED
);
355 int green
= GetIntAttribute(ui::AX_ATTR_COLOR_VALUE_GREEN
);
356 int blue
= GetIntAttribute(ui::AX_ATTR_COLOR_VALUE_BLUE
);
357 return base::UTF8ToUTF16(
358 base::StringPrintf("#%02X%02X%02X", red
, green
, blue
));
361 // Always prefer visible text if this is a link. Sites sometimes add
362 // a "title" attribute to a link with more information, but we can't
363 // lose the link text.
364 base::string16 name
= GetString16Attribute(ui::AX_ATTR_NAME
);
365 if (!name
.empty() && GetRole() == ui::AX_ROLE_LINK
)
368 // If there's no text value, the basic rule is: prefer description
369 // (aria-labelledby or aria-label), then help (title), then name
370 // (inner text), then value (control value). However, if
371 // title_elem_id is set, that means there's a label element
372 // supplying the name and then name takes precedence over help.
373 // TODO(dmazzoni): clean this up by providing more granular labels in
374 // Blink, making the platform-specific mapping to accessible text simpler.
375 base::string16 description
= GetString16Attribute(ui::AX_ATTR_DESCRIPTION
);
376 base::string16 help
= GetString16Attribute(ui::AX_ATTR_HELP
);
378 base::string16 placeholder
;
380 case ui::AX_ROLE_DATE
:
381 case ui::AX_ROLE_TEXT_FIELD
:
382 case ui::AX_ROLE_TIME
:
383 GetHtmlAttribute("placeholder", &placeholder
);
386 int title_elem_id
= GetIntAttribute(
387 ui::AX_ATTR_TITLE_UI_ELEMENT
);
389 if (!description
.empty())
391 else if (title_elem_id
&& !name
.empty())
393 else if (!help
.empty())
395 else if (!name
.empty())
397 else if (!placeholder
.empty())
399 else if (!value
.empty())
401 else if (title_elem_id
) {
402 BrowserAccessibility
* title_elem
=
403 manager()->GetFromID(title_elem_id
);
405 text
= static_cast<BrowserAccessibilityAndroid
*>(title_elem
)->GetText();
408 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
411 (HasOnlyStaticTextChildren() ||
412 (IsFocusable() && HasOnlyTextAndImageChildren()))) {
413 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
414 BrowserAccessibility
* child
= InternalGetChild(i
);
415 text
+= static_cast<BrowserAccessibilityAndroid
*>(child
)->GetText();
419 if (text
.empty() && (IsLink() || GetRole() == ui::AX_ROLE_IMAGE
)) {
420 base::string16 url
= GetString16Attribute(ui::AX_ATTR_URL
);
421 // Given a url like http://foo.com/bar/baz.png, just return the
422 // base name, e.g., "baz".
423 int trailing_slashes
= 0;
424 while (url
.size() - trailing_slashes
> 0 &&
425 url
[url
.size() - trailing_slashes
- 1] == '/') {
428 if (trailing_slashes
)
429 url
= url
.substr(0, url
.size() - trailing_slashes
);
430 size_t slash_index
= url
.rfind('/');
431 if (slash_index
!= std::string::npos
)
432 url
= url
.substr(slash_index
+ 1);
433 size_t dot_index
= url
.rfind('.');
434 if (dot_index
!= std::string::npos
)
435 url
= url
.substr(0, dot_index
);
442 int BrowserAccessibilityAndroid::GetItemIndex() const {
445 case ui::AX_ROLE_LIST_ITEM
:
446 case ui::AX_ROLE_LIST_BOX_OPTION
:
447 case ui::AX_ROLE_TREE_ITEM
:
448 index
= GetIndexInParent();
450 case ui::AX_ROLE_SLIDER
:
451 case ui::AX_ROLE_PROGRESS_INDICATOR
: {
452 // Return a percentage here for live feedback in an AccessibilityEvent.
453 // The exact value is returned in RangeCurrentValue.
454 float min
= GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
);
455 float max
= GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
);
456 float value
= GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
);
457 if (max
> min
&& value
>= min
&& value
<= max
)
458 index
= static_cast<int>(((value
- min
)) * 100 / (max
- min
));
465 int BrowserAccessibilityAndroid::GetItemCount() const {
468 case ui::AX_ROLE_LIST
:
469 case ui::AX_ROLE_LIST_BOX
:
470 case ui::AX_ROLE_DESCRIPTION_LIST
:
471 count
= PlatformChildCount();
473 case ui::AX_ROLE_SLIDER
:
474 case ui::AX_ROLE_PROGRESS_INDICATOR
:
475 // An AccessibilityEvent can only return integer information about a
476 // seek control, so we return a percentage. The real range is returned
477 // in RangeMin and RangeMax.
484 int BrowserAccessibilityAndroid::GetScrollX() const {
486 GetIntAttribute(ui::AX_ATTR_SCROLL_X
, &value
);
490 int BrowserAccessibilityAndroid::GetScrollY() const {
492 GetIntAttribute(ui::AX_ATTR_SCROLL_Y
, &value
);
496 int BrowserAccessibilityAndroid::GetMaxScrollX() const {
498 GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX
, &value
);
502 int BrowserAccessibilityAndroid::GetMaxScrollY() const {
504 GetIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX
, &value
);
508 int BrowserAccessibilityAndroid::GetTextChangeFromIndex() const {
510 while (index
< old_value_
.length() &&
511 index
< new_value_
.length() &&
512 old_value_
[index
] == new_value_
[index
]) {
518 int BrowserAccessibilityAndroid::GetTextChangeAddedCount() const {
519 size_t old_len
= old_value_
.length();
520 size_t new_len
= new_value_
.length();
522 while (left
< old_len
&&
524 old_value_
[left
] == new_value_
[left
]) {
528 while (right
< old_len
&&
530 old_value_
[old_len
- right
- 1] == new_value_
[new_len
- right
- 1]) {
533 return (new_len
- left
- right
);
536 int BrowserAccessibilityAndroid::GetTextChangeRemovedCount() const {
537 size_t old_len
= old_value_
.length();
538 size_t new_len
= new_value_
.length();
540 while (left
< old_len
&&
542 old_value_
[left
] == new_value_
[left
]) {
546 while (right
< old_len
&&
548 old_value_
[old_len
- right
- 1] == new_value_
[new_len
- right
- 1]) {
551 return (old_len
- left
- right
);
554 base::string16
BrowserAccessibilityAndroid::GetTextChangeBeforeText() const {
558 int BrowserAccessibilityAndroid::GetSelectionStart() const {
560 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
, &sel_start
);
564 int BrowserAccessibilityAndroid::GetSelectionEnd() const {
566 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, &sel_end
);
570 int BrowserAccessibilityAndroid::GetEditableTextLength() const {
571 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
572 return value
.length();
575 int BrowserAccessibilityAndroid::AndroidInputType() const {
576 std::string html_tag
= GetStringAttribute(
577 ui::AX_ATTR_HTML_TAG
);
578 if (html_tag
!= "input")
579 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL
;
582 if (!GetHtmlAttribute("type", &type
))
583 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT
;
585 if (type
.empty() || type
== "text" || type
== "search")
586 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT
;
587 else if (type
== "date")
588 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE
;
589 else if (type
== "datetime" || type
== "datetime-local")
590 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME
;
591 else if (type
== "email")
592 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL
;
593 else if (type
== "month")
594 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE
;
595 else if (type
== "number")
596 return ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER
;
597 else if (type
== "password")
598 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_PASSWORD
;
599 else if (type
== "tel")
600 return ANDROID_TEXT_INPUTTYPE_TYPE_PHONE
;
601 else if (type
== "time")
602 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME
;
603 else if (type
== "url")
604 return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI
;
605 else if (type
== "week")
606 return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME
;
608 return ANDROID_TEXT_INPUTTYPE_TYPE_NULL
;
611 int BrowserAccessibilityAndroid::AndroidLiveRegionType() const {
612 std::string live
= GetStringAttribute(
613 ui::AX_ATTR_LIVE_STATUS
);
614 if (live
== "polite")
615 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE
;
616 else if (live
== "assertive")
617 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE
;
618 return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE
;
621 int BrowserAccessibilityAndroid::AndroidRangeType() const {
622 return ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT
;
625 int BrowserAccessibilityAndroid::RowCount() const {
626 if (GetRole() == ui::AX_ROLE_GRID
||
627 GetRole() == ui::AX_ROLE_TABLE
) {
628 return CountChildrenWithRole(ui::AX_ROLE_ROW
);
631 if (GetRole() == ui::AX_ROLE_LIST
||
632 GetRole() == ui::AX_ROLE_LIST_BOX
||
633 GetRole() == ui::AX_ROLE_DESCRIPTION_LIST
||
634 GetRole() == ui::AX_ROLE_TREE
) {
635 return PlatformChildCount();
641 int BrowserAccessibilityAndroid::ColumnCount() const {
642 if (GetRole() == ui::AX_ROLE_GRID
||
643 GetRole() == ui::AX_ROLE_TABLE
) {
644 return CountChildrenWithRole(ui::AX_ROLE_COLUMN
);
649 int BrowserAccessibilityAndroid::RowIndex() const {
650 if (GetRole() == ui::AX_ROLE_LIST_ITEM
||
651 GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
||
652 GetRole() == ui::AX_ROLE_TREE_ITEM
) {
653 return GetIndexInParent();
656 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
);
659 int BrowserAccessibilityAndroid::RowSpan() const {
660 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN
);
663 int BrowserAccessibilityAndroid::ColumnIndex() const {
664 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
);
667 int BrowserAccessibilityAndroid::ColumnSpan() const {
668 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
);
671 float BrowserAccessibilityAndroid::RangeMin() const {
672 return GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
);
675 float BrowserAccessibilityAndroid::RangeMax() const {
676 return GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
);
679 float BrowserAccessibilityAndroid::RangeCurrentValue() const {
680 return GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
);
683 void BrowserAccessibilityAndroid::GetGranularityBoundaries(
685 std::vector
<int32
>* starts
,
686 std::vector
<int32
>* ends
,
688 switch (granularity
) {
689 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_LINE
:
690 GetLineBoundaries(starts
, ends
, offset
);
692 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD
:
693 GetWordBoundaries(starts
, ends
, offset
);
700 void BrowserAccessibilityAndroid::GetLineBoundaries(
701 std::vector
<int32
>* line_starts
,
702 std::vector
<int32
>* line_ends
,
704 // If this node has no children, treat it as all one line.
705 if (GetText().size() > 0 && !InternalChildCount()) {
706 line_starts
->push_back(offset
);
707 line_ends
->push_back(offset
+ GetText().size());
710 // If this is a static text node, get the line boundaries from the
711 // inline text boxes if possible.
712 if (GetRole() == ui::AX_ROLE_STATIC_TEXT
) {
714 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
715 BrowserAccessibilityAndroid
* child
=
716 static_cast<BrowserAccessibilityAndroid
*>(InternalGetChild(i
));
717 CHECK_EQ(ui::AX_ROLE_INLINE_TEXT_BOX
, child
->GetRole());
718 // TODO(dmazzoni): replace this with a proper API to determine
719 // if two inline text boxes are on the same line. http://crbug.com/421771
720 int y
= child
->GetLocation().y();
722 line_starts
->push_back(offset
);
723 } else if (y
!= last_y
) {
724 line_ends
->push_back(offset
);
725 line_starts
->push_back(offset
);
727 offset
+= child
->GetText().size();
730 line_ends
->push_back(offset
);
734 // Otherwise, call GetLineBoundaries recursively on the children.
735 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
736 BrowserAccessibilityAndroid
* child
=
737 static_cast<BrowserAccessibilityAndroid
*>(InternalGetChild(i
));
738 child
->GetLineBoundaries(line_starts
, line_ends
, offset
);
739 offset
+= child
->GetText().size();
743 void BrowserAccessibilityAndroid::GetWordBoundaries(
744 std::vector
<int32
>* word_starts
,
745 std::vector
<int32
>* word_ends
,
747 if (GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX
) {
748 const std::vector
<int32
>& starts
= GetIntListAttribute(
749 ui::AX_ATTR_WORD_STARTS
);
750 const std::vector
<int32
>& ends
= GetIntListAttribute(
751 ui::AX_ATTR_WORD_ENDS
);
752 for (size_t i
= 0; i
< starts
.size(); ++i
) {
753 word_starts
->push_back(offset
+ starts
[i
]);
754 word_ends
->push_back(offset
+ ends
[i
]);
759 base::string16 concatenated_text
;
760 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
761 BrowserAccessibilityAndroid
* child
=
762 static_cast<BrowserAccessibilityAndroid
*>(InternalGetChild(i
));
763 base::string16 child_text
= child
->GetText();
764 concatenated_text
+= child
->GetText();
767 base::string16 text
= GetText();
768 if (text
.empty() || concatenated_text
== text
) {
769 // Great - this node is just the concatenation of its children, so
770 // we can get the word boundaries recursively.
771 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
772 BrowserAccessibilityAndroid
* child
=
773 static_cast<BrowserAccessibilityAndroid
*>(InternalGetChild(i
));
774 child
->GetWordBoundaries(word_starts
, word_ends
, offset
);
775 offset
+= child
->GetText().size();
778 // This node has its own accessible text that doesn't match its
779 // visible text - like alt text for an image or something with an
780 // aria-label, so split the text into words locally.
781 base::i18n::BreakIterator
iter(text
, base::i18n::BreakIterator::BREAK_WORD
);
784 while (iter
.Advance()) {
786 word_starts
->push_back(iter
.prev());
787 word_ends
->push_back(iter
.pos());
793 bool BrowserAccessibilityAndroid::HasFocusableChild() const {
794 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
796 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
797 BrowserAccessibility
* child
= InternalGetChild(i
);
798 if (child
->HasState(ui::AX_STATE_FOCUSABLE
))
800 if (static_cast<BrowserAccessibilityAndroid
*>(child
)->HasFocusableChild())
806 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const {
807 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
809 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
810 BrowserAccessibility
* child
= InternalGetChild(i
);
811 if (child
->GetRole() != ui::AX_ROLE_STATIC_TEXT
)
817 bool BrowserAccessibilityAndroid::HasOnlyTextAndImageChildren() const {
818 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
820 for (uint32 i
= 0; i
< InternalChildCount(); i
++) {
821 BrowserAccessibility
* child
= InternalGetChild(i
);
822 if (child
->GetRole() != ui::AX_ROLE_STATIC_TEXT
&&
823 child
->GetRole() != ui::AX_ROLE_IMAGE
) {
830 bool BrowserAccessibilityAndroid::IsIframe() const {
831 base::string16 html_tag
= GetString16Attribute(
832 ui::AX_ATTR_HTML_TAG
);
833 return html_tag
== base::ASCIIToUTF16("iframe");
836 void BrowserAccessibilityAndroid::OnDataChanged() {
837 BrowserAccessibility::OnDataChanged();
839 if (IsEditableText()) {
840 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
841 if (value
!= new_value_
) {
842 old_value_
= new_value_
;
847 if (GetRole() == ui::AX_ROLE_ALERT
&& first_time_
)
848 manager()->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT
, this);
851 if (GetString16Attribute(
852 ui::AX_ATTR_CONTAINER_LIVE_STATUS
, &live
)) {
853 NotifyLiveRegionUpdate(live
);
859 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(
860 base::string16
& aria_live
) {
861 if (!EqualsASCII(aria_live
, aria_strings::kAriaLivePolite
) &&
862 !EqualsASCII(aria_live
, aria_strings::kAriaLiveAssertive
))
865 base::string16 text
= GetText();
866 if (cached_text_
!= text
) {
868 manager()->NotifyAccessibilityEvent(ui::AX_EVENT_SHOW
,
875 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role
) const {
877 for (uint32 i
= 0; i
< PlatformChildCount(); i
++) {
878 if (PlatformGetChild(i
)->GetRole() == role
)
884 } // namespace content