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_ && | |
97 manager_ && | |
98 manager_->delegate()) { | |
99 BrowserAccessibilityManager* child_manager = | |
100 manager_->delegate()->AccessibilityGetChildFrame( | |
101 child_frame_tree_node_id_); | |
102 if (child_manager) | |
103 return child_manager->GetRoot(); | |
104 } | |
105 | |
106 DCHECK(child_index < InternalChildCount()); | 86 DCHECK(child_index < InternalChildCount()); |
107 return InternalGetChild(child_index); | 87 return InternalGetChild(child_index); |
108 } | 88 } |
109 | 89 |
110 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 90 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
111 if (GetParent() && GetIndexInParent() > 0) | 91 if (GetParent() && GetIndexInParent() > 0) |
112 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 92 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
113 | 93 |
114 return NULL; | 94 return NULL; |
115 } | 95 } |
(...skipping 19 matching lines...) Expand all Loading... |
135 uint32 child_index) const { | 115 uint32 child_index) const { |
136 if (!node_ || !manager_) | 116 if (!node_ || !manager_) |
137 return NULL; | 117 return NULL; |
138 return manager_->GetFromAXNode(node_->children()[child_index]); | 118 return manager_->GetFromAXNode(node_->children()[child_index]); |
139 } | 119 } |
140 | 120 |
141 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 121 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
142 if (!node_ || !manager_) | 122 if (!node_ || !manager_) |
143 return NULL; | 123 return NULL; |
144 ui::AXNode* parent = node_->parent(); | 124 ui::AXNode* parent = node_->parent(); |
145 if (parent) | 125 return parent ? manager_->GetFromAXNode(parent) : NULL; |
146 return manager_->GetFromAXNode(parent); | |
147 return manager_->GetCrossFrameParent(); | |
148 } | 126 } |
149 | 127 |
150 int32 BrowserAccessibility::GetIndexInParent() const { | 128 int32 BrowserAccessibility::GetIndexInParent() const { |
151 return node_ ? node_->index_in_parent() : -1; | 129 return node_ ? node_->index_in_parent() : -1; |
152 } | 130 } |
153 | 131 |
154 int32 BrowserAccessibility::GetId() const { | 132 int32 BrowserAccessibility::GetId() const { |
155 return node_ ? node_->id() : -1; | 133 return node_ ? node_->id() : -1; |
156 } | 134 } |
157 | 135 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 673 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
696 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 674 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
697 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 675 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
698 | 676 |
699 int len = 0; | 677 int len = 0; |
700 for (size_t i = 0; i < InternalChildCount(); ++i) | 678 for (size_t i = 0; i < InternalChildCount(); ++i) |
701 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 679 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
702 return len; | 680 return len; |
703 } | 681 } |
704 | 682 |
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 | 683 } // namespace content |
OLD | NEW |