| 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 "CSSPropertyNames.h" |
| 29 | #include "HTMLNames.h" |
| 30 | #include "HTMLParserIdioms.h" |
| 31 | #include "HTMLTableElement.h" |
| 32 | #include "RenderTableCol.h" |
| 33 | #include "Text.h" |
| 34 | #include <wtf/IsoMallocInlines.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLTableColElement); |
| 39 | |
| 40 | const unsigned defaultSpan { 1 }; |
| 41 | const unsigned minSpan { 1 }; |
| 42 | const unsigned maxSpan { 1000 }; |
| 43 | |
| 44 | using namespace HTMLNames; |
| 45 | |
| 46 | inline HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document& document) |
| 47 | : HTMLTablePartElement(tagName, document) |
| 48 | , m_span(1) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | Ref<HTMLTableColElement> HTMLTableColElement::create(const QualifiedName& tagName, Document& document) |
| 53 | { |
| 54 | return adoptRef(*new HTMLTableColElement(tagName, document)); |
| 55 | } |
| 56 | |
| 57 | bool HTMLTableColElement::isPresentationAttribute(const QualifiedName& name) const |
| 58 | { |
| 59 | if (name == widthAttr) |
| 60 | return true; |
| 61 | return HTMLTablePartElement::isPresentationAttribute(name); |
| 62 | } |
| 63 | |
| 64 | void HTMLTableColElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) |
| 65 | { |
| 66 | if (name == widthAttr) |
| 67 | addHTMLLengthToStyle(style, CSSPropertyWidth, value); |
| 68 | else |
| 69 | HTMLTablePartElement::collectStyleForPresentationAttribute(name, value, style); |
| 70 | } |
| 71 | |
| 72 | void HTMLTableColElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 73 | { |
| 74 | if (name == spanAttr) { |
| 75 | m_span = clampHTMLNonNegativeIntegerToRange(value, minSpan, maxSpan, defaultSpan); |
| 76 | if (is<RenderTableCol>(renderer())) |
| 77 | downcast<RenderTableCol>(*renderer()).updateFromElement(); |
| 78 | } else if (name == widthAttr) { |
| 79 | if (!value.isEmpty()) { |
| 80 | if (is<RenderTableCol>(renderer())) { |
| 81 | RenderTableCol& col = downcast<RenderTableCol>(*renderer()); |
| 82 | int newWidth = width().toInt(); |
| 83 | if (newWidth != col.width()) |
| 84 | col.setNeedsLayoutAndPrefWidthsRecalc(); |
| 85 | } |
| 86 | } |
| 87 | } else |
| 88 | HTMLTablePartElement::parseAttribute(name, value); |
| 89 | } |
| 90 | |
| 91 | const StyleProperties* HTMLTableColElement::additionalPresentationAttributeStyle() const |
| 92 | { |
| 93 | if (!hasTagName(colgroupTag)) |
| 94 | return nullptr; |
| 95 | if (RefPtr<HTMLTableElement> table = findParentTable()) |
| 96 | return table->additionalGroupStyle(false); |
| 97 | return nullptr; |
| 98 | } |
| 99 | |
| 100 | void HTMLTableColElement::setSpan(unsigned span) |
| 101 | { |
| 102 | setUnsignedIntegralAttribute(spanAttr, limitToOnlyHTMLNonNegative(span, defaultSpan)); |
| 103 | } |
| 104 | |
| 105 | String HTMLTableColElement::width() const |
| 106 | { |
| 107 | return attributeWithoutSynchronization(widthAttr); |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | |