WebCore/html/HTMLTableElement.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, 2008, 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 "HTMLTableElement.h"
       
    27 
       
    28 #include "Attribute.h"
       
    29 #include "CSSPropertyNames.h"
       
    30 #include "CSSStyleSheet.h"
       
    31 #include "CSSValueKeywords.h"
       
    32 #include "ExceptionCode.h"
       
    33 #include "HTMLNames.h"
       
    34 #include "HTMLTableCaptionElement.h"
       
    35 #include "HTMLTableRowElement.h"
       
    36 #include "HTMLTableRowsCollection.h"
       
    37 #include "HTMLTableSectionElement.h"
       
    38 #include "RenderTable.h"
       
    39 #include "Text.h"
       
    40 
       
    41 namespace WebCore {
       
    42 
       
    43 using namespace HTMLNames;
       
    44 
       
    45 HTMLTableElement::HTMLTableElement(const QualifiedName& tagName, Document* document)
       
    46     : HTMLElement(tagName, document)
       
    47     , m_borderAttr(false)
       
    48     , m_borderColorAttr(false)
       
    49     , m_frameAttr(false)
       
    50     , m_rulesAttr(UnsetRules)
       
    51     , m_padding(1)
       
    52 {
       
    53     ASSERT(hasTagName(tableTag));
       
    54 }
       
    55 
       
    56 PassRefPtr<HTMLTableElement> HTMLTableElement::create(Document* document)
       
    57 {
       
    58     return adoptRef(new HTMLTableElement(tableTag, document));
       
    59 }
       
    60 
       
    61 PassRefPtr<HTMLTableElement> HTMLTableElement::create(const QualifiedName& tagName, Document* document)
       
    62 {
       
    63     return adoptRef(new HTMLTableElement(tagName, document));
       
    64 }
       
    65 
       
    66 bool HTMLTableElement::checkDTD(const Node* newChild)
       
    67 {
       
    68     if (newChild->isTextNode())
       
    69         return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
       
    70     return newChild->hasTagName(captionTag) ||
       
    71            newChild->hasTagName(colTag) || newChild->hasTagName(colgroupTag) ||
       
    72            newChild->hasTagName(theadTag) || newChild->hasTagName(tfootTag) ||
       
    73            newChild->hasTagName(tbodyTag) || newChild->hasTagName(formTag) ||
       
    74            newChild->hasTagName(scriptTag);
       
    75 }
       
    76 
       
    77 HTMLTableCaptionElement* HTMLTableElement::caption() const
       
    78 {
       
    79     for (Node* child = firstChild(); child; child = child->nextSibling()) {
       
    80         if (child->hasTagName(captionTag))
       
    81             return static_cast<HTMLTableCaptionElement*>(child);
       
    82     }
       
    83     return 0;
       
    84 }
       
    85 
       
    86 void HTMLTableElement::setCaption(PassRefPtr<HTMLTableCaptionElement> newCaption, ExceptionCode& ec)
       
    87 {
       
    88     deleteCaption();
       
    89     insertBefore(newCaption, firstChild(), ec);
       
    90 }
       
    91 
       
    92 HTMLTableSectionElement* HTMLTableElement::tHead() const
       
    93 {
       
    94     for (Node* child = firstChild(); child; child = child->nextSibling()) {
       
    95         if (child->hasTagName(theadTag))
       
    96             return static_cast<HTMLTableSectionElement*>(child);
       
    97     }
       
    98     return 0;
       
    99 }
       
   100 
       
   101 void HTMLTableElement::setTHead(PassRefPtr<HTMLTableSectionElement> newHead, ExceptionCode& ec)
       
   102 {
       
   103     deleteTHead();
       
   104 
       
   105     Node* child;
       
   106     for (child = firstChild(); child; child = child->nextSibling())
       
   107         if (child->isElementNode() && !child->hasTagName(captionTag) && !child->hasTagName(colgroupTag))
       
   108             break;
       
   109 
       
   110     insertBefore(newHead, child, ec);
       
   111 }
       
   112 
       
   113 HTMLTableSectionElement* HTMLTableElement::tFoot() const
       
   114 {
       
   115     for (Node* child = firstChild(); child; child = child->nextSibling()) {
       
   116         if (child->hasTagName(tfootTag))
       
   117             return static_cast<HTMLTableSectionElement*>(child);
       
   118     }
       
   119     return 0;
       
   120 }
       
   121 
       
   122 void HTMLTableElement::setTFoot(PassRefPtr<HTMLTableSectionElement> newFoot, ExceptionCode& ec)
       
   123 {
       
   124     deleteTFoot();
       
   125 
       
   126     Node* child;
       
   127     for (child = firstChild(); child; child = child->nextSibling())
       
   128         if (child->isElementNode() && !child->hasTagName(captionTag) && !child->hasTagName(colgroupTag) && !child->hasTagName(theadTag))
       
   129             break;
       
   130 
       
   131     insertBefore(newFoot, child, ec);
       
   132 }
       
   133 
       
   134 PassRefPtr<HTMLElement> HTMLTableElement::createTHead()
       
   135 {
       
   136     if (HTMLTableSectionElement* existingHead = tHead())
       
   137         return existingHead;
       
   138     RefPtr<HTMLTableSectionElement> head = HTMLTableSectionElement::create(theadTag, document());
       
   139     ExceptionCode ec;
       
   140     setTHead(head, ec);
       
   141     return head.release();
       
   142 }
       
   143 
       
   144 void HTMLTableElement::deleteTHead()
       
   145 {
       
   146     ExceptionCode ec;
       
   147     removeChild(tHead(), ec);
       
   148 }
       
   149 
       
   150 PassRefPtr<HTMLElement> HTMLTableElement::createTFoot()
       
   151 {
       
   152     if (HTMLTableSectionElement* existingFoot = tFoot())
       
   153         return existingFoot;
       
   154     RefPtr<HTMLTableSectionElement> foot = HTMLTableSectionElement::create(tfootTag, document());
       
   155     ExceptionCode ec;
       
   156     setTFoot(foot, ec);
       
   157     return foot.release();
       
   158 }
       
   159 
       
   160 void HTMLTableElement::deleteTFoot()
       
   161 {
       
   162     ExceptionCode ec;
       
   163     removeChild(tFoot(), ec);
       
   164 }
       
   165 
       
   166 PassRefPtr<HTMLElement> HTMLTableElement::createCaption()
       
   167 {
       
   168     if (HTMLTableCaptionElement* existingCaption = caption())
       
   169         return existingCaption;
       
   170     RefPtr<HTMLTableCaptionElement> caption = HTMLTableCaptionElement::create(captionTag, document());
       
   171     ExceptionCode ec;
       
   172     setCaption(caption, ec);
       
   173     return caption.release();
       
   174 }
       
   175 
       
   176 void HTMLTableElement::deleteCaption()
       
   177 {
       
   178     ExceptionCode ec;
       
   179     removeChild(caption(), ec);
       
   180 }
       
   181 
       
   182 HTMLTableSectionElement* HTMLTableElement::lastBody() const
       
   183 {
       
   184     for (Node* child = lastChild(); child; child = child->previousSibling()) {
       
   185         if (child->hasTagName(tbodyTag))
       
   186             return static_cast<HTMLTableSectionElement*>(child);
       
   187     }
       
   188     return 0;
       
   189 }
       
   190 
       
   191 PassRefPtr<HTMLElement> HTMLTableElement::insertRow(int index, ExceptionCode& ec)
       
   192 {
       
   193     if (index < -1) {
       
   194         ec = INDEX_SIZE_ERR;
       
   195         return 0;
       
   196     }
       
   197 
       
   198     HTMLTableRowElement* lastRow = 0;
       
   199     HTMLTableRowElement* row = 0;
       
   200     if (index == -1)
       
   201         lastRow = HTMLTableRowsCollection::lastRow(this);
       
   202     else {
       
   203         for (int i = 0; i <= index; ++i) {
       
   204             row = HTMLTableRowsCollection::rowAfter(this, lastRow);
       
   205             if (!row) {
       
   206                 if (i != index) {
       
   207                     ec = INDEX_SIZE_ERR;
       
   208                     return 0;
       
   209                 }
       
   210                 break;
       
   211             }
       
   212             lastRow = row;
       
   213         }
       
   214     }
       
   215 
       
   216     Node* parent;
       
   217     if (lastRow)
       
   218         parent = row ? row->parent() : lastRow->parent();
       
   219     else {
       
   220         parent = lastBody();
       
   221         if (!parent) {
       
   222             RefPtr<HTMLTableSectionElement> newBody = HTMLTableSectionElement::create(tbodyTag, document());
       
   223             RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
       
   224             newBody->appendChild(newRow, ec);
       
   225             appendChild(newBody.release(), ec);
       
   226             return newRow.release();
       
   227         }
       
   228     }
       
   229 
       
   230     RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
       
   231     parent->insertBefore(newRow, row, ec);
       
   232     return newRow.release();
       
   233 }
       
   234 
       
   235 void HTMLTableElement::deleteRow(int index, ExceptionCode& ec)
       
   236 {
       
   237     HTMLTableRowElement* row = 0;
       
   238     if (index == -1)
       
   239         row = HTMLTableRowsCollection::lastRow(this);
       
   240     else {
       
   241         for (int i = 0; i <= index; ++i) {
       
   242             row = HTMLTableRowsCollection::rowAfter(this, row);
       
   243             if (!row)
       
   244                 break;
       
   245         }
       
   246     }
       
   247     if (!row) {
       
   248         ec = INDEX_SIZE_ERR;
       
   249         return;
       
   250     }
       
   251     row->remove(ec);
       
   252 }
       
   253 
       
   254 ContainerNode* HTMLTableElement::legacyParserAddChild(PassRefPtr<Node> child)
       
   255 {
       
   256     if (child->hasTagName(formTag)) {
       
   257         // First add the child.
       
   258         HTMLElement::legacyParserAddChild(child);
       
   259 
       
   260         // Now simply return ourselves as the container to insert into.
       
   261         // This has the effect of demoting the form to a leaf and moving it safely out of the way.
       
   262         return this;
       
   263     }
       
   264 
       
   265     return HTMLElement::legacyParserAddChild(child.get());
       
   266 }
       
   267 
       
   268 bool HTMLTableElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
       
   269 {
       
   270     if (attrName == backgroundAttr) {
       
   271         result = (MappedAttributeEntry)(eLastEntry + document()->docID());
       
   272         return false;
       
   273     }
       
   274     
       
   275     if (attrName == widthAttr ||
       
   276         attrName == heightAttr ||
       
   277         attrName == bgcolorAttr ||
       
   278         attrName == cellspacingAttr ||
       
   279         attrName == vspaceAttr ||
       
   280         attrName == hspaceAttr ||
       
   281         attrName == valignAttr) {
       
   282         result = eUniversal;
       
   283         return false;
       
   284     }
       
   285     
       
   286     if (attrName == bordercolorAttr || attrName == frameAttr || attrName == rulesAttr) {
       
   287         result = eUniversal;
       
   288         return true;
       
   289     }
       
   290     
       
   291     if (attrName == borderAttr) {
       
   292         result = eTable;
       
   293         return true;
       
   294     }
       
   295     
       
   296     if (attrName == alignAttr) {
       
   297         result = eTable;
       
   298         return false;
       
   299     }
       
   300 
       
   301     return HTMLElement::mapToEntry(attrName, result);
       
   302 }
       
   303 
       
   304 static inline bool isTableCellAncestor(Node* n)
       
   305 {
       
   306     return n->hasTagName(theadTag) || n->hasTagName(tbodyTag) ||
       
   307            n->hasTagName(tfootTag) || n->hasTagName(trTag) ||
       
   308            n->hasTagName(thTag);
       
   309 }
       
   310 
       
   311 static bool setTableCellsChanged(Node* n)
       
   312 {
       
   313     ASSERT(n);
       
   314     bool cellChanged = false;
       
   315 
       
   316     if (n->hasTagName(tdTag))
       
   317         cellChanged = true;
       
   318     else if (isTableCellAncestor(n)) {
       
   319         for (Node* child = n->firstChild(); child; child = child->nextSibling())
       
   320             cellChanged |= setTableCellsChanged(child);
       
   321     }
       
   322 
       
   323     if (cellChanged)
       
   324        n->setNeedsStyleRecalc();
       
   325 
       
   326     return cellChanged;
       
   327 }
       
   328 
       
   329 void HTMLTableElement::parseMappedAttribute(Attribute* attr)
       
   330 {
       
   331     CellBorders bordersBefore = cellBorders();
       
   332     unsigned short oldPadding = m_padding;
       
   333 
       
   334     if (attr->name() == widthAttr)
       
   335         addCSSLength(attr, CSSPropertyWidth, attr->value());
       
   336     else if (attr->name() == heightAttr)
       
   337         addCSSLength(attr, CSSPropertyHeight, attr->value());
       
   338     else if (attr->name() == borderAttr)  {
       
   339         m_borderAttr = true;
       
   340         if (attr->decl()) {
       
   341             RefPtr<CSSValue> val = attr->decl()->getPropertyCSSValue(CSSPropertyBorderLeftWidth);
       
   342             if (val && val->isPrimitiveValue()) {
       
   343                 CSSPrimitiveValue* primVal = static_cast<CSSPrimitiveValue*>(val.get());
       
   344                 m_borderAttr = primVal->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER);
       
   345             }
       
   346         } else if (!attr->isNull()) {
       
   347             int border = 0;
       
   348             if (attr->isEmpty())
       
   349                 border = 1;
       
   350             else
       
   351                 border = attr->value().toInt();
       
   352             m_borderAttr = border;
       
   353             addCSSLength(attr, CSSPropertyBorderWidth, String::number(border));
       
   354         }
       
   355     } else if (attr->name() == bgcolorAttr)
       
   356         addCSSColor(attr, CSSPropertyBackgroundColor, attr->value());
       
   357     else if (attr->name() == bordercolorAttr) {
       
   358         m_borderColorAttr = attr->decl();
       
   359         if (!attr->decl() && !attr->isEmpty()) {
       
   360             addCSSColor(attr, CSSPropertyBorderColor, attr->value());
       
   361             m_borderColorAttr = true;
       
   362         }
       
   363     } else if (attr->name() == backgroundAttr) {
       
   364         String url = deprecatedParseURL(attr->value());
       
   365         if (!url.isEmpty())
       
   366             addCSSImageProperty(attr, CSSPropertyBackgroundImage, document()->completeURL(url).string());
       
   367     } else if (attr->name() == frameAttr) {
       
   368         // Cache the value of "frame" so that the table can examine it later.
       
   369         m_frameAttr = false;
       
   370         
       
   371         // Whether or not to hide the top/right/bottom/left borders.
       
   372         const int cTop = 0;
       
   373         const int cRight = 1;
       
   374         const int cBottom = 2;
       
   375         const int cLeft = 3;
       
   376         bool borders[4] = { false, false, false, false };
       
   377         
       
   378         // void, above, below, hsides, vsides, lhs, rhs, box, border
       
   379         if (equalIgnoringCase(attr->value(), "void"))
       
   380             m_frameAttr = true;
       
   381         else if (equalIgnoringCase(attr->value(), "above")) {
       
   382             m_frameAttr = true;
       
   383             borders[cTop] = true;
       
   384         } else if (equalIgnoringCase(attr->value(), "below")) {
       
   385             m_frameAttr = true;
       
   386             borders[cBottom] = true;
       
   387         } else if (equalIgnoringCase(attr->value(), "hsides")) {
       
   388             m_frameAttr = true;
       
   389             borders[cTop] = borders[cBottom] = true;
       
   390         } else if (equalIgnoringCase(attr->value(), "vsides")) {
       
   391             m_frameAttr = true;
       
   392             borders[cLeft] = borders[cRight] = true;
       
   393         } else if (equalIgnoringCase(attr->value(), "lhs")) {
       
   394             m_frameAttr = true;
       
   395             borders[cLeft] = true;
       
   396         } else if (equalIgnoringCase(attr->value(), "rhs")) {
       
   397             m_frameAttr = true;
       
   398             borders[cRight] = true;
       
   399         } else if (equalIgnoringCase(attr->value(), "box") ||
       
   400                    equalIgnoringCase(attr->value(), "border")) {
       
   401             m_frameAttr = true;
       
   402             borders[cTop] = borders[cBottom] = borders[cLeft] = borders[cRight] = true;
       
   403         }
       
   404         
       
   405         // Now map in the border styles of solid and hidden respectively.
       
   406         if (m_frameAttr) {
       
   407             addCSSProperty(attr, CSSPropertyBorderTopWidth, CSSValueThin);
       
   408             addCSSProperty(attr, CSSPropertyBorderBottomWidth, CSSValueThin);
       
   409             addCSSProperty(attr, CSSPropertyBorderLeftWidth, CSSValueThin);
       
   410             addCSSProperty(attr, CSSPropertyBorderRightWidth, CSSValueThin);
       
   411             addCSSProperty(attr, CSSPropertyBorderTopStyle, borders[cTop] ? CSSValueSolid : CSSValueHidden);
       
   412             addCSSProperty(attr, CSSPropertyBorderBottomStyle, borders[cBottom] ? CSSValueSolid : CSSValueHidden);
       
   413             addCSSProperty(attr, CSSPropertyBorderLeftStyle, borders[cLeft] ? CSSValueSolid : CSSValueHidden);
       
   414             addCSSProperty(attr, CSSPropertyBorderRightStyle, borders[cRight] ? CSSValueSolid : CSSValueHidden);
       
   415         }
       
   416     } else if (attr->name() == rulesAttr) {
       
   417         m_rulesAttr = UnsetRules;
       
   418         if (equalIgnoringCase(attr->value(), "none"))
       
   419             m_rulesAttr = NoneRules;
       
   420         else if (equalIgnoringCase(attr->value(), "groups"))
       
   421             m_rulesAttr = GroupsRules;
       
   422         else if (equalIgnoringCase(attr->value(), "rows"))
       
   423             m_rulesAttr = RowsRules;
       
   424         if (equalIgnoringCase(attr->value(), "cols"))
       
   425             m_rulesAttr = ColsRules;
       
   426         if (equalIgnoringCase(attr->value(), "all"))
       
   427             m_rulesAttr = AllRules;
       
   428         
       
   429         // The presence of a valid rules attribute causes border collapsing to be enabled.
       
   430         if (m_rulesAttr != UnsetRules)
       
   431             addCSSProperty(attr, CSSPropertyBorderCollapse, CSSValueCollapse);
       
   432     } else if (attr->name() == cellspacingAttr) {
       
   433         if (!attr->value().isEmpty())
       
   434             addCSSLength(attr, CSSPropertyBorderSpacing, attr->value());
       
   435     } else if (attr->name() == cellpaddingAttr) {
       
   436         if (!attr->value().isEmpty())
       
   437             m_padding = max(0, attr->value().toInt());
       
   438         else
       
   439             m_padding = 1;
       
   440     } else if (attr->name() == colsAttr) {
       
   441         // ###
       
   442     } else if (attr->name() == vspaceAttr) {
       
   443         addCSSLength(attr, CSSPropertyMarginTop, attr->value());
       
   444         addCSSLength(attr, CSSPropertyMarginBottom, attr->value());
       
   445     } else if (attr->name() == hspaceAttr) {
       
   446         addCSSLength(attr, CSSPropertyMarginLeft, attr->value());
       
   447         addCSSLength(attr, CSSPropertyMarginRight, attr->value());
       
   448     } else if (attr->name() == alignAttr) {
       
   449         if (!attr->value().isEmpty()) {
       
   450             if (equalIgnoringCase(attr->value(), "center")) {
       
   451                 addCSSProperty(attr, CSSPropertyMarginLeft, CSSValueAuto);
       
   452                 addCSSProperty(attr, CSSPropertyMarginRight, CSSValueAuto);
       
   453             } else
       
   454                 addCSSProperty(attr, CSSPropertyFloat, attr->value());
       
   455         }
       
   456     } else if (attr->name() == valignAttr) {
       
   457         if (!attr->value().isEmpty())
       
   458             addCSSProperty(attr, CSSPropertyVerticalAlign, attr->value());
       
   459     } else
       
   460         HTMLElement::parseMappedAttribute(attr);
       
   461 
       
   462     if (bordersBefore != cellBorders() || oldPadding != m_padding) {
       
   463         if (oldPadding != m_padding)
       
   464             m_paddingDecl = 0;
       
   465         bool cellChanged = false;
       
   466         for (Node* child = firstChild(); child; child = child->nextSibling())
       
   467             cellChanged |= setTableCellsChanged(child);
       
   468         if (cellChanged)
       
   469             setNeedsStyleRecalc();
       
   470     }
       
   471 }
       
   472 
       
   473 void HTMLTableElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
       
   474 {
       
   475     if ((!m_borderAttr && !m_borderColorAttr) || m_frameAttr)
       
   476         return;
       
   477 
       
   478     AtomicString borderValue = m_borderColorAttr ? "solid" : "outset";
       
   479     CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, tableborderAttr, borderValue);
       
   480     if (!decl) {
       
   481         decl = CSSMappedAttributeDeclaration::create().releaseRef(); // This single ref pins us in the table until the document dies.
       
   482         decl->setParent(document()->elementSheet());
       
   483         decl->setNode(this);
       
   484         decl->setStrictParsing(false); // Mapped attributes are just always quirky.
       
   485         
       
   486         int v = m_borderColorAttr ? CSSValueSolid : CSSValueOutset;
       
   487         decl->setProperty(CSSPropertyBorderTopStyle, v, false);
       
   488         decl->setProperty(CSSPropertyBorderBottomStyle, v, false);
       
   489         decl->setProperty(CSSPropertyBorderLeftStyle, v, false);
       
   490         decl->setProperty(CSSPropertyBorderRightStyle, v, false);
       
   491 
       
   492         setMappedAttributeDecl(ePersistent, tableborderAttr, borderValue, decl);
       
   493         decl->setParent(0);
       
   494         decl->setNode(0);
       
   495         decl->setMappedState(ePersistent, tableborderAttr, borderValue);
       
   496     }
       
   497     
       
   498     
       
   499     results.append(decl);
       
   500 }
       
   501 
       
   502 HTMLTableElement::CellBorders HTMLTableElement::cellBorders() const
       
   503 {
       
   504     switch (m_rulesAttr) {
       
   505         case NoneRules:
       
   506         case GroupsRules:
       
   507             return NoBorders;
       
   508         case AllRules:
       
   509             return SolidBorders;
       
   510         case ColsRules:
       
   511             return SolidBordersColsOnly;
       
   512         case RowsRules:
       
   513             return SolidBordersRowsOnly;
       
   514         case UnsetRules:
       
   515             if (!m_borderAttr)
       
   516                 return NoBorders;
       
   517             if (m_borderColorAttr)
       
   518                 return SolidBorders;
       
   519             return InsetBorders;
       
   520     }
       
   521     ASSERT_NOT_REACHED();
       
   522     return NoBorders;
       
   523 }
       
   524 
       
   525 void HTMLTableElement::addSharedCellDecls(Vector<CSSMutableStyleDeclaration*>& results)
       
   526 {
       
   527     addSharedCellBordersDecl(results);
       
   528     addSharedCellPaddingDecl(results);
       
   529 }
       
   530 
       
   531 void HTMLTableElement::addSharedCellBordersDecl(Vector<CSSMutableStyleDeclaration*>& results)
       
   532 {
       
   533     CellBorders borders = cellBorders();
       
   534 
       
   535     static const AtomicString* cellBorderNames[] = { new AtomicString("none"), new AtomicString("solid"), new AtomicString("inset"), new AtomicString("solid-cols"), new AtomicString("solid-rows") };
       
   536     const AtomicString& cellborderValue = *cellBorderNames[borders];
       
   537     CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, cellborderAttr, cellborderValue);
       
   538     if (!decl) {
       
   539         decl = CSSMappedAttributeDeclaration::create().releaseRef(); // This single ref pins us in the table until the document dies.
       
   540         decl->setParent(document()->elementSheet());
       
   541         decl->setNode(this);
       
   542         decl->setStrictParsing(false); // Mapped attributes are just always quirky.
       
   543         
       
   544         switch (borders) {
       
   545             case SolidBordersColsOnly:
       
   546                 decl->setProperty(CSSPropertyBorderLeftWidth, CSSValueThin, false);
       
   547                 decl->setProperty(CSSPropertyBorderRightWidth, CSSValueThin, false);
       
   548                 decl->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid, false);
       
   549                 decl->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid, false);
       
   550                 decl->setProperty(CSSPropertyBorderColor, "inherit", false);
       
   551                 break;
       
   552             case SolidBordersRowsOnly:
       
   553                 decl->setProperty(CSSPropertyBorderTopWidth, CSSValueThin, false);
       
   554                 decl->setProperty(CSSPropertyBorderBottomWidth, CSSValueThin, false);
       
   555                 decl->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid, false);
       
   556                 decl->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid, false);
       
   557                 decl->setProperty(CSSPropertyBorderColor, "inherit", false);
       
   558                 break;
       
   559             case SolidBorders:
       
   560                 decl->setProperty(CSSPropertyBorderWidth, "1px", false);
       
   561                 decl->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid, false);
       
   562                 decl->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid, false);
       
   563                 decl->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid, false);
       
   564                 decl->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid, false);
       
   565                 decl->setProperty(CSSPropertyBorderColor, "inherit", false);
       
   566                 break;
       
   567             case InsetBorders:
       
   568                 decl->setProperty(CSSPropertyBorderWidth, "1px", false);
       
   569                 decl->setProperty(CSSPropertyBorderTopStyle, CSSValueInset, false);
       
   570                 decl->setProperty(CSSPropertyBorderBottomStyle, CSSValueInset, false);
       
   571                 decl->setProperty(CSSPropertyBorderLeftStyle, CSSValueInset, false);
       
   572                 decl->setProperty(CSSPropertyBorderRightStyle, CSSValueInset, false);
       
   573                 decl->setProperty(CSSPropertyBorderColor, "inherit", false);
       
   574                 break;
       
   575             case NoBorders:
       
   576                 decl->setProperty(CSSPropertyBorderWidth, "0", false);
       
   577                 break;
       
   578         }
       
   579 
       
   580         setMappedAttributeDecl(ePersistent, cellborderAttr, *cellBorderNames[borders], decl);
       
   581         decl->setParent(0);
       
   582         decl->setNode(0);
       
   583         decl->setMappedState(ePersistent, cellborderAttr, cellborderValue);
       
   584     }
       
   585     
       
   586     results.append(decl);
       
   587 }
       
   588 
       
   589 void HTMLTableElement::addSharedCellPaddingDecl(Vector<CSSMutableStyleDeclaration*>& results)
       
   590 {
       
   591     if (m_padding == 0)
       
   592         return;
       
   593 
       
   594     if (!m_paddingDecl) {
       
   595         String paddingValue = String::number(m_padding);
       
   596         m_paddingDecl = getMappedAttributeDecl(eUniversal, cellpaddingAttr, paddingValue);
       
   597         if (!m_paddingDecl) {
       
   598             m_paddingDecl = CSSMappedAttributeDeclaration::create();
       
   599             m_paddingDecl->setParent(document()->elementSheet());
       
   600             m_paddingDecl->setNode(this);
       
   601             m_paddingDecl->setStrictParsing(false); // Mapped attributes are just always quirky.
       
   602             
       
   603             m_paddingDecl->setProperty(CSSPropertyPaddingTop, paddingValue, false);
       
   604             m_paddingDecl->setProperty(CSSPropertyPaddingRight, paddingValue, false);
       
   605             m_paddingDecl->setProperty(CSSPropertyPaddingBottom, paddingValue, false);
       
   606             m_paddingDecl->setProperty(CSSPropertyPaddingLeft, paddingValue, false);
       
   607         }
       
   608         setMappedAttributeDecl(eUniversal, cellpaddingAttr, paddingValue, m_paddingDecl.get());
       
   609         m_paddingDecl->setParent(0);
       
   610         m_paddingDecl->setNode(0);
       
   611         m_paddingDecl->setMappedState(eUniversal, cellpaddingAttr, paddingValue);
       
   612     }
       
   613     
       
   614     results.append(m_paddingDecl.get());
       
   615 }
       
   616 
       
   617 void HTMLTableElement::addSharedGroupDecls(bool rows, Vector<CSSMutableStyleDeclaration*>& results)
       
   618 {
       
   619     if (m_rulesAttr != GroupsRules)
       
   620         return;
       
   621 
       
   622     AtomicString rulesValue = rows ? "rowgroups" : "colgroups";
       
   623     CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, rulesAttr, rulesValue);
       
   624     if (!decl) {
       
   625         decl = CSSMappedAttributeDeclaration::create().releaseRef(); // This single ref pins us in the table until the document dies.
       
   626         decl->setParent(document()->elementSheet());
       
   627         decl->setNode(this);
       
   628         decl->setStrictParsing(false); // Mapped attributes are just always quirky.
       
   629         
       
   630         if (rows) {
       
   631             decl->setProperty(CSSPropertyBorderTopWidth, CSSValueThin, false);
       
   632             decl->setProperty(CSSPropertyBorderBottomWidth, CSSValueThin, false);
       
   633             decl->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid, false);
       
   634             decl->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid, false);
       
   635         } else {
       
   636             decl->setProperty(CSSPropertyBorderLeftWidth, CSSValueThin, false);
       
   637             decl->setProperty(CSSPropertyBorderRightWidth, CSSValueThin, false);
       
   638             decl->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid, false);
       
   639             decl->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid, false);
       
   640         }
       
   641 
       
   642         setMappedAttributeDecl(ePersistent, rulesAttr, rulesValue, decl);
       
   643         decl->setParent(0);
       
   644         decl->setNode(0);
       
   645         decl->setMappedState(ePersistent, rulesAttr, rulesValue);
       
   646     }
       
   647 
       
   648     results.append(decl);
       
   649 }
       
   650 
       
   651 void HTMLTableElement::attach()
       
   652 {
       
   653     ASSERT(!attached());
       
   654     HTMLElement::attach();
       
   655 }
       
   656 
       
   657 bool HTMLTableElement::isURLAttribute(Attribute *attr) const
       
   658 {
       
   659     return attr->name() == backgroundAttr;
       
   660 }
       
   661 
       
   662 PassRefPtr<HTMLCollection> HTMLTableElement::rows()
       
   663 {
       
   664     return HTMLTableRowsCollection::create(this);
       
   665 }
       
   666 
       
   667 PassRefPtr<HTMLCollection> HTMLTableElement::tBodies()
       
   668 {
       
   669     return HTMLCollection::create(this, TableTBodies);
       
   670 }
       
   671 
       
   672 String HTMLTableElement::rules() const
       
   673 {
       
   674     return getAttribute(rulesAttr);
       
   675 }
       
   676 
       
   677 String HTMLTableElement::summary() const
       
   678 {
       
   679     return getAttribute(summaryAttr);
       
   680 }
       
   681 
       
   682 void HTMLTableElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
       
   683 {
       
   684     HTMLElement::addSubresourceAttributeURLs(urls);
       
   685 
       
   686     addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr)));
       
   687 }
       
   688 
       
   689 }