| OLD | NEW |
| 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 "views/controls/scroll_view.h" | 5 #include "views/controls/scroll_view.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "views/controls/scrollbar/native_scroll_bar.h" | 9 #include "views/controls/scrollbar/native_scroll_bar.h" |
| 10 #include "views/widget/root_view.h" | 10 #include "views/widget/root_view.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // This is no op if bounds are the same | 254 // This is no op if bounds are the same |
| 255 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); | 255 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 gfx::Rect ScrollView::GetVisibleRect() const { | 259 gfx::Rect ScrollView::GetVisibleRect() const { |
| 260 if (!contents_) | 260 if (!contents_) |
| 261 return gfx::Rect(); | 261 return gfx::Rect(); |
| 262 | 262 |
| 263 const int x = | 263 const int x = |
| 264 (horiz_sb_ && horiz_sb_->IsVisible()) ? horiz_sb_->GetPosition() : 0; | 264 horiz_sb_->IsVisible() ? horiz_sb_->GetPosition() : 0; |
| 265 const int y = | 265 const int y = |
| 266 (vert_sb_ && vert_sb_->IsVisible()) ? vert_sb_->GetPosition() : 0; | 266 vert_sb_->IsVisible() ? vert_sb_->GetPosition() : 0; |
| 267 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); | 267 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void ScrollView::ScrollContentsRegionToBeVisible(int x, | 270 void ScrollView::ScrollContentsRegionToBeVisible(int x, |
| 271 int y, | 271 int y, |
| 272 int width, | 272 int width, |
| 273 int height) { | 273 int height) { |
| 274 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->IsVisible()) && | 274 if (!contents_ || (!horiz_sb_->IsVisible() && !vert_sb_->IsVisible())) |
| 275 (!vert_sb_ || !vert_sb_->IsVisible()))) { | |
| 276 return; | 275 return; |
| 277 } | |
| 278 | 276 |
| 279 // Figure out the maximums for this scroll view. | 277 // Figure out the maximums for this scroll view. |
| 280 const int contents_max_x = | 278 const int contents_max_x = |
| 281 std::max(viewport_->width(), contents_->width()); | 279 std::max(viewport_->width(), contents_->width()); |
| 282 const int contents_max_y = | 280 const int contents_max_y = |
| 283 std::max(viewport_->height(), contents_->height()); | 281 std::max(viewport_->height(), contents_->height()); |
| 284 | 282 |
| 285 // Make sure x and y are within the bounds of [0,contents_max_*]. | 283 // Make sure x and y are within the bounds of [0,contents_max_*]. |
| 286 x = std::max(0, std::min(contents_max_x, x)); | 284 x = std::max(0, std::min(contents_max_x, x)); |
| 287 y = std::max(0, std::min(contents_max_y, y)); | 285 y = std::max(0, std::min(contents_max_y, y)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 horiz_sb_->Update(vw, cw, -origin); | 328 horiz_sb_->Update(vw, cw, -origin); |
| 331 } | 329 } |
| 332 if (vert_sb_->IsVisible()) { | 330 if (vert_sb_->IsVisible()) { |
| 333 int vh = viewport_->height(); | 331 int vh = viewport_->height(); |
| 334 int ch = contents_->height(); | 332 int ch = contents_->height(); |
| 335 int origin = contents_->y(); | 333 int origin = contents_->y(); |
| 336 vert_sb_->Update(vh, ch, -origin); | 334 vert_sb_->Update(vh, ch, -origin); |
| 337 } | 335 } |
| 338 } | 336 } |
| 339 | 337 |
| 340 // TODO(ACW). We should really use ScrollWindowEx as needed | 338 // TODO(ACW): We should really use ScrollWindowEx as needed |
| 341 void ScrollView::ScrollToPosition(ScrollBar* source, int position) { | 339 void ScrollView::ScrollToPosition(ScrollBar* source, int position) { |
| 342 if (!contents_) | 340 if (!contents_) |
| 343 return; | 341 return; |
| 344 | 342 |
| 345 if (source == horiz_sb_ && horiz_sb_->IsVisible()) { | 343 if (source == horiz_sb_ && horiz_sb_->IsVisible()) { |
| 346 int vw = viewport_->width(); | 344 int vw = viewport_->width(); |
| 347 int cw = contents_->width(); | 345 int cw = contents_->width(); |
| 348 int origin = contents_->x(); | 346 int origin = contents_->x(); |
| 349 if (-origin != position) { | 347 if (-origin != position) { |
| 350 int max_pos = std::max(0, cw - vw); | 348 int max_pos = std::max(0, cw - vw); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 return controller_->GetRowInfo(y); | 493 return controller_->GetRowInfo(y); |
| 496 } | 494 } |
| 497 | 495 |
| 498 // FixedRowHeightScrollHelper ----------------------------------------------- | 496 // FixedRowHeightScrollHelper ----------------------------------------------- |
| 499 | 497 |
| 500 FixedRowHeightScrollHelper::FixedRowHeightScrollHelper(int top_margin, | 498 FixedRowHeightScrollHelper::FixedRowHeightScrollHelper(int top_margin, |
| 501 int row_height) | 499 int row_height) |
| 502 : VariableRowHeightScrollHelper(NULL), | 500 : VariableRowHeightScrollHelper(NULL), |
| 503 top_margin_(top_margin), | 501 top_margin_(top_margin), |
| 504 row_height_(row_height) { | 502 row_height_(row_height) { |
| 505 DCHECK(row_height > 0); | 503 DCHECK_GT(row_height, 0); |
| 506 } | 504 } |
| 507 | 505 |
| 508 VariableRowHeightScrollHelper::RowInfo | 506 VariableRowHeightScrollHelper::RowInfo |
| 509 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 507 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 510 if (y < top_margin_) | 508 if (y < top_margin_) |
| 511 return RowInfo(0, top_margin_); | 509 return RowInfo(0, top_margin_); |
| 512 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 510 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 513 row_height_); | 511 row_height_); |
| 514 } | 512 } |
| 515 | 513 |
| 516 } // namespace views | 514 } // namespace views |
| OLD | NEW |