Bug 1449089 part 4 - Move logic of nsCSSPseudoClasses::LangPseudoMatches into Gecko_MatchLang. r?emilio
MozReview-Commit-ID: 6c6TooaU6dQ
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -839,21 +839,48 @@ Gecko_GetLookAndFeelSystemColor(int32_t
bool
Gecko_MatchLang(RawGeckoElementBorrowed aElement,
nsAtom* aOverrideLang,
bool aHasOverrideLang,
const char16_t* aValue)
{
MOZ_ASSERT(!(aOverrideLang && !aHasOverrideLang),
"aHasOverrideLang should only be set when aOverrideLang is null");
-
- return nsCSSPseudoClasses::LangPseudoMatches(
- aElement,
- aHasOverrideLang ? aOverrideLang : nullptr,
- aHasOverrideLang, aValue, aElement->OwnerDoc());
+ MOZ_ASSERT(aValue, "null lang parameter");
+ if (!aValue || !*aValue) {
+ return false;
+ }
+
+ // We have to determine the language of the current element. Since
+ // this is currently no property and since the language is inherited
+ // from the parent we have to be prepared to look at all parent
+ // nodes. The language itself is encoded in the LANG attribute.
+ if (auto* language = aHasOverrideLang ? aOverrideLang : aElement->GetLang()) {
+ return nsStyleUtil::DashMatchCompare(nsDependentAtomString(language),
+ nsDependentString(aValue),
+ nsASCIICaseInsensitiveStringComparator());
+ }
+
+ // Try to get the language from the HTTP header or if this
+ // is missing as well from the preferences.
+ // The content language can be a comma-separated list of
+ // language codes.
+ nsAutoString language;
+ aElement->OwnerDoc()->GetContentLanguage(language);
+
+ nsDependentString langString(aValue);
+ language.StripWhitespace();
+ for (auto const& lang : language.Split(char16_t(','))) {
+ if (nsStyleUtil::DashMatchCompare(lang,
+ langString,
+ nsASCIICaseInsensitiveStringComparator())) {
+ return true;
+ }
+ }
+ return false;
}
nsAtom*
Gecko_GetXMLLangValue(RawGeckoElementBorrowed aElement)
{
const nsAttrValue* attr =
aElement->GetParsedAttr(nsGkAtoms::lang, kNameSpaceID_XML);
--- a/layout/style/nsCSSPseudoClasses.cpp
+++ b/layout/style/nsCSSPseudoClasses.cpp
@@ -165,61 +165,16 @@ nsCSSPseudoClasses::IsUserActionPseudoCl
{
// See http://dev.w3.org/csswg/selectors4/#useraction-pseudos
return aType == Type::hover ||
aType == Type::active ||
aType == Type::focus;
}
/* static */ bool
-nsCSSPseudoClasses::LangPseudoMatches(const mozilla::dom::Element* aElement,
- const nsAtom* aOverrideLang,
- bool aHasOverrideLang,
- const char16_t* aString,
- const nsIDocument* aDocument)
-{
- NS_ASSERTION(aString, "null lang parameter");
- if (!aString || !*aString) {
- return false;
- }
-
- // We have to determine the language of the current element. Since
- // this is currently no property and since the language is inherited
- // from the parent we have to be prepared to look at all parent
- // nodes. The language itself is encoded in the LANG attribute.
- if (auto* language = aHasOverrideLang ? aOverrideLang : aElement->GetLang()) {
- return nsStyleUtil::DashMatchCompare(nsDependentAtomString(language),
- nsDependentString(aString),
- nsASCIICaseInsensitiveStringComparator());
- }
-
- if (!aDocument) {
- return false;
- }
-
- // Try to get the language from the HTTP header or if this
- // is missing as well from the preferences.
- // The content language can be a comma-separated list of
- // language codes.
- nsAutoString language;
- aDocument->GetContentLanguage(language);
-
- nsDependentString langString(aString);
- language.StripWhitespace();
- for (auto const& lang : language.Split(char16_t(','))) {
- if (nsStyleUtil::DashMatchCompare(lang,
- langString,
- nsASCIICaseInsensitiveStringComparator())) {
- return true;
- }
- }
- return false;
-}
-
-/* static */ bool
nsCSSPseudoClasses::StringPseudoMatches(const mozilla::dom::Element* aElement,
CSSPseudoClassType aPseudo,
const char16_t* aString,
const nsIDocument* aDocument,
EventStates aStateMask,
bool* const aDependence)
{
@@ -275,22 +230,16 @@ nsCSSPseudoClasses::StringPseudoMatches(
}
} else {
// Selectors specifying other directions never match.
return false;
}
}
break;
- case CSSPseudoClassType::lang:
- if (LangPseudoMatches(aElement, nullptr, false, aString, aDocument)) {
- break;
- }
- return false;
-
default: MOZ_ASSERT_UNREACHABLE("Called StringPseudoMatches() with unknown string-like pseudo");
}
return true;
}
/* static */ Maybe<bool>
nsCSSPseudoClasses::MatchesElement(Type aType, const dom::Element* aElement)
{
--- a/layout/style/nsCSSPseudoClasses.h
+++ b/layout/style/nsCSSPseudoClasses.h
@@ -118,22 +118,16 @@ public:
*/
static bool StringPseudoMatches(const mozilla::dom::Element* aElement,
mozilla::CSSPseudoClassType aPseudo,
const char16_t* aString,
const nsIDocument* aDocument,
mozilla::EventStates aStateMask,
bool* const aDependence = nullptr);
- static bool LangPseudoMatches(const mozilla::dom::Element* aElement,
- const nsAtom* aOverrideLang,
- bool aHasOverrideLang,
- const char16_t* aString,
- const nsIDocument* aDocument);
-
static const mozilla::EventStates sPseudoClassStateDependences[size_t(Type::Count) + 2];
private:
static const uint32_t kPseudoClassFlags[size_t(Type::Count)];
static bool sPseudoClassEnabled[size_t(Type::Count)];
};
#endif /* nsCSSPseudoClasses_h___ */