From 4dae04e594f6662dcfb03fd304494841ca542091 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Fri, 23 Oct 2020 14:34:55 -0500 Subject: Issue #1673 - Part 1: Allow tab-size to accept . Currently -moz-tab-size only accepts values, and both Chrome and Firefox currently support 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. --- layout/generic/nsTextFrame.cpp | 74 ++++++++++++++++---------- layout/style/nsCSSPropList.h | 2 +- layout/style/nsComputedDOMStyle.cpp | 2 +- layout/style/nsRuleNode.cpp | 96 +++++++++++++++++++++++++--------- layout/style/nsStyleStruct.cpp | 4 +- layout/style/nsStyleStruct.h | 2 +- layout/style/test/property_database.js | 6 ++- 7 files changed, 124 insertions(+), 62 deletions(-) (limited to 'layout') diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index c7b55961c..749b8b944 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -3178,7 +3178,7 @@ public: return mFontMetrics; } - void CalcTabWidths(Range aTransformedRange); + void CalcTabWidths(Range aTransformedRange, gfxFloat aTabWidth); const gfxSkipCharsIterator& GetEndHint() { return mTempIterator; } @@ -3364,6 +3364,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) @@ -3411,17 +3433,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()); + } } } @@ -3444,33 +3465,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 @@ -3505,7 +3516,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); @@ -3527,7 +3537,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; @@ -8321,9 +8331,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 || @@ -8480,9 +8493,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) { diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 4f79db5a5..5c5cfcda1 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -3885,7 +3885,7 @@ CSS_PROP_TEXT( CSS_PROPERTY_PARSE_VALUE | CSS_PROPERTY_VALUE_NONNEGATIVE, "", - VARIANT_HI, + VARIANT_INHERIT | VARIANT_LNCALC, nullptr, offsetof(nsStyleText, mTabSize), eStyleAnimType_Discrete) diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 08c2846f7..bbad9c371 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -3972,7 +3972,7 @@ already_AddRefed nsComputedDOMStyle::DoGetTabSize() { RefPtr val = new nsROCSSPrimitiveValue; - val->SetNumber(StyleText()->mTabSize); + SetValueToCoord(val, StyleText()->mTabSize, true); return val.forget(); } diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 1136edee2..c2fd70879 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -4508,20 +4508,20 @@ TruncateStringToSingleGrapheme(nsAString& aStr) } } -struct LineHeightCalcObj +struct LengthNumberCalcObj { - float mLineHeight; + float LengthNumberCalcObj; bool mIsNumber; }; -struct SetLineHeightCalcOps : public css::NumbersAlreadyNormalizedOps +struct LengthNumberCalcOps : public css::FloatCoeffsAlreadyNormalizedOps { - typedef LineHeightCalcObj result_type; + typedef LengthNumberCalcObj result_type; nsStyleContext* const mStyleContext; nsPresContext* const mPresContext; RuleNodeCacheConditions& mConditions; - SetLineHeightCalcOps(nsStyleContext* aStyleContext, + LengthNumberCalcOps(nsStyleContext* aStyleContext, nsPresContext* aPresContext, RuleNodeCacheConditions& aConditions) : mStyleContext(aStyleContext), @@ -4536,15 +4536,15 @@ struct SetLineHeightCalcOps : public css::NumbersAlreadyNormalizedOps { MOZ_ASSERT(aValue1.mIsNumber == aValue2.mIsNumber); - LineHeightCalcObj result; + LengthNumberCalcObj result; result.mIsNumber = aValue1.mIsNumber; if (aCalcFunction == eCSSUnit_Calc_Plus) { - result.mLineHeight = aValue1.mLineHeight + aValue2.mLineHeight; + result.mValue = aValue1.mValue + aValue2.mValue; return result; } MOZ_ASSERT(aCalcFunction == eCSSUnit_Calc_Minus, "unexpected unit"); - result.mLineHeight = aValue1.mLineHeight - aValue2.mLineHeight; + result.mValue = aValue1.mValue - aValue2.mValue; return result; } @@ -4554,9 +4554,9 @@ struct SetLineHeightCalcOps : public css::NumbersAlreadyNormalizedOps { MOZ_ASSERT(aCalcFunction == eCSSUnit_Calc_Times_L, "unexpected unit"); - LineHeightCalcObj result; + LengthNumberCalcObj result; result.mIsNumber = aValue2.mIsNumber; - result.mLineHeight = aValue1 * aValue2.mLineHeight; + result.mValue = aValue1 * aValue2.mValue; return result; } @@ -4564,39 +4564,69 @@ struct SetLineHeightCalcOps : public css::NumbersAlreadyNormalizedOps MergeMultiplicativeR(nsCSSUnit aCalcFunction, result_type aValue1, float aValue2) { - LineHeightCalcObj result; + LengthNumberCalcObj result; result.mIsNumber = aValue1.mIsNumber; if (aCalcFunction == eCSSUnit_Calc_Times_R) { - result.mLineHeight = aValue1.mLineHeight * aValue2; + result.mValue = aValue1.mValue * aValue2; return result; } MOZ_ASSERT(aCalcFunction == eCSSUnit_Calc_Divided, "unexpected unit"); - result.mLineHeight = aValue1.mLineHeight / aValue2; + result.mValue = aValue1.mValue / aValue2; return result; } result_type ComputeLeafValue(const nsCSSValue& aValue) { - LineHeightCalcObj result; + LengthNumberCalcObj result; if (aValue.IsLengthUnit()) { result.mIsNumber = false; - result.mLineHeight = CalcLength(aValue, mStyleContext, + result.mValue = CalcLength(aValue, mStyleContext, + mPresContext, mConditions); + } + else if (eCSSUnit_Number == aValue.GetUnit()) { + result.mIsNumber = true; + result.mValue = aValue.GetFloatValue(); + } else { + MOZ_ASSERT(false, "unexpected value"); + result.mIsNumber = true; + result.mValue = 1.0f; + } + + return result; + } +}; + +struct SetLineHeightCalcOps : public LengthNumberCalcOps +{ + SetLineHeightCalcOps(nsStyleContext* aStyleContext, + nsPresContext* aPresContext, + RuleNodeCacheConditions& aConditions) + : LengthNumberCalcOps(aStyleContext, aPresContext, aConditions) + { + } + + result_type ComputeLeafValue(const nsCSSValue& aValue) + { + LengthNumberCalcObj result; + if (aValue.IsLengthUnit()) { + result.mIsNumber = false; + result.mValue = CalcLength(aValue, mStyleContext, mPresContext, mConditions); } else if (eCSSUnit_Percent == aValue.GetUnit()) { mConditions.SetUncacheable(); result.mIsNumber = false; nscoord fontSize = mStyleContext->StyleFont()->mFont.size; - result.mLineHeight = fontSize * aValue.GetPercentValue(); + result.mValue = fontSize * aValue.GetPercentValue(); } else if (eCSSUnit_Number == aValue.GetUnit()) { result.mIsNumber = true; - result.mLineHeight = aValue.GetFloatValue(); + result.mValue = aValue.GetFloatValue(); } else { MOZ_ASSERT(false, "unexpected value"); result.mIsNumber = true; - result.mLineHeight = 1.0f; + result.mValue = 1.0f; } return result; @@ -4620,11 +4650,25 @@ nsRuleNode::ComputeTextData(void* aStartStruct, mPresContext, text->*aField, conditions); }; - // tab-size: integer, inherit - SetValue(*aRuleData->ValueForTabSize(), - text->mTabSize, conditions, - SETVAL_INTEGER | SETVAL_UNSET_INHERIT, parentText->mTabSize, - NS_STYLE_TABSIZE_INITIAL); + // tab-size: number, length, calc, inherit + const nsCSSValue* tabSizeValue = aRuleData->ValueForTabSize(); + if (tabSizeValue->GetUnit() == eCSSUnit_Initial) { + text->mTabSize = nsStyleCoord(float(NS_STYLE_TABSIZE_INITIAL), eStyleUnit_Factor); + } else if (eCSSUnit_Calc == tabSizeValue->GetUnit()) { + LengthNumberCalcOps ops(aContext, mPresContext, conditions); + LengthNumberCalcObj obj = css::ComputeCalc(*tabSizeValue, ops); + float value = obj.mValue < 0 ? 0 : obj.mValue; + if (obj.mIsNumber) { + text->mTabSize.SetFactorValue(value); + } else { + text->mTabSize.SetCoordValue( + NSToCoordRoundWithClamp(value)); + } + } else { + SetCoord(*tabSizeValue, text->mTabSize, parentText->mTabSize, + SETCOORD_LH | SETCOORD_FACTOR | SETCOORD_UNSET_INHERIT, + aContext, mPresContext, conditions); + } // letter-spacing: normal, length, inherit SetCoord(*aRuleData->ValueForLetterSpacing(), @@ -4667,12 +4711,12 @@ nsRuleNode::ComputeTextData(void* aStartStruct, } else if (eCSSUnit_Calc == lineHeightValue->GetUnit()) { SetLineHeightCalcOps ops(aContext, mPresContext, conditions); - LineHeightCalcObj obj = css::ComputeCalc(*lineHeightValue, ops); + LengthNumberCalcObj obj = css::ComputeCalc(*lineHeightValue, ops); if (obj.mIsNumber) { - text->mLineHeight.SetFactorValue(obj.mLineHeight); + text->mLineHeight.SetFactorValue(obj.mValue); } else { text->mLineHeight.SetCoordValue( - NSToCoordRoundWithClamp(obj.mLineHeight)); + NSToCoordRoundWithClamp(obj.mValue)); } } else { diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 4c610cf08..a2b6833ac 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -3807,10 +3807,10 @@ nsStyleText::nsStyleText(StyleStructContext aContext) , mControlCharacterVisibility(nsCSSParser::ControlCharVisibilityDefault()) , mTextEmphasisStyle(NS_STYLE_TEXT_EMPHASIS_STYLE_NONE) , mTextRendering(NS_STYLE_TEXT_RENDERING_AUTO) - , mTabSize(NS_STYLE_TABSIZE_INITIAL) , mTextEmphasisColor(StyleComplexColor::CurrentColor()) , mWebkitTextFillColor(StyleComplexColor::CurrentColor()) , mWebkitTextStrokeColor(StyleComplexColor::CurrentColor()) + , mTabSize(float(NS_STYLE_TABSIZE_INITIAL), eStyleUnit_Factor) , mWordSpacing(0, nsStyleCoord::CoordConstructor) , mLetterSpacing(eStyleUnit_Normal) , mLineHeight(eStyleUnit_Normal) @@ -3845,10 +3845,10 @@ nsStyleText::nsStyleText(const nsStyleText& aSource) , mTextEmphasisPosition(aSource.mTextEmphasisPosition) , mTextEmphasisStyle(aSource.mTextEmphasisStyle) , mTextRendering(aSource.mTextRendering) - , mTabSize(aSource.mTabSize) , mTextEmphasisColor(aSource.mTextEmphasisColor) , mWebkitTextFillColor(aSource.mWebkitTextFillColor) , mWebkitTextStrokeColor(aSource.mWebkitTextStrokeColor) + , mTabSize(aSource.mTabSize) , mWordSpacing(aSource.mWordSpacing) , mLetterSpacing(aSource.mLetterSpacing) , mLineHeight(aSource.mLineHeight) diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 97724571d..c948d6056 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -2088,11 +2088,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText uint8_t mTextEmphasisPosition; // [inherited] see nsStyleConsts.h uint8_t mTextEmphasisStyle; // [inherited] see nsStyleConsts.h uint8_t mTextRendering; // [inherited] see nsStyleConsts.h - int32_t mTabSize; // [inherited] see nsStyleConsts.h mozilla::StyleComplexColor mTextEmphasisColor; // [inherited] mozilla::StyleComplexColor mWebkitTextFillColor; // [inherited] mozilla::StyleComplexColor mWebkitTextStrokeColor; // [inherited] + nsStyleCoord mTabSize; // [inherited] coord, factor, calc nsStyleCoord mWordSpacing; // [inherited] coord, percent, calc nsStyleCoord mLetterSpacing; // [inherited] coord, normal nsStyleCoord mLineHeight; // [inherited] coord, factor, normal diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index a7014c043..8624e17dd 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -2033,8 +2033,10 @@ var gCSSProperties = { inherited: true, type: CSS_TYPE_LONGHAND, initial_values: [ "8" ], - other_values: [ "0", "3", "99", "12000" ], - invalid_values: [ "-1", "-808", "3.0", "17.5" ] + other_values: [ "0", "2.5", "3", "99", "12000", "0px", "1em", + "calc(1px + 1em)", "calc(1px - 2px)", "calc(1 + 1)", "calc(-2.5)" ], + invalid_values: [ "9%", "calc(9% + 1px)", "calc(1 + 1em)", "-1", "-808", + "auto" ] }, "-moz-text-size-adjust": { domProp: "MozTextSizeAdjust", -- cgit v1.2.3 From 4de0e9c68d3f1a04d5d6c236d5f06fff7244c074 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Fri, 23 Oct 2020 19:45:52 -0500 Subject: Issue #1673 - Part 2: Make tab-size animatable and fix typos. There were a few typos in the previous patch and this patch also makes tab-size animatable which didn't really require much of a change at all. --- layout/generic/nsTextFrame.cpp | 6 +++--- layout/style/nsCSSPropList.h | 2 +- layout/style/nsRuleNode.cpp | 2 +- layout/style/test/test_transitions_per_property.html | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'layout') diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 749b8b944..83e50ca43 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -3437,7 +3437,7 @@ PropertyProvider::GetSpacingInternal(Range aRange, Spacing* aSpacing, if (!aIgnoreTabs) { gfxFloat tabWidth = ComputeTabWidthAppUnits(mFrame, mTextRun); if (tabWidth > 0) { - CalcTabWidths(aRange); + CalcTabWidths(aRange, tabWidth); if (mTabWidths) { mTabWidths->ApplySpacing(aSpacing, aRange.start - mStart.GetSkippedOffset(), @@ -3468,13 +3468,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) + gfxTextRun* aTextRun, gfxFloat aTabWidth) { // 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)/ aTabWidth) * aTabWidth; + return NS_round((aX + 1) / aTabWidth) * aTabWidth; } void diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 5c5cfcda1..53bc84547 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -3888,7 +3888,7 @@ CSS_PROP_TEXT( VARIANT_INHERIT | VARIANT_LNCALC, nullptr, offsetof(nsStyleText, mTabSize), - eStyleAnimType_Discrete) + eStyleAnimType_Coord) CSS_PROP_TABLE( table-layout, table_layout, diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index c2fd70879..739deaea1 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -4510,7 +4510,7 @@ TruncateStringToSingleGrapheme(nsAString& aStr) struct LengthNumberCalcObj { - float LengthNumberCalcObj; + float mValue; bool mIsNumber; }; diff --git a/layout/style/test/test_transitions_per_property.html b/layout/style/test/test_transitions_per_property.html index f188f4f6f..b7659adb7 100644 --- a/layout/style/test/test_transitions_per_property.html +++ b/layout/style/test/test_transitions_per_property.html @@ -248,6 +248,8 @@ var supported_properties = { // test_length_percent_calc_transition. "stroke-width": [ test_length_transition_svg, test_percent_transition, test_length_clamped_svg, test_percent_clamped ], + "-moz-tab-size": [ test_float_zeroToOne_transition, + test_float_aboveOne_transition, test_length_clamped ], "text-decoration": [ test_color_shorthand_transition, test_true_currentcolor_shorthand_transition ], "text-decoration-color": [ test_color_transition, -- cgit v1.2.3 From 90309c01a811c7e05baf6d95a2fde2bdd4cdeaf5 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Sun, 25 Oct 2020 14:27:17 -0500 Subject: 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. --- layout/generic/nsTextFrame.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'layout') diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 83e50ca43..a93c71b28 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -1718,6 +1718,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) { @@ -3092,6 +3102,7 @@ public: mLength(aLength), mWordSpacing(WordSpacing(aFrame, mTextRun, aTextStyle)), mLetterSpacing(LetterSpacing(aFrame, aTextStyle)), + mMinTabAdvance(-1.0), mHyphenWidth(-1), mOffsetFromBlockOriginForTabs(aOffsetFromBlockOriginForTabs), mReflowing(true), @@ -3116,6 +3127,7 @@ public: mLength(aFrame->GetContentLength()), mWordSpacing(WordSpacing(aFrame, mTextRun)), mLetterSpacing(LetterSpacing(aFrame)), + mMinTabAdvance(-1.0), mHyphenWidth(-1), mOffsetFromBlockOriginForTabs(0), mReflowing(false), @@ -3180,6 +3192,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: @@ -3212,6 +3231,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 char gfxFloat mHyphenWidth; gfxFloat mOffsetFromBlockOriginForTabs; @@ -3467,14 +3487,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 @@ -3537,7 +3556,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; @@ -8335,8 +8354,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 || @@ -8497,8 +8516,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); lineStart = i + 1; } else if (preformattedNewline) { -- cgit v1.2.3 From 770cb9a4b98947b5508278aeb7532d42fd973cae Mon Sep 17 00:00:00 2001 From: athenian200 Date: Tue, 27 Oct 2020 20:37:50 -0500 Subject: Issue #1673 - Part 4: Unprefix -moz-tab-size. While we do fail a couple of tests, the other mainstream browsers also fail them and I think our implementation of tab-size is good enough to be unprefixed at this point. Having this patch also makes testing easier. --- layout/style/nsCSSPropAliasList.h | 4 ++++ layout/style/nsCSSPropList.h | 6 +++--- layout/style/nsComputedDOMStylePropertyList.h | 2 +- layout/style/nsRuleNode.cpp | 2 +- layout/style/test/property_database.js | 11 +++++++++-- 5 files changed, 18 insertions(+), 7 deletions(-) (limited to 'layout') diff --git a/layout/style/nsCSSPropAliasList.h b/layout/style/nsCSSPropAliasList.h index 9ec71b2cf..334f3b1ac 100644 --- a/layout/style/nsCSSPropAliasList.h +++ b/layout/style/nsCSSPropAliasList.h @@ -223,6 +223,10 @@ CSS_PROP_ALIAS(-moz-columns, columns, MozColumns, "") +CSS_PROP_ALIAS(-moz-tab-size, + tab_size, + MozTabSize, + "") #define WEBKIT_PREFIX_PREF "layout.css.prefixes.webkit" diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 53bc84547..658ea68d7 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -3879,9 +3879,9 @@ CSS_PROP_FONT( eStyleAnimType_None) #endif // CSS_PROP_LIST_EXCLUDE_INTERNAL CSS_PROP_TEXT( - -moz-tab-size, - _moz_tab_size, - CSS_PROP_DOMPROP_PREFIXED(TabSize), + tab-size, + tab_size, + TabSize, CSS_PROPERTY_PARSE_VALUE | CSS_PROPERTY_VALUE_NONNEGATIVE, "", diff --git a/layout/style/nsComputedDOMStylePropertyList.h b/layout/style/nsComputedDOMStylePropertyList.h index 8d4d8e45e..6a18a7ad0 100644 --- a/layout/style/nsComputedDOMStylePropertyList.h +++ b/layout/style/nsComputedDOMStylePropertyList.h @@ -228,6 +228,7 @@ COMPUTED_STYLE_PROP(scroll_snap_type_x, ScrollSnapTypeX) COMPUTED_STYLE_PROP(scroll_snap_type_y, ScrollSnapTypeY) COMPUTED_STYLE_PROP(shape_outside, ShapeOutside) //// COMPUTED_STYLE_PROP(size, Size) +COMPUTED_STYLE_PROP(tab_size, TabSize) COMPUTED_STYLE_PROP(table_layout, TableLayout) COMPUTED_STYLE_PROP(text_align, TextAlign) COMPUTED_STYLE_PROP(text_align_last, TextAlignLast) @@ -295,7 +296,6 @@ COMPUTED_STYLE_PROP(_moz_outline_radius_bottomRight,OutlineRadiusBottomRight) COMPUTED_STYLE_PROP(_moz_outline_radius_topLeft, OutlineRadiusTopLeft) COMPUTED_STYLE_PROP(_moz_outline_radius_topRight, OutlineRadiusTopRight) COMPUTED_STYLE_PROP(stack_sizing, StackSizing) -COMPUTED_STYLE_PROP(_moz_tab_size, TabSize) COMPUTED_STYLE_PROP(text_size_adjust, TextSizeAdjust) COMPUTED_STYLE_PROP(user_focus, UserFocus) COMPUTED_STYLE_PROP(user_input, UserInput) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 739deaea1..58a99172a 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -4514,7 +4514,7 @@ struct LengthNumberCalcObj bool mIsNumber; }; -struct LengthNumberCalcOps : public css::FloatCoeffsAlreadyNormalizedOps +struct LengthNumberCalcOps : public css::NumbersAlreadyNormalizedOps { typedef LengthNumberCalcObj result_type; nsStyleContext* const mStyleContext; diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 8624e17dd..6b1ef5602 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -2028,8 +2028,8 @@ var gCSSProperties = { other_values: [ "ignore" ], invalid_values: [] }, - "-moz-tab-size": { - domProp: "MozTabSize", + "tab-size": { + domProp: "TabSize", inherited: true, type: CSS_TYPE_LONGHAND, initial_values: [ "8" ], @@ -2038,6 +2038,13 @@ var gCSSProperties = { invalid_values: [ "9%", "calc(9% + 1px)", "calc(1 + 1em)", "-1", "-808", "auto" ] }, + "-moz-tab-size": { + domProp: "MozTabSize", + inherited: true, + type: CSS_TYPE_SHORTHAND_AND_LONGHAND + alias_for: "tab-size", + subproperties: [ "tab-size" ] + }, "-moz-text-size-adjust": { domProp: "MozTextSizeAdjust", inherited: true, -- cgit v1.2.3 From 6c1b1bd18f2830a2f71027f9b3060200acfd4061 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Wed, 28 Oct 2020 22:57:34 -0500 Subject: Issue #1673 - Part 5: Fix brace style and missed -moz-tab-size reference. --- layout/style/nsRuleNode.cpp | 465 ++++++++++----------- .../style/test/test_transitions_per_property.html | 2 +- 2 files changed, 212 insertions(+), 255 deletions(-) (limited to 'layout') diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 58a99172a..8b0dd9bbb 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -870,8 +870,7 @@ static bool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord, bool result = true; if (aValue.GetUnit() == eCSSUnit_Null) { result = false; - } - else if ((((aMask & SETCOORD_LENGTH) != 0) && + } else if ((((aMask & SETCOORD_LENGTH) != 0) && aValue.IsLengthUnit()) || (((aMask & SETCOORD_CALC_LENGTH_ONLY) != 0) && aValue.IsCalcUnit())) { @@ -883,83 +882,63 @@ static bool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord, len = 0; } aCoord.SetCoordValue(len); - } - else if (((aMask & SETCOORD_PERCENT) != 0) && + } else if (((aMask & SETCOORD_PERCENT) != 0) && (aValue.GetUnit() == eCSSUnit_Percent)) { aCoord.SetPercentValue(aValue.GetPercentValue()); - } - else if (((aMask & SETCOORD_INTEGER) != 0) && + } else if (((aMask & SETCOORD_INTEGER) != 0) && (aValue.GetUnit() == eCSSUnit_Integer)) { aCoord.SetIntValue(aValue.GetIntValue(), eStyleUnit_Integer); - } - else if (((aMask & SETCOORD_ENUMERATED) != 0) && + } else if (((aMask & SETCOORD_ENUMERATED) != 0) && (aValue.GetUnit() == eCSSUnit_Enumerated)) { aCoord.SetIntValue(aValue.GetIntValue(), eStyleUnit_Enumerated); - } - else if (((aMask & SETCOORD_BOX_POSITION) != 0) && + } else if (((aMask & SETCOORD_BOX_POSITION) != 0) && (aValue.GetUnit() == eCSSUnit_Enumerated)) { aCoord.SetPercentValue(GetFloatFromBoxPosition(aValue.GetIntValue())); - } - else if (((aMask & SETCOORD_AUTO) != 0) && + } else if (((aMask & SETCOORD_AUTO) != 0) && (aValue.GetUnit() == eCSSUnit_Auto)) { aCoord.SetAutoValue(); - } - else if ((((aMask & SETCOORD_INHERIT) != 0) && + } else if ((((aMask & SETCOORD_INHERIT) != 0) && aValue.GetUnit() == eCSSUnit_Inherit) || (((aMask & SETCOORD_UNSET_INHERIT) != 0) && aValue.GetUnit() == eCSSUnit_Unset)) { aCoord = aParentCoord; // just inherit value from parent aConditions.SetUncacheable(); - } - else if (((aMask & SETCOORD_NORMAL) != 0) && + } else if (((aMask & SETCOORD_NORMAL) != 0) && (aValue.GetUnit() == eCSSUnit_Normal)) { aCoord.SetNormalValue(); - } - else if (((aMask & SETCOORD_NONE) != 0) && + } else if (((aMask & SETCOORD_NONE) != 0) && (aValue.GetUnit() == eCSSUnit_None)) { aCoord.SetNoneValue(); - } - else if (((aMask & SETCOORD_FACTOR) != 0) && + } else if (((aMask & SETCOORD_FACTOR) != 0) && (aValue.GetUnit() == eCSSUnit_Number)) { aCoord.SetFactorValue(aValue.GetFloatValue()); - } - else if (((aMask & SETCOORD_STORE_CALC) != 0) && + } else if (((aMask & SETCOORD_STORE_CALC) != 0) && (aValue.IsCalcUnit())) { SpecifiedCalcToComputedCalc(aValue, aCoord, aStyleContext, aConditions); - } - else if (aValue.GetUnit() == eCSSUnit_Initial || + } else if (aValue.GetUnit() == eCSSUnit_Initial || (aValue.GetUnit() == eCSSUnit_Unset && ((aMask & SETCOORD_UNSET_INITIAL) != 0))) { if ((aMask & SETCOORD_INITIAL_AUTO) != 0) { aCoord.SetAutoValue(); - } - else if ((aMask & SETCOORD_INITIAL_ZERO) != 0) { + } else if ((aMask & SETCOORD_INITIAL_ZERO) != 0) { aCoord.SetCoordValue(0); - } - else if ((aMask & SETCOORD_INITIAL_FACTOR_ZERO) != 0) { + } else if ((aMask & SETCOORD_INITIAL_FACTOR_ZERO) != 0) { aCoord.SetFactorValue(0.0f); - } - else if ((aMask & SETCOORD_INITIAL_NONE) != 0) { + } else if ((aMask & SETCOORD_INITIAL_NONE) != 0) { aCoord.SetNoneValue(); - } - else if ((aMask & SETCOORD_INITIAL_NORMAL) != 0) { + } else if ((aMask & SETCOORD_INITIAL_NORMAL) != 0) { aCoord.SetNormalValue(); - } - else if ((aMask & SETCOORD_INITIAL_HALF) != 0) { + } else if ((aMask & SETCOORD_INITIAL_HALF) != 0) { aCoord.SetPercentValue(0.5f); - } - else if ((aMask & SETCOORD_INITIAL_HUNDRED_PCT) != 0) { + } else if ((aMask & SETCOORD_INITIAL_HUNDRED_PCT) != 0) { aCoord.SetPercentValue(1.0f); - } - else if ((aMask & SETCOORD_INITIAL_FACTOR_ONE) != 0) { + } else if ((aMask & SETCOORD_INITIAL_FACTOR_ONE) != 0) { aCoord.SetFactorValue(1.0f); - } - else { + } else { result = false; // didn't set anything } - } - else if ((aMask & SETCOORD_ANGLE) != 0 && + } else if ((aMask & SETCOORD_ANGLE) != 0 && (aValue.IsAngularUnit())) { nsStyleUnit unit; switch (aValue.GetUnit()) { @@ -1038,8 +1017,7 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, if (aValue.IsNumericColorUnit()) { aResult = aValue.GetColorValue(); result = true; - } - else if (eCSSUnit_Ident == unit) { + } else if (eCSSUnit_Ident == unit) { nsAutoString value; aValue.GetStringValue(value); nscolor rgba; @@ -1047,8 +1025,7 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, aResult = rgba; result = true; } - } - else if (eCSSUnit_EnumColor == unit) { + } else if (eCSSUnit_EnumColor == unit) { int32_t intValue = aValue.GetIntValue(); if (0 <= intValue) { LookAndFeel::ColorID colorID = (LookAndFeel::ColorID) intValue; @@ -1107,13 +1084,11 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, break; } } - } - else if (eCSSUnit_Inherit == unit) { + } else if (eCSSUnit_Inherit == unit) { aResult = aParentColor; result = true; aConditions.SetUncacheable(); - } - else if (eCSSUnit_Enumerated == unit && + } else if (eCSSUnit_Enumerated == unit && aValue.GetIntValue() == NS_STYLE_COLOR_INHERIT_FROM_BODY) { NS_ASSERTION(aPresContext->CompatibilityMode() == eCompatibility_NavQuirks, "Should only get this value in quirks mode"); @@ -1586,14 +1561,17 @@ SetFactor(const nsCSSValue& aValue, float& aField, RuleNodeCacheConditions& aCon aField = aValue.GetFloatValue(); if (aFlags & SETFCT_POSITIVE) { NS_ASSERTION(aField >= 0.0f, "negative value for positive-only property"); - if (aField < 0.0f) + if (aField < 0.0f) { aField = 0.0f; - } + } + } if (aFlags & SETFCT_OPACITY) { - if (aField < 0.0f) + if (aField < 0.0f) { aField = 0.0f; - if (aField > 1.0f) + } + if (aField > 1.0f) { aField = 1.0f; + } } return; @@ -1727,10 +1705,11 @@ nsRuleNode::Transition(nsIStyleRule* aRule, SheetType aLevel, curr = curr->mNextSibling; ++numKids; } - if (curr) + if (curr) { next = curr; - else if (numKids >= kMaxChildrenInList) + } else if (numKids >= kMaxChildrenInList) { ConvertChildrenToHash(numKids); + } } if (ChildrenAreHashed()) { @@ -1740,9 +1719,9 @@ nsRuleNode::Transition(nsIStyleRule* aRule, SheetType aLevel, NS_WARNING("out of memory"); return this; } - if (entry->mRuleNode) + if (entry->mRuleNode) { next = entry->mRuleNode; - else { + } else { next = entry->mRuleNode = new (mPresContext) nsRuleNode(mPresContext, this, aRule, aLevel, aIsImportantRule); } @@ -1961,10 +1940,11 @@ CheckFontCallback(const nsRuleData* aRuleData, // Promote reset to mixed since we have something that depends on // the parent. But never promote to inherited since that could // cause inheritance of the exact value. - if (aResult == nsRuleNode::eRulePartialReset) + if (aResult == nsRuleNode::eRulePartialReset) { aResult = nsRuleNode::eRulePartialMixed; - else if (aResult == nsRuleNode::eRuleFullReset) + } else if (aResult == nsRuleNode::eRuleFullReset) { aResult = nsRuleNode::eRuleFullMixed; + } } return aResult; @@ -1997,10 +1977,11 @@ CheckTextCallback(const nsRuleData* aRuleData, textAlignValue->GetIntValue() == NS_STYLE_TEXT_ALIGN_MATCH_PARENT)) { // Promote reset to mixed since we have something that depends on // the parent. - if (aResult == nsRuleNode::eRulePartialReset) + if (aResult == nsRuleNode::eRulePartialReset) { aResult = nsRuleNode::eRulePartialMixed; - else if (aResult == nsRuleNode::eRuleFullReset) + } else if (aResult == nsRuleNode::eRuleFullReset) { aResult = nsRuleNode::eRuleFullMixed; + } } return aResult; @@ -2251,9 +2232,9 @@ nsRuleNode::CheckSpecifiedProperties(const nsStyleStructID aSID, * optimize based on the edge cases and not the in-between cases. */ nsRuleNode::RuleDetail result; - if (inherited == total) + if (inherited == total) { result = eRuleFullInherited; - else if (specified == total + } else if (specified == total // MathML defines 5 properties in Font that will never be set when // MathML is not in use. Therefore if all but five // properties have been set, and MathML is not enabled, we can treat @@ -2263,18 +2244,21 @@ nsRuleNode::CheckSpecifiedProperties(const nsStyleStructID aSID, || (aSID == eStyleStruct_Font && specified + 5 == total && !mPresContext->Document()->GetMathMLEnabled()) ) { - if (inherited == 0) + if (inherited == 0) { result = eRuleFullReset; - else + } else { result = eRuleFullMixed; - } else if (specified == 0) + } + + } else if (specified == 0) { result = eRuleNone; - else if (specified == inherited) + } else if (specified == inherited) { result = eRulePartialInherited; - else if (inherited == 0) + } else if (inherited == 0) { result = eRulePartialReset; - else + } else { result = eRulePartialMixed; + } CheckCallbackFn cb = gCheckCallbacks[aSID]; if (cb) { @@ -2321,8 +2305,9 @@ UnsetPropertiesWithoutFlags(const nsStyleStructID aSID, for (size_t i = 0, i_end = nsCSSProps::PropertyCountInStruct(aSID); i != i_end; ++i) { - if ((flagData[i] & aFlags) != aFlags) + if ((flagData[i] & aFlags) != aFlags) { values[i].Reset(); + } } } @@ -2452,8 +2437,9 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID, while (ruleNode) { // See if this rule node has cached the fact that the remaining // nodes along this path specify no data whatsoever. - if (ruleNode->mNoneBits & bit) + if (ruleNode->mNoneBits & bit) { break; + } // If the dependent bit is set on a rule node for this struct, that // means its rule won't have any information to add, so skip it. @@ -2472,9 +2458,9 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID, // Check for cached data after the inner loop above -- otherwise // we'll miss it. startStruct = ruleNode->mStyleData.GetStyleData(aSID); - if (startStruct) + if (startStruct) { break; // We found a rule with fully specified data. We don't - // need to go up the tree any further, since the remainder + } // need to go up the tree any further, since the remainder // of this branch has already been computed. // Ask the rule to fill in the properties that it specifies. @@ -2490,14 +2476,15 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID, RuleDetail oldDetail = detail; detail = CheckSpecifiedProperties(aSID, &ruleData); - if (oldDetail == eRuleNone && detail != eRuleNone) + if (oldDetail == eRuleNone && detail != eRuleNone) { highestNode = ruleNode; + } if (detail == eRuleFullReset || detail == eRuleFullMixed || - detail == eRuleFullInherited) + detail == eRuleFullInherited) { break; // We don't need to examine any more rules. All properties - // have been fully specified. + } // have been fully specified. // Climb up to the next rule in the tree (a less specific rule). rootNode = ruleNode; @@ -2540,8 +2527,9 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID, "can't have start struct and be fully specified"); bool isReset = nsCachedStyleData::IsReset(aSID); - if (!highestNode) + if (!highestNode) { highestNode = rootNode; + } MOZ_ASSERT(!(aSID == eStyleStruct_Variables && startStruct), "if we start caching Variables structs in the rule tree, then " @@ -2630,8 +2618,9 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID, // (detail == eRuleNone), which is the most common case here. // We must check |!isReset| because the Compute*Data functions for // reset structs wouldn't handle none bits correctly. - if (highestNode != this && !isReset) + if (highestNode != this && !isReset) { PropagateNoneBit(bit, highestNode); + } // All information must necessarily be inherited from our parent style context. // In the absence of any computed data in the rule tree and with @@ -2883,32 +2872,34 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex parentdata_ = maybeFakeParentData.ptr(); \ } \ } \ - if (eStyleStruct_##type_ == eStyleStruct_Variables) \ + if (eStyleStruct_##type_ == eStyleStruct_Variables) { \ /* no need to copy construct an nsStyleVariables, as we will copy */ \ /* inherited variables (and call SetUncacheable()) in */ \ /* ComputeVariablesData */ \ data_ = new (mPresContext) nsStyle##type_(mPresContext); \ - else if (aStartStruct) \ + } else if (aStartStruct) { \ /* We only need to compute the delta between this computed data and */ \ /* our computed data. */ \ data_ = new (mPresContext) \ nsStyle##type_(*static_cast(aStartStruct)); \ - else { \ + } else { \ if (aRuleDetail != eRuleFullMixed && aRuleDetail != eRuleFullReset) { \ /* No question. We will have to inherit. Go ahead and init */ \ /* with inherited vals from parent. */ \ conditions.SetUncacheable(); \ - if (parentdata_) \ + if (parentdata_) { \ data_ = new (mPresContext) nsStyle##type_(*parentdata_); \ - else \ + } else { \ data_ = new (mPresContext) nsStyle##type_(mPresContext); \ - } \ - else \ + } \ + } else { \ data_ = new (mPresContext) nsStyle##type_(mPresContext); \ + } \ } \ \ - if (!parentdata_) \ - parentdata_ = data_; + if (!parentdata_) { \ + parentdata_ = data_; \ + } \ /** * Begin an nsRuleNode::Compute*Data function for a reset struct. @@ -2932,14 +2923,14 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex } \ \ nsStyle##type_* data_; \ - if (aStartStruct) \ + if (aStartStruct) { \ /* We only need to compute the delta between this computed data and */ \ /* our computed data. */ \ data_ = new (mPresContext) \ nsStyle##type_(*static_cast(aStartStruct)); \ - else \ + } else { \ data_ = new (mPresContext) nsStyle##type_(mPresContext); \ - \ + } \ /* If |conditions.Cacheable()| might be true by the time we're done, we */ \ /* can't call parentContext->Style##type_() since it could recur into */ \ /* setting the same struct on the same rule node, causing a leak. */ \ @@ -3201,10 +3192,11 @@ nsRuleNode::CalcFontPointSize(int32_t aHTMLSize, int32_t aBasePointSize, aHTMLSize--; // input as 1-7 } - if (aHTMLSize < 0) + if (aHTMLSize < 0) { aHTMLSize = 0; - else if (aHTMLSize > 6) + } else if (aHTMLSize > 6) { aHTMLSize = 6; + } int32_t* column; switch (aFontSizeType) @@ -3225,9 +3217,7 @@ nsRuleNode::CalcFontPointSize(int32_t aHTMLSize, int32_t aBasePointSize, } else { dFontSize = nsPresContext::CSSPixelsToAppUnits(sStrictFontSizeTable[row][column[aHTMLSize]]); } - } - else - { + } else { int32_t factor = sFontSizeFactors[column[aHTMLSize]]; dFontSize = (factor * aBasePointSize) / 100; } @@ -3277,8 +3267,9 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize, // find largest index smaller than current for (index = indexMax; index >= indexMin; index--) { indexFontSize = CalcFontPointSize(index, aBasePointSize, aPresContext, aFontSizeType); - if (indexFontSize < aFontSize) + if (indexFontSize < aFontSize) { break; + } } // set up points beyond table for interpolation purposes if (indexFontSize == smallestIndexFontSize) { @@ -3295,12 +3286,10 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize, relativePosition = float(aFontSize - indexFontSize) / float(largerIndexFontSize - indexFontSize); // set the new size to have the same relative position between the next smallest two indexed sizes smallerSize = smallerIndexFontSize + NSToCoordRound(relativePosition * (indexFontSize - smallerIndexFontSize)); - } - else { // larger than HTML table, drop by 33% + } else { // larger than HTML table, drop by 33% smallerSize = NSToCoordRound(float(aFontSize) / 1.5); } - } - else { // smaller than HTML table, drop by 1px + } else { // smaller than HTML table, drop by 1px smallerSize = std::max(aFontSize - onePx, onePx); } return smallerSize; @@ -3344,8 +3333,9 @@ nsRuleNode::FindNextLargerFontSize(nscoord aFontSize, int32_t aBasePointSize, // find smallest index larger than current for (index = indexMin; index <= indexMax; index++) { indexFontSize = CalcFontPointSize(index, aBasePointSize, aPresContext, aFontSizeType); - if (indexFontSize > aFontSize) + if (indexFontSize > aFontSize) { break; + } } // set up points beyond table for interpolation purposes if (indexFontSize == smallestIndexFontSize) { @@ -3363,12 +3353,10 @@ nsRuleNode::FindNextLargerFontSize(nscoord aFontSize, int32_t aBasePointSize, // set the new size to have the same relative position between the next largest two indexed sizes adjustment = NSCoordSaturatingNonnegativeMultiply(largerIndexFontSize - indexFontSize, relativePosition); largerSize = NSCoordSaturatingAdd(indexFontSize, adjustment); - } - else { // larger than HTML table, increase by 50% + } else { // larger than HTML table, increase by 50% largerSize = NSCoordSaturatingMultiply(aFontSize, 1.5); } - } - else { // smaller than HTML table, increase by 1px + } else { // smaller than HTML table, increase by 1px largerSize = NSCoordSaturatingAdd(aFontSize, onePx); } return largerSize; @@ -3413,8 +3401,7 @@ struct SetFontSizeCalcOps : public css::BasicCoordCalcOps, if (!aValue.IsRelativeLengthUnit() && mParentFont->mAllowZoom) { size = nsStyleFont::ZoomText(mPresContext, size); } - } - else if (eCSSUnit_Percent == aValue.GetUnit()) { + } else if (eCSSUnit_Percent == aValue.GetUnit()) { mConditions.SetUncacheable(); // Note that % units use the parent's size unadjusted for scriptlevel // changes. A scriptlevel change between us and the parent is simply @@ -3458,12 +3445,10 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, (value <= NS_STYLE_FONT_SIZE_XXLARGE)) { *aSize = CalcFontPointSize(value, baseSize, aPresContext, eFontSize_CSS); - } - else if (NS_STYLE_FONT_SIZE_XXXLARGE == value) { + } else if (NS_STYLE_FONT_SIZE_XXXLARGE == value) { // is not specified in CSS, so we don't use eFontSize_CSS. *aSize = CalcFontPointSize(value, baseSize, aPresContext); - } - else if (NS_STYLE_FONT_SIZE_LARGER == value || + } else if (NS_STYLE_FONT_SIZE_LARGER == value || NS_STYLE_FONT_SIZE_SMALLER == value) { aConditions.SetUncacheable(); @@ -3483,8 +3468,7 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, NS_ASSERTION(*aSize >= parentSize, "FindNextLargerFontSize failed"); - } - else { + } else { *aSize = FindNextSmallerFontSize(parentSize, baseSize, aPresContext, eFontSize_CSS); NS_ASSERTION(*aSize < parentSize || @@ -3494,8 +3478,7 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, } else { NS_NOTREACHED("unexpected value"); } - } - else if (sizeValue->IsLengthUnit() || + } else if (sizeValue->IsLengthUnit() || sizeValue->GetUnit() == eCSSUnit_Percent || sizeValue->IsCalcUnit()) { SetFontSizeCalcOps ops(aParentSize, aParentFont, @@ -3511,12 +3494,10 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, // The calc ops will always zoom its result according to the value // of aParentFont->mAllowZoom. sizeIsZoomedAccordingToParent = true; - } - else if (eCSSUnit_System_Font == sizeValue->GetUnit()) { + } else if (eCSSUnit_System_Font == sizeValue->GetUnit()) { // this becomes our cascading size *aSize = aSystemFont.size; - } - else if (eCSSUnit_Inherit == sizeValue->GetUnit() || + } else if (eCSSUnit_Inherit == sizeValue->GetUnit() || eCSSUnit_Unset == sizeValue->GetUnit()) { aConditions.SetUncacheable(); // We apply scriptlevel change for this case, because the default is @@ -3524,8 +3505,7 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, // default. *aSize = aScriptLevelAdjustedParentSize; sizeIsZoomedAccordingToParent = true; - } - else if (eCSSUnit_Initial == sizeValue->GetUnit()) { + } else if (eCSSUnit_Initial == sizeValue->GetUnit()) { // The initial value is 'medium', which has magical sizing based on // the generic font family, so do that here too. *aSize = baseSize; @@ -3560,10 +3540,12 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext, } static int8_t ClampTo8Bit(int32_t aValue) { - if (aValue < -128) + if (aValue < -128) { return -128; - if (aValue > 127) + } + if (aValue > 127) { return 127; + } return int8_t(aValue); } @@ -3722,20 +3704,17 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, // to have since we'll still want it once we get rid of // SetGenericFont (bug 380915). aFont->mGenericID = aGenericFontID; - } - else if (eCSSUnit_System_Font == familyValue->GetUnit()) { + } else if (eCSSUnit_System_Font == familyValue->GetUnit()) { aFont->mFont.fontlist = systemFont.fontlist; aFont->mFont.systemFont = true; aFont->mGenericID = kGenericFont_NONE; - } - else if (eCSSUnit_Inherit == familyValue->GetUnit() || + } else if (eCSSUnit_Inherit == familyValue->GetUnit() || eCSSUnit_Unset == familyValue->GetUnit()) { aConditions.SetUncacheable(); aFont->mFont.fontlist = aParentFont->mFont.fontlist; aFont->mFont.systemFont = aParentFont->mFont.systemFont; aFont->mGenericID = aParentFont->mGenericID; - } - else if (eCSSUnit_Initial == familyValue->GetUnit()) { + } else if (eCSSUnit_Initial == familyValue->GetUnit()) { aFont->mFont.fontlist = defaultVariableFont->fontlist; aFont->mFont.systemFont = defaultVariableFont->systemFont; aFont->mGenericID = kGenericFont_NONE; @@ -3863,24 +3842,20 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, // "relative" aConditions.SetUncacheable(); aFont->mScriptLevel = ClampTo8Bit(aParentFont->mScriptLevel + scriptLevelValue->GetIntValue()); - } - else if (eCSSUnit_Number == scriptLevelValue->GetUnit()) { + } else if (eCSSUnit_Number == scriptLevelValue->GetUnit()) { // "absolute" aFont->mScriptLevel = ClampTo8Bit(int32_t(scriptLevelValue->GetFloatValue())); - } - else if (eCSSUnit_Auto == scriptLevelValue->GetUnit()) { + } else if (eCSSUnit_Auto == scriptLevelValue->GetUnit()) { // auto aConditions.SetUncacheable(); aFont->mScriptLevel = ClampTo8Bit(aParentFont->mScriptLevel + (aParentFont->mMathDisplay == NS_MATHML_DISPLAYSTYLE_INLINE ? 1 : 0)); - } - else if (eCSSUnit_Inherit == scriptLevelValue->GetUnit() || + } else if (eCSSUnit_Inherit == scriptLevelValue->GetUnit() || eCSSUnit_Unset == scriptLevelValue->GetUnit()) { aConditions.SetUncacheable(); aFont->mScriptLevel = aParentFont->mScriptLevel; - } - else if (eCSSUnit_Initial == scriptLevelValue->GetUnit()) { + } else if (eCSSUnit_Initial == scriptLevelValue->GetUnit()) { aFont->mScriptLevel = 0; } @@ -4151,10 +4126,11 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext, const nsCSSValue* sizeAdjustValue = aRuleData->ValueForFontSizeAdjust(); if (eCSSUnit_System_Font == sizeAdjustValue->GetUnit()) { aFont->mFont.sizeAdjust = systemFont.sizeAdjust; - } else + } else { SetFactor(*sizeAdjustValue, aFont->mFont.sizeAdjust, aConditions, aParentFont->mFont.sizeAdjust, -1.0f, SETFCT_NONE | SETFCT_UNSET_INHERIT); + } } /* static */ void @@ -4248,9 +4224,10 @@ nsRuleNode::SetGenericFont(nsPresContext* aPresContext, // aStartStruct. for (nsRuleNode* ruleNode = context->RuleNode(); ruleNode; ruleNode = ruleNode->GetParent()) { - if (ruleNode->mNoneBits & fontBit) + if (ruleNode->mNoneBits & fontBit) { // no more font rules on this branch, get out break; + } nsIStyleRule *rule = ruleNode->GetRule(); if (rule) { @@ -4264,8 +4241,9 @@ nsRuleNode::SetGenericFont(nsPresContext* aPresContext, // Avoid unnecessary operations in SetFont(). But we care if it's // the final value that we're computing. - if (i != 0) + if (i != 0) { ruleData.ValueForFontFamily()->Reset(); + } ResolveVariableReferences(eStyleStruct_Font, &ruleData, aContext); @@ -4352,8 +4330,7 @@ nsRuleNode::ComputeFontData(void* aStartStruct, nsRuleNode::SetFont(mPresContext, aContext, generic, aRuleData, parentFont, font, aStartStruct != nullptr, conditions); - } - else { + } else { // re-calculate the font as a generic font conditions.SetUncacheable(); nsRuleNode::SetGenericFont(mPresContext, aContext, generic, @@ -4388,8 +4365,9 @@ GetShadowData(const nsCSSValueList* aList, RefPtr shadowList = new(arrayLength) nsCSSShadowArray(arrayLength); - if (!shadowList) + if (!shadowList) { return nullptr; + } nsStyleCoord tempCoord; DebugOnly unitOK; @@ -4583,8 +4561,7 @@ struct LengthNumberCalcOps : public css::NumbersAlreadyNormalizedOps result.mIsNumber = false; result.mValue = CalcLength(aValue, mStyleContext, mPresContext, mConditions); - } - else if (eCSSUnit_Number == aValue.GetUnit()) { + } else if (eCSSUnit_Number == aValue.GetUnit()) { result.mIsNumber = true; result.mValue = aValue.GetFloatValue(); } else { @@ -4613,14 +4590,12 @@ struct SetLineHeightCalcOps : public LengthNumberCalcOps result.mIsNumber = false; result.mValue = CalcLength(aValue, mStyleContext, mPresContext, mConditions); - } - else if (eCSSUnit_Percent == aValue.GetUnit()) { + } else if (eCSSUnit_Percent == aValue.GetUnit()) { mConditions.SetUncacheable(); result.mIsNumber = false; nscoord fontSize = mStyleContext->StyleFont()->mFont.size; result.mValue = fontSize * aValue.GetPercentValue(); - } - else if (eCSSUnit_Number == aValue.GetUnit()) { + } else if (eCSSUnit_Number == aValue.GetUnit()) { result.mIsNumber = true; result.mValue = aValue.GetFloatValue(); } else { @@ -4704,12 +4679,10 @@ nsRuleNode::ComputeTextData(void* aStartStruct, text->mLineHeight.SetCoordValue( NSToCoordRound(float(aContext->StyleFont()->mFont.size) * lineHeightValue->GetPercentValue())); - } - else if (eCSSUnit_Initial == lineHeightValue->GetUnit() || + } else if (eCSSUnit_Initial == lineHeightValue->GetUnit() || eCSSUnit_System_Font == lineHeightValue->GetUnit()) { text->mLineHeight.SetNormalValue(); - } - else if (eCSSUnit_Calc == lineHeightValue->GetUnit()) { + } else if (eCSSUnit_Calc == lineHeightValue->GetUnit()) { SetLineHeightCalcOps ops(aContext, mPresContext, conditions); LengthNumberCalcObj obj = css::ComputeCalc(*lineHeightValue, ops); if (obj.mIsNumber) { @@ -4718,8 +4691,7 @@ nsRuleNode::ComputeTextData(void* aStartStruct, text->mLineHeight.SetCoordValue( NSToCoordRoundWithClamp(obj.mValue)); } - } - else { + } else { SetCoord(*lineHeightValue, text->mLineHeight, parentText->mLineHeight, SETCOORD_LEH | SETCOORD_FACTOR | SETCOORD_NORMAL | SETCOORD_UNSET_INHERIT, @@ -5047,8 +5019,7 @@ nsRuleNode::ComputeTextResetData(void* aStartStruct, mPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks); if (underlineLinks) { text->mTextDecorationLine |= NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; - } - else { + } else { text->mTextDecorationLine &= ~NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; } } @@ -5204,11 +5175,9 @@ nsRuleNode::ComputeUserInterfaceData(void* aStartStruct, conditions.SetUncacheable(); ui->mCursor = parentUI->mCursor; ui->mCursorImages = parentUI->mCursorImages; - } - else if (cursorUnit == eCSSUnit_Initial) { + } else if (cursorUnit == eCSSUnit_Initial) { ui->mCursor = NS_STYLE_CURSOR_AUTO; - } - else { + } else { // The parser will never create a list that is *all* URL values -- // that's invalid. MOZ_ASSERT(cursorUnit == eCSSUnit_List || cursorUnit == eCSSUnit_ListDep, @@ -5441,8 +5410,9 @@ CountTransitionProps(const TransitionPropInfo* aInfo, } else { data.num = aDisplay->*(info.sdCount); } - if (data.num > numTransitions) + if (data.num > numTransitions) { numTransitions = data.num; + } } return numTransitions; @@ -6124,13 +6094,11 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct, } else { display->mBinding = nullptr; } - } - else if (eCSSUnit_None == bindingValue->GetUnit() || + } else if (eCSSUnit_None == bindingValue->GetUnit() || eCSSUnit_Initial == bindingValue->GetUnit() || eCSSUnit_Unset == bindingValue->GetUnit()) { display->mBinding = nullptr; - } - else if (eCSSUnit_Inherit == bindingValue->GetUnit()) { + } else if (eCSSUnit_Inherit == bindingValue->GetUnit()) { conditions.SetUncacheable(); display->mBinding = parentDisplay->mBinding; } @@ -6167,12 +6135,10 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct, display->mBreakBefore = (NS_STYLE_PAGE_BREAK_AVOID != breakBeforeValue->GetIntValue() && NS_STYLE_PAGE_BREAK_AUTO != breakBeforeValue->GetIntValue()); - } - else if (eCSSUnit_Initial == breakBeforeValue->GetUnit() || + } else if (eCSSUnit_Initial == breakBeforeValue->GetUnit() || eCSSUnit_Unset == breakBeforeValue->GetUnit()) { display->mBreakBefore = false; - } - else if (eCSSUnit_Inherit == breakBeforeValue->GetUnit()) { + } else if (eCSSUnit_Inherit == breakBeforeValue->GetUnit()) { conditions.SetUncacheable(); display->mBreakBefore = parentDisplay->mBreakBefore; } @@ -6182,12 +6148,10 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct, display->mBreakAfter = (NS_STYLE_PAGE_BREAK_AVOID != breakAfterValue->GetIntValue() && NS_STYLE_PAGE_BREAK_AUTO != breakAfterValue->GetIntValue()); - } - else if (eCSSUnit_Initial == breakAfterValue->GetUnit() || + } else if (eCSSUnit_Initial == breakAfterValue->GetUnit() || eCSSUnit_Unset == breakAfterValue->GetUnit()) { display->mBreakAfter = false; - } - else if (eCSSUnit_Inherit == breakAfterValue->GetUnit()) { + } else if (eCSSUnit_Inherit == breakAfterValue->GetUnit()) { conditions.SetUncacheable(); display->mBreakAfter = parentDisplay->mBreakAfter; } @@ -6246,17 +6210,21 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct, // NS_STYLE_OVERFLOW_CLIP is a deprecated value, so if it's specified // in only one dimension, convert it to NS_STYLE_OVERFLOW_HIDDEN. - if (display->mOverflowX == NS_STYLE_OVERFLOW_CLIP) + if (display->mOverflowX == NS_STYLE_OVERFLOW_CLIP) { display->mOverflowX = NS_STYLE_OVERFLOW_HIDDEN; - if (display->mOverflowY == NS_STYLE_OVERFLOW_CLIP) + } + if (display->mOverflowY == NS_STYLE_OVERFLOW_CLIP) { display->mOverflowY = NS_STYLE_OVERFLOW_HIDDEN; + } // If 'visible' is specified but doesn't match the other dimension, it // turns into 'auto'. - if (display->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) + if (display->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) { display->mOverflowX = NS_STYLE_OVERFLOW_AUTO; - if (display->mOverflowY == NS_STYLE_OVERFLOW_VISIBLE) + } + if (display->mOverflowY == NS_STYLE_OVERFLOW_VISIBLE) { display->mOverflowY = NS_STYLE_OVERFLOW_AUTO; + } } // When 'contain: paint', update overflow from 'visible' to 'clip'. @@ -6735,11 +6703,9 @@ nsRuleNode::ComputeColorData(void* aStartStruct, colorValue->GetUnit() == eCSSUnit_Unset) { color->mColor = parentColor->mColor; conditions.SetUncacheable(); - } - else if (colorValue->GetUnit() == eCSSUnit_Initial) { + } else if (colorValue->GetUnit() == eCSSUnit_Initial) { color->mColor = mPresContext->DefaultColor(); - } - else { + } else { SetColor(*colorValue, parentColor->mColor, mPresContext, aContext, color->mColor, conditions); } @@ -7024,8 +6990,7 @@ struct BackgroundItemComputer const nsCSSValue &specified = aSpecifiedValue->*(axis->specified); if (eCSSUnit_Auto == specified.GetUnit()) { size.*(axis->type) = nsStyleImageLayers::Size::eAuto; - } - else if (eCSSUnit_Enumerated == specified.GetUnit()) { + } else if (eCSSUnit_Enumerated == specified.GetUnit()) { static_assert(nsStyleImageLayers::Size::eContain == NS_STYLE_IMAGELAYER_SIZE_CONTAIN && nsStyleImageLayers::Size::eCover == @@ -7035,8 +7000,7 @@ struct BackgroundItemComputer specified.GetIntValue() == NS_STYLE_IMAGELAYER_SIZE_COVER, "invalid enumerated value for size coordinate"); size.*(axis->type) = specified.GetIntValue(); - } - else if (eCSSUnit_Null == specified.GetUnit()) { + } else if (eCSSUnit_Null == specified.GetUnit()) { MOZ_ASSERT(axis == gBGSizeAxes + 1, "null allowed only as height value, and only " "for contain/cover/initial/inherit"); @@ -7055,14 +7019,12 @@ struct BackgroundItemComputer } #endif size.*(axis->type) = size.mWidthType; - } - else if (eCSSUnit_Percent == specified.GetUnit()) { + } else if (eCSSUnit_Percent == specified.GetUnit()) { (size.*(axis->result)).mLength = 0; (size.*(axis->result)).mPercent = specified.GetPercentValue(); (size.*(axis->result)).mHasPercent = true; size.*(axis->type) = nsStyleImageLayers::Size::eLengthPercentage; - } - else if (specified.IsLengthUnit()) { + } else if (specified.IsLengthUnit()) { (size.*(axis->result)).mLength = CalcLength(specified, aStyleContext, aStyleContext->PresContext(), aConditions); @@ -7154,8 +7116,9 @@ SetImageLayerList(nsStyleContext* aStyleContext, MOZ_ASSERT(false, "unexpected unit"); } - if (aItemCount > aMaxItemCount) + if (aItemCount > aMaxItemCount) { aMaxItemCount = aItemCount; + } } // The same as SetImageLayerList, but for values stored in @@ -7224,8 +7187,9 @@ SetImageLayerPositionCoordList( MOZ_ASSERT(false, "unexpected unit"); } - if (aItemCount > aMaxItemCount) + if (aItemCount > aMaxItemCount) { aMaxItemCount = aItemCount; + } } template @@ -7292,8 +7256,9 @@ SetImageLayerPairList(nsStyleContext* aStyleContext, MOZ_ASSERT(false, "unexpected unit"); } - if (aItemCount > aMaxItemCount) + if (aItemCount > aMaxItemCount) { aMaxItemCount = aItemCount; + } } template @@ -7638,26 +7603,22 @@ nsRuleNode::ComputeBorderData(void* aStartStruct, "Unexpected enum value"); border->SetBorderWidth(side, (mPresContext->GetBorderWidthTable())[value.GetIntValue()]); - } // OK to pass bad aParentCoord since we're not passing SETCOORD_INHERIT - else if (SetCoord(value, coord, nsStyleCoord(), + } else if (SetCoord(value, coord, nsStyleCoord(), SETCOORD_LENGTH | SETCOORD_CALC_LENGTH_ONLY, aContext, mPresContext, conditions)) { NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit"); // clamp negative calc() to 0. border->SetBorderWidth(side, std::max(coord.GetCoordValue(), 0)); - } - else if (eCSSUnit_Inherit == value.GetUnit()) { + } else if (eCSSUnit_Inherit == value.GetUnit()) { conditions.SetUncacheable(); border->SetBorderWidth(side, parentBorder->GetComputedBorder().Side(side)); - } - else if (eCSSUnit_Initial == value.GetUnit() || + } else if (eCSSUnit_Initial == value.GetUnit() || eCSSUnit_Unset == value.GetUnit()) { border->SetBorderWidth(side, (mPresContext->GetBorderWidthTable())[NS_STYLE_BORDER_WIDTH_MEDIUM]); - } - else { + } else { NS_ASSERTION(eCSSUnit_Null == value.GetUnit(), "missing case handling border width"); } @@ -7675,12 +7636,10 @@ nsRuleNode::ComputeBorderData(void* aStartStruct, "'none' should be handled as enumerated value"); if (eCSSUnit_Enumerated == unit) { border->SetBorderStyle(side, value.GetIntValue()); - } - else if (eCSSUnit_Initial == unit || + } else if (eCSSUnit_Initial == unit || eCSSUnit_Unset == unit) { border->SetBorderStyle(side, NS_STYLE_BORDER_STYLE_NONE); - } - else if (eCSSUnit_Inherit == unit) { + } else if (eCSSUnit_Inherit == unit) { conditions.SetUncacheable(); border->SetBorderStyle(side, parentBorder->GetBorderStyle(side)); } @@ -7733,9 +7692,9 @@ nsRuleNode::ComputeBorderData(void* aStartStruct, const nsCSSValueList* list = value.GetListValue(); while (list) { if (SetColor(list->mValue, unused, mPresContext, - aContext, borderColor, conditions)) + aContext, borderColor, conditions)) { border->AppendBorderColor(side, borderColor); - else { + } else { NS_NOTREACHED("unexpected item in -moz-border-*-colors list"); } list = list->mNext; @@ -7924,8 +7883,7 @@ nsRuleNode::ComputeOutlineData(void* aStartStruct, eCSSUnit_Unset == outlineWidthValue->GetUnit()) { outline->mOutlineWidth = nsStyleCoord(NS_STYLE_BORDER_WIDTH_MEDIUM, eStyleUnit_Enumerated); - } - else { + } else { SetCoord(*outlineWidthValue, outline->mOutlineWidth, parentOutline->mOutlineWidth, SETCOORD_LEH | SETCOORD_CALC_LENGTH_ONLY, aContext, @@ -8112,12 +8070,10 @@ nsRuleNode::ComputeListData(void* aStartStruct, SetStyleImageRequest([&](nsStyleImageRequest* req) { list->mListStyleImage = req; }, mPresContext, *imageValue, nsStyleImageRequest::Mode(0)); - } - else if (eCSSUnit_None == imageValue->GetUnit() || + } else if (eCSSUnit_None == imageValue->GetUnit() || eCSSUnit_Initial == imageValue->GetUnit()) { list->mListStyleImage = nullptr; - } - else if (eCSSUnit_Inherit == imageValue->GetUnit() || + } else if (eCSSUnit_Inherit == imageValue->GetUnit() || eCSSUnit_Unset == imageValue->GetUnit()) { conditions.SetUncacheable(); list->mListStyleImage = parentList->mListStyleImage; @@ -8150,31 +8106,35 @@ nsRuleNode::ComputeListData(void* aStartStruct, case eCSSUnit_Rect: { const nsCSSRect& rgnRect = imageRegionValue->GetRectValue(); - if (rgnRect.mTop.GetUnit() == eCSSUnit_Auto) + if (rgnRect.mTop.GetUnit() == eCSSUnit_Auto) { list->mImageRegion.y = 0; - else if (rgnRect.mTop.IsLengthUnit()) + } else if (rgnRect.mTop.IsLengthUnit()) { list->mImageRegion.y = CalcLength(rgnRect.mTop, aContext, mPresContext, conditions); + } - if (rgnRect.mBottom.GetUnit() == eCSSUnit_Auto) + if (rgnRect.mBottom.GetUnit() == eCSSUnit_Auto) { list->mImageRegion.height = 0; - else if (rgnRect.mBottom.IsLengthUnit()) + } else if (rgnRect.mBottom.IsLengthUnit()) { list->mImageRegion.height = CalcLength(rgnRect.mBottom, aContext, mPresContext, conditions) - list->mImageRegion.y; + } - if (rgnRect.mLeft.GetUnit() == eCSSUnit_Auto) + if (rgnRect.mLeft.GetUnit() == eCSSUnit_Auto) { list->mImageRegion.x = 0; - else if (rgnRect.mLeft.IsLengthUnit()) + } else if (rgnRect.mLeft.IsLengthUnit()) { list->mImageRegion.x = CalcLength(rgnRect.mLeft, aContext, mPresContext, conditions); + } - if (rgnRect.mRight.GetUnit() == eCSSUnit_Auto) + if (rgnRect.mRight.GetUnit() == eCSSUnit_Auto) { list->mImageRegion.width = 0; - else if (rgnRect.mRight.IsLengthUnit()) + } else if (rgnRect.mRight.IsLengthUnit()) { list->mImageRegion.width = CalcLength(rgnRect.mRight, aContext, mPresContext, conditions) - list->mImageRegion.x; + } break; } @@ -8867,8 +8827,9 @@ nsRuleNode::ComputeTableData(void* aStartStruct, // span: pixels (not a real CSS prop) const nsCSSValue* spanValue = aRuleData->ValueForSpan(); if (eCSSUnit_Enumerated == spanValue->GetUnit() || - eCSSUnit_Integer == spanValue->GetUnit()) + eCSSUnit_Integer == spanValue->GetUnit()) { table->mSpan = spanValue->GetIntValue(); + } COMPUTE_END_RESET(Table, table) } @@ -9268,20 +9229,17 @@ nsRuleNode::ComputeColumnData(void* aStartStruct, eCSSUnit_Unset == widthValue.GetUnit()) { column->SetColumnRuleWidth( (mPresContext->GetBorderWidthTable())[NS_STYLE_BORDER_WIDTH_MEDIUM]); - } - else if (eCSSUnit_Enumerated == widthValue.GetUnit()) { + } else if (eCSSUnit_Enumerated == widthValue.GetUnit()) { NS_ASSERTION(widthValue.GetIntValue() == NS_STYLE_BORDER_WIDTH_THIN || widthValue.GetIntValue() == NS_STYLE_BORDER_WIDTH_MEDIUM || widthValue.GetIntValue() == NS_STYLE_BORDER_WIDTH_THICK, "Unexpected enum value"); column->SetColumnRuleWidth( (mPresContext->GetBorderWidthTable())[widthValue.GetIntValue()]); - } - else if (eCSSUnit_Inherit == widthValue.GetUnit()) { + } else if (eCSSUnit_Inherit == widthValue.GetUnit()) { column->SetColumnRuleWidth(parent->GetComputedColumnRuleWidth()); conditions.SetUncacheable(); - } - else if (widthValue.IsLengthUnit() || widthValue.IsCalcUnit()) { + } else if (widthValue.IsLengthUnit() || widthValue.IsCalcUnit()) { nscoord len = CalcLength(widthValue, aContext, mPresContext, conditions); if (len < 0) { @@ -9301,12 +9259,10 @@ nsRuleNode::ComputeColumnData(void* aStartStruct, "'none' should be handled as enumerated value"); if (eCSSUnit_Enumerated == styleValue.GetUnit()) { column->mColumnRuleStyle = styleValue.GetIntValue(); - } - else if (eCSSUnit_Initial == styleValue.GetUnit() || + } else if (eCSSUnit_Initial == styleValue.GetUnit() || eCSSUnit_Unset == styleValue.GetUnit()) { column->mColumnRuleStyle = NS_STYLE_BORDER_STYLE_NONE; - } - else if (eCSSUnit_Inherit == styleValue.GetUnit()) { + } else if (eCSSUnit_Inherit == styleValue.GetUnit()) { conditions.SetUncacheable(); column->mColumnRuleStyle = parent->mColumnRuleStyle; } @@ -10320,8 +10276,7 @@ nsRuleNode::ComputeEffectsData(void* aStartStruct, if (clipRect.mTop.GetUnit() == eCSSUnit_Auto) { effects->mClip.y = 0; effects->mClipFlags |= NS_STYLE_CLIP_TOP_AUTO; - } - else if (clipRect.mTop.IsLengthUnit()) { + } else if (clipRect.mTop.IsLengthUnit()) { effects->mClip.y = CalcLength(clipRect.mTop, aContext, mPresContext, conditions); } @@ -10332,8 +10287,7 @@ nsRuleNode::ComputeEffectsData(void* aStartStruct, // nonempty if the actual clip rect could be nonempty. effects->mClip.height = NS_MAXSIZE; effects->mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO; - } - else if (clipRect.mBottom.IsLengthUnit()) { + } else if (clipRect.mBottom.IsLengthUnit()) { effects->mClip.height = CalcLength(clipRect.mBottom, aContext, mPresContext, conditions) - effects->mClip.y; @@ -10342,8 +10296,7 @@ nsRuleNode::ComputeEffectsData(void* aStartStruct, if (clipRect.mLeft.GetUnit() == eCSSUnit_Auto) { effects->mClip.x = 0; effects->mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO; - } - else if (clipRect.mLeft.IsLengthUnit()) { + } else if (clipRect.mLeft.IsLengthUnit()) { effects->mClip.x = CalcLength(clipRect.mLeft, aContext, mPresContext, conditions); } @@ -10354,8 +10307,7 @@ nsRuleNode::ComputeEffectsData(void* aStartStruct, // nonempty if the actual clip rect could be nonempty. effects->mClip.width = NS_MAXSIZE; effects->mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO; - } - else if (clipRect.mRight.IsLengthUnit()) { + } else if (clipRect.mRight.IsLengthUnit()) { effects->mClip.width = CalcLength(clipRect.mRight, aContext, mPresContext, conditions) - effects->mClip.x; @@ -10415,8 +10367,9 @@ nsRuleNode::GetStyleData(nsStyleStructID aSID, } } - if (MOZ_UNLIKELY(!aComputeData)) + if (MOZ_UNLIKELY(!aComputeData)) { return nullptr; + } // Nothing is cached. We'll have to delve further and examine our rules. data = WalkRuleTree(aSID, aContext); @@ -10453,18 +10406,18 @@ nsRuleNode::HasAuthorSpecifiedRules(nsStyleContext* aStyleContext, #endif uint32_t inheritBits = 0; - if (ruleTypeMask & NS_AUTHOR_SPECIFIED_BACKGROUND) + if (ruleTypeMask & NS_AUTHOR_SPECIFIED_BACKGROUND) { inheritBits |= NS_STYLE_INHERIT_BIT(Background); - - if (ruleTypeMask & NS_AUTHOR_SPECIFIED_BORDER) + } + if (ruleTypeMask & NS_AUTHOR_SPECIFIED_BORDER) { inheritBits |= NS_STYLE_INHERIT_BIT(Border); - - if (ruleTypeMask & NS_AUTHOR_SPECIFIED_PADDING) + } + if (ruleTypeMask & NS_AUTHOR_SPECIFIED_PADDING) { inheritBits |= NS_STYLE_INHERIT_BIT(Padding); - - if (ruleTypeMask & NS_AUTHOR_SPECIFIED_TEXT_SHADOW) + } + if (ruleTypeMask & NS_AUTHOR_SPECIFIED_TEXT_SHADOW) { inheritBits |= NS_STYLE_INHERIT_BIT(Text); - + } // properties in the SIDS, whether or not we care about them size_t nprops = 0, backgroundOffset, borderOffset, paddingOffset, textShadowOffset; @@ -10669,12 +10622,16 @@ nsRuleNode::HasAuthorSpecifiedRules(nsStyleContext* aStyleContext, // eCSSUnit_DummyInherit values to eCSSUnit_Null (so we will be able to // detect them being styled by the author) and move up to our parent // style context. - for (uint32_t i = 0; i < nValues; ++i) - if (values[i]->GetUnit() == eCSSUnit_Null) + for (uint32_t i = 0; i < nValues; ++i) { + if (values[i]->GetUnit() == eCSSUnit_Null) { values[i]->SetDummyValue(); - for (uint32_t i = 0; i < nValues; ++i) - if (values[i]->GetUnit() == eCSSUnit_DummyInherit) + } + } + for (uint32_t i = 0; i < nValues; ++i) { + if (values[i]->GetUnit() == eCSSUnit_DummyInherit) { values[i]->Reset(); + } + } styleContext = styleContext->GetParent(); } } while (haveExplicitUAInherit && styleContext); diff --git a/layout/style/test/test_transitions_per_property.html b/layout/style/test/test_transitions_per_property.html index b7659adb7..83524b60d 100644 --- a/layout/style/test/test_transitions_per_property.html +++ b/layout/style/test/test_transitions_per_property.html @@ -248,7 +248,7 @@ var supported_properties = { // test_length_percent_calc_transition. "stroke-width": [ test_length_transition_svg, test_percent_transition, test_length_clamped_svg, test_percent_clamped ], - "-moz-tab-size": [ test_float_zeroToOne_transition, + "tab-size": [ test_float_zeroToOne_transition, test_float_aboveOne_transition, test_length_clamped ], "text-decoration": [ test_color_shorthand_transition, test_true_currentcolor_shorthand_transition ], -- cgit v1.2.3