WebKit Bugzilla
Attachment 341830 Details for
Bug 186225
: [LFC] Merge width and margin computation for block-level, non-replaced and inline,replaced element in normal flow
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
Patch (text/plain), 10.37 KB, created by
zalan
on 2018-06-01 22:28:29 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
zalan
Created:
2018-06-01 22:28:29 PDT
Size:
10.37 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 4801ad32404..0cbeeec8a7b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,16 @@ >+2018-06-01 Alan Kinsley <zalan@apple.com> >+ >+ [LFC] Merge width and margin computation for block-level, non-replaced and inline,replaced element in normal flow >+ https://bugs.webkit.org/show_bug.cgi?id=186225 >+ >+ This patch merges the width and horizontal margin computation for >+ https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width and https://www.w3.org/TR/CSS22/visudet.html#blockwidth >+ >+ * layout/FormattingContextGeometry.cpp: >+ (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin): >+ * layout/blockformatting/BlockFormattingContextGeometry.cpp: >+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin): >+ > 2018-06-01 Zalan Bujtas <zalan@apple.com> > > [LFC] Merge width and horizontal margin computation >diff --git a/Source/WebCore/layout/FormattingContextGeometry.cpp b/Source/WebCore/layout/FormattingContextGeometry.cpp >index fedfed08658..1a26fef9cf8 100644 >--- a/Source/WebCore/layout/FormattingContextGeometry.cpp >+++ b/Source/WebCore/layout/FormattingContextGeometry.cpp >@@ -519,11 +519,13 @@ LayoutUnit FormattingContext::Geometry::inlineReplacedHeight(LayoutContext&, con > return computedHeightValue; > } > >-FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutContext&, const Box& layoutBox) >+FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox) > { > ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced()); > // 10.3.2 Inline, replaced elements > // >+ // A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'. >+ // > // 1. If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'. > // > // 2. If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio; >@@ -539,10 +541,21 @@ FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::inlineR > // 5. Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px. > // If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead. > auto& style = layoutBox.style(); >+ LayoutUnit computedWidthValue; >+ LayoutUnit computedMarginLeft; >+ LayoutUnit computedMarginRight; >+ >+ { >+ auto marginLeft = style.marginLeft(); >+ auto marginRight = style.marginRight(); >+ auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width(); >+ >+ computedMarginLeft = marginLeft.isAuto() ? LayoutUnit(0) : valueForLength(marginLeft, containingBlockWidth); >+ computedMarginRight = marginRight.isAuto() ? LayoutUnit(0) : valueForLength(marginRight, containingBlockWidth); >+ } >+ > auto width = style.logicalWidth(); > auto height = style.logicalHeight(); >- >- LayoutUnit computedWidthValue; > auto replaced = layoutBox.replaced(); > ASSERT(replaced); > >diff --git a/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp b/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp >index 8661ea01687..af2511f40ae 100644 >--- a/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp >+++ b/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp >@@ -121,29 +121,94 @@ FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::in > // 10.3.3 Block-level, non-replaced elements in normal flow > // The following constraints must hold among the used values of the other properties: > // 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block >+ // >+ // 1. If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' >+ // (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the width of the containing block, then >+ // any 'auto' values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero. >+ // >+ // 2. If all of the above have a computed value other than 'auto', the values are said to be "over-constrained" and one of the used values will >+ // have to be different from its computed value. If the 'direction' property of the containing block has the value 'ltr', the specified value >+ // of 'margin-right' is ignored and the value is calculated so as to make the equality true. If the value of 'direction' is 'rtl', >+ // this happens to 'margin-left' instead. >+ // >+ // 3. If there is exactly one value specified as 'auto', its used value follows from the equality. >+ // >+ // 4. If 'width' is set to 'auto', any other 'auto' values become '0' and 'width' follows from the resulting equality. >+ // >+ // 5. If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element with respect to the >+ // edges of the containing block. > >- // If 'width' is set to 'auto', any other 'auto' values become '0' and 'width' follows from the resulting equality. > auto& style = layoutBox.style(); >- auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width(); >+ auto width = style.logicalWidth(); >+ auto* containingBlock = layoutBox.containingBlock(); >+ auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*containingBlock)->width(); >+ auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox); > > LayoutUnit computedWidthValue; >- auto width = style.logicalWidth(); >- if (width.isAuto()) { >- auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox); >- auto marginLeft = displayBox.marginLeft(); >- auto marginRight = displayBox.marginRight(); >+ std::optional<LayoutUnit> computedMarginLeftValue; >+ std::optional<LayoutUnit> computedMarginRightValue; > >- auto paddingLeft = displayBox.paddingLeft(); >- auto paddingRight = displayBox.paddingRight(); >+ auto marginLeft = style.marginLeft(); >+ if (!marginLeft.isAuto()) >+ computedMarginLeftValue = valueForLength(marginLeft, containingBlockWidth); > >- auto borderLeft = displayBox.borderLeft(); >- auto borderRight = displayBox.borderRight(); >+ auto marginRight = style.marginRight(); >+ if (!marginRight.isAuto()) >+ computedMarginRightValue = valueForLength(marginRight, containingBlockWidth); > >- computedWidthValue = containingBlockWidth - (marginLeft + borderLeft + paddingLeft + paddingRight + borderRight + marginRight); >- } else >+ auto borderLeft = displayBox.borderLeft(); >+ auto borderRight = displayBox.borderRight(); >+ auto paddingLeft = displayBox.paddingLeft(); >+ auto paddingRight = displayBox.paddingRight(); >+ >+ // #1 >+ if (!width.isAuto()) { > computedWidthValue = valueForLength(width, containingBlockWidth); >+ auto horizontalSpaceForMargin = containingBlockWidth - (computedMarginLeftValue.value_or(0) + borderLeft + paddingLeft >+ + computedWidthValue + paddingRight + borderRight + computedMarginRightValue.value_or(0)); >+ >+ if (horizontalSpaceForMargin < 0) { >+ if (!computedMarginLeftValue) >+ computedMarginLeftValue = LayoutUnit(0); >+ if (!computedMarginRightValue) >+ computedMarginRightValue = LayoutUnit(0); >+ } >+ } >+ >+ // #2 >+ if (!width.isAuto() && !marginLeft.isAuto() && !marginRight.isAuto()) { >+ ASSERT(computedMarginLeftValue); >+ ASSERT(computedMarginRightValue); >+ >+ if (containingBlock->style().isLeftToRightDirection()) >+ computedMarginRightValue = containingBlockWidth - (*computedMarginLeftValue + borderLeft + paddingLeft + computedWidthValue + paddingRight + borderRight); >+ else >+ computedMarginLeftValue = containingBlockWidth - (*computedMarginRightValue + borderLeft + paddingLeft + computedWidthValue + paddingRight + borderRight); >+ } >+ >+ // #3 >+ if (!computedMarginLeftValue && !marginRight.isAuto() && !width.isAuto()) { >+ ASSERT(computedMarginRightValue); >+ computedMarginLeftValue = containingBlockWidth - (borderLeft + paddingLeft + computedWidthValue + paddingRight + borderRight + *computedMarginRightValue); >+ } else if (!computedMarginRightValue && !marginLeft.isAuto() && !width.isAuto()) { >+ ASSERT(computedMarginLeftValue); >+ computedMarginRightValue = containingBlockWidth - (*computedMarginLeftValue + borderLeft + paddingLeft + computedWidthValue + paddingRight + borderRight); >+ } >+ >+ // #4 >+ if (width.isAuto()) >+ computedWidthValue = containingBlockWidth - (computedMarginLeftValue.value_or(0) + borderLeft + paddingLeft + paddingRight + borderRight + computedMarginRightValue.value_or(0)); >+ >+ // #5 >+ if (!computedMarginLeftValue && !computedMarginRightValue) { >+ auto horizontalSpaceForMargin = containingBlockWidth - (borderLeft + paddingLeft + computedWidthValue + paddingRight + borderRight); >+ computedMarginLeftValue = computedMarginRightValue = horizontalSpaceForMargin / 2; >+ } >+ >+ ASSERT(computedMarginLeftValue); >+ ASSERT(computedMarginRightValue); > >- return FormattingContext::Geometry::WidthAndMargin { computedWidthValue, { } }; >+ return FormattingContext::Geometry::WidthAndMargin { computedWidthValue, { *computedMarginLeftValue, *computedMarginRightValue } }; > }; > > auto computedWidthAndMarginValue = compute();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186225
:
341830
|
341831