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

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

Issue 2372823002: Fix a case where the accessible bounding box of an inline text box was wrong. (Closed)
Patch Set: Fix bug in bounds calc uncovered by windows test Created 4 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/accessibility/bounds-calc.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 0, static_cast<int>(child->GetText().size())); 407 0, static_cast<int>(child->GetText().size()));
408 } 408 }
409 bounds.Union(child_rect); 409 bounds.Union(child_rect);
410 len -= (child_length_in_parent - start); 410 len -= (child_length_in_parent - start);
411 } 411 }
412 if (start > child_length_in_parent) 412 if (start > child_length_in_parent)
413 start -= child_length_in_parent; 413 start -= child_length_in_parent;
414 else 414 else
415 start = 0; 415 start = 0;
416 } 416 }
417 return RelativeToAbsoluteBounds(gfx::RectF(bounds), false); 417 return bounds;
418 } 418 }
419 419
420 int end = start + len; 420 int end = start + len;
421 int child_start = 0; 421 int child_start = 0;
422 int child_end = 0; 422 int child_end = 0;
423 gfx::Rect bounds; 423 gfx::Rect bounds;
424 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) { 424 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) {
425 BrowserAccessibility* child = InternalGetChild(i); 425 BrowserAccessibility* child = InternalGetChild(i);
426 if (child->GetRole() != ui::AX_ROLE_INLINE_TEXT_BOX) { 426 if (child->GetRole() != ui::AX_ROLE_INLINE_TEXT_BOX) {
427 DLOG(WARNING) << "BrowserAccessibility objects with role STATIC_TEXT " << 427 DLOG(WARNING) << "BrowserAccessibility objects with role STATIC_TEXT " <<
(...skipping 22 matching lines...) Expand all
450 450
451 const std::vector<int32_t>& character_offsets = 451 const std::vector<int32_t>& character_offsets =
452 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); 452 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS);
453 if (static_cast<int>(character_offsets.size()) != child_length) 453 if (static_cast<int>(character_offsets.size()) != child_length)
454 continue; 454 continue;
455 int start_pixel_offset = 455 int start_pixel_offset =
456 local_start > 0 ? character_offsets[local_start - 1] : 0; 456 local_start > 0 ? character_offsets[local_start - 1] : 0;
457 int end_pixel_offset = 457 int end_pixel_offset =
458 local_end > 0 ? character_offsets[local_end - 1] : 0; 458 local_end > 0 ? character_offsets[local_end - 1] : 0;
459 459
460 gfx::Rect child_rect = gfx::ToEnclosingRect(child->GetLocation()); 460 gfx::Rect child_rect = child->GetPageBoundsRect();
461 auto text_direction = static_cast<ui::AXTextDirection>( 461 auto text_direction = static_cast<ui::AXTextDirection>(
462 child->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION)); 462 child->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION));
463 gfx::Rect child_overlap_rect; 463 gfx::Rect child_overlap_rect;
464 switch (text_direction) { 464 switch (text_direction) {
465 case ui::AX_TEXT_DIRECTION_NONE: 465 case ui::AX_TEXT_DIRECTION_NONE:
466 case ui::AX_TEXT_DIRECTION_LTR: { 466 case ui::AX_TEXT_DIRECTION_LTR: {
467 int left = child_rect.x() + start_pixel_offset; 467 int left = child_rect.x() + start_pixel_offset;
468 int right = child_rect.x() + end_pixel_offset; 468 int right = child_rect.x() + end_pixel_offset;
469 child_overlap_rect = gfx::Rect(left, child_rect.y(), 469 child_overlap_rect = gfx::Rect(left, child_rect.y(),
470 right - left, child_rect.height()); 470 right - left, child_rect.height());
(...skipping 23 matching lines...) Expand all
494 default: 494 default:
495 NOTREACHED(); 495 NOTREACHED();
496 } 496 }
497 497
498 if (bounds.width() == 0 && bounds.height() == 0) 498 if (bounds.width() == 0 && bounds.height() == 0)
499 bounds = child_overlap_rect; 499 bounds = child_overlap_rect;
500 else 500 else
501 bounds.Union(child_overlap_rect); 501 bounds.Union(child_overlap_rect);
502 } 502 }
503 503
504 return RelativeToAbsoluteBounds(gfx::RectF(bounds), false); 504 return bounds;
505 } 505 }
506 506
507 gfx::Rect BrowserAccessibility::GetScreenBoundsForRange(int start, int len) 507 gfx::Rect BrowserAccessibility::GetScreenBoundsForRange(int start, int len)
508 const { 508 const {
509 gfx::Rect bounds = GetPageBoundsForRange(start, len); 509 gfx::Rect bounds = GetPageBoundsForRange(start, len);
510 510
511 // Adjust the bounds by the top left corner of the containing view's bounds 511 // Adjust the bounds by the top left corner of the containing view's bounds
512 // in screen coordinates. 512 // in screen coordinates.
513 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); 513 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
514 514
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 } 1212 }
1213 } 1213 }
1214 1214
1215 node = container; 1215 node = container;
1216 } 1216 }
1217 1217
1218 return gfx::ToEnclosingRect(bounds); 1218 return gfx::ToEnclosingRect(bounds);
1219 } 1219 }
1220 1220
1221 } // namespace content 1221 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/accessibility/bounds-calc.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698