From cc43119a670572b9e8e399cda582af7ad1f5f20e Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 8 Dec 2015 03:12:44 +1100 Subject: [PATCH] Bug 1040668 followup 3 - Wrap lang attribute mapping code in NS_STYLE_INHERIT_BIT test. r=dbaron --HG-- extra : source : 08c7fa7f0d4563c69b3a17ae676eaddfed237034 --- dom/html/nsGenericHTMLElement.cpp | 63 +++++++++++++++++++------------ 1 file changed, 38 insertions(+), 25 deletions(-) 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