~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/html/HTMLTableCellElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
24
 * Boston, MA 02111-1307, USA.
 
25
 */
 
26
#include "config.h"
 
27
#include "HTMLTableCellElement.h"
 
28
 
 
29
#include "CSSPropertyNames.h"
 
30
#include "CSSValueKeywords.h"
 
31
#include "HTMLNames.h"
 
32
#include "HTMLTableElement.h"
 
33
#include "RenderTableCell.h"
 
34
 
 
35
using std::max;
 
36
using std::min;
 
37
 
 
38
namespace WebCore {
 
39
 
 
40
// Clamp rowspan at 8k to match Firefox.
 
41
static const int maxRowspan = 8190;
 
42
 
 
43
using namespace HTMLNames;
 
44
 
 
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)
 
53
{
 
54
}
 
55
 
 
56
HTMLTableCellElement::~HTMLTableCellElement()
 
57
{
 
58
}
 
59
 
 
60
int HTMLTableCellElement::cellIndex() const
 
61
{
 
62
    int index = 0;
 
63
    for (const Node * node = previousSibling(); node; node = node->previousSibling()) {
 
64
        if (node->hasTagName(tdTag) || node->hasTagName(thTag))
 
65
            index++;
 
66
    }
 
67
    
 
68
    return index;
 
69
}
 
70
 
 
71
bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
 
72
{
 
73
    if (attrName == nowrapAttr) {
 
74
        result = eUniversal;
 
75
        return false;
 
76
    }
 
77
    
 
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;
 
82
    }
 
83
 
 
84
    return HTMLTablePartElement::mapToEntry(attrName, result);
 
85
}
 
86
 
 
87
void HTMLTableCellElement::parseMappedAttribute(MappedAttribute *attr)
 
88
{
 
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) {
 
100
        if (!attr->isNull())
 
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());
 
107
        }
 
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());
 
113
        }
 
114
    } else
 
115
        HTMLTablePartElement::parseMappedAttribute(attr);
 
116
}
 
117
 
 
118
// used by table cells to share style decls created by the enclosing table.
 
119
CSSMutableStyleDeclaration* HTMLTableCellElement::additionalAttributeStyleDecl()
 
120
{
 
121
    Node* p = parentNode();
 
122
    while (p && !p->hasTagName(tableTag))
 
123
        p = p->parentNode();
 
124
    return p ? static_cast<HTMLTableElement*>(p)->getSharedCellDecl() : 0;
 
125
}
 
126
 
 
127
bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const
 
128
{
 
129
    return attr->name() == backgroundAttr;
 
130
}
 
131
 
 
132
String HTMLTableCellElement::abbr() const
 
133
{
 
134
    return getAttribute(abbrAttr);
 
135
}
 
136
 
 
137
void HTMLTableCellElement::setAbbr(const String &value)
 
138
{
 
139
    setAttribute(abbrAttr, value);
 
140
}
 
141
 
 
142
String HTMLTableCellElement::align() const
 
143
{
 
144
    return getAttribute(alignAttr);
 
145
}
 
146
 
 
147
void HTMLTableCellElement::setAlign(const String &value)
 
148
{
 
149
    setAttribute(alignAttr, value);
 
150
}
 
151
 
 
152
String HTMLTableCellElement::axis() const
 
153
{
 
154
    return getAttribute(axisAttr);
 
155
}
 
156
 
 
157
void HTMLTableCellElement::setAxis(const String &value)
 
158
{
 
159
    setAttribute(axisAttr, value);
 
160
}
 
161
 
 
162
String HTMLTableCellElement::bgColor() const
 
163
{
 
164
    return getAttribute(bgcolorAttr);
 
165
}
 
166
 
 
167
void HTMLTableCellElement::setBgColor(const String &value)
 
168
{
 
169
    setAttribute(bgcolorAttr, value);
 
170
}
 
171
 
 
172
String HTMLTableCellElement::ch() const
 
173
{
 
174
    return getAttribute(charAttr);
 
175
}
 
176
 
 
177
void HTMLTableCellElement::setCh(const String &value)
 
178
{
 
179
    setAttribute(charAttr, value);
 
180
}
 
181
 
 
182
String HTMLTableCellElement::chOff() const
 
183
{
 
184
    return getAttribute(charoffAttr);
 
185
}
 
186
 
 
187
void HTMLTableCellElement::setChOff(const String &value)
 
188
{
 
189
    setAttribute(charoffAttr, value);
 
190
}
 
191
 
 
192
void HTMLTableCellElement::setColSpan(int n)
 
193
{
 
194
    setAttribute(colspanAttr, String::number(n));
 
195
}
 
196
 
 
197
String HTMLTableCellElement::headers() const
 
198
{
 
199
    return getAttribute(headersAttr);
 
200
}
 
201
 
 
202
void HTMLTableCellElement::setHeaders(const String &value)
 
203
{
 
204
    setAttribute(headersAttr, value);
 
205
}
 
206
 
 
207
String HTMLTableCellElement::height() const
 
208
{
 
209
    return getAttribute(heightAttr);
 
210
}
 
211
 
 
212
void HTMLTableCellElement::setHeight(const String &value)
 
213
{
 
214
    setAttribute(heightAttr, value);
 
215
}
 
216
 
 
217
bool HTMLTableCellElement::noWrap() const
 
218
{
 
219
    return !getAttribute(nowrapAttr).isNull();
 
220
}
 
221
 
 
222
void HTMLTableCellElement::setNoWrap(bool b)
 
223
{
 
224
    setAttribute(nowrapAttr, b ? "" : 0);
 
225
}
 
226
 
 
227
void HTMLTableCellElement::setRowSpan(int n)
 
228
{
 
229
    setAttribute(rowspanAttr, String::number(n));
 
230
}
 
231
 
 
232
String HTMLTableCellElement::scope() const
 
233
{
 
234
    return getAttribute(scopeAttr);
 
235
}
 
236
 
 
237
void HTMLTableCellElement::setScope(const String &value)
 
238
{
 
239
    setAttribute(scopeAttr, value);
 
240
}
 
241
 
 
242
String HTMLTableCellElement::vAlign() const
 
243
{
 
244
    return getAttribute(valignAttr);
 
245
}
 
246
 
 
247
void HTMLTableCellElement::setVAlign(const String &value)
 
248
{
 
249
    setAttribute(valignAttr, value);
 
250
}
 
251
 
 
252
String HTMLTableCellElement::width() const
 
253
{
 
254
    return getAttribute(widthAttr);
 
255
}
 
256
 
 
257
void HTMLTableCellElement::setWidth(const String &value)
 
258
{
 
259
    setAttribute(widthAttr, value);
 
260
}
 
261
 
 
262
}