|
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, 2010 Apple Inc. All rights reserved. |
|
8 * |
|
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. |
|
13 * |
|
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. |
|
18 * |
|
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. |
|
23 */ |
|
24 |
|
25 #include "config.h" |
|
26 #include "HTMLTableCellElement.h" |
|
27 |
|
28 #include "Attribute.h" |
|
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 inline HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, Document* document) |
|
46 : HTMLTablePartElement(tagName, document) |
|
47 , m_row(-1) |
|
48 , m_col(-1) |
|
49 , m_rowSpan(1) |
|
50 , m_colSpan(1) |
|
51 { |
|
52 } |
|
53 |
|
54 PassRefPtr<HTMLTableCellElement> HTMLTableCellElement::create(const QualifiedName& tagName, Document* document) |
|
55 { |
|
56 return adoptRef(new HTMLTableCellElement(tagName, document)); |
|
57 } |
|
58 |
|
59 int HTMLTableCellElement::cellIndex() const |
|
60 { |
|
61 int index = 0; |
|
62 for (const Node * node = previousSibling(); node; node = node->previousSibling()) { |
|
63 if (node->hasTagName(tdTag) || node->hasTagName(thTag)) |
|
64 index++; |
|
65 } |
|
66 |
|
67 return index; |
|
68 } |
|
69 |
|
70 bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const |
|
71 { |
|
72 if (attrName == nowrapAttr) { |
|
73 result = eUniversal; |
|
74 return false; |
|
75 } |
|
76 |
|
77 if (attrName == widthAttr || |
|
78 attrName == heightAttr) { |
|
79 result = eCell; // Because of the quirky behavior of ignoring 0 values, cells are special. |
|
80 return false; |
|
81 } |
|
82 |
|
83 return HTMLTablePartElement::mapToEntry(attrName, result); |
|
84 } |
|
85 |
|
86 void HTMLTableCellElement::parseMappedAttribute(Attribute* attr) |
|
87 { |
|
88 if (attr->name() == rowspanAttr) { |
|
89 m_rowSpan = max(1, min(attr->value().toInt(), maxRowspan)); |
|
90 if (renderer() && renderer()->isTableCell()) |
|
91 toRenderTableCell(renderer())->updateFromElement(); |
|
92 } else if (attr->name() == colspanAttr) { |
|
93 m_colSpan = max(1, attr->value().toInt()); |
|
94 if (renderer() && renderer()->isTableCell()) |
|
95 toRenderTableCell(renderer())->updateFromElement(); |
|
96 } else if (attr->name() == nowrapAttr) { |
|
97 if (!attr->isNull()) |
|
98 addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueWebkitNowrap); |
|
99 } else if (attr->name() == widthAttr) { |
|
100 if (!attr->value().isEmpty()) { |
|
101 int widthInt = attr->value().toInt(); |
|
102 if (widthInt > 0) // width="0" is ignored for compatibility with WinIE. |
|
103 addCSSLength(attr, CSSPropertyWidth, attr->value()); |
|
104 } |
|
105 } else if (attr->name() == heightAttr) { |
|
106 if (!attr->value().isEmpty()) { |
|
107 int heightInt = attr->value().toInt(); |
|
108 if (heightInt > 0) // height="0" is ignored for compatibility with WinIE. |
|
109 addCSSLength(attr, CSSPropertyHeight, attr->value()); |
|
110 } |
|
111 } else |
|
112 HTMLTablePartElement::parseMappedAttribute(attr); |
|
113 } |
|
114 |
|
115 // used by table cells to share style decls created by the enclosing table. |
|
116 void HTMLTableCellElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results) |
|
117 { |
|
118 Node* p = parentNode(); |
|
119 while (p && !p->hasTagName(tableTag)) |
|
120 p = p->parentNode(); |
|
121 if (!p) |
|
122 return; |
|
123 static_cast<HTMLTableElement*>(p)->addSharedCellDecls(results); |
|
124 } |
|
125 |
|
126 bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const |
|
127 { |
|
128 return attr->name() == backgroundAttr; |
|
129 } |
|
130 |
|
131 String HTMLTableCellElement::abbr() const |
|
132 { |
|
133 return getAttribute(abbrAttr); |
|
134 } |
|
135 |
|
136 String HTMLTableCellElement::axis() const |
|
137 { |
|
138 return getAttribute(axisAttr); |
|
139 } |
|
140 |
|
141 void HTMLTableCellElement::setColSpan(int n) |
|
142 { |
|
143 setAttribute(colspanAttr, String::number(n)); |
|
144 } |
|
145 |
|
146 String HTMLTableCellElement::headers() const |
|
147 { |
|
148 return getAttribute(headersAttr); |
|
149 } |
|
150 |
|
151 void HTMLTableCellElement::setRowSpan(int n) |
|
152 { |
|
153 setAttribute(rowspanAttr, String::number(n)); |
|
154 } |
|
155 |
|
156 String HTMLTableCellElement::scope() const |
|
157 { |
|
158 return getAttribute(scopeAttr); |
|
159 } |
|
160 |
|
161 void HTMLTableCellElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const |
|
162 { |
|
163 HTMLTablePartElement::addSubresourceAttributeURLs(urls); |
|
164 |
|
165 addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr))); |
|
166 } |
|
167 |
|
168 } |