Backed out changeset 62f7af8fe549 (bug 1843981) for causing valgrind bustage. CLOSED...
[gecko.git] / dom / html / HTMLPreElement.cpp
blobfeaa764bd59433b7c3a0c796c1c24f6ce41b24ed
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/. */
7 #include "mozilla/dom/HTMLPreElement.h"
8 #include "mozilla/dom/HTMLPreElementBinding.h"
10 #include "mozilla/MappedDeclarationsBuilder.h"
11 #include "nsAttrValueInlines.h"
12 #include "nsGkAtoms.h"
13 #include "nsStyleConsts.h"
15 NS_IMPL_NS_NEW_HTML_ELEMENT(Pre)
17 namespace mozilla::dom {
19 HTMLPreElement::~HTMLPreElement() = default;
21 NS_IMPL_ELEMENT_CLONE(HTMLPreElement)
23 bool HTMLPreElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
24 const nsAString& aValue,
25 nsIPrincipal* aMaybeScriptedPrincipal,
26 nsAttrValue& aResult) {
27 if (aNamespaceID == kNameSpaceID_None) {
28 if (aAttribute == nsGkAtoms::width) {
29 return aResult.ParseIntValue(aValue);
33 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
34 aMaybeScriptedPrincipal, aResult);
37 void HTMLPreElement::MapAttributesIntoRule(
38 MappedDeclarationsBuilder& aBuilder) {
39 // wrap: empty
40 if (aBuilder.GetAttr(nsGkAtoms::wrap)) {
41 aBuilder.SetKeywordValue(eCSSProperty_white_space,
42 StyleWhiteSpace::PreWrap);
45 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
48 NS_IMETHODIMP_(bool)
49 HTMLPreElement::IsAttributeMapped(const nsAtom* aAttribute) const {
50 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
51 return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
54 static const MappedAttributeEntry attributes[] = {
55 {nsGkAtoms::wrap},
56 {nullptr},
59 static const MappedAttributeEntry* const map[] = {
60 attributes,
61 sCommonAttributeMap,
64 return FindAttributeDependence(aAttribute, map);
67 nsMapRuleToAttributesFunc HTMLPreElement::GetAttributeMappingFunction() const {
68 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
69 return nsGenericHTMLElement::GetAttributeMappingFunction();
72 return &MapAttributesIntoRule;
75 JSObject* HTMLPreElement::WrapNode(JSContext* aCx,
76 JS::Handle<JSObject*> aGivenProto) {
77 return HTMLPreElement_Binding::Wrap(aCx, this, aGivenProto);
80 } // namespace mozilla::dom