Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1997 Martin Jones (mjones (at) kde.org)
      3  *           (C) 1997 Torben Weis (weis (at) kde.org)
      4  *           (C) 1998 Waldo Bastian (bastian (at) kde.org)
      5  *           (C) 1999 Lars Knoll (knoll (at) kde.org)
      6  *           (C) 1999 Antti Koivisto (koivisto (at) 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 "HTMLTableColElement.h"
     27 
     28 #include "Attribute.h"
     29 #include "CSSPropertyNames.h"
     30 #include "HTMLNames.h"
     31 #include "HTMLTableElement.h"
     32 #include "RenderTableCol.h"
     33 #include "Text.h"
     34 
     35 namespace WebCore {
     36 
     37 using namespace HTMLNames;
     38 
     39 inline HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document* document)
     40     : HTMLTablePartElement(tagName, document)
     41     , m_span(1)
     42 {
     43 }
     44 
     45 PassRefPtr<HTMLTableColElement> HTMLTableColElement::create(const QualifiedName& tagName, Document* document)
     46 {
     47     return adoptRef(new HTMLTableColElement(tagName, document));
     48 }
     49 
     50 bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
     51 {
     52     if (attrName == widthAttr) {
     53         result = eUniversal;
     54         return false;
     55     }
     56 
     57     return HTMLTablePartElement::mapToEntry(attrName, result);
     58 }
     59 
     60 void HTMLTableColElement::parseMappedAttribute(Attribute* attr)
     61 {
     62     if (attr->name() == spanAttr) {
     63         m_span = !attr->isNull() ? attr->value().toInt() : 1;
     64         if (renderer() && renderer()->isTableCol())
     65             renderer()->updateFromElement();
     66     } else if (attr->name() == widthAttr) {
     67         if (!attr->value().isEmpty()) {
     68             addCSSLength(attr, CSSPropertyWidth, attr->value());
     69             if (renderer() && renderer()->isTableCol()) {
     70                 RenderTableCol* col = toRenderTableCol(renderer());
     71                 int newWidth = width().toInt();
     72                 if (newWidth != col->width())
     73                     col->setNeedsLayoutAndPrefWidthsRecalc();
     74             }
     75         }
     76     } else
     77         HTMLTablePartElement::parseMappedAttribute(attr);
     78 }
     79 
     80 // used by table columns and column groups to share style decls created by the enclosing table.
     81 void HTMLTableColElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
     82 {
     83     if (!hasLocalName(colgroupTag))
     84         return;
     85     ContainerNode* p = parentNode();
     86     while (p && !p->hasTagName(tableTag))
     87         p = p->parentNode();
     88     if (!p)
     89         return;
     90     static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(false, results);
     91 }
     92 
     93 void HTMLTableColElement::setSpan(int n)
     94 {
     95     setAttribute(spanAttr, String::number(n));
     96 }
     97 
     98 String HTMLTableColElement::width() const
     99 {
    100     return getAttribute(widthAttr);
    101 }
    102 
    103 }
    104