Skip to content

Commit

Permalink
[IFC][Ruby] Add support for flipped vertical annotation overhang
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262849

Reviewed by Antti Koivisto.

* Source/WebCore/layout/formattingContexts/inline/ruby/RubyFormattingContext.cpp:
(WebCore::Layout::RubyFormattingContext::visualRectIncludingBlockDirection const):
(WebCore::Layout::RubyFormattingContext::annotationOverlapCheck const):
* Source/WebCore/layout/formattingContexts/inline/ruby/RubyFormattingContext.h:

Canonical link: https://commits.webkit.org/269058@main
  • Loading branch information
alanbaradlay committed Oct 8, 2023
1 parent cf6d4e0 commit e21786e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,25 @@ InlineLayoutUnit RubyFormattingContext::applyRubyAlign(Line& line, WTF::Range<si
return centerOffset;
}

InlineLayoutRect RubyFormattingContext::visualRectIncludingBlockDirection(const InlineLayoutRect& visualRectIgnoringBlockDirection) const
{
if (!parentFormattingContext().root().style().isFlippedLinesWritingMode())
return visualRectIgnoringBlockDirection;

ASSERT(parentFormattingContext().root().style().isVerticalWritingMode());
auto flippedRect = visualRectIgnoringBlockDirection;
flippedRect.setX(flippedRect.x() - flippedRect.width());
return flippedRect;
}

std::optional<bool> RubyFormattingContext::annotationOverlapCheck(const InlineDisplay::Box& adjacentDisplayBox, const InlineLayoutRect& overhangingRect) const
{
// We are in the middle of a line, should not see any line breaks or ellipsis boxes here.
ASSERT(adjacentDisplayBox.isText() || adjacentDisplayBox.isAtomicInlineLevelBox() || adjacentDisplayBox.isInlineBox() || adjacentDisplayBox.isGenericInlineLevelBox() || adjacentDisplayBox.isWordSeparator());
// Skip empty content like <span></span>
if (adjacentDisplayBox.visualRectIgnoringBlockDirection().isEmpty())
return { };
if (adjacentDisplayBox.inkOverflow().intersects(overhangingRect))
if (visualRectIncludingBlockDirection(adjacentDisplayBox.inkOverflow()).intersects(visualRectIncludingBlockDirection(overhangingRect)))
return true;
auto& adjacentLayoutBox = adjacentDisplayBox.layoutBox();
if (adjacentLayoutBox.isRuby()) {
Expand All @@ -400,7 +411,7 @@ std::optional<bool> RubyFormattingContext::annotationOverlapCheck(const InlineDi
return false;
if (adjacentLayoutBox.isRubyBase() && adjacentLayoutBox.associatedRubyAnnotationBox()) {
auto annotationMarginBoxRect = InlineLayoutRect { BoxGeometry::marginBoxRect(parentFormattingContext().geometryForBox(*adjacentLayoutBox.associatedRubyAnnotationBox())) };
if (annotationMarginBoxRect.intersects(overhangingRect))
if (visualRectIncludingBlockDirection(annotationMarginBoxRect).intersects(visualRectIncludingBlockDirection(overhangingRect)))
return true;
}
return { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RubyFormattingContext {
std::optional<bool> annotationOverlapCheck(const InlineDisplay::Box&, const InlineLayoutRect& overhangingRect) const;
void placeRubyContent(WTF::Range<size_t> candidateRange, const InlineItemList&, Line&);
InlineLayoutUnit logicaWidthForRubyRange(WTF::Range<size_t> candidateRange, const InlineItemList&, InlineLayoutUnit lineContentLogicalRight) const;
InlineLayoutRect visualRectIncludingBlockDirection(const InlineLayoutRect& visualRectIgnoringBlockDirection) const;

const InlineFormattingContext& parentFormattingContext() const { return m_parentFormattingContext; }

Expand Down

0 comments on commit e21786e

Please sign in to comment.