2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2006 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include "SVGStyleElement.h"
28 #include "Attribute.h"
29 #include "CSSStyleSheet.h"
31 #include "ExceptionCode.h"
33 #include <wtf/StdLibExtras.h>
37 inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
38 : SVGElement(tagName, document)
39 , StyleElement(document, createdByParser)
41 ASSERT(hasTagName(SVGNames::styleTag));
44 SVGStyleElement::~SVGStyleElement()
46 StyleElement::clearDocumentData(document(), this);
49 PassRefPtr<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
51 return adoptRef(new SVGStyleElement(tagName, document, createdByParser));
54 const AtomicString& SVGStyleElement::type() const
56 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css"));
57 const AtomicString& n = fastGetAttribute(SVGNames::typeAttr);
58 return n.isNull() ? defaultValue : n;
61 void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec)
63 setAttribute(SVGNames::typeAttr, type, ec);
66 const AtomicString& SVGStyleElement::media() const
68 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all"));
69 const AtomicString& n = fastGetAttribute(SVGNames::mediaAttr);
70 return n.isNull() ? defaultValue : n;
73 void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec)
75 setAttribute(SVGNames::mediaAttr, media, ec);
78 String SVGStyleElement::title() const
80 return fastGetAttribute(SVGNames::titleAttr);
83 void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec)
85 setAttribute(SVGNames::titleAttr, title, ec);
88 bool SVGStyleElement::isSupportedAttribute(const QualifiedName& attrName)
90 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
91 if (supportedAttributes.isEmpty()) {
92 SVGLangSpace::addSupportedAttributes(supportedAttributes);
93 supportedAttributes.add(SVGNames::titleAttr);
95 return supportedAttributes.contains(attrName);
98 void SVGStyleElement::parseMappedAttribute(Attribute* attr)
100 if (!isSupportedAttribute(attr->name())) {
101 SVGElement::parseMappedAttribute(attr);
105 if (attr->name() == SVGNames::titleAttr) {
107 m_sheet->setTitle(attr->value());
111 if (SVGLangSpace::parseMappedAttribute(attr))
114 ASSERT_NOT_REACHED();
117 void SVGStyleElement::finishParsingChildren()
119 StyleElement::finishParsingChildren(this);
120 SVGElement::finishParsingChildren();
123 void SVGStyleElement::insertedIntoDocument()
125 SVGElement::insertedIntoDocument();
126 StyleElement::insertedIntoDocument(document(), this);
129 void SVGStyleElement::removedFromDocument()
131 SVGElement::removedFromDocument();
132 StyleElement::removedFromDocument(document(), this);
135 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
137 StyleElement::childrenChanged(this);
138 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
143 #endif // ENABLE(SVG)