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" |
11 #include "content/browser/accessibility/browser_accessibility_manager.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager.h" |
12 #include "content/common/accessibility_messages.h" | 12 #include "content/common/accessibility_messages.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 #if !defined(OS_MACOSX) && \ | 16 #if !defined(OS_MACOSX) && \ |
17 !defined(OS_WIN) && \ | 17 !defined(OS_WIN) && \ |
18 !defined(OS_ANDROID) | 18 !defined(OS_ANDROID) |
19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other | 19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other |
20 // platform, instantiate the base class. | 20 // platform, instantiate the base class. |
21 // static | 21 // static |
22 BrowserAccessibility* BrowserAccessibility::Create() { | 22 BrowserAccessibility* BrowserAccessibility::Create() { |
23 return new BrowserAccessibility(); | 23 return new BrowserAccessibility(); |
24 } | 24 } |
25 #endif | 25 #endif |
26 | 26 |
27 BrowserAccessibility::BrowserAccessibility() | 27 BrowserAccessibility::BrowserAccessibility() |
28 : manager_(NULL), | 28 : manager_(NULL), |
29 node_(NULL), | 29 node_(NULL) { |
30 child_frame_tree_node_id_(0) { | |
31 } | 30 } |
32 | 31 |
33 BrowserAccessibility::~BrowserAccessibility() { | 32 BrowserAccessibility::~BrowserAccessibility() { |
34 } | 33 } |
35 | 34 |
36 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
37 ui::AXNode* node) { | 36 ui::AXNode* node) { |
38 manager_ = manager; | 37 manager_ = manager; |
39 node_ = node; | 38 node_ = node; |
40 } | 39 } |
(...skipping 16 matching lines...) Expand all Loading... |
57 case ui::AX_ROLE_STATIC_TEXT: | 56 case ui::AX_ROLE_STATIC_TEXT: |
58 case ui::AX_ROLE_TEXT_AREA: | 57 case ui::AX_ROLE_TEXT_AREA: |
59 case ui::AX_ROLE_TEXT_FIELD: | 58 case ui::AX_ROLE_TEXT_FIELD: |
60 return true; | 59 return true; |
61 default: | 60 default: |
62 return false; | 61 return false; |
63 } | 62 } |
64 } | 63 } |
65 | 64 |
66 uint32 BrowserAccessibility::PlatformChildCount() const { | 65 uint32 BrowserAccessibility::PlatformChildCount() const { |
67 if (child_frame_tree_node_id_ && | |
68 manager_ && manager_->delegate()) { | |
69 BrowserAccessibilityManager* child_manager = | |
70 manager_->delegate()->AccessibilityGetChildFrame( | |
71 child_frame_tree_node_id_); | |
72 if (child_manager) | |
73 return 1; | |
74 } | |
75 | |
76 return PlatformIsLeaf() ? 0 : InternalChildCount(); | 66 return PlatformIsLeaf() ? 0 : InternalChildCount(); |
77 } | 67 } |
78 | 68 |
79 bool BrowserAccessibility::IsNative() const { | 69 bool BrowserAccessibility::IsNative() const { |
80 return false; | 70 return false; |
81 } | 71 } |
82 | 72 |
83 bool BrowserAccessibility::IsDescendantOf( | 73 bool BrowserAccessibility::IsDescendantOf( |
84 BrowserAccessibility* ancestor) { | 74 BrowserAccessibility* ancestor) { |
85 if (this == ancestor) { | 75 if (this == ancestor) { |
86 return true; | 76 return true; |
87 } else if (GetParent()) { | 77 } else if (GetParent()) { |
88 return GetParent()->IsDescendantOf(ancestor); | 78 return GetParent()->IsDescendantOf(ancestor); |
89 } | 79 } |
90 | 80 |
91 return false; | 81 return false; |
92 } | 82 } |
93 | 83 |
94 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( | 84 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( |
95 uint32 child_index) const { | 85 uint32 child_index) const { |
96 if (child_index == 0 && child_frame_tree_node_id_ && | 86 DCHECK(child_index < InternalChildCount()); |
97 manager_ && | 87 BrowserAccessibility* result = InternalGetChild(child_index); |
98 manager_->delegate()) { | 88 |
| 89 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) { |
99 BrowserAccessibilityManager* child_manager = | 90 BrowserAccessibilityManager* child_manager = |
100 manager_->delegate()->AccessibilityGetChildFrame( | 91 manager_->delegate()->AccessibilityGetChildFrame(result->GetId()); |
101 child_frame_tree_node_id_); | |
102 if (child_manager) | 92 if (child_manager) |
103 return child_manager->GetRoot(); | 93 result = child_manager->GetRoot(); |
104 } | 94 } |
105 | 95 |
106 DCHECK(child_index < InternalChildCount()); | 96 return result; |
107 return InternalGetChild(child_index); | |
108 } | 97 } |
109 | 98 |
110 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 99 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
111 if (GetParent() && GetIndexInParent() > 0) | 100 if (GetParent() && GetIndexInParent() > 0) |
112 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 101 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
113 | 102 |
114 return NULL; | 103 return NULL; |
115 } | 104 } |
116 | 105 |
117 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { | 106 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { |
(...skipping 19 matching lines...) Expand all Loading... |
137 return NULL; | 126 return NULL; |
138 return manager_->GetFromAXNode(node_->children()[child_index]); | 127 return manager_->GetFromAXNode(node_->children()[child_index]); |
139 } | 128 } |
140 | 129 |
141 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 130 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
142 if (!node_ || !manager_) | 131 if (!node_ || !manager_) |
143 return NULL; | 132 return NULL; |
144 ui::AXNode* parent = node_->parent(); | 133 ui::AXNode* parent = node_->parent(); |
145 if (parent) | 134 if (parent) |
146 return manager_->GetFromAXNode(parent); | 135 return manager_->GetFromAXNode(parent); |
147 return manager_->GetCrossFrameParent(); | 136 |
| 137 if (!manager_->delegate()) |
| 138 return NULL; |
| 139 |
| 140 BrowserAccessibility* host_node = |
| 141 manager_->delegate()->AccessibilityGetParentFrame(); |
| 142 if (!host_node) |
| 143 return NULL; |
| 144 |
| 145 return host_node->GetParent(); |
148 } | 146 } |
149 | 147 |
150 int32 BrowserAccessibility::GetIndexInParent() const { | 148 int32 BrowserAccessibility::GetIndexInParent() const { |
151 return node_ ? node_->index_in_parent() : -1; | 149 return node_ ? node_->index_in_parent() : -1; |
152 } | 150 } |
153 | 151 |
154 int32 BrowserAccessibility::GetId() const { | 152 int32 BrowserAccessibility::GetId() const { |
155 return node_ ? node_->id() : -1; | 153 return node_ ? node_->id() : -1; |
156 } | 154 } |
157 | 155 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 693 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
696 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 694 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
697 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 695 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
698 | 696 |
699 int len = 0; | 697 int len = 0; |
700 for (size_t i = 0; i < InternalChildCount(); ++i) | 698 for (size_t i = 0; i < InternalChildCount(); ++i) |
701 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 699 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
702 return len; | 700 return len; |
703 } | 701 } |
704 | 702 |
705 void BrowserAccessibility::SetChildFrameTreeNodeId( | |
706 int64 child_frame_tree_node_id) { | |
707 child_frame_tree_node_id_ = child_frame_tree_node_id; | |
708 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, this); | |
709 } | |
710 | |
711 } // namespace content | 703 } // namespace content |
OLD | NEW |