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/HTMLPreElement.h"
8 #include "mozilla/dom/HTMLPreElementBinding.h"
9
10 #include "mozilla/MappedDeclarations.h"
11 #include "nsAttrValueInlines.h"
12 #include "nsGkAtoms.h"
13 #include "nsStyleConsts.h"
14 #include "nsMappedAttributes.h"
15
16 NS_IMPL_NS_NEW_HTML_ELEMENT(Pre)
17
18 namespace mozilla::dom {
19
20 HTMLPreElement::~HTMLPreElement() = default;
21
NS_IMPL_ELEMENT_CLONE(HTMLPreElement)22 NS_IMPL_ELEMENT_CLONE(HTMLPreElement)
23
24 bool HTMLPreElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
25 const nsAString& aValue,
26 nsIPrincipal* aMaybeScriptedPrincipal,
27 nsAttrValue& aResult) {
28 if (aNamespaceID == kNameSpaceID_None) {
29 if (aAttribute == nsGkAtoms::width) {
30 return aResult.ParseIntValue(aValue);
31 }
32 }
33
34 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
35 aMaybeScriptedPrincipal, aResult);
36 }
37
MapAttributesIntoRule(const nsMappedAttributes * aAttributes,MappedDeclarations & aDecls)38 void HTMLPreElement::MapAttributesIntoRule(
39 const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
40 if (!aDecls.PropertyIsSet(eCSSProperty_white_space)) {
41 // wrap: empty
42 if (aAttributes->GetAttr(nsGkAtoms::wrap))
43 aDecls.SetKeywordValue(eCSSProperty_white_space,
44 StyleWhiteSpace::PreWrap);
45 }
46
47 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
48 }
49
NS_IMETHODIMP_(bool)50 NS_IMETHODIMP_(bool)
51 HTMLPreElement::IsAttributeMapped(const nsAtom* aAttribute) const {
52 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
53 return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
54 }
55
56 static const MappedAttributeEntry attributes[] = {
57 {nsGkAtoms::wrap},
58 {nullptr},
59 };
60
61 static const MappedAttributeEntry* const map[] = {
62 attributes,
63 sCommonAttributeMap,
64 };
65
66 return FindAttributeDependence(aAttribute, map);
67 }
68
GetAttributeMappingFunction() const69 nsMapRuleToAttributesFunc HTMLPreElement::GetAttributeMappingFunction() const {
70 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
71 return nsGenericHTMLElement::GetAttributeMappingFunction();
72 }
73
74 return &MapAttributesIntoRule;
75 }
76
WrapNode(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)77 JSObject* HTMLPreElement::WrapNode(JSContext* aCx,
78 JS::Handle<JSObject*> aGivenProto) {
79 return HTMLPreElement_Binding::Wrap(aCx, this, aGivenProto);
80 }
81
82 } // namespace mozilla::dom
83