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