Title: [245779] trunk/Source/WebCore
Revision
245779
Author
[email protected]
Date
2019-05-26 07:04:13 -0700 (Sun, 26 May 2019)

Log Message

[LFC][Verification] Add areEssentiallyEqual for LayoutRect
https://bugs.webkit.org/show_bug.cgi?id=198250
<rdar://problem/51140119>

Reviewed by Antti Koivisto.

WebKit's inline layout is a mix of int/float/LayoutUnit types, while LFC mostly uses LayoutUnit.
When we compute the used size of a block container (based on the inline tree), the final value might go through a few conversions.

* layout/Verification.cpp:
(WebCore::Layout::areEssentiallyEqual):
(WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (245778 => 245779)


--- trunk/Source/WebCore/ChangeLog	2019-05-26 11:31:49 UTC (rev 245778)
+++ trunk/Source/WebCore/ChangeLog	2019-05-26 14:04:13 UTC (rev 245779)
@@ -1,3 +1,18 @@
+2019-05-26  Zalan Bujtas  <[email protected]>
+
+        [LFC][Verification] Add areEssentiallyEqual for LayoutRect
+        https://bugs.webkit.org/show_bug.cgi?id=198250
+        <rdar://problem/51140119>
+
+        Reviewed by Antti Koivisto.
+
+        WebKit's inline layout is a mix of int/float/LayoutUnit types, while LFC mostly uses LayoutUnit.
+        When we compute the used size of a block container (based on the inline tree), the final value might go through a few conversions.
+
+        * layout/Verification.cpp:
+        (WebCore::Layout::areEssentiallyEqual):
+        (WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):
+
 2019-05-26  Wenson Hsieh  <[email protected]>
 
         [iOS] Dropped text, attachments, and images should animate into place

Modified: trunk/Source/WebCore/layout/Verification.cpp (245778 => 245779)


--- trunk/Source/WebCore/layout/Verification.cpp	2019-05-26 11:31:49 UTC (rev 245778)
+++ trunk/Source/WebCore/layout/Verification.cpp	2019-05-26 14:04:13 UTC (rev 245779)
@@ -42,14 +42,28 @@
 namespace WebCore {
 namespace Layout {
 
-static bool areEssentiallyEqual(float a, LayoutUnit b)
+static bool areEssentiallyEqual(LayoutUnit a, LayoutUnit b)
 {
-    if (a == b.toFloat())
+    if (a == b)
         return true;
+    // 1/4th CSS pixel.
+    constexpr float epsilon = kFixedPointDenominator / 4;
+    return abs(a.rawValue() - b.rawValue()) <= epsilon;
+}
 
-    return fabs(a - b.toFloat()) <= 10 * LayoutUnit::epsilon();
+static bool areEssentiallyEqual(float a, LayoutUnit b)
+{
+    return areEssentiallyEqual(LayoutUnit { a }, b);
 }
 
+static bool areEssentiallyEqual(LayoutRect a, LayoutRect b)
+{
+    return areEssentiallyEqual(a.x(), b.x())
+        && areEssentiallyEqual(a.y(), b.y())
+        && areEssentiallyEqual(a.width(), b.width())
+        && areEssentiallyEqual(a.height(), b.height());
+}
+
 static bool outputMismatchingSimpleLineInformationIfNeeded(TextStream& stream, const LayoutState& layoutState, const RenderBlockFlow& blockFlow, const Container& inlineFormattingRoot)
 {
     auto* lineLayoutData = blockFlow.simpleLineLayout();
@@ -216,27 +230,27 @@
     if (renderer.isInFlowPositioned())
         frameRect.move(renderer.offsetForInFlowPosition());
 
-    if (frameRect != displayBox.rect()) {
+    if (!areEssentiallyEqual(frameRect, displayBox.rect())) {
         outputRect("frameBox", renderer.frameRect(), displayBox.rect());
         return true;
     }
 
-    if (renderer.borderBoxRect() != displayBox.borderBox()) {
+    if (!areEssentiallyEqual(renderer.borderBoxRect(), displayBox.borderBox())) {
         outputRect("borderBox", renderer.borderBoxRect(), displayBox.borderBox());
         return true;
     }
 
-    if (renderer.paddingBoxRect() != displayBox.paddingBox()) {
+    if (!areEssentiallyEqual(renderer.paddingBoxRect(), displayBox.paddingBox())) {
         outputRect("paddingBox", renderer.paddingBoxRect(), displayBox.paddingBox());
         return true;
     }
 
-    if (renderer.contentBoxRect() != displayBox.contentBox()) {
+    if (!areEssentiallyEqual(renderer.contentBoxRect(), displayBox.contentBox())) {
         outputRect("contentBox", renderer.contentBoxRect(), displayBox.contentBox());
         return true;
     }
 
-    if (renderer.marginBoxRect() != renderBoxLikeMarginBox(displayBox)) {
+    if (!areEssentiallyEqual(renderer.marginBoxRect(), renderBoxLikeMarginBox(displayBox))) {
         // In certain cases, like out-of-flow boxes with margin auto, marginBoxRect() returns 0. It's clearly incorrect,
         // so let's check the individual margin values instead (and at this point we know that all other boxes match).
         auto marginsMatch = displayBox.marginBefore() == renderer.marginBefore()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to