Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / html / HTMLTableCellElement.cpp
blob593968590f1386d806418d45e219cdfb06e45d77
1 /**
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #include "config.h"
26 #include "HTMLTableCellElement.h"
28 #include "CSSPropertyNames.h"
29 #include "CSSValueKeywords.h"
30 #include "HTMLNames.h"
31 #include "HTMLTableElement.h"
32 #include "MappedAttribute.h"
33 #include "RenderTableCell.h"
35 using std::max;
36 using std::min;
38 namespace WebCore {
40 // Clamp rowspan at 8k to match Firefox.
41 static const int maxRowspan = 8190;
43 using namespace HTMLNames;
45 HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, Document *doc)
46 : HTMLTablePartElement(tagName, doc)
47 , _row(-1)
48 , _col(-1)
49 , rSpan(1)
50 , cSpan(1)
51 , rowHeight(0)
52 , m_solid(false)
56 HTMLTableCellElement::~HTMLTableCellElement()
60 int HTMLTableCellElement::cellIndex() const
62 int index = 0;
63 for (const Node * node = previousSibling(); node; node = node->previousSibling()) {
64 if (node->hasTagName(tdTag) || node->hasTagName(thTag))
65 index++;
68 return index;
71 bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
73 if (attrName == nowrapAttr) {
74 result = eUniversal;
75 return false;
78 if (attrName == widthAttr ||
79 attrName == heightAttr) {
80 result = eCell; // Because of the quirky behavior of ignoring 0 values, cells are special.
81 return false;
84 return HTMLTablePartElement::mapToEntry(attrName, result);
87 void HTMLTableCellElement::parseMappedAttribute(MappedAttribute *attr)
89 if (attr->name() == rowspanAttr) {
90 rSpan = !attr->isNull() ? attr->value().toInt() : 1;
91 rSpan = max(1, min(rSpan, maxRowspan));
92 if (renderer() && renderer()->isTableCell())
93 toRenderTableCell(renderer())->updateFromElement();
94 } else if (attr->name() == colspanAttr) {
95 cSpan = !attr->isNull() ? attr->value().toInt() : 1;
96 cSpan = max(1, cSpan);
97 if (renderer() && renderer()->isTableCell())
98 toRenderTableCell(renderer())->updateFromElement();
99 } else if (attr->name() == nowrapAttr) {
100 if (!attr->isNull())
101 addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueWebkitNowrap);
102 } else if (attr->name() == widthAttr) {
103 if (!attr->value().isEmpty()) {
104 int widthInt = attr->value().toInt();
105 if (widthInt > 0) // width="0" is ignored for compatibility with WinIE.
106 addCSSLength(attr, CSSPropertyWidth, attr->value());
108 } else if (attr->name() == heightAttr) {
109 if (!attr->value().isEmpty()) {
110 int heightInt = attr->value().toInt();
111 if (heightInt > 0) // height="0" is ignored for compatibility with WinIE.
112 addCSSLength(attr, CSSPropertyHeight, attr->value());
114 } else
115 HTMLTablePartElement::parseMappedAttribute(attr);
118 // used by table cells to share style decls created by the enclosing table.
119 void HTMLTableCellElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
121 Node* p = parentNode();
122 while (p && !p->hasTagName(tableTag))
123 p = p->parentNode();
124 if (!p)
125 return;
126 static_cast<HTMLTableElement*>(p)->addSharedCellDecls(results);
129 bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const
131 return attr->name() == backgroundAttr;
134 String HTMLTableCellElement::abbr() const
136 return getAttribute(abbrAttr);
139 void HTMLTableCellElement::setAbbr(const String &value)
141 setAttribute(abbrAttr, value);
144 String HTMLTableCellElement::align() const
146 return getAttribute(alignAttr);
149 void HTMLTableCellElement::setAlign(const String &value)
151 setAttribute(alignAttr, value);
154 String HTMLTableCellElement::axis() const
156 return getAttribute(axisAttr);
159 void HTMLTableCellElement::setAxis(const String &value)
161 setAttribute(axisAttr, value);
164 String HTMLTableCellElement::bgColor() const
166 return getAttribute(bgcolorAttr);
169 void HTMLTableCellElement::setBgColor(const String &value)
171 setAttribute(bgcolorAttr, value);
174 String HTMLTableCellElement::ch() const
176 return getAttribute(charAttr);
179 void HTMLTableCellElement::setCh(const String &value)
181 setAttribute(charAttr, value);
184 String HTMLTableCellElement::chOff() const
186 return getAttribute(charoffAttr);
189 void HTMLTableCellElement::setChOff(const String &value)
191 setAttribute(charoffAttr, value);
194 void HTMLTableCellElement::setColSpan(int n)
196 setAttribute(colspanAttr, String::number(n));
199 String HTMLTableCellElement::headers() const
201 return getAttribute(headersAttr);
204 void HTMLTableCellElement::setHeaders(const String &value)
206 setAttribute(headersAttr, value);
209 String HTMLTableCellElement::height() const
211 return getAttribute(heightAttr);
214 void HTMLTableCellElement::setHeight(const String &value)
216 setAttribute(heightAttr, value);
219 bool HTMLTableCellElement::noWrap() const
221 return !getAttribute(nowrapAttr).isNull();
224 void HTMLTableCellElement::setNoWrap(bool b)
226 setAttribute(nowrapAttr, b ? "" : 0);
229 void HTMLTableCellElement::setRowSpan(int n)
231 setAttribute(rowspanAttr, String::number(n));
234 String HTMLTableCellElement::scope() const
236 return getAttribute(scopeAttr);
239 void HTMLTableCellElement::setScope(const String &value)
241 setAttribute(scopeAttr, value);
244 String HTMLTableCellElement::vAlign() const
246 return getAttribute(valignAttr);
249 void HTMLTableCellElement::setVAlign(const String &value)
251 setAttribute(valignAttr, value);
254 String HTMLTableCellElement::width() const
256 return getAttribute(widthAttr);
259 void HTMLTableCellElement::setWidth(const String &value)
261 setAttribute(widthAttr, value);
264 void HTMLTableCellElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
266 HTMLTablePartElement::addSubresourceAttributeURLs(urls);
268 addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr)));