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 Apple Computer, Inc.
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.
26 #include "core/html/HTMLTablePartElement.h"
28 #include "core/CSSPropertyNames.h"
29 #include "core/CSSValueKeywords.h"
30 #include "core/HTMLNames.h"
31 #include "core/css/CSSImageValue.h"
32 #include "core/css/StylePropertySet.h"
33 #include "core/dom/Document.h"
34 #include "core/dom/NodeRenderingTraversal.h"
35 #include "core/html/HTMLTableElement.h"
36 #include "core/html/parser/HTMLParserIdioms.h"
37 #include "platform/weborigin/Referrer.h"
41 using namespace HTMLNames;
43 bool HTMLTablePartElement::isPresentationAttribute(const QualifiedName& name) const
45 if (name == bgcolorAttr || name == backgroundAttr || name == valignAttr || name == alignAttr || name == heightAttr)
47 return HTMLElement::isPresentationAttribute(name);
50 void HTMLTablePartElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
52 if (name == bgcolorAttr)
53 addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value);
54 else if (name == backgroundAttr) {
55 String url = stripLeadingAndTrailingHTMLSpaces(value);
57 RefPtrWillBeRawPtr<CSSImageValue> imageValue = CSSImageValue::create(url, document().completeURL(url));
58 imageValue->setReferrer(Referrer(document().outgoingReferrer(), document().referrerPolicy()));
59 style->setProperty(CSSProperty(CSSPropertyBackgroundImage, imageValue.release()));
61 } else if (name == valignAttr) {
62 if (equalIgnoringCase(value, "top"))
63 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueTop);
64 else if (equalIgnoringCase(value, "middle"))
65 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueMiddle);
66 else if (equalIgnoringCase(value, "bottom"))
67 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueBottom);
68 else if (equalIgnoringCase(value, "baseline"))
69 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueBaseline);
71 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value);
72 } else if (name == alignAttr) {
73 if (equalIgnoringCase(value, "middle") || equalIgnoringCase(value, "center"))
74 addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitCenter);
75 else if (equalIgnoringCase(value, "absmiddle"))
76 addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueCenter);
77 else if (equalIgnoringCase(value, "left"))
78 addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitLeft);
79 else if (equalIgnoringCase(value, "right"))
80 addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitRight);
82 addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, value);
83 } else if (name == heightAttr) {
85 addHTMLLengthToStyle(style, CSSPropertyHeight, value);
87 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
90 HTMLTableElement* HTMLTablePartElement::findParentTable() const
92 ContainerNode* parent = NodeRenderingTraversal::parent(this);
93 while (parent && !isHTMLTableElement(*parent))
94 parent = NodeRenderingTraversal::parent(parent);
95 return toHTMLTableElement(parent);