Skip to content

Commit

Permalink
[Legacy line layout removal] Remove annotations and text combine
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271226
rdar://124999850

Reviewed by Alan Baradlay.

They are not not used anymore.

* Source/WebCore/rendering/LegacyInlineFlowBox.cpp:
(WebCore::LegacyInlineFlowBox::addToLine):
(WebCore::LegacyInlineFlowBox::adjustPosition):
(WebCore::LegacyInlineFlowBox::computeOverAnnotationAdjustment const): Deleted.
(WebCore::LegacyInlineFlowBox::computeUnderAnnotationAdjustment const): Deleted.
* Source/WebCore/rendering/LegacyInlineFlowBox.h:
(WebCore::LegacyInlineFlowBox::LegacyInlineFlowBox):
(WebCore::LegacyInlineFlowBox::hasTextDescendants const):
(WebCore::LegacyInlineFlowBox::logicalFrameRectIncludingLineHeight const):
(WebCore::LegacyInlineFlowBox::hasHardLinebreak const): Deleted.
(WebCore::LegacyInlineFlowBox::descendantsHaveSameLineHeightAndBaseline const): Deleted.
(WebCore::LegacyInlineFlowBox::clearDescendantsHaveSameLineHeightAndBaseline): Deleted.

Also remove descendantsHaveSameLineHeightAndBaseline bit which no one is using.

* Source/WebCore/rendering/LegacyLineLayout.cpp:
(WebCore::LegacyLineLayout::createLineBoxes):
(WebCore::LegacyLineLayout::layoutLineBoxes):
* Source/WebCore/rendering/LegacyRootInlineBox.cpp:
(WebCore::LegacyRootInlineBox::selectionTop const):
(WebCore::LegacyRootInlineBox::selectionBottom const):
* Source/WebCore/rendering/line/BreakingContext.h:
(WebCore::textWidth):
(WebCore::BreakingContext::handleText):
(WebCore::iteratorIsBeyondEndOfRenderCombineText): Deleted.
* Source/WebCore/rendering/line/LineBreaker.cpp:
(WebCore::LineBreaker::skipLeadingWhitespace):

Canonical link: https://commits.webkit.org/276347@main
  • Loading branch information
anttijk committed Mar 19, 2024
1 parent c1017d3 commit 6b47b20
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ class BoxLegacyPath {

TextBoxSelectableRange selectableRange() const { return inlineTextBox()->selectableRange(); }

TextRun textRun(TextRunMode mode = TextRunMode::Painting) const
TextRun textRun(TextRunMode = TextRunMode::Painting) const
{
bool ignoreCombinedText = mode == TextRunMode::Editing;
if (isText())
return inlineTextBox()->createTextRun(ignoreCombinedText);
return inlineTextBox()->createTextRun();
ASSERT_NOT_REACHED();
return TextRun { emptyString() };
}
Expand Down
77 changes: 1 addition & 76 deletions Source/WebCore/rendering/LegacyInlineFlowBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,6 @@ void LegacyInlineFlowBox::addToLine(LegacyInlineBox* child)
if (blockFlow->hasTextDescendants())
setHasTextDescendantsOnAncestors(this);
}
if (descendantsHaveSameLineHeightAndBaseline()) {
const RenderStyle& parentStyle = lineStyle();
const RenderStyle& childStyle = child->lineStyle();
bool shouldClearDescendantsHaveSameLineHeightAndBaseline = false;
if (child->isInlineTextBox()) {
if (child->renderer().parent() != &renderer()) {
if (!parentStyle.fontCascade().metricsOfPrimaryFont().hasIdenticalAscentDescentAndLineGap(childStyle.fontCascade().metricsOfPrimaryFont())
|| parentStyle.lineHeight() != childStyle.lineHeight()
|| (parentStyle.verticalAlign() != VerticalAlign::Baseline && !isRootInlineBox()) || childStyle.verticalAlign() != VerticalAlign::Baseline)
shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
}
if (childStyle.hasTextCombine() || childStyle.textEmphasisMark() != TextEmphasisMark::None)
shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
} else {
auto& childFlowBox = downcast<LegacyInlineFlowBox>(*child);
// Check the child's bit, and then also check for differences in font, line-height, vertical-align
if (!childFlowBox.descendantsHaveSameLineHeightAndBaseline()
|| !parentStyle.fontCascade().metricsOfPrimaryFont().hasIdenticalAscentDescentAndLineGap(childStyle.fontCascade().metricsOfPrimaryFont())
|| parentStyle.lineHeight() != childStyle.lineHeight()
|| (parentStyle.verticalAlign() != VerticalAlign::Baseline && !isRootInlineBox()) || childStyle.verticalAlign() != VerticalAlign::Baseline
|| childStyle.hasBorder() || childStyle.hasPadding() || childStyle.hasTextCombine())
shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
}

if (shouldClearDescendantsHaveSameLineHeightAndBaseline)
clearDescendantsHaveSameLineHeightAndBaseline();
}

const RenderStyle& childStyle = child->lineStyle();
if (child->isInlineTextBox()) {
Expand Down Expand Up @@ -247,7 +220,7 @@ void LegacyInlineFlowBox::adjustPosition(float dx, float dy)
for (auto* child = firstChild(); child; child = child->nextOnLine())
child->adjustPosition(dx, dy);
if (m_overflow)
m_overflow->move(LayoutUnit(dx), LayoutUnit(dy)); // FIXME: Rounding error here since overflow was pixel snapped, but nobody other than list markers passes non-integral values here.
m_overflow->move(LayoutUnit(dx), LayoutUnit(dy));
}

inline void LegacyInlineFlowBox::addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow)
Expand Down Expand Up @@ -576,54 +549,6 @@ RenderObject::HighlightState LegacyInlineFlowBox::selectionState() const
return RenderObject::HighlightState::None;
}

LayoutUnit LegacyInlineFlowBox::computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const
{
LayoutUnit result;
for (auto* child = firstChild(); child; child = child->nextOnLine()) {
if (auto* flowBox = dynamicDowncast<LegacyInlineFlowBox>(*child))
result = std::max(result, flowBox->computeOverAnnotationAdjustment(allowedPosition));

if (auto* textBox = dynamicDowncast<LegacyInlineTextBox>(*child)) {
const RenderStyle& childLineStyle = child->lineStyle();
auto markExistsAndIsAbove = RenderText::emphasisMarkExistsAndIsAbove(textBox->renderer(), childLineStyle);
if (markExistsAndIsAbove && *markExistsAndIsAbove) {
if (!childLineStyle.isFlippedLinesWritingMode()) {
int topOfEmphasisMark = child->logicalTop() - childLineStyle.fontCascade().emphasisMarkHeight(childLineStyle.textEmphasisMarkString());
result = std::max(result, allowedPosition - topOfEmphasisMark);
} else {
int bottomOfEmphasisMark = child->logicalBottom() + childLineStyle.fontCascade().emphasisMarkHeight(childLineStyle.textEmphasisMarkString());
result = std::max(result, bottomOfEmphasisMark - allowedPosition);
}
}
}
}
return result;
}

LayoutUnit LegacyInlineFlowBox::computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const
{
LayoutUnit result;
for (auto* child = firstChild(); child; child = child->nextOnLine()) {
if (auto* flowBox = dynamicDowncast<LegacyInlineFlowBox>(*child))
result = std::max(result, flowBox->computeUnderAnnotationAdjustment(allowedPosition));

if (auto* textBox = dynamicDowncast<LegacyInlineTextBox>(*child)) {
const RenderStyle& childLineStyle = child->lineStyle();
auto markExistsAndIsAbove = RenderText::emphasisMarkExistsAndIsAbove(textBox->renderer(), childLineStyle);
if (markExistsAndIsAbove && !*markExistsAndIsAbove) {
if (!childLineStyle.isFlippedLinesWritingMode()) {
LayoutUnit bottomOfEmphasisMark { child->logicalBottom() + childLineStyle.fontCascade().emphasisMarkHeight(childLineStyle.textEmphasisMarkString()) };
result = std::max(result, bottomOfEmphasisMark - allowedPosition);
} else {
LayoutUnit topOfEmphasisMark { child->logicalTop() - childLineStyle.fontCascade().emphasisMarkHeight(childLineStyle.textEmphasisMarkString()) };
result = std::max(result, allowedPosition - topOfEmphasisMark);
}
}
}
}
return result;
}

#if ENABLE(TREE_DEBUGGING)

const char* LegacyInlineFlowBox::boxName() const
Expand Down
58 changes: 10 additions & 48 deletions Source/WebCore/rendering/LegacyInlineFlowBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,7 @@ class LegacyInlineFlowBox : public LegacyInlineBox {
public:
explicit LegacyInlineFlowBox(RenderBoxModelObject& renderer)
: LegacyInlineBox(renderer)
, m_hasHardLinebreak(false)
, m_descendantsHaveSameLineHeightAndBaseline(true)
, m_baselineType(AlphabeticBaseline)
, m_hasAnnotationsBefore(false)
, m_hasAnnotationsAfter(false)
, m_hasSelfPaintInlineBox(false)
#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
, m_hasBadChildList(false)
#endif
, m_firstChild(nullptr)
, m_lastChild(nullptr)
, m_prevLineBox(nullptr)
, m_nextLineBox(nullptr)
{
// Internet Explorer and Firefox always create a marker for list items, even when the list-style-type is none. We do not make a marker
// in the list-style-type: none case, since it is wasteful to do so. However, in order to match other browsers we have to pretend like
// an invisible marker exists. The side effect of having an invisible marker is that the quirks mode behavior of shrinking lines with no
// text children must not apply. This change also means that gaps will exist between image bullet list items. Even when the list bullet
// is an image, the line is still considered to be immune from the quirk.
m_hasTextChildren = renderer.style().display() == DisplayType::ListItem;
m_hasTextDescendants = m_hasTextChildren;
}

#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
Expand Down Expand Up @@ -125,9 +105,6 @@ class LegacyInlineFlowBox : public LegacyInlineBox {
inline float paddingLogicalLeft() const;
inline float paddingLogicalRight() const;

LayoutUnit computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const;
LayoutUnit computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const;

void computeOverflow(LayoutUnit lineTop, LayoutUnit lineBottom, GlyphOverflowAndFallbackFontsMap&);

void removeChild(LegacyInlineBox* child);
Expand All @@ -136,7 +113,6 @@ class LegacyInlineFlowBox : public LegacyInlineBox {

bool hasTextChildren() const { return m_hasTextChildren; }
bool hasTextDescendants() const { return m_hasTextDescendants; }
bool hasHardLinebreak() const { return m_hasHardLinebreak; }
void setHasTextChildren() { m_hasTextChildren = true; setHasTextDescendants(); }
void setHasTextDescendants() { m_hasTextDescendants = true; }

Expand Down Expand Up @@ -211,14 +187,6 @@ class LegacyInlineFlowBox : public LegacyInlineBox {
{
return FloatRect(logicalLeft(), lineTop, logicalWidth(), lineBottom - lineTop);
}

bool descendantsHaveSameLineHeightAndBaseline() const { return m_descendantsHaveSameLineHeightAndBaseline; }
void clearDescendantsHaveSameLineHeightAndBaseline()
{
m_descendantsHaveSameLineHeightAndBaseline = false;
if (parent() && parent()->descendantsHaveSameLineHeightAndBaseline())
parent()->clearDescendantsHaveSameLineHeightAndBaseline();
}

bool hasSelfPaintInlineBox() const { return m_hasSelfPaintInlineBox; }

Expand All @@ -233,42 +201,36 @@ class LegacyInlineFlowBox : public LegacyInlineBox {
void addReplacedChildOverflow(const LegacyInlineBox*, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow);

private:
unsigned m_hasTextChildren : 1;
unsigned m_hasTextDescendants : 1;
unsigned m_hasHardLinebreak : 1;
unsigned m_descendantsHaveSameLineHeightAndBaseline : 1;
unsigned m_hasTextChildren : 1 { false };
unsigned m_hasTextDescendants : 1 { false };

protected:
// The following members are only used by RootInlineBox but moved here to keep the bits packed.

// Whether or not this line uses alphabetic or ideographic baselines by default.
unsigned m_baselineType : 1; // FontBaseline

// If the line contains any ruby runs, then this will be true.
unsigned m_hasAnnotationsBefore : 1;
unsigned m_hasAnnotationsAfter : 1;
unsigned m_baselineType : 1 { AlphabeticBaseline }; // FontBaseline

unsigned m_lineBreakBidiStatusEor : 5; // UCharDirection
unsigned m_lineBreakBidiStatusLastStrong : 5; // UCharDirection
unsigned m_lineBreakBidiStatusLast : 5; // UCharDirection

unsigned m_hasSelfPaintInlineBox : 1;
unsigned m_hasSelfPaintInlineBox : 1 { false };

// End of RootInlineBox-specific members.

#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
private:
unsigned m_hasBadChildList : 1;
unsigned m_hasBadChildList : 1 { false };
#endif

protected:
RefPtr<RenderOverflow> m_overflow;

LegacyInlineBox* m_firstChild;
LegacyInlineBox* m_lastChild;
LegacyInlineFlowBox* m_prevLineBox; // The previous box that also uses our RenderObject
LegacyInlineFlowBox* m_nextLineBox; // The next box that also uses our RenderObject
LegacyInlineBox* m_firstChild { nullptr };
LegacyInlineBox* m_lastChild { nullptr };

LegacyInlineFlowBox* m_prevLineBox { nullptr }; // The previous box that also uses our RenderObject
LegacyInlineFlowBox* m_nextLineBox { nullptr }; // The next box that also uses our RenderObject
};

#ifdef NDEBUG
Expand Down
40 changes: 6 additions & 34 deletions Source/WebCore/rendering/LegacyInlineTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ LegacyInlineTextBox::~LegacyInlineTextBox()

bool LegacyInlineTextBox::hasTextContent() const
{
if (m_len > 1)
return true;
if (auto* combinedText = this->combinedText()) {
ASSERT(m_len == 1);
return !combinedText->combinedStringForRendering().isEmpty();
}
return m_len;
}

Expand Down Expand Up @@ -161,7 +155,7 @@ RenderObject::HighlightState LegacyInlineTextBox::selectionState() const

const FontCascade& LegacyInlineTextBox::lineFont() const
{
return combinedText() ? combinedText()->textCombineFont() : lineStyle().fontCascade();
return lineStyle().fontCascade();
}

LayoutRect snappedSelectionRect(const LayoutRect& selectionRect, float logicalRight, float selectionTop, float selectionHeight, bool isHorizontal)
Expand Down Expand Up @@ -283,16 +277,10 @@ TextBoxSelectableRange LegacyInlineTextBox::selectableRange() const
{
// Fix up the offset if we are combined text because we manage these embellishments.
// That is, they are not reflected in renderer().text(). We treat combined text as a single unit.
auto additionalLengthAtEnd = [&] {
if (auto* combinedText = this->combinedText())
return combinedText->combinedStringForRendering().length() - m_len;
return 0u;
}();

return {
m_start,
m_len,
additionalLengthAtEnd,
0u,
isLineBreak()
};
}
Expand Down Expand Up @@ -326,39 +314,23 @@ float LegacyInlineTextBox::textPos() const
return logicalLeft() - root().logicalLeft();
}

TextRun LegacyInlineTextBox::createTextRun(bool ignoreCombinedText) const
TextRun LegacyInlineTextBox::createTextRun() const
{
const auto& style = lineStyle();
TextRun textRun { text(ignoreCombinedText), textPos(), 0, ExpansionBehavior::forbidAll(), direction(), style.rtlOrdering() == Order::Visual, !renderer().canUseSimpleFontCodePath() };
TextRun textRun { text(), textPos(), 0, ExpansionBehavior::forbidAll(), direction(), style.rtlOrdering() == Order::Visual, !renderer().canUseSimpleFontCodePath() };
textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
return textRun;
}

String LegacyInlineTextBox::text(bool ignoreCombinedText) const
String LegacyInlineTextBox::text() const
{
String result;
if (auto* combinedText = this->combinedText()) {
if (ignoreCombinedText)
result = renderer().text().substring(m_start, m_len);
else
result = combinedText->combinedStringForRendering();
} else
result = renderer().text().substring(m_start, m_len);
String result = renderer().text().substring(m_start, m_len);

// This works because this replacement doesn't affect string indices. We're replacing a single Unicode code unit with another Unicode code unit.
// How convenient.
return RenderBlock::updateSecurityDiscCharacters(lineStyle(), WTFMove(result));
}

const RenderCombineText* LegacyInlineTextBox::combinedText() const
{
if (!lineStyle().hasTextCombine())
return nullptr;

auto* renderCombineText = dynamicDowncast<RenderCombineText>(renderer());
return renderCombineText && renderCombineText->isCombined() ? renderCombineText : nullptr;
}

#if ENABLE(TREE_DEBUGGING)

const char* LegacyInlineTextBox::boxName() const
Expand Down
13 changes: 2 additions & 11 deletions Source/WebCore/rendering/LegacyInlineTextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

namespace WebCore {

class RenderCombineText;

namespace InlineIterator {
class BoxLegacyPath;
}
Expand All @@ -56,12 +54,6 @@ class LegacyInlineTextBox : public LegacyInlineBox {

bool hasTextContent() const;

// These functions do not account for combined text. For combined text this box will always have len() == 1
// regardless of whether the resulting composition is the empty string. Use hasTextContent() if you want to
// know whether this box has text content.
//
// FIXME: These accessors should ASSERT(!isDirty()). See https://bugs.webkit.org/show_bug.cgi?id=97264
// Note len() == 1 for combined text regardless of whether the composition is empty. Use hasTextContent() to
unsigned start() const { return m_start; }
unsigned end() const { return m_start + m_len; }
unsigned len() const { return m_len; }
Expand Down Expand Up @@ -136,11 +128,10 @@ class LegacyInlineTextBox : public LegacyInlineBox {
private:
friend class InlineIterator::BoxLegacyPath;

const RenderCombineText* combinedText() const;
const FontCascade& lineFont() const;

String text(bool ignoreCombinedText = false) const; // The effective text for the run.
TextRun createTextRun(bool ignoreCombinedText = false) const;
String text() const; // The effective text for the run.
TextRun createTextRun() const;

LegacyInlineTextBox* m_prevTextBox { nullptr }; // The previous box that also uses our RenderObject
LegacyInlineTextBox* m_nextTextBox { nullptr }; // The next box that also uses our RenderObject
Expand Down
15 changes: 1 addition & 14 deletions Source/WebCore/rendering/LegacyLineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ LegacyInlineFlowBox* LegacyLineLayout::createLineBoxes(RenderObject* obj, const
unsigned lineDepth = 1;
LegacyInlineFlowBox* parentBox = nullptr;
LegacyInlineFlowBox* result = nullptr;
bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
do {
RenderInline* inlineFlow = obj != &m_flow ? &checkedDowncast<RenderInline>(*obj) : nullptr;

Expand All @@ -217,8 +216,6 @@ LegacyInlineFlowBox* LegacyLineLayout::createLineBoxes(RenderObject* obj, const
parentBox = downcast<LegacyInlineFlowBox>(newBox);
parentBox->setIsFirstLine(lineInfo.isFirstLine());
parentBox->setIsHorizontal(m_flow.isHorizontalWritingMode());
if (!hasDefaultLineBoxContain)
parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
constructedNewBox = true;
}

Expand Down Expand Up @@ -864,21 +861,11 @@ void LegacyLineLayout::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repain
layoutRunsAndFloats(layoutState, hasInlineChild);
}

// Expand the last line to accommodate Ruby and emphasis marks.
int lastLineAnnotationsAdjustment = 0;
if (lastRootBox()) {
LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), m_flow.logicalHeight() + m_flow.paddingAfter());
if (!style().isFlippedLinesWritingMode())
lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
else
lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
}

// Now do the handling of the bottom of the block, adding in our bottom border/padding and
// determining the correct collapsed bottom margin information. This collapse is only necessary
// if our last child was an anonymous inline block that might need to propagate margin information out to
// us.
LayoutUnit afterEdge = m_flow.borderAndPaddingAfter() + m_flow.scrollbarLogicalHeight() + lastLineAnnotationsAdjustment;
LayoutUnit afterEdge = m_flow.borderAndPaddingAfter() + m_flow.scrollbarLogicalHeight();
m_flow.setLogicalHeight(m_flow.logicalHeight() + afterEdge);

if (!firstRootBox() && m_flow.hasLineIfEmpty())
Expand Down
Loading

0 comments on commit 6b47b20

Please sign in to comment.