tor-browser

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

HTMLBRElement.cpp (2694B)


      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/HTMLBRElement.h"
      8 
      9 #include "mozilla/MappedDeclarationsBuilder.h"
     10 #include "mozilla/dom/HTMLBRElementBinding.h"
     11 #include "nsAttrValueInlines.h"
     12 #include "nsStyleConsts.h"
     13 
     14 NS_IMPL_NS_NEW_HTML_ELEMENT(BR)
     15 
     16 namespace mozilla::dom {
     17 
     18 HTMLBRElement::HTMLBRElement(
     19    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     20    : nsGenericHTMLElement(std::move(aNodeInfo)) {}
     21 
     22 HTMLBRElement::~HTMLBRElement() = default;
     23 
     24 NS_IMPL_ELEMENT_CLONE(HTMLBRElement)
     25 
     26 static constexpr nsAttrValue::EnumTableEntry kClearTable[] = {
     27    {"left", StyleClear::Left},
     28    {"right", StyleClear::Right},
     29    {"all", StyleClear::Both},
     30    {"both", StyleClear::Both},
     31 };
     32 
     33 bool HTMLBRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
     34                                   const nsAString& aValue,
     35                                   nsIPrincipal* aMaybeScriptedPrincipal,
     36                                   nsAttrValue& aResult) {
     37  if (aAttribute == nsGkAtoms::clear && aNamespaceID == kNameSpaceID_None) {
     38    return aResult.ParseEnumValue(aValue, kClearTable, false);
     39  }
     40 
     41  return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
     42                                              aMaybeScriptedPrincipal, aResult);
     43 }
     44 
     45 void HTMLBRElement::MapAttributesIntoRule(MappedDeclarationsBuilder& aBuilder) {
     46  if (!aBuilder.PropertyIsSet(eCSSProperty_clear)) {
     47    const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::clear);
     48    if (value && value->Type() == nsAttrValue::eEnum) {
     49      aBuilder.SetKeywordValue(eCSSProperty_clear, value->GetEnumValue());
     50    }
     51  }
     52  nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
     53 }
     54 
     55 NS_IMETHODIMP_(bool)
     56 HTMLBRElement::IsAttributeMapped(const nsAtom* aAttribute) const {
     57  static const MappedAttributeEntry attributes[] = {{nsGkAtoms::clear},
     58                                                    {nullptr}};
     59 
     60  static const MappedAttributeEntry* const map[] = {
     61      attributes,
     62      sCommonAttributeMap,
     63  };
     64 
     65  return FindAttributeDependence(aAttribute, map);
     66 }
     67 
     68 nsMapRuleToAttributesFunc HTMLBRElement::GetAttributeMappingFunction() const {
     69  return &MapAttributesIntoRule;
     70 }
     71 
     72 JSObject* HTMLBRElement::WrapNode(JSContext* aCx,
     73                                  JS::Handle<JSObject*> aGivenProto) {
     74  return HTMLBRElement_Binding::Wrap(aCx, this, aGivenProto);
     75 }
     76 
     77 }  // namespace mozilla::dom