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

Unified Diff: chrome/views/controls/scroll_view.cc

Issue 60059: Fix for issue 9659 (Closed)
Patch Set: Fixed up comments Created 11 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/views/controls/scroll_view.cc
diff --git a/chrome/views/controls/scroll_view.cc b/chrome/views/controls/scroll_view.cc
index 5e28cfe964516a5a3f4b6f92e725cd61c5d45b9a..49787ed1fddaf41dd016185e86bcf2bf36a5ca11 100644
--- a/chrome/views/controls/scroll_view.cc
+++ b/chrome/views/controls/scroll_view.cc
@@ -277,25 +277,42 @@ void ScrollView::ScrollContentsRegionToBeVisible(int x,
return;
}
+ // Figure out the maximums for this scroll view.
const int contents_max_x =
std::max(viewport_->width(), contents_->width());
const int contents_max_y =
std::max(viewport_->height(), contents_->height());
+
+ // Make sure x and y are within the bounds of [0,contents_max_*].
x = std::max(0, std::min(contents_max_x, x));
y = std::max(0, std::min(contents_max_y, y));
+
+ // Figure out how far and down the rectangle will go taking width
+ // and height into account. This will be "clipped" by the viewport.
const int max_x = std::min(contents_max_x,
x + std::min(width, viewport_->width()));
const int max_y = std::min(contents_max_y,
y + std::min(height,
viewport_->height()));
+
+ // See if the rect is already visible. Note the width is (max_x - x)
+ // and the height is (max_y - y) to take into account the clipping of
+ // either viewport or the content size.
const gfx::Rect vis_rect = GetVisibleRect();
- if (vis_rect.Contains(gfx::Rect(x, y, max_x, max_y)))
+ if (vis_rect.Contains(gfx::Rect(x, y, max_x - x, max_y - y)))
return;
+ // Shift contents_'s X and Y so that the region is visible. If we
+ // need to shift up or left from where we currently are then we need
+ // to get it so that the content appears in the upper/left
+ // corner. This is done by setting the offset to -X or -Y. For down
+ // or right shifts we need to make sure it appears in the
+ // lower/right corner. This is calculated by taking max_x or max_y
+ // and scaling it back by the size of the viewport.
const int new_x =
- (vis_rect.x() < x) ? x : std::max(0, max_x - viewport_->width());
+ (vis_rect.x() > x) ? x : std::max(0, max_x - viewport_->width());
const int new_y =
- (vis_rect.y() < y) ? y : std::max(0, max_x - viewport_->height());
+ (vis_rect.y() > y) ? y : std::max(0, max_y - viewport_->height());
contents_->SetX(-new_x);
contents_->SetY(-new_y);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698