XMLStylesheetProcessingInstruction.h (3126B)
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 mozilla_dom_XMLStylesheetProcessingInstruction_h 8 #define mozilla_dom_XMLStylesheetProcessingInstruction_h 9 10 #include "mozilla/dom/LinkStyle.h" 11 #include "mozilla/dom/ProcessingInstruction.h" 12 #include "nsIURI.h" 13 14 namespace mozilla::dom { 15 16 class XMLStylesheetProcessingInstruction final : public ProcessingInstruction, 17 public LinkStyle { 18 public: 19 XMLStylesheetProcessingInstruction( 20 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 21 const nsAString& aData) 22 : ProcessingInstruction(std::move(aNodeInfo), aData) {} 23 24 XMLStylesheetProcessingInstruction(nsNodeInfoManager* aNodeInfoManager, 25 const nsAString& aData) 26 : ProcessingInstruction( 27 aNodeInfoManager->GetNodeInfo( 28 nsGkAtoms::processingInstructionTagName, nullptr, 29 kNameSpaceID_None, PROCESSING_INSTRUCTION_NODE, 30 nsGkAtoms::xml_stylesheet), 31 aData) {} 32 33 // CC 34 NS_DECL_ISUPPORTS_INHERITED 35 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XMLStylesheetProcessingInstruction, 36 ProcessingInstruction) 37 38 // nsINode 39 virtual void SetNodeValueInternal( 40 const nsAString& aNodeValue, mozilla::ErrorResult& aError, 41 MutationEffectOnScript aMutationEffectOnScript) override; 42 43 // nsIContent 44 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; 45 virtual void UnbindFromTree(UnbindContext&) override; 46 47 /** 48 * Tells this processing instruction to use a different base URI. This is used 49 * for proper loading of xml-stylesheet processing instructions in XUL 50 * overlays and is only currently used by nsXMLStylesheetPI. 51 * 52 * @param aNewBaseURI the new base URI, nullptr to use the default base URI. 53 */ 54 void OverrideBaseURI(nsIURI* aNewBaseURI); 55 56 // LinkStyle 57 void GetCharset(nsAString& aCharset) override; 58 59 virtual void SetDataInternal(const nsAString& aData, 60 MutationEffectOnScript aMutationEffectOnScript, 61 mozilla::ErrorResult& rv) override { 62 CharacterData::SetDataInternal(aData, aMutationEffectOnScript, rv); 63 if (rv.Failed()) { 64 return; 65 } 66 (void)UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes); 67 } 68 69 protected: 70 virtual ~XMLStylesheetProcessingInstruction(); 71 72 nsCOMPtr<nsIURI> mOverriddenBaseURI; 73 74 nsIContent& AsContent() final { return *this; } 75 const LinkStyle* AsLinkStyle() const final { return this; } 76 Maybe<SheetInfo> GetStyleSheetInfo() final; 77 78 already_AddRefed<CharacterData> CloneDataNode( 79 mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const final; 80 }; 81 82 } // namespace mozilla::dom 83 84 #endif // mozilla_dom_XMLStylesheetProcessingInstruction_h