Bug 1365162 - Part 4: Add FFI functions for getting the relevant lang attribute value for an element or snapshot. r=emilio
MozReview-Commit-ID: 6xL0FI2qrG1
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -812,16 +812,35 @@ Gecko_GetXMLLangValue(RawGeckoElementBor
template <typename Implementor>
static nsIAtom*
AtomAttrValue(Implementor* aElement, nsIAtom* aName)
{
const nsAttrValue* attr = aElement->GetParsedAttr(aName);
return attr ? attr->GetAtomValue() : nullptr;
}
+template <typename Implementor>
+static nsIAtom*
+LangValue(Implementor* aElement)
+{
+ const nsAttrValue* attr =
+ aElement->GetParsedAttr(nsGkAtoms::lang, kNameSpaceID_XML);
+ if (!attr && aElement->SupportsLangAttr()) {
+ attr = aElement->GetParsedAttr(nsGkAtoms::lang);
+ }
+
+ if (!attr) {
+ return nullptr;
+ }
+
+ nsString lang;
+ attr->ToString(lang);
+ return NS_Atomize(lang).take();
+}
+
template <typename Implementor, typename MatchFn>
static bool
DoMatch(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName, MatchFn aMatch)
{
if (aNS) {
int32_t ns = nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNS,
aElement->IsInChromeDocument());
NS_ENSURE_TRUE(ns != kNameSpaceID_Unknown, false);
@@ -994,16 +1013,20 @@ ClassOrClassList(Implementor* aElement,
return atomArray->Length();
}
#define SERVO_IMPL_ELEMENT_ATTR_MATCHING_FUNCTIONS(prefix_, implementor_) \
nsIAtom* prefix_##AtomAttrValue(implementor_ aElement, nsIAtom* aName) \
{ \
return AtomAttrValue(aElement, aName); \
} \
+ nsIAtom* prefix_##LangValue(implementor_ aElement) \
+ { \
+ return LangValue(aElement); \
+ } \
bool prefix_##HasAttr(implementor_ aElement, nsIAtom* aNS, nsIAtom* aName) \
{ \
return HasAttr(aElement, aNS, aName); \
} \
bool prefix_##AttrEquals(implementor_ aElement, nsIAtom* aNS, \
nsIAtom* aName, nsIAtom* aStr, bool aIgnoreCase) \
{ \
return AttrEquals(aElement, aNS, aName, aStr, aIgnoreCase); \
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -164,16 +164,17 @@ nsIAtom* Gecko_LocalName(RawGeckoElement
nsIAtom* Gecko_Namespace(RawGeckoElementBorrowed element);
nsIAtom* Gecko_GetElementId(RawGeckoElementBorrowed element);
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, \
nsIAtom* str, bool ignoreCase); \
bool prefix_##AttrDashEquals(implementor_ element, nsIAtom* ns, \
nsIAtom* name, nsIAtom* str); \
bool prefix_##AttrIncludes(implementor_ element, nsIAtom* ns, \
nsIAtom* name, nsIAtom* str); \
bool prefix_##AttrHasSubstring(implementor_ element, nsIAtom* ns, \