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 "HTMLTableColElement.h"
29
30 #include "CSSPropertyNames.h"
31 #include "HTMLNames.h"
32 #include "HTMLTableElement.h"
33 #include "MappedAttribute.h"
34 #include "RenderTableCol.h"
35 #include "Text.h"
36
37 namespace WebCore {
38
39 using namespace HTMLNames;
40
HTMLTableColElement(const QualifiedName & tagName,Document * doc)41 HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document *doc)
42 : HTMLTablePartElement(tagName, doc)
43 {
44 _span = 1;
45 }
46
endTagRequirement() const47 HTMLTagStatus HTMLTableColElement::endTagRequirement() const
48 {
49 return hasLocalName(colTag) ? TagStatusForbidden : TagStatusOptional;
50 }
51
tagPriority() const52 int HTMLTableColElement::tagPriority() const
53 {
54 return hasLocalName(colTag) ? 0 : 1;
55 }
56
checkDTD(const Node * newChild)57 bool HTMLTableColElement::checkDTD(const Node* newChild)
58 {
59 if (hasLocalName(colTag))
60 return false;
61
62 if (newChild->isTextNode())
63 return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
64 return newChild->hasTagName(colTag);
65 }
66
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const67 bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
68 {
69 if (attrName == widthAttr) {
70 result = eUniversal;
71 return false;
72 }
73
74 return HTMLTablePartElement::mapToEntry(attrName, result);
75 }
76
parseMappedAttribute(MappedAttribute * attr)77 void HTMLTableColElement::parseMappedAttribute(MappedAttribute *attr)
78 {
79 if (attr->name() == spanAttr) {
80 _span = !attr->isNull() ? attr->value().toInt() : 1;
81 if (renderer() && renderer()->isTableCol())
82 renderer()->updateFromElement();
83 } else if (attr->name() == widthAttr) {
84 if (!attr->value().isEmpty()) {
85 addCSSLength(attr, CSSPropertyWidth, attr->value());
86 if (renderer() && renderer()->isTableCol()) {
87 RenderTableCol* col = toRenderTableCol(renderer());
88 int newWidth = width().toInt();
89 if (newWidth != col->width())
90 col->setNeedsLayoutAndPrefWidthsRecalc();
91 }
92 }
93 } else
94 HTMLTablePartElement::parseMappedAttribute(attr);
95 }
96
97 // used by table columns and column groups to share style decls created by the enclosing table.
additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration * > & results)98 void HTMLTableColElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
99 {
100 if (!hasLocalName(colgroupTag))
101 return;
102 Node* p = parentNode();
103 while (p && !p->hasTagName(tableTag))
104 p = p->parentNode();
105 if (!p)
106 return;
107 static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(false, results);
108 }
109
align() const110 String HTMLTableColElement::align() const
111 {
112 return getAttribute(alignAttr);
113 }
114
setAlign(const String & value)115 void HTMLTableColElement::setAlign(const String &value)
116 {
117 setAttribute(alignAttr, value);
118 }
119
ch() const120 String HTMLTableColElement::ch() const
121 {
122 return getAttribute(charAttr);
123 }
124
setCh(const String & value)125 void HTMLTableColElement::setCh(const String &value)
126 {
127 setAttribute(charAttr, value);
128 }
129
chOff() const130 String HTMLTableColElement::chOff() const
131 {
132 return getAttribute(charoffAttr);
133 }
134
setChOff(const String & value)135 void HTMLTableColElement::setChOff(const String &value)
136 {
137 setAttribute(charoffAttr, value);
138 }
139
setSpan(int n)140 void HTMLTableColElement::setSpan(int n)
141 {
142 setAttribute(spanAttr, String::number(n));
143 }
144
vAlign() const145 String HTMLTableColElement::vAlign() const
146 {
147 return getAttribute(valignAttr);
148 }
149
setVAlign(const String & value)150 void HTMLTableColElement::setVAlign(const String &value)
151 {
152 setAttribute(valignAttr, value);
153 }
154
width() const155 String HTMLTableColElement::width() const
156 {
157 return getAttribute(widthAttr);
158 }
159
setWidth(const String & value)160 void HTMLTableColElement::setWidth(const String &value)
161 {
162 setAttribute(widthAttr, value);
163 }
164
165 }
166