| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 role() == blink::WebAXRoleRootWebArea || | 33 role() == blink::WebAXRoleRootWebArea || |
| 34 role() == blink::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 base::string16 name = GetText(); |
| 44 if (role() == blink::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(blink::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; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::string16 BrowserAccessibilityAndroid::GetText() const { |
| 172 if (IsIframe() || | 172 if (IsIframe() || |
| 173 role() == blink::WebAXRoleWebArea) { | 173 role() == blink::WebAXRoleWebArea) { |
| 174 return string16(); | 174 return base::string16(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 string16 description = GetString16Attribute( | 177 base::string16 description = GetString16Attribute( |
| 178 AccessibilityNodeData::ATTR_DESCRIPTION); | 178 AccessibilityNodeData::ATTR_DESCRIPTION); |
| 179 string16 text; | 179 base::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 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 187 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
| 188 // from within this! | 188 // from within this! |
| 189 if (text.empty() && HasOnlyStaticTextChildren()) { | 189 if (text.empty() && HasOnlyStaticTextChildren()) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 size_t right = 0; | 314 size_t right = 0; |
| 315 while (right < old_len && | 315 while (right < old_len && |
| 316 right < new_len && | 316 right < new_len && |
| 317 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { | 317 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { |
| 318 right++; | 318 right++; |
| 319 } | 319 } |
| 320 return (old_len - left - right); | 320 return (old_len - left - right); |
| 321 } | 321 } |
| 322 | 322 |
| 323 string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const { | 323 base::string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const { |
| 324 return old_value_; | 324 return old_value_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 int BrowserAccessibilityAndroid::GetSelectionStart() const { | 327 int BrowserAccessibilityAndroid::GetSelectionStart() const { |
| 328 int sel_start = 0; | 328 int sel_start = 0; |
| 329 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_START, &sel_start); | 329 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_START, &sel_start); |
| 330 return sel_start; | 330 return sel_start; |
| 331 } | 331 } |
| 332 | 332 |
| 333 int BrowserAccessibilityAndroid::GetSelectionEnd() const { | 333 int BrowserAccessibilityAndroid::GetSelectionEnd() const { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 358 // from within this! | 358 // from within this! |
| 359 for (uint32 i = 0; i < child_count(); i++) { | 359 for (uint32 i = 0; i < child_count(); i++) { |
| 360 BrowserAccessibility* child = children()[i]; | 360 BrowserAccessibility* child = children()[i]; |
| 361 if (child->role() != blink::WebAXRoleStaticText) | 361 if (child->role() != blink::WebAXRoleStaticText) |
| 362 return false; | 362 return false; |
| 363 } | 363 } |
| 364 return true; | 364 return true; |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool BrowserAccessibilityAndroid::IsIframe() const { | 367 bool BrowserAccessibilityAndroid::IsIframe() const { |
| 368 string16 html_tag = GetString16Attribute( | 368 base::string16 html_tag = GetString16Attribute( |
| 369 AccessibilityNodeData::ATTR_HTML_TAG); | 369 AccessibilityNodeData::ATTR_HTML_TAG); |
| 370 return html_tag == ASCIIToUTF16("iframe"); | 370 return html_tag == ASCIIToUTF16("iframe"); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void BrowserAccessibilityAndroid::PostInitialize() { | 373 void BrowserAccessibilityAndroid::PostInitialize() { |
| 374 BrowserAccessibility::PostInitialize(); | 374 BrowserAccessibility::PostInitialize(); |
| 375 | 375 |
| 376 if (IsEditableText()) { | 376 if (IsEditableText()) { |
| 377 if (base::UTF8ToUTF16(value_) != new_value_) { | 377 if (base::UTF8ToUTF16(value_) != new_value_) { |
| 378 old_value_ = new_value_; | 378 old_value_ = new_value_; |
| 379 new_value_ = base::UTF8ToUTF16(value_); | 379 new_value_ = base::UTF8ToUTF16(value_); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 if (role_ == blink::WebAXRoleAlert && first_time_) | 383 if (role_ == blink::WebAXRoleAlert && first_time_) |
| 384 manager_->NotifyAccessibilityEvent(blink::WebAXEventAlert, this); | 384 manager_->NotifyAccessibilityEvent(blink::WebAXEventAlert, this); |
| 385 | 385 |
| 386 string16 live; | 386 base::string16 live; |
| 387 if (GetString16Attribute( | 387 if (GetString16Attribute( |
| 388 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) { | 388 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) { |
| 389 NotifyLiveRegionUpdate(live); | 389 NotifyLiveRegionUpdate(live); |
| 390 } | 390 } |
| 391 | 391 |
| 392 first_time_ = false; | 392 first_time_ = false; |
| 393 } | 393 } |
| 394 | 394 |
| 395 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { | 395 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate( |
| 396 base::string16& aria_live) { |
| 396 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && | 397 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && |
| 397 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) | 398 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) |
| 398 return; | 399 return; |
| 399 | 400 |
| 400 string16 text = GetText(); | 401 base::string16 text = GetText(); |
| 401 if (cached_text_ != text) { | 402 if (cached_text_ != text) { |
| 402 if (!text.empty()) { | 403 if (!text.empty()) { |
| 403 manager_->NotifyAccessibilityEvent(blink::WebAXEventShow, | 404 manager_->NotifyAccessibilityEvent(blink::WebAXEventShow, |
| 404 this); | 405 this); |
| 405 } | 406 } |
| 406 cached_text_ = text; | 407 cached_text_ = text; |
| 407 } | 408 } |
| 408 } | 409 } |
| 409 | 410 |
| 410 } // namespace content | 411 } // namespace content |
| OLD | NEW |