Bug 1040668 followup 3 - Wrap lang attribute mapping code in NS_STYLE_INHERIT_BIT test. r=dbaron

This commit is contained in:
Xidorn Quan 2015-12-08 03:12:44 +11:00
parent 1d090d34c2
commit 0360da3bb8

View File

@ -1301,6 +1301,43 @@ nsGenericHTMLElement::ParseScrollingValue(const nsAString& aString,
return aResult.ParseEnumValue(aString, kScrollingTable, false);
}
static inline void
MapLangAttributeInto(const nsMappedAttributes* aAttributes, nsRuleData* aData)
{
if (!(aData->mSIDs & (NS_STYLE_INHERIT_BIT(Font) |
NS_STYLE_INHERIT_BIT(Text)))) {
return;
}
const nsAttrValue* langValue = aAttributes->GetAttr(nsGkAtoms::lang);
if (!langValue || langValue->Type() != nsAttrValue::eString) {
return;
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
nsCSSValue* lang = aData->ValueForLang();
if (lang->GetUnit() == eCSSUnit_Null) {
lang->SetStringValue(langValue->GetStringValue(), eCSSUnit_Ident);
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
nsCSSValue* emphasisPos = aData->ValueForTextEmphasisPosition();
if (emphasisPos->GetUnit() == eCSSUnit_Null) {
const nsAString& lang = langValue->GetStringValue();
if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("zh"))) {
emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH,
eCSSUnit_Enumerated);
} else if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("ja")) ||
nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("mn"))) {
// This branch is currently no part of the spec.
// See bug 1040668 comment 69 and comment 75.
emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT,
eCSSUnit_Enumerated);
}
}
}
}
/**
* Handle attributes common to all html elements
*/
@ -1327,31 +1364,7 @@ nsGenericHTMLElement::MapCommonAttributesIntoExceptHidden(const nsMappedAttribut
}
}
const nsAttrValue* langValue = aAttributes->GetAttr(nsGkAtoms::lang);
if (langValue && langValue->Type() == nsAttrValue::eString) {
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
nsCSSValue* lang = aData->ValueForLang();
if (lang->GetUnit() == eCSSUnit_Null) {
lang->SetStringValue(langValue->GetStringValue(), eCSSUnit_Ident);
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
nsCSSValue* emphasisPos = aData->ValueForTextEmphasisPosition();
if (emphasisPos->GetUnit() == eCSSUnit_Null) {
const nsAString& lang = langValue->GetStringValue();
if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("zh"))) {
emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH,
eCSSUnit_Enumerated);
} else if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("ja")) ||
nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("mn"))) {
// This branch is currently no part of the spec.
// See bug 1040668 comment 69 and comment 75.
emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT,
eCSSUnit_Enumerated);
}
}
}
}
MapLangAttributeInto(aAttributes, aData);
}
void