2
* This file is part of the DOM implementation for KDE.
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.
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.
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.
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., 59 Temple Place - Suite 330,
24
* Boston, MA 02111-1307, USA.
27
#include "HTMLTableCellElement.h"
29
#include "CSSPropertyNames.h"
30
#include "CSSValueKeywords.h"
31
#include "HTMLNames.h"
32
#include "HTMLTableElement.h"
33
#include "RenderTableCell.h"
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)
56
HTMLTableCellElement::~HTMLTableCellElement()
60
int HTMLTableCellElement::cellIndex() const
63
for (const Node * node = previousSibling(); node; node = node->previousSibling()) {
64
if (node->hasTagName(tdTag) || node->hasTagName(thTag))
71
bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
73
if (attrName == nowrapAttr) {
78
if (attrName == widthAttr ||
79
attrName == heightAttr) {
80
result = eCell; // Because of the quirky behavior of ignoring 0 values, cells are special.
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
static_cast<RenderTableCell*>(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
static_cast<RenderTableCell*>(renderer())->updateFromElement();
99
} else if (attr->name() == nowrapAttr) {
101
addCSSProperty(attr, CSS_PROP_WHITE_SPACE, CSS_VAL__WEBKIT_NOWRAP);
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, CSS_PROP_WIDTH, 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, CSS_PROP_HEIGHT, attr->value());
115
HTMLTablePartElement::parseMappedAttribute(attr);
118
// used by table cells to share style decls created by the enclosing table.
119
CSSMutableStyleDeclaration* HTMLTableCellElement::additionalAttributeStyleDecl()
121
Node* p = parentNode();
122
while (p && !p->hasTagName(tableTag))
124
return p ? static_cast<HTMLTableElement*>(p)->getSharedCellDecl() : 0;
127
bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const
129
return attr->name() == backgroundAttr;
132
String HTMLTableCellElement::abbr() const
134
return getAttribute(abbrAttr);
137
void HTMLTableCellElement::setAbbr(const String &value)
139
setAttribute(abbrAttr, value);
142
String HTMLTableCellElement::align() const
144
return getAttribute(alignAttr);
147
void HTMLTableCellElement::setAlign(const String &value)
149
setAttribute(alignAttr, value);
152
String HTMLTableCellElement::axis() const
154
return getAttribute(axisAttr);
157
void HTMLTableCellElement::setAxis(const String &value)
159
setAttribute(axisAttr, value);
162
String HTMLTableCellElement::bgColor() const
164
return getAttribute(bgcolorAttr);
167
void HTMLTableCellElement::setBgColor(const String &value)
169
setAttribute(bgcolorAttr, value);
172
String HTMLTableCellElement::ch() const
174
return getAttribute(charAttr);
177
void HTMLTableCellElement::setCh(const String &value)
179
setAttribute(charAttr, value);
182
String HTMLTableCellElement::chOff() const
184
return getAttribute(charoffAttr);
187
void HTMLTableCellElement::setChOff(const String &value)
189
setAttribute(charoffAttr, value);
192
void HTMLTableCellElement::setColSpan(int n)
194
setAttribute(colspanAttr, String::number(n));
197
String HTMLTableCellElement::headers() const
199
return getAttribute(headersAttr);
202
void HTMLTableCellElement::setHeaders(const String &value)
204
setAttribute(headersAttr, value);
207
String HTMLTableCellElement::height() const
209
return getAttribute(heightAttr);
212
void HTMLTableCellElement::setHeight(const String &value)
214
setAttribute(heightAttr, value);
217
bool HTMLTableCellElement::noWrap() const
219
return !getAttribute(nowrapAttr).isNull();
222
void HTMLTableCellElement::setNoWrap(bool b)
224
setAttribute(nowrapAttr, b ? "" : 0);
227
void HTMLTableCellElement::setRowSpan(int n)
229
setAttribute(rowspanAttr, String::number(n));
232
String HTMLTableCellElement::scope() const
234
return getAttribute(scopeAttr);
237
void HTMLTableCellElement::setScope(const String &value)
239
setAttribute(scopeAttr, value);
242
String HTMLTableCellElement::vAlign() const
244
return getAttribute(valignAttr);
247
void HTMLTableCellElement::setVAlign(const String &value)
249
setAttribute(valignAttr, value);
252
String HTMLTableCellElement::width() const
254
return getAttribute(widthAttr);
257
void HTMLTableCellElement::setWidth(const String &value)
259
setAttribute(widthAttr, value);