[IFC][Integration] RenderBlockFlow::findClosestTextAtAbsolutePoint should use root inline box iterator
https://bugs.webkit.org/show_bug.cgi?id=237786
Reviewed by Antti Koivisto.
Let's remove root inline box APIs from the line iterator interface.
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::findClosestTextAtAbsolutePoint): Replace line iterator with root inline box iterator
and check whether the local point is in between these root inline boxes.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@291207 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 92c0379..0a1799d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2022-03-12 Alan Bujtas <zalan@apple.com>
+
+ [IFC][Integration] RenderBlockFlow::findClosestTextAtAbsolutePoint should use root inline box iterator
+ https://bugs.webkit.org/show_bug.cgi?id=237786
+
+ Reviewed by Antti Koivisto.
+
+ Let's remove root inline box APIs from the line iterator interface.
+
+ * rendering/RenderBlockFlow.cpp:
+ (WebCore::RenderBlockFlow::findClosestTextAtAbsolutePoint): Replace line iterator with root inline box iterator
+ and check whether the local point is in between these root inline boxes.
+
2022-03-11 Per Arne Vollan <pvollan@apple.com>
[macOS] Image decoders should be restricted for Mail
diff --git a/Source/WebCore/layout/integration/InlineIteratorLine.h b/Source/WebCore/layout/integration/InlineIteratorLine.h
index 8a8f070..70a0b80 100644
--- a/Source/WebCore/layout/integration/InlineIteratorLine.h
+++ b/Source/WebCore/layout/integration/InlineIteratorLine.h
@@ -64,7 +64,6 @@
LayoutRect selectionRect() const;
RenderObject::HighlightState selectionState() const;
- float y() const;
float contentLogicalLeft() const;
float contentLogicalRight() const;
float contentLogicalWidth() const;
@@ -196,13 +195,6 @@
return { LayoutPoint { contentLogicalLeft(), selectionTop() }, LayoutPoint { contentLogicalRight(), selectionBottom() } };
}
-inline float Line::y() const
-{
- return WTF::switchOn(m_pathVariant, [](const auto& path) {
- return path.y();
- });
-}
-
inline float Line::contentLogicalLeft() const
{
return WTF::switchOn(m_pathVariant, [](const auto& path) {
diff --git a/Source/WebCore/layout/integration/InlineIteratorLineLegacyPath.h b/Source/WebCore/layout/integration/InlineIteratorLineLegacyPath.h
index 07dda9e..713a7ab 100644
--- a/Source/WebCore/layout/integration/InlineIteratorLineLegacyPath.h
+++ b/Source/WebCore/layout/integration/InlineIteratorLineLegacyPath.h
@@ -51,7 +51,6 @@
LayoutUnit lineBoxTop() const { return m_rootInlineBox->lineBoxTop(); }
LayoutUnit lineBoxBottom() const { return m_rootInlineBox->lineBoxBottom(); }
- float y() const { return m_rootInlineBox->y(); }
float contentLogicalLeft() const { return m_rootInlineBox->logicalLeft(); }
float contentLogicalRight() const { return m_rootInlineBox->logicalRight(); }
float logicalHeight() const { return m_rootInlineBox->logicalHeight(); }
diff --git a/Source/WebCore/layout/integration/InlineIteratorLineModernPath.h b/Source/WebCore/layout/integration/InlineIteratorLineModernPath.h
index a8ad4c4..a5f2657 100644
--- a/Source/WebCore/layout/integration/InlineIteratorLineModernPath.h
+++ b/Source/WebCore/layout/integration/InlineIteratorLineModernPath.h
@@ -64,7 +64,6 @@
float contentLogicalLeft() const { return line().lineBoxLeft() + line().contentLogicalOffset(); }
float contentLogicalRight() const { return contentLogicalLeft() + line().contentLogicalWidth(); }
- float y() const { return lineBoxTop(); }
float logicalHeight() const { return lineBoxBottom() - lineBoxTop(); }
bool isHorizontal() const { return line().isHorizontal(); }
FontBaseline baselineType() const { return line().baselineType(); }
diff --git a/Source/WebCore/rendering/RenderBlockFlow.cpp b/Source/WebCore/rendering/RenderBlockFlow.cpp
index 6954ae6..f60f537 100644
--- a/Source/WebCore/rendering/RenderBlockFlow.cpp
+++ b/Source/WebCore/rendering/RenderBlockFlow.cpp
@@ -3331,18 +3331,19 @@
// Only check the gaps between the root line boxes. We deliberately ignore overflow because
// experience has shown that hit tests on an exploded text node can fail when within the
// overflow fragment.
- for (auto current = InlineIterator::firstLineFor(blockFlow), last = InlineIterator::lastLineFor(blockFlow); current && current != last; current.traverseNext()) {
- float currentBottom = current->y() + current->logicalHeight();
- if (localPoint.y() < currentBottom)
- return nullptr;
-
- auto next = current->next();
- float nextTop = next->y();
- if (localPoint.y() < nextTop) {
- auto run = current->closestRunForLogicalLeftPosition(localPoint.x());
- if (run && is<RenderText>(run->renderer()))
- return const_cast<RenderText*>(&downcast<RenderText>(run->renderer()));
+ auto previousRootInlineBoxBottom = std::optional<float> { };
+ for (auto box = InlineIterator::firstRootInlineBoxFor(blockFlow); box; box.traverseNextInlineBox()) {
+ if (previousRootInlineBoxBottom) {
+ if (localPoint.y() < *previousRootInlineBoxBottom)
+ return nullptr;
+
+ if (localPoint.y() > *previousRootInlineBoxBottom && localPoint.y() < box->logicalTop()) {
+ auto run = box->line()->closestRunForLogicalLeftPosition(localPoint.x());
+ if (run && is<RenderText>(run->renderer()))
+ return const_cast<RenderText*>(&downcast<RenderText>(run->renderer()));
+ }
}
+ previousRootInlineBoxBottom = box->logicalBottom();
}
return nullptr;
}