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 "nsIDOMHTMLTableCaptionElem.h"
41 : #include "nsIDOMEventTarget.h"
42 : #include "nsGenericHTMLElement.h"
43 : #include "nsGkAtoms.h"
44 : #include "nsStyleConsts.h"
45 : #include "nsMappedAttributes.h"
46 : #include "nsRuleData.h"
47 :
48 : using namespace mozilla;
49 :
50 : class nsHTMLTableCaptionElement : public nsGenericHTMLElement,
51 : public nsIDOMHTMLTableCaptionElement
52 : {
53 : public:
54 : nsHTMLTableCaptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
55 : virtual ~nsHTMLTableCaptionElement();
56 :
57 : // nsISupports
58 : NS_DECL_ISUPPORTS_INHERITED
59 :
60 : // nsIDOMNode
61 0 : NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
62 :
63 : // nsIDOMElement
64 0 : NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
65 :
66 : // nsIDOMHTMLElement
67 0 : NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
68 :
69 : // nsIDOMHTMLTableCaptionElement
70 : NS_DECL_NSIDOMHTMLTABLECAPTIONELEMENT
71 :
72 : virtual bool ParseAttribute(PRInt32 aNamespaceID,
73 : nsIAtom* aAttribute,
74 : const nsAString& aValue,
75 : nsAttrValue& aResult);
76 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
77 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
78 :
79 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
80 :
81 : virtual nsXPCClassInfo* GetClassInfo();
82 : };
83 :
84 :
85 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(TableCaption)
86 :
87 :
88 0 : nsHTMLTableCaptionElement::nsHTMLTableCaptionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
89 0 : : nsGenericHTMLElement(aNodeInfo)
90 : {
91 0 : }
92 :
93 0 : nsHTMLTableCaptionElement::~nsHTMLTableCaptionElement()
94 : {
95 0 : }
96 :
97 :
98 0 : NS_IMPL_ADDREF_INHERITED(nsHTMLTableCaptionElement, nsGenericElement)
99 0 : NS_IMPL_RELEASE_INHERITED(nsHTMLTableCaptionElement, nsGenericElement)
100 :
101 :
102 0 : DOMCI_NODE_DATA(HTMLTableCaptionElement, nsHTMLTableCaptionElement)
103 :
104 : // QueryInterface implementation for nsHTMLTableCaptionElement
105 0 : NS_INTERFACE_TABLE_HEAD(nsHTMLTableCaptionElement)
106 0 : NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLTableCaptionElement,
107 : nsIDOMHTMLTableCaptionElement)
108 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLTableCaptionElement,
109 : nsGenericHTMLElement)
110 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLTableCaptionElement)
111 :
112 :
113 0 : NS_IMPL_ELEMENT_CLONE(nsHTMLTableCaptionElement)
114 :
115 :
116 0 : NS_IMPL_STRING_ATTR(nsHTMLTableCaptionElement, Align, align)
117 :
118 :
119 : static const nsAttrValue::EnumTable kCaptionAlignTable[] = {
120 : { "left", NS_STYLE_CAPTION_SIDE_LEFT },
121 : { "right", NS_STYLE_CAPTION_SIDE_RIGHT },
122 : { "top", NS_STYLE_CAPTION_SIDE_TOP },
123 : { "bottom", NS_STYLE_CAPTION_SIDE_BOTTOM },
124 : { 0 }
125 : };
126 :
127 : bool
128 0 : nsHTMLTableCaptionElement::ParseAttribute(PRInt32 aNamespaceID,
129 : nsIAtom* aAttribute,
130 : const nsAString& aValue,
131 : nsAttrValue& aResult)
132 : {
133 0 : if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
134 0 : return aResult.ParseEnumValue(aValue, kCaptionAlignTable, false);
135 : }
136 :
137 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
138 0 : aResult);
139 : }
140 :
141 : static
142 0 : void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
143 : {
144 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TableBorder)) {
145 0 : nsCSSValue* captionSide = aData->ValueForCaptionSide();
146 0 : if (captionSide->GetUnit() == eCSSUnit_Null) {
147 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
148 0 : if (value && value->Type() == nsAttrValue::eEnum)
149 0 : captionSide->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
150 : }
151 : }
152 :
153 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
154 0 : }
155 :
156 : NS_IMETHODIMP_(bool)
157 0 : nsHTMLTableCaptionElement::IsAttributeMapped(const nsIAtom* aAttribute) const
158 : {
159 : static const MappedAttributeEntry attributes[] = {
160 : { &nsGkAtoms::align },
161 : { nsnull }
162 : };
163 :
164 : static const MappedAttributeEntry* const map[] = {
165 : attributes,
166 : sCommonAttributeMap,
167 : };
168 :
169 0 : return FindAttributeDependence(aAttribute, map);
170 : }
171 :
172 :
173 :
174 : nsMapRuleToAttributesFunc
175 0 : nsHTMLTableCaptionElement::GetAttributeMappingFunction() const
176 : {
177 0 : return &MapAttributesIntoRule;
178 : }
|