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 
SVGStyleElement(const QualifiedName & tagName,Document * document,bool createdByParser)37 inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
38     : SVGElement(tagName, document)
39     , StyleElement(document, createdByParser)
40 {
41 }
42 
~SVGStyleElement()43 SVGStyleElement::~SVGStyleElement()
44 {
45     StyleElement::clearDocumentData(document(), this);
46 }
47 
create(const QualifiedName & tagName,Document * document,bool createdByParser)48 PassRefPtr<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
49 {
50     return adoptRef(new SVGStyleElement(tagName, document, createdByParser));
51 }
52 
type() const53 const AtomicString& SVGStyleElement::type() const
54 {
55     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css"));
56     const AtomicString& n = getAttribute(SVGNames::typeAttr);
57     return n.isNull() ? defaultValue : n;
58 }
59 
setType(const AtomicString & type,ExceptionCode & ec)60 void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec)
61 {
62     setAttribute(SVGNames::typeAttr, type, ec);
63 }
64 
media() const65 const AtomicString& SVGStyleElement::media() const
66 {
67     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all"));
68     const AtomicString& n = getAttribute(SVGNames::mediaAttr);
69     return n.isNull() ? defaultValue : n;
70 }
71 
setMedia(const AtomicString & media,ExceptionCode & ec)72 void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec)
73 {
74     setAttribute(SVGNames::mediaAttr, media, ec);
75 }
76 
title() const77 String SVGStyleElement::title() const
78 {
79     return getAttribute(SVGNames::titleAttr);
80 }
81 
setTitle(const AtomicString & title,ExceptionCode & ec)82 void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec)
83 {
84     setAttribute(SVGNames::titleAttr, title, ec);
85 }
86 
parseMappedAttribute(Attribute * attr)87 void SVGStyleElement::parseMappedAttribute(Attribute* attr)
88 {
89     if (attr->name() == SVGNames::titleAttr && m_sheet)
90         m_sheet->setTitle(attr->value());
91     else {
92         if (SVGLangSpace::parseMappedAttribute(attr))
93             return;
94         SVGElement::parseMappedAttribute(attr);
95     }
96 }
97 
finishParsingChildren()98 void SVGStyleElement::finishParsingChildren()
99 {
100     StyleElement::finishParsingChildren(this);
101     SVGElement::finishParsingChildren();
102 }
103 
insertedIntoDocument()104 void SVGStyleElement::insertedIntoDocument()
105 {
106     SVGElement::insertedIntoDocument();
107     StyleElement::insertedIntoDocument(document(), this);
108 }
109 
removedFromDocument()110 void SVGStyleElement::removedFromDocument()
111 {
112     SVGElement::removedFromDocument();
113     StyleElement::removedFromDocument(document(), this);
114 }
115 
childrenChanged(bool changedByParser,Node * beforeChange,Node * afterChange,int childCountDelta)116 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
117 {
118     StyleElement::childrenChanged(this);
119     SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
120 }
121 
122 }
123 
124 #endif // ENABLE(SVG)
125