SVGStyleElement.h (3474B)
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/. */ 6 7 #ifndef DOM_SVG_SVGSTYLEELEMENT_H_ 8 #define DOM_SVG_SVGSTYLEELEMENT_H_ 9 10 #include "SVGElement.h" 11 #include "mozilla/dom/LinkStyle.h" 12 #include "nsStubMutationObserver.h" 13 14 nsresult NS_NewSVGStyleElement( 15 nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 16 17 namespace mozilla::dom { 18 19 using SVGStyleElementBase = SVGElement; 20 21 class SVGStyleElement final : public SVGStyleElementBase, 22 public nsStubMutationObserver, 23 public LinkStyle { 24 protected: 25 friend nsresult(::NS_NewSVGStyleElement( 26 nsIContent** aResult, 27 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)); 28 explicit SVGStyleElement( 29 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 30 ~SVGStyleElement() = default; 31 32 JSObject* WrapNode(JSContext* aCx, 33 JS::Handle<JSObject*> aGivenProto) override; 34 35 public: 36 NS_DECL_ISUPPORTS_INHERITED 37 38 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGStyleElement, SVGStyleElementBase) 39 40 // nsIContent 41 nsresult BindToTree(BindContext&, nsINode& aParent) override; 42 void UnbindFromTree(UnbindContext&) override; 43 virtual void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 44 const nsAttrValue* aValue, 45 const nsAttrValue* aOldValue, 46 nsIPrincipal* aMaybeScriptedPrincipal, 47 bool aNotify) override; 48 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 49 const nsAString& aValue, 50 nsIPrincipal* aMaybeScriptedPrincipal, 51 nsAttrValue& aResult) override; 52 53 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 54 55 // nsIMutationObserver 56 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED 57 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED 58 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED 59 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED 60 61 // WebIDL 62 bool Disabled() const; 63 void SetDisabled(bool aDisabled); 64 void GetMedia(nsAString& aMedia); 65 void SetMedia(const nsAString& aMedia, ErrorResult& rv); 66 void GetType(nsAString& aType); 67 void SetType(const nsAString& aType, ErrorResult& rv); 68 void GetTitle(nsAString& aTitle); 69 void SetTitle(const nsAString& aTitle, ErrorResult& rv); 70 71 protected: 72 // Dummy init method to make the NS_IMPL_NS_NEW_SVG_ELEMENT and 73 // NS_IMPL_ELEMENT_CLONE_WITH_INIT usable with this class. This should be 74 // completely optimized away. 75 inline nsresult Init() { return NS_OK; } 76 77 // LinkStyle overrides 78 nsIContent& AsContent() final { return *this; } 79 const LinkStyle* AsLinkStyle() const final { return this; } 80 Maybe<SheetInfo> GetStyleSheetInfo() final; 81 82 /** 83 * Common method to call from the various mutation observer methods. 84 * aContent is a content node that's either the one that changed or its 85 * parent; we should only respond to the change if aContent is non-anonymous. 86 */ 87 void ContentChanged(nsIContent* aContent); 88 nsresult CopyInnerTo(SVGStyleElement* aDest); 89 }; 90 91 } // namespace mozilla::dom 92 93 #endif // DOM_SVG_SVGSTYLEELEMENT_H_