• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Apple Computer, Inc.
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 "HTMLTableColElement.h"
27 
28 #include "CSSPropertyNames.h"
29 #include "HTMLNames.h"
30 #include "HTMLTableElement.h"
31 #include "MappedAttribute.h"
32 #include "RenderTableCol.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             renderer()->updateFromElement();
81     } else if (attr->name() == widthAttr) {
82         if (!attr->value().isEmpty()) {
83             addCSSLength(attr, CSSPropertyWidth, attr->value());
84             if (renderer() && renderer()->isTableCol()) {
85                 RenderTableCol* col = toRenderTableCol(renderer());
86                 int newWidth = width().toInt();
87                 if (newWidth != col->width())
88                     col->setNeedsLayoutAndPrefWidthsRecalc();
89             }
90         }
91     } else
92         HTMLTablePartElement::parseMappedAttribute(attr);
93 }
94 
95 // used by table columns and column groups to share style decls created by the enclosing table.
additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration * > & results)96 void HTMLTableColElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
97 {
98     if (!hasLocalName(colgroupTag))
99         return;
100     Node* p = parentNode();
101     while (p && !p->hasTagName(tableTag))
102         p = p->parentNode();
103     if (!p)
104         return;
105     static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(false, results);
106 }
107 
align() const108 String HTMLTableColElement::align() const
109 {
110     return getAttribute(alignAttr);
111 }
112 
setAlign(const String & value)113 void HTMLTableColElement::setAlign(const String &value)
114 {
115     setAttribute(alignAttr, value);
116 }
117 
ch() const118 String HTMLTableColElement::ch() const
119 {
120     return getAttribute(charAttr);
121 }
122 
setCh(const String & value)123 void HTMLTableColElement::setCh(const String &value)
124 {
125     setAttribute(charAttr, value);
126 }
127 
chOff() const128 String HTMLTableColElement::chOff() const
129 {
130     return getAttribute(charoffAttr);
131 }
132 
setChOff(const String & value)133 void HTMLTableColElement::setChOff(const String &value)
134 {
135     setAttribute(charoffAttr, value);
136 }
137 
setSpan(int n)138 void HTMLTableColElement::setSpan(int n)
139 {
140     setAttribute(spanAttr, String::number(n));
141 }
142 
vAlign() const143 String HTMLTableColElement::vAlign() const
144 {
145     return getAttribute(valignAttr);
146 }
147 
setVAlign(const String & value)148 void HTMLTableColElement::setVAlign(const String &value)
149 {
150     setAttribute(valignAttr, value);
151 }
152 
width() const153 String HTMLTableColElement::width() const
154 {
155     return getAttribute(widthAttr);
156 }
157 
setWidth(const String & value)158 void HTMLTableColElement::setWidth(const String &value)
159 {
160     setAttribute(widthAttr, value);
161 }
162 
163 }
164