1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "mozilla/Util.h"
39 :
40 : #include "nsIDOMHTMLOListElement.h"
41 : #include "nsIDOMHTMLDListElement.h"
42 : #include "nsIDOMHTMLUListElement.h"
43 : #include "nsIDOMEventTarget.h"
44 : #include "nsGenericHTMLElement.h"
45 : #include "nsGkAtoms.h"
46 : #include "nsStyleConsts.h"
47 : #include "nsMappedAttributes.h"
48 : #include "nsRuleData.h"
49 :
50 : using namespace mozilla;
51 :
52 : class nsHTMLSharedListElement : public nsGenericHTMLElement,
53 : public nsIDOMHTMLOListElement,
54 : public nsIDOMHTMLDListElement,
55 : public nsIDOMHTMLUListElement
56 : {
57 : public:
58 : nsHTMLSharedListElement(already_AddRefed<nsINodeInfo> aNodeInfo);
59 : virtual ~nsHTMLSharedListElement();
60 :
61 : // nsISupports
62 : NS_DECL_ISUPPORTS_INHERITED
63 :
64 : // nsIDOMNode
65 0 : NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
66 :
67 : // nsIDOMElement
68 0 : NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
69 :
70 : // nsIDOMHTMLElement
71 0 : NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
72 :
73 : // nsIDOMHTMLOListElement
74 : NS_DECL_NSIDOMHTMLOLISTELEMENT
75 :
76 : // nsIDOMHTMLDListElement
77 : // fully declared by NS_DECL_NSIDOMHTMLOLISTELEMENT
78 :
79 : // nsIDOMHTMLUListElement
80 : // fully declared by NS_DECL_NSIDOMHTMLOLISTELEMENT
81 :
82 : virtual bool ParseAttribute(PRInt32 aNamespaceID,
83 : nsIAtom* aAttribute,
84 : const nsAString& aValue,
85 : nsAttrValue& aResult);
86 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
87 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
88 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
89 0 : virtual nsXPCClassInfo* GetClassInfo()
90 : {
91 0 : return static_cast<nsXPCClassInfo*>(GetClassInfoInternal());
92 : }
93 : nsIClassInfo* GetClassInfoInternal();
94 : };
95 :
96 :
97 8 : NS_IMPL_NS_NEW_HTML_ELEMENT(SharedList)
98 :
99 :
100 4 : nsHTMLSharedListElement::nsHTMLSharedListElement(already_AddRefed<nsINodeInfo> aNodeInfo)
101 4 : : nsGenericHTMLElement(aNodeInfo)
102 : {
103 4 : }
104 :
105 8 : nsHTMLSharedListElement::~nsHTMLSharedListElement()
106 : {
107 16 : }
108 :
109 :
110 44 : NS_IMPL_ADDREF_INHERITED(nsHTMLSharedListElement, nsGenericElement)
111 44 : NS_IMPL_RELEASE_INHERITED(nsHTMLSharedListElement, nsGenericElement)
112 :
113 :
114 : DOMCI_DATA(HTMLOListElement, nsHTMLSharedListElement)
115 : DOMCI_DATA(HTMLDListElement, nsHTMLSharedListElement)
116 : DOMCI_DATA(HTMLUListElement, nsHTMLSharedListElement)
117 :
118 : nsIClassInfo*
119 0 : nsHTMLSharedListElement::GetClassInfoInternal()
120 : {
121 0 : if (mNodeInfo->Equals(nsGkAtoms::ol)) {
122 0 : return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLOListElement_id);
123 : }
124 0 : if (mNodeInfo->Equals(nsGkAtoms::dl)) {
125 0 : return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLDListElement_id);
126 : }
127 0 : if (mNodeInfo->Equals(nsGkAtoms::ul)) {
128 0 : return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLUListElement_id);
129 : }
130 0 : return nsnull;
131 : }
132 :
133 : // QueryInterface implementation for nsHTMLSharedListElement
134 121 : NS_INTERFACE_TABLE_HEAD(nsHTMLSharedListElement)
135 : NS_HTML_CONTENT_INTERFACE_TABLE_AMBIGUOUS_BEGIN(nsHTMLSharedListElement,
136 : nsIDOMHTMLOListElement)
137 121 : NS_OFFSET_AND_INTERFACE_TABLE_END
138 121 : NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE_AMBIGUOUS(nsHTMLSharedListElement,
139 : nsGenericHTMLElement,
140 : nsIDOMHTMLOListElement)
141 0 : NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLOListElement, ol)
142 0 : NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLDListElement, dl)
143 0 : NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLUListElement, ul)
144 :
145 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_GETTER(GetClassInfoInternal)
146 0 : NS_HTML_CONTENT_INTERFACE_MAP_END
147 :
148 :
149 0 : NS_IMPL_ELEMENT_CLONE(nsHTMLSharedListElement)
150 :
151 :
152 0 : NS_IMPL_BOOL_ATTR(nsHTMLSharedListElement, Compact, compact)
153 0 : NS_IMPL_INT_ATTR_DEFAULT_VALUE(nsHTMLSharedListElement, Start, start, 1)
154 0 : NS_IMPL_STRING_ATTR(nsHTMLSharedListElement, Type, type)
155 :
156 : // Shared with nsHTMLSharedElement.cpp
157 : nsAttrValue::EnumTable kListTypeTable[] = {
158 : { "none", NS_STYLE_LIST_STYLE_NONE },
159 : { "disc", NS_STYLE_LIST_STYLE_DISC },
160 : { "circle", NS_STYLE_LIST_STYLE_CIRCLE },
161 : { "round", NS_STYLE_LIST_STYLE_CIRCLE },
162 : { "square", NS_STYLE_LIST_STYLE_SQUARE },
163 : { "decimal", NS_STYLE_LIST_STYLE_DECIMAL },
164 : { "lower-roman", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
165 : { "upper-roman", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
166 : { "lower-alpha", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
167 : { "upper-alpha", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
168 : { 0 }
169 : };
170 :
171 : static const nsAttrValue::EnumTable kOldListTypeTable[] = {
172 : { "1", NS_STYLE_LIST_STYLE_DECIMAL },
173 : { "A", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
174 : { "a", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
175 : { "I", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
176 : { "i", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
177 : { 0 }
178 : };
179 :
180 : bool
181 0 : nsHTMLSharedListElement::ParseAttribute(PRInt32 aNamespaceID,
182 : nsIAtom* aAttribute,
183 : const nsAString& aValue,
184 : nsAttrValue& aResult)
185 : {
186 0 : if (aNamespaceID == kNameSpaceID_None) {
187 0 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
188 0 : mNodeInfo->Equals(nsGkAtoms::ul)) {
189 0 : if (aAttribute == nsGkAtoms::type) {
190 0 : return aResult.ParseEnumValue(aValue, kListTypeTable, false) ||
191 0 : aResult.ParseEnumValue(aValue, kOldListTypeTable, true);
192 : }
193 0 : if (aAttribute == nsGkAtoms::start) {
194 0 : return aResult.ParseIntValue(aValue);
195 : }
196 : }
197 : }
198 :
199 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
200 0 : aResult);
201 : }
202 :
203 : static void
204 0 : MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
205 : {
206 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(List)) {
207 0 : nsCSSValue* listStyleType = aData->ValueForListStyleType();
208 0 : if (listStyleType->GetUnit() == eCSSUnit_Null) {
209 : // type: enum
210 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type);
211 0 : if (value) {
212 0 : if (value->Type() == nsAttrValue::eEnum)
213 0 : listStyleType->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
214 : else
215 0 : listStyleType->SetIntValue(NS_STYLE_LIST_STYLE_DECIMAL, eCSSUnit_Enumerated);
216 : }
217 : }
218 : }
219 :
220 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
221 0 : }
222 :
223 : NS_IMETHODIMP_(bool)
224 0 : nsHTMLSharedListElement::IsAttributeMapped(const nsIAtom* aAttribute) const
225 : {
226 0 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
227 0 : mNodeInfo->Equals(nsGkAtoms::ul)) {
228 : static const MappedAttributeEntry attributes[] = {
229 : { &nsGkAtoms::type },
230 : { nsnull }
231 : };
232 :
233 : static const MappedAttributeEntry* const map[] = {
234 : attributes,
235 : sCommonAttributeMap,
236 : };
237 :
238 0 : return FindAttributeDependence(aAttribute, map);
239 : }
240 :
241 0 : return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
242 : }
243 :
244 : nsMapRuleToAttributesFunc
245 0 : nsHTMLSharedListElement::GetAttributeMappingFunction() const
246 : {
247 0 : if (mNodeInfo->Equals(nsGkAtoms::ol) ||
248 0 : mNodeInfo->Equals(nsGkAtoms::ul)) {
249 0 : return &MapAttributesIntoRule;
250 : }
251 :
252 0 : return nsGenericHTMLElement::GetAttributeMappingFunction();
253 : }
|