Bug 1365162 - Part 2: Factor out lang="" namespace checks. r=emilio draft
authorCameron McCormack <cam@mcc.id.au>
Wed, 07 Jun 2017 11:10:07 +0800
changeset 590154 69293fa3683e504ffd581563b3625a5a4238d4de
parent 590153 a2b131e57c9f2caac9eac23ec026175edd43e003
child 590155 732696be18d2680a6d35adeba71259128c35a3f5
push id62612
push userbmo:cam@mcc.id.au
push dateWed, 07 Jun 2017 07:54:44 +0000
reviewersemilio
bugs1365162
milestone55.0a1
Bug 1365162 - Part 2: Factor out lang="" namespace checks. r=emilio MozReview-Commit-ID: CBwV3xB5sz9
dom/base/nsIContent.h
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -916,30 +916,33 @@ public:
 
   /**
    * If the content is a part of HTML editor, this returns editing
    * host content.  When the content is in designMode, this returns its body
    * element.  Also, when the content isn't editable, this returns null.
    */
   mozilla::dom::Element* GetEditingHost();
 
+  bool SupportsLangAttr() const {
+    return IsHTMLElement() || IsSVGElement() || IsXULElement();
+  }
+
   /**
    * Determining language. Look at the nearest ancestor element that has a lang
    * attribute in the XML namespace or is an HTML/SVG element and has a lang in
    * no namespace attribute.  Returns false if no language was specified.
    */
   bool GetLang(nsAString& aResult) const {
     for (const nsIContent* content = this; content; content = content->GetParent()) {
       if (content->GetAttrCount() > 0) {
         // xml:lang has precedence over lang on HTML elements (see
         // XHTML1 section C.7).
         bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
                                           aResult);
-        if (!hasAttr && (content->IsHTMLElement() || content->IsSVGElement() ||
-            content->IsXULElement())) {
+        if (!hasAttr && content->SupportsLangAttr()) {
           hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
                                      aResult);
         }
         NS_ASSERTION(hasAttr || aResult.IsEmpty(),
                      "GetAttr that returns false should not make string non-empty");
         if (hasAttr) {
           return true;
         }