Title: [267923] trunk/Source/WebCore
Revision
267923
Author
[email protected]
Date
2020-10-03 08:02:22 -0700 (Sat, 03 Oct 2020)

Log Message

Floating-point math causes shrink-wrapped content to line wrap sometimes
https://bugs.webkit.org/show_bug.cgi?id=217136
<rdar://problem/69801790>

Reviewed by Antti Koivisto.

Since the preferred width computation and the actual inline layout run though different codepaths,
they may compute slightly different content width due to the limited floating point precision.
Use WTF::areEssentiallyEqual when deciding if the content overflows the current line.

* rendering/line/LineWidth.cpp:
(WebCore::LineWidth::fitsOnLineIncludingExtraWidth const):
(WebCore::LineWidth::fitsOnLineExcludingTrailingWhitespace const):
(WebCore::LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (267922 => 267923)


--- trunk/Source/WebCore/ChangeLog	2020-10-03 14:39:32 UTC (rev 267922)
+++ trunk/Source/WebCore/ChangeLog	2020-10-03 15:02:22 UTC (rev 267923)
@@ -1,5 +1,22 @@
 2020-10-03  Zalan Bujtas  <[email protected]>
 
+        Floating-point math causes shrink-wrapped content to line wrap sometimes
+        https://bugs.webkit.org/show_bug.cgi?id=217136
+        <rdar://problem/69801790>
+
+        Reviewed by Antti Koivisto.
+
+        Since the preferred width computation and the actual inline layout run though different codepaths,
+        they may compute slightly different content width due to the limited floating point precision.
+        Use WTF::areEssentiallyEqual when deciding if the content overflows the current line.
+
+        * rendering/line/LineWidth.cpp:
+        (WebCore::LineWidth::fitsOnLineIncludingExtraWidth const):
+        (WebCore::LineWidth::fitsOnLineExcludingTrailingWhitespace const):
+        (WebCore::LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace const):
+
+2020-10-03  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC][Soft hyphen] Do not split InlineItems at soft hyphens when hyphenations is disabled
         https://bugs.webkit.org/show_bug.cgi?id=217266
 

Modified: trunk/Source/WebCore/rendering/line/LineWidth.cpp (267922 => 267923)


--- trunk/Source/WebCore/rendering/line/LineWidth.cpp	2020-10-03 14:39:32 UTC (rev 267922)
+++ trunk/Source/WebCore/rendering/line/LineWidth.cpp	2020-10-03 15:02:22 UTC (rev 267923)
@@ -50,14 +50,22 @@
 
 bool LineWidth::fitsOnLineIncludingExtraWidth(float extra) const
 {
-    return currentWidth() + extra <= m_availableWidth;
+    auto adjustedCurrentWidth = currentWidth() + extra;
+    return adjustedCurrentWidth < m_availableWidth || WTF::areEssentiallyEqual(adjustedCurrentWidth, m_availableWidth);
 }
 
 bool LineWidth::fitsOnLineExcludingTrailingWhitespace(float extra) const
 {
-    return currentWidth() - m_trailingWhitespaceWidth + extra <= m_availableWidth;
+    auto adjustedCurrentWidth = currentWidth() - m_trailingWhitespaceWidth + extra;
+    return adjustedCurrentWidth < m_availableWidth || WTF::areEssentiallyEqual(adjustedCurrentWidth, m_availableWidth);
 }
 
+bool LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace() const
+{
+    auto adjustedCurrentWidth = currentWidth() - m_trailingCollapsedWhitespaceWidth;
+    return adjustedCurrentWidth < m_availableWidth || WTF::areEssentiallyEqual(adjustedCurrentWidth, m_availableWidth);
+}
+
 void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight)
 {
     LayoutUnit height = m_block.logicalHeight();
@@ -226,11 +234,6 @@
     m_availableWidth = std::max<float>(0, m_right - m_left) + m_overhangWidth;
 }
 
-bool LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace() const
-{
-    return currentWidth() - m_trailingCollapsedWhitespaceWidth <= m_availableWidth;
-}
-
 IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle& style)
 {
     IndentTextOrNot shouldIndentText = DoNotIndentText;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to