Skip to content

Commit

Permalink
[Legacy line layout removal] Remove text-align support
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271646
rdar://125353160

Reviewed by Alan Baradlay.

* Source/WebCore/rendering/LegacyLineLayout.cpp:
(WebCore::updateLogicalWidthForLeftAlignedBlock): Deleted.
(WebCore::updateLogicalWidthForRightAlignedBlock): Deleted.
(WebCore::updateLogicalWidthForCenterAlignedBlock): Deleted.
(WebCore::LegacyLineLayout::updateLogicalWidthForAlignment): Deleted.
* Source/WebCore/rendering/LegacyLineLayout.h:
* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::adjustPositionedBlock):
(WebCore::RenderBlockFlow::updateStaticInlinePositionForChild):
(WebCore::RenderBlockFlow::staticInlinePositionForOriginalDisplayInline):
(WebCore::RenderBlockFlow::startAlignedOffsetForLine): Deleted.

Rename for clarity.
Move minimal version of the alignment code needed for static positioning here.

* Source/WebCore/rendering/RenderBlockFlow.h:
* Source/WebCore/rendering/line/LineInlineHeaders.h:
(WebCore::setStaticPositions): Deleted.

Canonical link: https://commits.webkit.org/276684@main
  • Loading branch information
anttijk committed Mar 26, 2024
1 parent 1674e8f commit 09ad6a2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 143 deletions.
102 changes: 0 additions & 102 deletions Source/WebCore/rendering/LegacyLineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,108 +288,6 @@ LegacyRootInlineBox* LegacyLineLayout::constructLine(BidiRunList<BidiRun>& bidiR
return lastRootBox();
}

static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
// The direction of the block should determine what happens with wide lines.
// In particular with RTL blocks, wide lines should still spill out to the left.
if (isLeftToRightDirection) {
if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
return;
}

if (trailingSpaceRun)
trailingSpaceRun->box()->setLogicalWidth(0);
else if (totalLogicalWidth > availableLogicalWidth)
logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
}

static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
// Wide lines spill out of the block based off direction.
// So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
// side of the block.
if (isLeftToRightDirection) {
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceRun->box()->setLogicalWidth(0);
}
logicalLeft += std::max(0.f, availableLogicalWidth - totalLogicalWidth);
return;
}

if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
} else
logicalLeft += availableLogicalWidth - totalLogicalWidth;
}

static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
float trailingSpaceWidth = 0;
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
}
if (isLeftToRightDirection)
logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
else
logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
}

void LegacyLineLayout::updateLogicalWidthForAlignment(RenderBlockFlow& flow, const TextAlignMode& textAlign, const LegacyRootInlineBox* rootInlineBox, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
{
TextDirection direction;
if (rootInlineBox && flow.style().unicodeBidi() == UnicodeBidi::Plaintext)
direction = rootInlineBox->direction();
else
direction = flow.style().direction();

bool isLeftToRightDirection = flow.style().isLeftToRightDirection();

// Armed with the total width of the line (without justification),
// we now examine our text-align property in order to determine where to position the
// objects horizontally. The total width of the line can be increased if we end up
// justifying text.
switch (textAlign) {
case TextAlignMode::Left:
case TextAlignMode::WebKitLeft:
updateLogicalWidthForLeftAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case TextAlignMode::Right:
case TextAlignMode::WebKitRight:
updateLogicalWidthForRightAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case TextAlignMode::Center:
case TextAlignMode::WebKitCenter:
updateLogicalWidthForCenterAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case TextAlignMode::Justify:
if (expansionOpportunityCount) {
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceRun->box()->setLogicalWidth(0);
}
break;
}
FALLTHROUGH;
case TextAlignMode::Start:
if (direction == TextDirection::LTR)
updateLogicalWidthForLeftAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
else
updateLogicalWidthForRightAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case TextAlignMode::End:
if (direction == TextDirection::LTR)
updateLogicalWidthForRightAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
else
updateLogicalWidthForLeftAlignedBlock(isLeftToRightDirection, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
}
}

void LegacyLineLayout::removeInlineBox(BidiRun& run, const LegacyRootInlineBox& rootLineBox) const
{
auto* inlineBox = run.box();
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/rendering/LegacyLineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class LegacyLineLayout {
size_t lineCount() const;

static void appendRunsForObject(BidiRunList<BidiRun>*, int start, int end, RenderObject&, InlineBidiResolver&);
static void updateLogicalWidthForAlignment(RenderBlockFlow&, const TextAlignMode&, const LegacyRootInlineBox*, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount);

private:
std::unique_ptr<LegacyRootInlineBox> createRootInlineBox();
Expand Down
44 changes: 23 additions & 21 deletions Source/WebCore/rendering/RenderBlockFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ void RenderBlockFlow::adjustPositionedBlock(RenderBox& child, const MarginInfo&
bool hasStaticBlockPosition = child.style().hasStaticBlockPosition(isHorizontal);

LayoutUnit logicalTop = logicalHeight();
updateStaticInlinePositionForChild(child, logicalTop, DoNotIndentText);
updateStaticInlinePositionForChild(child, logicalTop);

if (!marginInfo.canCollapseWithMarginBefore()) {
// Positioned blocks don't collapse margins, so add the margin provided by
Expand All @@ -1207,7 +1207,7 @@ void RenderBlockFlow::adjustPositionedBlock(RenderBox& child, const MarginInfo&
LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin();
logicalTop += collapsedBeforePos - collapsedBeforeNeg;
}

RenderLayer* childLayer = child.layer();
if (childLayer->staticBlockPosition() != logicalTop) {
childLayer->setStaticBlockPosition(logicalTop);
Expand Down Expand Up @@ -1268,10 +1268,10 @@ void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo)
setLogicalHeight(logicalHeight() - marginOffset);
}

void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop, IndentTextOrNot shouldIndentText)
void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop)
{
if (child.style().isOriginalDisplayInlineType())
setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, shouldIndentText));
setStaticInlinePositionForChild(child, logicalTop, staticInlinePositionForOriginalDisplayInline(logicalTop));
else
setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent(logicalTop));
}
Expand All @@ -1285,36 +1285,38 @@ void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox& child, LayoutUn
child.layer()->setStaticInlinePosition(inlinePosition);
}

LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot shouldIndentText)
LayoutUnit RenderBlockFlow::staticInlinePositionForOriginalDisplayInline(LayoutUnit logicalTop)
{
TextAlignMode textAlign = style().textAlign();
bool shouldApplyIndentText = false;
bool isLeftToRightDirection = style().isLeftToRightDirection();

float logicalLeft = logicalLeftOffsetForLine(logicalTop, DoNotIndentText);
float logicalRight = logicalRightOffsetForLine(logicalTop, DoNotIndentText);

switch (textAlign) {
case TextAlignMode::Left:
case TextAlignMode::WebKitLeft:
shouldApplyIndentText = style().isLeftToRightDirection();
break;
case TextAlignMode::Right:
case TextAlignMode::WebKitRight:
shouldApplyIndentText = !style().isLeftToRightDirection();
logicalLeft = logicalRight;
break;
case TextAlignMode::Center:
case TextAlignMode::WebKitCenter:
logicalLeft += (logicalRight - logicalLeft) / 2;
break;
case TextAlignMode::Justify:
case TextAlignMode::Start:
shouldApplyIndentText = true;
if (!isLeftToRightDirection)
logicalLeft = logicalRight;
break;
case TextAlignMode::End:
if (isLeftToRightDirection)
logicalLeft = logicalRight;
break;
default:
shouldApplyIndentText = false;
}
if (shouldApplyIndentText) // FIXME: Handle TextAlignMode::End here
return startOffsetForLine(position, shouldIndentText);

// updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
float totalLogicalWidth = 0;
float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), DoNotIndentText);
float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), DoNotIndentText) - logicalLeft;

LegacyLineLayout::updateLogicalWidthForAlignment(*this, textAlign, nullptr, nullptr, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);

if (!style().isLeftToRightDirection())
if (!isLeftToRightDirection)
return LayoutUnit(logicalWidth() - logicalLeft);

return LayoutUnit(logicalLeft);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/RenderBlockFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ class RenderBlockFlow : public RenderBlock {
void trimBlockEndChildrenMargins();

void setStaticInlinePositionForChild(RenderBox& child, LayoutUnit blockOffset, LayoutUnit inlinePosition);
void updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop, IndentTextOrNot shouldIndentText);
void updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop);

LayoutUnit startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot);
LayoutUnit staticInlinePositionForOriginalDisplayInline(LayoutUnit logicalTop);

LayoutUnit collapseMargins(RenderBox& child, MarginInfo&);
LayoutUnit collapseMarginsWithChildInfo(RenderBox* child, RenderObject* prevSibling, MarginInfo&);
Expand Down
17 changes: 0 additions & 17 deletions Source/WebCore/rendering/line/LineInlineHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,4 @@ inline bool requiresLineBox(const LegacyInlineIterator& it, const LineInfo& line
return notJustWhitespace || rendererIsEmptyInline;
}

inline void setStaticPositions(RenderBlockFlow& block, RenderBox& child, IndentTextOrNot shouldIndentText)
{
// FIXME: The math here is actually not really right. It's a best-guess approximation that
// will work for the common cases
RenderElement* containerBlock = child.container();
LayoutUnit blockHeight = block.logicalHeight();
if (auto* renderInline = dynamicDowncast<RenderInline>(*containerBlock)) {
// A relative positioned inline encloses us. In this case, we also have to determine our
// position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned
// inline so that we can obtain the value later.
renderInline->layer()->setStaticInlinePosition(block.startAlignedOffsetForLine(blockHeight, DoNotIndentText));
renderInline->layer()->setStaticBlockPosition(blockHeight);
}
block.updateStaticInlinePositionForChild(child, blockHeight, shouldIndentText);
child.layer()->setStaticBlockPosition(blockHeight);
}

} // namespace WebCore

0 comments on commit 09ad6a2

Please sign in to comment.