From bbbb83c93790f2873db6aa79eae64ad7306be67c Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 18 Dec 2017 17:29:32 +0900 Subject: [PATCH] Bug 1425412 - part 10: Create factory methods for AddStyleSheetTransaction and RemoveStyleSheetTransaction, and remove EditorBase::CreateTxnForAddStyleSheet() and EditorBase::CreateTxnForRemoveStyleSheet() r=m_kato This patch creates factory methods for AddStyleSheetTransaction and RemoveStyleSheetTransaction, and removes EditorBase::CreateTxnForAddStyleSheet() and EditorBase::CreateTxnForRemoveStyleSheet() instead. MozReview-Commit-ID: 6dnZctDtNik --HG-- extra : rebase_source : 43eaadbde06e4a0b061ea8136e12ffeccfaf5592 --- editor/libeditor/EditorBase.cpp | 18 ----------- editor/libeditor/EditorBase.h | 12 -------- editor/libeditor/HTMLEditor.cpp | 12 ++------ editor/libeditor/StyleSheetTransactions.cpp | 10 +++---- editor/libeditor/StyleSheetTransactions.h | 33 +++++++++++++++++---- 5 files changed, 33 insertions(+), 52 deletions(-) diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index 24b1a166eaa4..e9e64402c640 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -4583,24 +4583,6 @@ EditorBase::DoAfterRedoTransaction() MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(1)); } -already_AddRefed -EditorBase::CreateTxnForAddStyleSheet(StyleSheet* aSheet) -{ - RefPtr transaction = - new AddStyleSheetTransaction(*this, aSheet); - - return transaction.forget(); -} - -already_AddRefed -EditorBase::CreateTxnForRemoveStyleSheet(StyleSheet* aSheet) -{ - RefPtr transaction = - new RemoveStyleSheetTransaction(*this, aSheet); - - return transaction.forget(); -} - already_AddRefed EditorBase::CreateTxnForDeleteSelection(EDirection aAction, nsINode** aRemovingNode, diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index 5fd66ba97a9e..bdc87998c3fa 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -560,18 +560,6 @@ protected: int32_t* aOffset, int32_t* aLength); - /** - * Create a transaction for adding a style sheet. - */ - already_AddRefed - CreateTxnForAddStyleSheet(StyleSheet* aSheet); - - /** - * Create a transaction for removing a style sheet. - */ - already_AddRefed - CreateTxnForRemoveStyleSheet(StyleSheet* aSheet); - nsresult DeleteText(nsGenericDOMDataNode& aElement, uint32_t aOffset, uint32_t aLength); diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 5ad446b230a5..c72bd2e68f42 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -2802,11 +2802,7 @@ HTMLEditor::RemoveStyleSheet(const nsAString& aURL) NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED); RefPtr transaction = - CreateTxnForRemoveStyleSheet(sheet); - if (!transaction) { - return NS_ERROR_NULL_POINTER; - } - + RemoveStyleSheetTransaction::Create(*this, *sheet); nsresult rv = DoTransaction(transaction); if (NS_SUCCEEDED(rv)) { mLastStyleSheetURL.Truncate(); // forget it @@ -3382,11 +3378,7 @@ HTMLEditor::StyleSheetLoaded(StyleSheet* aSheet, RemoveStyleSheet(mLastStyleSheetURL); RefPtr transaction = - CreateTxnForAddStyleSheet(aSheet); - if (!transaction) { - return NS_OK; - } - + AddStyleSheetTransaction::Create(*this, *aSheet); nsresult rv = DoTransaction(transaction); if (NS_SUCCEEDED(rv)) { // Get the URI, then url spec from the sheet diff --git a/editor/libeditor/StyleSheetTransactions.cpp b/editor/libeditor/StyleSheetTransactions.cpp index f07c917e5fa1..200f88671709 100644 --- a/editor/libeditor/StyleSheetTransactions.cpp +++ b/editor/libeditor/StyleSheetTransactions.cpp @@ -45,11 +45,10 @@ RemoveStyleSheet(EditorBase& aEditor, StyleSheet* aSheet) ******************************************************************************/ AddStyleSheetTransaction::AddStyleSheetTransaction(EditorBase& aEditorBase, - StyleSheet* aSheet) + StyleSheet& aStyleSheet) : mEditorBase(&aEditorBase) - , mSheet(aSheet) + , mSheet(&aStyleSheet) { - MOZ_ASSERT(aSheet); } NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTransaction, @@ -93,11 +92,10 @@ AddStyleSheetTransaction::GetTxnDescription(nsAString& aString) RemoveStyleSheetTransaction::RemoveStyleSheetTransaction( EditorBase& aEditorBase, - StyleSheet* aSheet) + StyleSheet& aStyleSheet) : mEditorBase(&aEditorBase) - , mSheet(aSheet) + , mSheet(&aStyleSheet) { - MOZ_ASSERT(aSheet); } NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTransaction, diff --git a/editor/libeditor/StyleSheetTransactions.h b/editor/libeditor/StyleSheetTransactions.h index 9b0e746269e2..9ba48ec5e654 100644 --- a/editor/libeditor/StyleSheetTransactions.h +++ b/editor/libeditor/StyleSheetTransactions.h @@ -17,12 +17,23 @@ namespace mozilla { class AddStyleSheetTransaction final : public EditTransactionBase { +protected: + AddStyleSheetTransaction(EditorBase& aEditor, StyleSheet& aStyleSheet); + public: /** - * @param aEditor The object providing core editing operations - * @param aSheet The stylesheet to add - */ - AddStyleSheetTransaction(EditorBase& aEditor, StyleSheet* aSheet); + * Creates an add style sheet transaction. This never returns nullptr. + * + * @param aEditorBase The editor. + * @param aSheet The style sheet to add. + */ + static already_AddRefed + Create(EditorBase& aEditorBase, StyleSheet& aStyleSheet) + { + RefPtr transaction = + new AddStyleSheetTransaction(aEditorBase, aStyleSheet); + return transaction.forget(); + } NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AddStyleSheetTransaction, EditTransactionBase) @@ -40,12 +51,23 @@ protected: class RemoveStyleSheetTransaction final : public EditTransactionBase { +protected: + RemoveStyleSheetTransaction(EditorBase& aEditor, StyleSheet& aStyleSheet); + public: /** + * Creates a remove style sheet transaction. This never returns nullptr. + * * @param aEditor The object providing core editing operations. * @param aSheet The stylesheet to remove. */ - RemoveStyleSheetTransaction(EditorBase& aEditor, StyleSheet* aSheet); + static already_AddRefed + Create(EditorBase& aEditorBase, StyleSheet& aStyleSheet) + { + RefPtr transaction = + new RemoveStyleSheetTransaction(aEditorBase, aStyleSheet); + return transaction.forget(); + } NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(RemoveStyleSheetTransaction, EditTransactionBase) @@ -58,7 +80,6 @@ protected: RefPtr mEditorBase; // The style sheet to remove. RefPtr mSheet; - }; } // namespace mozilla