Diff
Modified: trunk/Source/WebCore/ChangeLog (253268 => 253269)
--- trunk/Source/WebCore/ChangeLog 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/ChangeLog 2019-12-08 15:10:06 UTC (rev 253269)
@@ -1,3 +1,44 @@
+2019-12-08 Zalan Bujtas <[email protected]>
+
+ [LFC][IFC] Switch over to float based types in inline layout
+ https://bugs.webkit.org/show_bug.cgi?id=204995
+ <rdar://problem/57733349>
+
+ Reviewed by Antti Koivisto.
+
+ Due to the relatively significant difference between float and LayoutUnit's precision, IFC
+ is unable to produce matching layout under the same constraints.
+ Let's switch over to float based types until after either CLL switches over to LayoutUnit
+ or LayoutUnit gains high enough precision.
+
+ See webkit.org/b/204986 for more info.
+
+ * layout/LayoutUnits.h:
+ (WebCore::Layout::maxInlineLayoutUnit):
+ * layout/Verification.cpp:
+ (WebCore::Layout::areEssentiallyEqual):
+ * layout/inlineformatting/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
+ * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+ (WebCore::Layout::InlineFormattingContext::Quirks::lineHeightConstraints const):
+ * layout/inlineformatting/InlineLineBreaker.cpp:
+ (WebCore::Layout::LineBreaker::wordBreakingBehavior const):
+ * layout/inlineformatting/InlineLineBuilder.cpp:
+ (WebCore::Layout::LineBuilder::alignContentHorizontally const):
+ (WebCore::Layout::LineBuilder::adjustBaselineAndLineHeight):
+ (WebCore::Layout::LineBuilder::halfLeadingMetrics):
+ (WebCore::Layout::LineBuilder::TrimmableContent::append):
+ * layout/inlineformatting/LineLayoutContext.cpp:
+ (WebCore::Layout::inlineItemWidth):
+ * layout/inlineformatting/text/TextUtil.cpp:
+ (WebCore::Layout::TextUtil::width):
+ (WebCore::Layout::TextUtil::fixedPitchWidth):
+ (WebCore::Layout::TextUtil::split):
+ * layout/integration/LayoutIntegrationLineLayout.cpp:
+ (WebCore::LayoutIntegration::LineLayout::firstLineBaseline const):
+ (WebCore::LayoutIntegration::LineLayout::lastLineBaseline const):
+ (WebCore::LayoutIntegration::LineLayout::paint):
+
2019-12-07 Said Abou-Hallawa <[email protected]>
Make ColorSpace an enum class
Modified: trunk/Source/WebCore/layout/LayoutUnits.h (253268 => 253269)
--- trunk/Source/WebCore/layout/LayoutUnits.h 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/LayoutUnits.h 2019-12-08 15:10:06 UTC (rev 253269)
@@ -34,15 +34,24 @@
namespace WebCore {
-namespace Display {
-class Box;
-}
+#define USE_FLOAT_AS_INLINE_LAYOUT_UNIT 1
+#if USE_FLOAT_AS_INLINE_LAYOUT_UNIT
+using InlineLayoutUnit = float;
+using InlineLayoutPoint = FloatPoint;
+using InlineLayoutSize = FloatSize;
+using InlineLayoutRect = FloatRect;
+#else
using InlineLayoutUnit = LayoutUnit;
using InlineLayoutPoint = LayoutPoint;
using InlineLayoutSize = LayoutSize;
using InlineLayoutRect = LayoutRect;
+#endif
+namespace Display {
+class Box;
+}
+
namespace Layout {
struct Position {
@@ -214,6 +223,15 @@
return LayoutRect { rect };
}
+inline InlineLayoutUnit maxInlineLayoutUnit()
+{
+#if USE_FLOAT_AS_INLINE_LAYOUT_UNIT
+ return std::numeric_limits<float>::max();
+#else
+ return LayoutUnit::max();
+#endif
}
+
}
+}
#endif
Modified: trunk/Source/WebCore/layout/Verification.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/Verification.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/Verification.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -54,9 +54,9 @@
return abs(a.rawValue() - b.rawValue()) <= epsilon;
}
-static bool areEssentiallyEqual(float a, LayoutUnit b)
+static bool areEssentiallyEqual(float a, InlineLayoutUnit b)
{
- return areEssentiallyEqual(LayoutUnit { a }, b);
+ return areEssentiallyEqual(LayoutUnit { a }, LayoutUnit { b });
}
static bool areEssentiallyEqual(LayoutRect a, LayoutRect b)
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -223,7 +223,7 @@
return computedIntrinsicWidthForConstraint(usedHorizontalValues);
};
- auto constraints = geometry().constrainByMinMaxWidth(root(), { toLayoutUnit(maximumLineWidth(0)), toLayoutUnit(maximumLineWidth(InlineLayoutUnit::max())) });
+ auto constraints = geometry().constrainByMinMaxWidth(root(), { toLayoutUnit(maximumLineWidth(0)), toLayoutUnit(maximumLineWidth(maxInlineLayoutUnit())) });
formattingState().setIntrinsicWidthConstraints(constraints);
return constraints;
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -78,7 +78,7 @@
{
// computedLineHeight takes font-size into account when line-height is not set.
// Strut is the imaginary box that we put on every line. It sets the initial vertical constraints for each new line.
- auto strutHeight = formattingRoot.style().computedLineHeight();
+ InlineLayoutUnit strutHeight = formattingRoot.style().computedLineHeight();
auto strutBaselineOffset = LineBuilder::halfLeadingMetrics(formattingRoot.style().fontMetrics(), strutHeight).ascent();
if (layoutState().inNoQuirksMode())
return { strutHeight, strutBaselineOffset, { } };
@@ -89,7 +89,7 @@
return { initialBaselineOffset, initialBaselineOffset, Display::LineBox::Baseline { strutBaselineOffset, strutHeight - strutBaselineOffset } };
}
// FIXME: The only reason why we use intValue() here is to match current inline tree (integral)behavior.
- auto initialLineHeight = InlineLayoutUnit { lineHeight.intValue() };
+ InlineLayoutUnit initialLineHeight = lineHeight.intValue();
auto initialBaselineOffset = LineBuilder::halfLeadingMetrics(formattingRoot.style().fontMetrics(), initialLineHeight).ascent();
return { initialLineHeight, initialBaselineOffset, Display::LineBox::Baseline { strutBaselineOffset, strutHeight - strutBaselineOffset } };
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -111,7 +111,7 @@
// At this point the available width can very well be negative e.g. when some part of the continuous text content can not be broken into parts ->
// <span style="word-break: keep-all">textcontentwithnobreak</span><span>textcontentwithyesbreak</span>
// When the first span computes longer than the available space, by the time we get to the second span, the adjusted available space becomes negative.
- auto adjustedAvailableWidth = std::max(0_lu, availableWidth - accumulatedRunWidth);
+ auto adjustedAvailableWidth = std::max<InlineLayoutUnit>(0, availableWidth - accumulatedRunWidth);
if (auto leftSide = tryBreakingTextRun(run, adjustedAvailableWidth))
return BreakingContext::PartialTrailingContent { index, leftSide->length, leftSide->logicalWidth, leftSide->needsHyphen };
// If this run is not breakable, we need to check if any previous run is breakable
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -343,10 +343,10 @@
case TextAlignMode::Right:
case TextAlignMode::WebKitRight:
case TextAlignMode::End:
- return std::max(availableWidth(), 0_lu);
+ return std::max<InlineLayoutUnit>(availableWidth(), 0);
case TextAlignMode::Center:
case TextAlignMode::WebKitCenter:
- return std::max(availableWidth() / 2, 0_lu);
+ return std::max<InlineLayoutUnit>(availableWidth() / 2, 0);
case TextAlignMode::Justify:
ASSERT_NOT_REACHED();
break;
@@ -598,7 +598,7 @@
// Non inline-block boxes sit on the baseline (including their bottom margin).
m_lineBox.setAscentIfGreater(marginBoxHeight);
// Ignore negative descent (yes, negative descent is a thing).
- m_lineBox.setLogicalHeightIfGreater(marginBoxHeight + std::max(0_lu, baseline.descent()));
+ m_lineBox.setLogicalHeightIfGreater(marginBoxHeight + std::max<InlineLayoutUnit>(0, baseline.descent()));
}
break;
}
@@ -682,10 +682,10 @@
auto ascent = fontMetrics.ascent();
auto descent = fontMetrics.descent();
// 10.8.1 Leading and half-leading
- auto leading = lineLogicalHeight - (ascent + descent);
- // Inline tree is all integer based.
- auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0);
- auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0);
+ auto halfLeading = (lineLogicalHeight - (ascent + descent)) / 2;
+ // Inline tree height is all integer based.
+ auto adjustedAscent = std::max<InlineLayoutUnit>(floorf(ascent + halfLeading), 0);
+ auto adjustedDescent = std::max<InlineLayoutUnit>(ceilf(descent + halfLeading), 0);
return { adjustedAscent, adjustedDescent };
}
@@ -716,7 +716,7 @@
trimmableWidth = trimmableRun.trailingLetterSpacing();
}
// word-spacing could very well be negative, but it does not mean that the line gains that much extra space when the content is trimmed.
- trimmableWidth = std::max(0_lu, trimmableWidth);
+ trimmableWidth = std::max<InlineLayoutUnit>(0, trimmableWidth);
ASSERT(trimmableWidth >= 0);
m_width += trimmableWidth;
Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -38,7 +38,7 @@
static InlineLayoutUnit inlineItemWidth(const FormattingContext& formattingContext, const InlineItem& inlineItem, InlineLayoutUnit contentLogicalLeft)
{
if (inlineItem.isLineBreak())
- return 0_lu;
+ return 0;
if (is<InlineTextItem>(inlineItem)) {
auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
@@ -47,7 +47,7 @@
auto end = inlineTextItem.isCollapsible() ? inlineTextItem.start() + 1 : inlineTextItem.end();
contentWidth = TextUtil::width(inlineTextItem.layoutBox(), inlineTextItem.start(), end, contentLogicalLeft);
}
- auto wordSpacing = inlineTextItem.isWhitespace() ? InlineLayoutUnit(inlineTextItem.style().fontCascade().wordSpacing()) : 0_lu;
+ auto wordSpacing = InlineLayoutUnit(inlineTextItem.isWhitespace() ? inlineTextItem.style().fontCascade().wordSpacing() : 0);
return *contentWidth + wordSpacing;
}
Modified: trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -71,7 +71,7 @@
if (measureWithEndSpace)
width -= (font.spaceWidth() + font.wordSpacing());
- return std::max(0_lu, InlineLayoutUnit::fromFloatRound(width));
+ return std::max<InlineLayoutUnit>(0 , InlineLayoutUnit(width));
}
InlineLayoutUnit TextUtil::fixedPitchWidth(const StringView& text, const RenderStyle& style, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft)
@@ -90,7 +90,7 @@
width += font.wordSpacing();
}
- return std::max(0_lu, InlineLayoutUnit::fromFloatRound(width));
+ return std::max<InlineLayoutUnit>(0, InlineLayoutUnit(width));
}
TextUtil::SplitData TextUtil::split(const Box& inlineBox, unsigned startPosition, unsigned length, InlineLayoutUnit textWidth, InlineLayoutUnit availableWidth, InlineLayoutUnit contentLogicalLeft)
@@ -100,7 +100,8 @@
// Pathological case of (extremely)long string and narrow lines.
// Adjust the range so that we can pick a reasonable midpoint.
InlineLayoutUnit averageCharacterWidth = textWidth / length;
- auto right = std::min<unsigned>(left + (2 * availableWidth / averageCharacterWidth).toUnsigned(), (startPosition + length - 1));
+ unsigned offset = toLayoutUnit(2 * availableWidth / averageCharacterWidth).toUnsigned();
+ auto right = std::min<unsigned>(left + offset, (startPosition + length - 1));
// Preserve the left width for the final split position so that we don't need to remeasure the left side again.
InlineLayoutUnit leftSideWidth = 0;
while (left < right) {
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (253268 => 253269)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp 2019-12-08 05:59:22 UTC (rev 253268)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp 2019-12-08 15:10:06 UTC (rev 253269)
@@ -117,7 +117,7 @@
}
auto& firstLineBox = inlineContent->lineBoxes.first();
- return firstLineBox.logicalTop() + firstLineBox.baselineOffset();
+ return Layout::toLayoutUnit(firstLineBox.logicalTop() + firstLineBox.baselineOffset());
}
LayoutUnit LineLayout::lastLineBaseline() const
@@ -129,7 +129,7 @@
}
auto& lastLineBox = inlineContent->lineBoxes.last();
- return lastLineBox.logicalTop() + lastLineBox.baselineOffset();
+ return Layout::toLayoutUnit(lastLineBox.logicalTop() + lastLineBox.baselineOffset());
}
const Display::InlineContent* LineLayout::displayInlineContent() const
@@ -241,7 +241,7 @@
auto baselineOffset = paintOffset.y() + lineBox.logicalTop() + lineBox.baselineOffset();
auto behavior = textContext.expansion() ? textContext.expansion()->behavior : DefaultExpansion;
- auto horizontalExpansion = textContext.expansion() ? textContext.expansion()->horizontalExpansion : 0_lu;
+ auto horizontalExpansion = textContext.expansion() ? Layout::toLayoutUnit(textContext.expansion()->horizontalExpansion) : 0_lu;
auto logicalLeft = paintOffset.x() + run.logicalLeft();
String textWithHyphen;