| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() == AccessibilityNodeData::ROLE_WEB_AREA) { | 173 role() == AccessibilityNodeData::ROLE_WEB_AREA) { |
| 174 return string16(); | 174 return string16(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 string16 description; | 177 string16 description = GetString16Attribute( |
| 178 GetStringAttribute(AccessibilityNodeData::ATTR_DESCRIPTION, &description); | 178 AccessibilityNodeData::ATTR_DESCRIPTION); |
| 179 | |
| 180 string16 text; | 179 string16 text; |
| 181 if (!name().empty()) | 180 if (!name().empty()) |
| 182 text = name(); | 181 text = base::UTF8ToUTF16(name()); |
| 183 else if (!description.empty()) | 182 else if (!description.empty()) |
| 184 text = description; | 183 text = description; |
| 185 else if (!value().empty()) | 184 else if (!value().empty()) |
| 186 text = value(); | 185 text = base::UTF8ToUTF16(value()); |
| 187 | 186 |
| 188 if (text.empty() && HasOnlyStaticTextChildren()) { | 187 if (text.empty() && HasOnlyStaticTextChildren()) { |
| 189 for (uint32 i = 0; i < child_count(); i++) { | 188 for (uint32 i = 0; i < child_count(); i++) { |
| 190 BrowserAccessibility* child = GetChild(i); | 189 BrowserAccessibility* child = GetChild(i); |
| 191 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); | 190 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); |
| 192 } | 191 } |
| 193 } | 192 } |
| 194 | 193 |
| 195 switch(role()) { | 194 switch(role()) { |
| 196 case AccessibilityNodeData::ROLE_IMAGE_MAP_LINK: | 195 case AccessibilityNodeData::ROLE_IMAGE_MAP_LINK: |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { | 353 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { |
| 355 for (uint32 i = 0; i < child_count(); i++) { | 354 for (uint32 i = 0; i < child_count(); i++) { |
| 356 BrowserAccessibility* child = GetChild(i); | 355 BrowserAccessibility* child = GetChild(i); |
| 357 if (child->role() != AccessibilityNodeData::ROLE_STATIC_TEXT) | 356 if (child->role() != AccessibilityNodeData::ROLE_STATIC_TEXT) |
| 358 return false; | 357 return false; |
| 359 } | 358 } |
| 360 return true; | 359 return true; |
| 361 } | 360 } |
| 362 | 361 |
| 363 bool BrowserAccessibilityAndroid::IsIframe() const { | 362 bool BrowserAccessibilityAndroid::IsIframe() const { |
| 364 string16 html_tag; | 363 string16 html_tag = GetString16Attribute( |
| 365 GetStringAttribute(AccessibilityNodeData::ATTR_HTML_TAG, &html_tag); | 364 AccessibilityNodeData::ATTR_HTML_TAG); |
| 366 return html_tag == ASCIIToUTF16("iframe"); | 365 return html_tag == ASCIIToUTF16("iframe"); |
| 367 } | 366 } |
| 368 | 367 |
| 369 void BrowserAccessibilityAndroid::PostInitialize() { | 368 void BrowserAccessibilityAndroid::PostInitialize() { |
| 370 BrowserAccessibility::PostInitialize(); | 369 BrowserAccessibility::PostInitialize(); |
| 371 | 370 |
| 372 if (IsEditableText()) { | 371 if (IsEditableText()) { |
| 373 if (value_ != new_value_) { | 372 if (base::UTF8ToUTF16(value_) != new_value_) { |
| 374 old_value_ = new_value_; | 373 old_value_ = new_value_; |
| 375 new_value_ = value_; | 374 new_value_ = base::UTF8ToUTF16(value_); |
| 376 } | 375 } |
| 377 } | 376 } |
| 378 | 377 |
| 379 if (role_ == AccessibilityNodeData::ROLE_ALERT && first_time_) | 378 if (role_ == AccessibilityNodeData::ROLE_ALERT && first_time_) |
| 380 manager_->NotifyAccessibilityEvent(AccessibilityNotificationAlert, this); | 379 manager_->NotifyAccessibilityEvent(AccessibilityNotificationAlert, this); |
| 381 | 380 |
| 382 string16 live; | 381 string16 live; |
| 383 if (GetStringAttribute(AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, | 382 if (GetString16Attribute( |
| 384 &live)) { | 383 AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, &live)) { |
| 385 NotifyLiveRegionUpdate(live); | 384 NotifyLiveRegionUpdate(live); |
| 386 } | 385 } |
| 387 | 386 |
| 388 first_time_ = false; | 387 first_time_ = false; |
| 389 } | 388 } |
| 390 | 389 |
| 391 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { | 390 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { |
| 392 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && | 391 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && |
| 393 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) | 392 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) |
| 394 return; | 393 return; |
| 395 | 394 |
| 396 string16 text = GetText(); | 395 string16 text = GetText(); |
| 397 if (cached_text_ != text) { | 396 if (cached_text_ != text) { |
| 398 if (!text.empty()) { | 397 if (!text.empty()) { |
| 399 manager_->NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, | 398 manager_->NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, |
| 400 this); | 399 this); |
| 401 } | 400 } |
| 402 cached_text_ = text; | 401 cached_text_ = text; |
| 403 } | 402 } |
| 404 } | 403 } |
| 405 | 404 |
| 406 } // namespace content | 405 } // namespace content |
| OLD | NEW |