| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 int local_end = overlap_end - child_start; | 449 int local_end = overlap_end - child_start; |
| 450 // |local_end| and |local_start| may equal |child_length| when the caret is | 450 // |local_end| and |local_start| may equal |child_length| when the caret is |
| 451 // at the end of a text field. | 451 // at the end of a text field. |
| 452 DCHECK_GE(local_start, 0); | 452 DCHECK_GE(local_start, 0); |
| 453 DCHECK_LE(local_start, child_length); | 453 DCHECK_LE(local_start, child_length); |
| 454 DCHECK_GE(local_end, 0); | 454 DCHECK_GE(local_end, 0); |
| 455 DCHECK_LE(local_end, child_length); | 455 DCHECK_LE(local_end, child_length); |
| 456 | 456 |
| 457 const std::vector<int32_t>& character_offsets = | 457 const std::vector<int32_t>& character_offsets = |
| 458 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); | 458 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); |
| 459 if (static_cast<int>(character_offsets.size()) != child_length) | 459 int character_offsets_length = static_cast<int>(character_offsets.size()); |
| 460 continue; | 460 if (character_offsets_length < child_length) { |
| 461 // Blink might not return pixel offsets for all characters. |
| 462 // Clamp the character range to be within the number of provided pixels. |
| 463 local_start = std::min(local_start, character_offsets_length); |
| 464 local_end = std::min(local_end, character_offsets_length); |
| 465 } |
| 461 int start_pixel_offset = | 466 int start_pixel_offset = |
| 462 local_start > 0 ? character_offsets[local_start - 1] : 0; | 467 local_start > 0 ? character_offsets[local_start - 1] : 0; |
| 463 int end_pixel_offset = | 468 int end_pixel_offset = |
| 464 local_end > 0 ? character_offsets[local_end - 1] : 0; | 469 local_end > 0 ? character_offsets[local_end - 1] : 0; |
| 465 | 470 |
| 466 gfx::Rect child_rect = child->GetPageBoundsRect(); | 471 gfx::Rect child_rect = child->GetPageBoundsRect(); |
| 467 auto text_direction = static_cast<ui::AXTextDirection>( | 472 auto text_direction = static_cast<ui::AXTextDirection>( |
| 468 child->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION)); | 473 child->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION)); |
| 469 gfx::Rect child_overlap_rect; | 474 gfx::Rect child_overlap_rect; |
| 470 switch (text_direction) { | 475 switch (text_direction) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 490 child_rect.width(), bottom - top); | 495 child_rect.width(), bottom - top); |
| 491 break; | 496 break; |
| 492 } | 497 } |
| 493 case ui::AX_TEXT_DIRECTION_BTT: { | 498 case ui::AX_TEXT_DIRECTION_BTT: { |
| 494 int bottom = child_rect.bottom() - start_pixel_offset; | 499 int bottom = child_rect.bottom() - start_pixel_offset; |
| 495 int top = child_rect.bottom() - end_pixel_offset; | 500 int top = child_rect.bottom() - end_pixel_offset; |
| 496 child_overlap_rect = gfx::Rect(child_rect.x(), top, | 501 child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| 497 child_rect.width(), bottom - top); | 502 child_rect.width(), bottom - top); |
| 498 break; | 503 break; |
| 499 } | 504 } |
| 500 default: | |
| 501 NOTREACHED(); | |
| 502 } | 505 } |
| 503 | 506 |
| 504 if (bounds.width() == 0 && bounds.height() == 0) | 507 if (bounds.width() == 0 && bounds.height() == 0) |
| 505 bounds = child_overlap_rect; | 508 bounds = child_overlap_rect; |
| 506 else | 509 else |
| 507 bounds.Union(child_overlap_rect); | 510 bounds.Union(child_overlap_rect); |
| 508 } | 511 } |
| 509 | 512 |
| 510 return bounds; | 513 return bounds; |
| 511 } | 514 } |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 } | 1227 } |
| 1225 } | 1228 } |
| 1226 | 1229 |
| 1227 node = container; | 1230 node = container; |
| 1228 } | 1231 } |
| 1229 | 1232 |
| 1230 return gfx::ToEnclosingRect(bounds); | 1233 return gfx::ToEnclosingRect(bounds); |
| 1231 } | 1234 } |
| 1232 | 1235 |
| 1233 } // namespace content | 1236 } // namespace content |
| OLD | NEW |