summaryrefslogtreecommitdiffstats
path: root/layout/style/nsRuleNode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'layout/style/nsRuleNode.cpp')
-rw-r--r--layout/style/nsRuleNode.cpp96
1 files changed, 70 insertions, 26 deletions
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 {