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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
9 #include "ui/views/test/test_views.h" | 9 #include "ui/views/test/test_views.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const int kWidth = 100; | 15 const int kWidth = 100; |
16 const int kMinHeight = 50; | 16 const int kMinHeight = 50; |
17 const int kMaxHeight = 100; | 17 const int kMaxHeight = 100; |
18 | 18 |
19 // View implementation that allows setting the preferred size. | 19 // View implementation that allows setting the preferred size. |
20 class CustomView : public View { | 20 class CustomView : public View { |
21 public: | 21 public: |
22 CustomView() {} | 22 CustomView() {} |
23 | 23 |
24 void SetPreferredSize(const gfx::Size& size) { | 24 void SetPreferredSize(const gfx::Size& size) { |
25 preferred_size_ = size; | 25 preferred_size_ = size; |
26 PreferredSizeChanged(); | 26 PreferredSizeChanged(); |
27 } | 27 } |
28 | 28 |
29 virtual gfx::Size GetPreferredSize() OVERRIDE { return preferred_size_; } | 29 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 30 return preferred_size_; |
| 31 } |
30 | 32 |
31 virtual void Layout() OVERRIDE { | 33 virtual void Layout() OVERRIDE { |
32 gfx::Size pref = GetPreferredSize(); | 34 gfx::Size pref = GetPreferredSize(); |
33 int width = pref.width(); | 35 int width = pref.width(); |
34 int height = pref.height(); | 36 int height = pref.height(); |
35 if (parent()) { | 37 if (parent()) { |
36 width = std::max(parent()->width(), width); | 38 width = std::max(parent()->width(), width); |
37 height = std::max(parent()->height(), height); | 39 height = std::max(parent()->height(), height); |
38 } | 40 } |
39 SetBounds(x(), y(), width, height); | 41 SetBounds(x(), y(), width, height); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 scroll_view.Layout(); | 328 scroll_view.Layout(); |
327 | 329 |
328 int scroll_bar_width = scroll_view.GetScrollBarWidth(); | 330 int scroll_bar_width = scroll_view.GetScrollBarWidth(); |
329 int expected_width = kWidth - scroll_bar_width; | 331 int expected_width = kWidth - scroll_bar_width; |
330 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); | 332 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); |
331 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); | 333 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); |
332 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); | 334 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); |
333 } | 335 } |
334 | 336 |
335 } // namespace views | 337 } // namespace views |
OLD | NEW |