Skip to content

Commit

Permalink
Backed out 4 changesets (bug 1253840) for causing multiple failures i…
Browse files Browse the repository at this point in the history
…n nsLineLayout.cpp. CLOSED TREE

Backed out changeset 1a47c4ddf44c (bug 1253840)
Backed out changeset 816a9266d111 (bug 1253840)
Backed out changeset 7ce24f83240a (bug 1253840)
Backed out changeset cf6eff426d61 (bug 1253840)
  • Loading branch information
Stanca Serban committed May 19, 2023
1 parent 80bb4b4 commit 403e698
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 383 deletions.
5 changes: 2 additions & 3 deletions gfx/thebes/gfxTextRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ uint32_t gfxTextRun::BreakAndMeasureText(
gfxFloat aWidth, const PropertyProvider& aProvider,
SuppressBreak aSuppressBreak, gfxFont::BoundingBoxType aBoundingBoxType,
DrawTarget* aRefDrawTarget, bool aCanWordWrap, bool aCanWhitespaceWrap,
TrimmableWS* aOutTrimmableWhitespace, Metrics& aOutMetrics,
gfxFloat* aOutTrimmableWhitespace, Metrics& aOutMetrics,
bool& aOutUsedHyphenation, uint32_t& aOutLastBreak,
gfxBreakPriority& aBreakPriority) {
aMaxLength = std::min(aMaxLength, GetLength() - aStart);
Expand Down Expand Up @@ -1174,8 +1174,7 @@ uint32_t gfxTextRun::BreakAndMeasureText(
aRefDrawTarget, &aProvider);

if (aOutTrimmableWhitespace) {
aOutTrimmableWhitespace->mAdvance = trimmableAdvance;
aOutTrimmableWhitespace->mCount = trimmableChars;
*aOutTrimmableWhitespace = trimmableAdvance;
}

if (charsFit == aMaxLength) {
Expand Down
9 changes: 1 addition & 8 deletions gfx/thebes/gfxTextRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ class gfxTextRun : public gfxShapedText {
nsTArray<HyphenType>& aHyphenBuffer,
HyphenationState* aWordState);

// Struct used by BreakAndMeasureText to return the amount of trimmable
// trailing whitespace included in the run.
struct TrimmableWS {
mozilla::gfx::Float mAdvance = 0;
uint32_t mCount = 0;
};

/**
* Finds the longest substring that will fit into the given width.
* Uses GetHyphenationBreaks and GetSpacing from aProvider.
Expand Down Expand Up @@ -462,7 +455,7 @@ class gfxTextRun : public gfxShapedText {
SuppressBreak aSuppressBreak, gfxFont::BoundingBoxType aBoundingBoxType,
DrawTarget* aRefDrawTarget, bool aCanWordWrap, bool aCanWhitespaceWrap,
// Output parameters:
TrimmableWS* aOutTrimmableWhitespace, // may be null
gfxFloat* aOutTrimmableWhitespace, // may be null
Metrics& aOutMetrics, bool& aOutUsedHyphenation, uint32_t& aOutLastBreak,
// In/out:
gfxBreakPriority& aBreakPriority);
Expand Down
55 changes: 3 additions & 52 deletions layout/generic/nsLineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3046,8 +3046,7 @@ void nsLineLayout::ExpandInlineRubyBoxes(PerSpanData* aSpan) {
}
}

nscoord nsLineLayout::GetHangFrom(const PerSpanData* aSpan,
bool aLineIsRTL) const {
nscoord nsLineLayout::GetHangFrom(const PerSpanData* aSpan, bool aLineIsRTL) {
const PerFrameData* pfd = aSpan->mLastFrame;
nscoord result = 0;
while (pfd) {
Expand Down Expand Up @@ -3080,36 +3079,6 @@ nscoord nsLineLayout::GetHangFrom(const PerSpanData* aSpan,
return result;
}

gfxTextRun::TrimmableWS nsLineLayout::GetTrimFrom(const PerSpanData* aSpan,
bool aLineIsRTL) const {
const PerFrameData* pfd = aSpan->mLastFrame;
while (pfd) {
if (const PerSpanData* childSpan = pfd->mSpan) {
return GetTrimFrom(childSpan, aLineIsRTL);
}
if (pfd->mIsTextFrame) {
auto* lastText = static_cast<nsTextFrame*>(pfd->mFrame);
auto result = lastText->GetTrimmableWS();
if (result.mAdvance) {
lastText->EnsureTextRun(nsTextFrame::eInflated);
auto* textRun = lastText->GetTextRun(nsTextFrame::eInflated);
if (textRun && textRun->IsRightToLeft() != aLineIsRTL) {
result.mAdvance = -result.mAdvance;
}
}
return result;
}
if (!pfd->mSkipWhenTrimmingWhitespace) {
// If we hit a frame on the end that's not text and not a placeholder or
// <br>, then there is no trailing whitespace to trim. Stop the search.
return gfxTextRun::TrimmableWS{};
}
// Scan back for a preceding frame whose whitespace we can trim.
pfd = pfd->mPrev;
}
return gfxTextRun::TrimmableWS{};
}

// Align inline frames within the line according to the CSS text-align
// property.
void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {
Expand Down Expand Up @@ -3137,15 +3106,8 @@ void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {

// Check if there's trailing whitespace we need to "hang" at line-wrap.
nscoord hang = 0;
uint32_t trimCount = 0;
if (aLine->IsLineWrapped()) {
if (textAlign == StyleTextAlign::Justify) {
auto trim = GetTrimFrom(mRootSpan, lineWM.IsBidiRTL());
hang = NSToCoordRound(trim.mAdvance);
trimCount = trim.mCount;
} else {
hang = GetHangFrom(mRootSpan, lineWM.IsBidiRTL());
}
hang = GetHangFrom(mRootSpan, lineWM.IsBidiRTL());
}

bool isSVG = LineContainerFrame()->IsInSVGTextSubtree();
Expand Down Expand Up @@ -3182,27 +3144,16 @@ void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {
switch (textAlign) {
case StyleTextAlign::Justify: {
int32_t opportunities =
psd->mFrame->mJustificationInfo.mInnerOpportunities -
(hang ? trimCount : 0);
psd->mFrame->mJustificationInfo.mInnerOpportunities;
if (opportunities > 0) {
int32_t gaps = opportunities * 2 + additionalGaps;
remainingISize += std::abs(hang);
JustificationApplicationState applyState(gaps, remainingISize);

// Apply the justification, and make sure to update our linebox
// width to account for it.
aLine->ExpandBy(ApplyFrameJustification(psd, applyState),
ContainerSizeForSpan(psd));

// If the trimmable trailing whitespace that we want to hang had
// reverse-inline directionality, adjust line position to account for
// it being at the inline-start side.
// On top of the original "hang" amount, justification will have
// modified its width, so we include that adjustment here.
if (hang < 0) {
dx = hang - trimCount * remainingISize / opportunities;
}

MOZ_ASSERT(applyState.mGaps.mHandled == applyState.mGaps.mCount,
"Unprocessed justification gaps");
NS_ASSERTION(
Expand Down
5 changes: 1 addition & 4 deletions layout/generic/nsLineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define nsLineLayout_h___

#include "gfxTypes.h"
#include "gfxTextRun.h"
#include "JustificationUtils.h"
#include "mozilla/ArenaAllocator.h"
#include "mozilla/WritingModes.h"
Expand Down Expand Up @@ -527,9 +526,7 @@ class nsLineLayout {

// Get the advance of any trailing hangable whitespace. If the whitespace
// has directionality opposite to the line, the result is negated.
nscoord GetHangFrom(const PerSpanData* aSpan, bool aLineIsRTL) const;
gfxTextRun::TrimmableWS GetTrimFrom(const PerSpanData* aSpan,
bool aLineIsRTL) const;
nscoord GetHangFrom(const PerSpanData* aSpan, bool aLineIsRTL);

gfxBreakPriority mLastOptionalBreakPriority;
int32_t mLastOptionalBreakFrameOffset;
Expand Down
103 changes: 31 additions & 72 deletions layout/generic/nsTextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ NS_DECLARE_FRAME_PROPERTY_RELEASABLE(UninflatedTextRunProperty, gfxTextRun)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(FontSizeInflationProperty, float)

NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(HangableWhitespaceProperty, nscoord)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(TrimmableWhitespaceProperty,
gfxTextRun::TrimmableWS)

struct nsTextFrame::PaintTextSelectionParams : nsTextFrame::PaintTextParams {
Point textBaselinePt;
Expand Down Expand Up @@ -2231,7 +2229,8 @@ already_AddRefed<gfxTextRun> BuildTextRunsScanner::BuildTextRunForFrames(
flags |= GetSpacingFlags(f);
nsTextFrameUtils::CompressionMode compression =
GetCSSWhitespaceToCompressionMode(f, textStyle);
if ((enabledJustification || f->ShouldSuppressLineBreak()) && !isSVG) {
if ((enabledJustification || f->ShouldSuppressLineBreak()) &&
!textStyle->WhiteSpaceIsSignificant() && !isSVG) {
flags |= gfx::ShapedTextFlags::TEXT_ENABLE_SPACING;
}
fontStyle = f->StyleFont();
Expand Down Expand Up @@ -3890,7 +3889,7 @@ nsTArray<nsTextFrame*>* nsTextFrame::GetContinuations() {
if (!mNextContinuation) {
return nullptr;
}
if (mPropertyFlags & PropertyFlags::Continuations) {
if (mHasContinuationsProperty) {
return GetProperty(ContinuationsProperty());
}
size_t count = 0;
Expand All @@ -3908,7 +3907,7 @@ nsTArray<nsTextFrame*>* nsTextFrame::GetContinuations() {
continuations = nullptr;
}
AddProperty(ContinuationsProperty(), continuations);
mPropertyFlags |= PropertyFlags::Continuations;
mHasContinuationsProperty = true;
return continuations;
}

Expand Down Expand Up @@ -8157,53 +8156,20 @@ void nsTextFrame::SetFontSizeInflation(float aInflation) {
void nsTextFrame::SetHangableISize(nscoord aISize) {
MOZ_ASSERT(aISize >= 0, "unexpected negative hangable advance");
if (aISize <= 0) {
ClearHangableISize();
if (mHasHangableWS) {
RemoveProperty(HangableWhitespaceProperty());
}
mHasHangableWS = false;
return;
}
SetProperty(HangableWhitespaceProperty(), aISize);
mPropertyFlags |= PropertyFlags::HangableWS;
mHasHangableWS = true;
}

nscoord nsTextFrame::GetHangableISize() const {
MOZ_ASSERT(!!(mPropertyFlags & PropertyFlags::HangableWS) ==
HasProperty(HangableWhitespaceProperty()),
MOZ_ASSERT(mHasHangableWS == HasProperty(HangableWhitespaceProperty()),
"flag/property mismatch!");
return (mPropertyFlags & PropertyFlags::HangableWS)
? GetProperty(HangableWhitespaceProperty())
: 0;
}

void nsTextFrame::ClearHangableISize() {
if (mPropertyFlags & PropertyFlags::HangableWS) {
RemoveProperty(HangableWhitespaceProperty());
mPropertyFlags &= ~PropertyFlags::HangableWS;
}
}

void nsTextFrame::SetTrimmableWS(gfxTextRun::TrimmableWS aTrimmableWS) {
MOZ_ASSERT(aTrimmableWS.mAdvance >= 0, "negative trimmable size");
if (aTrimmableWS.mAdvance <= 0) {
ClearTrimmableWS();
return;
}
SetProperty(TrimmableWhitespaceProperty(), aTrimmableWS);
mPropertyFlags |= PropertyFlags::TrimmableWS;
}

gfxTextRun::TrimmableWS nsTextFrame::GetTrimmableWS() const {
MOZ_ASSERT(!!(mPropertyFlags & PropertyFlags::TrimmableWS) ==
HasProperty(TrimmableWhitespaceProperty()),
"flag/property mismatch!");
return (mPropertyFlags & PropertyFlags::TrimmableWS)
? GetProperty(TrimmableWhitespaceProperty())
: gfxTextRun::TrimmableWS{};
}

void nsTextFrame::ClearTrimmableWS() {
if (mPropertyFlags & PropertyFlags::TrimmableWS) {
RemoveProperty(TrimmableWhitespaceProperty());
mPropertyFlags &= ~PropertyFlags::TrimmableWS;
}
return mHasHangableWS ? GetProperty(HangableWhitespaceProperty()) : 0;
}

/* virtual */
Expand Down Expand Up @@ -9202,7 +9168,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
gfxTextRun::Metrics textMetrics;
uint32_t transformedLastBreak = 0;
bool usedHyphenation = false;
gfxTextRun::TrimmableWS trimmableWS;
gfxFloat trimmableWidth = 0;
gfxFloat availWidth = aAvailableWidth;
if (Style()->IsTextCombined()) {
// If text-combine-upright is 'all', we would compress whatever long
Expand All @@ -9227,7 +9193,8 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
availWidth, provider, suppressBreak, boundingBoxType, aDrawTarget,
textStyle->WordCanWrap(this), isBreakSpaces,
// The following are output parameters:
canTrimTrailingWhitespace || whitespaceCanHang ? &trimmableWS : nullptr,
canTrimTrailingWhitespace || whitespaceCanHang ? &trimmableWidth
: nullptr,
textMetrics, usedHyphenation, transformedLastBreak,
// In/out
breakPriority);
Expand Down Expand Up @@ -9288,49 +9255,40 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
}

bool brokeText = forceBreak >= 0 || transformedCharsFit < transformedLength;
if (trimmableWS.mAdvance > 0.0) {
if (trimmableWidth > 0.0) {
if (canTrimTrailingWhitespace) {
// Optimization: if we we can be sure this frame will be at end of line,
// then trim the whitespace now.
if (brokeText || HasAnyStateBits(TEXT_IS_IN_TOKEN_MATHML)) {
// We're definitely going to break so our trailing whitespace should
// definitely be trimmed. Record that we've already done it.
AddStateBits(TEXT_TRIMMED_TRAILING_WHITESPACE);
textMetrics.mAdvanceWidth -= trimmableWS.mAdvance;
trimmableWS.mAdvance = 0.0;
textMetrics.mAdvanceWidth -= trimmableWidth;
trimmableWidth = 0.0;
}
ClearHangableISize();
ClearTrimmableWS();
SetHangableISize(0);
} else if (whitespaceCanHang) {
// Figure out how much whitespace will hang if at end-of-line.
gfxFloat hang =
std::min(std::max(0.0, textMetrics.mAdvanceWidth - availWidth),
gfxFloat(trimmableWS.mAdvance));
SetHangableISize(NSToCoordRound(trimmableWS.mAdvance - hang));
// nsLineLayout only needs the TrimmableWS property if justifying, so
// check whether this is relevant.
if (textStyle->mTextAlign == StyleTextAlign::Justify ||
textStyle->mTextAlignLast == StyleTextAlignLast::Justify) {
SetTrimmableWS(trimmableWS);
}
trimmableWidth);
SetHangableISize(NSToCoordRound(trimmableWidth - hang));
textMetrics.mAdvanceWidth -= hang;
trimmableWS.mAdvance = 0.0;
trimmableWidth = 0.0;
} else {
MOZ_ASSERT_UNREACHABLE("How did trimmableWS get set?!");
ClearHangableISize();
ClearTrimmableWS();
trimmableWS.mAdvance = 0.0;
MOZ_ASSERT_UNREACHABLE("How did trimmableWidth get set?!");
SetHangableISize(0);
trimmableWidth = 0.0;
}
} else {
// Remove any stale frame properties.
ClearHangableISize();
ClearTrimmableWS();
// Remove any stale frame property.
SetHangableISize(0);
}

if (!brokeText && lastBreak >= 0) {
// Since everything fit and no break was forced,
// record the last break opportunity
NS_ASSERTION(textMetrics.mAdvanceWidth - trimmableWS.mAdvance <= availWidth,
NS_ASSERTION(textMetrics.mAdvanceWidth - trimmableWidth <= availWidth,
"If the text doesn't fit, and we have a break opportunity, "
"why didn't MeasureText use it?");
MOZ_ASSERT(lastBreak >= offset, "Strange break position");
Expand Down Expand Up @@ -9458,7 +9416,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
// at most one space so there's no way for trimmable width from a previous
// frame to accumulate with trimmable width from this frame.)
if (transformedCharsFit > 0) {
aLineLayout.SetTrimmableISize(NSToCoordFloor(trimmableWS.mAdvance));
aLineLayout.SetTrimmableISize(NSToCoordFloor(trimmableWidth));
AddStateBits(TEXT_HAS_NONCOLLAPSED_CHARACTERS);
}
bool breakAfter = forceBreakAfter;
Expand Down Expand Up @@ -9486,7 +9444,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
// trailing whitespace. So we need to subtract trimmableWidth here
// because if we did break at this point, that much width would be
// trimmed.
if (textMetrics.mAdvanceWidth - trimmableWS.mAdvance > availWidth) {
if (textMetrics.mAdvanceWidth - trimmableWidth > availWidth) {
breakAfter = true;
} else {
aLineLayout.NotifyOptionalBreakPosition(this, length, true,
Expand Down Expand Up @@ -9541,7 +9499,8 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
}

// Compute space and letter counts for justification, if required
if ((lineContainer->StyleText()->mTextAlign == StyleTextAlign::Justify ||
if (!textStyle->WhiteSpaceIsSignificant() &&
(lineContainer->StyleText()->mTextAlign == StyleTextAlign::Justify ||
lineContainer->StyleText()->mTextAlignLast ==
StyleTextAlignLast::Justify ||
shouldSuppressLineBreak) &&
Expand Down
Loading

0 comments on commit 403e698

Please sign in to comment.