b622e81b77ad1f2b14c740ca97023739f297e37f
[platform/framework/web/crosswalk.git] / src / content / browser / accessibility / browser_accessibility_android.cc
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.
4
5 #include "content/browser/accessibility/browser_accessibility_android.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
9 #include "content/common/accessibility_messages.h"
10
11 namespace {
12
13 // These are enums from android.text.InputType in Java:
14 enum {
15   ANDROID_TEXT_INPUTTYPE_TYPE_NULL = 0,
16   ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME = 0x4,
17   ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE = 0x14,
18   ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME = 0x24,
19   ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER = 0x2,
20   ANDROID_TEXT_INPUTTYPE_TYPE_PHONE = 0x3,
21   ANDROID_TEXT_INPUTTYPE_TYPE_TEXT = 0x1,
22   ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI = 0x11,
23   ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EDIT_TEXT = 0xa1,
24   ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL = 0xd1,
25   ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_PASSWORD = 0xe1
26 };
27
28 // These are enums from android.view.View in Java:
29 enum {
30   ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE = 0,
31   ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE = 1,
32   ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 2
33 };
34
35 // These are enums from
36 // android.view.accessibility.AccessibilityNodeInfo.RangeInfo in Java:
37 enum {
38   ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT = 1
39 };
40
41 }  // namespace
42
43 namespace content {
44
45 // static
46 BrowserAccessibility* BrowserAccessibility::Create() {
47   return new BrowserAccessibilityAndroid();
48 }
49
50 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() {
51   first_time_ = true;
52 }
53
54 bool BrowserAccessibilityAndroid::IsNative() const {
55   return true;
56 }
57
58 void BrowserAccessibilityAndroid::OnLocationChanged() {
59   manager()->NotifyAccessibilityEvent(ui::AX_EVENT_LOCATION_CHANGED, this);
60 }
61
62 bool BrowserAccessibilityAndroid::PlatformIsLeaf() const {
63   if (InternalChildCount() == 0)
64     return true;
65
66   // Iframes are always allowed to contain children.
67   if (IsIframe() ||
68       GetRole() == ui::AX_ROLE_ROOT_WEB_AREA ||
69       GetRole() == ui::AX_ROLE_WEB_AREA) {
70     return false;
71   }
72
73   // If it has a focusable child, we definitely can't leave out children.
74   if (HasFocusableChild())
75     return false;
76
77   // Headings with text can drop their children.
78   base::string16 name = GetText();
79   if (GetRole() == ui::AX_ROLE_HEADING && !name.empty())
80     return true;
81
82   // Focusable nodes with text can drop their children.
83   if (HasState(ui::AX_STATE_FOCUSABLE) && !name.empty())
84     return true;
85
86   // Nodes with only static text as children can drop their children.
87   if (HasOnlyStaticTextChildren())
88     return true;
89
90   return BrowserAccessibility::PlatformIsLeaf();
91 }
92
93 bool BrowserAccessibilityAndroid::IsCheckable() const {
94   bool checkable = false;
95   bool is_aria_pressed_defined;
96   bool is_mixed;
97   GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed);
98   if (GetRole() == ui::AX_ROLE_CHECK_BOX ||
99       GetRole() == ui::AX_ROLE_RADIO_BUTTON ||
100       is_aria_pressed_defined) {
101     checkable = true;
102   }
103   if (HasState(ui::AX_STATE_CHECKED))
104     checkable = true;
105   return checkable;
106 }
107
108 bool BrowserAccessibilityAndroid::IsChecked() const {
109   return HasState(ui::AX_STATE_CHECKED);
110 }
111
112 bool BrowserAccessibilityAndroid::IsClickable() const {
113   return (PlatformIsLeaf() && !GetText().empty());
114 }
115
116 bool BrowserAccessibilityAndroid::IsCollection() const {
117   return (GetRole() == ui::AX_ROLE_GRID ||
118           GetRole() == ui::AX_ROLE_LIST ||
119           GetRole() == ui::AX_ROLE_LIST_BOX ||
120           GetRole() == ui::AX_ROLE_TABLE ||
121           GetRole() == ui::AX_ROLE_TREE);
122 }
123
124 bool BrowserAccessibilityAndroid::IsCollectionItem() const {
125   return (GetRole() == ui::AX_ROLE_CELL ||
126           GetRole() == ui::AX_ROLE_COLUMN_HEADER ||
127           GetRole() == ui::AX_ROLE_DESCRIPTION_LIST_TERM ||
128           GetRole() == ui::AX_ROLE_LIST_BOX_OPTION ||
129           GetRole() == ui::AX_ROLE_LIST_ITEM ||
130           GetRole() == ui::AX_ROLE_ROW_HEADER ||
131           GetRole() == ui::AX_ROLE_TREE_ITEM);
132 }
133
134 bool BrowserAccessibilityAndroid::IsContentInvalid() const {
135   std::string invalid;
136   return GetHtmlAttribute("aria-invalid", &invalid);
137 }
138
139 bool BrowserAccessibilityAndroid::IsDismissable() const {
140   return false;  // No concept of "dismissable" on the web currently.
141 }
142
143 bool BrowserAccessibilityAndroid::IsEnabled() const {
144   return HasState(ui::AX_STATE_ENABLED);
145 }
146
147 bool BrowserAccessibilityAndroid::IsFocusable() const {
148   bool focusable = HasState(ui::AX_STATE_FOCUSABLE);
149   if (IsIframe() ||
150       GetRole() == ui::AX_ROLE_WEB_AREA) {
151     focusable = false;
152   }
153   return focusable;
154 }
155
156 bool BrowserAccessibilityAndroid::IsFocused() const {
157   return manager()->GetFocus(manager()->GetRoot()) == this;
158 }
159
160 bool BrowserAccessibilityAndroid::IsHeading() const {
161   return (GetRole() == ui::AX_ROLE_COLUMN_HEADER ||
162           GetRole() == ui::AX_ROLE_HEADING ||
163           GetRole() == ui::AX_ROLE_ROW_HEADER);
164 }
165
166 bool BrowserAccessibilityAndroid::IsHierarchical() const {
167   return (GetRole() == ui::AX_ROLE_LIST ||
168           GetRole() == ui::AX_ROLE_TREE);
169 }
170
171 bool BrowserAccessibilityAndroid::IsLink() const {
172   return GetRole() == ui::AX_ROLE_LINK ||
173          GetRole() == ui::AX_ROLE_IMAGE_MAP_LINK;
174 }
175
176 bool BrowserAccessibilityAndroid::IsMultiLine() const {
177   return GetRole() == ui::AX_ROLE_TEXT_AREA;
178 }
179
180 bool BrowserAccessibilityAndroid::IsPassword() const {
181   return HasState(ui::AX_STATE_PROTECTED);
182 }
183
184 bool BrowserAccessibilityAndroid::IsRangeType() const {
185   return (GetRole() == ui::AX_ROLE_PROGRESS_INDICATOR ||
186           GetRole() == ui::AX_ROLE_SCROLL_BAR ||
187           GetRole() == ui::AX_ROLE_SLIDER);
188 }
189
190 bool BrowserAccessibilityAndroid::IsScrollable() const {
191   int dummy;
192   return GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, &dummy);
193 }
194
195 bool BrowserAccessibilityAndroid::IsSelected() const {
196   return HasState(ui::AX_STATE_SELECTED);
197 }
198
199 bool BrowserAccessibilityAndroid::IsVisibleToUser() const {
200   return !HasState(ui::AX_STATE_INVISIBLE);
201 }
202
203 bool BrowserAccessibilityAndroid::CanOpenPopup() const {
204   return HasState(ui::AX_STATE_HASPOPUP);
205 }
206
207 const char* BrowserAccessibilityAndroid::GetClassName() const {
208   const char* class_name = NULL;
209
210   switch(GetRole()) {
211     case ui::AX_ROLE_EDITABLE_TEXT:
212     case ui::AX_ROLE_SPIN_BUTTON:
213     case ui::AX_ROLE_TEXT_AREA:
214     case ui::AX_ROLE_TEXT_FIELD:
215       class_name = "android.widget.EditText";
216       break;
217     case ui::AX_ROLE_SLIDER:
218       class_name = "android.widget.SeekBar";
219       break;
220     case ui::AX_ROLE_COMBO_BOX:
221       class_name = "android.widget.Spinner";
222       break;
223     case ui::AX_ROLE_BUTTON:
224     case ui::AX_ROLE_MENU_BUTTON:
225     case ui::AX_ROLE_POP_UP_BUTTON:
226       class_name = "android.widget.Button";
227       break;
228     case ui::AX_ROLE_CHECK_BOX:
229       class_name = "android.widget.CheckBox";
230       break;
231     case ui::AX_ROLE_RADIO_BUTTON:
232       class_name = "android.widget.RadioButton";
233       break;
234     case ui::AX_ROLE_TOGGLE_BUTTON:
235       class_name = "android.widget.ToggleButton";
236       break;
237     case ui::AX_ROLE_CANVAS:
238     case ui::AX_ROLE_IMAGE:
239       class_name = "android.widget.Image";
240       break;
241     case ui::AX_ROLE_PROGRESS_INDICATOR:
242       class_name = "android.widget.ProgressBar";
243       break;
244     case ui::AX_ROLE_TAB_LIST:
245       class_name = "android.widget.TabWidget";
246       break;
247     case ui::AX_ROLE_GRID:
248     case ui::AX_ROLE_TABLE:
249       class_name = "android.widget.GridView";
250       break;
251     case ui::AX_ROLE_LIST:
252     case ui::AX_ROLE_LIST_BOX:
253       class_name = "android.widget.ListView";
254       break;
255     case ui::AX_ROLE_DIALOG:
256       class_name = "android.app.Dialog";
257       break;
258     case ui::AX_ROLE_ROOT_WEB_AREA:
259       class_name = "android.webkit.WebView";
260       break;
261     default:
262       class_name = "android.view.View";
263       break;
264   }
265
266   return class_name;
267 }
268
269 base::string16 BrowserAccessibilityAndroid::GetText() const {
270   if (IsIframe() ||
271       GetRole() == ui::AX_ROLE_WEB_AREA) {
272     return base::string16();
273   }
274
275   // See comment in browser_accessibility_win.cc for details.
276   // The difference here is that we can only expose one accessible
277   // name on Android, not 2 or 3 like on Windows or Mac.
278   //
279   // The basic rule is: prefer description (aria-labelledby or aria-label),
280   // then help (title), then name (inner text), then value (control value).
281   // However, if title_elem_id is set, that means there's a label element
282   // supplying the name and then name takes precedence over help.
283   // TODO(dmazzoni): clean this up by providing more granular labels in
284   // Blink, making the platform-specific mapping to accessible text simpler.
285   base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION);
286   base::string16 help = GetString16Attribute(ui::AX_ATTR_HELP);
287   int title_elem_id = GetIntAttribute(
288       ui::AX_ATTR_TITLE_UI_ELEMENT);
289   base::string16 text;
290   if (!description.empty())
291     text = description;
292   else if (title_elem_id && !name().empty())
293     text = base::UTF8ToUTF16(name());
294   else if (!help.empty())
295     text = help;
296   else if (!name().empty())
297     text = base::UTF8ToUTF16(name());
298   else if (!value().empty())
299     text = base::UTF8ToUTF16(value());
300
301   // This is called from PlatformIsLeaf, so don't call PlatformChildCount
302   // from within this!
303   if (text.empty() && HasOnlyStaticTextChildren()) {
304     for (uint32 i = 0; i < InternalChildCount(); i++) {
305       BrowserAccessibility* child = InternalGetChild(i);
306       text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText();
307     }
308   }
309
310   switch(GetRole()) {
311     case ui::AX_ROLE_HEADING:
312       // Only append "heading" if this node already has text.
313       if (!text.empty())
314         text += base::ASCIIToUTF16(" Heading");
315       break;
316   }
317
318   if (text.empty() && IsLink()) {
319     base::string16 url = GetString16Attribute(ui::AX_ATTR_URL);
320     // Given a url like http://foo.com/bar/baz.png, just return the
321     // base name, e.g., "baz".
322     int trailing_slashes = 0;
323     while (url.size() - trailing_slashes > 0 &&
324            url[url.size() - trailing_slashes - 1] == '/') {
325       trailing_slashes++;
326     }
327     if (trailing_slashes)
328       url = url.substr(0, url.size() - trailing_slashes);
329     size_t slash_index = url.rfind('/');
330     if (slash_index != std::string::npos)
331       url = url.substr(slash_index + 1);
332     size_t dot_index = url.rfind('.');
333     if (dot_index != std::string::npos)
334       url = url.substr(0, dot_index);
335     text = url;
336   }
337
338   return text;
339 }
340
341 int BrowserAccessibilityAndroid::GetItemIndex() const {
342   int index = 0;
343   switch(GetRole()) {
344     case ui::AX_ROLE_LIST_ITEM:
345     case ui::AX_ROLE_LIST_BOX_OPTION:
346     case ui::AX_ROLE_TREE_ITEM:
347       index = GetIndexInParent();
348       break;
349     case ui::AX_ROLE_SLIDER:
350     case ui::AX_ROLE_PROGRESS_INDICATOR: {
351       float value_for_range;
352       if (GetFloatAttribute(
353               ui::AX_ATTR_VALUE_FOR_RANGE, &value_for_range)) {
354         index = static_cast<int>(value_for_range);
355       }
356       break;
357     }
358   }
359   return index;
360 }
361
362 int BrowserAccessibilityAndroid::GetItemCount() const {
363   int count = 0;
364   switch(GetRole()) {
365     case ui::AX_ROLE_LIST:
366     case ui::AX_ROLE_LIST_BOX:
367       count = PlatformChildCount();
368       break;
369     case ui::AX_ROLE_SLIDER:
370     case ui::AX_ROLE_PROGRESS_INDICATOR: {
371       float max_value_for_range;
372       if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE,
373                             &max_value_for_range)) {
374         count = static_cast<int>(max_value_for_range);
375       }
376       break;
377     }
378   }
379   return count;
380 }
381
382 int BrowserAccessibilityAndroid::GetScrollX() const {
383   int value = 0;
384   GetIntAttribute(ui::AX_ATTR_SCROLL_X, &value);
385   return value;
386 }
387
388 int BrowserAccessibilityAndroid::GetScrollY() const {
389   int value = 0;
390   GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &value);
391   return value;
392 }
393
394 int BrowserAccessibilityAndroid::GetMaxScrollX() const {
395   int value = 0;
396   GetIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, &value);
397   return value;
398 }
399
400 int BrowserAccessibilityAndroid::GetMaxScrollY() const {
401   int value = 0;
402   GetIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, &value);
403   return value;
404 }
405
406 int BrowserAccessibilityAndroid::GetTextChangeFromIndex() const {
407   size_t index = 0;
408   while (index < old_value_.length() &&
409          index < new_value_.length() &&
410          old_value_[index] == new_value_[index]) {
411     index++;
412   }
413   return index;
414 }
415
416 int BrowserAccessibilityAndroid::GetTextChangeAddedCount() const {
417   size_t old_len = old_value_.length();
418   size_t new_len = new_value_.length();
419   size_t left = 0;
420   while (left < old_len &&
421          left < new_len &&
422          old_value_[left] == new_value_[left]) {
423     left++;
424   }
425   size_t right = 0;
426   while (right < old_len &&
427          right < new_len &&
428          old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) {
429     right++;
430   }
431   return (new_len - left - right);
432 }
433
434 int BrowserAccessibilityAndroid::GetTextChangeRemovedCount() const {
435   size_t old_len = old_value_.length();
436   size_t new_len = new_value_.length();
437   size_t left = 0;
438   while (left < old_len &&
439          left < new_len &&
440          old_value_[left] == new_value_[left]) {
441     left++;
442   }
443   size_t right = 0;
444   while (right < old_len &&
445          right < new_len &&
446          old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) {
447     right++;
448   }
449   return (old_len - left - right);
450 }
451
452 base::string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const {
453   return old_value_;
454 }
455
456 int BrowserAccessibilityAndroid::GetSelectionStart() const {
457   int sel_start = 0;
458   GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &sel_start);
459   return sel_start;
460 }
461
462 int BrowserAccessibilityAndroid::GetSelectionEnd() const {
463   int sel_end = 0;
464   GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &sel_end);
465   return sel_end;
466 }
467
468 int BrowserAccessibilityAndroid::GetEditableTextLength() const {
469   return value().length();
470 }
471
472 int BrowserAccessibilityAndroid::AndroidInputType() const {
473   std::string html_tag = GetStringAttribute(
474       ui::AX_ATTR_HTML_TAG);
475   if (html_tag != "input")
476     return ANDROID_TEXT_INPUTTYPE_TYPE_NULL;
477
478   std::string type;
479   if (!GetHtmlAttribute("type", &type))
480     return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT;
481
482   if (type == "" || type == "text" || type == "search")
483     return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT;
484   else if (type == "date")
485     return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE;
486   else if (type == "datetime" || type == "datetime-local")
487     return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME;
488   else if (type == "email")
489     return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_EMAIL;
490   else if (type == "month")
491     return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_DATE;
492   else if (type == "number")
493     return ANDROID_TEXT_INPUTTYPE_TYPE_NUMBER;
494   else if (type == "password")
495     return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_WEB_PASSWORD;
496   else if (type == "tel")
497     return ANDROID_TEXT_INPUTTYPE_TYPE_PHONE;
498   else if (type == "time")
499     return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME_TIME;
500   else if (type == "url")
501     return ANDROID_TEXT_INPUTTYPE_TYPE_TEXT_URI;
502   else if (type == "week")
503     return ANDROID_TEXT_INPUTTYPE_TYPE_DATETIME;
504
505   return ANDROID_TEXT_INPUTTYPE_TYPE_NULL;
506 }
507
508 int BrowserAccessibilityAndroid::AndroidLiveRegionType() const {
509   std::string live = GetStringAttribute(
510       ui::AX_ATTR_LIVE_STATUS);
511   if (live == "polite")
512     return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_POLITE;
513   else if (live == "assertive")
514     return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_ASSERTIVE;
515   return ANDROID_VIEW_VIEW_ACCESSIBILITY_LIVE_REGION_NONE;
516 }
517
518 int BrowserAccessibilityAndroid::AndroidRangeType() const {
519   return ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT;
520 }
521
522 int BrowserAccessibilityAndroid::RowCount() const {
523   if (GetRole() == ui::AX_ROLE_GRID ||
524       GetRole() == ui::AX_ROLE_TABLE) {
525     return CountChildrenWithRole(ui::AX_ROLE_ROW);
526   }
527
528   if (GetRole() == ui::AX_ROLE_LIST ||
529       GetRole() == ui::AX_ROLE_LIST_BOX ||
530       GetRole() == ui::AX_ROLE_TREE) {
531     return PlatformChildCount();
532   }
533
534   return 0;
535 }
536
537 int BrowserAccessibilityAndroid::ColumnCount() const {
538   if (GetRole() == ui::AX_ROLE_GRID ||
539       GetRole() == ui::AX_ROLE_TABLE) {
540     return CountChildrenWithRole(ui::AX_ROLE_COLUMN);
541   }
542   return 0;
543 }
544
545 int BrowserAccessibilityAndroid::RowIndex() const {
546   if (GetRole() == ui::AX_ROLE_LIST_ITEM ||
547       GetRole() == ui::AX_ROLE_LIST_BOX_OPTION ||
548       GetRole() == ui::AX_ROLE_TREE_ITEM) {
549     return GetIndexInParent();
550   }
551
552   return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX);
553 }
554
555 int BrowserAccessibilityAndroid::RowSpan() const {
556   return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN);
557 }
558
559 int BrowserAccessibilityAndroid::ColumnIndex() const {
560   return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX);
561 }
562
563 int BrowserAccessibilityAndroid::ColumnSpan() const {
564   return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN);
565 }
566
567 float BrowserAccessibilityAndroid::RangeMin() const {
568   return GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE);
569 }
570
571 float BrowserAccessibilityAndroid::RangeMax() const {
572   return GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE);
573 }
574
575 float BrowserAccessibilityAndroid::RangeCurrentValue() const {
576   return GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE);
577 }
578
579 bool BrowserAccessibilityAndroid::HasFocusableChild() const {
580   // This is called from PlatformIsLeaf, so don't call PlatformChildCount
581   // from within this!
582   for (uint32 i = 0; i < InternalChildCount(); i++) {
583     BrowserAccessibility* child = InternalGetChild(i);
584     if (child->HasState(ui::AX_STATE_FOCUSABLE))
585       return true;
586     if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild())
587       return true;
588   }
589   return false;
590 }
591
592 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const {
593   // This is called from PlatformIsLeaf, so don't call PlatformChildCount
594   // from within this!
595   for (uint32 i = 0; i < InternalChildCount(); i++) {
596     BrowserAccessibility* child = InternalGetChild(i);
597     if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT)
598       return false;
599   }
600   return true;
601 }
602
603 bool BrowserAccessibilityAndroid::IsIframe() const {
604   base::string16 html_tag = GetString16Attribute(
605       ui::AX_ATTR_HTML_TAG);
606   return html_tag == base::ASCIIToUTF16("iframe");
607 }
608
609 void BrowserAccessibilityAndroid::OnDataChanged() {
610   BrowserAccessibility::OnDataChanged();
611
612   if (IsEditableText()) {
613     if (base::UTF8ToUTF16(value()) != new_value_) {
614       old_value_ = new_value_;
615       new_value_ = base::UTF8ToUTF16(value());
616     }
617   }
618
619   if (GetRole() == ui::AX_ROLE_ALERT && first_time_)
620     manager()->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, this);
621
622   base::string16 live;
623   if (GetString16Attribute(
624       ui::AX_ATTR_CONTAINER_LIVE_STATUS, &live)) {
625     NotifyLiveRegionUpdate(live);
626   }
627
628   first_time_ = false;
629 }
630
631 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(
632     base::string16& aria_live) {
633   if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) &&
634       !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive))
635     return;
636
637   base::string16 text = GetText();
638   if (cached_text_ != text) {
639     if (!text.empty()) {
640       manager()->NotifyAccessibilityEvent(ui::AX_EVENT_SHOW,
641                                          this);
642     }
643     cached_text_ = text;
644   }
645 }
646
647 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const {
648   int count = 0;
649   for (uint32 i = 0; i < PlatformChildCount(); i++) {
650     if (PlatformGetChild(i)->GetRole() == role)
651       count++;
652   }
653   return count;
654 }
655
656 }  // namespace content