WebCore/html/HTMLTableSectionElement.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 "HTMLTableSectionElement.h"
       
    27 
       
    28 #include "ExceptionCode.h"
       
    29 #include "HTMLCollection.h"
       
    30 #include "HTMLNames.h"
       
    31 #include "HTMLTableRowElement.h"
       
    32 #include "HTMLTableElement.h"
       
    33 #include "NodeList.h"
       
    34 #include "Text.h"
       
    35 
       
    36 namespace WebCore {
       
    37 
       
    38 using namespace HTMLNames;
       
    39 
       
    40 inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document)
       
    41     : HTMLTablePartElement(tagName, document)
       
    42 {
       
    43 }
       
    44 
       
    45 PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document* document)
       
    46 {
       
    47     return adoptRef(new HTMLTableSectionElement(tagName, document));
       
    48 }
       
    49 
       
    50 bool HTMLTableSectionElement::checkDTD(const Node* newChild)
       
    51 {
       
    52     if (newChild->isTextNode())
       
    53         return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
       
    54     return newChild->hasTagName(trTag) || newChild->hasTagName(formTag) ||
       
    55            newChild->hasTagName(scriptTag);
       
    56 }
       
    57 
       
    58 ContainerNode* HTMLTableSectionElement::legacyParserAddChild(PassRefPtr<Node> child)
       
    59 {
       
    60     if (child->hasTagName(formTag)) {
       
    61         // First add the child.
       
    62         HTMLTablePartElement::legacyParserAddChild(child);
       
    63 
       
    64         // Now simply return ourselves as the container to insert into.
       
    65         // This has the effect of demoting the form to a leaf and moving it safely out of the way.
       
    66         return this;
       
    67     }
       
    68 
       
    69     return HTMLTablePartElement::legacyParserAddChild(child);
       
    70 }
       
    71 
       
    72 // used by table row groups to share style decls created by the enclosing table.
       
    73 void HTMLTableSectionElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
       
    74 {
       
    75     Node* p = parentNode();
       
    76     while (p && !p->hasTagName(tableTag))
       
    77         p = p->parentNode();
       
    78     if (!p)
       
    79         return;
       
    80     static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(true, results);
       
    81 }
       
    82 
       
    83 // these functions are rather slow, since we need to get the row at
       
    84 // the index... but they aren't used during usual HTML parsing anyway
       
    85 PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec)
       
    86 {
       
    87     RefPtr<HTMLTableRowElement> row;
       
    88     RefPtr<HTMLCollection> children = rows();
       
    89     int numRows = children ? (int)children->length() : 0;
       
    90     if (index < -1 || index > numRows)
       
    91         ec = INDEX_SIZE_ERR; // per the DOM
       
    92     else {
       
    93         row = HTMLTableRowElement::create(trTag, document());
       
    94         if (numRows == index || index == -1)
       
    95             appendChild(row, ec);
       
    96         else {
       
    97             Node* n;
       
    98             if (index < 1)
       
    99                 n = firstChild();
       
   100             else
       
   101                 n = children->item(index);
       
   102             insertBefore(row, n, ec);
       
   103         }
       
   104     }
       
   105     return row.release();
       
   106 }
       
   107 
       
   108 void HTMLTableSectionElement::deleteRow(int index, ExceptionCode& ec)
       
   109 {
       
   110     RefPtr<HTMLCollection> children = rows();
       
   111     int numRows = children ? (int)children->length() : 0;
       
   112     if (index == -1)
       
   113         index = numRows - 1;
       
   114     if (index >= 0 && index < numRows) {
       
   115         RefPtr<Node> row = children->item(index);
       
   116         HTMLElement::removeChild(row.get(), ec);
       
   117     } else
       
   118         ec = INDEX_SIZE_ERR;
       
   119 }
       
   120 
       
   121 int HTMLTableSectionElement::numRows() const
       
   122 {
       
   123     int rows = 0;
       
   124     const Node *n = firstChild();
       
   125     while (n) {
       
   126         if (n->hasTagName(trTag))
       
   127             rows++;
       
   128         n = n->nextSibling();
       
   129     }
       
   130 
       
   131     return rows;
       
   132 }
       
   133 
       
   134 String HTMLTableSectionElement::align() const
       
   135 {
       
   136     return getAttribute(alignAttr);
       
   137 }
       
   138 
       
   139 void HTMLTableSectionElement::setAlign(const String &value)
       
   140 {
       
   141     setAttribute(alignAttr, value);
       
   142 }
       
   143 
       
   144 String HTMLTableSectionElement::ch() const
       
   145 {
       
   146     return getAttribute(charAttr);
       
   147 }
       
   148 
       
   149 void HTMLTableSectionElement::setCh(const String &value)
       
   150 {
       
   151     setAttribute(charAttr, value);
       
   152 }
       
   153 
       
   154 String HTMLTableSectionElement::chOff() const
       
   155 {
       
   156     return getAttribute(charoffAttr);
       
   157 }
       
   158 
       
   159 void HTMLTableSectionElement::setChOff(const String &value)
       
   160 {
       
   161     setAttribute(charoffAttr, value);
       
   162 }
       
   163 
       
   164 String HTMLTableSectionElement::vAlign() const
       
   165 {
       
   166     return getAttribute(valignAttr);
       
   167 }
       
   168 
       
   169 void HTMLTableSectionElement::setVAlign(const String &value)
       
   170 {
       
   171     setAttribute(valignAttr, value);
       
   172 }
       
   173 
       
   174 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
       
   175 {
       
   176     return HTMLCollection::create(this, TSectionRows);
       
   177 }
       
   178 
       
   179 }