Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / accessibility / browser_accessibility.cc
blob16a8ed2147b8f909f96620eee26d39a6d421c293
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
3 // found in the LICENSE file.
5 #include "content/browser/accessibility/browser_accessibility.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "content/browser/accessibility/browser_accessibility_manager.h"
14 #include "content/common/accessibility_messages.h"
15 #include "ui/accessibility/ax_text_utils.h"
17 namespace content {
19 #if !defined(OS_MACOSX) && \
20 !defined(OS_WIN) && \
21 !defined(OS_ANDROID)
22 // We have subclassess of BrowserAccessibility on Mac and Win. For any other
23 // platform, instantiate the base class.
24 // static
25 BrowserAccessibility* BrowserAccessibility::Create() {
26 return new BrowserAccessibility();
28 #endif
30 BrowserAccessibility::BrowserAccessibility()
31 : manager_(NULL),
32 node_(NULL) {
35 BrowserAccessibility::~BrowserAccessibility() {
38 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager,
39 ui::AXNode* node) {
40 manager_ = manager;
41 node_ = node;
44 bool BrowserAccessibility::PlatformIsLeaf() const {
45 if (InternalChildCount() == 0)
46 return true;
48 // All of these roles may have children that we use as internal
49 // implementation details, but we want to expose them as leaves
50 // to platform accessibility APIs.
51 switch (GetRole()) {
52 case ui::AX_ROLE_LINE_BREAK:
53 case ui::AX_ROLE_SLIDER:
54 case ui::AX_ROLE_STATIC_TEXT:
55 case ui::AX_ROLE_TEXT_FIELD:
56 return true;
57 default:
58 return false;
62 uint32 BrowserAccessibility::PlatformChildCount() const {
63 return PlatformIsLeaf() ? 0 : InternalChildCount();
66 bool BrowserAccessibility::IsNative() const {
67 return false;
70 bool BrowserAccessibility::IsDescendantOf(
71 BrowserAccessibility* ancestor) {
72 if (this == ancestor) {
73 return true;
74 } else if (GetParent()) {
75 return GetParent()->IsDescendantOf(ancestor);
78 return false;
81 BrowserAccessibility* BrowserAccessibility::PlatformGetChild(
82 uint32 child_index) const {
83 DCHECK(child_index < InternalChildCount());
84 BrowserAccessibility* result = InternalGetChild(child_index);
86 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) {
87 BrowserAccessibilityManager* child_manager =
88 manager_->delegate()->AccessibilityGetChildFrame(result->GetId());
89 if (child_manager)
90 result = child_manager->GetRoot();
93 return result;
96 bool BrowserAccessibility::PlatformIsChildOfLeaf() const {
97 BrowserAccessibility* ancestor = GetParent();
98 while (ancestor) {
99 if (ancestor->PlatformIsLeaf())
100 return true;
101 ancestor = ancestor->GetParent();
104 return false;
107 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() {
108 if (GetParent() && GetIndexInParent() > 0)
109 return GetParent()->InternalGetChild(GetIndexInParent() - 1);
111 return NULL;
114 BrowserAccessibility* BrowserAccessibility::GetNextSibling() {
115 if (GetParent() &&
116 GetIndexInParent() >= 0 &&
117 GetIndexInParent() < static_cast<int>(
118 GetParent()->InternalChildCount() - 1)) {
119 return GetParent()->InternalGetChild(GetIndexInParent() + 1);
122 return NULL;
125 uint32 BrowserAccessibility::InternalChildCount() const {
126 if (!node_ || !manager_)
127 return 0;
128 return static_cast<uint32>(node_->child_count());
131 BrowserAccessibility* BrowserAccessibility::InternalGetChild(
132 uint32 child_index) const {
133 if (!node_ || !manager_)
134 return NULL;
135 return manager_->GetFromAXNode(node_->ChildAtIndex(child_index));
138 BrowserAccessibility* BrowserAccessibility::GetParent() const {
139 if (!node_ || !manager_)
140 return NULL;
141 ui::AXNode* parent = node_->parent();
142 if (parent)
143 return manager_->GetFromAXNode(parent);
145 if (!manager_->delegate())
146 return NULL;
148 BrowserAccessibility* host_node =
149 manager_->delegate()->AccessibilityGetParentFrame();
150 if (!host_node)
151 return NULL;
153 return host_node->GetParent();
156 int32 BrowserAccessibility::GetIndexInParent() const {
157 return node_ ? node_->index_in_parent() : -1;
160 int32 BrowserAccessibility::GetId() const {
161 return node_ ? node_->id() : -1;
164 const ui::AXNodeData& BrowserAccessibility::GetData() const {
165 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ());
166 if (node_)
167 return node_->data();
168 else
169 return empty_data;
172 gfx::Rect BrowserAccessibility::GetLocation() const {
173 return GetData().location;
176 int32 BrowserAccessibility::GetRole() const {
177 return GetData().role;
180 int32 BrowserAccessibility::GetState() const {
181 return GetData().state;
184 const BrowserAccessibility::HtmlAttributes&
185 BrowserAccessibility::GetHtmlAttributes() const {
186 return GetData().html_attributes;
189 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const {
190 gfx::Rect bounds = GetLocation();
191 return ElementBoundsToLocalBounds(bounds);
194 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const {
195 gfx::Rect bounds = GetLocalBoundsRect();
197 // Adjust the bounds by the top left corner of the containing view's bounds
198 // in screen coordinates.
199 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
201 return bounds;
204 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len)
205 const {
206 if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
207 // Apply recursively to all static text descendants. For example, if
208 // you call it on a div with two text node children, it just calls
209 // GetLocalBoundsForRange on each of the two children (adjusting
210 // |start| for each one) and unions the resulting rects.
211 gfx::Rect bounds;
212 for (size_t i = 0; i < InternalChildCount(); ++i) {
213 BrowserAccessibility* child = InternalGetChild(i);
214 int child_len = child->GetStaticTextLenRecursive();
215 if (start < child_len && start + len > 0) {
216 gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len);
217 bounds.Union(child_rect);
219 start -= child_len;
221 return ElementBoundsToLocalBounds(bounds);
224 int end = start + len;
225 int child_start = 0;
226 int child_end = 0;
228 gfx::Rect bounds;
229 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) {
230 BrowserAccessibility* child = InternalGetChild(i);
231 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
232 std::string child_text;
233 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text);
234 int child_len = static_cast<int>(child_text.size());
235 child_start = child_end;
236 child_end += child_len;
238 if (child_end < start)
239 continue;
241 int overlap_start = std::max(start, child_start);
242 int overlap_end = std::min(end, child_end);
244 int local_start = overlap_start - child_start;
245 int local_end = overlap_end - child_start;
247 gfx::Rect child_rect = child->GetLocation();
248 int text_direction = child->GetIntAttribute(
249 ui::AX_ATTR_TEXT_DIRECTION);
250 const std::vector<int32>& character_offsets = child->GetIntListAttribute(
251 ui::AX_ATTR_CHARACTER_OFFSETS);
252 int start_pixel_offset =
253 local_start > 0 ? character_offsets[local_start - 1] : 0;
254 int end_pixel_offset =
255 local_end > 0 ? character_offsets[local_end - 1] : 0;
257 gfx::Rect child_overlap_rect;
258 switch (text_direction) {
259 case ui::AX_TEXT_DIRECTION_NONE:
260 case ui::AX_TEXT_DIRECTION_LR: {
261 int left = child_rect.x() + start_pixel_offset;
262 int right = child_rect.x() + end_pixel_offset;
263 child_overlap_rect = gfx::Rect(left, child_rect.y(),
264 right - left, child_rect.height());
265 break;
267 case ui::AX_TEXT_DIRECTION_RL: {
268 int right = child_rect.right() - start_pixel_offset;
269 int left = child_rect.right() - end_pixel_offset;
270 child_overlap_rect = gfx::Rect(left, child_rect.y(),
271 right - left, child_rect.height());
272 break;
274 case ui::AX_TEXT_DIRECTION_TB: {
275 int top = child_rect.y() + start_pixel_offset;
276 int bottom = child_rect.y() + end_pixel_offset;
277 child_overlap_rect = gfx::Rect(child_rect.x(), top,
278 child_rect.width(), bottom - top);
279 break;
281 case ui::AX_TEXT_DIRECTION_BT: {
282 int bottom = child_rect.bottom() - start_pixel_offset;
283 int top = child_rect.bottom() - end_pixel_offset;
284 child_overlap_rect = gfx::Rect(child_rect.x(), top,
285 child_rect.width(), bottom - top);
286 break;
288 default:
289 NOTREACHED();
292 if (bounds.width() == 0 && bounds.height() == 0)
293 bounds = child_overlap_rect;
294 else
295 bounds.Union(child_overlap_rect);
298 return ElementBoundsToLocalBounds(bounds);
301 gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len)
302 const {
303 gfx::Rect bounds = GetLocalBoundsForRange(start, len);
305 // Adjust the bounds by the top left corner of the containing view's bounds
306 // in screen coordinates.
307 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
309 return bounds;
312 int BrowserAccessibility::GetWordStartBoundary(
313 int start, ui::TextBoundaryDirection direction) const {
314 int word_start = 0;
315 int prev_word_start = 0;
316 if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
317 for (size_t i = 0; i < InternalChildCount(); ++i) {
318 BrowserAccessibility* child = InternalGetChild(i);
319 int child_len = child->GetStaticTextLenRecursive();
320 int child_word_start = child->GetWordStartBoundary(start, direction);
321 word_start += child_word_start;
322 if (child_word_start != child_len)
323 break;
324 start -= child_len;
326 return word_start;
329 int child_start = 0;
330 int child_end = 0;
331 for (size_t i = 0; i < InternalChildCount(); ++i) {
332 // The next child starts where the previous one ended.
333 child_start = child_end;
334 BrowserAccessibility* child = InternalGetChild(i);
335 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
336 const std::string& child_text = child->GetStringAttribute(
337 ui::AX_ATTR_VALUE);
338 int child_len = static_cast<int>(child_text.size());
339 child_end += child_len; // End is one past the last character.
341 const std::vector<int32>& word_starts = child->GetIntListAttribute(
342 ui::AX_ATTR_WORD_STARTS);
343 if (word_starts.empty()) {
344 word_start = child_end;
345 continue;
348 int local_start = start - child_start;
349 std::vector<int32>::const_iterator iter = std::upper_bound(
350 word_starts.begin(), word_starts.end(), local_start);
351 if (iter != word_starts.end()) {
352 if (direction == ui::FORWARDS_DIRECTION) {
353 word_start = child_start + *iter;
354 } else if (direction == ui::BACKWARDS_DIRECTION) {
355 if (iter == word_starts.begin()) {
356 // Return the position of the last word in the previous child.
357 word_start = prev_word_start;
358 } else {
359 word_start = child_start + *(iter - 1);
361 } else {
362 NOTREACHED();
364 break;
367 // No word start that is >= to the requested offset has been found.
368 prev_word_start = child_start + *(iter - 1);
369 if (direction == ui::FORWARDS_DIRECTION) {
370 word_start = child_end;
371 } else if (direction == ui::BACKWARDS_DIRECTION) {
372 word_start = prev_word_start;
373 } else {
374 NOTREACHED();
378 return word_start;
381 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint(
382 const gfx::Point& point) {
383 // The best result found that's a child of this object.
384 BrowserAccessibility* child_result = NULL;
385 // The best result that's an indirect descendant like grandchild, etc.
386 BrowserAccessibility* descendant_result = NULL;
388 // Walk the children recursively looking for the BrowserAccessibility that
389 // most tightly encloses the specified point. Walk backwards so that in
390 // the absence of any other information, we assume the object that occurs
391 // later in the tree is on top of one that comes before it.
392 for (int i = static_cast<int>(PlatformChildCount()) - 1; i >= 0; --i) {
393 BrowserAccessibility* child = PlatformGetChild(i);
395 // Skip table columns because cells are only contained in rows,
396 // not columns.
397 if (child->GetRole() == ui::AX_ROLE_COLUMN)
398 continue;
400 if (child->GetGlobalBoundsRect().Contains(point)) {
401 BrowserAccessibility* result = child->BrowserAccessibilityForPoint(point);
402 if (result == child && !child_result)
403 child_result = result;
404 if (result != child && !descendant_result)
405 descendant_result = result;
408 if (child_result && descendant_result)
409 break;
412 // Explanation of logic: it's possible that this point overlaps more than
413 // one child of this object. If so, as a heuristic we prefer if the point
414 // overlaps a descendant of one of the two children and not the other.
415 // As an example, suppose you have two rows of buttons - the buttons don't
416 // overlap, but the rows do. Without this heuristic, we'd greedily only
417 // consider one of the containers.
418 if (descendant_result)
419 return descendant_result;
420 if (child_result)
421 return child_result;
423 return this;
426 void BrowserAccessibility::Destroy() {
427 // Allow the object to fire a TextRemoved notification.
428 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this);
429 node_ = NULL;
430 manager_ = NULL;
432 NativeReleaseReference();
435 void BrowserAccessibility::NativeReleaseReference() {
436 delete this;
439 bool BrowserAccessibility::HasBoolAttribute(
440 ui::AXBoolAttribute attribute) const {
441 const ui::AXNodeData& data = GetData();
442 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
443 if (data.bool_attributes[i].first == attribute)
444 return true;
447 return false;
451 bool BrowserAccessibility::GetBoolAttribute(
452 ui::AXBoolAttribute attribute) const {
453 const ui::AXNodeData& data = GetData();
454 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
455 if (data.bool_attributes[i].first == attribute)
456 return data.bool_attributes[i].second;
459 return false;
462 bool BrowserAccessibility::GetBoolAttribute(
463 ui::AXBoolAttribute attribute, bool* value) const {
464 const ui::AXNodeData& data = GetData();
465 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
466 if (data.bool_attributes[i].first == attribute) {
467 *value = data.bool_attributes[i].second;
468 return true;
472 return false;
475 bool BrowserAccessibility::HasFloatAttribute(
476 ui::AXFloatAttribute attribute) const {
477 const ui::AXNodeData& data = GetData();
478 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
479 if (data.float_attributes[i].first == attribute)
480 return true;
483 return false;
486 float BrowserAccessibility::GetFloatAttribute(
487 ui::AXFloatAttribute attribute) const {
488 const ui::AXNodeData& data = GetData();
489 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
490 if (data.float_attributes[i].first == attribute)
491 return data.float_attributes[i].second;
494 return 0.0;
497 bool BrowserAccessibility::GetFloatAttribute(
498 ui::AXFloatAttribute attribute, float* value) const {
499 const ui::AXNodeData& data = GetData();
500 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
501 if (data.float_attributes[i].first == attribute) {
502 *value = data.float_attributes[i].second;
503 return true;
507 return false;
510 bool BrowserAccessibility::HasIntAttribute(
511 ui::AXIntAttribute attribute) const {
512 const ui::AXNodeData& data = GetData();
513 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
514 if (data.int_attributes[i].first == attribute)
515 return true;
518 return false;
521 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const {
522 const ui::AXNodeData& data = GetData();
523 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
524 if (data.int_attributes[i].first == attribute)
525 return data.int_attributes[i].second;
528 return 0;
531 bool BrowserAccessibility::GetIntAttribute(
532 ui::AXIntAttribute attribute, int* value) const {
533 const ui::AXNodeData& data = GetData();
534 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
535 if (data.int_attributes[i].first == attribute) {
536 *value = data.int_attributes[i].second;
537 return true;
541 return false;
544 bool BrowserAccessibility::HasStringAttribute(
545 ui::AXStringAttribute attribute) const {
546 const ui::AXNodeData& data = GetData();
547 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
548 if (data.string_attributes[i].first == attribute)
549 return true;
552 return false;
555 const std::string& BrowserAccessibility::GetStringAttribute(
556 ui::AXStringAttribute attribute) const {
557 const ui::AXNodeData& data = GetData();
558 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ());
559 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
560 if (data.string_attributes[i].first == attribute)
561 return data.string_attributes[i].second;
564 return empty_string;
567 bool BrowserAccessibility::GetStringAttribute(
568 ui::AXStringAttribute attribute, std::string* value) const {
569 const ui::AXNodeData& data = GetData();
570 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
571 if (data.string_attributes[i].first == attribute) {
572 *value = data.string_attributes[i].second;
573 return true;
577 return false;
580 base::string16 BrowserAccessibility::GetString16Attribute(
581 ui::AXStringAttribute attribute) const {
582 std::string value_utf8;
583 if (!GetStringAttribute(attribute, &value_utf8))
584 return base::string16();
585 return base::UTF8ToUTF16(value_utf8);
588 bool BrowserAccessibility::GetString16Attribute(
589 ui::AXStringAttribute attribute,
590 base::string16* value) const {
591 std::string value_utf8;
592 if (!GetStringAttribute(attribute, &value_utf8))
593 return false;
594 *value = base::UTF8ToUTF16(value_utf8);
595 return true;
598 bool BrowserAccessibility::HasIntListAttribute(
599 ui::AXIntListAttribute attribute) const {
600 const ui::AXNodeData& data = GetData();
601 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
602 if (data.intlist_attributes[i].first == attribute)
603 return true;
606 return false;
609 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute(
610 ui::AXIntListAttribute attribute) const {
611 const ui::AXNodeData& data = GetData();
612 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ());
613 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
614 if (data.intlist_attributes[i].first == attribute)
615 return data.intlist_attributes[i].second;
618 return empty_vector;
621 bool BrowserAccessibility::GetIntListAttribute(
622 ui::AXIntListAttribute attribute,
623 std::vector<int32>* value) const {
624 const ui::AXNodeData& data = GetData();
625 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
626 if (data.intlist_attributes[i].first == attribute) {
627 *value = data.intlist_attributes[i].second;
628 return true;
632 return false;
635 bool BrowserAccessibility::GetHtmlAttribute(
636 const char* html_attr, std::string* value) const {
637 for (size_t i = 0; i < GetHtmlAttributes().size(); ++i) {
638 const std::string& attr = GetHtmlAttributes()[i].first;
639 if (LowerCaseEqualsASCII(attr, html_attr)) {
640 *value = GetHtmlAttributes()[i].second;
641 return true;
645 return false;
648 bool BrowserAccessibility::GetHtmlAttribute(
649 const char* html_attr, base::string16* value) const {
650 std::string value_utf8;
651 if (!GetHtmlAttribute(html_attr, &value_utf8))
652 return false;
653 *value = base::UTF8ToUTF16(value_utf8);
654 return true;
657 bool BrowserAccessibility::GetAriaTristate(
658 const char* html_attr,
659 bool* is_defined,
660 bool* is_mixed) const {
661 *is_defined = false;
662 *is_mixed = false;
664 base::string16 value;
665 if (!GetHtmlAttribute(html_attr, &value) ||
666 value.empty() ||
667 EqualsASCII(value, "undefined")) {
668 return false; // Not set (and *is_defined is also false)
671 *is_defined = true;
673 if (EqualsASCII(value, "true"))
674 return true;
676 if (EqualsASCII(value, "mixed"))
677 *is_mixed = true;
679 return false; // Not set
682 bool BrowserAccessibility::HasState(ui::AXState state_enum) const {
683 return (GetState() >> state_enum) & 1;
686 bool BrowserAccessibility::IsCellOrTableHeaderRole() const {
687 return (GetRole() == ui::AX_ROLE_CELL ||
688 GetRole() == ui::AX_ROLE_COLUMN_HEADER ||
689 GetRole() == ui::AX_ROLE_ROW_HEADER);
692 bool BrowserAccessibility::IsEditableText() const {
693 // These roles don't have readonly set, but they're not editable text.
694 if (GetRole() == ui::AX_ROLE_SCROLL_AREA ||
695 GetRole() == ui::AX_ROLE_COLUMN ||
696 GetRole() == ui::AX_ROLE_TABLE_HEADER_CONTAINER) {
697 return false;
700 // Note: WebAXStateReadonly being false means it's either a text control,
701 // or contenteditable. We also check for editable text roles to cover
702 // another element that has role=textbox set on it.
703 return (!HasState(ui::AX_STATE_READ_ONLY) ||
704 GetRole() == ui::AX_ROLE_TEXT_FIELD);
707 bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const {
708 if (GetRole() != ui::AX_ROLE_WEB_AREA &&
709 GetRole() != ui::AX_ROLE_ROOT_WEB_AREA) {
710 return false;
713 BrowserAccessibility* parent = GetParent();
714 if (!parent)
715 return false;
717 BrowserAccessibility* grandparent = parent->GetParent();
718 if (!grandparent)
719 return false;
721 return grandparent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL;
724 int BrowserAccessibility::GetStaticTextLenRecursive() const {
725 if (GetRole() == ui::AX_ROLE_STATIC_TEXT)
726 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size());
728 int len = 0;
729 for (size_t i = 0; i < InternalChildCount(); ++i)
730 len += InternalGetChild(i)->GetStaticTextLenRecursive();
731 return len;
734 BrowserAccessibility* BrowserAccessibility::GetParentForBoundsCalculation()
735 const {
736 if (!node_ || !manager_)
737 return NULL;
738 ui::AXNode* parent = node_->parent();
739 if (parent)
740 return manager_->GetFromAXNode(parent);
742 if (!manager_->delegate())
743 return NULL;
745 return manager_->delegate()->AccessibilityGetParentFrame();
748 gfx::Rect BrowserAccessibility::ElementBoundsToLocalBounds(gfx::Rect bounds)
749 const {
750 // Walk up the parent chain. Every time we encounter a Web Area, offset
751 // based on the scroll bars and then offset based on the origin of that
752 // nested web area.
753 BrowserAccessibility* parent = GetParentForBoundsCalculation();
754 bool need_to_offset_web_area =
755 (GetRole() == ui::AX_ROLE_WEB_AREA ||
756 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA);
757 while (parent) {
758 if (need_to_offset_web_area &&
759 parent->GetLocation().width() > 0 &&
760 parent->GetLocation().height() > 0) {
761 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y());
762 need_to_offset_web_area = false;
765 // On some platforms, we don't want to take the root scroll offsets
766 // into account.
767 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA &&
768 !manager()->UseRootScrollOffsetsWhenComputingBounds()) {
769 break;
772 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA ||
773 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) {
774 int sx = 0;
775 int sy = 0;
776 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) &&
777 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) {
778 bounds.Offset(-sx, -sy);
780 need_to_offset_web_area = true;
782 parent = parent->GetParentForBoundsCalculation();
785 return bounds;
788 } // namespace content