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 "nsIDOMHTMLDivElement.h"
41 : #include "nsIDOMEventTarget.h"
42 : #include "nsGenericHTMLElement.h"
43 : #include "nsGkAtoms.h"
44 : #include "nsStyleConsts.h"
45 : #include "nsMappedAttributes.h"
46 :
47 : using namespace mozilla;
48 :
49 : class nsHTMLDivElement : public nsGenericHTMLElement,
50 : public nsIDOMHTMLDivElement
51 : {
52 : public:
53 : nsHTMLDivElement(already_AddRefed<nsINodeInfo> aNodeInfo);
54 : virtual ~nsHTMLDivElement();
55 :
56 : // nsISupports
57 : NS_DECL_ISUPPORTS_INHERITED
58 :
59 : // nsIDOMNode
60 0 : NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
61 :
62 : // nsIDOMElement
63 0 : NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
64 :
65 : // nsIDOMHTMLElement
66 0 : NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
67 :
68 : // nsIDOMHTMLDivElement
69 : NS_DECL_NSIDOMHTMLDIVELEMENT
70 :
71 : virtual bool ParseAttribute(PRInt32 aNamespaceID,
72 : nsIAtom* aAttribute,
73 : const nsAString& aValue,
74 : nsAttrValue& aResult);
75 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
76 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
77 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
78 :
79 : virtual nsXPCClassInfo* GetClassInfo();
80 : };
81 :
82 :
83 2 : NS_IMPL_NS_NEW_HTML_ELEMENT(Div)
84 :
85 :
86 1 : nsHTMLDivElement::nsHTMLDivElement(already_AddRefed<nsINodeInfo> aNodeInfo)
87 1 : : nsGenericHTMLElement(aNodeInfo)
88 : {
89 1 : }
90 :
91 2 : nsHTMLDivElement::~nsHTMLDivElement()
92 : {
93 4 : }
94 :
95 :
96 5 : NS_IMPL_ADDREF_INHERITED(nsHTMLDivElement, nsGenericElement)
97 5 : NS_IMPL_RELEASE_INHERITED(nsHTMLDivElement, nsGenericElement)
98 :
99 0 : DOMCI_NODE_DATA(HTMLDivElement, nsHTMLDivElement)
100 :
101 : // QueryInterface implementation for nsHTMLDivElement
102 6 : NS_INTERFACE_TABLE_HEAD(nsHTMLDivElement)
103 6 : NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLDivElement, nsIDOMHTMLDivElement)
104 6 : NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLDivElement,
105 : nsGenericHTMLElement)
106 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLDivElement)
107 :
108 0 : NS_IMPL_ELEMENT_CLONE(nsHTMLDivElement)
109 :
110 :
111 0 : NS_IMPL_STRING_ATTR(nsHTMLDivElement, Align, align)
112 :
113 :
114 : bool
115 2 : nsHTMLDivElement::ParseAttribute(PRInt32 aNamespaceID,
116 : nsIAtom* aAttribute,
117 : const nsAString& aValue,
118 : nsAttrValue& aResult)
119 : {
120 2 : if (aNamespaceID == kNameSpaceID_None) {
121 0 : if (mNodeInfo->Equals(nsGkAtoms::marquee)) {
122 0 : if ((aAttribute == nsGkAtoms::width) ||
123 : (aAttribute == nsGkAtoms::height)) {
124 0 : return aResult.ParseSpecialIntValue(aValue);
125 : }
126 0 : if (aAttribute == nsGkAtoms::bgcolor) {
127 0 : return aResult.ParseColor(aValue);
128 : }
129 0 : if ((aAttribute == nsGkAtoms::hspace) ||
130 : (aAttribute == nsGkAtoms::vspace)) {
131 0 : return aResult.ParseIntWithBounds(aValue, 0);
132 : }
133 : }
134 :
135 0 : if (mNodeInfo->Equals(nsGkAtoms::div) &&
136 : aAttribute == nsGkAtoms::align) {
137 0 : return ParseDivAlignValue(aValue, aResult);
138 : }
139 : }
140 :
141 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
142 2 : aResult);
143 : }
144 :
145 : static void
146 0 : MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
147 : {
148 0 : nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aData);
149 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
150 0 : }
151 :
152 : static void
153 0 : MapMarqueeAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
154 : {
155 0 : nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
156 0 : nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
157 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
158 0 : nsGenericHTMLElement::MapBGColorInto(aAttributes, aData);
159 0 : }
160 :
161 : NS_IMETHODIMP_(bool)
162 0 : nsHTMLDivElement::IsAttributeMapped(const nsIAtom* aAttribute) const
163 : {
164 0 : if (mNodeInfo->Equals(nsGkAtoms::div)) {
165 : static const MappedAttributeEntry* const map[] = {
166 : sDivAlignAttributeMap,
167 : sCommonAttributeMap
168 : };
169 0 : return FindAttributeDependence(aAttribute, map);
170 : }
171 0 : if (mNodeInfo->Equals(nsGkAtoms::marquee)) {
172 : static const MappedAttributeEntry* const map[] = {
173 : sImageMarginSizeAttributeMap,
174 : sBackgroundColorAttributeMap,
175 : sCommonAttributeMap
176 : };
177 0 : return FindAttributeDependence(aAttribute, map);
178 : }
179 :
180 0 : return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
181 : }
182 :
183 : nsMapRuleToAttributesFunc
184 0 : nsHTMLDivElement::GetAttributeMappingFunction() const
185 : {
186 0 : if (mNodeInfo->Equals(nsGkAtoms::div)) {
187 0 : return &MapAttributesIntoRule;
188 : }
189 0 : if (mNodeInfo->Equals(nsGkAtoms::marquee)) {
190 0 : return &MapMarqueeAttributesIntoRule;
191 : }
192 0 : return nsGenericHTMLElement::GetAttributeMappingFunction();
193 : }
194 :
|