Home | History | Annotate | Download | only in rendering
      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, 2009 Apple Inc. All rights reserved.
      8  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
      9  *
     10  * This library is free software; you can redistribute it and/or
     11  * modify it under the terms of the GNU Library General Public
     12  * License as published by the Free Software Foundation; either
     13  * version 2 of the License, or (at your option) any later version.
     14  *
     15  * This library is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18  * Library General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU Library General Public License
     21  * along with this library; see the file COPYING.LIB.  If not, write to
     22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     23  * Boston, MA 02110-1301, USA.
     24  */
     25 
     26 #include "config.h"
     27 #include "RenderTableCol.h"
     28 
     29 #include "CachedImage.h"
     30 #include "HTMLNames.h"
     31 #include "HTMLTableColElement.h"
     32 #include "RenderTable.h"
     33 
     34 namespace WebCore {
     35 
     36 using namespace HTMLNames;
     37 
     38 RenderTableCol::RenderTableCol(Node* node)
     39     : RenderBox(node)
     40     , m_span(1)
     41 {
     42     // init RenderObject attributes
     43     setInline(true); // our object is not Inline
     44     updateFromElement();
     45 }
     46 
     47 void RenderTableCol::updateFromElement()
     48 {
     49     int oldSpan = m_span;
     50     Node* n = node();
     51     if (n && (n->hasTagName(colTag) || n->hasTagName(colgroupTag))) {
     52         HTMLTableColElement* tc = static_cast<HTMLTableColElement*>(n);
     53         m_span = tc->span();
     54     } else
     55         m_span = !(style() && style()->display() == TABLE_COLUMN_GROUP);
     56     if (m_span != oldSpan && style() && parent())
     57         setNeedsLayoutAndPrefWidthsRecalc();
     58 }
     59 
     60 bool RenderTableCol::isChildAllowed(RenderObject* child, RenderStyle* style) const
     61 {
     62     return !child->isText() && style && (style->display() == TABLE_COLUMN);
     63 }
     64 
     65 bool RenderTableCol::canHaveChildren() const
     66 {
     67     // Cols cannot have children. This is actually necessary to fix a bug
     68     // with libraries.uc.edu, which makes a <p> be a table-column.
     69     return style()->display() == TABLE_COLUMN_GROUP;
     70 }
     71 
     72 IntRect RenderTableCol::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer)
     73 {
     74     // For now, just repaint the whole table.
     75     // FIXME: Find a better way to do this, e.g., need to repaint all the cells that we
     76     // might have propagated a background color or borders into.
     77     // FIXME: check for repaintContainer each time here?
     78 
     79     RenderTable* parentTable = table();
     80     if (!parentTable)
     81         return IntRect();
     82     return parentTable->clippedOverflowRectForRepaint(repaintContainer);
     83 }
     84 
     85 void RenderTableCol::imageChanged(WrappedImagePtr, const IntRect*)
     86 {
     87     // FIXME: Repaint only the rect the image paints in.
     88     repaint();
     89 }
     90 
     91 void RenderTableCol::computePreferredLogicalWidths()
     92 {
     93     setPreferredLogicalWidthsDirty(false);
     94 
     95     for (RenderObject* child = firstChild(); child; child = child->nextSibling())
     96         child->setPreferredLogicalWidthsDirty(false);
     97 }
     98 
     99 RenderTable* RenderTableCol::table() const
    100 {
    101     RenderObject* table = parent();
    102     if (table && !table->isTable())
    103         table = table->parent();
    104     return table && table->isTable() ? toRenderTable(table) : 0;
    105 }
    106 
    107 }
    108