Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / dom / svg / SVGStyleElement.cpp
blob74b661ba40c6792599d6198be6c84a0cb9b9f81b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/Element.h"
8 #include "mozilla/dom/SVGStyleElement.h"
9 #include "nsContentUtils.h"
10 #include "mozilla/dom/SVGStyleElementBinding.h"
12 NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Style)
14 namespace mozilla {
15 namespace dom {
17 JSObject*
18 SVGStyleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
20 return SVGStyleElementBinding::Wrap(aCx, this, aGivenProto);
23 //----------------------------------------------------------------------
24 // nsISupports methods
26 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGStyleElement,
27 SVGStyleElementBase,
28 nsIStyleSheetLinkingElement,
29 nsIMutationObserver)
31 NS_IMPL_CYCLE_COLLECTION_CLASS(SVGStyleElement)
33 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGStyleElement,
34 SVGStyleElementBase)
35 tmp->nsStyleLinkElement::Traverse(cb);
36 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
38 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
39 SVGStyleElementBase)
40 tmp->nsStyleLinkElement::Unlink();
41 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
43 //----------------------------------------------------------------------
44 // Implementation
46 SVGStyleElement::SVGStyleElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
47 : SVGStyleElementBase(aNodeInfo)
49 AddMutationObserver(this);
52 SVGStyleElement::~SVGStyleElement()
56 //----------------------------------------------------------------------
57 // nsIDOMNode methods
60 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGStyleElement)
63 //----------------------------------------------------------------------
64 // nsIContent methods
66 nsresult
67 SVGStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
68 nsIContent* aBindingParent,
69 bool aCompileEventHandlers)
71 nsresult rv = SVGStyleElementBase::BindToTree(aDocument, aParent,
72 aBindingParent,
73 aCompileEventHandlers);
74 NS_ENSURE_SUCCESS(rv, rv);
76 void (SVGStyleElement::*update)() = &SVGStyleElement::UpdateStyleSheetInternal;
77 nsContentUtils::AddScriptRunner(
78 NewRunnableMethod("dom::SVGStyleElement::BindToTree", this, update));
80 return rv;
83 void
84 SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
86 nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
87 ShadowRoot* oldShadow = GetContainingShadow();
88 SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
89 UpdateStyleSheetInternal(oldDoc, oldShadow);
92 nsresult
93 SVGStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
94 const nsAttrValue* aValue,
95 const nsAttrValue* aOldValue,
96 nsIPrincipal* aMaybeScriptedPrincipal,
97 bool aNotify)
99 if (aNameSpaceID == kNameSpaceID_None) {
100 if (aName == nsGkAtoms::title ||
101 aName == nsGkAtoms::media ||
102 aName == nsGkAtoms::type) {
103 UpdateStyleSheetInternal(nullptr, nullptr, true);
107 return SVGStyleElementBase::AfterSetAttr(aNameSpaceID, aName, aValue,
108 aOldValue, aMaybeScriptedPrincipal,
109 aNotify);
112 bool
113 SVGStyleElement::ParseAttribute(int32_t aNamespaceID,
114 nsAtom* aAttribute,
115 const nsAString& aValue,
116 nsIPrincipal* aMaybeScriptedPrincipal,
117 nsAttrValue& aResult)
119 if (aNamespaceID == kNameSpaceID_None &&
120 aAttribute == nsGkAtoms::crossorigin) {
121 ParseCORSValue(aValue, aResult);
122 return true;
125 return SVGStyleElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
126 aMaybeScriptedPrincipal, aResult);
129 //----------------------------------------------------------------------
130 // nsIMutationObserver methods
132 void
133 SVGStyleElement::CharacterDataChanged(nsIContent* aContent,
134 const CharacterDataChangeInfo&)
136 ContentChanged(aContent);
139 void
140 SVGStyleElement::ContentAppended(nsIContent* aFirstNewContent)
142 ContentChanged(aFirstNewContent->GetParent());
145 void
146 SVGStyleElement::ContentInserted(nsIContent* aChild)
148 ContentChanged(aChild);
151 void
152 SVGStyleElement::ContentRemoved(nsIContent* aChild,
153 nsIContent* aPreviousSibling)
155 ContentChanged(aChild);
158 void
159 SVGStyleElement::ContentChanged(nsIContent* aContent)
161 if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
162 UpdateStyleSheetInternal(nullptr, nullptr);
166 //----------------------------------------------------------------------
168 void
169 SVGStyleElement::GetXmlspace(nsAString & aXmlspace)
171 GetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace);
174 void
175 SVGStyleElement::SetXmlspace(const nsAString & aXmlspace, ErrorResult& rv)
177 rv = SetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace, true);
180 void
181 SVGStyleElement::GetMedia(nsAString & aMedia)
183 GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
186 void
187 SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv)
189 rv = SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
192 void
193 SVGStyleElement::GetType(nsAString & aType)
195 GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
198 void
199 SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv)
201 rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
204 void
205 SVGStyleElement::GetTitle(nsAString & aTitle)
207 GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
210 void
211 SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
213 rv = SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
216 //----------------------------------------------------------------------
217 // nsStyleLinkElement methods
219 already_AddRefed<nsIURI>
220 SVGStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
222 *aIsInline = true;
223 *aTriggeringPrincipal = nullptr;
224 return nullptr;
227 void
228 SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
229 nsAString& aType,
230 nsAString& aMedia,
231 bool* aIsAlternate)
233 *aIsAlternate = false;
235 nsAutoString title;
236 GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
237 title.CompressWhitespace();
238 aTitle.Assign(title);
240 GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
241 // The SVG spec is formulated in terms of the CSS2 spec,
242 // which specifies that media queries are case insensitive.
243 nsContentUtils::ASCIIToLower(aMedia);
245 GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
246 if (aType.IsEmpty()) {
247 aType.AssignLiteral("text/css");
251 CORSMode
252 SVGStyleElement::GetCORSMode() const
254 return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
257 } // namespace dom
258 } // namespace mozilla