| 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/layout/grid_layout.h" | 5 #include "ui/views/layout/grid_layout.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
| 10 | 10 |
| 11 namespace views { | 11 namespace views { |
| 12 | 12 |
| 13 void ExpectViewBoundsEquals(int x, int y, int w, int h, | 13 void ExpectViewBoundsEquals(int x, int y, int w, int h, |
| 14 const View* view) { | 14 const View* view) { |
| 15 EXPECT_EQ(x, view->x()); | 15 EXPECT_EQ(x, view->x()); |
| 16 EXPECT_EQ(y, view->y()); | 16 EXPECT_EQ(y, view->y()); |
| 17 EXPECT_EQ(w, view->width()); | 17 EXPECT_EQ(w, view->width()); |
| 18 EXPECT_EQ(h, view->height()); | 18 EXPECT_EQ(h, view->height()); |
| 19 } | 19 } |
| 20 | 20 |
| 21 class SettableSizeView : public View { | 21 class SettableSizeView : public View { |
| 22 public: | 22 public: |
| 23 explicit SettableSizeView(const gfx::Size& pref) { | 23 explicit SettableSizeView(const gfx::Size& pref) { |
| 24 pref_ = pref; | 24 pref_ = pref; |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual gfx::Size GetPreferredSize() OVERRIDE { | 27 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 28 return pref_; | 28 return pref_; |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 gfx::Size pref_; | 32 gfx::Size pref_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // A view with fixed circumference that trades height for width. | 35 // A view with fixed circumference that trades height for width. |
| 36 class FlexibleView : public View { | 36 class FlexibleView : public View { |
| 37 public: | 37 public: |
| 38 explicit FlexibleView(int circumference) { | 38 explicit FlexibleView(int circumference) { |
| 39 circumference_ = circumference; | 39 circumference_ = circumference; |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual gfx::Size GetPreferredSize() OVERRIDE { | 42 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 43 return gfx::Size(0, circumference_ / 2); | 43 return gfx::Size(0, circumference_ / 2); |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual int GetHeightForWidth(int width) OVERRIDE { | 46 virtual int GetHeightForWidth(int width) const OVERRIDE { |
| 47 return std::max(0, circumference_ / 2 - width); | 47 return std::max(0, circumference_ / 2 - width); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 int circumference_; | 51 int circumference_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class GridLayoutTest : public testing::Test { | 54 class GridLayoutTest : public testing::Test { |
| 55 public: | 55 public: |
| 56 GridLayoutTest() : layout(&host) {} | 56 GridLayoutTest() : layout(&host) {} |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 EXPECT_EQ(gfx::Size(10, 20), pref); | 660 EXPECT_EQ(gfx::Size(10, 20), pref); |
| 661 | 661 |
| 662 layout.set_minimum_size(gfx::Size(40, 40)); | 662 layout.set_minimum_size(gfx::Size(40, 40)); |
| 663 GetPreferredSize(); | 663 GetPreferredSize(); |
| 664 EXPECT_EQ(gfx::Size(40, 40), pref); | 664 EXPECT_EQ(gfx::Size(40, 40), pref); |
| 665 | 665 |
| 666 RemoveAll(); | 666 RemoveAll(); |
| 667 } | 667 } |
| 668 | 668 |
| 669 } // namespace views | 669 } // namespace views |
| OLD | NEW |