Bug 838506 - Part 1: Add a -moz-math-display property. r=heycam

This commit is contained in:
Frédéric Wang 2014-01-14 09:39:50 -05:00
parent a8fb7fbeeb
commit 3feaa3f08b
10 changed files with 62 additions and 11 deletions

View File

@ -7933,8 +7933,11 @@ CSSParserImpl::ParseSingleValueProperty(nsCSSValue& aValue,
// We only allow 'script-level' when unsafe rules are enabled, because
// otherwise it could interfere with rulenode optimizations if used in
// a non-MathML-enabled document.
if (aPropID == eCSSProperty_script_level && !mUnsafeRulesEnabled)
// a non-MathML-enabled document. We also only allow math-display when
// unsafe rules are enabled.
if (!mUnsafeRulesEnabled &&
(aPropID == eCSSProperty_script_level ||
aPropID == eCSSProperty_math_display))
return false;
const int32_t *kwtable = nsCSSProps::kKeywordTableTable[aPropID];

View File

@ -3356,9 +3356,10 @@ CSS_PROP_FONT(
// property when mUnsafeRulesEnabled is set.
CSS_PROPERTY_PARSE_VALUE,
"",
// script-level can take Integer or Number values, but only Integer
// script-level can take Auto, Integer and Number values, but only Auto
// ("increment if parent is not in displaystyle") and Integer
// ("relative") values can be specified in a style sheet.
VARIANT_HI,
VARIANT_AHI,
nullptr,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -3394,6 +3395,18 @@ CSS_PROP_FONT(
kMathVariantKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
CSS_PROP_FONT(
-moz-math-display,
math_display,
MathDisplay,
// NOTE: CSSParserImpl::ParseSingleValueProperty only accepts this
// property when mUnsafeRulesEnabled is set.
CSS_PROPERTY_PARSE_VALUE,
"",
VARIANT_HK,
kMathDisplayKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
#endif // !defined(CSS_PROP_LIST_EXCLUDE_INTERNAL)
#endif // !defined(CSS_PROP_LIST_ONLY_COMPONENTS_OF_ALL_SHORTHAND)

View File

@ -1356,6 +1356,12 @@ const int32_t nsCSSProps::kMathVariantKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kMathDisplayKTable[] = {
eCSSKeyword_inline, NS_MATHML_DISPLAYSTYLE_INLINE,
eCSSKeyword_block, NS_MATHML_DISPLAYSTYLE_BLOCK,
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kContextOpacityKTable[] = {
eCSSKeyword_context_fill_opacity, NS_STYLE_CONTEXT_FILL_OPACITY,
eCSSKeyword_context_stroke_opacity, NS_STYLE_CONTEXT_STROKE_OPACITY,

View File

@ -522,6 +522,7 @@ public:
static const int32_t kListStyleKTable[];
static const int32_t kMaskTypeKTable[];
static const int32_t kMathVariantKTable[];
static const int32_t kMathDisplayKTable[];
static const int32_t kContextOpacityKTable[];
static const int32_t kContextPatternKTable[];
static const int32_t kOrientKTable[];

View File

@ -1861,7 +1861,8 @@ AreAllMathMLPropertiesUndefined(const nsRuleData* aRuleData)
aRuleData->ValueForScriptLevel()->GetUnit() == eCSSUnit_Null &&
aRuleData->ValueForScriptSizeMultiplier()->GetUnit() == eCSSUnit_Null &&
aRuleData->ValueForScriptMinSize()->GetUnit() == eCSSUnit_Null &&
aRuleData->ValueForMathVariant()->GetUnit() == eCSSUnit_Null;
aRuleData->ValueForMathVariant()->GetUnit() == eCSSUnit_Null &&
aRuleData->ValueForMathDisplay()->GetUnit() == eCSSUnit_Null;
}
#endif
@ -1911,13 +1912,13 @@ nsRuleNode::CheckSpecifiedProperties(const nsStyleStructID aSID,
if (inherited == total)
result = eRuleFullInherited;
else if (specified == total
// MathML defines 4 properties in Font that will never be set when
// MathML is not in use. Therefore if all but four
// 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
// this as fully specified. Code in nsMathMLElementFactory will
// rebuild the rule tree and style data when MathML is first enabled
// (see nsMathMLElement::BindToTree).
|| (aSID == eStyleStruct_Font && specified + 4 == total &&
|| (aSID == eStyleStruct_Font && specified + 5 == total &&
!mPresContext->Document()->GetMathMLEnabled())
) {
if (inherited == 0)
@ -3339,6 +3340,13 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
aParentFont->mMathVariant, NS_MATHML_MATHVARIANT_NONE,
0, 0, 0, 0);
// -moz-math-display: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForMathDisplay(), aFont->mMathDisplay,
aCanStoreInRuleTree,
SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
aParentFont->mMathDisplay, NS_MATHML_DISPLAYSTYLE_INLINE,
0, 0, 0, 0);
// font-smoothing: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForOSXFontSmoothing(),
aFont->mFont.smoothing, aCanStoreInRuleTree,
@ -3448,12 +3456,20 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
const nsCSSValue* scriptLevelValue = aRuleData->ValueForScriptLevel();
if (eCSSUnit_Integer == scriptLevelValue->GetUnit()) {
// "relative"
aCanStoreInRuleTree = false;
aFont->mScriptLevel = ClampTo8Bit(aParentFont->mScriptLevel + scriptLevelValue->GetIntValue());
}
else if (eCSSUnit_Number == scriptLevelValue->GetUnit()) {
// "absolute"
aFont->mScriptLevel = ClampTo8Bit(int32_t(scriptLevelValue->GetFloatValue()));
}
else if (eCSSUnit_Auto == scriptLevelValue->GetUnit()) {
// auto
aCanStoreInRuleTree = false;
aFont->mScriptLevel = ClampTo8Bit(aParentFont->mScriptLevel +
(aParentFont->mMathDisplay ==
NS_MATHML_DISPLAYSTYLE_INLINE ? 1 : 0));
}
else if (eCSSUnit_Inherit == scriptLevelValue->GetUnit() ||
eCSSUnit_Unset == scriptLevelValue->GetUnit()) {
aCanStoreInRuleTree = false;

View File

@ -554,6 +554,10 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_MATHML_MATHVARIANT_LOOPED 17
#define NS_MATHML_MATHVARIANT_STRETCHED 18
// See nsStyleFont::mMathDisplay
#define NS_MATHML_DISPLAYSTYLE_INLINE 0
#define NS_MATHML_DISPLAYSTYLE_BLOCK 1
// See nsStylePosition::mWidth, mMinWidth, mMaxWidth
#define NS_STYLE_WIDTH_MAX_CONTENT 0
#define NS_STYLE_WIDTH_MIN_CONTENT 1

View File

@ -81,7 +81,9 @@ nsInitialStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
index == nsCSSProps::PropertyIndexInStruct(
eCSSProperty_script_min_size) ||
index == nsCSSProps::PropertyIndexInStruct(
eCSSProperty_math_variant)) {
eCSSProperty_math_variant) ||
index == nsCSSProps::PropertyIndexInStruct(
eCSSProperty_math_display)) {
continue;
}
}

View File

@ -102,6 +102,7 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
, mGenericID(aSrc.mGenericID)
, mScriptLevel(aSrc.mScriptLevel)
, mMathVariant(aSrc.mMathVariant)
, mMathDisplay(aSrc.mMathDisplay)
, mExplicitLanguage(aSrc.mExplicitLanguage)
, mAllowZoom(aSrc.mAllowZoom)
, mScriptUnconstrainedSize(aSrc.mScriptUnconstrainedSize)
@ -133,6 +134,7 @@ nsStyleFont::Init(nsPresContext* aPresContext)
mScriptLevel = 0;
mScriptSizeMultiplier = NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER;
mMathVariant = NS_MATHML_MATHVARIANT_NONE;
mMathDisplay = NS_MATHML_DISPLAYSTYLE_INLINE;
mAllowZoom = true;
nsAutoString language;
@ -194,7 +196,8 @@ nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aOther) const
if (mSize != aOther.mSize ||
mLanguage != aOther.mLanguage ||
mExplicitLanguage != aOther.mExplicitLanguage ||
mMathVariant != aOther.mMathVariant) {
mMathVariant != aOther.mMathVariant ||
mMathDisplay != aOther.mMathDisplay) {
return NS_STYLE_HINT_REFLOW;
}
return CalcFontDifference(mFont, aOther.mFont);

View File

@ -109,6 +109,8 @@ public:
int8_t mScriptLevel; // [inherited]
// MathML mathvariant support
uint8_t mMathVariant; // [inherited]
// MathML displaystyle support
uint8_t mMathDisplay; // [inherited]
// was mLanguage set based on a lang attribute in the document?
bool mExplicitLanguage; // [inherited]

View File

@ -147,7 +147,8 @@ const char *gInaccessibleProperties[] = {
"-moz-script-level", // parsed by UA sheets only
"-moz-script-size-multiplier",
"-moz-script-min-size",
"-moz-math-variant"
"-moz-math-variant",
"-moz-math-display" // parsed by UA sheets only
};
inline int