1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef StylesheetTransactions_h 7 #define StylesheetTransactions_h 8 9 #include "mozilla/EditorBase.h" // mEditor 10 #include "mozilla/EditTransactionBase.h" // for EditTransactionBase, etc. 11 #include "mozilla/StyleSheet.h" // for mozilla::StyleSheet 12 #include "nsCycleCollectionParticipant.h" 13 #include "nsID.h" // for REFNSIID 14 #include "nscore.h" // for NS_IMETHOD 15 16 namespace mozilla { 17 18 class AddStyleSheetTransaction final : public EditTransactionBase { 19 protected: 20 AddStyleSheetTransaction(EditorBase& aEditor, StyleSheet& aStyleSheet); 21 22 public: 23 /** 24 * Creates an add style sheet transaction. This never returns nullptr. 25 * 26 * @param aEditorBase The editor. 27 * @param aSheet The style sheet to add. 28 */ Create(EditorBase & aEditorBase,StyleSheet & aStyleSheet)29 static already_AddRefed<AddStyleSheetTransaction> Create( 30 EditorBase& aEditorBase, StyleSheet& aStyleSheet) { 31 RefPtr<AddStyleSheetTransaction> transaction = 32 new AddStyleSheetTransaction(aEditorBase, aStyleSheet); 33 return transaction.forget(); 34 } 35 36 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AddStyleSheetTransaction, 37 EditTransactionBase) 38 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; 39 40 NS_DECL_EDITTRANSACTIONBASE 41 42 protected: 43 // The editor that created this transaction. 44 RefPtr<EditorBase> mEditorBase; 45 // The style sheet to add. 46 RefPtr<mozilla::StyleSheet> mSheet; 47 }; 48 49 class RemoveStyleSheetTransaction final : public EditTransactionBase { 50 protected: 51 RemoveStyleSheetTransaction(EditorBase& aEditor, StyleSheet& aStyleSheet); 52 53 public: 54 /** 55 * Creates a remove style sheet transaction. This never returns nullptr. 56 * 57 * @param aEditor The object providing core editing operations. 58 * @param aSheet The stylesheet to remove. 59 */ Create(EditorBase & aEditorBase,StyleSheet & aStyleSheet)60 static already_AddRefed<RemoveStyleSheetTransaction> Create( 61 EditorBase& aEditorBase, StyleSheet& aStyleSheet) { 62 RefPtr<RemoveStyleSheetTransaction> transaction = 63 new RemoveStyleSheetTransaction(aEditorBase, aStyleSheet); 64 return transaction.forget(); 65 } 66 67 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(RemoveStyleSheetTransaction, 68 EditTransactionBase) 69 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; 70 71 NS_DECL_EDITTRANSACTIONBASE 72 73 protected: 74 // The editor that created this transaction. 75 RefPtr<EditorBase> mEditorBase; 76 // The style sheet to remove. 77 RefPtr<StyleSheet> mSheet; 78 }; 79 80 } // namespace mozilla 81 82 #endif // #ifndef StylesheetTransactions_h 83