initial import
[vuplus_webkit] / Source / WebCore / svg / SVGStyleElement.cpp
1 /*
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>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include "config.h"
24
25 #if ENABLE(SVG)
26 #include "SVGStyleElement.h"
27
28 #include "Attribute.h"
29 #include "CSSStyleSheet.h"
30 #include "Document.h"
31 #include "ExceptionCode.h"
32 #include "SVGNames.h"
33 #include <wtf/StdLibExtras.h>
34
35 namespace WebCore {
36
37 inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
38     : SVGElement(tagName, document)
39     , StyleElement(document, createdByParser)
40 {
41     ASSERT(hasTagName(SVGNames::styleTag));
42 }
43
44 SVGStyleElement::~SVGStyleElement()
45 {
46     StyleElement::clearDocumentData(document(), this);
47 }
48
49 PassRefPtr<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
50 {
51     return adoptRef(new SVGStyleElement(tagName, document, createdByParser));
52 }
53
54 const AtomicString& SVGStyleElement::type() const
55 {
56     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css"));
57     const AtomicString& n = fastGetAttribute(SVGNames::typeAttr);
58     return n.isNull() ? defaultValue : n;
59 }
60
61 void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec)
62 {
63     setAttribute(SVGNames::typeAttr, type, ec);
64 }
65
66 const AtomicString& SVGStyleElement::media() const
67 {
68     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all"));
69     const AtomicString& n = fastGetAttribute(SVGNames::mediaAttr);
70     return n.isNull() ? defaultValue : n;
71 }
72
73 void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec)
74 {
75     setAttribute(SVGNames::mediaAttr, media, ec);
76 }
77
78 String SVGStyleElement::title() const
79 {
80     return fastGetAttribute(SVGNames::titleAttr);
81 }
82
83 void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec)
84 {
85     setAttribute(SVGNames::titleAttr, title, ec);
86 }
87
88 bool SVGStyleElement::isSupportedAttribute(const QualifiedName& attrName)
89 {
90     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
91     if (supportedAttributes.isEmpty()) {
92         SVGLangSpace::addSupportedAttributes(supportedAttributes);
93         supportedAttributes.add(SVGNames::titleAttr);
94     }
95     return supportedAttributes.contains(attrName);
96 }
97
98 void SVGStyleElement::parseMappedAttribute(Attribute* attr)
99 {
100     if (!isSupportedAttribute(attr->name())) {
101         SVGElement::parseMappedAttribute(attr);
102         return;
103     }
104
105     if (attr->name() == SVGNames::titleAttr) {
106         if (m_sheet)
107             m_sheet->setTitle(attr->value());
108         return;
109     }
110
111     if (SVGLangSpace::parseMappedAttribute(attr))
112         return;
113
114     ASSERT_NOT_REACHED();
115 }
116
117 void SVGStyleElement::finishParsingChildren()
118 {
119     StyleElement::finishParsingChildren(this);
120     SVGElement::finishParsingChildren();
121 }
122
123 void SVGStyleElement::insertedIntoDocument()
124 {
125     SVGElement::insertedIntoDocument();
126     StyleElement::insertedIntoDocument(document(), this);
127 }
128
129 void SVGStyleElement::removedFromDocument()
130 {
131     SVGElement::removedFromDocument();
132     StyleElement::removedFromDocument(document(), this);
133 }
134
135 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
136 {
137     StyleElement::childrenChanged(this);
138     SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
139 }
140
141 }
142
143 #endif // ENABLE(SVG)