Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLPreElement.cpp
blobc3f7185706ddfa64af7c2b7dd7482d840989cb3e
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/MappedDeclarations.h"
11 #include "nsAttrValueInlines.h"
12 #include "nsGkAtoms.h"
13 #include "nsStyleConsts.h"
14 #include "nsMappedAttributes.h"
16 NS_IMPL_NS_NEW_HTML_ELEMENT(Pre)
18 namespace mozilla {
19 namespace dom {
21 HTMLPreElement::~HTMLPreElement() = default;
23 NS_IMPL_ELEMENT_CLONE(HTMLPreElement)
25 bool HTMLPreElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
26 const nsAString& aValue,
27 nsIPrincipal* aMaybeScriptedPrincipal,
28 nsAttrValue& aResult) {
29 if (aNamespaceID == kNameSpaceID_None) {
30 if (aAttribute == nsGkAtoms::width) {
31 return aResult.ParseIntValue(aValue);
35 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
36 aMaybeScriptedPrincipal, aResult);
39 void HTMLPreElement::MapAttributesIntoRule(
40 const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
41 if (!aDecls.PropertyIsSet(eCSSProperty_white_space)) {
42 // wrap: empty
43 if (aAttributes->GetAttr(nsGkAtoms::wrap))
44 aDecls.SetKeywordValue(eCSSProperty_white_space,
45 StyleWhiteSpace::PreWrap);
48 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
51 NS_IMETHODIMP_(bool)
52 HTMLPreElement::IsAttributeMapped(const nsAtom* aAttribute) const {
53 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
54 return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
57 static const MappedAttributeEntry attributes[] = {
58 {nsGkAtoms::wrap},
59 {nullptr},
62 static const MappedAttributeEntry* const map[] = {
63 attributes,
64 sCommonAttributeMap,
67 return FindAttributeDependence(aAttribute, map);
70 nsMapRuleToAttributesFunc HTMLPreElement::GetAttributeMappingFunction() const {
71 if (!mNodeInfo->Equals(nsGkAtoms::pre)) {
72 return nsGenericHTMLElement::GetAttributeMappingFunction();
75 return &MapAttributesIntoRule;
78 JSObject* HTMLPreElement::WrapNode(JSContext* aCx,
79 JS::Handle<JSObject*> aGivenProto) {
80 return HTMLPreElement_Binding::Wrap(aCx, this, aGivenProto);
83 } // namespace dom
84 } // namespace mozilla