Bug 1365162 - Part 4: Add FFI functions for getting the relevant lang attribute value for an element or snapshot. r=emilio
authorCameron McCormack <cam@mcc.id.au>
Wed, 07 Jun 2017 12:16:52 +0800
changeset 411013 c1cac2541d866bdca8d405df2ba432f6d65ccb6f
parent 411012 e10c7dba03490b6c74c8b3cdcb11948684e8e867
child 411014 383f5061c80eda1a9579283d29f64ccbe5d8db3f
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1365162
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -811,16 +811,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);
@@ -993,16 +1012,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,           \