Line data Source code
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/HTMLSharedListElement.h"
8 : #include "mozilla/dom/HTMLDListElementBinding.h"
9 : #include "mozilla/dom/HTMLOListElementBinding.h"
10 : #include "mozilla/dom/HTMLUListElementBinding.h"
11 :
12 : #include "mozilla/GenericSpecifiedValuesInlines.h"
13 : #include "nsGenericHTMLElement.h"
14 : #include "nsAttrValueInlines.h"
15 : #include "nsGkAtoms.h"
16 : #include "nsStyleConsts.h"
17 : #include "nsMappedAttributes.h"
18 :
19 2 : NS_IMPL_NS_NEW_HTML_ELEMENT(SharedList)
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 0 : HTMLSharedListElement::~HTMLSharedListElement()
25 : {
26 0 : }
27 :
28 2 : NS_IMPL_ADDREF_INHERITED(HTMLSharedListElement, Element)
29 1 : NS_IMPL_RELEASE_INHERITED(HTMLSharedListElement, Element)
30 :
31 : // QueryInterface implementation for nsHTMLSharedListElement
32 1 : NS_INTERFACE_MAP_BEGIN(HTMLSharedListElement)
33 1 : NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLOListElement, ol)
34 1 : NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLUListElement, ul)
35 1 : NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
36 :
37 :
38 0 : NS_IMPL_ELEMENT_CLONE(HTMLSharedListElement)
39 :
40 :
41 0 : NS_IMPL_BOOL_ATTR(HTMLSharedListElement, Compact, compact)
42 0 : NS_IMPL_INT_ATTR_DEFAULT_VALUE(HTMLSharedListElement, Start, start, 1)
43 0 : NS_IMPL_STRING_ATTR(HTMLSharedListElement, Type, type)
44 0 : NS_IMPL_BOOL_ATTR(HTMLSharedListElement, Reversed, reversed)
45 :
46 : // Shared with nsHTMLSharedElement.cpp
47 : nsAttrValue::EnumTable kListTypeTable[] = {
48 : { "none", NS_STYLE_LIST_STYLE_NONE },
49 : { "disc", NS_STYLE_LIST_STYLE_DISC },
50 : { "circle", NS_STYLE_LIST_STYLE_CIRCLE },
51 : { "round", NS_STYLE_LIST_STYLE_CIRCLE },
52 : { "square", NS_STYLE_LIST_STYLE_SQUARE },
53 : { "decimal", NS_STYLE_LIST_STYLE_DECIMAL },
54 : { "lower-roman", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
55 : { "upper-roman", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
56 : { "lower-alpha", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
57 : { "upper-alpha", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
58 : { nullptr, 0 }
59 : };
60 :
61 : static const nsAttrValue::EnumTable kOldListTypeTable[] = {
62 : { "1", NS_STYLE_LIST_STYLE_DECIMAL },
63 : { "A", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
64 : { "a", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
65 : { "I", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
66 : { "i", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
67 : { nullptr, 0 }
68 : };
69 :
70 : bool
71 1 : HTMLSharedListElement::ParseAttribute(int32_t aNamespaceID,
72 : nsIAtom* aAttribute,
73 : const nsAString& aValue,
74 : nsAttrValue& aResult)
75 : {
76 1 : if (aNamespaceID == kNameSpaceID_None) {
77 2 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
78 1 : mNodeInfo->Equals(nsGkAtoms::ul)) {
79 1 : if (aAttribute == nsGkAtoms::type) {
80 0 : return aResult.ParseEnumValue(aValue, kListTypeTable, false) ||
81 0 : aResult.ParseEnumValue(aValue, kOldListTypeTable, true);
82 : }
83 1 : if (aAttribute == nsGkAtoms::start) {
84 0 : return aResult.ParseIntValue(aValue);
85 : }
86 : }
87 : }
88 :
89 1 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
90 1 : aResult);
91 : }
92 :
93 : void
94 0 : HTMLSharedListElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
95 : GenericSpecifiedValues* aData)
96 : {
97 0 : if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(List))) {
98 0 : if (!aData->PropertyIsSet(eCSSProperty_list_style_type)) {
99 : // type: enum
100 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type);
101 0 : if (value && value->Type() == nsAttrValue::eEnum) {
102 0 : aData->SetKeywordValue(eCSSProperty_list_style_type, value->GetEnumValue());
103 : }
104 : }
105 : }
106 :
107 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
108 0 : }
109 :
110 : NS_IMETHODIMP_(bool)
111 2 : HTMLSharedListElement::IsAttributeMapped(const nsIAtom* aAttribute) const
112 : {
113 4 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
114 2 : mNodeInfo->Equals(nsGkAtoms::ul)) {
115 : static const MappedAttributeEntry attributes[] = {
116 : { &nsGkAtoms::type },
117 : { nullptr }
118 : };
119 :
120 : static const MappedAttributeEntry* const map[] = {
121 : attributes,
122 : sCommonAttributeMap,
123 : };
124 :
125 2 : return FindAttributeDependence(aAttribute, map);
126 : }
127 :
128 0 : return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
129 : }
130 :
131 : nsMapRuleToAttributesFunc
132 0 : HTMLSharedListElement::GetAttributeMappingFunction() const
133 : {
134 0 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
135 0 : mNodeInfo->Equals(nsGkAtoms::ul)) {
136 0 : return &MapAttributesIntoRule;
137 : }
138 :
139 0 : return nsGenericHTMLElement::GetAttributeMappingFunction();
140 : }
141 :
142 : JSObject*
143 0 : HTMLSharedListElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
144 : {
145 0 : if (mNodeInfo->Equals(nsGkAtoms::ol)) {
146 0 : return HTMLOListElementBinding::Wrap(aCx, this, aGivenProto);
147 : }
148 0 : if (mNodeInfo->Equals(nsGkAtoms::dl)) {
149 0 : return HTMLDListElementBinding::Wrap(aCx, this, aGivenProto);
150 : }
151 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::ul));
152 0 : return HTMLUListElementBinding::Wrap(aCx, this, aGivenProto);
153 : }
154 :
155 : } // namespace dom
156 : } // namespace mozilla
|