WebCore/html/HTMLTableColElement.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "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 HTMLTagStatus HTMLTableColElement::endTagRequirement() const
       
    51 {
       
    52     return hasLocalName(colTag) ? TagStatusForbidden : TagStatusOptional;
       
    53 }
       
    54 
       
    55 int HTMLTableColElement::tagPriority() const
       
    56 {
       
    57     return hasLocalName(colTag) ? 0 : 1;
       
    58 }
       
    59 
       
    60 bool HTMLTableColElement::checkDTD(const Node* newChild)
       
    61 {
       
    62     if (hasLocalName(colTag))
       
    63         return false;
       
    64     
       
    65     if (newChild->isTextNode())
       
    66         return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
       
    67     return newChild->hasTagName(colTag);
       
    68 }
       
    69 
       
    70 bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
       
    71 {
       
    72     if (attrName == widthAttr) {
       
    73         result = eUniversal;
       
    74         return false;
       
    75     }
       
    76 
       
    77     return HTMLTablePartElement::mapToEntry(attrName, result);
       
    78 }
       
    79 
       
    80 void HTMLTableColElement::parseMappedAttribute(Attribute* attr)
       
    81 {
       
    82     if (attr->name() == spanAttr) {
       
    83         m_span = !attr->isNull() ? attr->value().toInt() : 1;
       
    84         if (renderer() && renderer()->isTableCol())
       
    85             renderer()->updateFromElement();
       
    86     } else if (attr->name() == widthAttr) {
       
    87         if (!attr->value().isEmpty()) {
       
    88             addCSSLength(attr, CSSPropertyWidth, attr->value());
       
    89             if (renderer() && renderer()->isTableCol()) {
       
    90                 RenderTableCol* col = toRenderTableCol(renderer());
       
    91                 int newWidth = width().toInt();
       
    92                 if (newWidth != col->width())
       
    93                     col->setNeedsLayoutAndPrefWidthsRecalc();
       
    94             }
       
    95         }
       
    96     } else
       
    97         HTMLTablePartElement::parseMappedAttribute(attr);
       
    98 }
       
    99 
       
   100 // used by table columns and column groups to share style decls created by the enclosing table.
       
   101 void HTMLTableColElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
       
   102 {
       
   103     if (!hasLocalName(colgroupTag))
       
   104         return;
       
   105     Node* p = parentNode();
       
   106     while (p && !p->hasTagName(tableTag))
       
   107         p = p->parentNode();
       
   108     if (!p)
       
   109         return;
       
   110     static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(false, results);
       
   111 }
       
   112 
       
   113 void HTMLTableColElement::setSpan(int n)
       
   114 {
       
   115     setAttribute(spanAttr, String::number(n));
       
   116 }
       
   117 
       
   118 String HTMLTableColElement::width() const
       
   119 {
       
   120     return getAttribute(widthAttr);
       
   121 }
       
   122 
       
   123 }