Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: ui/views/layout/box_layout_unittest.cc

Issue 2836313002: BoxLayout now suports per-view margins. (Closed)
Patch Set: Merged with master. Removed cached orientation_ from ViewWrapper. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/layout/box_layout.cc ('k') | ui/views/view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/layout/box_layout_unittest.cc
diff --git a/ui/views/layout/box_layout_unittest.cc b/ui/views/layout/box_layout_unittest.cc
index b14a80c23353fae54bde2ebe66018cd5fbd4a5a8..5afa088ceea610d1a178dffeef7bd7f0d51cae15 100644
--- a/ui/views/layout/box_layout_unittest.cc
+++ b/ui/views/layout/box_layout_unittest.cc
@@ -10,6 +10,7 @@
#include "ui/gfx/geometry/insets.h"
#include "ui/views/test/test_views.h"
#include "ui/views/view.h"
+#include "ui/views/view_properties.h"
namespace views {
@@ -638,4 +639,241 @@ TEST_F(BoxLayoutTest, MinimumCrossAxisHorizontal) {
EXPECT_EQ(gfx::Size(20, 30), layout->GetPreferredSize(host_.get()));
}
+TEST_F(BoxLayoutTest, MarginsUncollapsedHorizontal) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(58, 22), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 12), v1->bounds());
+ EXPECT_EQ(gfx::Rect(34, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsCollapsedHorizontal) {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kHorizontal, gfx::Insets(0, 0), 0, true);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(54, 22), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 12), v1->bounds());
+ EXPECT_EQ(gfx::Rect(30, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsUncollapsedVertical) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kVertical);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 42), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(4, 26, 22, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsCollapsedVertical) {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kVertical, gfx::Insets(0, 0), 0, true);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 37), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(4, 21, 22, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, UnbalancedMarginsUncollapsedHorizontal) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 4, 4));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 3, 6));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(59, 20), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(33, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, UnbalancedMarginsCollapsedHorizontal) {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kHorizontal, gfx::Insets(0, 0), 0, true);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 4, 4));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 3, 6));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(55, 20), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(29, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, UnbalancedMarginsUncollapsedVertical) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kVertical);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(4, 5, 5, 3));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 3, 5));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 38), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 4, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(5, 25, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, UnbalancedMarginsCollapsedVertical) {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kVertical, gfx::Insets(0, 0), 0, true);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(4, 5, 5, 3));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 3, 5));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 33), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 4, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(5, 20, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, OverlappingCrossMarginsAlignEnd) {
+ {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_END);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(3, 0, 0, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 2, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(9, layout->GetPreferredSize(host_.get()).height());
+ }
+ host_->RemoveAllChildViews(true);
+ {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kHorizontal, gfx::Insets(0, 0), 0, true);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_END);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(3, 0, 0, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 2, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(9, layout->GetPreferredSize(host_.get()).height());
+ }
+}
+
+TEST_F(BoxLayoutTest, OverlappingCrossMarginsAlignStretch) {
+ {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(3, 0, 0, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 2, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(10, layout->GetPreferredSize(host_.get()).height());
+ }
+ host_->RemoveAllChildViews(true);
+ {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kHorizontal, gfx::Insets(0, 0), 0, true);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(3, 0, 0, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 2, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(10, layout->GetPreferredSize(host_.get()).height());
+ }
+}
+
+TEST_F(BoxLayoutTest, OverlappingCrossMarginsAlignStart) {
+ {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_START);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 3, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(2, 0, 0, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(9, layout->GetPreferredSize(host_.get()).height());
+ }
+ host_->RemoveAllChildViews(true);
+ {
+ BoxLayout* layout =
+ new BoxLayout(BoxLayout::kHorizontal, gfx::Insets(0, 0), 0, true);
+ host_->SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_START);
+ View* v1 = new StaticSizedView(gfx::Size(20, 4));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(0, 0, 3, 0));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 5));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(2, 0, 0, 0));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(9, layout->GetPreferredSize(host_.get()).height());
+ }
+}
+
} // namespace views
« no previous file with comments | « ui/views/layout/box_layout.cc ('k') | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698