tor-browser

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

HTMLHeadingElement.cpp (2726B)


      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 #include "mozilla/dom/HTMLHeadingElement.h"
      8 
      9 #include "mozilla/MappedDeclarationsBuilder.h"
     10 #include "mozilla/dom/HTMLHeadingElementBinding.h"
     11 #include "nsGkAtoms.h"
     12 
     13 NS_IMPL_NS_NEW_HTML_ELEMENT(Heading)
     14 
     15 namespace mozilla::dom {
     16 
     17 HTMLHeadingElement::~HTMLHeadingElement() = default;
     18 
     19 NS_IMPL_ELEMENT_CLONE(HTMLHeadingElement)
     20 
     21 JSObject* HTMLHeadingElement::WrapNode(JSContext* aCx,
     22                                       JS::Handle<JSObject*> aGivenProto) {
     23  return HTMLHeadingElement_Binding::Wrap(aCx, this, aGivenProto);
     24 }
     25 
     26 bool HTMLHeadingElement::ParseAttribute(int32_t aNamespaceID,
     27                                        nsAtom* aAttribute,
     28                                        const nsAString& aValue,
     29                                        nsIPrincipal* aMaybeScriptedPrincipal,
     30                                        nsAttrValue& aResult) {
     31  if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
     32    return ParseDivAlignValue(aValue, aResult);
     33  }
     34 
     35  return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
     36                                              aMaybeScriptedPrincipal, aResult);
     37 }
     38 
     39 void HTMLHeadingElement::UpdateLevel(bool aNotify) {
     40  AutoStateChangeNotifier notifier(*this, aNotify);
     41  RemoveStatesSilently(ElementState::HEADING_LEVEL_BITS);
     42  uint64_t level = ComputedLevel();
     43 
     44  // ElementState has 4 bits for the heading level, but they are not the LMB,
     45  // so we need to shift the given level up to those bits.
     46  MOZ_ASSERT(level > 0 && level < 16, "ComputedLevel() must fit into 4 bits!");
     47  uint64_t bits = (level << HEADING_LEVEL_OFFSET);
     48  MOZ_ASSERT((bits & ElementState::HEADING_LEVEL_BITS.bits) == bits);
     49 
     50  AddStatesSilently(ElementState(bits));
     51 }
     52 
     53 void HTMLHeadingElement::MapAttributesIntoRule(
     54    MappedDeclarationsBuilder& aBuilder) {
     55  nsGenericHTMLElement::MapDivAlignAttributeInto(aBuilder);
     56  nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
     57 }
     58 
     59 NS_IMETHODIMP_(bool)
     60 HTMLHeadingElement::IsAttributeMapped(const nsAtom* aAttribute) const {
     61  static const MappedAttributeEntry* const map[] = {sDivAlignAttributeMap,
     62                                                    sCommonAttributeMap};
     63 
     64  return FindAttributeDependence(aAttribute, map);
     65 }
     66 
     67 nsMapRuleToAttributesFunc HTMLHeadingElement::GetAttributeMappingFunction()
     68    const {
     69  return &MapAttributesIntoRule;
     70 }
     71 
     72 }  // namespace mozilla::dom