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

Side by Side Diff: chrome/views/controls/scroll_view.cc

Issue 60059: Fix for issue 9659 (Closed)
Patch Set: Fixed up comments Created 11 years, 8 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 | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/views/controls/scroll_view.h" 5 #include "chrome/views/controls/scroll_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/common/resource_bundle.h" 8 #include "chrome/common/resource_bundle.h"
9 #include "chrome/views/controls/scrollbar/native_scroll_bar.h" 9 #include "chrome/views/controls/scrollbar/native_scroll_bar.h"
10 #include "chrome/views/widget/root_view.h" 10 #include "chrome/views/widget/root_view.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 void ScrollView::ScrollContentsRegionToBeVisible(int x, 271 void ScrollView::ScrollContentsRegionToBeVisible(int x,
272 int y, 272 int y,
273 int width, 273 int width,
274 int height) { 274 int height) {
275 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->IsVisible()) && 275 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->IsVisible()) &&
276 (!vert_sb_ || !vert_sb_->IsVisible()))) { 276 (!vert_sb_ || !vert_sb_->IsVisible()))) {
277 return; 277 return;
278 } 278 }
279 279
280 // Figure out the maximums for this scroll view.
280 const int contents_max_x = 281 const int contents_max_x =
281 std::max(viewport_->width(), contents_->width()); 282 std::max(viewport_->width(), contents_->width());
282 const int contents_max_y = 283 const int contents_max_y =
283 std::max(viewport_->height(), contents_->height()); 284 std::max(viewport_->height(), contents_->height());
285
286 // Make sure x and y are within the bounds of [0,contents_max_*].
284 x = std::max(0, std::min(contents_max_x, x)); 287 x = std::max(0, std::min(contents_max_x, x));
285 y = std::max(0, std::min(contents_max_y, y)); 288 y = std::max(0, std::min(contents_max_y, y));
289
290 // Figure out how far and down the rectangle will go taking width
291 // and height into account. This will be "clipped" by the viewport.
286 const int max_x = std::min(contents_max_x, 292 const int max_x = std::min(contents_max_x,
287 x + std::min(width, viewport_->width())); 293 x + std::min(width, viewport_->width()));
288 const int max_y = std::min(contents_max_y, 294 const int max_y = std::min(contents_max_y,
289 y + std::min(height, 295 y + std::min(height,
290 viewport_->height())); 296 viewport_->height()));
297
298 // See if the rect is already visible. Note the width is (max_x - x)
299 // and the height is (max_y - y) to take into account the clipping of
300 // either viewport or the content size.
291 const gfx::Rect vis_rect = GetVisibleRect(); 301 const gfx::Rect vis_rect = GetVisibleRect();
292 if (vis_rect.Contains(gfx::Rect(x, y, max_x, max_y))) 302 if (vis_rect.Contains(gfx::Rect(x, y, max_x - x, max_y - y)))
293 return; 303 return;
294 304
305 // Shift contents_'s X and Y so that the region is visible. If we
306 // need to shift up or left from where we currently are then we need
307 // to get it so that the content appears in the upper/left
308 // corner. This is done by setting the offset to -X or -Y. For down
309 // or right shifts we need to make sure it appears in the
310 // lower/right corner. This is calculated by taking max_x or max_y
311 // and scaling it back by the size of the viewport.
295 const int new_x = 312 const int new_x =
296 (vis_rect.x() < x) ? x : std::max(0, max_x - viewport_->width()); 313 (vis_rect.x() > x) ? x : std::max(0, max_x - viewport_->width());
297 const int new_y = 314 const int new_y =
298 (vis_rect.y() < y) ? y : std::max(0, max_x - viewport_->height()); 315 (vis_rect.y() > y) ? y : std::max(0, max_y - viewport_->height());
299 316
300 contents_->SetX(-new_x); 317 contents_->SetX(-new_x);
301 contents_->SetY(-new_y); 318 contents_->SetY(-new_y);
302 UpdateScrollBarPositions(); 319 UpdateScrollBarPositions();
303 } 320 }
304 321
305 void ScrollView::UpdateScrollBarPositions() { 322 void ScrollView::UpdateScrollBarPositions() {
306 if (!contents_) { 323 if (!contents_) {
307 return; 324 return;
308 } 325 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 508
492 VariableRowHeightScrollHelper::RowInfo 509 VariableRowHeightScrollHelper::RowInfo
493 FixedRowHeightScrollHelper::GetRowInfo(int y) { 510 FixedRowHeightScrollHelper::GetRowInfo(int y) {
494 if (y < top_margin_) 511 if (y < top_margin_)
495 return RowInfo(0, top_margin_); 512 return RowInfo(0, top_margin_);
496 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, 513 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_,
497 row_height_); 514 row_height_);
498 } 515 }
499 516
500 } // namespace views 517 } // namespace views
OLDNEW
« 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