Chromium Code Reviews| Index: content/browser/accessibility/browser_accessibility.cc |
| =================================================================== |
| --- content/browser/accessibility/browser_accessibility.cc (revision 112482) |
| +++ content/browser/accessibility/browser_accessibility.cc (working copy) |
| @@ -133,8 +133,8 @@ |
| BrowserAccessibility* root = manager_->GetRoot(); |
| int scroll_x = 0; |
| int scroll_y = 0; |
| - root->GetIntAttribute(WebAccessibility::ATTR_DOC_SCROLLX, &scroll_x); |
| - root->GetIntAttribute(WebAccessibility::ATTR_DOC_SCROLLY, &scroll_y); |
| + root->GetIntAttribute(WebAccessibility::ATTR_SCROLL_X, &scroll_x); |
| + root->GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y, &scroll_y); |
| bounds.Offset(-scroll_x, -scroll_y); |
| return bounds; |
| @@ -163,6 +163,94 @@ |
| return this; |
| } |
| +void BrowserAccessibility::ScrollToMakeVisible(const gfx::Rect& subfocus, |
| + const gfx::Rect& focus, |
| + const gfx::Rect& viewport) { |
| + int scroll_x = 0; |
| + int scroll_x_min = 0; |
| + int scroll_x_max = 0; |
| + int scroll_y = 0; |
| + int scroll_y_min = 0; |
| + int scroll_y_max = 0; |
| + if (!GetIntAttribute(WebAccessibility::ATTR_SCROLL_X, &scroll_x) || |
| + !GetIntAttribute(WebAccessibility::ATTR_SCROLL_X_MIN, &scroll_x_min) || |
| + !GetIntAttribute(WebAccessibility::ATTR_SCROLL_X_MAX, &scroll_x_max) || |
| + !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y, &scroll_y) || |
| + !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y_MIN, &scroll_y_min) || |
| + !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y_MAX, &scroll_y_max)) { |
| + return; |
| + } |
| + |
| + int viewport_left = std::max(viewport.x(), 0); |
|
David Tseng
2011/12/02 00:02:17
Why isn't this std::max(viewport.x(), location_.x(
dmazzoni
2011/12/03 00:37:10
location_ is in global coordinates. We want things
|
| + int viewport_top = std::max(viewport.y(), 0); |
|
David Tseng
2011/12/02 00:02:17
ditto.
|
| + int viewport_right = std::min(viewport.right(), location_.right()); |
| + int viewport_bottom = std::min(viewport.bottom(), location_.bottom()); |
| + |
| + int new_scroll_x = ComputeBestScrollOffset( |
|
David Tseng
2011/12/02 00:02:17
Did you try using Rect's as primitives to perform
dmazzoni
2011/12/03 00:37:10
Used Intersect, above. Good idea.
I don't think t
|
| + scroll_x, |
| + subfocus.x(), subfocus.right(), |
| + focus.x(), focus.right(), |
| + viewport_left, viewport_right); |
| + new_scroll_x = std::max(new_scroll_x, scroll_x_min); |
| + new_scroll_x = std::min(new_scroll_x, scroll_x_max); |
| + |
| + int new_scroll_y = ComputeBestScrollOffset( |
| + scroll_y, |
| + subfocus.y(), subfocus.bottom(), |
| + focus.y(), focus.bottom(), |
| + viewport_top, viewport_bottom); |
| + new_scroll_y = std::max(new_scroll_y, scroll_y_min); |
| + new_scroll_y = std::min(new_scroll_y, scroll_y_max); |
| + |
| + manager_->ChangeScrollPosition(*this, new_scroll_x, new_scroll_y); |
| +} |
| + |
| +// static |
| +int BrowserAccessibility::ComputeBestScrollOffset( |
| + int current_scroll_offset, |
| + int subfocus_min, int subfocus_max, |
| + int focus_min, int focus_max, |
| + int viewport_min, int viewport_max) { |
| + int viewport_size = viewport_max - viewport_min; |
| + |
| + // If the focus size is larger than the viewport size, shrink it in the |
| + // direction of subfocus. |
| + if (focus_max - focus_min > viewport_size) { |
| + // Subfocus must be within focus: |
| + subfocus_min = std::max(subfocus_min, focus_min); |
| + subfocus_max = std::min(subfocus_max, focus_max); |
| + |
| + // Subfocus must be no larger than the viewport size; favor top/left. |
| + if (subfocus_max - subfocus_min > viewport_size) |
| + subfocus_max = subfocus_min + viewport_size; |
| + |
| + if (subfocus_min + viewport_size > focus_max) { |
| + focus_min = focus_max - viewport_size; |
| + } else { |
| + focus_min = subfocus_min; |
| + focus_max = subfocus_min + viewport_size; |
| + } |
| + } |
| + |
| + // Exit now if the focus is already within the viewport. |
| + if (focus_min - current_scroll_offset >= viewport_min && |
| + focus_max - current_scroll_offset <= viewport_max) { |
| + return current_scroll_offset; |
| + } |
| + |
| + // Scroll left if we're too far to the right. |
| + if (focus_max - current_scroll_offset > viewport_max) |
| + return focus_max - viewport_max; |
| + |
| + // Scroll right if we're too far to the left. |
| + if (focus_min - current_scroll_offset < viewport_min) |
| + return focus_min - viewport_min; |
| + |
| + // This shouldn't happen. |
| + NOTREACHED(); |
| + return current_scroll_offset; |
| +} |
| + |
| void BrowserAccessibility::InternalAddReference() { |
| ref_count_++; |
| } |