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, 2013 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 "SVGStyleElement.h" |
25 | |
26 | #include "CSSStyleSheet.h" |
27 | #include "Document.h" |
28 | #include "SVGNames.h" |
29 | #include <wtf/IsoMallocInlines.h> |
30 | #include <wtf/StdLibExtras.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGStyleElement); |
35 | |
36 | inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document& document, bool createdByParser) |
37 | : SVGElement(tagName, document) |
38 | , m_styleSheetOwner(document, createdByParser) |
39 | , m_svgLoadEventTimer(*this, &SVGElement::svgLoadEventTimerFired) |
40 | { |
41 | ASSERT(hasTagName(SVGNames::styleTag)); |
42 | } |
43 | |
44 | SVGStyleElement::~SVGStyleElement() |
45 | { |
46 | m_styleSheetOwner.clearDocumentData(*this); |
47 | } |
48 | |
49 | Ref<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) |
50 | { |
51 | return adoptRef(*new SVGStyleElement(tagName, document, createdByParser)); |
52 | } |
53 | |
54 | bool SVGStyleElement::disabled() const |
55 | { |
56 | return sheet() && sheet()->disabled(); |
57 | } |
58 | |
59 | void SVGStyleElement::setDisabled(bool setDisabled) |
60 | { |
61 | if (auto styleSheet = makeRefPtr(sheet())) |
62 | styleSheet->setDisabled(setDisabled); |
63 | } |
64 | |
65 | const AtomicString& SVGStyleElement::type() const |
66 | { |
67 | static NeverDestroyed<const AtomicString> defaultValue("text/css" , AtomicString::ConstructFromLiteral); |
68 | const AtomicString& n = getAttribute(SVGNames::typeAttr); |
69 | return n.isNull() ? defaultValue.get() : n; |
70 | } |
71 | |
72 | void SVGStyleElement::setType(const AtomicString& type) |
73 | { |
74 | setAttribute(SVGNames::typeAttr, type); |
75 | } |
76 | |
77 | const AtomicString& SVGStyleElement::media() const |
78 | { |
79 | static NeverDestroyed<const AtomicString> defaultValue("all" , AtomicString::ConstructFromLiteral); |
80 | const AtomicString& n = attributeWithoutSynchronization(SVGNames::mediaAttr); |
81 | return n.isNull() ? defaultValue.get() : n; |
82 | } |
83 | |
84 | void SVGStyleElement::setMedia(const AtomicString& media) |
85 | { |
86 | setAttributeWithoutSynchronization(SVGNames::mediaAttr, media); |
87 | } |
88 | |
89 | String SVGStyleElement::title() const |
90 | { |
91 | return attributeWithoutSynchronization(SVGNames::titleAttr); |
92 | } |
93 | |
94 | void SVGStyleElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
95 | { |
96 | if (name == SVGNames::titleAttr) { |
97 | if (sheet() && !isInShadowTree()) |
98 | sheet()->setTitle(value); |
99 | return; |
100 | } |
101 | if (name == SVGNames::typeAttr) { |
102 | m_styleSheetOwner.setContentType(value); |
103 | return; |
104 | } |
105 | if (name == SVGNames::mediaAttr) { |
106 | m_styleSheetOwner.setMedia(value); |
107 | return; |
108 | } |
109 | |
110 | SVGElement::parseAttribute(name, value); |
111 | } |
112 | |
113 | void SVGStyleElement::finishParsingChildren() |
114 | { |
115 | m_styleSheetOwner.finishParsingChildren(*this); |
116 | SVGElement::finishParsingChildren(); |
117 | } |
118 | |
119 | Node::InsertedIntoAncestorResult SVGStyleElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree) |
120 | { |
121 | auto result = SVGElement::insertedIntoAncestor(insertionType, parentOfInsertedTree); |
122 | if (insertionType.connectedToDocument) |
123 | m_styleSheetOwner.insertedIntoDocument(*this); |
124 | return result; |
125 | } |
126 | |
127 | void SVGStyleElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree) |
128 | { |
129 | SVGElement::removedFromAncestor(removalType, oldParentOfRemovedTree); |
130 | if (removalType.disconnectedFromDocument) |
131 | m_styleSheetOwner.removedFromDocument(*this); |
132 | } |
133 | |
134 | void SVGStyleElement::childrenChanged(const ChildChange& change) |
135 | { |
136 | SVGElement::childrenChanged(change); |
137 | m_styleSheetOwner.childrenChanged(*this); |
138 | } |
139 | |
140 | } |
141 | |