Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "views/layout/grid_layout.h" | 6 #include "views/layout/grid_layout.h" |
| 7 #include "views/view.h" | 7 #include "views/view.h" |
| 8 | 8 |
| 9 using views::ColumnSet; | 9 using views::ColumnSet; |
| 10 using views::GridLayout; | 10 using views::GridLayout; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 public: | 55 public: |
| 56 virtual void SetUp() { | 56 virtual void SetUp() { |
| 57 layout = new GridLayout(&host); | 57 layout = new GridLayout(&host); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void TearDown() { | 60 virtual void TearDown() { |
| 61 delete layout; | 61 delete layout; |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void RemoveAll() { | 64 virtual void RemoveAll() { |
| 65 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { | 65 for (size_t i = host.child_count() - 1; i >= 0; i--) |
|
sky
2011/02/08 19:11:54
THis never stops.
PS I don't like size_t
| |
| 66 host.RemoveChildView(host.GetChildViewAt(i)); | 66 host.RemoveChildView(host.GetChildViewAt(i)); |
| 67 } | |
| 68 } | 67 } |
| 69 | 68 |
| 70 void GetPreferredSize() { | 69 void GetPreferredSize() { |
| 71 pref = layout->GetPreferredSize(&host); | 70 pref = layout->GetPreferredSize(&host); |
| 72 } | 71 } |
| 73 | 72 |
| 74 gfx::Size pref; | 73 gfx::Size pref; |
| 75 gfx::Rect bounds; | 74 gfx::Rect bounds; |
| 76 View host; | 75 View host; |
| 77 GridLayout* layout; | 76 GridLayout* layout; |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 class GridLayoutAlignmentTest : public testing::Test { | 79 class GridLayoutAlignmentTest : public testing::Test { |
| 81 public: | 80 public: |
| 82 GridLayoutAlignmentTest() : | 81 GridLayoutAlignmentTest() : |
| 83 host(), | 82 host(), |
| 84 v1(gfx::Size(10, 20)), | 83 v1(gfx::Size(10, 20)), |
| 85 layout(new GridLayout(&host)) {} | 84 layout(new GridLayout(&host)) {} |
| 86 | 85 |
| 87 virtual void SetUp() { | 86 virtual void SetUp() { |
| 88 } | 87 } |
| 89 | 88 |
| 90 virtual void TearDown() { | 89 virtual void TearDown() { |
| 91 delete layout; | 90 delete layout; |
| 92 } | 91 } |
| 93 | 92 |
| 94 virtual void RemoveAll() { | 93 virtual void RemoveAll() { |
| 95 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { | 94 for (size_t i = host.child_count() - 1; i >= 0; i--) |
|
sky
2011/02/08 19:11:54
This never stops.
PS I don't like size_t
| |
| 96 host.RemoveChildView(host.GetChildViewAt(i)); | 95 host.RemoveChildView(host.GetChildViewAt(i)); |
| 97 } | |
| 98 } | 96 } |
| 99 | 97 |
| 100 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { | 98 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { |
| 101 ColumnSet* c1 = layout->AddColumnSet(0); | 99 ColumnSet* c1 = layout->AddColumnSet(0); |
| 102 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); | 100 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); |
| 103 layout->StartRow(1, 0); | 101 layout->StartRow(1, 0); |
| 104 layout->AddView(&v1); | 102 layout->AddView(&v1); |
| 105 gfx::Size pref = layout->GetPreferredSize(&host); | 103 gfx::Size pref = layout->GetPreferredSize(&host); |
| 106 EXPECT_EQ(gfx::Size(10, 20), pref); | 104 EXPECT_EQ(gfx::Size(10, 20), pref); |
| 107 host.SetBounds(0, 0, 100, 100); | 105 host.SetBounds(0, 0, 100, 100); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 // ordering doesn't influence sizing behaviour. | 597 // ordering doesn't influence sizing behaviour. |
| 600 layout->StartRow(0, 2); | 598 layout->StartRow(0, 2); |
| 601 View* view3 = new FlexibleView(40); | 599 View* view3 = new FlexibleView(40); |
| 602 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); | 600 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); |
| 603 | 601 |
| 604 // We expect a height of 50: 30 from the variable width view in the first row | 602 // We expect a height of 50: 30 from the variable width view in the first row |
| 605 // plus 20 from the statically sized view in the second row. The flexible | 603 // plus 20 from the statically sized view in the second row. The flexible |
| 606 // view in the third row should contribute no height. | 604 // view in the third row should contribute no height. |
| 607 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); | 605 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); |
| 608 } | 606 } |
| OLD | NEW |