mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-20 22:27:31 +09:00
Issue #1673 - Part 3: Bring minimum tab advance up to spec.
This provides a clearer rule for the minimum tab advance that brings us to alignment with the spec and both major browsers.
This commit is contained in:
parent
b739e46f74
commit
a64dc2a367
1 changed files with 30 additions and 11 deletions
|
|
@ -1716,6 +1716,16 @@ GetSpaceWidthAppUnits(const gfxTextRun* aTextRun)
|
||||||
return spaceWidthAppUnits;
|
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
|
static nscoord
|
||||||
LetterSpacing(nsIFrame* aFrame, const nsStyleText* aStyleText = nullptr)
|
LetterSpacing(nsIFrame* aFrame, const nsStyleText* aStyleText = nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -3090,6 +3100,7 @@ public:
|
||||||
mLength(aLength),
|
mLength(aLength),
|
||||||
mWordSpacing(WordSpacing(aFrame, mTextRun, aTextStyle)),
|
mWordSpacing(WordSpacing(aFrame, mTextRun, aTextStyle)),
|
||||||
mLetterSpacing(LetterSpacing(aFrame, aTextStyle)),
|
mLetterSpacing(LetterSpacing(aFrame, aTextStyle)),
|
||||||
|
mMinTabAdvance(-1.0),
|
||||||
mHyphenWidth(-1),
|
mHyphenWidth(-1),
|
||||||
mOffsetFromBlockOriginForTabs(aOffsetFromBlockOriginForTabs),
|
mOffsetFromBlockOriginForTabs(aOffsetFromBlockOriginForTabs),
|
||||||
mReflowing(true),
|
mReflowing(true),
|
||||||
|
|
@ -3114,6 +3125,7 @@ public:
|
||||||
mLength(aFrame->GetContentLength()),
|
mLength(aFrame->GetContentLength()),
|
||||||
mWordSpacing(WordSpacing(aFrame, mTextRun)),
|
mWordSpacing(WordSpacing(aFrame, mTextRun)),
|
||||||
mLetterSpacing(LetterSpacing(aFrame)),
|
mLetterSpacing(LetterSpacing(aFrame)),
|
||||||
|
mMinTabAdvance(-1.0),
|
||||||
mHyphenWidth(-1),
|
mHyphenWidth(-1),
|
||||||
mOffsetFromBlockOriginForTabs(0),
|
mOffsetFromBlockOriginForTabs(0),
|
||||||
mReflowing(false),
|
mReflowing(false),
|
||||||
|
|
@ -3178,6 +3190,13 @@ public:
|
||||||
|
|
||||||
void CalcTabWidths(Range aTransformedRange, gfxFloat aTabWidth);
|
void CalcTabWidths(Range aTransformedRange, gfxFloat aTabWidth);
|
||||||
|
|
||||||
|
gfxFloat MinTabAdvance() {
|
||||||
|
if (mMinTabAdvance < 0.0) {
|
||||||
|
mMinTabAdvance = GetMinTabAdvanceAppUnits(mTextRun);
|
||||||
|
}
|
||||||
|
return mMinTabAdvance;
|
||||||
|
}
|
||||||
|
|
||||||
const gfxSkipCharsIterator& GetEndHint() { return mTempIterator; }
|
const gfxSkipCharsIterator& GetEndHint() { return mTempIterator; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -3210,6 +3229,7 @@ protected:
|
||||||
int32_t mLength; // DOM string length, may be INT32_MAX
|
int32_t mLength; // DOM string length, may be INT32_MAX
|
||||||
gfxFloat mWordSpacing; // space for each whitespace char
|
gfxFloat mWordSpacing; // space for each whitespace char
|
||||||
gfxFloat mLetterSpacing; // space for each letter
|
gfxFloat mLetterSpacing; // space for each letter
|
||||||
|
gfxFloat mMinTabAdvance; // min advance for <tab> char
|
||||||
gfxFloat mHyphenWidth;
|
gfxFloat mHyphenWidth;
|
||||||
gfxFloat mOffsetFromBlockOriginForTabs;
|
gfxFloat mOffsetFromBlockOriginForTabs;
|
||||||
|
|
||||||
|
|
@ -3465,14 +3485,13 @@ PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing,
|
||||||
|
|
||||||
// aX and the result are in whole appunits.
|
// aX and the result are in whole appunits.
|
||||||
static gfxFloat
|
static gfxFloat
|
||||||
AdvanceToNextTab(gfxFloat aX, nsIFrame* aFrame,
|
AdvanceToNextTab(gfxFloat aX, nsIFrame* aFrame, gfxTextRun* aTextRun,
|
||||||
gfxTextRun* aTextRun, gfxFloat aTabWidth)
|
gfxFloat aTabWidth, gfxFloat aMinAdvance)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Advance aX to the next multiple of *aCachedTabWidth. We must advance
|
// Advance aX to the next multiple of aTabWidth. We must advance
|
||||||
// by at least 1 appunit.
|
// by at least aMinAdvance.
|
||||||
// XXX should we make this 1 CSS pixel?
|
return ceil((aX + aMinAdvance) / aTabWidth) * aTabWidth;
|
||||||
return NS_round((aX + 1) / aTabWidth) * aTabWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -3535,7 +3554,7 @@ PropertyProvider::CalcTabWidths(Range aRange, gfxFloat aTabWidth)
|
||||||
mFrame->SetProperty(TabWidthProperty(), mTabWidths);
|
mFrame->SetProperty(TabWidthProperty(), mTabWidths);
|
||||||
}
|
}
|
||||||
double nextTab = AdvanceToNextTab(mOffsetFromBlockOriginForTabs,
|
double nextTab = AdvanceToNextTab(mOffsetFromBlockOriginForTabs,
|
||||||
mFrame, mTextRun, aTabWidth);
|
mFrame, mTextRun, aTabWidth, MinTabAdvance());
|
||||||
mTabWidths->mWidths.AppendElement(TabWidth(i - startOffset,
|
mTabWidths->mWidths.AppendElement(TabWidth(i - startOffset,
|
||||||
NSToIntRound(nextTab - mOffsetFromBlockOriginForTabs)));
|
NSToIntRound(nextTab - mOffsetFromBlockOriginForTabs)));
|
||||||
mOffsetFromBlockOriginForTabs = nextTab;
|
mOffsetFromBlockOriginForTabs = nextTab;
|
||||||
|
|
@ -8333,8 +8352,8 @@ nsTextFrame::AddInlineMinISizeForFlow(nsRenderingContext *aRenderingContext,
|
||||||
tabWidth = ComputeTabWidthAppUnits(this, textRun);
|
tabWidth = ComputeTabWidthAppUnits(this, textRun);
|
||||||
}
|
}
|
||||||
gfxFloat afterTab =
|
gfxFloat afterTab =
|
||||||
AdvanceToNextTab(aData->mCurrentLine, this,
|
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth,
|
||||||
textRun, tabWidth);
|
provider.MinTabAdvance());
|
||||||
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
|
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
|
||||||
wordStart = i + 1;
|
wordStart = i + 1;
|
||||||
} else if (i < flowEndInTextRun ||
|
} else if (i < flowEndInTextRun ||
|
||||||
|
|
@ -8495,8 +8514,8 @@ nsTextFrame::AddInlinePrefISizeForFlow(nsRenderingContext *aRenderingContext,
|
||||||
tabWidth = ComputeTabWidthAppUnits(this, textRun);
|
tabWidth = ComputeTabWidthAppUnits(this, textRun);
|
||||||
}
|
}
|
||||||
gfxFloat afterTab =
|
gfxFloat afterTab =
|
||||||
AdvanceToNextTab(aData->mCurrentLine, this,
|
AdvanceToNextTab(aData->mCurrentLine, this, textRun, tabWidth,
|
||||||
textRun, tabWidth);
|
provider.MinTabAdvance());
|
||||||
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
|
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
|
||||||
lineStart = i + 1;
|
lineStart = i + 1;
|
||||||
} else if (preformattedNewline) {
|
} else if (preformattedNewline) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue