OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/ng/ng_absolute_utils.h" | 5 #include "core/layout/ng/ng_absolute_utils.h" |
6 | 6 |
7 #include "core/layout/ng/ng_constraint_space_builder.h" | 7 #include "core/layout/ng/ng_constraint_space_builder.h" |
8 #include "core/layout/ng/ng_length_utils.h" | 8 #include "core/layout/ng/ng_length_utils.h" |
9 #include "core/style/ComputedStyle.h" | 9 #include "core/style/ComputedStyle.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 namespace { | 13 namespace { |
14 | 14 |
15 #define NGAuto LayoutUnit(-1) | 15 #define NGAuto LayoutUnit(-1) |
16 | 16 |
17 class NGAbsoluteUtilsTest : public ::testing::Test { | 17 class NGAbsoluteUtilsTest : public ::testing::Test { |
18 protected: | 18 protected: |
19 void SetUp() override { | 19 void SetUp() override { |
20 style_ = ComputedStyle::create(); | 20 style_ = ComputedStyle::create(); |
21 // If not set, border widths will always be 0. | 21 // If not set, border widths will always be 0. |
22 style_->setBorderLeftStyle(EBorderStyle::BorderStyleSolid); | 22 style_->setBorderLeftStyle(EBorderStyle::BorderStyleSolid); |
23 style_->setBorderRightStyle(EBorderStyle::BorderStyleSolid); | 23 style_->setBorderRightStyle(EBorderStyle::BorderStyleSolid); |
24 style_->setBorderTopStyle(EBorderStyle::BorderStyleSolid); | 24 style_->setBorderTopStyle(EBorderStyle::BorderStyleSolid); |
25 style_->setBorderBottomStyle(EBorderStyle::BorderStyleSolid); | 25 style_->setBorderBottomStyle(EBorderStyle::BorderStyleSolid); |
26 style_->setBoxSizing(EBoxSizing::BoxSizingBorderBox); | 26 style_->setBoxSizing(EBoxSizing::kBorderBox); |
27 container_size_ = NGLogicalSize(LayoutUnit(200), LayoutUnit(300)); | 27 container_size_ = NGLogicalSize(LayoutUnit(200), LayoutUnit(300)); |
28 NGConstraintSpaceBuilder builder(kHorizontalTopBottom); | 28 NGConstraintSpaceBuilder builder(kHorizontalTopBottom); |
29 builder.SetAvailableSize(container_size_); | 29 builder.SetAvailableSize(container_size_); |
30 ltr_space_ = builder.SetWritingMode(kHorizontalTopBottom) | 30 ltr_space_ = builder.SetWritingMode(kHorizontalTopBottom) |
31 .SetTextDirection(TextDirection::kLtr) | 31 .SetTextDirection(TextDirection::kLtr) |
32 .ToConstraintSpace(); | 32 .ToConstraintSpace(); |
33 rtl_space_ = builder.SetWritingMode(kHorizontalTopBottom) | 33 rtl_space_ = builder.SetWritingMode(kHorizontalTopBottom) |
34 .SetTextDirection(TextDirection::kRtl) | 34 .SetTextDirection(TextDirection::kRtl) |
35 .ToConstraintSpace(); | 35 .ToConstraintSpace(); |
36 vertical_lr_space_ = builder.SetWritingMode(kVerticalLeftRight) | 36 vertical_lr_space_ = builder.SetWritingMode(kVerticalLeftRight) |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 EXPECT_EQ(minmax_60.min_content, p.size.width); | 240 EXPECT_EQ(minmax_60.min_content, p.size.width); |
241 | 241 |
242 // Rule 4: left is auto. | 242 // Rule 4: left is auto. |
243 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, right); | 243 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, right); |
244 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 244 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
245 estimated_inline.reset(); | 245 estimated_inline.reset(); |
246 p = ComputePartialAbsoluteWithChildInlineSize( | 246 p = ComputePartialAbsoluteWithChildInlineSize( |
247 *ltr_space_, *style_, static_position, estimated_inline); | 247 *ltr_space_, *style_, static_position, estimated_inline); |
248 EXPECT_EQ(left + margin_left, p.inset.left); | 248 EXPECT_EQ(left + margin_left, p.inset.left); |
249 | 249 |
250 // Rule 4: left is auto, EBoxSizing::BoxSizingContentBox | 250 // Rule 4: left is auto, EBoxSizing::kContentBox |
251 style_->setBoxSizing(EBoxSizing::BoxSizingContentBox); | 251 style_->setBoxSizing(EBoxSizing::kContentBox); |
252 SetHorizontalStyle(NGAuto, margin_left, width - border_left - border_right - | 252 SetHorizontalStyle(NGAuto, margin_left, width - border_left - border_right - |
253 padding_left - padding_right, | 253 padding_left - padding_right, |
254 margin_right, right); | 254 margin_right, right); |
255 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 255 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
256 estimated_inline.reset(); | 256 estimated_inline.reset(); |
257 p = ComputePartialAbsoluteWithChildInlineSize( | 257 p = ComputePartialAbsoluteWithChildInlineSize( |
258 *ltr_space_, *style_, static_position, estimated_inline); | 258 *ltr_space_, *style_, static_position, estimated_inline); |
259 EXPECT_EQ(left + margin_left, p.inset.left); | 259 EXPECT_EQ(left + margin_left, p.inset.left); |
260 style_->setBoxSizing(EBoxSizing::BoxSizingBorderBox); | 260 style_->setBoxSizing(EBoxSizing::kBorderBox); |
261 | 261 |
262 // Rule 5: right is auto. | 262 // Rule 5: right is auto. |
263 SetHorizontalStyle(left, margin_left, width, margin_right, NGAuto); | 263 SetHorizontalStyle(left, margin_left, width, margin_right, NGAuto); |
264 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 264 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
265 estimated_inline.reset(); | 265 estimated_inline.reset(); |
266 p = ComputePartialAbsoluteWithChildInlineSize( | 266 p = ComputePartialAbsoluteWithChildInlineSize( |
267 *ltr_space_, *style_, static_position, estimated_inline); | 267 *ltr_space_, *style_, static_position, estimated_inline); |
268 EXPECT_EQ(right + margin_right, p.inset.right); | 268 EXPECT_EQ(right + margin_right, p.inset.right); |
269 | 269 |
270 // Rule 6: width is auto. | 270 // Rule 6: width is auto. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); | 418 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); |
419 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); | 419 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); |
420 auto_height.reset(); | 420 auto_height.reset(); |
421 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, | 421 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
422 auto_height, &p); | 422 auto_height, &p); |
423 EXPECT_EQ(height, p.size.height); | 423 EXPECT_EQ(height, p.size.height); |
424 } | 424 } |
425 | 425 |
426 } // namespace | 426 } // namespace |
427 } // namespace blink | 427 } // namespace blink |
OLD | NEW |