Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / svg / SVGStyleElement.cpp
blobb942eda10c84ada8af90448317045c1dd2237507
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>
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.
23 #include "config.h"
24 #include "core/svg/SVGStyleElement.h"
26 #include "core/MediaTypeNames.h"
27 #include "core/css/CSSStyleSheet.h"
28 #include "core/events/Event.h"
29 #include "wtf/StdLibExtras.h"
31 namespace blink {
33 static SVGStyleEventSender& styleErrorEventSender()
35 DEFINE_STATIC_LOCAL(SVGStyleEventSender, sharedErrorEventSender, (EventTypeNames::error));
36 return sharedErrorEventSender;
39 inline SVGStyleElement::SVGStyleElement(Document& document, bool createdByParser)
40 : SVGElement(SVGNames::styleTag, document)
41 , StyleElement(&document, createdByParser)
45 SVGStyleElement::~SVGStyleElement()
47 #if !ENABLE(OILPAN)
48 StyleElement::clearDocumentData(document(), this);
49 #endif
51 styleErrorEventSender().cancelEvent(this);
54 PassRefPtrWillBeRawPtr<SVGStyleElement> SVGStyleElement::create(Document& document, bool createdByParser)
56 return adoptRefWillBeNoop(new SVGStyleElement(document, createdByParser));
59 bool SVGStyleElement::disabled() const
61 if (!m_sheet)
62 return false;
64 return m_sheet->disabled();
67 void SVGStyleElement::setDisabled(bool setDisabled)
69 if (CSSStyleSheet* styleSheet = sheet())
70 styleSheet->setDisabled(setDisabled);
73 const AtomicString& SVGStyleElement::type() const
75 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css", AtomicString::ConstructFromLiteral));
76 const AtomicString& n = getAttribute(SVGNames::typeAttr);
77 return n.isNull() ? defaultValue : n;
80 void SVGStyleElement::setType(const AtomicString& type)
82 setAttribute(SVGNames::typeAttr, type);
85 const AtomicString& SVGStyleElement::media() const
87 const AtomicString& n = fastGetAttribute(SVGNames::mediaAttr);
88 return n.isNull() ? MediaTypeNames::all : n;
91 void SVGStyleElement::setMedia(const AtomicString& media)
93 setAttribute(SVGNames::mediaAttr, media);
96 String SVGStyleElement::title() const
98 return fastGetAttribute(SVGNames::titleAttr);
101 void SVGStyleElement::setTitle(const AtomicString& title)
103 setAttribute(SVGNames::titleAttr, title);
106 void SVGStyleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
108 if (name == SVGNames::titleAttr) {
109 if (m_sheet)
110 m_sheet->setTitle(value);
112 return;
115 SVGElement::parseAttribute(name, value);
118 void SVGStyleElement::finishParsingChildren()
120 StyleElement::ProcessingResult result = StyleElement::finishParsingChildren(this);
121 SVGElement::finishParsingChildren();
122 if (result == StyleElement::ProcessingFatalError)
123 notifyLoadedSheetAndAllCriticalSubresources(ErrorOccurredLoadingSubresource);
126 Node::InsertionNotificationRequest SVGStyleElement::insertedInto(ContainerNode* insertionPoint)
128 SVGElement::insertedInto(insertionPoint);
129 StyleElement::insertedInto(this, insertionPoint);
130 return InsertionShouldCallDidNotifySubtreeInsertions;
133 void SVGStyleElement::didNotifySubtreeInsertionsToDocument()
135 if (StyleElement::processStyleSheet(document(), this) == StyleElement::ProcessingFatalError)
136 notifyLoadedSheetAndAllCriticalSubresources(ErrorOccurredLoadingSubresource);
139 void SVGStyleElement::removedFrom(ContainerNode* insertionPoint)
141 SVGElement::removedFrom(insertionPoint);
142 StyleElement::removedFrom(this, insertionPoint);
145 void SVGStyleElement::childrenChanged(const ChildrenChange& change)
147 SVGElement::childrenChanged(change);
148 if (StyleElement::childrenChanged(this) == StyleElement::ProcessingFatalError)
149 notifyLoadedSheetAndAllCriticalSubresources(ErrorOccurredLoadingSubresource);
152 void SVGStyleElement::notifyLoadedSheetAndAllCriticalSubresources(LoadedSheetErrorStatus errorStatus)
154 if (errorStatus != NoErrorLoadingSubresource)
155 styleErrorEventSender().dispatchEventSoon(this);
158 void SVGStyleElement::dispatchPendingEvent(SVGStyleEventSender* eventSender)
160 ASSERT_UNUSED(eventSender, eventSender == &styleErrorEventSender());
161 dispatchEvent(Event::create(EventTypeNames::error));
164 DEFINE_TRACE(SVGStyleElement)
166 StyleElement::trace(visitor);
167 SVGElement::trace(visitor);