[LFC][IFC] Do not floor the computed intrinsic width values
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2020 14:51:29 +0000 (14:51 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2020 14:51:29 +0000 (14:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208796
<rdar://problem/60209522>

Reviewed by Antti Koivisto.

Source/WebCore:

Floored intrinsic values could lead to unexpected line breaks.
(This happens because IFC uses float currently, while other layout systems use LayoutUnit.)

Test: fast/layoutformattingcontext/absolute-positioned-simple-table3.html

* layout/LayoutUnits.h:
(WebCore::Layout::ceiledLayoutUnit):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthForConstraint const):
* layout/inlineformatting/InlineFormattingContext.h:

LayoutTests:

* fast/layoutformattingcontext/absolute-positioned-simple-table3-expected.html: Added.
* fast/layoutformattingcontext/absolute-positioned-simple-table3.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258138 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3-expected.html [new file with mode: 0644]
LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

index 9d7988d..578a227 100644 (file)
@@ -1,3 +1,14 @@
+2020-03-09  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Do not floor the computed intrinsic width values
+        https://bugs.webkit.org/show_bug.cgi?id=208796
+        <rdar://problem/60209522>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/absolute-positioned-simple-table3-expected.html: Added.
+        * fast/layoutformattingcontext/absolute-positioned-simple-table3.html: Added.
+
 2020-03-08  Lauro Moura  <lmoura@igalia.com>
 
         [WPE] Mark some tests as crashing
diff --git a/LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3-expected.html b/LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3-expected.html
new file mode 100644 (file)
index 0000000..144410f
--- /dev/null
@@ -0,0 +1,7 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+div {
+    padding: 45px;
+}
+</style>
+<div>text content text content</div>
diff --git a/LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3.html b/LayoutTests/fast/layoutformattingcontext/absolute-positioned-simple-table3.html
new file mode 100644 (file)
index 0000000..472381e
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    position: absolute;
+    top: 50px;
+    left: 50px;
+}
+</style>
+<table><tr><td>text content</td><td>text content</td></tr></table>
index 6dcb9aa..c567049 100644 (file)
@@ -1,5 +1,25 @@
 2020-03-09  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Do not floor the computed intrinsic width values
+        https://bugs.webkit.org/show_bug.cgi?id=208796
+        <rdar://problem/60209522>
+
+        Reviewed by Antti Koivisto.
+
+        Floored intrinsic values could lead to unexpected line breaks.
+        (This happens because IFC uses float currently, while other layout systems use LayoutUnit.)
+
+        Test: fast/layoutformattingcontext/absolute-positioned-simple-table3.html
+
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::ceiledLayoutUnit):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthForConstraint const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+
+2020-03-09  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][TFC] Do no try to distribute extra space in case of shrink to fit (max preferred width).
         https://bugs.webkit.org/show_bug.cgi?id=208795
         <rdar://problem/60208329>
index a2be3c9..c1311f9 100644 (file)
@@ -185,6 +185,11 @@ inline LayoutUnit toLayoutUnit(InlineLayoutUnit value)
     return LayoutUnit { value };
 }
 
+inline LayoutUnit ceiledLayoutUnit(InlineLayoutUnit value)
+{
+    return LayoutUnit::fromFloatCeil(value);
+}
+
 inline LayoutPoint toLayoutPoint(const InlineLayoutPoint& point)
 {
     return LayoutPoint { point };
index dffd93e..59ae895 100644 (file)
@@ -222,15 +222,17 @@ FormattingContext::IntrinsicWidthConstraints InlineFormattingContext::computedIn
             auto contentWidth = (availableWidth ? intrinsicWidths->maximum : intrinsicWidths->minimum) - displayBox.horizontalMarginBorderAndPadding();
             displayBox.setContentBoxWidth(contentWidth);
         }
-        return computedIntrinsicWidthForConstraint({ 0_lu, toLayoutUnit(availableWidth) });
+        return computedIntrinsicWidthForConstraint(availableWidth);
     };
 
-    auto constraints = geometry().constrainByMinMaxWidth(root(), { toLayoutUnit(maximumLineWidth(0)), toLayoutUnit(maximumLineWidth(maxInlineLayoutUnit())) });
+    auto minimumContentWidth = ceiledLayoutUnit(maximumLineWidth(0));
+    auto maximumContentWidth = ceiledLayoutUnit(maximumLineWidth(maxInlineLayoutUnit()));
+    auto constraints = geometry().constrainByMinMaxWidth(root(), { minimumContentWidth, maximumContentWidth });
     formattingState().setIntrinsicWidthConstraints(constraints);
     return constraints;
 }
 
-InlineLayoutUnit InlineFormattingContext::computedIntrinsicWidthForConstraint(const HorizontalConstraints& horizontalConstraints) const
+InlineLayoutUnit InlineFormattingContext::computedIntrinsicWidthForConstraint(InlineLayoutUnit availableWidth) const
 {
     auto& inlineItems = formattingState().inlineItems();
     auto maximumLineWidth = InlineLayoutUnit { };
@@ -239,7 +241,7 @@ InlineLayoutUnit InlineFormattingContext::computedIntrinsicWidthForConstraint(co
     auto layoutRange = LineLayoutContext::InlineItemRange { 0 , inlineItems.size() };
     while (!layoutRange.isEmpty()) {
         // Only the horiztonal available width is constrained when computing intrinsic width.
-        lineBuilder.initialize(LineBuilder::Constraints { { }, horizontalConstraints.logicalWidth, false, { } });
+        lineBuilder.initialize(LineBuilder::Constraints { { }, availableWidth, false, { } });
         auto lineContent = lineLayoutContext.layoutLine(lineBuilder, layoutRange, { });
         layoutRange.start = *lineContent.trailingInlineItemIndex + 1;
         // FIXME: Use line logical left and right to take floats into account.
index 5279866..88b9920 100644 (file)
@@ -80,7 +80,7 @@ private:
     void lineLayout(InlineItems&, LineLayoutContext::InlineItemRange, const HorizontalConstraints&, const VerticalConstraints&);
 
     void computeIntrinsicWidthForFormattingRoot(const Box&);
-    InlineLayoutUnit computedIntrinsicWidthForConstraint(const HorizontalConstraints&) const;
+    InlineLayoutUnit computedIntrinsicWidthForConstraint(InlineLayoutUnit availableWidth) const;
 
     void computeHorizontalMargin(const Box&, const HorizontalConstraints&);
     void computeHeightAndMargin(const Box&, const HorizontalConstraints&);