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() const override { | 29 gfx::Size GetPreferredSize() const override { return preferred_size_; } |
30 return preferred_size_; | |
31 } | |
32 | 30 |
33 virtual void Layout() override { | 31 void Layout() override { |
34 gfx::Size pref = GetPreferredSize(); | 32 gfx::Size pref = GetPreferredSize(); |
35 int width = pref.width(); | 33 int width = pref.width(); |
36 int height = pref.height(); | 34 int height = pref.height(); |
37 if (parent()) { | 35 if (parent()) { |
38 width = std::max(parent()->width(), width); | 36 width = std::max(parent()->width(), width); |
39 height = std::max(parent()->height(), height); | 37 height = std::max(parent()->height(), height); |
40 } | 38 } |
41 SetBounds(x(), y(), width, height); | 39 SetBounds(x(), y(), width, height); |
42 } | 40 } |
43 | 41 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 EXPECT_FALSE(corner_view->parent()); | 367 EXPECT_FALSE(corner_view->parent()); |
370 | 368 |
371 // Corner view should reappear when both scrollbars reappear. | 369 // Corner view should reappear when both scrollbars reappear. |
372 contents->SetBounds(0, 0, 200, 200); | 370 contents->SetBounds(0, 0, 200, 200); |
373 scroll_view.Layout(); | 371 scroll_view.Layout(); |
374 EXPECT_EQ(&scroll_view, corner_view->parent()); | 372 EXPECT_EQ(&scroll_view, corner_view->parent()); |
375 EXPECT_TRUE(corner_view->visible()); | 373 EXPECT_TRUE(corner_view->visible()); |
376 } | 374 } |
377 | 375 |
378 } // namespace views | 376 } // namespace views |
OLD | NEW |