Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / HTMLTableColElement.cpp
blob807339796bf19dc623b1ee6ec888bea050b3aacc
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.
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.
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.
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.
25 #include "config.h"
26 #include "core/html/HTMLTableColElement.h"
28 #include "core/CSSPropertyNames.h"
29 #include "core/HTMLNames.h"
30 #include "core/html/HTMLTableElement.h"
31 #include "core/html/parser/HTMLParserIdioms.h"
32 #include "core/layout/LayoutTableCol.h"
34 namespace blink {
36 using namespace HTMLNames;
38 inline HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document& document)
39 : HTMLTablePartElement(tagName, document)
40 , m_span(1)
44 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLTableColElement)
46 bool HTMLTableColElement::isPresentationAttribute(const QualifiedName& name) const
48 if (name == widthAttr)
49 return true;
50 return HTMLTablePartElement::isPresentationAttribute(name);
53 void HTMLTableColElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
55 if (name == widthAttr)
56 addHTMLLengthToStyle(style, CSSPropertyWidth, value);
57 else
58 HTMLTablePartElement::collectStyleForPresentationAttribute(name, value, style);
61 void HTMLTableColElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
63 if (name == spanAttr) {
64 unsigned newSpan = 0;
65 if (value.isEmpty() || !parseHTMLNonNegativeInteger(value, newSpan) || newSpan < 1) {
66 // If the value of span is not a valid non-negative integer greater than zero,
67 // set it to 1.
68 newSpan = 1;
70 m_span = newSpan;
71 if (layoutObject() && layoutObject()->isLayoutTableCol())
72 layoutObject()->updateFromElement();
73 } else if (name == widthAttr) {
74 if (!value.isEmpty()) {
75 if (layoutObject() && layoutObject()->isLayoutTableCol()) {
76 LayoutTableCol* col = toLayoutTableCol(layoutObject());
77 int newWidth = width().toInt();
78 if (newWidth != col->size().width())
79 col->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::AttributeChanged);
82 } else {
83 HTMLTablePartElement::parseAttribute(name, value);
87 const StylePropertySet* HTMLTableColElement::additionalPresentationAttributeStyle()
89 if (!hasTagName(colgroupTag))
90 return nullptr;
91 if (HTMLTableElement* table = findParentTable())
92 return table->additionalGroupStyle(false);
93 return nullptr;
96 void HTMLTableColElement::setSpan(unsigned n)
98 setUnsignedIntegralAttribute(spanAttr, n);
101 const AtomicString& HTMLTableColElement::width() const
103 return getAttribute(widthAttr);