Title: [283981] trunk/Source/WebCore
Revision
283981
Author
[email protected]
Date
2021-10-12 08:43:57 -0700 (Tue, 12 Oct 2021)

Log Message

[LFC][Integration] Add support for painting inline box decorations
https://bugs.webkit.org/show_bug.cgi?id=231561

Reviewed by Alan Bujtas.

Add code for painting inline box backgrounds and borders with InlineBoxPainter.
This patch does not enable anything new yet.

* layout/integration/InlineIteratorInlineBox.cpp:
(WebCore::InlineIterator::inlineBoxFor):
* layout/integration/InlineIteratorInlineBox.h:
* layout/integration/LayoutIntegrationCoverage.cpp:

Add a new flag for background-clip:text which is not yet supported by code.
It becomes relevant when background painting is enabled.

(WebCore::LayoutIntegration::printReason):
(WebCore::LayoutIntegration::canUseForRenderInlineChild):
* layout/integration/LayoutIntegrationCoverage.h:
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::paint):

Paint inline boxes using InlineBoxPainter.

(WebCore::LayoutIntegration::LineLayout::paintTextBoxUsingPhysicalCoordinates): Deleted.

Simplify the intersection code and move it to paint().

* layout/integration/LayoutIntegrationLineLayout.h:
* rendering/InlineBoxPainter.cpp:
(WebCore::InlineBoxPainter::InlineBoxPainter):

Take InlineDisplay::Box.

* rendering/InlineBoxPainter.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283980 => 283981)


--- trunk/Source/WebCore/ChangeLog	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/ChangeLog	2021-10-12 15:43:57 UTC (rev 283981)
@@ -1,3 +1,41 @@
+2021-10-12  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Add support for painting inline box decorations
+        https://bugs.webkit.org/show_bug.cgi?id=231561
+
+        Reviewed by Alan Bujtas.
+
+        Add code for painting inline box backgrounds and borders with InlineBoxPainter.
+        This patch does not enable anything new yet.
+
+        * layout/integration/InlineIteratorInlineBox.cpp:
+        (WebCore::InlineIterator::inlineBoxFor):
+        * layout/integration/InlineIteratorInlineBox.h:
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+
+        Add a new flag for background-clip:text which is not yet supported by code.
+        It becomes relevant when background painting is enabled.
+
+        (WebCore::LayoutIntegration::printReason):
+        (WebCore::LayoutIntegration::canUseForRenderInlineChild):
+        * layout/integration/LayoutIntegrationCoverage.h:
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::paint):
+
+        Paint inline boxes using InlineBoxPainter.
+
+        (WebCore::LayoutIntegration::LineLayout::paintTextBoxUsingPhysicalCoordinates): Deleted.
+
+        Simplify the intersection code and move it to paint().
+
+        * layout/integration/LayoutIntegrationLineLayout.h:
+        * rendering/InlineBoxPainter.cpp:
+        (WebCore::InlineBoxPainter::InlineBoxPainter):
+
+        Take InlineDisplay::Box.
+
+        * rendering/InlineBoxPainter.h:
+
 2021-10-12  Aditya Keerthi  <[email protected]>
 
         [css-ui] Fix interpolation of accent-color

Modified: trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.cpp (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.cpp	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.cpp	2021-10-12 15:43:57 UTC (rev 283981)
@@ -91,6 +91,11 @@
 }
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+InlineBoxIterator inlineBoxFor(const LayoutIntegration::InlineContent& content, const InlineDisplay::Box& box)
+{
+    return inlineBoxFor(content, content.indexForBox(box));
+}
+
 InlineBoxIterator inlineBoxFor(const LayoutIntegration::InlineContent& content, size_t boxIndex)
 {
     ASSERT(content.boxes[boxIndex].isInlineBox());

Modified: trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.h (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.h	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/InlineIteratorInlineBox.h	2021-10-12 15:43:57 UTC (rev 283981)
@@ -67,6 +67,7 @@
 
 InlineBoxIterator inlineBoxFor(const LegacyInlineFlowBox&);
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+InlineBoxIterator inlineBoxFor(const LayoutIntegration::InlineContent&, const InlineDisplay::Box&);
 InlineBoxIterator inlineBoxFor(const LayoutIntegration::InlineContent&, size_t boxIndex);
 #endif
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-10-12 15:43:57 UTC (rev 283981)
@@ -212,6 +212,9 @@
     case AvoidanceReason::InlineBoxHasBackground:
         stream << "inline box has background";
         break;
+    case AvoidanceReason::InlineBoxHasBackgroundClipText:
+        stream << "inline box has background-clip: text";
+        break;
     default:
         break;
     }
@@ -481,6 +484,8 @@
         SET_REASON_AND_RETURN_IF_NEEDED(InlineBoxHasBorderOrBorderImage, reasons, includeReasons);
     if (style.hasBackground())
         SET_REASON_AND_RETURN_IF_NEEDED(InlineBoxHasBackground, reasons, includeReasons);
+    if (style.backgroundClip() == FillBox::Text)
+        SET_REASON_AND_RETURN_IF_NEEDED(InlineBoxHasBackgroundClipText, reasons, includeReasons);
     if (style.hasOutline())
         SET_REASON_AND_RETURN_IF_NEEDED(ContentHasOutline, reasons, includeReasons);
     if (renderInline.isInFlowPositioned())

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-10-12 15:43:57 UTC (rev 283981)
@@ -91,7 +91,7 @@
     MultiColumnFlowIsFloating                    = 1LLU  << 50,
     // Unused                                    = 1LLU  << 51,
     // Unused                                    = 1LLU  << 52,
-    // Unused                                    = 1LLU  << 53,
+    InlineBoxHasBackgroundClipText               = 1LLU  << 53,
     UnsupportedFieldset                          = 1LLU  << 54,
     ChildBoxIsFloatingOrPositioned               = 1LLU  << 55,
     ContentIsSVG                                 = 1LLU  << 56,

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-12 15:43:57 UTC (rev 283981)
@@ -33,6 +33,7 @@
 #include "HitTestLocation.h"
 #include "HitTestRequest.h"
 #include "HitTestResult.h"
+#include "InlineBoxPainter.h"
 #include "InlineDamage.h"
 #include "InlineFormattingContext.h"
 #include "InlineFormattingState.h"
@@ -505,18 +506,40 @@
     if (paintInfo.phase != PaintPhase::Foreground && paintInfo.phase != PaintPhase::EventRegion && paintInfo.phase != PaintPhase::TextClip && paintInfo.phase != PaintPhase::Selection)
         return;
 
-    auto paintRect = paintInfo.rect;
-    paintRect.moveBy(-paintOffset);
+    auto damageRect = paintInfo.rect;
+    damageRect.moveBy(-paintOffset);
 
-    for (auto& box : m_inlineContent->boxesForRect(paintRect)) {
+    auto hasDamage = [&](auto& box) {
+        if (box.style().visibility() != Visibility::Visible)
+            return false;
+        auto rect = enclosingLayoutRect(box.inkOverflow());
+        flow().flipForWritingMode(rect);
+        // FIXME: This should test for intersection but horizontal ink overflow is miscomputed in a few cases (like with negative letter-spacing).
+        return damageRect.maxY() > rect.y() && damageRect.y() < rect.maxY();
+    };
+
+    for (auto& box : m_inlineContent->boxesForRect(damageRect)) {
         if (box.isLineBreak())
             continue;
-        if (box.isInlineBox())
+
+        if (box.isInlineBox()) {
+            if (!hasDamage(box))
+                continue;
+
+            InlineBoxPainter painter(*m_inlineContent, box, paintInfo, paintOffset);
+            painter.paint();
             continue;
+        }
+
         if (box.text()) {
-            paintTextBoxUsingPhysicalCoordinates(paintInfo, paintOffset, box);
+            if (!box.text()->length() || !hasDamage(box))
+                continue;
+
+            TextBoxPainter painter(*m_inlineContent, box, paintInfo, paintOffset);
+            painter.paint();
             continue;
         }
+
         if (auto& renderer = m_boxTree.rendererForLayoutBox(box.layoutBox()); is<RenderBox>(renderer) && renderer.isReplaced()) {
             auto& renderBox = downcast<RenderBox>(renderer);
             if (!renderBox.hasSelfPaintingLayer() && paintInfo.shouldPaintWithinRoot(renderBox))
@@ -593,44 +616,6 @@
     m_inlineContent = nullptr;
 }
 
-void LineLayout::paintTextBoxUsingPhysicalCoordinates(PaintInfo& paintInfo, const LayoutPoint& paintOffset, const InlineDisplay::Box& textBox)
-{
-    auto& style = textBox.style();
-    if (textBox.style().visibility() != Visibility::Visible)
-        return;
-
-    auto& textContent = *textBox.text();
-    if (!textContent.length())
-        return;
-
-    auto& formattingContextRoot = flow();
-    auto blockIsHorizontalWriting = formattingContextRoot.style().isHorizontalWritingMode();
-    auto physicalPaintOffset = paintOffset;
-    if (!blockIsHorizontalWriting) {
-        // FIXME: Figure out why this translate is required.
-        physicalPaintOffset.move({ 0, -textBox.logicalRect().height() });
-    }
-
-    auto physicalRect = [&](const auto& rect) -> FloatRect {
-        if (!style.isFlippedBlocksWritingMode())
-            return rect;
-        if (!blockIsHorizontalWriting)
-            return FloatRect { formattingContextRoot.width() - rect.bottom(), rect.left() , rect.width(), rect.height() };
-        ASSERT_NOT_IMPLEMENTED_YET();
-        return rect;
-    };
-
-    auto visualOverflowRect = physicalRect(textBox.inkOverflow());
-
-    auto damagedRect = paintInfo.rect;
-    damagedRect.moveBy(-physicalPaintOffset);
-    if (damagedRect.y() > visualOverflowRect.maxY() || damagedRect.maxY() < visualOverflowRect.y())
-        return;
-
-    TextBoxPainter painter(*m_inlineContent, textBox, paintInfo, paintOffset);
-    painter.paint();
-}
-
 Layout::InlineDamage& LineLayout::ensureLineDamage()
 {
     if (!m_lineDamage)

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h (283980 => 283981)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2021-10-12 15:43:57 UTC (rev 283981)
@@ -124,8 +124,6 @@
     InlineContent& ensureInlineContent();
     void updateLayoutBoxDimensions(const RenderBox&);
 
-    void paintTextBoxUsingPhysicalCoordinates(PaintInfo&, const LayoutPoint& paintOffset, const InlineDisplay::Box&);
-
     Layout::InlineDamage& ensureLineDamage();
 
     const Layout::ContainerBox& rootLayoutBox() const;

Modified: trunk/Source/WebCore/rendering/InlineBoxPainter.cpp (283980 => 283981)


--- trunk/Source/WebCore/rendering/InlineBoxPainter.cpp	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/rendering/InlineBoxPainter.cpp	2021-10-12 15:43:57 UTC (rev 283981)
@@ -37,7 +37,19 @@
 namespace WebCore {
 
 InlineBoxPainter::InlineBoxPainter(const LegacyInlineFlowBox& inlineBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
-    : m_inlineBox(*InlineIterator::inlineBoxFor(inlineBox))
+    : InlineBoxPainter(*InlineIterator::inlineBoxFor(inlineBox), paintInfo, paintOffset)
+{
+}
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+InlineBoxPainter::InlineBoxPainter(const LayoutIntegration::InlineContent& inlineContent, const InlineDisplay::Box& box, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+    : InlineBoxPainter(*InlineIterator::inlineBoxFor(inlineContent, box), paintInfo, paintOffset)
+{
+}
+#endif
+
+InlineBoxPainter::InlineBoxPainter(const InlineIterator::InlineBox& inlineBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+    : m_inlineBox(inlineBox)
     , m_paintInfo(paintInfo)
     , m_paintOffset(paintOffset)
     , m_renderer(m_inlineBox.renderer())

Modified: trunk/Source/WebCore/rendering/InlineBoxPainter.h (283980 => 283981)


--- trunk/Source/WebCore/rendering/InlineBoxPainter.h	2021-10-12 13:48:18 UTC (rev 283980)
+++ trunk/Source/WebCore/rendering/InlineBoxPainter.h	2021-10-12 15:43:57 UTC (rev 283981)
@@ -42,11 +42,16 @@
 class InlineBoxPainter {
 public:
     InlineBoxPainter(const LegacyInlineFlowBox&, PaintInfo&, const LayoutPoint& paintOffset);
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    InlineBoxPainter(const LayoutIntegration::InlineContent&, const InlineDisplay::Box&, PaintInfo&, const LayoutPoint& paintOffset);
+#endif
     ~InlineBoxPainter();
 
     void paint();
 
 private:
+    InlineBoxPainter(const InlineIterator::InlineBox&, PaintInfo&, const LayoutPoint& paintOffset);
+
     void paintMask();
     void paintDecorations();
     void paintFillLayers(const Color&, const FillLayer&, const LayoutRect& paintRect, CompositeOperator);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to