| 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" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 LayoutUnit border_left(9); | 104 LayoutUnit border_left(9); |
| 105 LayoutUnit padding_left(11); | 105 LayoutUnit padding_left(11); |
| 106 LayoutUnit right(13); | 106 LayoutUnit right(13); |
| 107 LayoutUnit margin_right(15); | 107 LayoutUnit margin_right(15); |
| 108 LayoutUnit border_right(17); | 108 LayoutUnit border_right(17); |
| 109 LayoutUnit padding_right(19); | 109 LayoutUnit padding_right(19); |
| 110 | 110 |
| 111 LayoutUnit width = | 111 LayoutUnit width = |
| 112 container_size_.inline_size - left - margin_left - right - margin_right; | 112 container_size_.inline_size - left - margin_left - right - margin_right; |
| 113 | 113 |
| 114 Optional<LayoutUnit> estimated_inline; | 114 Optional<MinAndMaxContentSizes> estimated_inline; |
| 115 MinAndMaxContentSizes minmax_60{LayoutUnit(60), LayoutUnit(60)}; |
| 115 | 116 |
| 116 style_->setBorderLeftWidth(border_left.toInt()); | 117 style_->setBorderLeftWidth(border_left.toInt()); |
| 117 style_->setBorderRightWidth(border_right.toInt()); | 118 style_->setBorderRightWidth(border_right.toInt()); |
| 118 style_->setPaddingLeft(Length(padding_left.toInt(), LengthType::Fixed)); | 119 style_->setPaddingLeft(Length(padding_left.toInt(), LengthType::Fixed)); |
| 119 style_->setPaddingRight(Length(padding_right.toInt(), LengthType::Fixed)); | 120 style_->setPaddingRight(Length(padding_right.toInt(), LengthType::Fixed)); |
| 120 | 121 |
| 121 // These default to 3 which is not what we want. | 122 // These default to 3 which is not what we want. |
| 122 style_->setBorderBottomWidth(0); | 123 style_->setBorderBottomWidth(0); |
| 123 style_->setBorderTopWidth(0); | 124 style_->setBorderTopWidth(0); |
| 124 | 125 |
| 125 NGAbsolutePhysicalPosition p; | 126 NGAbsolutePhysicalPosition p; |
| 126 | 127 |
| 127 NGStaticPosition static_position{NGStaticPosition::kTopLeft, | 128 NGStaticPosition static_position{NGStaticPosition::kTopLeft, |
| 128 {LayoutUnit(), LayoutUnit()}}; | 129 {LayoutUnit(), LayoutUnit()}}; |
| 129 NGStaticPosition static_right_position{NGStaticPosition::kTopRight, | 130 NGStaticPosition static_right_position{NGStaticPosition::kTopRight, |
| 130 {LayoutUnit(), LayoutUnit()}}; | 131 {LayoutUnit(), LayoutUnit()}}; |
| 131 // | 132 // |
| 132 // Tests. | 133 // Tests. |
| 133 // | 134 // |
| 134 | 135 |
| 135 // All auto => width is estimated_inline, left is 0. | 136 // All auto => width is estimated_inline, left is 0. |
| 136 SetHorizontalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); | 137 SetHorizontalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); |
| 137 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); | 138 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); |
| 138 estimated_inline = LayoutUnit(60); | 139 estimated_inline = minmax_60; |
| 139 p = ComputePartialAbsoluteWithChildInlineSize( | 140 p = ComputePartialAbsoluteWithChildInlineSize( |
| 140 *ltr_space_, *style_, static_position, estimated_inline); | 141 *ltr_space_, *style_, static_position, estimated_inline); |
| 141 EXPECT_EQ(*estimated_inline, p.size.width); | 142 EXPECT_EQ(minmax_60.min_content, p.size.width); |
| 142 EXPECT_EQ(LayoutUnit(0), p.inset.left); | 143 EXPECT_EQ(LayoutUnit(0), p.inset.left); |
| 143 | 144 |
| 144 // All auto => width is estimated_inline, static_position is right | 145 // All auto => width is estimated_inline, static_position is right |
| 145 SetHorizontalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); | 146 SetHorizontalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); |
| 146 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); | 147 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); |
| 147 estimated_inline = LayoutUnit(60); | 148 estimated_inline = minmax_60; |
| 148 p = ComputePartialAbsoluteWithChildInlineSize( | 149 p = ComputePartialAbsoluteWithChildInlineSize( |
| 149 *ltr_space_, *style_, static_right_position, estimated_inline); | 150 *ltr_space_, *style_, static_right_position, estimated_inline); |
| 150 EXPECT_EQ(*estimated_inline, p.size.width); | 151 EXPECT_EQ(minmax_60.min_content, p.size.width); |
| 151 EXPECT_EQ(LayoutUnit(0), p.inset.right); | 152 EXPECT_EQ(LayoutUnit(0), p.inset.right); |
| 152 | 153 |
| 153 // All auto + RTL. | 154 // All auto + RTL. |
| 154 p = ComputePartialAbsoluteWithChildInlineSize( | 155 p = ComputePartialAbsoluteWithChildInlineSize( |
| 155 *rtl_space_, *style_, static_position, estimated_inline); | 156 *rtl_space_, *style_, static_position, estimated_inline); |
| 156 EXPECT_EQ(*estimated_inline, p.size.width); | 157 EXPECT_EQ(minmax_60.min_content, p.size.width); |
| 157 EXPECT_EQ(container_size_.inline_size - *estimated_inline, p.inset.right); | 158 EXPECT_EQ(container_size_.inline_size - minmax_60.min_content, p.inset.right); |
| 158 | 159 |
| 159 // left, right, and left are known, compute margins. | 160 // left, right, and left are known, compute margins. |
| 160 SetHorizontalStyle(left, NGAuto, width, NGAuto, right); | 161 SetHorizontalStyle(left, NGAuto, width, NGAuto, right); |
| 161 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 162 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
| 162 estimated_inline.reset(); | 163 estimated_inline.reset(); |
| 163 p = ComputePartialAbsoluteWithChildInlineSize( | 164 p = ComputePartialAbsoluteWithChildInlineSize( |
| 164 *ltr_space_, *style_, static_position, estimated_inline); | 165 *ltr_space_, *style_, static_position, estimated_inline); |
| 165 LayoutUnit marginSpace = | 166 LayoutUnit marginSpace = |
| 166 (container_size_.inline_size - left - right - p.size.width) / 2; | 167 (container_size_.inline_size - left - right - p.size.width) / 2; |
| 167 EXPECT_EQ(left + marginSpace, p.inset.left); | 168 EXPECT_EQ(left + marginSpace, p.inset.left); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 197 SetHorizontalStyle(left, NGAuto, LayoutUnit(200), NGAuto, right); | 198 SetHorizontalStyle(left, NGAuto, LayoutUnit(200), NGAuto, right); |
| 198 estimated_inline.reset(); | 199 estimated_inline.reset(); |
| 199 p = ComputePartialAbsoluteWithChildInlineSize( | 200 p = ComputePartialAbsoluteWithChildInlineSize( |
| 200 *rtl_space_, *style_, static_position, estimated_inline); | 201 *rtl_space_, *style_, static_position, estimated_inline); |
| 201 EXPECT_EQ(-right, p.inset.left); | 202 EXPECT_EQ(-right, p.inset.left); |
| 202 EXPECT_EQ(right, p.inset.right); | 203 EXPECT_EQ(right, p.inset.right); |
| 203 | 204 |
| 204 // Rule 1 left and width are auto. | 205 // Rule 1 left and width are auto. |
| 205 SetHorizontalStyle(NGAuto, margin_left, NGAuto, margin_right, right); | 206 SetHorizontalStyle(NGAuto, margin_left, NGAuto, margin_right, right); |
| 206 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); | 207 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); |
| 207 estimated_inline = LayoutUnit(60); | 208 estimated_inline = minmax_60; |
| 208 p = ComputePartialAbsoluteWithChildInlineSize( | 209 p = ComputePartialAbsoluteWithChildInlineSize( |
| 209 *ltr_space_, *style_, static_position, estimated_inline); | 210 *ltr_space_, *style_, static_position, estimated_inline); |
| 210 EXPECT_EQ(*estimated_inline, p.size.width); | 211 EXPECT_EQ(minmax_60.min_content, p.size.width); |
| 211 | 212 |
| 212 // Rule 2 left and right are auto LTR. | 213 // Rule 2 left and right are auto LTR. |
| 213 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, NGAuto); | 214 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, NGAuto); |
| 214 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 215 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
| 215 estimated_inline.reset(); | 216 estimated_inline.reset(); |
| 216 p = ComputePartialAbsoluteWithChildInlineSize( | 217 p = ComputePartialAbsoluteWithChildInlineSize( |
| 217 *ltr_space_, *style_, static_position, estimated_inline); | 218 *ltr_space_, *style_, static_position, estimated_inline); |
| 218 EXPECT_EQ(margin_left, p.inset.left); | 219 EXPECT_EQ(margin_left, p.inset.left); |
| 219 EXPECT_EQ(container_size_.inline_size - margin_left - width, p.inset.right); | 220 EXPECT_EQ(container_size_.inline_size - margin_left - width, p.inset.right); |
| 220 | 221 |
| 221 // Rule 2 left and right are auto RTL. | 222 // Rule 2 left and right are auto RTL. |
| 222 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, NGAuto); | 223 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, NGAuto); |
| 223 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 224 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
| 224 estimated_inline.reset(); | 225 estimated_inline.reset(); |
| 225 p = ComputePartialAbsoluteWithChildInlineSize( | 226 p = ComputePartialAbsoluteWithChildInlineSize( |
| 226 *rtl_space_, *style_, static_position, estimated_inline); | 227 *rtl_space_, *style_, static_position, estimated_inline); |
| 227 EXPECT_EQ(margin_left, p.inset.left); | 228 EXPECT_EQ(margin_left, p.inset.left); |
| 228 EXPECT_EQ(container_size_.inline_size - margin_left - width, p.inset.right); | 229 EXPECT_EQ(container_size_.inline_size - margin_left - width, p.inset.right); |
| 229 | 230 |
| 230 // Rule 3 width and right are auto. | 231 // Rule 3 width and right are auto. |
| 231 SetHorizontalStyle(left, margin_left, NGAuto, margin_right, NGAuto); | 232 SetHorizontalStyle(left, margin_left, NGAuto, margin_right, NGAuto); |
| 232 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); | 233 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), true); |
| 233 estimated_inline = LayoutUnit(60); | 234 estimated_inline = minmax_60; |
| 234 p = ComputePartialAbsoluteWithChildInlineSize( | 235 p = ComputePartialAbsoluteWithChildInlineSize( |
| 235 *ltr_space_, *style_, static_position, estimated_inline); | 236 *ltr_space_, *style_, static_position, estimated_inline); |
| 236 EXPECT_EQ( | 237 EXPECT_EQ( |
| 237 container_size_.inline_size - *estimated_inline - left - margin_left, | 238 container_size_.inline_size - minmax_60.min_content - left - margin_left, |
| 238 p.inset.right); | 239 p.inset.right); |
| 239 EXPECT_EQ(*estimated_inline, p.size.width); | 240 EXPECT_EQ(minmax_60.min_content, p.size.width); |
| 240 | 241 |
| 241 // Rule 4: left is auto. | 242 // Rule 4: left is auto. |
| 242 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, right); | 243 SetHorizontalStyle(NGAuto, margin_left, width, margin_right, right); |
| 243 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); | 244 EXPECT_EQ(AbsoluteNeedsChildInlineSize(*style_), false); |
| 244 estimated_inline.reset(); | 245 estimated_inline.reset(); |
| 245 p = ComputePartialAbsoluteWithChildInlineSize( | 246 p = ComputePartialAbsoluteWithChildInlineSize( |
| 246 *ltr_space_, *style_, static_position, estimated_inline); | 247 *ltr_space_, *style_, static_position, estimated_inline); |
| 247 EXPECT_EQ(left + margin_left, p.inset.left); | 248 EXPECT_EQ(left + margin_left, p.inset.left); |
| 248 | 249 |
| 249 // Rule 4: left is auto, EBoxSizing::BoxSizingContentBox | 250 // Rule 4: left is auto, EBoxSizing::BoxSizingContentBox |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); | 418 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); |
| 418 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); | 419 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); |
| 419 auto_height.reset(); | 420 auto_height.reset(); |
| 420 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, | 421 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
| 421 auto_height, &p); | 422 auto_height, &p); |
| 422 EXPECT_EQ(height, p.size.height); | 423 EXPECT_EQ(height, p.size.height); |
| 423 } | 424 } |
| 424 | 425 |
| 425 } // namespace | 426 } // namespace |
| 426 } // namespace blink | 427 } // namespace blink |
| OLD | NEW |