Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / html / HTMLSharedListElement.cpp
blobb5a86a8154b2758278ada550b441b57ff9d48992
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,
26 nsGenericHTMLElement)
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,
37 false);
40 if (mNodeInfo->Equals(nsGkAtoms::ol)) {
41 if (aAttribute == nsGkAtoms::type) {
42 return aResult.ParseEnumValue(aValue, HTMLLIElement::kOLTypeTable,
43 true);
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;
73 int32_t start = 0;
74 if (haveStart) {
75 start = startAttr->GetIntegerValue() - 1;
77 bool haveReversed = !!aBuilder.GetAttr(nsGkAtoms::reversed);
78 if (haveReversed) {
79 if (haveStart) {
80 start += 2; // i.e. the attr value + 1
81 } else {
82 start = std::numeric_limits<int32_t>::min();
85 if (haveStart || haveReversed) {
86 aBuilder.SetCounterResetListItem(start, haveReversed);
90 HTMLSharedListElement::MapAttributesIntoRule(aBuilder);
93 NS_IMETHODIMP_(bool)
94 HTMLSharedListElement::IsAttributeMapped(const nsAtom* aAttribute) const {
95 if (mNodeInfo->Equals(nsGkAtoms::ul)) {
96 static const MappedAttributeEntry attributes[] = {{nsGkAtoms::type},
97 {nullptr}};
99 static const MappedAttributeEntry* const map[] = {
100 attributes,
101 sCommonAttributeMap,
104 return FindAttributeDependence(aAttribute, map);
107 if (mNodeInfo->Equals(nsGkAtoms::ol)) {
108 static const MappedAttributeEntry attributes[] = {{nsGkAtoms::type},
109 {nsGkAtoms::start},
110 {nsGkAtoms::reversed},
111 {nullptr}};
113 static const MappedAttributeEntry* const map[] = {
114 attributes,
115 sCommonAttributeMap,
118 return FindAttributeDependence(aAttribute, map);
121 return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
124 nsMapRuleToAttributesFunc HTMLSharedListElement::GetAttributeMappingFunction()
125 const {
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