| 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" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/native_theme/native_theme.h" | 12 #include "ui/native_theme/native_theme.h" |
| 13 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
| 14 #include "ui/views/border.h" | 14 #include "ui/views/border.h" |
| 15 #include "ui/views/controls/focus_ring.h" |
| 15 #include "ui/views/style/platform_style.h" | 16 #include "ui/views/style/platform_style.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 | 18 |
| 18 namespace views { | 19 namespace views { |
| 19 | 20 |
| 20 const char ScrollView::kViewClassName[] = "ScrollView"; | 21 const char ScrollView::kViewClassName[] = "ScrollView"; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const base::Feature kToolkitViewsScrollWithLayers { | 25 const base::Feature kToolkitViewsScrollWithLayers { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 265 } |
| 265 | 266 |
| 266 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { | 267 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { |
| 267 DCHECK(vert_sb); | 268 DCHECK(vert_sb); |
| 268 vert_sb->SetVisible(vert_sb_->visible()); | 269 vert_sb->SetVisible(vert_sb_->visible()); |
| 269 delete vert_sb_; | 270 delete vert_sb_; |
| 270 vert_sb->set_controller(this); | 271 vert_sb->set_controller(this); |
| 271 vert_sb_ = vert_sb; | 272 vert_sb_ = vert_sb; |
| 272 } | 273 } |
| 273 | 274 |
| 275 void ScrollView::SetHasFocusRing(bool has_focus_ring) { |
| 276 if (has_focus_ring == (focus_ring_ != nullptr)) |
| 277 return; |
| 278 if (has_focus_ring) { |
| 279 focus_ring_ = FocusRing::Install(this); |
| 280 } else { |
| 281 FocusRing::Uninstall(this); |
| 282 focus_ring_ = nullptr; |
| 283 } |
| 284 SchedulePaint(); |
| 285 } |
| 286 |
| 274 gfx::Size ScrollView::GetPreferredSize() const { | 287 gfx::Size ScrollView::GetPreferredSize() const { |
| 275 if (!is_bounded()) | 288 if (!is_bounded()) |
| 276 return View::GetPreferredSize(); | 289 return View::GetPreferredSize(); |
| 277 | 290 |
| 278 gfx::Size size = contents()->GetPreferredSize(); | 291 gfx::Size size = contents()->GetPreferredSize(); |
| 279 size.SetToMax(gfx::Size(size.width(), min_height_)); | 292 size.SetToMax(gfx::Size(size.width(), min_height_)); |
| 280 size.SetToMin(gfx::Size(size.width(), max_height_)); | 293 size.SetToMin(gfx::Size(size.width(), max_height_)); |
| 281 gfx::Insets insets = GetInsets(); | 294 gfx::Insets insets = GetInsets(); |
| 282 size.Enlarge(insets.width(), insets.height()); | 295 size.Enlarge(insets.width(), insets.height()); |
| 283 return size; | 296 return size; |
| 284 } | 297 } |
| 285 | 298 |
| 286 int ScrollView::GetHeightForWidth(int width) const { | 299 int ScrollView::GetHeightForWidth(int width) const { |
| 287 if (!is_bounded()) | 300 if (!is_bounded()) |
| 288 return View::GetHeightForWidth(width); | 301 return View::GetHeightForWidth(width); |
| 289 | 302 |
| 290 gfx::Insets insets = GetInsets(); | 303 gfx::Insets insets = GetInsets(); |
| 291 width = std::max(0, width - insets.width()); | 304 width = std::max(0, width - insets.width()); |
| 292 int height = contents()->GetHeightForWidth(width) + insets.height(); | 305 int height = contents()->GetHeightForWidth(width) + insets.height(); |
| 293 return std::min(std::max(height, min_height_), max_height_); | 306 return std::min(std::max(height, min_height_), max_height_); |
| 294 } | 307 } |
| 295 | 308 |
| 296 void ScrollView::Layout() { | 309 void ScrollView::Layout() { |
| 310 if (focus_ring_) |
| 311 focus_ring_->Layout(); |
| 312 |
| 297 gfx::Rect available_rect = GetContentsBounds(); | 313 gfx::Rect available_rect = GetContentsBounds(); |
| 298 if (is_bounded()) { | 314 if (is_bounded()) { |
| 299 int content_width = available_rect.width(); | 315 int content_width = available_rect.width(); |
| 300 int content_height = contents()->GetHeightForWidth(content_width); | 316 int content_height = contents()->GetHeightForWidth(content_width); |
| 301 if (content_height > height()) { | 317 if (content_height > height()) { |
| 302 content_width = std::max(content_width - GetScrollBarWidth(), 0); | 318 content_width = std::max(content_width - GetScrollBarWidth(), 0); |
| 303 content_height = contents()->GetHeightForWidth(content_width); | 319 content_height = contents()->GetHeightForWidth(content_width); |
| 304 } | 320 } |
| 305 if (contents()->bounds().size() != gfx::Size(content_width, content_height)) | 321 if (contents()->bounds().size() != gfx::Size(content_width, content_height)) |
| 306 contents()->SetBounds(0, 0, content_width, content_height); | 322 contents()->SetBounds(0, 0, content_width, content_height); |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 782 |
| 767 VariableRowHeightScrollHelper::RowInfo | 783 VariableRowHeightScrollHelper::RowInfo |
| 768 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 784 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 769 if (y < top_margin_) | 785 if (y < top_margin_) |
| 770 return RowInfo(0, top_margin_); | 786 return RowInfo(0, top_margin_); |
| 771 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 787 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 772 row_height_); | 788 row_height_); |
| 773 } | 789 } |
| 774 | 790 |
| 775 } // namespace views | 791 } // namespace views |
| OLD | NEW |