diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 8ae8240e3798..f3ca091fb0c5 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -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