| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 FocusRing::Uninstall(this); | 276 FocusRing::Uninstall(this); |
| 277 focus_ring_ = nullptr; | 277 focus_ring_ = nullptr; |
| 278 } | 278 } |
| 279 SchedulePaint(); | 279 SchedulePaint(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 gfx::Size ScrollView::GetPreferredSize() const { | 282 gfx::Size ScrollView::GetPreferredSize() const { |
| 283 if (!is_bounded()) | 283 if (!is_bounded()) |
| 284 return View::GetPreferredSize(); | 284 return View::GetPreferredSize(); |
| 285 | 285 |
| 286 gfx::Size size = contents_->GetPreferredSize(); | 286 gfx::Size size = contents()->GetPreferredSize(); |
| 287 size.SetToMax(gfx::Size(size.width(), min_height_)); | 287 size.SetToMax(gfx::Size(size.width(), min_height_)); |
| 288 size.SetToMin(gfx::Size(size.width(), max_height_)); | 288 size.SetToMin(gfx::Size(size.width(), max_height_)); |
| 289 gfx::Insets insets = GetInsets(); | 289 gfx::Insets insets = GetInsets(); |
| 290 size.Enlarge(insets.width(), insets.height()); | 290 size.Enlarge(insets.width(), insets.height()); |
| 291 return size; | 291 return size; |
| 292 } | 292 } |
| 293 | 293 |
| 294 int ScrollView::GetHeightForWidth(int width) const { | 294 int ScrollView::GetHeightForWidth(int width) const { |
| 295 if (!is_bounded()) | 295 if (!is_bounded()) |
| 296 return View::GetHeightForWidth(width); | 296 return View::GetHeightForWidth(width); |
| 297 | 297 |
| 298 gfx::Insets insets = GetInsets(); | 298 gfx::Insets insets = GetInsets(); |
| 299 width = std::max(0, width - insets.width()); | 299 width = std::max(0, width - insets.width()); |
| 300 int height = contents_->GetHeightForWidth(width) + insets.height(); | 300 int height = contents()->GetHeightForWidth(width) + insets.height(); |
| 301 return std::min(std::max(height, min_height_), max_height_); | 301 return std::min(std::max(height, min_height_), max_height_); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void ScrollView::Layout() { | 304 void ScrollView::Layout() { |
| 305 if (focus_ring_) | 305 if (focus_ring_) |
| 306 focus_ring_->Layout(); | 306 focus_ring_->Layout(); |
| 307 | 307 |
| 308 gfx::Rect available_rect = GetContentsBounds(); | 308 gfx::Rect available_rect = GetContentsBounds(); |
| 309 if (is_bounded()) { | 309 if (is_bounded()) { |
| 310 int content_width = available_rect.width(); | 310 int content_width = available_rect.width(); |
| 311 int content_height = contents_->GetHeightForWidth(content_width); | 311 int content_height = contents()->GetHeightForWidth(content_width); |
| 312 if (content_height > height()) { | 312 if (content_height > height()) { |
| 313 content_width = std::max(content_width - GetScrollBarWidth(), 0); | 313 content_width = std::max(content_width - GetScrollBarWidth(), 0); |
| 314 content_height = contents_->GetHeightForWidth(content_width); | 314 content_height = contents()->GetHeightForWidth(content_width); |
| 315 } | 315 } |
| 316 contents_->SetSize(gfx::Size(content_width, content_height)); | 316 if (contents()->bounds().size() != gfx::Size(content_width, content_height)) |
| 317 contents()->SetBounds(0, 0, content_width, content_height); |
| 317 } | 318 } |
| 318 | 319 |
| 319 // Most views will want to auto-fit the available space. Most of them want to | 320 // Most views will want to auto-fit the available space. Most of them want to |
| 320 // use all available width (without overflowing) and only overflow in | 321 // use all available width (without overflowing) and only overflow in |
| 321 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc. | 322 // height. Examples are HistoryView, MostVisitedView, DownloadTabView, etc. |
| 322 // Other views want to fit in both ways. An example is PrintView. To make both | 323 // Other views want to fit in both ways. An example is PrintView. To make both |
| 323 // happy, assume a vertical scrollbar but no horizontal scrollbar. To override | 324 // happy, assume a vertical scrollbar but no horizontal scrollbar. To override |
| 324 // this default behavior, the inner view has to calculate the available space, | 325 // this default behavior, the inner view has to calculate the available space, |
| 325 // used ComputeScrollBarsVisibility() to use the same calculation that is done | 326 // used ComputeScrollBarsVisibility() to use the same calculation that is done |
| 326 // here and sets its bound to fit within. | 327 // here and sets its bound to fit within. |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 782 |
| 782 VariableRowHeightScrollHelper::RowInfo | 783 VariableRowHeightScrollHelper::RowInfo |
| 783 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 784 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 784 if (y < top_margin_) | 785 if (y < top_margin_) |
| 785 return RowInfo(0, top_margin_); | 786 return RowInfo(0, top_margin_); |
| 786 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 787 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 787 row_height_); | 788 row_height_); |
| 788 } | 789 } |
| 789 | 790 |
| 790 } // namespace views | 791 } // namespace views |
| OLD | NEW |