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

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

Issue 849143003: Fix focus and bounds calculations for guest frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 BrowserAccessibility::GetHtmlAttributes() const { 176 BrowserAccessibility::GetHtmlAttributes() const {
177 return GetData().html_attributes; 177 return GetData().html_attributes;
178 } 178 }
179 179
180 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { 180 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const {
181 gfx::Rect bounds = GetLocation(); 181 gfx::Rect bounds = GetLocation();
182 182
183 // Walk up the parent chain. Every time we encounter a Web Area, offset 183 // Walk up the parent chain. Every time we encounter a Web Area, offset
184 // based on the scroll bars and then offset based on the origin of that 184 // based on the scroll bars and then offset based on the origin of that
185 // nested web area. 185 // nested web area.
186 BrowserAccessibility* parent = GetParent(); 186 BrowserAccessibility* parent = GetParentForBoundsCalculation();
187 bool need_to_offset_web_area = 187 bool need_to_offset_web_area =
188 (GetRole() == ui::AX_ROLE_WEB_AREA || 188 (GetRole() == ui::AX_ROLE_WEB_AREA ||
189 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA); 189 GetRole() == ui::AX_ROLE_ROOT_WEB_AREA);
190 while (parent) { 190 while (parent) {
191 if (need_to_offset_web_area && 191 if (need_to_offset_web_area &&
192 parent->GetLocation().width() > 0 && 192 parent->GetLocation().width() > 0 &&
193 parent->GetLocation().height() > 0) { 193 parent->GetLocation().height() > 0) {
194 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y()); 194 bounds.Offset(parent->GetLocation().x(), parent->GetLocation().y());
195 need_to_offset_web_area = false; 195 need_to_offset_web_area = false;
196 } 196 }
197 197
198 // On some platforms, we don't want to take the root scroll offsets 198 // On some platforms, we don't want to take the root scroll offsets
199 // into account. 199 // into account.
200 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA && 200 if (parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA &&
201 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { 201 !manager()->UseRootScrollOffsetsWhenComputingBounds()) {
202 break; 202 break;
203 } 203 }
204 204
205 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA || 205 if (parent->GetRole() == ui::AX_ROLE_WEB_AREA ||
206 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) { 206 parent->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA) {
207 int sx = 0; 207 int sx = 0;
208 int sy = 0; 208 int sy = 0;
209 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && 209 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) &&
210 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { 210 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) {
211 bounds.Offset(-sx, -sy); 211 bounds.Offset(-sx, -sy);
212 } 212 }
213 need_to_offset_web_area = true; 213 need_to_offset_web_area = true;
214 } 214 }
215 parent = parent->GetParent(); 215 parent = parent->GetParentForBoundsCalculation();
216 } 216 }
217 217
218 return bounds; 218 return bounds;
219 } 219 }
220 220
221 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { 221 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const {
222 gfx::Rect bounds = GetLocalBoundsRect(); 222 gfx::Rect bounds = GetLocalBoundsRect();
223 223
224 // Adjust the bounds by the top left corner of the containing view's bounds 224 // Adjust the bounds by the top left corner of the containing view's bounds
225 // in screen coordinates. 225 // in screen coordinates.
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 int BrowserAccessibility::GetStaticTextLenRecursive() const { 709 int BrowserAccessibility::GetStaticTextLenRecursive() const {
710 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) 710 if (GetRole() == ui::AX_ROLE_STATIC_TEXT)
711 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); 711 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size());
712 712
713 int len = 0; 713 int len = 0;
714 for (size_t i = 0; i < InternalChildCount(); ++i) 714 for (size_t i = 0; i < InternalChildCount(); ++i)
715 len += InternalGetChild(i)->GetStaticTextLenRecursive(); 715 len += InternalGetChild(i)->GetStaticTextLenRecursive();
716 return len; 716 return len;
717 } 717 }
718 718
719 BrowserAccessibility* BrowserAccessibility::GetParentForBoundsCalculation()
720 const {
721 if (!node_ || !manager_)
722 return NULL;
723 ui::AXNode* parent = node_->parent();
724 if (parent)
725 return manager_->GetFromAXNode(parent);
726
727 if (!manager_->delegate())
728 return NULL;
729
730 BrowserAccessibility* host_node =
731 manager_->delegate()->AccessibilityGetParentFrame();
732 if (!host_node)
733 return NULL;
aboxhall 2015/01/15 05:08:25 Totally fine if you want to leave it this way, but
dmazzoni 2015/01/15 21:02:33 Great observation. Simplified.
734
735 return host_node;
736 }
737
719 } // namespace content 738 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698