Title: [283726] trunk/Source/WebCore
Revision
283726
Author
[email protected]
Date
2021-10-07 11:32:49 -0700 (Thu, 07 Oct 2021)

Log Message

[LFC][Integration] Use optimized InlineContent::boxesForRect for hit testing
https://bugs.webkit.org/show_bug.cgi?id=231363

Reviewed by Alan Bujtas.

This makes hit testing large blocks faster.

* layout/integration/LayoutIntegrationInlineContent.cpp:
(WebCore::LayoutIntegration::InlineContent::boxesForRect const):
(WebCore::LayoutIntegration:: const): Deleted.
* layout/integration/LayoutIntegrationInlineContent.h:
(WebCore::LayoutIntegration::InlineContent::BoxRange::begin const):
(WebCore::LayoutIntegration::InlineContent::BoxRange::end const):
(WebCore::LayoutIntegration::InlineContent::BoxRange::rbegin const):
(WebCore::LayoutIntegration::InlineContent::BoxRange::rend const):

Add a reversable iterator.

* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::hitTest):

Hit test using boxesForRect.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283725 => 283726)


--- trunk/Source/WebCore/ChangeLog	2021-10-07 18:28:08 UTC (rev 283725)
+++ trunk/Source/WebCore/ChangeLog	2021-10-07 18:32:49 UTC (rev 283726)
@@ -1,3 +1,28 @@
+2021-10-07  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Use optimized InlineContent::boxesForRect for hit testing
+        https://bugs.webkit.org/show_bug.cgi?id=231363
+
+        Reviewed by Alan Bujtas.
+
+        This makes hit testing large blocks faster.
+
+        * layout/integration/LayoutIntegrationInlineContent.cpp:
+        (WebCore::LayoutIntegration::InlineContent::boxesForRect const):
+        (WebCore::LayoutIntegration:: const): Deleted.
+        * layout/integration/LayoutIntegrationInlineContent.h:
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::begin const):
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::end const):
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::rbegin const):
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::rend const):
+
+        Add a reversable iterator.
+
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::hitTest):
+
+        Hit test using boxesForRect.
+
 2021-10-07  Darin Adler  <[email protected]>
 
         Get rid of the deviceClass function, up-leveling to deviceClassIsSmallScreen

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp (283725 => 283726)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2021-10-07 18:28:08 UTC (rev 283725)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2021-10-07 18:32:49 UTC (rev 283726)
@@ -47,7 +47,7 @@
     return boxes.size() > 1;
 };
 
-WTF::IteratorRange<const InlineDisplay::Box*> InlineContent::boxesForRect(const LayoutRect& rect) const
+auto InlineContent::boxesForRect(const LayoutRect& rect) const -> BoxRange
 {
     if (boxes.isEmpty())
         return { nullptr, nullptr };

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h (283725 => 283726)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2021-10-07 18:28:08 UTC (rev 283725)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2021-10-07 18:32:49 UTC (rev 283726)
@@ -66,7 +66,20 @@
     bool hasContent() const;
     
     const Line& lineForBox(const InlineDisplay::Box& box) const { return lines[box.lineIndex()]; }
-    WTF::IteratorRange<const InlineDisplay::Box*> boxesForRect(const LayoutRect&) const;
+
+    struct BoxRange {
+        using reverse_iterator = std::reverse_iterator<const InlineDisplay::Box*>;
+
+        const InlineDisplay::Box* rangeBegin;
+        const InlineDisplay::Box* rangeEnd;
+
+        auto begin() const { return rangeBegin; }
+        auto end() const { return rangeEnd; }
+        auto rbegin() const { return reverse_iterator { rangeEnd  }; }
+        auto rend() const { return reverse_iterator { rangeBegin }; }
+    };
+    BoxRange boxesForRect(const LayoutRect&) const;
+
     void shrinkToFit();
 
     const LineLayout& lineLayout() const { return *m_lineLayout; }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (283725 => 283726)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-07 18:28:08 UTC (rev 283725)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-07 18:32:49 UTC (rev 283726)
@@ -533,10 +533,11 @@
     if (!m_inlineContent)
         return false;
 
-    auto& inlineContent = *m_inlineContent;
+    auto hitTestBoundingBox = locationInContainer.boundingBox();
+    hitTestBoundingBox.moveBy(-accumulatedOffset);
+    auto boxRange = m_inlineContent->boxesForRect(hitTestBoundingBox);
 
-    // FIXME: This should do something efficient to find the box range.
-    for (auto& box : WTF::makeReversedRange(inlineContent.boxes)) {
+    for (auto& box : WTF::makeReversedRange(boxRange)) {
         auto& renderer = m_boxTree.rendererForLayoutBox(box.layoutBox());
 
         if (!box.isRootInlineBox() && is<RenderLayerModelObject>(renderer) && downcast<RenderLayerModelObject>(renderer).hasSelfPaintingLayer())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to