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, 2013 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.
24 #include "SVGStyleElement.h"
26 #include "CSSStyleSheet.h"
29 #include <wtf/IsoMallocInlines.h>
30 #include <wtf/StdLibExtras.h>
34 WTF_MAKE_ISO_ALLOCATED_IMPL(SVGStyleElement);
36 inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document& document, bool createdByParser)
37 : SVGElement(tagName, document)
38 , m_styleSheetOwner(document, createdByParser)
39 , m_loadEventTimer(*this, &SVGElement::loadEventTimerFired)
41 ASSERT(hasTagName(SVGNames::styleTag));
44 SVGStyleElement::~SVGStyleElement()
46 m_styleSheetOwner.clearDocumentData(*this);
49 Ref<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
51 return adoptRef(*new SVGStyleElement(tagName, document, createdByParser));
54 bool SVGStyleElement::disabled() const
56 return sheet() && sheet()->disabled();
59 void SVGStyleElement::setDisabled(bool setDisabled)
61 if (auto styleSheet = makeRefPtr(sheet()))
62 styleSheet->setDisabled(setDisabled);
65 const AtomString& SVGStyleElement::type() const
67 static NeverDestroyed<const AtomString> defaultValue("text/css", AtomString::ConstructFromLiteral);
68 const AtomString& n = getAttribute(SVGNames::typeAttr);
69 return n.isNull() ? defaultValue.get() : n;
72 void SVGStyleElement::setType(const AtomString& type)
74 setAttribute(SVGNames::typeAttr, type);
77 const AtomString& SVGStyleElement::media() const
79 static NeverDestroyed<const AtomString> defaultValue("all", AtomString::ConstructFromLiteral);
80 const AtomString& n = attributeWithoutSynchronization(SVGNames::mediaAttr);
81 return n.isNull() ? defaultValue.get() : n;
84 void SVGStyleElement::setMedia(const AtomString& media)
86 setAttributeWithoutSynchronization(SVGNames::mediaAttr, media);
89 String SVGStyleElement::title() const
91 return attributeWithoutSynchronization(SVGNames::titleAttr);
94 void SVGStyleElement::parseAttribute(const QualifiedName& name, const AtomString& value)
96 if (name == SVGNames::titleAttr) {
97 if (sheet() && !isInShadowTree())
98 sheet()->setTitle(value);
101 if (name == SVGNames::typeAttr) {
102 m_styleSheetOwner.setContentType(value);
105 if (name == SVGNames::mediaAttr) {
106 m_styleSheetOwner.setMedia(value);
110 SVGElement::parseAttribute(name, value);
113 void SVGStyleElement::finishParsingChildren()
115 m_styleSheetOwner.finishParsingChildren(*this);
116 SVGElement::finishParsingChildren();
119 Node::InsertedIntoAncestorResult SVGStyleElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
121 auto result = SVGElement::insertedIntoAncestor(insertionType, parentOfInsertedTree);
122 if (insertionType.connectedToDocument)
123 m_styleSheetOwner.insertedIntoDocument(*this);
127 void SVGStyleElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
129 SVGElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
130 if (removalType.disconnectedFromDocument)
131 m_styleSheetOwner.removedFromDocument(*this);
134 void SVGStyleElement::childrenChanged(const ChildChange& change)
136 SVGElement::childrenChanged(change);
137 m_styleSheetOwner.childrenChanged(*this);