Skip to content

Commit

Permalink
[IFC][Ruby] Remove redundant ruby code (RubyFormattingContext)
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265773

Reviewed by Antti Koivisto.

* Source/WebCore/layout/formattingContexts/inline/ruby/RubyFormattingContext.cpp:
(WebCore::Layout::nextWrapOpportunityWithinRubyContainer): Deleted.
(WebCore::Layout::RubyFormattingContext::layoutInlineAxis): Deleted.
(WebCore::Layout::RubyFormattingContext::placeRubyContent): Deleted.
(WebCore::Layout::RubyFormattingContext::layoutRubyBaseInlineAxis): Deleted.
(WebCore::Layout::RubyFormattingContext::nextWrapOpportunity): Deleted.
(WebCore::Layout::RubyFormattingContext::logicaWidthForRubyRange const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/ruby/RubyFormattingContext.h:
(): Deleted.

Canonical link: https://commits.webkit.org/271548@main
  • Loading branch information
alanbaradlay committed Dec 5, 2023
1 parent a5a8f71 commit b6802ce
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@
namespace WebCore {
namespace Layout {

static inline size_t nextWrapOpportunityWithinRubyContainer(size_t startIndex, const InlineItemRange& rubyRange, const InlineItemList& inlineItemList)
{
// We only allow wrap opportunity between ruby bases.
for (size_t index = startIndex; index < rubyRange.endIndex(); ++index) {
auto& rubyItem = inlineItemList[index];
if (rubyItem.isInlineBoxEnd() && rubyItem.layoutBox().isRubyBase()) {
// We are at the end of a ruby base, need to check if we are between bases.
if (index + 1 == rubyRange.endIndex()) {
ASSERT_NOT_REACHED();
continue;
}
auto& nextRubyItem = inlineItemList[index + 1];
if (nextRubyItem.isInlineBoxStart()) {
ASSERT(nextRubyItem.layoutBox().isRubyBase());
return index + 1;
}
}
}
return rubyRange.endIndex();
}

static bool isInterlinearAnnotation(const Box* annotationBox)
{
return annotationBox && annotationBox->isInterlinearRubyAnnotationBox();
Expand Down Expand Up @@ -209,90 +188,6 @@ void RubyFormattingContext::applyRubyAlign(Line& line, const InlineFormattingCon
}
}

RubyFormattingContext::InlineLayoutResult RubyFormattingContext::layoutInlineAxis(const InlineItemRange& rubyRange, const InlineItemList& inlineItemList, Line& line, InlineLayoutUnit availableWidth)
{
ASSERT(!rubyRange.isEmpty());
// Ruby container inline item list is as follows:
// [ruby container start][ruby base start][ruby base content][ruby base end][...][ruby container end]
auto currentIndex = rubyRange.startIndex();
while (currentIndex < rubyRange.endIndex()) {
auto candidateContentEnd = nextWrapOpportunityWithinRubyContainer(currentIndex, rubyRange, inlineItemList);
auto contentLogicalWidth = logicaWidthForRubyRange({ currentIndex, candidateContentEnd }, inlineItemList, line.contentLogicalRight());
auto shouldPlaceRubyRange = contentLogicalWidth <= availableWidth || !line.hasContent();
if (!shouldPlaceRubyRange)
return { InlineContentBreaker::IsEndOfLine::Yes, currentIndex - rubyRange.startIndex() };
placeRubyContent({ currentIndex, candidateContentEnd }, inlineItemList, line);
availableWidth -= contentLogicalWidth;
currentIndex = candidateContentEnd;
}
return { availableWidth >= 0 ? InlineContentBreaker::IsEndOfLine::No : InlineContentBreaker::IsEndOfLine::Yes, currentIndex - rubyRange.startIndex() };
}

void RubyFormattingContext::placeRubyContent(WTF::Range<size_t> candidateRange, const InlineItemList& inlineItemList, Line& line)
{
ASSERT(candidateRange.end() <= inlineItemList.size());
ASSERT(inlineItemList[candidateRange.begin()].layoutBox().isRuby() || inlineItemList[candidateRange.begin()].layoutBox().isRubyBase());
auto& formattingUtils = parentFormattingContext().formattingUtils();

auto index = candidateRange.begin();
auto logicalRightSpacingForBase = InlineLayoutUnit { };
while (index < candidateRange.end()) {
auto appendInlineLevelItem = [&](auto& inlineBoxItem, InlineLayoutUnit extraSpacingEnd = { }) {
ASSERT(inlineBoxItem.layoutBox().isRuby() || inlineBoxItem.layoutBox().isRubyBase() || inlineBoxItem.layoutBox().isRubyAnnotationBox());

auto logicalWidth = formattingUtils.inlineItemWidth(inlineBoxItem, line.contentLogicalRight(), { });
line.append(inlineBoxItem, inlineBoxItem.style(), logicalWidth + extraSpacingEnd);
++index;
};

auto& rubyItem = inlineItemList[index];
auto& rubyLayoutBox = rubyItem.layoutBox();
ASSERT(rubyItem.isInlineBoxStart() || rubyItem.isInlineBoxEnd() || rubyLayoutBox.isRubyAnnotationBox());

if (rubyLayoutBox.isRuby()) {
appendInlineLevelItem(rubyItem);
ASSERT(rubyItem.isInlineBoxStart() || (rubyItem.isInlineBoxEnd() && index == candidateRange.end()));
continue;
}
if (rubyLayoutBox.isRubyBase()) {
// ruby column: represented by a single ruby base and one ruby annotation
// from each interlinear annotation level in its ruby segment.
if (rubyItem.isInlineBoxStart()) {
appendInlineLevelItem(rubyItem);
auto baseLayoutResult = layoutRubyBaseInlineAxis(line, rubyLayoutBox, index, inlineItemList);
index += baseLayoutResult.committedCount;
logicalRightSpacingForBase = baseLayoutResult.logicalRightSpacing;
continue;
}
ASSERT(rubyItem.isInlineBoxEnd());
appendInlineLevelItem(rubyItem, logicalRightSpacingForBase);
continue;
}
ASSERT_NOT_REACHED();
++index;
}
}

RubyFormattingContext::BaseLayoutResult RubyFormattingContext::layoutRubyBaseInlineAxis(Line& line, const Box& rubyBaseLayoutBox, size_t rubyBaseContentStartIndex, const InlineItemList& inlineItemList)
{
// Append ruby base content (including start/end inline box) to the line and apply "ruby-align: space-around" on the ruby subrange.
auto& formattingUtils = parentFormattingContext().formattingUtils();
auto baseRunStart = line.runs().size();

auto index = rubyBaseContentStartIndex;
while (index < inlineItemList.size() && &inlineItemList[index].layoutBox() != &rubyBaseLayoutBox) {
auto& rubyBaseContentItem = inlineItemList[index++];
auto logicalWidth = !rubyBaseContentItem.isOpaque() ? formattingUtils.inlineItemWidth(rubyBaseContentItem, line.contentLogicalRight(), { }) : InlineLayoutUnit();
line.append(rubyBaseContentItem, rubyBaseContentItem.style(), logicalWidth);
}
ASSERT(index < inlineItemList.size());
auto logicalRightSpacing = InlineLayoutUnit { };
auto baseRunCount = line.runs().size() - baseRunStart;
if (baseRunCount)
applyRubyAlign(line, parentFormattingContext());
return { index - rubyBaseContentStartIndex, logicalRightSpacing };
}

InlineLayoutPoint RubyFormattingContext::placeAnnotationBox(const Box& rubyBaseLayoutBox)
{
ASSERT(rubyBaseLayoutBox.isRubyBase());
Expand Down Expand Up @@ -507,27 +402,6 @@ InlineLayoutUnit RubyFormattingContext::overhangForAnnotationAfter(const Box& ru
return wouldAnnotationOrBaseOverlapLineContent() ? 0.f : overhangValue;
}

std::optional<size_t> RubyFormattingContext::nextWrapOpportunity(size_t inlineItemIndex, std::optional<size_t> previousInlineItemIndex, const InlineItemRange& layoutRange, const InlineItemList& inlineItemList)
{
auto& inlineItem = inlineItemList[inlineItemIndex];
ASSERT(inlineItem.isInlineBoxStart() || inlineItem.isInlineBoxEnd());

auto& layoutBox = inlineItem.layoutBox();
auto startsWithRubyInlineBox = layoutBox.isRuby() || layoutBox.isRubyBase();
if (!startsWithRubyInlineBox) {
// This is not ruby content.
return { };
}
if (previousInlineItemIndex && startsWithRubyInlineBox) {
// There's always a soft wrap opportunitiy before <ruby>/ruby base.
return inlineItemIndex;
}
// Skip to the end of the ruby container.
for (; inlineItemIndex < layoutRange.endIndex() && (!inlineItemList[inlineItemIndex].isInlineBoxEnd() || !inlineItemList[inlineItemIndex].layoutBox().isRuby()); ++inlineItemIndex) { }
ASSERT(inlineItemIndex < layoutRange.endIndex());
return inlineItemIndex + 1;
}

InlineLayoutRect RubyFormattingContext::visualRectIncludingBlockDirection(const InlineLayoutRect& visualRectIgnoringBlockDirection) const
{
auto& rootStyle = parentFormattingContext().root().style();
Expand Down Expand Up @@ -558,57 +432,6 @@ bool RubyFormattingContext::annotationOverlapCheck(const InlineDisplay::Box& adj
return false;
}

InlineLayoutUnit RubyFormattingContext::logicaWidthForRubyRange(WTF::Range<size_t> candidateRange, const InlineItemList& inlineItemList, InlineLayoutUnit lineContentLogicalRight) const
{
ASSERT(candidateRange.end() <= inlineItemList.size());
ASSERT(inlineItemList[candidateRange.begin()].layoutBox().isRuby() || inlineItemList[candidateRange.begin()].layoutBox().isRubyBase());

auto& formattingUtils = parentFormattingContext().formattingUtils();
auto candidateContentLogicalWidth = InlineLayoutUnit { };
auto index = candidateRange.begin();

while (index < candidateRange.end()) {
auto& rubyItem = inlineItemList[index];
auto& rubyLayoutBox = rubyItem.layoutBox();

if (rubyLayoutBox.isRuby()) {
ASSERT(rubyItem.isInlineBoxStart() || rubyItem.isInlineBoxEnd());
candidateContentLogicalWidth += formattingUtils.inlineItemWidth(rubyItem, lineContentLogicalRight + candidateContentLogicalWidth, { });
++index;
continue;
}

if (rubyLayoutBox.isRubyBase()) {
ASSERT(rubyItem.isInlineBoxStart());

auto baseLogicalWidth = [&] {
// Base content needs special handling with taking annotation box into account.
auto logicalWidth = InlineLayoutUnit { };
for (; index < candidateRange.end(); ++index) {
auto& baseInlineItem = inlineItemList[index];
logicalWidth += !baseInlineItem.isOpaque() ? formattingUtils.inlineItemWidth(baseInlineItem, lineContentLogicalRight + logicalWidth, { }) : InlineLayoutUnit();
if (&baseInlineItem.layoutBox() == &rubyLayoutBox && baseInlineItem.isInlineBoxEnd()) {
// End of base.
++index;
return logicalWidth;
}
}
ASSERT_NOT_REACHED();
return InlineLayoutUnit { };
};
if (auto* annotationBox = rubyLayoutBox.associatedRubyAnnotationBox()) {
auto annotationMarginBoxWidth = InlineLayoutUnit { parentFormattingContext().geometryForBox(*annotationBox).marginBoxWidth() };
candidateContentLogicalWidth += isInterlinearAnnotation(annotationBox) ? std::max(baseLogicalWidth(), annotationMarginBoxWidth) : (baseLogicalWidth() + annotationMarginBoxWidth);
} else
candidateContentLogicalWidth += baseLogicalWidth();
continue;
}
ASSERT_NOT_REACHED();
++index;
}
return candidateContentLogicalWidth;
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class RubyFormattingContext {
public:
RubyFormattingContext(const InlineFormattingContext& parentFormattingContext);

struct InlineLayoutResult {
InlineContentBreaker::IsEndOfLine isEndOfLine { InlineContentBreaker::IsEndOfLine::No };
size_t committedCount { 0 };
};
InlineLayoutResult layoutInlineAxis(const InlineItemRange&, const InlineItemList&, Line&, InlineLayoutUnit availableWidth);

void applyAnnotationContributionToLayoutBounds(InlineLevelBox& rubyBaseInlineBox) const;
InlineLayoutPoint placeAnnotationBox(const Box& rubyBaseLayoutBox);
InlineLayoutSize sizeAnnotationBox(const Box& rubyBaseLayoutBox);
Expand All @@ -62,14 +56,7 @@ class RubyFormattingContext {
static void applyRubyAlign(Line&, const InlineFormattingContext&);

private:
struct BaseLayoutResult {
size_t committedCount { 0 };
InlineLayoutUnit logicalRightSpacing { 0.f };
};
BaseLayoutResult layoutRubyBaseInlineAxis(Line&, const Box& rubyBaseLayoutBox, size_t rubyBaseContentStart, const InlineItemList&);
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 b6802ce

Please sign in to comment.