Bug 1862332 [wpt PR 42877] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / dom / html / HTMLLIElement.cpp
blobfcaa120b03b29f7910f7206f28693fe1cc55603e
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 "nsGkAtoms.h"
12 #include "nsStyleConsts.h"
14 NS_IMPL_NS_NEW_HTML_ELEMENT(LI)
16 namespace mozilla::dom {
18 HTMLLIElement::~HTMLLIElement() = default;
20 NS_IMPL_ELEMENT_CLONE(HTMLLIElement)
22 // https://html.spec.whatwg.org/#lists
23 const nsAttrValue::EnumTable HTMLLIElement::kULTypeTable[] = {
24 {"none", ListStyle::None},
25 {"disc", ListStyle::Disc},
26 {"circle", ListStyle::Circle},
27 {"square", ListStyle::Square},
28 {nullptr, 0}};
30 // https://html.spec.whatwg.org/#lists
31 const nsAttrValue::EnumTable HTMLLIElement::kOLTypeTable[] = {
32 {"A", ListStyle::UpperAlpha}, {"a", ListStyle::LowerAlpha},
33 {"I", ListStyle::UpperRoman}, {"i", ListStyle::LowerRoman},
34 {"1", ListStyle::Decimal}, {nullptr, 0}};
36 bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
37 const nsAString& aValue,
38 nsIPrincipal* aMaybeScriptedPrincipal,
39 nsAttrValue& aResult) {
40 if (aNamespaceID == kNameSpaceID_None) {
41 if (aAttribute == nsGkAtoms::type) {
42 return aResult.ParseEnumValue(aValue, kOLTypeTable, true) ||
43 aResult.ParseEnumValue(aValue, kULTypeTable, false);
45 if (aAttribute == nsGkAtoms::value) {
46 return aResult.ParseIntValue(aValue);
50 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
51 aMaybeScriptedPrincipal, aResult);
54 void HTMLLIElement::MapAttributesIntoRule(MappedDeclarationsBuilder& aBuilder) {
55 if (!aBuilder.PropertyIsSet(eCSSProperty_list_style_type)) {
56 // type: enum
57 const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::type);
58 if (value && value->Type() == nsAttrValue::eEnum) {
59 aBuilder.SetKeywordValue(eCSSProperty_list_style_type,
60 value->GetEnumValue());
64 // Map <li value=INTEGER> to 'counter-set: list-item INTEGER'.
65 const nsAttrValue* attrVal = aBuilder.GetAttr(nsGkAtoms::value);
66 if (attrVal && attrVal->Type() == nsAttrValue::eInteger) {
67 if (!aBuilder.PropertyIsSet(eCSSProperty_counter_set)) {
68 aBuilder.SetCounterSetListItem(attrVal->GetIntegerValue());
72 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
75 NS_IMETHODIMP_(bool)
76 HTMLLIElement::IsAttributeMapped(const nsAtom* aAttribute) const {
77 static const MappedAttributeEntry attributes[] = {
78 {nsGkAtoms::type},
79 {nsGkAtoms::value},
80 {nullptr},
83 static const MappedAttributeEntry* const map[] = {
84 attributes,
85 sCommonAttributeMap,
88 return FindAttributeDependence(aAttribute, map);
91 nsMapRuleToAttributesFunc HTMLLIElement::GetAttributeMappingFunction() const {
92 return &MapAttributesIntoRule;
95 JSObject* HTMLLIElement::WrapNode(JSContext* aCx,
96 JS::Handle<JSObject*> aGivenProto) {
97 return HTMLLIElement_Binding::Wrap(aCx, this, aGivenProto);
100 } // namespace mozilla::dom