summaryrefslogtreecommitdiffstats
path: root/layout/generic
diff options
context:
space:
mode:
authorathenian200 <athenian200@outlook.com>2020-10-23 14:34:55 -0500
committerathenian200 <athenian200@outlook.com>2020-10-28 14:16:42 -0500
commit49765b53af01284a5d5479dfb8bb56da0ba87ca5 (patch)
treefb71b01560fea3049c351d9bd1ff64b1f8d1775e /layout/generic
parent33a402947c28b35c55fae782be3a45bafa97d293 (diff)
downloadUXP-49765b53af01284a5d5479dfb8bb56da0ba87ca5.tar
UXP-49765b53af01284a5d5479dfb8bb56da0ba87ca5.tar.gz
UXP-49765b53af01284a5d5479dfb8bb56da0ba87ca5.tar.lz
UXP-49765b53af01284a5d5479dfb8bb56da0ba87ca5.tar.xz
UXP-49765b53af01284a5d5479dfb8bb56da0ba87ca5.zip
Issue #1673 - Part 1: Allow tab-size to accept <length>.
Currently -moz-tab-size only accepts <number> values, and both Chrome and Firefox currently support <length> values and have for some time now. So with this you would be able to support sizes in px or em, for instance. This was implemented in Firefox 53 and was trivial to backport.
Diffstat (limited to 'layout/generic')
-rw-r--r--layout/generic/nsTextFrame.cpp74
1 files changed, 45 insertions, 29 deletions
diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp
index 4decdc8ec..663002ba1 100644
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -3176,7 +3176,7 @@ public:
return mFontMetrics;
}
- void CalcTabWidths(Range aTransformedRange);
+ void CalcTabWidths(Range aTransformedRange, gfxFloat aTabWidth);
const gfxSkipCharsIterator& GetEndHint() { return mTempIterator; }
@@ -3362,6 +3362,28 @@ CanAddSpacingAfter(const gfxTextRun* aTextRun, uint32_t aOffset)
aTextRun->IsLigatureGroupStart(aOffset + 1);
}
+static gfxFloat
+ComputeTabWidthAppUnits(nsIFrame* aFrame, gfxTextRun* aTextRun)
+{
+ const nsStyleText* textStyle = aFrame->StyleText();
+ if (textStyle->mTabSize.GetUnit() != eStyleUnit_Factor) {
+ nscoord w = textStyle->mTabSize.GetCoordValue();
+ MOZ_ASSERT(w >= 0);
+ return w;
+ }
+
+ gfxFloat spaces = textStyle->mTabSize.GetFactorValue();
+ MOZ_ASSERT(spaces >= 0);
+
+ // Round the space width when converting to appunits the same way
+ // textruns do.
+ gfxFloat spaceWidthAppUnits =
+ NS_round(GetFirstFontMetrics(aTextRun->GetFontGroup(),
+ aTextRun->IsVertical()).spaceWidth *
+ aTextRun->GetAppUnitsPerDevUnit());
+ return spaces * spaceWidthAppUnits;
+}
+
void
PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing,
bool aIgnoreTabs)
@@ -3409,17 +3431,16 @@ PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing,
}
}
- // Ignore tab spacing rather than computing it, if the tab size is 0
- if (!aIgnoreTabs)
- aIgnoreTabs = mFrame->StyleText()->mTabSize == 0;
-
// Now add tab spacing, if there is any
if (!aIgnoreTabs) {
- CalcTabWidths(aRange);
- if (mTabWidths) {
- mTabWidths->ApplySpacing(aSpacing,
- aRange.start - mStart.GetSkippedOffset(),
- aRange.Length());
+ gfxFloat tabWidth = ComputeTabWidthAppUnits(mFrame, mTextRun);
+ if (tabWidth > 0) {
+ CalcTabWidths(aRange);
+ if (mTabWidths) {
+ mTabWidths->ApplySpacing(aSpacing,
+ aRange.start - mStart.GetSkippedOffset(),
+ aRange.Length());
+ }
}
}
@@ -3442,33 +3463,23 @@ PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing,
}
}
-static gfxFloat
-ComputeTabWidthAppUnits(nsIFrame* aFrame, const gfxTextRun* aTextRun)
-{
- // Get the number of spaces from CSS -moz-tab-size
- const nsStyleText* textStyle = aFrame->StyleText();
-
- return textStyle->mTabSize * GetSpaceWidthAppUnits(aTextRun);
-}
-
// aX and the result are in whole appunits.
static gfxFloat
AdvanceToNextTab(gfxFloat aX, nsIFrame* aFrame,
- const gfxTextRun* aTextRun, gfxFloat* aCachedTabWidth)
+ gfxTextRun* aTextRun, gfxFloat* aTabWidth)
{
- if (*aCachedTabWidth < 0) {
- *aCachedTabWidth = ComputeTabWidthAppUnits(aFrame, aTextRun);
- }
// 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 ceil((aX + 1)/(*aCachedTabWidth))*(*aCachedTabWidth);
+ return ceil((aX + 1)/ aTabWidth) * aTabWidth;
}
void
-PropertyProvider::CalcTabWidths(Range aRange)
+PropertyProvider::CalcTabWidths(Range aRange, gfxFloat aTabWidth)
{
+ MOZ_ASSERT(aTabWidth > 0);
+
if (!mTabWidths) {
if (mReflowing && !mLineContainer) {
// Intrinsic width computation does its own tab processing. We
@@ -3503,7 +3514,6 @@ PropertyProvider::CalcTabWidths(Range aRange)
NS_ASSERTION(mReflowing,
"We need precomputed tab widths, but don't have enough.");
- gfxFloat tabWidth = -1;
for (uint32_t i = tabsEnd; i < aRange.end; ++i) {
Spacing spacing;
GetSpacingInternal(Range(i, i + 1), &spacing, true);
@@ -3525,7 +3535,7 @@ PropertyProvider::CalcTabWidths(Range aRange)
mFrame->SetProperty(TabWidthProperty(), mTabWidths);
}
double nextTab = AdvanceToNextTab(mOffsetFromBlockOriginForTabs,
- mFrame, mTextRun, &tabWidth);
+ mFrame, mTextRun, aTabWidth);
mTabWidths->mWidths.AppendElement(TabWidth(i - startOffset,
NSToIntRound(nextTab - mOffsetFromBlockOriginForTabs)));
mOffsetFromBlockOriginForTabs = nextTab;
@@ -8319,9 +8329,12 @@ nsTextFrame::AddInlineMinISizeForFlow(nsRenderingContext *aRenderingContext,
PropertyProvider::Spacing spacing;
provider.GetSpacing(Range(i, i + 1), &spacing);
aData->mCurrentLine += nscoord(spacing.mBefore);
+ if (tabWidth < 0) {
+ tabWidth = ComputeTabWidthAppUnits(this, textRun);
+ }
gfxFloat afterTab =
AdvanceToNextTab(aData->mCurrentLine, this,
- textRun, &tabWidth);
+ textRun, tabWidth);
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
wordStart = i + 1;
} else if (i < flowEndInTextRun ||
@@ -8478,9 +8491,12 @@ nsTextFrame::AddInlinePrefISizeForFlow(nsRenderingContext *aRenderingContext,
PropertyProvider::Spacing spacing;
provider.GetSpacing(Range(i, i + 1), &spacing);
aData->mCurrentLine += nscoord(spacing.mBefore);
+ if (tabWidth < 0) {
+ tabWidth = ComputeTabWidthAppUnits(this, textRun);
+ }
gfxFloat afterTab =
AdvanceToNextTab(aData->mCurrentLine, this,
- textRun, &tabWidth);
+ textRun, tabWidth);
aData->mCurrentLine = nscoord(afterTab + spacing.mAfter);
lineStart = i + 1;
} else if (preformattedNewline) {