Skip to content
Permalink
Browse files
Add way to get parent inline box to the inline iterator
https://bugs.webkit.org/show_bug.cgi?id=243792

Reviewed by Alan Bujtas.

* Source/WebCore/layout/integration/inline/InlineIteratorBox.cpp:
(WebCore::InlineIterator::Box::parentInlineBox const):
* Source/WebCore/layout/integration/inline/InlineIteratorBox.h:
* Source/WebCore/layout/integration/inline/InlineIteratorBoxLegacyPath.h:
(WebCore::InlineIterator::BoxLegacyPath::parentInlineBox const):
* Source/WebCore/layout/integration/inline/InlineIteratorBoxModernPath.h:
(WebCore::InlineIterator::BoxModernPath::parentInlineBox const):

Canonical link: https://commits.webkit.org/253304@main
  • Loading branch information
anttijk committed Aug 10, 2022
1 parent c51d445 commit 1d07fae7e956b36a4ab52078da4e781b33688483
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
@@ -81,6 +81,13 @@ LeafBoxIterator Box::previousOnLineIgnoringLineBreak() const
return LeafBoxIterator(*this).traversePreviousOnLineIgnoringLineBreak();
}

InlineBoxIterator Box::parentInlineBox() const
{
return WTF::switchOn(m_pathVariant, [](auto& path) -> InlineBoxIterator {
return { path.parentInlineBox() };
});
}

LineBoxIterator Box::lineBox() const
{
return WTF::switchOn(m_pathVariant, [](const BoxLegacyPath& path) {
@@ -99,6 +99,8 @@ class Box {
LeafBoxIterator nextOnLineIgnoringLineBreak() const;
LeafBoxIterator previousOnLineIgnoringLineBreak() const;

InlineBoxIterator parentInlineBox() const;

LineBoxIterator lineBox() const;

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
@@ -118,6 +118,11 @@ class BoxLegacyPath {
return { inlineFlowBox()->lastLeafDescendant() };
}

BoxLegacyPath parentInlineBox() const
{
return { m_inlineBox->parent() };
}

TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; }
bool isFirstLine() const { return !rootInlineBox().prevRootBox(); }

@@ -212,6 +212,27 @@ class BoxModernPath {
return last;
}

BoxModernPath parentInlineBox() const
{
ASSERT(!atEnd());

auto candidate = *this;

if (isRootInlineBox()) {
candidate.setAtEnd();
return candidate;
}

auto& parentLayoutBox = box().layoutBox().parent();
do {
candidate.traversePreviousBox();
} while (!candidate.atEnd() && &candidate.box().layoutBox() != &parentLayoutBox);

ASSERT(candidate.atEnd() || candidate.box().isInlineBox());

return candidate;
}

TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; }
bool isFirstLine() const { return !box().lineIndex(); }

0 comments on commit 1d07fae

Please sign in to comment.