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/HTMLSharedListElement.h"
8 #include "mozilla/dom/HTMLDListElementBinding.h"
9 #include "mozilla/dom/HTMLOListElementBinding.h"
10 #include "mozilla/dom/HTMLUListElementBinding.h"
11 #include "mozilla/dom/HTMLLIElement.h"
13 #include "mozilla/MappedDeclarationsBuilder.h"
14 #include "nsGenericHTMLElement.h"
15 #include "nsAttrValueInlines.h"
16 #include "nsGkAtoms.h"
17 #include "nsStyleConsts.h"
19 NS_IMPL_NS_NEW_HTML_ELEMENT(SharedList
)
21 namespace mozilla::dom
{
23 HTMLSharedListElement::~HTMLSharedListElement() = default;
25 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLSharedListElement
,
28 NS_IMPL_ELEMENT_CLONE(HTMLSharedListElement
)
30 bool HTMLSharedListElement::ParseAttribute(
31 int32_t aNamespaceID
, nsAtom
* aAttribute
, const nsAString
& aValue
,
32 nsIPrincipal
* aMaybeScriptedPrincipal
, nsAttrValue
& aResult
) {
33 if (aNamespaceID
== kNameSpaceID_None
) {
34 if (mNodeInfo
->Equals(nsGkAtoms::ul
)) {
35 if (aAttribute
== nsGkAtoms::type
) {
36 return aResult
.ParseEnumValue(aValue
, HTMLLIElement::kULTypeTable
,
40 if (mNodeInfo
->Equals(nsGkAtoms::ol
)) {
41 if (aAttribute
== nsGkAtoms::type
) {
42 return aResult
.ParseEnumValue(aValue
, HTMLLIElement::kOLTypeTable
,
45 if (aAttribute
== nsGkAtoms::start
) {
46 return aResult
.ParseIntValue(aValue
);
51 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
52 aMaybeScriptedPrincipal
, aResult
);
55 void HTMLSharedListElement::MapAttributesIntoRule(
56 MappedDeclarationsBuilder
& aBuilder
) {
57 if (!aBuilder
.PropertyIsSet(eCSSProperty_list_style_type
)) {
58 const nsAttrValue
* value
= aBuilder
.GetAttr(nsGkAtoms::type
);
59 if (value
&& value
->Type() == nsAttrValue::eEnum
) {
60 aBuilder
.SetKeywordValue(eCSSProperty_list_style_type
,
61 value
->GetEnumValue());
65 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder
);
68 void HTMLSharedListElement::MapOLAttributesIntoRule(
69 MappedDeclarationsBuilder
& aBuilder
) {
70 if (!aBuilder
.PropertyIsSet(eCSSProperty_counter_reset
)) {
71 const nsAttrValue
* startAttr
= aBuilder
.GetAttr(nsGkAtoms::start
);
72 bool haveStart
= startAttr
&& startAttr
->Type() == nsAttrValue::eInteger
;
75 start
= startAttr
->GetIntegerValue() - 1;
77 bool haveReversed
= !!aBuilder
.GetAttr(nsGkAtoms::reversed
);
80 start
+= 2; // i.e. the attr value + 1
82 start
= std::numeric_limits
<int32_t>::min();
85 if (haveStart
|| haveReversed
) {
86 aBuilder
.SetCounterResetListItem(start
, haveReversed
);
90 HTMLSharedListElement::MapAttributesIntoRule(aBuilder
);
94 HTMLSharedListElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
95 if (mNodeInfo
->Equals(nsGkAtoms::ul
)) {
96 static const MappedAttributeEntry attributes
[] = {{nsGkAtoms::type
},
99 static const MappedAttributeEntry
* const map
[] = {
104 return FindAttributeDependence(aAttribute
, map
);
107 if (mNodeInfo
->Equals(nsGkAtoms::ol
)) {
108 static const MappedAttributeEntry attributes
[] = {{nsGkAtoms::type
},
110 {nsGkAtoms::reversed
},
113 static const MappedAttributeEntry
* const map
[] = {
118 return FindAttributeDependence(aAttribute
, map
);
121 return nsGenericHTMLElement::IsAttributeMapped(aAttribute
);
124 nsMapRuleToAttributesFunc
HTMLSharedListElement::GetAttributeMappingFunction()
126 if (mNodeInfo
->Equals(nsGkAtoms::ul
)) {
127 return &MapAttributesIntoRule
;
129 if (mNodeInfo
->Equals(nsGkAtoms::ol
)) {
130 return &MapOLAttributesIntoRule
;
133 return nsGenericHTMLElement::GetAttributeMappingFunction();
136 JSObject
* HTMLSharedListElement::WrapNode(JSContext
* aCx
,
137 JS::Handle
<JSObject
*> aGivenProto
) {
138 if (mNodeInfo
->Equals(nsGkAtoms::ol
)) {
139 return HTMLOListElement_Binding::Wrap(aCx
, this, aGivenProto
);
141 if (mNodeInfo
->Equals(nsGkAtoms::dl
)) {
142 return HTMLDListElement_Binding::Wrap(aCx
, this, aGivenProto
);
144 MOZ_ASSERT(mNodeInfo
->Equals(nsGkAtoms::ul
));
145 return HTMLUListElement_Binding::Wrap(aCx
, this, aGivenProto
);
148 } // namespace mozilla::dom