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/HTMLLIElement.h"
8 #include "mozilla/dom/HTMLLIElementBinding.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(LI
)
17 namespace mozilla::dom
{
19 HTMLLIElement::~HTMLLIElement() = default;
21 NS_IMPL_ELEMENT_CLONE(HTMLLIElement
)
23 // values that are handled case-insensitively
24 static const nsAttrValue::EnumTable kUnorderedListItemTypeTable
[] = {
25 {"disc", ListStyle::Disc
},
26 {"circle", ListStyle::Circle
},
27 {"round", ListStyle::Circle
},
28 {"square", ListStyle::Square
},
31 // values that are handled case-sensitively
32 static const nsAttrValue::EnumTable kOrderedListItemTypeTable
[] = {
33 {"A", ListStyle::UpperAlpha
}, {"a", ListStyle::LowerAlpha
},
34 {"I", ListStyle::UpperRoman
}, {"i", ListStyle::LowerRoman
},
35 {"1", ListStyle::Decimal
}, {nullptr, 0}};
37 bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
38 const nsAString
& aValue
,
39 nsIPrincipal
* aMaybeScriptedPrincipal
,
40 nsAttrValue
& aResult
) {
41 if (aNamespaceID
== kNameSpaceID_None
) {
42 if (aAttribute
== nsGkAtoms::type
) {
43 return aResult
.ParseEnumValue(aValue
, kOrderedListItemTypeTable
, true) ||
44 aResult
.ParseEnumValue(aValue
, kUnorderedListItemTypeTable
, false);
46 if (aAttribute
== nsGkAtoms::value
) {
47 return aResult
.ParseIntValue(aValue
);
51 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
52 aMaybeScriptedPrincipal
, aResult
);
55 void HTMLLIElement::MapAttributesIntoRule(MappedDeclarationsBuilder
& aBuilder
) {
56 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 // Map <li value=INTEGER> to 'counter-set: list-item INTEGER'.
66 const nsAttrValue
* attrVal
= aBuilder
.GetAttr(nsGkAtoms::value
);
67 if (attrVal
&& attrVal
->Type() == nsAttrValue::eInteger
) {
68 if (!aBuilder
.PropertyIsSet(eCSSProperty_counter_set
)) {
69 aBuilder
.SetCounterSetListItem(attrVal
->GetIntegerValue());
73 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder
);
77 HTMLLIElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
78 static const MappedAttributeEntry attributes
[] = {
84 static const MappedAttributeEntry
* const map
[] = {
89 return FindAttributeDependence(aAttribute
, map
);
92 nsMapRuleToAttributesFunc
HTMLLIElement::GetAttributeMappingFunction() const {
93 return &MapAttributesIntoRule
;
96 JSObject
* HTMLLIElement::WrapNode(JSContext
* aCx
,
97 JS::Handle
<JSObject
*> aGivenProto
) {
98 return HTMLLIElement_Binding::Wrap(aCx
, this, aGivenProto
);
101 } // namespace mozilla::dom