• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/svg/SVGStyleElement.h"
25 
26 #include "core/css/CSSStyleSheet.h"
27 #include "wtf/StdLibExtras.h"
28 
29 namespace WebCore {
30 
SVGStyleElement(Document & document,bool createdByParser)31 inline SVGStyleElement::SVGStyleElement(Document& document, bool createdByParser)
32     : SVGElement(SVGNames::styleTag, document)
33     , StyleElement(&document, createdByParser)
34     , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired)
35 {
36     ScriptWrappable::init(this);
37 }
38 
~SVGStyleElement()39 SVGStyleElement::~SVGStyleElement()
40 {
41     StyleElement::clearDocumentData(document(), this);
42 }
43 
create(Document & document,bool createdByParser)44 PassRefPtr<SVGStyleElement> SVGStyleElement::create(Document& document, bool createdByParser)
45 {
46     return adoptRef(new SVGStyleElement(document, createdByParser));
47 }
48 
disabled() const49 bool SVGStyleElement::disabled() const
50 {
51     if (!m_sheet)
52         return false;
53 
54     return m_sheet->disabled();
55 }
56 
setDisabled(bool setDisabled)57 void SVGStyleElement::setDisabled(bool setDisabled)
58 {
59     if (CSSStyleSheet* styleSheet = sheet())
60         styleSheet->setDisabled(setDisabled);
61 }
62 
type() const63 const AtomicString& SVGStyleElement::type() const
64 {
65     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css", AtomicString::ConstructFromLiteral));
66     const AtomicString& n = getAttribute(SVGNames::typeAttr);
67     return n.isNull() ? defaultValue : n;
68 }
69 
setType(const AtomicString & type)70 void SVGStyleElement::setType(const AtomicString& type)
71 {
72     setAttribute(SVGNames::typeAttr, type);
73 }
74 
media() const75 const AtomicString& SVGStyleElement::media() const
76 {
77     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all", AtomicString::ConstructFromLiteral));
78     const AtomicString& n = fastGetAttribute(SVGNames::mediaAttr);
79     return n.isNull() ? defaultValue : n;
80 }
81 
setMedia(const AtomicString & media)82 void SVGStyleElement::setMedia(const AtomicString& media)
83 {
84     setAttribute(SVGNames::mediaAttr, media);
85 }
86 
title() const87 String SVGStyleElement::title() const
88 {
89     return fastGetAttribute(SVGNames::titleAttr);
90 }
91 
setTitle(const AtomicString & title)92 void SVGStyleElement::setTitle(const AtomicString& title)
93 {
94     setAttribute(SVGNames::titleAttr, title);
95 }
96 
isSupportedAttribute(const QualifiedName & attrName)97 bool SVGStyleElement::isSupportedAttribute(const QualifiedName& attrName)
98 {
99     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
100     if (supportedAttributes.isEmpty())
101         supportedAttributes.add(SVGNames::titleAttr);
102     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
103 }
104 
parseAttribute(const QualifiedName & name,const AtomicString & value)105 void SVGStyleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
106 {
107     if (!isSupportedAttribute(name)) {
108         SVGElement::parseAttribute(name, value);
109         return;
110     }
111 
112     if (name == SVGNames::titleAttr) {
113         if (m_sheet)
114             m_sheet->setTitle(value);
115         return;
116     }
117 
118     ASSERT_NOT_REACHED();
119 }
120 
finishParsingChildren()121 void SVGStyleElement::finishParsingChildren()
122 {
123     StyleElement::finishParsingChildren(this);
124     SVGElement::finishParsingChildren();
125 }
126 
insertedInto(ContainerNode * rootParent)127 Node::InsertionNotificationRequest SVGStyleElement::insertedInto(ContainerNode* rootParent)
128 {
129     SVGElement::insertedInto(rootParent);
130     return InsertionShouldCallDidNotifySubtreeInsertions;
131 }
132 
didNotifySubtreeInsertionsToDocument()133 void SVGStyleElement::didNotifySubtreeInsertionsToDocument()
134 {
135     StyleElement::processStyleSheet(document(), this);
136 }
137 
removedFrom(ContainerNode * rootParent)138 void SVGStyleElement::removedFrom(ContainerNode* rootParent)
139 {
140     SVGElement::removedFrom(rootParent);
141     if (rootParent->inDocument())
142         StyleElement::removedFromDocument(document(), this);
143 }
144 
childrenChanged(bool changedByParser,Node * beforeChange,Node * afterChange,int childCountDelta)145 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
146 {
147     SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
148     StyleElement::childrenChanged(this);
149 }
150 
151 }
152