1 /**
2 * This file is part of the DOM implementation for KDE.
3 *
4 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
5 * (C) 1997 Torben Weis (weis@kde.org)
6 * (C) 1998 Waldo Bastian (bastian@kde.org)
7 * (C) 1999 Lars Knoll (knoll@kde.org)
8 * (C) 1999 Antti Koivisto (koivisto@kde.org)
9 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25 */
26
27 #include "config.h"
28 #include "HTMLTableCellElement.h"
29
30 #include "CSSPropertyNames.h"
31 #include "CSSValueKeywords.h"
32 #include "HTMLNames.h"
33 #include "HTMLTableElement.h"
34 #include "MappedAttribute.h"
35 #include "RenderTableCell.h"
36 #ifdef ANDROID_LAYOUT
37 #include "Document.h"
38 #include "Frame.h"
39 #include "Settings.h"
40 #endif
41
42 using std::max;
43 using std::min;
44
45 namespace WebCore {
46
47 // Clamp rowspan at 8k to match Firefox.
48 static const int maxRowspan = 8190;
49
50 using namespace HTMLNames;
51
HTMLTableCellElement(const QualifiedName & tagName,Document * doc)52 HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, Document *doc)
53 : HTMLTablePartElement(tagName, doc)
54 , _row(-1)
55 , _col(-1)
56 , rSpan(1)
57 , cSpan(1)
58 , rowHeight(0)
59 , m_solid(false)
60 {
61 }
62
~HTMLTableCellElement()63 HTMLTableCellElement::~HTMLTableCellElement()
64 {
65 }
66
cellIndex() const67 int HTMLTableCellElement::cellIndex() const
68 {
69 int index = 0;
70 for (const Node * node = previousSibling(); node; node = node->previousSibling()) {
71 if (node->hasTagName(tdTag) || node->hasTagName(thTag))
72 index++;
73 }
74
75 return index;
76 }
77
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const78 bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
79 {
80 if (attrName == nowrapAttr) {
81 result = eUniversal;
82 return false;
83 }
84
85 if (attrName == widthAttr ||
86 attrName == heightAttr) {
87 result = eCell; // Because of the quirky behavior of ignoring 0 values, cells are special.
88 return false;
89 }
90
91 return HTMLTablePartElement::mapToEntry(attrName, result);
92 }
93
parseMappedAttribute(MappedAttribute * attr)94 void HTMLTableCellElement::parseMappedAttribute(MappedAttribute *attr)
95 {
96 if (attr->name() == rowspanAttr) {
97 rSpan = !attr->isNull() ? attr->value().toInt() : 1;
98 rSpan = max(1, min(rSpan, maxRowspan));
99 if (renderer() && renderer()->isTableCell())
100 toRenderTableCell(renderer())->updateFromElement();
101 } else if (attr->name() == colspanAttr) {
102 cSpan = !attr->isNull() ? attr->value().toInt() : 1;
103 cSpan = max(1, cSpan);
104 if (renderer() && renderer()->isTableCell())
105 toRenderTableCell(renderer())->updateFromElement();
106 } else if (attr->name() == nowrapAttr) {
107 #ifdef ANDROID_LAYOUT
108 if (!(document()->frame()) || document()->frame()->settings()->layoutAlgorithm() != Settings::kLayoutSSR)
109 #endif
110 if (!attr->isNull())
111 addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueWebkitNowrap);
112 } else if (attr->name() == widthAttr) {
113 if (!attr->value().isEmpty()) {
114 int widthInt = attr->value().toInt();
115 if (widthInt > 0) // width="0" is ignored for compatibility with WinIE.
116 addCSSLength(attr, CSSPropertyWidth, attr->value());
117 }
118 } else if (attr->name() == heightAttr) {
119 if (!attr->value().isEmpty()) {
120 int heightInt = attr->value().toInt();
121 if (heightInt > 0) // height="0" is ignored for compatibility with WinIE.
122 addCSSLength(attr, CSSPropertyHeight, attr->value());
123 }
124 } else
125 HTMLTablePartElement::parseMappedAttribute(attr);
126 }
127
128 // used by table cells to share style decls created by the enclosing table.
additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration * > & results)129 void HTMLTableCellElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
130 {
131 Node* p = parentNode();
132 while (p && !p->hasTagName(tableTag))
133 p = p->parentNode();
134 if (!p)
135 return;
136 static_cast<HTMLTableElement*>(p)->addSharedCellDecls(results);
137 }
138
isURLAttribute(Attribute * attr) const139 bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const
140 {
141 return attr->name() == backgroundAttr;
142 }
143
abbr() const144 String HTMLTableCellElement::abbr() const
145 {
146 return getAttribute(abbrAttr);
147 }
148
setAbbr(const String & value)149 void HTMLTableCellElement::setAbbr(const String &value)
150 {
151 setAttribute(abbrAttr, value);
152 }
153
align() const154 String HTMLTableCellElement::align() const
155 {
156 return getAttribute(alignAttr);
157 }
158
setAlign(const String & value)159 void HTMLTableCellElement::setAlign(const String &value)
160 {
161 setAttribute(alignAttr, value);
162 }
163
axis() const164 String HTMLTableCellElement::axis() const
165 {
166 return getAttribute(axisAttr);
167 }
168
setAxis(const String & value)169 void HTMLTableCellElement::setAxis(const String &value)
170 {
171 setAttribute(axisAttr, value);
172 }
173
bgColor() const174 String HTMLTableCellElement::bgColor() const
175 {
176 return getAttribute(bgcolorAttr);
177 }
178
setBgColor(const String & value)179 void HTMLTableCellElement::setBgColor(const String &value)
180 {
181 setAttribute(bgcolorAttr, value);
182 }
183
ch() const184 String HTMLTableCellElement::ch() const
185 {
186 return getAttribute(charAttr);
187 }
188
setCh(const String & value)189 void HTMLTableCellElement::setCh(const String &value)
190 {
191 setAttribute(charAttr, value);
192 }
193
chOff() const194 String HTMLTableCellElement::chOff() const
195 {
196 return getAttribute(charoffAttr);
197 }
198
setChOff(const String & value)199 void HTMLTableCellElement::setChOff(const String &value)
200 {
201 setAttribute(charoffAttr, value);
202 }
203
setColSpan(int n)204 void HTMLTableCellElement::setColSpan(int n)
205 {
206 setAttribute(colspanAttr, String::number(n));
207 }
208
headers() const209 String HTMLTableCellElement::headers() const
210 {
211 return getAttribute(headersAttr);
212 }
213
setHeaders(const String & value)214 void HTMLTableCellElement::setHeaders(const String &value)
215 {
216 setAttribute(headersAttr, value);
217 }
218
height() const219 String HTMLTableCellElement::height() const
220 {
221 return getAttribute(heightAttr);
222 }
223
setHeight(const String & value)224 void HTMLTableCellElement::setHeight(const String &value)
225 {
226 setAttribute(heightAttr, value);
227 }
228
noWrap() const229 bool HTMLTableCellElement::noWrap() const
230 {
231 return !getAttribute(nowrapAttr).isNull();
232 }
233
setNoWrap(bool b)234 void HTMLTableCellElement::setNoWrap(bool b)
235 {
236 setAttribute(nowrapAttr, b ? "" : 0);
237 }
238
setRowSpan(int n)239 void HTMLTableCellElement::setRowSpan(int n)
240 {
241 setAttribute(rowspanAttr, String::number(n));
242 }
243
scope() const244 String HTMLTableCellElement::scope() const
245 {
246 return getAttribute(scopeAttr);
247 }
248
setScope(const String & value)249 void HTMLTableCellElement::setScope(const String &value)
250 {
251 setAttribute(scopeAttr, value);
252 }
253
vAlign() const254 String HTMLTableCellElement::vAlign() const
255 {
256 return getAttribute(valignAttr);
257 }
258
setVAlign(const String & value)259 void HTMLTableCellElement::setVAlign(const String &value)
260 {
261 setAttribute(valignAttr, value);
262 }
263
width() const264 String HTMLTableCellElement::width() const
265 {
266 return getAttribute(widthAttr);
267 }
268
setWidth(const String & value)269 void HTMLTableCellElement::setWidth(const String &value)
270 {
271 setAttribute(widthAttr, value);
272 }
273
addSubresourceAttributeURLs(ListHashSet<KURL> & urls) const274 void HTMLTableCellElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
275 {
276 HTMLTablePartElement::addSubresourceAttributeURLs(urls);
277
278 addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr)));
279 }
280
281 }
282