Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / html / HTMLLIElement.cpp
blobf40572bfbce63d4cf7e3120899d81cf744e5ed5e
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/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(LI)
18 namespace mozilla {
19 namespace dom {
21 HTMLLIElement::~HTMLLIElement() {}
23 NS_IMPL_ELEMENT_CLONE(HTMLLIElement)
25 // values that are handled case-insensitively
26 static const nsAttrValue::EnumTable kUnorderedListItemTypeTable[] = {
27 {"disc", NS_STYLE_LIST_STYLE_DISC},
28 {"circle", NS_STYLE_LIST_STYLE_CIRCLE},
29 {"round", NS_STYLE_LIST_STYLE_CIRCLE},
30 {"square", NS_STYLE_LIST_STYLE_SQUARE},
31 {nullptr, 0}};
33 // values that are handled case-sensitively
34 static const nsAttrValue::EnumTable kOrderedListItemTypeTable[] = {
35 {"A", NS_STYLE_LIST_STYLE_UPPER_ALPHA},
36 {"a", NS_STYLE_LIST_STYLE_LOWER_ALPHA},
37 {"I", NS_STYLE_LIST_STYLE_UPPER_ROMAN},
38 {"i", NS_STYLE_LIST_STYLE_LOWER_ROMAN},
39 {"1", NS_STYLE_LIST_STYLE_DECIMAL},
40 {nullptr, 0}};
42 bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
43 const nsAString& aValue,
44 nsIPrincipal* aMaybeScriptedPrincipal,
45 nsAttrValue& aResult) {
46 if (aNamespaceID == kNameSpaceID_None) {
47 if (aAttribute == nsGkAtoms::type) {
48 return aResult.ParseEnumValue(aValue, kOrderedListItemTypeTable, true) ||
49 aResult.ParseEnumValue(aValue, kUnorderedListItemTypeTable, false);
51 if (aAttribute == nsGkAtoms::value) {
52 return aResult.ParseIntValue(aValue);
56 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
57 aMaybeScriptedPrincipal, aResult);
60 void HTMLLIElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
61 MappedDeclarations& aDecls) {
62 if (!aDecls.PropertyIsSet(eCSSProperty_list_style_type)) {
63 // type: enum
64 const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type);
65 if (value && value->Type() == nsAttrValue::eEnum)
66 aDecls.SetKeywordValue(eCSSProperty_list_style_type,
67 value->GetEnumValue());
70 // Map <li value=INTEGER> to 'counter-set: list-item INTEGER'.
71 const nsAttrValue* attrVal = aAttributes->GetAttr(nsGkAtoms::value);
72 if (attrVal && attrVal->Type() == nsAttrValue::eInteger) {
73 if (!aDecls.PropertyIsSet(eCSSProperty_counter_set)) {
74 aDecls.SetCounterSetListItem(attrVal->GetIntegerValue());
78 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
81 NS_IMETHODIMP_(bool)
82 HTMLLIElement::IsAttributeMapped(const nsAtom* aAttribute) const {
83 static const MappedAttributeEntry attributes[] = {
84 {nsGkAtoms::type},
85 {nsGkAtoms::value},
86 {nullptr},
89 static const MappedAttributeEntry* const map[] = {
90 attributes,
91 sCommonAttributeMap,
94 return FindAttributeDependence(aAttribute, map);
97 nsMapRuleToAttributesFunc HTMLLIElement::GetAttributeMappingFunction() const {
98 return &MapAttributesIntoRule;
101 JSObject* HTMLLIElement::WrapNode(JSContext* aCx,
102 JS::Handle<JSObject*> aGivenProto) {
103 return HTMLLIElement_Binding::Wrap(aCx, this, aGivenProto);
106 } // namespace dom
107 } // namespace mozilla