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
)
21 HTMLPreElement::~HTMLPreElement()
25 NS_IMPL_ELEMENT_CLONE(HTMLPreElement
)
28 HTMLPreElement::ParseAttribute(int32_t aNamespaceID
,
30 const nsAString
& aValue
,
31 nsIPrincipal
* aMaybeScriptedPrincipal
,
34 if (aNamespaceID
== kNameSpaceID_None
) {
35 if (aAttribute
== nsGkAtoms::width
) {
36 return aResult
.ParseIntValue(aValue
);
40 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
41 aMaybeScriptedPrincipal
, aResult
);
45 HTMLPreElement::MapAttributesIntoRule(const nsMappedAttributes
* aAttributes
,
46 MappedDeclarations
& aDecls
)
48 if (!aDecls
.PropertyIsSet(eCSSProperty_white_space
)) {
50 if (aAttributes
->GetAttr(nsGkAtoms::wrap
))
51 aDecls
.SetKeywordValue(eCSSProperty_white_space
, StyleWhiteSpace::PreWrap
);
54 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes
, aDecls
);
58 HTMLPreElement::IsAttributeMapped(const nsAtom
* aAttribute
) const
60 if (!mNodeInfo
->Equals(nsGkAtoms::pre
)) {
61 return nsGenericHTMLElement::IsAttributeMapped(aAttribute
);
64 static const MappedAttributeEntry attributes
[] = {
69 static const MappedAttributeEntry
* const map
[] = {
74 return FindAttributeDependence(aAttribute
, map
);
77 nsMapRuleToAttributesFunc
78 HTMLPreElement::GetAttributeMappingFunction() const
80 if (!mNodeInfo
->Equals(nsGkAtoms::pre
)) {
81 return nsGenericHTMLElement::GetAttributeMappingFunction();
84 return &MapAttributesIntoRule
;
88 HTMLPreElement::WrapNode(JSContext
*aCx
, JS::Handle
<JSObject
*> aGivenProto
)
90 return HTMLPreElement_Binding::Wrap(aCx
, this, aGivenProto
);
94 } // namespace mozilla