Bug 1365162 - Part 6: Add FFI function for matching :lang(). r=emilio
MozReview-Commit-ID: 4iFDJpzQ3p8
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -794,16 +794,40 @@ Gecko_MatchStringArgPseudo(RawGeckoEleme
bool* aSetSlowSelectorFlag)
{
EventStates dummyMask; // mask is never read because we pass aDependence=nullptr
return nsCSSRuleProcessor::StringPseudoMatches(aElement, aType, aIdent,
aElement->OwnerDoc(), true,
dummyMask, aSetSlowSelectorFlag, nullptr);
}
+bool
+Gecko_MatchLang(RawGeckoElementBorrowed aElement,
+ nsIAtom* aOverrideLang,
+ bool aHasOverrideLang,
+ const char16_t* aValue)
+{
+ MOZ_ASSERT(!(aOverrideLang && !aHasOverrideLang),
+ "aHasOverrideLang should only be set when aOverrideLang is null");
+
+ if (!aHasOverrideLang) {
+ return nsCSSRuleProcessor::LangPseudoMatches(aElement, nullptr, false,
+ aValue, aElement->OwnerDoc());
+ }
+
+ if (aOverrideLang) {
+ nsDependentAtomString overrideLang(aOverrideLang);
+ return nsCSSRuleProcessor::LangPseudoMatches(aElement, &overrideLang, true,
+ aValue, aElement->OwnerDoc());
+ }
+
+ return nsCSSRuleProcessor::LangPseudoMatches(aElement, nullptr, true,
+ aValue, aElement->OwnerDoc());
+}
+
nsIAtom*
Gecko_GetXMLLangValue(RawGeckoElementBorrowed aElement)
{
nsString string;
if (aElement->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang, string)) {
return NS_Atomize(string).take();
}
return nullptr;
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -158,17 +158,19 @@ RawGeckoNodeBorrowedOrNull Gecko_GetNext
// Selector Matching.
uint64_t Gecko_ElementState(RawGeckoElementBorrowed element);
bool Gecko_IsTextNode(RawGeckoNodeBorrowed node);
bool Gecko_IsRootElement(RawGeckoElementBorrowed element);
bool Gecko_MatchesElement(mozilla::CSSPseudoClassType type, RawGeckoElementBorrowed element);
nsIAtom* Gecko_LocalName(RawGeckoElementBorrowed element);
nsIAtom* Gecko_Namespace(RawGeckoElementBorrowed element);
nsIAtom* Gecko_GetElementId(RawGeckoElementBorrowed element);
-
+bool Gecko_MatchLang(RawGeckoElementBorrowed element,
+ nsIAtom* override_lang, bool has_override_lang,
+ const char16_t* value);
nsIAtom* Gecko_GetXMLLangValue(RawGeckoElementBorrowed element);
// Attributes.
#define SERVO_DECLARE_ELEMENT_ATTR_MATCHING_FUNCTIONS(prefix_, implementor_) \
nsIAtom* prefix_##AtomAttrValue(implementor_ element, nsIAtom* attribute); \
nsIAtom* prefix_##LangValue(implementor_ element); \
bool prefix_##HasAttr(implementor_ element, nsIAtom* ns, nsIAtom* name); \
bool prefix_##AttrEquals(implementor_ element, nsIAtom* ns, nsIAtom* name, \