HTMLLIElement.cpp (3426B)
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/. */ 6 7 #include "mozilla/dom/HTMLLIElement.h" 8 9 #include "mozilla/MappedDeclarationsBuilder.h" 10 #include "mozilla/dom/HTMLLIElementBinding.h" 11 #include "nsGkAtoms.h" 12 #include "nsStyleConsts.h" 13 14 NS_IMPL_NS_NEW_HTML_ELEMENT(LI) 15 16 namespace mozilla::dom { 17 18 HTMLLIElement::~HTMLLIElement() = default; 19 20 NS_IMPL_ELEMENT_CLONE(HTMLLIElement) 21 22 // https://html.spec.whatwg.org/#lists 23 const nsAttrValue::EnumTableEntry HTMLLIElement::kULTypeTable[] = { 24 {"none", ListStyle::None}, 25 {"disc", ListStyle::Disc}, 26 {"circle", ListStyle::Circle}, 27 {"square", ListStyle::Square}, 28 }; 29 30 // https://html.spec.whatwg.org/#lists 31 const nsAttrValue::EnumTableEntry HTMLLIElement::kOLTypeTable[] = { 32 {"A", ListStyle::UpperAlpha}, {"a", ListStyle::LowerAlpha}, 33 {"I", ListStyle::UpperRoman}, {"i", ListStyle::LowerRoman}, 34 {"1", ListStyle::Decimal}, 35 }; 36 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, kOLTypeTable, true) || 44 aResult.ParseEnumValue(aValue, kULTypeTable, false); 45 } 46 if (aAttribute == nsGkAtoms::value) { 47 return aResult.ParseIntValue(aValue); 48 } 49 } 50 51 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, 52 aMaybeScriptedPrincipal, aResult); 53 } 54 55 void HTMLLIElement::MapAttributesIntoRule(MappedDeclarationsBuilder& aBuilder) { 56 if (!aBuilder.PropertyIsSet(eCSSProperty_list_style_type)) { 57 // type: enum 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()); 62 } 63 } 64 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()); 70 } 71 } 72 73 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder); 74 } 75 76 NS_IMETHODIMP_(bool) 77 HTMLLIElement::IsAttributeMapped(const nsAtom* aAttribute) const { 78 static const MappedAttributeEntry attributes[] = { 79 {nsGkAtoms::type}, 80 {nsGkAtoms::value}, 81 {nullptr}, 82 }; 83 84 static const MappedAttributeEntry* const map[] = { 85 attributes, 86 sCommonAttributeMap, 87 }; 88 89 return FindAttributeDependence(aAttribute, map); 90 } 91 92 nsMapRuleToAttributesFunc HTMLLIElement::GetAttributeMappingFunction() const { 93 return &MapAttributesIntoRule; 94 } 95 96 JSObject* HTMLLIElement::WrapNode(JSContext* aCx, 97 JS::Handle<JSObject*> aGivenProto) { 98 return HTMLLIElement_Binding::Wrap(aCx, this, aGivenProto); 99 } 100 101 } // namespace mozilla::dom