Chromium Code Reviews| Index: content/browser/accessibility/browser_accessibility.cc |
| diff --git a/content/browser/accessibility/browser_accessibility.cc b/content/browser/accessibility/browser_accessibility.cc |
| index 1a6678d7b0051a5366c347d9f8c05485c7d28fc0..05ff807ac735bf2272099d00e0f525fb9213678c 100644 |
| --- a/content/browser/accessibility/browser_accessibility.cc |
| +++ b/content/browser/accessibility/browser_accessibility.cc |
| @@ -189,6 +189,95 @@ gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { |
| return bounds; |
| } |
| +gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len) |
| + const { |
| + DCHECK_EQ(role_, WebKit::WebAXRoleStaticText); |
| + int end = start + len; |
| + int child_start = 0; |
| + int child_end = 0; |
| + |
| + gfx::Rect bounds; |
| + for (size_t i = 0; i < children_.size(); i++) { |
|
David Tseng
2013/10/17 21:32:02
You only need to iterate up to text length "end",
dmazzoni
2013/10/21 17:25:38
Good point. I added a condition to the for loop so
David Tseng
2013/10/23 17:00:50
nit: ++i
dmazzoni
2013/11/01 18:39:37
Done.
|
| + BrowserAccessibility* child = children_[i]; |
| + DCHECK_EQ(child->role(), WebKit::WebAXRoleInlineTextBox); |
| + std::string child_text; |
| + child->GetStringAttribute(AccessibilityNodeData::ATTR_VALUE, &child_text); |
| + int child_len = static_cast<int>(child_text.size()); |
| + child_start = child_end; |
| + child_end += child_len; |
| + |
| + int overlap_start = std::max(start, child_start); |
|
aboxhall
2013/10/04 18:53:07
Could we just do
if (start > child_end || end < ch
dmazzoni
2013/10/21 17:25:38
Done.
|
| + int overlap_end = std::min(end, child_end); |
| + |
| + if (overlap_end <= overlap_start) |
| + continue; |
| + |
| + int local_start = overlap_start - child_start; |
| + int local_end = overlap_end - child_start; |
| + |
| + gfx::Rect child_rect = child->location(); |
| + int text_direction = child->GetIntAttribute( |
| + AccessibilityNodeData::ATTR_TEXT_DIRECTION); |
| + const std::vector<int32>& character_offsets = child->GetIntListAttribute( |
| + AccessibilityNodeData::ATTR_CHARACTER_OFFSETS); |
| + int start_pixel_offset = |
| + local_start > 0 ? character_offsets[local_start - 1] : 0; |
| + int end_pixel_offset = |
| + local_end > 0 ? character_offsets[local_end - 1] : 0; |
| + |
| + gfx::Rect child_overlap_rect; |
| + switch (text_direction) { |
| + default: |
|
David Tseng
2013/10/23 17:00:50
Do you expect to get anything other than the four
dmazzoni
2013/11/01 18:39:37
No. Changed to NOTREACHED.
|
| + case WebKit::WebAXTextDirectionLR: { |
| + int left = child_rect.x() + start_pixel_offset; |
| + int right = child_rect.x() + end_pixel_offset; |
| + child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| + right - left, child_rect.height()); |
| + break; |
| + } |
| + case WebKit::WebAXTextDirectionRL: { |
| + int right = child_rect.right() - start_pixel_offset; |
| + int left = child_rect.right() - end_pixel_offset; |
| + child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| + right - left, child_rect.height()); |
| + break; |
| + } |
| + case WebKit::WebAXTextDirectionTB: { |
| + int top = child_rect.y() + start_pixel_offset; |
| + int bottom = child_rect.y() + end_pixel_offset; |
| + child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| + child_rect.width(), bottom - top); |
| + break; |
| + } |
| + case WebKit::WebAXTextDirectionBT: { |
| + int bottom = child_rect.bottom() - start_pixel_offset; |
| + int top = child_rect.bottom() - end_pixel_offset; |
| + child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| + child_rect.width(), bottom - top); |
| + break; |
| + } |
| + } |
| + |
| + if (bounds.width() == 0 && bounds.height() == 0) |
|
aboxhall
2013/10/04 18:53:07
Would IsEmpty() do here? Or is it conceivable that
dmazzoni
2013/10/21 17:25:38
It will happen - a common example is a space chara
|
| + bounds = child_overlap_rect; |
| + else |
| + bounds.Union(child_overlap_rect); |
| + } |
| + |
| + return bounds; |
| +} |
| + |
| +gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len) |
| + const { |
| + gfx::Rect bounds = GetLocalBoundsForRange(start, len); |
| + |
| + // Adjust the bounds by the top left corner of the containing view's bounds |
| + // in screen coordinates. |
| + bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
| + |
| + return bounds; |
| +} |
| + |
| BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( |
| const gfx::Point& point) { |
| // Walk the children recursively looking for the BrowserAccessibility that |