| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/views/controls/scroll_view.h" | 5 #include "ui/views/controls/scroll_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | 8 #include "ui/views/controls/scrollbar/native_scroll_bar.h" |
| 9 #include "ui/views/widget/root_view.h" | 9 #include "ui/views/widget/root_view.h" |
| 10 | 10 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // This is no op if bounds are the same | 255 // This is no op if bounds are the same |
| 256 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); | 256 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 gfx::Rect ScrollView::GetVisibleRect() const { | 260 gfx::Rect ScrollView::GetVisibleRect() const { |
| 261 if (!contents_) | 261 if (!contents_) |
| 262 return gfx::Rect(); | 262 return gfx::Rect(); |
| 263 | 263 |
| 264 const int x = | 264 const int x = |
| 265 (horiz_sb_ && horiz_sb_->IsVisible()) ? horiz_sb_->GetPosition() : 0; | 265 horiz_sb_->IsVisible() ? horiz_sb_->GetPosition() : 0; |
| 266 const int y = | 266 const int y = |
| 267 (vert_sb_ && vert_sb_->IsVisible()) ? vert_sb_->GetPosition() : 0; | 267 vert_sb_->IsVisible() ? vert_sb_->GetPosition() : 0; |
| 268 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); | 268 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void ScrollView::ScrollContentsRegionToBeVisible(const gfx::Rect& rect) { | 271 void ScrollView::ScrollContentsRegionToBeVisible(const gfx::Rect& rect) { |
| 272 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->IsVisible()) && | 272 if (!contents_ || (!horiz_sb_->IsVisible() && !vert_sb_->IsVisible())) |
| 273 (!vert_sb_ || !vert_sb_->IsVisible()))) { | |
| 274 return; | 273 return; |
| 275 } | |
| 276 | 274 |
| 277 // Figure out the maximums for this scroll view. | 275 // Figure out the maximums for this scroll view. |
| 278 const int contents_max_x = | 276 const int contents_max_x = |
| 279 std::max(viewport_->width(), contents_->width()); | 277 std::max(viewport_->width(), contents_->width()); |
| 280 const int contents_max_y = | 278 const int contents_max_y = |
| 281 std::max(viewport_->height(), contents_->height()); | 279 std::max(viewport_->height(), contents_->height()); |
| 282 | 280 |
| 283 // Make sure x and y are within the bounds of [0,contents_max_*]. | 281 // Make sure x and y are within the bounds of [0,contents_max_*]. |
| 284 int x = std::max(0, std::min(contents_max_x, rect.x())); | 282 int x = std::max(0, std::min(contents_max_x, rect.x())); |
| 285 int y = std::max(0, std::min(contents_max_y, rect.y())); | 283 int y = std::max(0, std::min(contents_max_y, rect.y())); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 490 |
| 493 VariableRowHeightScrollHelper::RowInfo | 491 VariableRowHeightScrollHelper::RowInfo |
| 494 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 492 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 495 if (y < top_margin_) | 493 if (y < top_margin_) |
| 496 return RowInfo(0, top_margin_); | 494 return RowInfo(0, top_margin_); |
| 497 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 495 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 498 row_height_); | 496 row_height_); |
| 499 } | 497 } |
| 500 | 498 |
| 501 } // namespace views | 499 } // namespace views |
| OLD | NEW |