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/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/native_theme/native_theme.h" | 9 #include "ui/native_theme/native_theme.h" |
10 #include "ui/views/border.h" | 10 #include "ui/views/border.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 180 } |
181 | 181 |
182 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { | 182 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { |
183 DCHECK(vert_sb); | 183 DCHECK(vert_sb); |
184 vert_sb->SetVisible(vert_sb_->visible()); | 184 vert_sb->SetVisible(vert_sb_->visible()); |
185 delete vert_sb_; | 185 delete vert_sb_; |
186 vert_sb->set_controller(this); | 186 vert_sb->set_controller(this); |
187 vert_sb_ = vert_sb; | 187 vert_sb_ = vert_sb; |
188 } | 188 } |
189 | 189 |
190 gfx::Size ScrollView::GetPreferredSize() { | 190 gfx::Size ScrollView::GetPreferredSize() const { |
191 if (!is_bounded()) | 191 if (!is_bounded()) |
192 return View::GetPreferredSize(); | 192 return View::GetPreferredSize(); |
193 | 193 |
194 gfx::Size size = contents()->GetPreferredSize(); | 194 gfx::Size size = contents()->GetPreferredSize(); |
195 size.SetToMax(gfx::Size(size.width(), min_height_)); | 195 size.SetToMax(gfx::Size(size.width(), min_height_)); |
196 size.SetToMin(gfx::Size(size.width(), max_height_)); | 196 size.SetToMin(gfx::Size(size.width(), max_height_)); |
197 gfx::Insets insets = GetInsets(); | 197 gfx::Insets insets = GetInsets(); |
198 size.Enlarge(insets.width(), insets.height()); | 198 size.Enlarge(insets.width(), insets.height()); |
199 return size; | 199 return size; |
200 } | 200 } |
201 | 201 |
202 int ScrollView::GetHeightForWidth(int width) { | 202 int ScrollView::GetHeightForWidth(int width) const { |
203 if (!is_bounded()) | 203 if (!is_bounded()) |
204 return View::GetHeightForWidth(width); | 204 return View::GetHeightForWidth(width); |
205 | 205 |
206 gfx::Insets insets = GetInsets(); | 206 gfx::Insets insets = GetInsets(); |
207 width = std::max(0, width - insets.width()); | 207 width = std::max(0, width - insets.width()); |
208 int height = contents()->GetHeightForWidth(width) + insets.height(); | 208 int height = contents()->GetHeightForWidth(width) + insets.height(); |
209 return std::min(std::max(height, min_height_), max_height_); | 209 return std::min(std::max(height, min_height_), max_height_); |
210 } | 210 } |
211 | 211 |
212 void ScrollView::Layout() { | 212 void ScrollView::Layout() { |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 | 621 |
622 VariableRowHeightScrollHelper::RowInfo | 622 VariableRowHeightScrollHelper::RowInfo |
623 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 623 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
624 if (y < top_margin_) | 624 if (y < top_margin_) |
625 return RowInfo(0, top_margin_); | 625 return RowInfo(0, top_margin_); |
626 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 626 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
627 row_height_); | 627 row_height_); |
628 } | 628 } |
629 | 629 |
630 } // namespace views | 630 } // namespace views |
OLD | NEW |