tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLHeadingElement.h (2224B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_HTMLHeadingElement_h
      8 #define mozilla_dom_HTMLHeadingElement_h
      9 
     10 #include "nsGenericHTMLElement.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 class HTMLHeadingElement final : public nsGenericHTMLElement {
     15 public:
     16  explicit HTMLHeadingElement(
     17      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     18      : nsGenericHTMLElement(std::move(aNodeInfo)) {
     19    MOZ_ASSERT(IsHTMLHeadingElement());
     20    UpdateLevel(false);
     21  }
     22 
     23  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
     24                      const nsAString& aValue,
     25                      nsIPrincipal* aMaybeScriptedPrincipal,
     26                      nsAttrValue& aResult) override;
     27  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
     28  nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
     29  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     30 
     31  void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
     32    return SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
     33  }
     34  void GetAlign(DOMString& aAlign) const {
     35    return GetHTMLAttr(nsGkAtoms::align, aAlign);
     36  }
     37 
     38  uint32_t ComputedLevel() const {
     39    nsAtom* name = NodeInfo()->NameAtom();
     40    if (name == nsGkAtoms::h1) {
     41      return 1;
     42    }
     43    if (name == nsGkAtoms::h2) {
     44      return 2;
     45    }
     46    if (name == nsGkAtoms::h3) {
     47      return 3;
     48    }
     49    if (name == nsGkAtoms::h4) {
     50      return 4;
     51    }
     52    if (name == nsGkAtoms::h5) {
     53      return 5;
     54    }
     55    MOZ_ASSERT(name == nsGkAtoms::h6);
     56    return 6;
     57  }
     58 
     59  void UpdateLevel(bool aNotify);
     60 
     61  NS_IMPL_FROMNODE_HELPER(HTMLHeadingElement, IsHTMLHeadingElement())
     62 
     63 protected:
     64  virtual ~HTMLHeadingElement();
     65 
     66  JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     67 
     68 private:
     69  static void MapAttributesIntoRule(MappedDeclarationsBuilder&);
     70 };
     71 
     72 }  // namespace mozilla::dom
     73 
     74 #endif  // mozilla_dom_HTMLHeadingElement_h