summaryrefslogtreecommitdiffstats
path: root/layout/style
diff options
context:
space:
mode:
authorathenian200 <athenian200@outlook.com>2020-10-23 14:34:55 -0500
committerMoonchild <moonchild@palemoon.org>2020-11-18 10:51:09 +0000
commit4dae04e594f6662dcfb03fd304494841ca542091 (patch)
tree4c0e3d936c8504f84ab55b3d864d505f1033e7f1 /layout/style
parentb9c41e262438d85e2b3f0fb7905b69818ff875aa (diff)
downloadUXP-4dae04e594f6662dcfb03fd304494841ca542091.tar
UXP-4dae04e594f6662dcfb03fd304494841ca542091.tar.gz
UXP-4dae04e594f6662dcfb03fd304494841ca542091.tar.lz
UXP-4dae04e594f6662dcfb03fd304494841ca542091.tar.xz
UXP-4dae04e594f6662dcfb03fd304494841ca542091.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/style')
-rw-r--r--layout/style/nsCSSPropList.h2
-rw-r--r--layout/style/nsComputedDOMStyle.cpp2
-rw-r--r--layout/style/nsRuleNode.cpp96
-rw-r--r--layout/style/nsStyleStruct.cpp4
-rw-r--r--layout/style/nsStyleStruct.h2
-rw-r--r--layout/style/test/property_database.js6
6 files changed, 79 insertions, 33 deletions
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<CSSValue>
nsComputedDOMStyle::DoGetTabSize()
{
RefPtr<nsROCSSPrimitiveValue> 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",