Bug 998590 - Cleanup HTMLHeadingElement, and add HTMLHeadingElement::FromNode. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 16 Oct 2019 14:25:05 +0000
changeset 559191 0e06e454c8c8a9286e1416c664dd250704ac81c2
parent 559190 fe2312ad6c4fd03510106cfdbe51480ffcff031d
child 559192 e46f94e125546017360f0a4c1e2f03632f2156af
push id12175
push userccoroiu@mozilla.com
push dateThu, 17 Oct 2019 19:29:09 +0000
treeherdermozilla-beta@d333b6ef1fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs998590
milestone71.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 998590 - Cleanup HTMLHeadingElement, and add HTMLHeadingElement::FromNode. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D49406
dom/base/nsINode.h
dom/html/HTMLHeadingElement.h
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -741,16 +741,21 @@ class nsINode : public mozilla::dom::Eve
   }
 
   bool IsShadowRoot() const {
     const bool isShadowRoot = IsInShadowTree() && !GetParentNode();
     MOZ_ASSERT_IF(isShadowRoot, IsDocumentFragment());
     return isShadowRoot;
   }
 
+  bool IsHTMLHeadingElement() const {
+    return IsAnyOfHTMLElements(nsGkAtoms::h1, nsGkAtoms::h2, nsGkAtoms::h3,
+                               nsGkAtoms::h4, nsGkAtoms::h5, nsGkAtoms::h6);
+  }
+
   /**
    * Insert a content node before another or at the end.
    * This method handles calling BindToTree on the child appropriately.
    *
    * @param aKid the content to insert
    * @param aBeforeThis an existing node. Use nullptr if you want to
    *        add aKid at the end.
    * @param aNotify whether to notify the document (current document for
--- a/dom/html/HTMLHeadingElement.h
+++ b/dom/html/HTMLHeadingElement.h
@@ -12,38 +12,41 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLHeadingElement final : public nsGenericHTMLElement {
  public:
   explicit HTMLHeadingElement(
       already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
-      : nsGenericHTMLElement(std::move(aNodeInfo)) {}
+      : nsGenericHTMLElement(std::move(aNodeInfo)) {
+    MOZ_ASSERT(IsHTMLHeadingElement());
+  }
 
-  virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
-                              const nsAString& aValue,
-                              nsIPrincipal* aMaybeScriptedPrincipal,
-                              nsAttrValue& aResult) override;
+  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
+                      const nsAString& aValue,
+                      nsIPrincipal* aMaybeScriptedPrincipal,
+                      nsAttrValue& aResult) override;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
   nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
-  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
+  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
     return SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
   }
   void GetAlign(DOMString& aAlign) const {
     return GetHTMLAttr(nsGkAtoms::align, aAlign);
   }
 
+  NS_IMPL_FROMNODE_HELPER(HTMLHeadingElement, IsHTMLHeadingElement())
+
  protected:
   virtual ~HTMLHeadingElement();
 
-  virtual JSObject* WrapNode(JSContext* aCx,
-                             JS::Handle<JSObject*> aGivenProto) override;
+  JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
 
  private:
   static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
                                     MappedDeclarations&);
 };
 
 }  // namespace dom
 }  // namespace mozilla