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::dom
{
20 HTMLPreElement::~HTMLPreElement() = default;
22 NS_IMPL_ELEMENT_CLONE(HTMLPreElement
)
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
);
34 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
35 aMaybeScriptedPrincipal
, aResult
);
38 void HTMLPreElement::MapAttributesIntoRule(
39 const nsMappedAttributes
* aAttributes
, MappedDeclarations
& aDecls
) {
40 if (!aDecls
.PropertyIsSet(eCSSProperty_white_space
)) {
42 if (aAttributes
->GetAttr(nsGkAtoms::wrap
))
43 aDecls
.SetKeywordValue(eCSSProperty_white_space
,
44 StyleWhiteSpace::PreWrap
);
47 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes
, aDecls
);
51 HTMLPreElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
52 if (!mNodeInfo
->Equals(nsGkAtoms::pre
)) {
53 return nsGenericHTMLElement::IsAttributeMapped(aAttribute
);
56 static const MappedAttributeEntry attributes
[] = {
61 static const MappedAttributeEntry
* const map
[] = {
66 return FindAttributeDependence(aAttribute
, map
);
69 nsMapRuleToAttributesFunc
HTMLPreElement::GetAttributeMappingFunction() const {
70 if (!mNodeInfo
->Equals(nsGkAtoms::pre
)) {
71 return nsGenericHTMLElement::GetAttributeMappingFunction();
74 return &MapAttributesIntoRule
;
77 JSObject
* HTMLPreElement::WrapNode(JSContext
* aCx
,
78 JS::Handle
<JSObject
*> aGivenProto
) {
79 return HTMLPreElement_Binding::Wrap(aCx
, this, aGivenProto
);
82 } // namespace mozilla::dom