Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: content/browser/accessibility/browser_accessibility.cc

Issue 224803005: Refactor BrowserAccessibility to prepare for AXNode (re-land) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gtk Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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(TOOLKIT_GTK) && \ 18 !defined(TOOLKIT_GTK) && \
19 !defined(OS_ANDROID) 19 !defined(OS_ANDROID)
20 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, 20 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK,
21 // and Win. For any other platform, instantiate the base class. 21 // and Win. For any other platform, instantiate the base class.
22 // static 22 // static
23 BrowserAccessibility* BrowserAccessibility::Create() { 23 BrowserAccessibility* BrowserAccessibility::Create() {
24 return new BrowserAccessibility(); 24 return new BrowserAccessibility();
25 } 25 }
26 #endif 26 #endif
27 27
28 BrowserAccessibility::BrowserAccessibility() 28 BrowserAccessibility::BrowserAccessibility()
29 : manager_(NULL), 29 : manager_(NULL),
30 parent_(NULL), 30 deprecated_parent_(NULL),
31 index_in_parent_(0), 31 deprecated_index_in_parent_(0),
32 renderer_id_(0),
33 role_(0),
34 state_(0),
35 instance_active_(false) { 32 instance_active_(false) {
33 data_.id = 0;
34 data_.role = ui::AX_ROLE_UNKNOWN;
35 data_.state = 0;
36 } 36 }
37 37
38 BrowserAccessibility::~BrowserAccessibility() { 38 BrowserAccessibility::~BrowserAccessibility() {
39 } 39 }
40 40
41 bool BrowserAccessibility::PlatformIsLeaf() const { 41 bool BrowserAccessibility::PlatformIsLeaf() const {
42 if (child_count() == 0) 42 if (InternalChildCount() == 0)
43 return true; 43 return true;
44 44
45 // All of these roles may have children that we use as internal 45 // All of these roles may have children that we use as internal
46 // implementation details, but we want to expose them as leaves 46 // implementation details, but we want to expose them as leaves
47 // to platform accessibility APIs. 47 // to platform accessibility APIs.
48 switch (role_) { 48 switch (GetRole()) {
49 case ui::AX_ROLE_EDITABLE_TEXT: 49 case ui::AX_ROLE_EDITABLE_TEXT:
50 case ui::AX_ROLE_SLIDER: 50 case ui::AX_ROLE_SLIDER:
51 case ui::AX_ROLE_STATIC_TEXT: 51 case ui::AX_ROLE_STATIC_TEXT:
52 case ui::AX_ROLE_TEXT_AREA: 52 case ui::AX_ROLE_TEXT_AREA:
53 case ui::AX_ROLE_TEXT_FIELD: 53 case ui::AX_ROLE_TEXT_FIELD:
54 return true; 54 return true;
55 default: 55 default:
56 return false; 56 return false;
57 } 57 }
58 } 58 }
59 59
60 uint32 BrowserAccessibility::PlatformChildCount() const { 60 uint32 BrowserAccessibility::PlatformChildCount() const {
61 return PlatformIsLeaf() ? 0 : children_.size(); 61 return PlatformIsLeaf() ? 0 : InternalChildCount();
62 } 62 }
63 63
64 void BrowserAccessibility::DetachTree( 64 void BrowserAccessibility::DetachTree(
65 std::vector<BrowserAccessibility*>* nodes) { 65 std::vector<BrowserAccessibility*>* nodes) {
66 nodes->push_back(this); 66 nodes->push_back(this);
67 for (size_t i = 0; i < children_.size(); ++i) 67 for (size_t i = 0; i < InternalChildCount(); ++i)
68 children_[i]->DetachTree(nodes); 68 InternalGetChild(i)->DetachTree(nodes);
69 children_.clear(); 69 deprecated_children_.clear();
70 parent_ = NULL; 70 deprecated_parent_ = NULL;
71 } 71 }
72 72
73 void BrowserAccessibility::InitializeTreeStructure( 73 void BrowserAccessibility::InitializeTreeStructure(
74 BrowserAccessibilityManager* manager, 74 BrowserAccessibilityManager* manager,
75 BrowserAccessibility* parent, 75 BrowserAccessibility* parent,
76 int32 renderer_id, 76 int32 id,
77 int32 index_in_parent) { 77 int32 index_in_parent) {
78 manager_ = manager; 78 manager_ = manager;
79 parent_ = parent; 79 deprecated_parent_ = parent;
80 renderer_id_ = renderer_id; 80 data_.id = id;
81 index_in_parent_ = index_in_parent; 81 deprecated_index_in_parent_ = index_in_parent;
82 } 82 }
83 83
84 void BrowserAccessibility::InitializeData(const ui::AXNodeData& src) { 84 void BrowserAccessibility::InitializeData(const ui::AXNodeData& src) {
85 DCHECK_EQ(renderer_id_, src.id); 85 DCHECK_EQ(data_.id, src.id);
86 role_ = src.role; 86 data_ = src;
87 state_ = src.state;
88 string_attributes_ = src.string_attributes;
89 int_attributes_ = src.int_attributes;
90 float_attributes_ = src.float_attributes;
91 bool_attributes_ = src.bool_attributes;
92 intlist_attributes_ = src.intlist_attributes;
93 html_attributes_ = src.html_attributes;
94 location_ = src.location;
95 instance_active_ = true; 87 instance_active_ = true;
96 88
97 GetStringAttribute(ui::AX_ATTR_NAME, &name_); 89 GetStringAttribute(ui::AX_ATTR_NAME, &name_);
98 GetStringAttribute(ui::AX_ATTR_VALUE, &value_); 90 GetStringAttribute(ui::AX_ATTR_VALUE, &value_);
99 91
100 PreInitialize(); 92 PreInitialize();
101 } 93 }
102 94
103 bool BrowserAccessibility::IsNative() const { 95 bool BrowserAccessibility::IsNative() const {
104 return false; 96 return false;
105 } 97 }
106 98
107 void BrowserAccessibility::SwapChildren( 99 void BrowserAccessibility::SwapChildren(
108 std::vector<BrowserAccessibility*>& children) { 100 std::vector<BrowserAccessibility*>& children) {
109 children.swap(children_); 101 children.swap(deprecated_children_);
110 } 102 }
111 103
112 void BrowserAccessibility::UpdateParent(BrowserAccessibility* parent, 104 void BrowserAccessibility::UpdateParent(BrowserAccessibility* parent,
113 int index_in_parent) { 105 int index_in_parent) {
114 parent_ = parent; 106 deprecated_parent_ = parent;
115 index_in_parent_ = index_in_parent; 107 deprecated_index_in_parent_ = index_in_parent;
116 } 108 }
117 109
118 void BrowserAccessibility::SetLocation(const gfx::Rect& new_location) { 110 void BrowserAccessibility::SetLocation(const gfx::Rect& new_location) {
119 location_ = new_location; 111 data_.location = new_location;
120 } 112 }
121 113
122 bool BrowserAccessibility::IsDescendantOf( 114 bool BrowserAccessibility::IsDescendantOf(
123 BrowserAccessibility* ancestor) { 115 BrowserAccessibility* ancestor) {
124 if (this == ancestor) { 116 if (this == ancestor) {
125 return true; 117 return true;
126 } else if (parent_) { 118 } else if (GetParent()) {
127 return parent_->IsDescendantOf(ancestor); 119 return GetParent()->IsDescendantOf(ancestor);
128 } 120 }
129 121
130 return false; 122 return false;
131 } 123 }
132 124
133 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( 125 BrowserAccessibility* BrowserAccessibility::PlatformGetChild(
134 uint32 child_index) const { 126 uint32 child_index) const {
135 DCHECK(child_index < children_.size()); 127 DCHECK(child_index < InternalChildCount());
136 return children_[child_index]; 128 return InternalGetChild(child_index);
137 } 129 }
138 130
139 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { 131 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() {
140 if (parent_ && index_in_parent_ > 0) 132 if (GetParent() && GetIndexInParent() > 0)
141 return parent_->children_[index_in_parent_ - 1]; 133 return GetParent()->InternalGetChild(GetIndexInParent() - 1);
142 134
143 return NULL; 135 return NULL;
144 } 136 }
145 137
146 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { 138 BrowserAccessibility* BrowserAccessibility::GetNextSibling() {
147 if (parent_ && 139 if (GetParent() &&
148 index_in_parent_ >= 0 && 140 GetIndexInParent() >= 0 &&
149 index_in_parent_ < static_cast<int>(parent_->children_.size() - 1)) { 141 GetIndexInParent() < static_cast<int>(
150 return parent_->children_[index_in_parent_ + 1]; 142 GetParent()->InternalChildCount() - 1)) {
143 return GetParent()->InternalGetChild(GetIndexInParent() + 1);
151 } 144 }
152 145
153 return NULL; 146 return NULL;
154 } 147 }
155 148
156 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { 149 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const {
157 gfx::Rect bounds = location_; 150 gfx::Rect bounds = GetLocation();
158 151
159 // Walk up the parent chain. Every time we encounter a Web Area, offset 152 // Walk up the parent chain. Every time we encounter a Web Area, offset
160 // based on the scroll bars and then offset based on the origin of that 153 // based on the scroll bars and then offset based on the origin of that
161 // nested web area. 154 // nested web area.
162 BrowserAccessibility* parent = parent_; 155 BrowserAccessibility* parent = GetParent();
163 bool need_to_offset_web_area = 156 bool need_to_offset_web_area =
164 (role_ == ui::AX_ROLE_WEB_AREA || 157 (GetRole() == ui::AX_ROLE_WEB_AREA ||
165 role_ == ui::AX_ROLE_ROOT_WEB_AREA); 158 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA);
166 while (parent) { 159 while (parent) {
167 if (need_to_offset_web_area && 160 if (need_to_offset_web_area &&
168 parent->location().width() > 0 && 161 parent->GetLocation().width() > 0 &&
169 parent->location().height() > 0) { 162 parent->GetLocation().height() > 0) {
170 bounds.Offset(parent->location().x(), parent->location().y()); 163 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y());
171 need_to_offset_web_area = false; 164 need_to_offset_web_area = false;
172 } 165 }
173 166
174 // On some platforms, we don't want to take the root scroll offsets 167 // On some platforms, we don't want to take the root scroll offsets
175 // into account. 168 // into account.
176 if (parent->role() == ui::AX_ROLE_ROOT_WEB_AREA && 169 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA &&
177 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { 170 !manager()->UseRootScrollOffsetsWhenComputingBounds()) {
178 break; 171 break;
179 } 172 }
180 173
181 if (parent->role() == ui::AX_ROLE_WEB_AREA || 174 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA ||
182 parent->role() == ui::AX_ROLE_ROOT_WEB_AREA) { 175 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) {
183 int sx = 0; 176 int sx = 0;
184 int sy = 0; 177 int sy = 0;
185 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && 178 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) &&
186 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { 179 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) {
187 bounds.Offset(-sx, -sy); 180 bounds.Offset(-sx, -sy);
188 } 181 }
189 need_to_offset_web_area = true; 182 need_to_offset_web_area = true;
190 } 183 }
191 parent = parent->parent(); 184 parent = parent->GetParent();
192 } 185 }
193 186
194 return bounds; 187 return bounds;
195 } 188 }
196 189
197 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { 190 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const {
198 gfx::Rect bounds = GetLocalBoundsRect(); 191 gfx::Rect bounds = GetLocalBoundsRect();
199 192
200 // Adjust the bounds by the top left corner of the containing view's bounds 193 // Adjust the bounds by the top left corner of the containing view's bounds
201 // in screen coordinates. 194 // in screen coordinates.
202 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); 195 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
203 196
204 return bounds; 197 return bounds;
205 } 198 }
206 199
207 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len) 200 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len)
208 const { 201 const {
209 if (role() != ui::AX_ROLE_STATIC_TEXT) { 202 if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
210 // Apply recursively to all static text descendants. For example, if 203 // Apply recursively to all static text descendants. For example, if
211 // you call it on a div with two text node children, it just calls 204 // you call it on a div with two text node children, it just calls
212 // GetLocalBoundsForRange on each of the two children (adjusting 205 // GetLocalBoundsForRange on each of the two children (adjusting
213 // |start| for each one) and unions the resulting rects. 206 // |start| for each one) and unions the resulting rects.
214 gfx::Rect bounds; 207 gfx::Rect bounds;
215 for (size_t i = 0; i < children_.size(); ++i) { 208 for (size_t i = 0; i < InternalChildCount(); ++i) {
216 BrowserAccessibility* child = children_[i]; 209 BrowserAccessibility* child = InternalGetChild(i);
217 int child_len = child->GetStaticTextLenRecursive(); 210 int child_len = child->GetStaticTextLenRecursive();
218 if (start < child_len && start + len > 0) { 211 if (start < child_len && start + len > 0) {
219 gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len); 212 gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len);
220 bounds.Union(child_rect); 213 bounds.Union(child_rect);
221 } 214 }
222 start -= child_len; 215 start -= child_len;
223 } 216 }
224 return bounds; 217 return bounds;
225 } 218 }
226 219
227 int end = start + len; 220 int end = start + len;
228 int child_start = 0; 221 int child_start = 0;
229 int child_end = 0; 222 int child_end = 0;
230 223
231 gfx::Rect bounds; 224 gfx::Rect bounds;
232 for (size_t i = 0; i < children_.size() && child_end < start + len; ++i) { 225 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) {
233 BrowserAccessibility* child = children_[i]; 226 BrowserAccessibility* child = InternalGetChild(i);
234 DCHECK_EQ(child->role(), ui::AX_ROLE_INLINE_TEXT_BOX); 227 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
235 std::string child_text; 228 std::string child_text;
236 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text); 229 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text);
237 int child_len = static_cast<int>(child_text.size()); 230 int child_len = static_cast<int>(child_text.size());
238 child_start = child_end; 231 child_start = child_end;
239 child_end += child_len; 232 child_end += child_len;
240 233
241 if (child_end < start) 234 if (child_end < start)
242 continue; 235 continue;
243 236
244 int overlap_start = std::max(start, child_start); 237 int overlap_start = std::max(start, child_start);
245 int overlap_end = std::min(end, child_end); 238 int overlap_end = std::min(end, child_end);
246 239
247 int local_start = overlap_start - child_start; 240 int local_start = overlap_start - child_start;
248 int local_end = overlap_end - child_start; 241 int local_end = overlap_end - child_start;
249 242
250 gfx::Rect child_rect = child->location(); 243 gfx::Rect child_rect = child->GetLocation();
251 int text_direction = child->GetIntAttribute( 244 int text_direction = child->GetIntAttribute(
252 ui::AX_ATTR_TEXT_DIRECTION); 245 ui::AX_ATTR_TEXT_DIRECTION);
253 const std::vector<int32>& character_offsets = child->GetIntListAttribute( 246 const std::vector<int32>& character_offsets = child->GetIntListAttribute(
254 ui::AX_ATTR_CHARACTER_OFFSETS); 247 ui::AX_ATTR_CHARACTER_OFFSETS);
255 int start_pixel_offset = 248 int start_pixel_offset =
256 local_start > 0 ? character_offsets[local_start - 1] : 0; 249 local_start > 0 ? character_offsets[local_start - 1] : 0;
257 int end_pixel_offset = 250 int end_pixel_offset =
258 local_end > 0 ? character_offsets[local_end - 1] : 0; 251 local_end > 0 ? character_offsets[local_end - 1] : 0;
259 252
260 gfx::Rect child_overlap_rect; 253 gfx::Rect child_overlap_rect;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 314
322 // Walk the children recursively looking for the BrowserAccessibility that 315 // Walk the children recursively looking for the BrowserAccessibility that
323 // most tightly encloses the specified point. Walk backwards so that in 316 // most tightly encloses the specified point. Walk backwards so that in
324 // the absence of any other information, we assume the object that occurs 317 // the absence of any other information, we assume the object that occurs
325 // later in the tree is on top of one that comes before it. 318 // later in the tree is on top of one that comes before it.
326 for (int i = static_cast<int>(PlatformChildCount()) - 1; i >= 0; --i) { 319 for (int i = static_cast<int>(PlatformChildCount()) - 1; i >= 0; --i) {
327 BrowserAccessibility* child = PlatformGetChild(i); 320 BrowserAccessibility* child = PlatformGetChild(i);
328 321
329 // Skip table columns because cells are only contained in rows, 322 // Skip table columns because cells are only contained in rows,
330 // not columns. 323 // not columns.
331 if (child->role() == ui::AX_ROLE_COLUMN) 324 if (child->GetRole() == ui::AX_ROLE_COLUMN)
332 continue; 325 continue;
333 326
334 if (child->GetGlobalBoundsRect().Contains(point)) { 327 if (child->GetGlobalBoundsRect().Contains(point)) {
335 BrowserAccessibility* result = child->BrowserAccessibilityForPoint(point); 328 BrowserAccessibility* result = child->BrowserAccessibilityForPoint(point);
336 if (result == child && !child_result) 329 if (result == child && !child_result)
337 child_result = result; 330 child_result = result;
338 if (result != child && !descendant_result) 331 if (result != child && !descendant_result)
339 descendant_result = result; 332 descendant_result = result;
340 } 333 }
341 334
342 if (child_result && descendant_result) 335 if (child_result && descendant_result)
343 break; 336 break;
344 } 337 }
345 338
346 // Explanation of logic: it's possible that this point overlaps more than 339 // Explanation of logic: it's possible that this point overlaps more than
347 // one child of this object. If so, as a heuristic we prefer if the point 340 // one child of this object. If so, as a heuristic we prefer if the point
348 // overlaps a descendant of one of the two children and not the other. 341 // overlaps a descendant of one of the two children and not the other.
349 // As an example, suppose you have two rows of buttons - the buttons don't 342 // As an example, suppose you have two rows of buttons - the buttons don't
350 // overlap, but the rows do. Without this heuristic, we'd greedily only 343 // overlap, but the rows do. Without this heuristic, we'd greedily only
351 // consider one of the containers. 344 // consider one of the containers.
352 if (descendant_result) 345 if (descendant_result)
353 return descendant_result; 346 return descendant_result;
354 if (child_result) 347 if (child_result)
355 return child_result; 348 return child_result;
356 349
357 return this; 350 return this;
358 } 351 }
359 352
360 void BrowserAccessibility::Destroy() { 353 void BrowserAccessibility::Destroy() {
361 for (std::vector<BrowserAccessibility*>::iterator iter = children_.begin(); 354 for (uint32 i = 0; i < InternalChildCount(); i++)
362 iter != children_.end(); 355 InternalGetChild(i)->Destroy();
363 ++iter) { 356 deprecated_children_.clear();
364 (*iter)->Destroy();
365 }
366 children_.clear();
367 357
368 // Allow the object to fire a TextRemoved notification. 358 // Allow the object to fire a TextRemoved notification.
369 name_.clear(); 359 name_.clear();
370 value_.clear(); 360 value_.clear();
371 PostInitialize(); 361 PostInitialize();
372 362
373 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); 363 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this);
374 364
375 instance_active_ = false; 365 instance_active_ = false;
376 manager_->RemoveNode(this); 366 manager_->RemoveNode(this);
377 NativeReleaseReference(); 367 NativeReleaseReference();
378 } 368 }
379 369
380 void BrowserAccessibility::NativeReleaseReference() { 370 void BrowserAccessibility::NativeReleaseReference() {
381 delete this; 371 delete this;
382 } 372 }
383 373
384 bool BrowserAccessibility::HasBoolAttribute( 374 bool BrowserAccessibility::HasBoolAttribute(
385 ui::AXBoolAttribute attribute) const { 375 ui::AXBoolAttribute attribute) const {
386 for (size_t i = 0; i < bool_attributes_.size(); ++i) { 376 for (size_t i = 0; i < data_.bool_attributes.size(); ++i) {
387 if (bool_attributes_[i].first == attribute) 377 if (data_.bool_attributes[i].first == attribute)
388 return true; 378 return true;
389 } 379 }
390 380
391 return false; 381 return false;
392 } 382 }
393 383
394 384
395 bool BrowserAccessibility::GetBoolAttribute( 385 bool BrowserAccessibility::GetBoolAttribute(
396 ui::AXBoolAttribute attribute) const { 386 ui::AXBoolAttribute attribute) const {
397 for (size_t i = 0; i < bool_attributes_.size(); ++i) { 387 for (size_t i = 0; i < data_.bool_attributes.size(); ++i) {
398 if (bool_attributes_[i].first == attribute) 388 if (data_.bool_attributes[i].first == attribute)
399 return bool_attributes_[i].second; 389 return data_.bool_attributes[i].second;
400 } 390 }
401 391
402 return false; 392 return false;
403 } 393 }
404 394
405 bool BrowserAccessibility::GetBoolAttribute( 395 bool BrowserAccessibility::GetBoolAttribute(
406 ui::AXBoolAttribute attribute, bool* value) const { 396 ui::AXBoolAttribute attribute, bool* value) const {
407 for (size_t i = 0; i < bool_attributes_.size(); ++i) { 397 for (size_t i = 0; i < data_.bool_attributes.size(); ++i) {
408 if (bool_attributes_[i].first == attribute) { 398 if (data_.bool_attributes[i].first == attribute) {
409 *value = bool_attributes_[i].second; 399 *value = data_.bool_attributes[i].second;
410 return true; 400 return true;
411 } 401 }
412 } 402 }
413 403
414 return false; 404 return false;
415 } 405 }
416 406
417 bool BrowserAccessibility::HasFloatAttribute( 407 bool BrowserAccessibility::HasFloatAttribute(
418 ui::AXFloatAttribute attribute) const { 408 ui::AXFloatAttribute attribute) const {
419 for (size_t i = 0; i < float_attributes_.size(); ++i) { 409 for (size_t i = 0; i < data_.float_attributes.size(); ++i) {
420 if (float_attributes_[i].first == attribute) 410 if (data_.float_attributes[i].first == attribute)
421 return true; 411 return true;
422 } 412 }
423 413
424 return false; 414 return false;
425 } 415 }
426 416
427 float BrowserAccessibility::GetFloatAttribute( 417 float BrowserAccessibility::GetFloatAttribute(
428 ui::AXFloatAttribute attribute) const { 418 ui::AXFloatAttribute attribute) const {
429 for (size_t i = 0; i < float_attributes_.size(); ++i) { 419 for (size_t i = 0; i < data_.float_attributes.size(); ++i) {
430 if (float_attributes_[i].first == attribute) 420 if (data_.float_attributes[i].first == attribute)
431 return float_attributes_[i].second; 421 return data_.float_attributes[i].second;
432 } 422 }
433 423
434 return 0.0; 424 return 0.0;
435 } 425 }
436 426
437 bool BrowserAccessibility::GetFloatAttribute( 427 bool BrowserAccessibility::GetFloatAttribute(
438 ui::AXFloatAttribute attribute, float* value) const { 428 ui::AXFloatAttribute attribute, float* value) const {
439 for (size_t i = 0; i < float_attributes_.size(); ++i) { 429 for (size_t i = 0; i < data_.float_attributes.size(); ++i) {
440 if (float_attributes_[i].first == attribute) { 430 if (data_.float_attributes[i].first == attribute) {
441 *value = float_attributes_[i].second; 431 *value = data_.float_attributes[i].second;
442 return true; 432 return true;
443 } 433 }
444 } 434 }
445 435
446 return false; 436 return false;
447 } 437 }
448 438
449 bool BrowserAccessibility::HasIntAttribute( 439 bool BrowserAccessibility::HasIntAttribute(
450 ui::AXIntAttribute attribute) const { 440 ui::AXIntAttribute attribute) const {
451 for (size_t i = 0; i < int_attributes_.size(); ++i) { 441 for (size_t i = 0; i < data_.int_attributes.size(); ++i) {
452 if (int_attributes_[i].first == attribute) 442 if (data_.int_attributes[i].first == attribute)
453 return true; 443 return true;
454 } 444 }
455 445
456 return false; 446 return false;
457 } 447 }
458 448
459 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const { 449 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const {
460 for (size_t i = 0; i < int_attributes_.size(); ++i) { 450 for (size_t i = 0; i < data_.int_attributes.size(); ++i) {
461 if (int_attributes_[i].first == attribute) 451 if (data_.int_attributes[i].first == attribute)
462 return int_attributes_[i].second; 452 return data_.int_attributes[i].second;
463 } 453 }
464 454
465 return 0; 455 return 0;
466 } 456 }
467 457
468 bool BrowserAccessibility::GetIntAttribute( 458 bool BrowserAccessibility::GetIntAttribute(
469 ui::AXIntAttribute attribute, int* value) const { 459 ui::AXIntAttribute attribute, int* value) const {
470 for (size_t i = 0; i < int_attributes_.size(); ++i) { 460 for (size_t i = 0; i < data_.int_attributes.size(); ++i) {
471 if (int_attributes_[i].first == attribute) { 461 if (data_.int_attributes[i].first == attribute) {
472 *value = int_attributes_[i].second; 462 *value = data_.int_attributes[i].second;
473 return true; 463 return true;
474 } 464 }
475 } 465 }
476 466
477 return false; 467 return false;
478 } 468 }
479 469
480 bool BrowserAccessibility::HasStringAttribute( 470 bool BrowserAccessibility::HasStringAttribute(
481 ui::AXStringAttribute attribute) const { 471 ui::AXStringAttribute attribute) const {
482 for (size_t i = 0; i < string_attributes_.size(); ++i) { 472 for (size_t i = 0; i < data_.string_attributes.size(); ++i) {
483 if (string_attributes_[i].first == attribute) 473 if (data_.string_attributes[i].first == attribute)
484 return true; 474 return true;
485 } 475 }
486 476
487 return false; 477 return false;
488 } 478 }
489 479
490 const std::string& BrowserAccessibility::GetStringAttribute( 480 const std::string& BrowserAccessibility::GetStringAttribute(
491 ui::AXStringAttribute attribute) const { 481 ui::AXStringAttribute attribute) const {
492 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ()); 482 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ());
493 for (size_t i = 0; i < string_attributes_.size(); ++i) { 483 for (size_t i = 0; i < data_.string_attributes.size(); ++i) {
494 if (string_attributes_[i].first == attribute) 484 if (data_.string_attributes[i].first == attribute)
495 return string_attributes_[i].second; 485 return data_.string_attributes[i].second;
496 } 486 }
497 487
498 return empty_string; 488 return empty_string;
499 } 489 }
500 490
501 bool BrowserAccessibility::GetStringAttribute( 491 bool BrowserAccessibility::GetStringAttribute(
502 ui::AXStringAttribute attribute, std::string* value) const { 492 ui::AXStringAttribute attribute, std::string* value) const {
503 for (size_t i = 0; i < string_attributes_.size(); ++i) { 493 for (size_t i = 0; i < data_.string_attributes.size(); ++i) {
504 if (string_attributes_[i].first == attribute) { 494 if (data_.string_attributes[i].first == attribute) {
505 *value = string_attributes_[i].second; 495 *value = data_.string_attributes[i].second;
506 return true; 496 return true;
507 } 497 }
508 } 498 }
509 499
510 return false; 500 return false;
511 } 501 }
512 502
513 base::string16 BrowserAccessibility::GetString16Attribute( 503 base::string16 BrowserAccessibility::GetString16Attribute(
514 ui::AXStringAttribute attribute) const { 504 ui::AXStringAttribute attribute) const {
515 std::string value_utf8; 505 std::string value_utf8;
516 if (!GetStringAttribute(attribute, &value_utf8)) 506 if (!GetStringAttribute(attribute, &value_utf8))
517 return base::string16(); 507 return base::string16();
518 return base::UTF8ToUTF16(value_utf8); 508 return base::UTF8ToUTF16(value_utf8);
519 } 509 }
520 510
521 bool BrowserAccessibility::GetString16Attribute( 511 bool BrowserAccessibility::GetString16Attribute(
522 ui::AXStringAttribute attribute, 512 ui::AXStringAttribute attribute,
523 base::string16* value) const { 513 base::string16* value) const {
524 std::string value_utf8; 514 std::string value_utf8;
525 if (!GetStringAttribute(attribute, &value_utf8)) 515 if (!GetStringAttribute(attribute, &value_utf8))
526 return false; 516 return false;
527 *value = base::UTF8ToUTF16(value_utf8); 517 *value = base::UTF8ToUTF16(value_utf8);
528 return true; 518 return true;
529 } 519 }
530 520
531 void BrowserAccessibility::SetStringAttribute( 521 void BrowserAccessibility::SetStringAttribute(
532 ui::AXStringAttribute attribute, const std::string& value) { 522 ui::AXStringAttribute attribute, const std::string& value) {
533 for (size_t i = 0; i < string_attributes_.size(); ++i) { 523 for (size_t i = 0; i < data_.string_attributes.size(); ++i) {
534 if (string_attributes_[i].first == attribute) { 524 if (data_.string_attributes[i].first == attribute) {
535 string_attributes_[i].second = value; 525 data_.string_attributes[i].second = value;
536 return; 526 return;
537 } 527 }
538 } 528 }
539 if (!value.empty()) 529 if (!value.empty())
540 string_attributes_.push_back(std::make_pair(attribute, value)); 530 data_.string_attributes.push_back(std::make_pair(attribute, value));
541 } 531 }
542 532
543 bool BrowserAccessibility::HasIntListAttribute( 533 bool BrowserAccessibility::HasIntListAttribute(
544 ui::AXIntListAttribute attribute) const { 534 ui::AXIntListAttribute attribute) const {
545 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { 535 for (size_t i = 0; i < data_.intlist_attributes.size(); ++i) {
546 if (intlist_attributes_[i].first == attribute) 536 if (data_.intlist_attributes[i].first == attribute)
547 return true; 537 return true;
548 } 538 }
549 539
550 return false; 540 return false;
551 } 541 }
552 542
553 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute( 543 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute(
554 ui::AXIntListAttribute attribute) const { 544 ui::AXIntListAttribute attribute) const {
555 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ()); 545 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ());
556 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { 546 for (size_t i = 0; i < data_.intlist_attributes.size(); ++i) {
557 if (intlist_attributes_[i].first == attribute) 547 if (data_.intlist_attributes[i].first == attribute)
558 return intlist_attributes_[i].second; 548 return data_.intlist_attributes[i].second;
559 } 549 }
560 550
561 return empty_vector; 551 return empty_vector;
562 } 552 }
563 553
564 bool BrowserAccessibility::GetIntListAttribute( 554 bool BrowserAccessibility::GetIntListAttribute(
565 ui::AXIntListAttribute attribute, 555 ui::AXIntListAttribute attribute,
566 std::vector<int32>* value) const { 556 std::vector<int32>* value) const {
567 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { 557 for (size_t i = 0; i < data_.intlist_attributes.size(); ++i) {
568 if (intlist_attributes_[i].first == attribute) { 558 if (data_.intlist_attributes[i].first == attribute) {
569 *value = intlist_attributes_[i].second; 559 *value = data_.intlist_attributes[i].second;
570 return true; 560 return true;
571 } 561 }
572 } 562 }
573 563
574 return false; 564 return false;
575 } 565 }
576 566
577 bool BrowserAccessibility::GetHtmlAttribute( 567 bool BrowserAccessibility::GetHtmlAttribute(
578 const char* html_attr, std::string* value) const { 568 const char* html_attr, std::string* value) const {
579 for (size_t i = 0; i < html_attributes_.size(); ++i) { 569 for (size_t i = 0; i < GetHtmlAttributes().size(); ++i) {
580 const std::string& attr = html_attributes_[i].first; 570 const std::string& attr = GetHtmlAttributes()[i].first;
581 if (LowerCaseEqualsASCII(attr, html_attr)) { 571 if (LowerCaseEqualsASCII(attr, html_attr)) {
582 *value = html_attributes_[i].second; 572 *value = GetHtmlAttributes()[i].second;
583 return true; 573 return true;
584 } 574 }
585 } 575 }
586 576
587 return false; 577 return false;
588 } 578 }
589 579
590 bool BrowserAccessibility::GetHtmlAttribute( 580 bool BrowserAccessibility::GetHtmlAttribute(
591 const char* html_attr, base::string16* value) const { 581 const char* html_attr, base::string16* value) const {
592 std::string value_utf8; 582 std::string value_utf8;
(...skipping 22 matching lines...) Expand all
615 if (EqualsASCII(value, "true")) 605 if (EqualsASCII(value, "true"))
616 return true; 606 return true;
617 607
618 if (EqualsASCII(value, "mixed")) 608 if (EqualsASCII(value, "mixed"))
619 *is_mixed = true; 609 *is_mixed = true;
620 610
621 return false; // Not set 611 return false; // Not set
622 } 612 }
623 613
624 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { 614 bool BrowserAccessibility::HasState(ui::AXState state_enum) const {
625 return (state_ >> state_enum) & 1; 615 return (GetState() >> state_enum) & 1;
626 } 616 }
627 617
628 bool BrowserAccessibility::IsEditableText() const { 618 bool BrowserAccessibility::IsEditableText() const {
629 // These roles don't have readonly set, but they're not editable text. 619 // These roles don't have readonly set, but they're not editable text.
630 if (role_ == ui::AX_ROLE_SCROLL_AREA || 620 if (GetRole() == ui::AX_ROLE_SCROLL_AREA ||
631 role_ == ui::AX_ROLE_COLUMN || 621 GetRole() == ui::AX_ROLE_COLUMN ||
632 role_ == ui::AX_ROLE_TABLE_HEADER_CONTAINER) { 622 GetRole() == ui::AX_ROLE_TABLE_HEADER_CONTAINER) {
633 return false; 623 return false;
634 } 624 }
635 625
636 // Note: WebAXStateReadonly being false means it's either a text control, 626 // Note: WebAXStateReadonly being false means it's either a text control,
637 // or contenteditable. We also check for editable text roles to cover 627 // or contenteditable. We also check for editable text roles to cover
638 // another element that has role=textbox set on it. 628 // another element that has role=textbox set on it.
639 return (!HasState(ui::AX_STATE_READ_ONLY) || 629 return (!HasState(ui::AX_STATE_READ_ONLY) ||
640 role_ == ui::AX_ROLE_TEXT_FIELD || 630 GetRole() == ui::AX_ROLE_TEXT_FIELD ||
641 role_ == ui::AX_ROLE_TEXT_AREA); 631 GetRole() == ui::AX_ROLE_TEXT_AREA);
642 } 632 }
643 633
644 std::string BrowserAccessibility::GetTextRecursive() const { 634 std::string BrowserAccessibility::GetTextRecursive() const {
645 if (!name_.empty()) { 635 if (!name_.empty()) {
646 return name_; 636 return name_;
647 } 637 }
648 638
649 std::string result; 639 std::string result;
650 for (uint32 i = 0; i < PlatformChildCount(); ++i) 640 for (uint32 i = 0; i < PlatformChildCount(); ++i)
651 result += PlatformGetChild(i)->GetTextRecursive(); 641 result += PlatformGetChild(i)->GetTextRecursive();
652 return result; 642 return result;
653 } 643 }
654 644
655 int BrowserAccessibility::GetStaticTextLenRecursive() const { 645 int BrowserAccessibility::GetStaticTextLenRecursive() const {
656 if (role_ == ui::AX_ROLE_STATIC_TEXT) 646 if (GetRole() == ui::AX_ROLE_STATIC_TEXT)
657 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); 647 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size());
658 648
659 int len = 0; 649 int len = 0;
660 for (size_t i = 0; i < children_.size(); ++i) 650 for (size_t i = 0; i < InternalChildCount(); ++i)
661 len += children_[i]->GetStaticTextLenRecursive(); 651 len += InternalGetChild(i)->GetStaticTextLenRecursive();
662 return len; 652 return len;
663 } 653 }
664 654
665 } // namespace content 655 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility.h ('k') | content/browser/accessibility/browser_accessibility_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698