ported from UXP: Issue #1673 - Part 3: Bring minimum tab advance up to spec. (a64dc2a3)

This commit is contained in:
2022-04-18 13:34:58 +08:00
parent 50e66e9867
commit 75f9d9728b
+30 -9
View File
@@ -1720,6 +1720,16 @@ GetSpaceWidthAppUnits(const gfxTextRun* aTextRun)
return spaceWidthAppUnits;
}
static gfxFloat
GetMinTabAdvanceAppUnits(const gfxTextRun* aTextRun)
{
gfxFloat chWidthAppUnits =
NS_round(GetFirstFontMetrics(aTextRun->GetFontGroup(),
aTextRun->IsVertical()).zeroOrAveCharWidth *
aTextRun->GetAppUnitsPerDevUnit());
return 0.5 * chWidthAppUnits;
}
static nscoord
LetterSpacing(nsIFrame* aFrame, const nsStyleText* aStyleText = nullptr)
{
@@ -3094,6 +3104,7 @@ public:
mLength(aLength),
mWordSpacing(WordSpacing(aFrame, mTextRun, aTextStyle)),
mLetterSpacing(LetterSpacing(aFrame, aTextStyle)),
mMinTabAdvance(-1.0),
mHyphenWidth(-1),
mOffsetFromBlockOriginForTabs(aOffsetFromBlockOriginForTabs),
mReflowing(true),
@@ -3118,6 +3129,7 @@ public:
mLength(aFrame->GetContentLength()),
mWordSpacing(WordSpacing(aFrame, mTextRun)),
mLetterSpacing(LetterSpacing(aFrame)),
mMinTabAdvance(-1.0),
mHyphenWidth(-1),
mOffsetFromBlockOriginForTabs(0),
mReflowing(false),
@@ -3182,6 +3194,13 @@ public:
void CalcTabWidths(Range aTransformedRange, gfxFloat aTabWidth);
gfxFloat MinTabAdvance() {
if (mMinTabAdvance < 0.0) {
mMinTabAdvance = GetMinTabAdvanceAppUnits(mTextRun);
}
return mMinTabAdvance;
}
const gfxSkipCharsIterator& GetEndHint() { return mTempIterator; }
protected:
@@ -3214,6 +3233,7 @@ protected:
int32_t mLength; // DOM string length, may be INT32_MAX
gfxFloat mWordSpacing; // space for each whitespace char
gfxFloat mLetterSpacing; // space for each letter
gfxFloat mMinTabAdvance; // min advance for <tab> char
gfxFloat mHyphenWidth;
gfxFloat mOffsetFromBlockOriginForTabs;
@@ -3474,14 +3494,13 @@ PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing,
// aX and the result are in whole appunits.
static gfxFloat
AdvanceToNextTab(gfxFloat aX, nsIFrame* aFrame,
gfxTextRun* aTextRun, gfxFloat aTabWidth)
AdvanceToNextTab(gfxFloat aX, nsIFrame* aFrame, gfxTextRun* aTextRun,
gfxFloat aTabWidth, gfxFloat aMinAdvance)
{
// Advance aX to the next multiple of *aCachedTabWidth. We must advance
// by at least 1 appunit.
// XXX should we make this 1 CSS pixel?
return NS_round((aX + 1) / aTabWidth) * aTabWidth;
// Advance aX to the next multiple of aTabWidth. We must advance
// by at least aMinAdvance.
return ceil((aX + aMinAdvance) / aTabWidth) * aTabWidth;
}
void
@@ -3544,7 +3563,7 @@ PropertyProvider::CalcTabWidths(Range aRange, gfxFloat aTabWidth)
mFrame->SetProperty(TabWidthProperty(), mTabWidths);
}
double nextTab = AdvanceToNextTab(mOffsetFromBlockOriginForTabs,
mFrame, mTextRun, aTabWidth);
mFrame, mTextRun, aTabWidth, MinTabAdvance());
mTabWidths->mWidths.AppendElement(TabWidth(i - startOffset,
NSToIntRound(nextTab - mOffsetFromBlockOriginForTabs)));
mOffsetFromBlockOriginForTabs = nextTab;
@@ -8464,7 +8483,8 @@ nsTextFrame::AddInlineMinISizeForFlow(nsRenderingContext *aRenderingContext,
tabWidth = ComputeTabWidthAppUnits(this, textRun);
}
gfxFloat afterTab =
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth);
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth,
provider.MinTabAdvance());
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
wordStart = i + 1;
} else if (i < flowEndInTextRun ||
@@ -8627,7 +8647,8 @@ nsTextFrame::AddInlinePrefISizeForFlow(nsRenderingContext *aRenderingContext,
tabWidth = ComputeTabWidthAppUnits(this, textRun);
}
gfxFloat afterTab =
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth);
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth,
provider.MinTabAdvance());
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
aData->mLineIsEmpty = false;
lineStart = i + 1;