| 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 "base/test/gtest_util.h" | 8 #include "base/test/gtest_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/views/border.h" |
| 10 #include "ui/views/test/platform_test_helper.h" | 11 #include "ui/views/test/platform_test_helper.h" |
| 11 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
| 12 | 13 |
| 13 namespace views { | 14 namespace views { |
| 14 | 15 |
| 15 void ExpectViewBoundsEquals(int x, int y, int w, int h, | 16 void ExpectViewBoundsEquals(int x, int y, int w, int h, |
| 16 const View* view) { | 17 const View* view) { |
| 17 EXPECT_EQ(x, view->x()); | 18 EXPECT_EQ(x, view->x()); |
| 18 EXPECT_EQ(y, view->y()); | 19 EXPECT_EQ(y, view->y()); |
| 19 EXPECT_EQ(w, view->width()); | 20 EXPECT_EQ(w, view->width()); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 EXPECT_EQ(gfx::Size(50, 30), pref); | 492 EXPECT_EQ(gfx::Size(50, 30), pref); |
| 492 | 493 |
| 493 host.SetBounds(0, 0, 50, 100); | 494 host.SetBounds(0, 0, 50, 100); |
| 494 layout.Layout(&host); | 495 layout.Layout(&host); |
| 495 ExpectViewBoundsEquals(0, 0, 50, 90, &v1); | 496 ExpectViewBoundsEquals(0, 0, 50, 90, &v1); |
| 496 ExpectViewBoundsEquals(0, 90, 50, 10, &v2); | 497 ExpectViewBoundsEquals(0, 90, 50, 10, &v2); |
| 497 | 498 |
| 498 RemoveAll(); | 499 RemoveAll(); |
| 499 } | 500 } |
| 500 | 501 |
| 501 TEST_F(GridLayoutTest, Insets) { | 502 TEST_F(GridLayoutTest, Border) { |
| 503 host.SetBorder(CreateEmptyBorder(1, 2, 3, 4)); |
| 502 SettableSizeView v1(gfx::Size(10, 20)); | 504 SettableSizeView v1(gfx::Size(10, 20)); |
| 503 ColumnSet* c1 = layout.AddColumnSet(0); | 505 ColumnSet* c1 = layout.AddColumnSet(0); |
| 504 layout.SetInsets(1, 2, 3, 4); | |
| 505 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 506 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 506 0, GridLayout::USE_PREF, 0, 0); | 507 0, GridLayout::USE_PREF, 0, 0); |
| 507 layout.StartRow(0, 0); | 508 layout.StartRow(0, 0); |
| 508 layout.AddView(&v1); | 509 layout.AddView(&v1); |
| 509 | 510 |
| 510 GetPreferredSize(); | 511 GetPreferredSize(); |
| 511 EXPECT_EQ(gfx::Size(16, 24), pref); | 512 EXPECT_EQ(gfx::Size(16, 24), pref); |
| 512 | 513 |
| 513 host.SetBounds(0, 0, pref.width(), pref.height()); | 514 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 514 layout.Layout(&host); | 515 layout.Layout(&host); |
| 515 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); | 516 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); |
| 516 | 517 |
| 517 RemoveAll(); | 518 RemoveAll(); |
| 518 } | 519 } |
| 519 | 520 |
| 520 TEST_F(GridLayoutTest, FixedSize) { | 521 TEST_F(GridLayoutTest, FixedSize) { |
| 521 layout.SetInsets(2, 2, 2, 2); | 522 host.SetBorder(CreateEmptyBorder(2, 2, 2, 2)); |
| 522 | 523 |
| 523 ColumnSet* set = layout.AddColumnSet(0); | 524 ColumnSet* set = layout.AddColumnSet(0); |
| 524 | 525 |
| 525 int column_count = 4; | 526 int column_count = 4; |
| 526 int title_width = 100; | 527 int title_width = 100; |
| 527 int row_count = 2; | 528 int row_count = 2; |
| 528 int pref_width = 10; | 529 int pref_width = 10; |
| 529 int pref_height = 20; | 530 int pref_height = 20; |
| 530 | 531 |
| 531 for (int i = 0; i < column_count; ++i) { | 532 for (int i = 0; i < column_count; ++i) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 796 |
| 796 // If the View has nothing to change, adding should succeed. | 797 // If the View has nothing to change, adding should succeed. |
| 797 view.set_target_size(view.GetPreferredSize()); | 798 view.set_target_size(view.GetPreferredSize()); |
| 798 grid_layout->AddView(&view); | 799 grid_layout->AddView(&view); |
| 799 EXPECT_TRUE(view.parent()); | 800 EXPECT_TRUE(view.parent()); |
| 800 | 801 |
| 801 RemoveAll(); | 802 RemoveAll(); |
| 802 } | 803 } |
| 803 | 804 |
| 804 } // namespace views | 805 } // namespace views |
| OLD | NEW |