OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "content/browser/accessibility/browser_accessibility.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 BrowserAccessibility::~BrowserAccessibility() { | 32 BrowserAccessibility::~BrowserAccessibility() { |
33 } | 33 } |
34 | 34 |
35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
36 ui::AXNode* node) { | 36 ui::AXNode* node) { |
37 manager_ = manager; | 37 manager_ = manager; |
38 node_ = node; | 38 node_ = node; |
39 } | 39 } |
40 | 40 |
| 41 void BrowserAccessibility::OnDataChanged() { |
| 42 GetStringAttribute(ui::AX_ATTR_NAME, &name_); |
| 43 GetStringAttribute(ui::AX_ATTR_VALUE, &value_); |
| 44 } |
| 45 |
41 bool BrowserAccessibility::PlatformIsLeaf() const { | 46 bool BrowserAccessibility::PlatformIsLeaf() const { |
42 if (InternalChildCount() == 0) | 47 if (InternalChildCount() == 0) |
43 return true; | 48 return true; |
44 | 49 |
45 // All of these roles may have children that we use as internal | 50 // All of these roles may have children that we use as internal |
46 // implementation details, but we want to expose them as leaves | 51 // implementation details, but we want to expose them as leaves |
47 // to platform accessibility APIs. | 52 // to platform accessibility APIs. |
48 switch (GetRole()) { | 53 switch (GetRole()) { |
49 case ui::AX_ROLE_LINE_BREAK: | 54 case ui::AX_ROLE_LINE_BREAK: |
50 case ui::AX_ROLE_SLIDER: | 55 case ui::AX_ROLE_SLIDER: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) { | 89 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) { |
85 BrowserAccessibilityManager* child_manager = | 90 BrowserAccessibilityManager* child_manager = |
86 manager_->delegate()->AccessibilityGetChildFrame(result->GetId()); | 91 manager_->delegate()->AccessibilityGetChildFrame(result->GetId()); |
87 if (child_manager) | 92 if (child_manager) |
88 result = child_manager->GetRoot(); | 93 result = child_manager->GetRoot(); |
89 } | 94 } |
90 | 95 |
91 return result; | 96 return result; |
92 } | 97 } |
93 | 98 |
94 bool BrowserAccessibility::PlatformIsChildOfLeaf() const { | |
95 BrowserAccessibility* ancestor = GetParent(); | |
96 while (ancestor) { | |
97 if (ancestor->PlatformIsLeaf()) | |
98 return true; | |
99 ancestor = ancestor->GetParent(); | |
100 } | |
101 | |
102 return false; | |
103 } | |
104 | |
105 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 99 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
106 if (GetParent() && GetIndexInParent() > 0) | 100 if (GetParent() && GetIndexInParent() > 0) |
107 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 101 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
108 | 102 |
109 return NULL; | 103 return NULL; |
110 } | 104 } |
111 | 105 |
112 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { | 106 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { |
113 if (GetParent() && | 107 if (GetParent() && |
114 GetIndexInParent() >= 0 && | 108 GetIndexInParent() >= 0 && |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (descendant_result) | 377 if (descendant_result) |
384 return descendant_result; | 378 return descendant_result; |
385 if (child_result) | 379 if (child_result) |
386 return child_result; | 380 return child_result; |
387 | 381 |
388 return this; | 382 return this; |
389 } | 383 } |
390 | 384 |
391 void BrowserAccessibility::Destroy() { | 385 void BrowserAccessibility::Destroy() { |
392 // Allow the object to fire a TextRemoved notification. | 386 // Allow the object to fire a TextRemoved notification. |
| 387 name_.clear(); |
| 388 value_.clear(); |
| 389 |
393 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); | 390 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); |
394 node_ = NULL; | 391 node_ = NULL; |
395 manager_ = NULL; | 392 manager_ = NULL; |
396 | 393 |
397 NativeReleaseReference(); | 394 NativeReleaseReference(); |
398 } | 395 } |
399 | 396 |
400 void BrowserAccessibility::NativeReleaseReference() { | 397 void BrowserAccessibility::NativeReleaseReference() { |
401 delete this; | 398 delete this; |
402 } | 399 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 bool BrowserAccessibility::GetString16Attribute( | 550 bool BrowserAccessibility::GetString16Attribute( |
554 ui::AXStringAttribute attribute, | 551 ui::AXStringAttribute attribute, |
555 base::string16* value) const { | 552 base::string16* value) const { |
556 std::string value_utf8; | 553 std::string value_utf8; |
557 if (!GetStringAttribute(attribute, &value_utf8)) | 554 if (!GetStringAttribute(attribute, &value_utf8)) |
558 return false; | 555 return false; |
559 *value = base::UTF8ToUTF16(value_utf8); | 556 *value = base::UTF8ToUTF16(value_utf8); |
560 return true; | 557 return true; |
561 } | 558 } |
562 | 559 |
| 560 void BrowserAccessibility::SetStringAttribute( |
| 561 ui::AXStringAttribute attribute, const std::string& value) { |
| 562 if (!node_) |
| 563 return; |
| 564 ui::AXNodeData data = GetData(); |
| 565 for (size_t i = 0; i < data.string_attributes.size(); ++i) { |
| 566 if (data.string_attributes[i].first == attribute) { |
| 567 data.string_attributes[i].second = value; |
| 568 node_->SetData(data); |
| 569 return; |
| 570 } |
| 571 } |
| 572 if (!value.empty()) { |
| 573 data.string_attributes.push_back(std::make_pair(attribute, value)); |
| 574 node_->SetData(data); |
| 575 } |
| 576 } |
| 577 |
563 bool BrowserAccessibility::HasIntListAttribute( | 578 bool BrowserAccessibility::HasIntListAttribute( |
564 ui::AXIntListAttribute attribute) const { | 579 ui::AXIntListAttribute attribute) const { |
565 const ui::AXNodeData& data = GetData(); | 580 const ui::AXNodeData& data = GetData(); |
566 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) { | 581 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) { |
567 if (data.intlist_attributes[i].first == attribute) | 582 if (data.intlist_attributes[i].first == attribute) |
568 return true; | 583 return true; |
569 } | 584 } |
570 | 585 |
571 return false; | 586 return false; |
572 } | 587 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 if (!parent) | 695 if (!parent) |
681 return false; | 696 return false; |
682 | 697 |
683 BrowserAccessibility* grandparent = parent->GetParent(); | 698 BrowserAccessibility* grandparent = parent->GetParent(); |
684 if (!grandparent) | 699 if (!grandparent) |
685 return false; | 700 return false; |
686 | 701 |
687 return grandparent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL; | 702 return grandparent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL; |
688 } | 703 } |
689 | 704 |
| 705 std::string BrowserAccessibility::GetTextRecursive() const { |
| 706 if (!name_.empty()) { |
| 707 return name_; |
| 708 } |
| 709 |
| 710 std::string result; |
| 711 for (uint32 i = 0; i < PlatformChildCount(); ++i) |
| 712 result += PlatformGetChild(i)->GetTextRecursive(); |
| 713 return result; |
| 714 } |
| 715 |
690 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 716 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
691 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 717 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
692 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 718 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
693 | 719 |
694 int len = 0; | 720 int len = 0; |
695 for (size_t i = 0; i < InternalChildCount(); ++i) | 721 for (size_t i = 0; i < InternalChildCount(); ++i) |
696 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 722 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
697 return len; | 723 return len; |
698 } | 724 } |
699 | 725 |
700 BrowserAccessibility* BrowserAccessibility::GetParentForBoundsCalculation() | 726 BrowserAccessibility* BrowserAccessibility::GetParentForBoundsCalculation() |
701 const { | 727 const { |
702 if (!node_ || !manager_) | 728 if (!node_ || !manager_) |
703 return NULL; | 729 return NULL; |
704 ui::AXNode* parent = node_->parent(); | 730 ui::AXNode* parent = node_->parent(); |
705 if (parent) | 731 if (parent) |
706 return manager_->GetFromAXNode(parent); | 732 return manager_->GetFromAXNode(parent); |
707 | 733 |
708 if (!manager_->delegate()) | 734 if (!manager_->delegate()) |
709 return NULL; | 735 return NULL; |
710 | 736 |
711 return manager_->delegate()->AccessibilityGetParentFrame(); | 737 return manager_->delegate()->AccessibilityGetParentFrame(); |
712 } | 738 } |
713 | 739 |
714 } // namespace content | 740 } // namespace content |
OLD | NEW |