Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc b/third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc |
| index f9791360f3cf8ec69649fdf4239de6e8562f5720..1e90934489873779e4443e1b5310e21402afae83 100644 |
| --- a/third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc |
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc |
| @@ -25,6 +25,19 @@ bool AbsoluteVerticalNeedsEstimate(const ComputedStyle& style) { |
| (height.isAuto() && (style.top().isAuto() || style.bottom().isAuto())); |
| } |
| +LayoutUnit ResolveWidth(const Length& width, |
| + const NGConstraintSpace& space, |
| + const ComputedStyle& style, |
| + const Optional<MinAndMaxContentSizes>& child_minmax) { |
| + if (space.WritingMode() == kHorizontalTopBottom) |
| + return ResolveInlineLength(space, style, child_minmax, width, |
| + LengthResolveType::kContentSize); |
|
cbiesinger
2017/01/19 22:49:13
So, you really need to pass in the LengthResolveTy
atotic
2017/01/19 23:47:43
done. The usage of Resolve.. methods keeps trippin
|
| + LayoutUnit computed_width = |
| + child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); |
| + return ResolveBlockLength(space, style, style.width(), computed_width, |
| + LengthResolveType::kContentSize); |
| +} |
| + |
| // Implement absolute horizontal size resolution algorithm. |
| // https://www.w3.org/TR/css-position-3/#abs-non-replaced-width |
| void ComputeAbsoluteHorizontal( |
| @@ -58,19 +71,17 @@ void ComputeAbsoluteHorizontal( |
| right = valueForLength(style.right(), percentage_physical.width); |
| LayoutUnit border_padding = |
| border_left + border_right + padding_left + padding_right; |
| + Optional<LayoutUnit> min_width; |
| + if (!style.minWidth().isAuto()) |
| + min_width = ResolveWidth(style.minWidth(), space, style, child_minmax); |
| + Optional<LayoutUnit> max_width; |
| + if (!style.maxWidth().isMaxSizeNone()) |
| + max_width = ResolveWidth(style.maxWidth(), space, style, child_minmax); |
| Optional<LayoutUnit> width; |
| if (!style.width().isAuto()) { |
| - if (space.WritingMode() == kHorizontalTopBottom) { |
| - width = ResolveInlineLength(space, style, child_minmax, style.width(), |
| - LengthResolveType::kContentSize); |
| - } else { |
| - LayoutUnit computed_width = |
| - child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); |
| - width = ResolveBlockLength(space, style, style.width(), computed_width, |
| - LengthResolveType::kContentSize); |
| - } |
| + width = ResolveWidth(style.width(), space, style, child_minmax); |
| + width = ConstrainByMinMax(*width, min_width, max_width); |
| } |
| - |
| NGPhysicalSize container_size = |
| space.AvailableSize().ConvertToPhysical(space.WritingMode()); |
| DCHECK(container_size.width != NGSizeIndefinite); |
| @@ -85,6 +96,7 @@ void ComputeAbsoluteHorizontal( |
| margin_right = LayoutUnit(); |
| DCHECK(child_minmax.has_value()); |
| width = child_minmax->ShrinkToFit(container_size.width); |
| + width = ConstrainByMinMax(*width, min_width, max_width); |
| if (space.Direction() == TextDirection::kLtr) { |
| left = static_position.LeftPosition(container_size.width, *width, |
| *margin_left, *margin_right); |
| @@ -140,6 +152,7 @@ void ComputeAbsoluteHorizontal( |
| DCHECK(right.has_value()); |
| DCHECK(child_minmax.has_value()); |
| width = child_minmax->ShrinkToFit(container_size.width); |
| + width = ConstrainByMinMax(*width, min_width, max_width); |
| } else if (!left && !right) { |
| // Rule 2. |
| DCHECK(width.has_value()); |
| @@ -153,6 +166,7 @@ void ComputeAbsoluteHorizontal( |
| // Rule 3. |
| DCHECK(child_minmax.has_value()); |
| width = child_minmax->ShrinkToFit(container_size.width); |
| + width = ConstrainByMinMax(*width, min_width, max_width); |
| } |
| // Rules 4 through 6, 1 out of 3 are unknown. |
| @@ -169,6 +183,7 @@ void ComputeAbsoluteHorizontal( |
| DCHECK_EQ(container_size.width, |
| *left + *right + *margin_left + *margin_right + *width); |
| + width = ConstrainByMinMax(*width, min_width, max_width); |
| // Negative widths are not allowed. |
| width = std::max(*width, border_padding); |
| @@ -177,6 +192,18 @@ void ComputeAbsoluteHorizontal( |
| position->size.width = *width; |
| } |
| +LayoutUnit ResolveHeight(const Length& height, |
|
cbiesinger
2017/01/19 22:49:13
I would move this function to the top, under Resol
atotic
2017/01/19 23:47:43
done.
|
| + const NGConstraintSpace& space, |
| + const ComputedStyle& style, |
| + const Optional<MinAndMaxContentSizes>& child_minmax) { |
| + if (space.WritingMode() != kHorizontalTopBottom) |
| + return ResolveInlineLength(space, style, child_minmax, height, |
| + LengthResolveType::kContentSize); |
| + LayoutUnit computed_height = |
| + child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); |
| + return ResolveBlockLength(space, style, height, computed_height, |
| + LengthResolveType::kContentSize); |
| +} |
| // Implements absolute vertical size resolution algorithm. |
| // https://www.w3.org/TR/css-position-3/#abs-non-replaced-height |
| void ComputeAbsoluteVertical( |
| @@ -212,17 +239,16 @@ void ComputeAbsoluteVertical( |
| LayoutUnit border_padding = |
| border_top + border_bottom + padding_top + padding_bottom; |
| + Optional<LayoutUnit> min_height; |
| + if (!style.minHeight().isAuto()) |
| + min_height = ResolveHeight(style.minHeight(), space, style, child_minmax); |
| + Optional<LayoutUnit> max_height; |
| + if (!style.maxHeight().isMaxSizeNone()) |
| + max_height = ResolveHeight(style.maxHeight(), space, style, child_minmax); |
| Optional<LayoutUnit> height; |
| if (!style.height().isAuto()) { |
| - if (space.WritingMode() == kHorizontalTopBottom) { |
| - LayoutUnit computed_height = |
| - child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); |
| - height = ResolveBlockLength(space, style, style.height(), computed_height, |
| - LengthResolveType::kContentSize); |
| - } else { |
| - height = ResolveInlineLength(space, style, child_minmax, style.height(), |
| - LengthResolveType::kContentSize); |
| - } |
| + height = ResolveHeight(style.height(), space, style, child_minmax); |
| + height = ConstrainByMinMax(*height, min_height, max_height); |
| } |
| NGPhysicalSize container_size = |
| @@ -240,6 +266,7 @@ void ComputeAbsoluteVertical( |
| margin_bottom = LayoutUnit(); |
| DCHECK(child_minmax.has_value()); |
| height = child_minmax->ShrinkToFit(container_size.height); |
| + height = ConstrainByMinMax(*height, min_height, max_height); |
| top = static_position.TopPosition(container_size.height, *height, |
| *margin_top, *margin_bottom); |
| } else if (top && bottom && height) { |
| @@ -279,6 +306,7 @@ void ComputeAbsoluteVertical( |
| DCHECK(bottom.has_value()); |
| DCHECK(child_minmax.has_value()); |
| height = child_minmax->ShrinkToFit(container_size.height); |
| + height = ConstrainByMinMax(*height, min_height, max_height); |
| } else if (!top && !bottom) { |
| // Rule 2. |
| DCHECK(height.has_value()); |
| @@ -288,6 +316,7 @@ void ComputeAbsoluteVertical( |
| // Rule 3. |
| DCHECK(child_minmax.has_value()); |
| height = child_minmax->ShrinkToFit(container_size.height); |
| + height = ConstrainByMinMax(*height, min_height, max_height); |
| } |
| // Rules 4 through 6, 1 out of 3 are unknown. |
| @@ -304,6 +333,7 @@ void ComputeAbsoluteVertical( |
| DCHECK_EQ(container_size.height, |
| *top + *bottom + *margin_top + *margin_bottom + *height); |
| + height = ConstrainByMinMax(*height, min_height, max_height); |
| // Negative heights are not allowed. |
| height = std::max(*height, border_padding); |