Skip to content

Commit

Permalink
[IFC][Ruby] Fix base range off-by-one errors
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266154

Reviewed by Antti Koivisto.

Range ends are always exclusive.

* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::applyRubyOverhang):
* Source/WebCore/layout/formattingContexts/inline/ruby/RubyFormattingContext.cpp:
(WebCore::Layout::RubyFormattingContext::applyRubyAlignOnBaseContent):
(WebCore::Layout::RubyFormattingContext::overhangForAnnotationAfter):

Canonical link: https://commits.webkit.org/271838@main
  • Loading branch information
alanbaradlay committed Dec 10, 2023
1 parent ebae091 commit 194305d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ void InlineDisplayContentBuilder::applyRubyOverhang(InlineDisplay::Boxes& displa
if (beforeOverhang)
moveBoxRangeToVisualLeft(rubyBaseStart, displayBoxes.size() - 1, beforeOverhang);
if (afterOverhang)
moveBoxRangeToVisualLeft(startEndPair.end() + 1, displayBoxes.size() - 1, afterOverhang);
moveBoxRangeToVisualLeft(startEndPair.end(), displayBoxes.size() - 1, afterOverhang);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,26 @@ InlineLayoutUnit RubyFormattingContext::baseEndAdditionalLogicalWidth(const Box&
size_t RubyFormattingContext::applyRubyAlignOnBaseContent(size_t rubyBaseStart, Line& line, HashMap<const Box*, InlineLayoutUnit>& alignmentOffsetList, const InlineFormattingContext& inlineFormattingContext)
{
auto& runs = line.runs();
auto& rubyBaseLayoutBox = runs[rubyBaseStart].layoutBox();
auto* annotationBox = rubyBaseLayoutBox.associatedRubyAnnotationBox();
if (!annotationBox)
if (runs.isEmpty()) {
ASSERT_NOT_REACHED();
return rubyBaseStart;

}
auto& rubyBaseLayoutBox = runs[rubyBaseStart].layoutBox();
auto rubyBaseEnd = [&] {
auto& rubyBox = rubyBaseLayoutBox.parent();
for (auto index = rubyBaseStart + 1; index < runs.size(); ++index) {
if (&runs[index].layoutBox().parent() == &rubyBox)
return index;
}
return runs.size();
return runs.size() - 1;
}();
if (rubyBaseEnd == rubyBaseStart + 1) {
if (rubyBaseEnd - rubyBaseStart == 1) {
// Blank base needs no alignment.
return rubyBaseEnd;
}
auto* annotationBox = rubyBaseLayoutBox.associatedRubyAnnotationBox();
if (!annotationBox)
return rubyBaseEnd;

auto annotationBoxLogicalWidth = InlineLayoutUnit { inlineFormattingContext.geometryForBox(*annotationBox).marginBoxWidth() };
auto baseContentLogicalWidth = runs[rubyBaseEnd].logicalLeft() - runs[rubyBaseStart].logicalRight();
Expand Down Expand Up @@ -500,7 +503,7 @@ InlineLayoutUnit RubyFormattingContext::overhangForAnnotationAfter(const Box& ru
overhangingAnnotationRect.move(offset);
baseContentBoxRect.move(offset);

for (size_t index = boxes.size() - 1; index > rubyBaseRange.end(); --index) {
for (size_t index = boxes.size() - 1; index >= rubyBaseRange.end(); --index) {
auto& previousDisplayBox = boxes[index];
if (annotationOverlapCheck(previousDisplayBox, overhangingAnnotationRect, inlineFormattingContext))
return true;
Expand Down

0 comments on commit 194305d

Please sign in to comment.