Skip to content

Commit

Permalink
[LFC] Add margin computation for floating, replaced elements.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=186337

Reviewed by Antti Koivisto.

If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.

* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):

Canonical link: https://commits.webkit.org/201722@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbaradlay committed Jun 6, 2018
1 parent 684a736 commit d73de52
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
14 changes: 14 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,17 @@
2018-06-06 Zalan Bujtas <zalan@apple.com>

[LFC] Add margin computation for floating, replaced elements.
https://bugs.webkit.org/show_bug.cgi?id=186337

Reviewed by Antti Koivisto.

If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.

* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):

2018-06-06 Zalan Bujtas <zalan@apple.com>

[LFC] Add margin computation for floating, no-replaced elements.
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/layout/FormattingContext.h
Expand Up @@ -95,7 +95,8 @@ class FormattingContext {
static LayoutPoint outOfFlowPosition(LayoutContext&, const Box&);

static LayoutUnit inlineReplacedHeight(LayoutContext&, const Box&);
static WidthAndMargin inlineReplacedWidthAndMargin(LayoutContext&, const Box&);
static WidthAndMargin inlineReplacedWidthAndMargin(LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedMarginLeft = { },
std::optional<LayoutUnit> precomputedMarginRight = { });

static Display::Box::Edges computedBorder(LayoutContext&, const Box&);
static std::optional<Display::Box::Edges> computedPadding(LayoutContext&, const Box&);
Expand Down
42 changes: 30 additions & 12 deletions Source/WebCore/layout/FormattingContextGeometry.cpp
Expand Up @@ -255,8 +255,18 @@ FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::floatin
ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
// 10.3.6 Floating, replaced elements
//
// The used value of 'width' is determined as for inline replaced elements.
return inlineReplacedWidthAndMargin(layoutContext, layoutBox);
// 1. If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.
// 2. The used value of 'width' is determined as for inline replaced elements.
auto& style = layoutBox.style();
std::optional<LayoutUnit> computedMarginLeftValue;
std::optional<LayoutUnit> computedMarginRightValue;

if (style.marginLeft().isAuto())
computedMarginLeftValue = LayoutUnit { 0 };
if (style.marginRight().isAuto())
computedMarginRightValue = LayoutUnit { 0 };

return inlineReplacedWidthAndMargin(layoutContext, layoutBox, computedMarginLeftValue, computedMarginRightValue);
}

static LayoutPoint outOfFlowNonReplacedPosition(LayoutContext& layoutContext, const Box& layoutBox)
Expand Down Expand Up @@ -534,7 +544,8 @@ LayoutUnit FormattingContext::Geometry::inlineReplacedHeight(LayoutContext&, con
return computedHeightValue;
}

FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
FormattingContext::Geometry::WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox,
std::optional<LayoutUnit> precomputedMarginLeft, std::optional<LayoutUnit> precomputedMarginRight)
{
ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
// 10.3.2 Inline, replaced elements
Expand All @@ -556,19 +567,26 @@ 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 computedMarginLeftValue;
LayoutUnit computedMarginRightValue;
auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();

{
auto marginLeft = style.marginLeft();
auto computeMarginRight = [&]() {
if (precomputedMarginRight)
return precomputedMarginRight.value();
auto marginRight = style.marginRight();
auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
return marginRight.isAuto() ? LayoutUnit { 0 } : valueForLength(marginRight, containingBlockWidth);
};

computedMarginLeftValue = marginLeft.isAuto() ? LayoutUnit(0) : valueForLength(marginLeft, containingBlockWidth);
computedMarginRightValue = marginRight.isAuto() ? LayoutUnit(0) : valueForLength(marginRight, containingBlockWidth);
}
auto computeMarginLeft = [&]() {
if (precomputedMarginLeft)
return precomputedMarginLeft.value();
auto marginLeft = style.marginLeft();
return marginLeft.isAuto() ? LayoutUnit { 0 } : valueForLength(marginLeft, containingBlockWidth);
};

LayoutUnit computedMarginLeftValue = computeMarginLeft();
LayoutUnit computedMarginRightValue = computeMarginRight();

LayoutUnit computedWidthValue;
auto width = style.logicalWidth();
auto height = style.logicalHeight();
auto replaced = layoutBox.replaced();
Expand Down

0 comments on commit d73de52

Please sign in to comment.