Bug 1365162 - Part 4: Add FFI functions for getting the relevant lang attribute value for an element or snapshot. r=emilio draft
authorCameron McCormack <cam@mcc.id.au>
Wed, 07 Jun 2017 12:16:52 +0800
changeset 590156 f8690b1f0638735546fe29fae35d5e08cd08f4a2
parent 590155 732696be18d2680a6d35adeba71259128c35a3f5
child 590157 34ecd37a22fc0076193ea8481a3fbd6f006c1667
push id62612
push userbmo:cam@mcc.id.au
push dateWed, 07 Jun 2017 07:54:44 +0000
reviewersemilio
bugs1365162
milestone55.0a1
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
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
--- 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,           \