author | Masayuki Nakano <masayuki@d-toybox.com> |
Thu, 07 Jul 2016 17:20:22 +0900 | |
changeset 385863 | 3a0e413508d3aac1baad6442a16e433160012263 |
parent 385862 | 809c4a7e48571d41c2d3ab46c3019c9af6364570 |
child 385864 | 18fb1efeffa5378d95bfd553603cd829d2fa03ec |
push id | 22587 |
push user | masayuki@d-toybox.com |
push date | Sat, 09 Jul 2016 06:59:31 +0000 |
reviewers | mccr8 |
bugs | 1260651 |
milestone | 50.0a1 |
rename from editor/libeditor/nsStyleSheetTxns.cpp rename to editor/libeditor/StyleSheetTransactions.cpp --- a/editor/libeditor/nsStyleSheetTxns.cpp +++ b/editor/libeditor/StyleSheetTransactions.cpp @@ -1,29 +1,29 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsStyleSheetTxns.h" +#include "StyleSheetTransactions.h" #include <stddef.h> // for nullptr #include "nsAString.h" #include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc #include "mozilla/StyleSheetHandle.h" // for mozilla::StyleSheetHandle #include "mozilla/StyleSheetHandleInlines.h" #include "nsDebug.h" // for NS_ENSURE_TRUE #include "nsError.h" // for NS_OK, etc #include "nsIDOMDocument.h" // for nsIDOMDocument #include "nsIDocument.h" // for nsIDocument #include "nsIDocumentObserver.h" // for UPDATE_STYLE #include "nsIEditor.h" // for nsIEditor -using namespace mozilla; +namespace mozilla { static void AddStyleSheet(nsIEditor* aEditor, StyleSheetHandle aSheet) { nsCOMPtr<nsIDOMDocument> domDoc; aEditor->GetDocument(getter_AddRefs(domDoc)); nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); if (doc) { @@ -41,106 +41,115 @@ RemoveStyleSheet(nsIEditor* aEditor, Sty nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); if (doc) { doc->BeginUpdate(UPDATE_STYLE); doc->RemoveStyleSheet(aSheet); doc->EndUpdate(UPDATE_STYLE); } } -AddStyleSheetTxn::AddStyleSheetTxn() -: EditTxn() -, mEditor(nullptr) +/****************************************************************************** + * AddStyleSheetTransaction + ******************************************************************************/ + +AddStyleSheetTransaction::AddStyleSheetTransaction() + : mEditor(nullptr) { } -NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTxn, EditTxn, +NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTransaction, EditTxn, mSheet) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTransaction) NS_INTERFACE_MAP_END_INHERITING(EditTxn) NS_IMETHODIMP -AddStyleSheetTxn::Init(nsIEditor* aEditor, StyleSheetHandle aSheet) +AddStyleSheetTransaction::Init(nsIEditor* aEditor, + StyleSheetHandle aSheet) { NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); mEditor = aEditor; mSheet = aSheet; return NS_OK; } NS_IMETHODIMP -AddStyleSheetTxn::DoTransaction() +AddStyleSheetTransaction::DoTransaction() { NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); AddStyleSheet(mEditor, mSheet); return NS_OK; } NS_IMETHODIMP -AddStyleSheetTxn::UndoTransaction() +AddStyleSheetTransaction::UndoTransaction() { NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); RemoveStyleSheet(mEditor, mSheet); return NS_OK; } NS_IMETHODIMP -AddStyleSheetTxn::GetTxnDescription(nsAString& aString) +AddStyleSheetTransaction::GetTxnDescription(nsAString& aString) { - aString.AssignLiteral("AddStyleSheetTxn"); + aString.AssignLiteral("AddStyleSheetTransaction"); return NS_OK; } +/****************************************************************************** + * RemoveStyleSheetTransaction + ******************************************************************************/ -RemoveStyleSheetTxn::RemoveStyleSheetTxn() -: EditTxn() -, mEditor(nullptr) +RemoveStyleSheetTransaction::RemoveStyleSheetTransaction() + : mEditor(nullptr) { } -NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTxn, EditTxn, +NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTransaction, EditTxn, mSheet) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTransaction) NS_INTERFACE_MAP_END_INHERITING(EditTxn) NS_IMETHODIMP -RemoveStyleSheetTxn::Init(nsIEditor* aEditor, StyleSheetHandle aSheet) +RemoveStyleSheetTransaction::Init(nsIEditor* aEditor, + StyleSheetHandle aSheet) { NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); mEditor = aEditor; mSheet = aSheet; return NS_OK; } NS_IMETHODIMP -RemoveStyleSheetTxn::DoTransaction() +RemoveStyleSheetTransaction::DoTransaction() { NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); RemoveStyleSheet(mEditor, mSheet); return NS_OK; } NS_IMETHODIMP -RemoveStyleSheetTxn::UndoTransaction() +RemoveStyleSheetTransaction::UndoTransaction() { NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); AddStyleSheet(mEditor, mSheet); return NS_OK; } NS_IMETHODIMP -RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString) +RemoveStyleSheetTransaction::GetTxnDescription(nsAString& aString) { - aString.AssignLiteral("RemoveStyleSheetTxn"); + aString.AssignLiteral("RemoveStyleSheetTransaction"); return NS_OK; } + +} // namespace mozilla
rename from editor/libeditor/nsStyleSheetTxns.h rename to editor/libeditor/StyleSheetTransactions.h --- a/editor/libeditor/nsStyleSheetTxns.h +++ b/editor/libeditor/StyleSheetTransactions.h @@ -1,65 +1,71 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsStylesheetTxns_h__ -#define nsStylesheetTxns_h__ +#ifndef StylesheetTransactions_h +#define StylesheetTransactions_h #include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN #include "mozilla/StyleSheetHandle.h" // for mozilla::StyleSheetHandle #include "nsCycleCollectionParticipant.h" #include "nsID.h" // for REFNSIID #include "nscore.h" // for NS_IMETHOD class nsIEditor; -class AddStyleSheetTxn : public EditTxn +namespace mozilla { + +class AddStyleSheetTransaction final : public EditTxn { public: - /** Initialize the transaction. - * @param aEditor the object providing core editing operations - * @param aSheet the stylesheet to add + /** + * Initialize the transaction. + * @param aEditor The object providing core editing operations + * @param aSheet The stylesheet to add */ - NS_IMETHOD Init(nsIEditor* aEditor, mozilla::StyleSheetHandle aSheet); + NS_IMETHOD Init(nsIEditor* aEditor, StyleSheetHandle aSheet); - AddStyleSheetTxn(); + AddStyleSheetTransaction(); - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AddStyleSheetTxn, EditTxn) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AddStyleSheetTransaction, EditTxn) NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; NS_DECL_EDITTXN protected: - - nsIEditor* mEditor; // the editor that created this transaction - mozilla::StyleSheetHandle::RefPtr mSheet; // the style sheet to add - + // The editor that created this transaction. + nsIEditor* mEditor; + // The style sheet to add. + mozilla::StyleSheetHandle::RefPtr mSheet; }; -class RemoveStyleSheetTxn : public EditTxn +class RemoveStyleSheetTransaction final : public EditTxn { public: - /** Initialize the transaction. - * @param aEditor the object providing core editing operations - * @param aSheet the stylesheet to remove - */ - NS_IMETHOD Init(nsIEditor* aEditor, mozilla::StyleSheetHandle aSheet); + /** + * Initialize the transaction. + * @param aEditor The object providing core editing operations. + * @param aSheet The stylesheet to remove. + */ + NS_IMETHOD Init(nsIEditor* aEditor, StyleSheetHandle aSheet); - RemoveStyleSheetTxn(); + RemoveStyleSheetTransaction(); - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(RemoveStyleSheetTxn, EditTxn) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(RemoveStyleSheetTransaction, EditTxn) NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; NS_DECL_EDITTXN protected: - - nsIEditor* mEditor; // the editor that created this transaction - mozilla::StyleSheetHandle::RefPtr mSheet; // the style sheet to remove + // The editor that created this transaction. + nsIEditor* mEditor; + // The style sheet to remove. + StyleSheetHandle::RefPtr mSheet; }; +} // namespace mozilla -#endif /* nsStylesheetTxns_h__ */ +#endif // #ifndef StylesheetTransactions_h
--- a/editor/libeditor/moz.build +++ b/editor/libeditor/moz.build @@ -42,24 +42,24 @@ UNIFIED_SOURCES += [ 'nsHTMLEditRules.cpp', 'nsHTMLInlineTableEditor.cpp', 'nsHTMLObjectResizer.cpp', 'nsHTMLURIRefObject.cpp', 'nsInternetCiter.cpp', 'nsPlaintextDataTransfer.cpp', 'nsPlaintextEditor.cpp', 'nsSelectionState.cpp', - 'nsStyleSheetTxns.cpp', 'nsTableEditor.cpp', 'nsTextEditRules.cpp', 'nsTextEditRulesBidi.cpp', 'nsWSRunObject.cpp', 'PlaceholderTransaction.cpp', 'SetDocumentTitleTransaction.cpp', 'SplitNodeTransaction.cpp', + 'StyleSheetTransactions.cpp', 'TextEditorTest.cpp', 'TextEditUtils.cpp', 'TypeInState.cpp', ] LOCAL_INCLUDES += [ '/dom/base', '/editor/txmgr',
--- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -19,16 +19,17 @@ #include "EditAggregateTransaction.h" // for EditAggregateTransaction #include "EditorUtils.h" // for AutoRules, etc #include "EditTxn.h" // for EditTxn #include "InsertNodeTransaction.h" // for InsertNodeTransaction #include "InsertTextTransaction.h" // for InsertTextTransaction #include "JoinNodeTransaction.h" // for JoinNodeTransaction #include "PlaceholderTransaction.h" // for PlaceholderTransaction #include "SplitNodeTransaction.h" // for SplitNodeTransaction +#include "StyleSheetTransactions.h" // for AddStyleSheetTransaction, etc #include "TextEditUtils.h" // for TextEditUtils #include "mozFlushType.h" // for mozFlushType::Flush_Frames #include "mozInlineSpellChecker.h" // for mozInlineSpellChecker #include "mozilla/CheckedInt.h" // for CheckedInt #include "mozilla/IMEStateManager.h" // for IMEStateManager #include "mozilla/Preferences.h" // for Preferences #include "mozilla/dom/Selection.h" // for Selection, etc #include "mozilla/Services.h" // for GetObserverService @@ -93,17 +94,16 @@ #include "nsPIDOMWindow.h" // for nsPIDOMWindow #include "nsPresContext.h" // for nsPresContext #include "nsRange.h" // for nsRange #include "nsReadableUtils.h" // for EmptyString, ToNewCString #include "nsString.h" // for nsAutoString, nsString, etc #include "nsStringFwd.h" // for nsAFlatString #include "nsStyleConsts.h" // for NS_STYLE_DIRECTION_RTL, etc #include "nsStyleContext.h" // for nsStyleContext -#include "nsStyleSheetTxns.h" // for AddStyleSheetTxn, etc #include "nsStyleStruct.h" // for nsStyleDisplay, nsStyleText, etc #include "nsStyleStructFwd.h" // for nsIFrame::StyleUIReset, etc #include "nsTextNode.h" // for nsTextNode #include "nsThreadUtils.h" // for nsRunnable #include "nsTransactionManager.h" // for nsTransactionManager #include "prtime.h" // for PR_Now class nsIOutputStream; @@ -4241,40 +4241,42 @@ nsEditor::CreateTxnForComposition(const RefPtr<CompositionTransaction> transaction = new CompositionTransaction(*mIMETextNode, mIMETextOffset, mIMETextLength, mComposition->GetRanges(), aStringToInsert, *this); return transaction.forget(); } NS_IMETHODIMP -nsEditor::CreateTxnForAddStyleSheet(StyleSheetHandle aSheet, AddStyleSheetTxn* *aTxn) -{ - RefPtr<AddStyleSheetTxn> txn = new AddStyleSheetTxn(); - - nsresult rv = txn->Init(this, aSheet); - if (NS_SUCCEEDED(rv)) - { - txn.forget(aTxn); +nsEditor::CreateTxnForAddStyleSheet(StyleSheetHandle aSheet, + AddStyleSheetTransaction** aTransaction) +{ + RefPtr<AddStyleSheetTransaction> transaction = new AddStyleSheetTransaction(); + + nsresult rv = transaction->Init(this, aSheet); + if (NS_SUCCEEDED(rv)) { + transaction.forget(aTransaction); } return rv; } NS_IMETHODIMP -nsEditor::CreateTxnForRemoveStyleSheet(StyleSheetHandle aSheet, RemoveStyleSheetTxn* *aTxn) -{ - RefPtr<RemoveStyleSheetTxn> txn = new RemoveStyleSheetTxn(); - - nsresult rv = txn->Init(this, aSheet); - if (NS_SUCCEEDED(rv)) - { - txn.forget(aTxn); +nsEditor::CreateTxnForRemoveStyleSheet( + StyleSheetHandle aSheet, + RemoveStyleSheetTransaction** aTransaction) +{ + RefPtr<RemoveStyleSheetTransaction> transaction = + new RemoveStyleSheetTransaction(); + + nsresult rv = transaction->Init(this, aSheet); + if (NS_SUCCEEDED(rv)) { + transaction.forget(aTransaction); } return rv; } nsresult nsEditor::CreateTxnForDeleteSelection(EDirection aAction,
--- a/editor/libeditor/nsEditor.h +++ b/editor/libeditor/nsEditor.h @@ -22,18 +22,16 @@ #include "nsISupportsImpl.h" // for nsEditor::Release, etc #include "nsIWeakReferenceUtils.h" // for nsWeakPtr #include "nsLiteralString.h" // for NS_LITERAL_STRING #include "nsSelectionState.h" // for nsRangeUpdater, etc #include "nsString.h" // for nsCString #include "nsWeakReference.h" // for nsSupportsWeakReference #include "nscore.h" // for nsresult, nsAString, etc -class AddStyleSheetTxn; -class RemoveStyleSheetTxn; class nsIAtom; class nsIContent; class nsIDOMDocument; class nsIDOMEvent; class nsIDOMEventListener; class nsIDOMEventTarget; class nsIDOMKeyEvent; class nsIDOMNode; @@ -47,29 +45,31 @@ class nsIPresShell; class nsISupports; class nsITransaction; class nsIWidget; class nsRange; class nsString; class nsTransactionManager; namespace mozilla { +class AddStyleSheetTransaction; class AutoRules; class AutoSelectionRestorer; class AutoTransactionsConserveSelection; class ChangeAttributeTransaction; class CompositionTransaction; class CreateElementTransaction; class DeleteNodeTransaction; class DeleteTextTransaction; class EditAggregateTransaction; class ErrorResult; class InsertNodeTransaction; class InsertTextTransaction; class JoinNodeTransaction; +class RemoveStyleSheetTransaction; class SplitNodeTransaction; class TextComposition; struct EditorDOMPoint; namespace dom { class DataTransfer; class Element; class EventTarget; @@ -311,23 +311,25 @@ protected: int32_t aOffset); // Never returns null. already_AddRefed<mozilla::CompositionTransaction> CreateTxnForComposition(const nsAString& aStringToInsert); /** create a transaction for adding a style sheet */ - NS_IMETHOD CreateTxnForAddStyleSheet(mozilla::StyleSheetHandle aSheet, - AddStyleSheetTxn* *aTxn); + NS_IMETHOD CreateTxnForAddStyleSheet( + mozilla::StyleSheetHandle aSheet, + mozilla::AddStyleSheetTransaction** aTransaction); /** create a transaction for removing a style sheet */ - NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::StyleSheetHandle aSheet, - RemoveStyleSheetTxn* *aTxn); + NS_IMETHOD CreateTxnForRemoveStyleSheet( + mozilla::StyleSheetHandle aSheet, + mozilla::RemoveStyleSheetTransaction** aTransaction); nsresult DeleteText(nsGenericDOMDataNode& aElement, uint32_t aOffset, uint32_t aLength); // NS_IMETHOD DeleteRange(nsIDOMRange *aRange); already_AddRefed<mozilla::DeleteTextTransaction> CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
--- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -10,16 +10,17 @@ #include "mozilla/TextEvents.h" #include "nsCRT.h" #include "nsUnicharUtils.h" #include "HTMLEditUtils.h" #include "SetDocumentTitleTransaction.h" +#include "StyleSheetTransactions.h" #include "TextEditUtils.h" #include "nsHTMLEditRules.h" #include "nsHTMLEditorEventListener.h" #include "TypeInState.h" #include "nsHTMLURIRefObject.h" @@ -50,19 +51,16 @@ #include "nsPresContext.h" #include "nsFocusManager.h" #include "nsPIDOMWindow.h" // netwerk #include "nsIURI.h" #include "nsNetUtil.h" -// Transactionas -#include "nsStyleSheetTxns.h" - // Misc #include "EditorUtils.h" #include "TextEditorTest.h" #include "nsWSRunObject.h" #include "nsGkAtoms.h" #include "nsIWidget.h" #include "nsIFrame.h" @@ -2824,25 +2822,27 @@ nsHTMLEditor::ReplaceStyleSheet(const ns } NS_IMETHODIMP nsHTMLEditor::RemoveStyleSheet(const nsAString &aURL) { StyleSheetHandle::RefPtr sheet = GetStyleSheetForURL(aURL); NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED); - RefPtr<RemoveStyleSheetTxn> txn; - nsresult rv = CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(txn)); - if (!txn) rv = NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(rv)) - { - rv = DoTransaction(txn); - if (NS_SUCCEEDED(rv)) + RefPtr<RemoveStyleSheetTransaction> transaction; + nsresult rv = + CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(transaction)); + if (!transaction) { + rv = NS_ERROR_NULL_POINTER; + } + if (NS_SUCCEEDED(rv)) { + rv = DoTransaction(transaction); + if (NS_SUCCEEDED(rv)) { mLastStyleSheetURL.Truncate(); // forget it - + } // Remove it from our internal list rv = RemoveStyleSheetFromList(aURL); } return rv; } @@ -3395,30 +3395,29 @@ nsHTMLEditor::StyleSheetLoaded(StyleShee nsresult aStatus) { nsresult rv = NS_OK; AutoEditBatch batchIt(this); if (!mLastStyleSheetURL.IsEmpty()) RemoveStyleSheet(mLastStyleSheetURL); - RefPtr<AddStyleSheetTxn> txn; - rv = CreateTxnForAddStyleSheet(aSheet, getter_AddRefs(txn)); - if (!txn) rv = NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(rv)) - { - rv = DoTransaction(txn); - if (NS_SUCCEEDED(rv)) - { + RefPtr<AddStyleSheetTransaction> transaction; + rv = CreateTxnForAddStyleSheet(aSheet, getter_AddRefs(transaction)); + if (!transaction) { + rv = NS_ERROR_NULL_POINTER; + } + if (NS_SUCCEEDED(rv)) { + rv = DoTransaction(transaction); + if (NS_SUCCEEDED(rv)) { // Get the URI, then url spec from the sheet nsAutoCString spec; rv = aSheet->GetSheetURI()->GetSpec(spec); - if (NS_SUCCEEDED(rv)) - { + if (NS_SUCCEEDED(rv)) { // Save it so we can remove before applying the next one mLastStyleSheetURL.AssignWithConversion(spec.get()); // Also save in our arrays of urls and sheets AddNewStyleSheetToList(mLastStyleSheetURL, aSheet); } } }
--- a/layout/style/StyleSheetHandleInlines.h +++ b/layout/style/StyleSheetHandleInlines.h @@ -171,49 +171,49 @@ StyleSheetHandle::Ptr::SizeOfIncludingTh #ifdef DEBUG void StyleSheetHandle::Ptr::List(FILE* aOut, int32_t aIndex) const { FORWARD(List, (aOut, aIndex)); } #endif -} // namespace mozilla - #undef FORWARD inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - mozilla::StyleSheetHandle& aField, + StyleSheetHandle& aField, const char* aName, uint32_t aFlags = 0) { if (aField && aField->IsGecko()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCallback, aName); aCallback.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, aField->AsGecko())); } } inline void -ImplCycleCollectionUnlink(mozilla::StyleSheetHandle& aField) +ImplCycleCollectionUnlink(StyleSheetHandle& aField) { aField = nullptr; } inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - mozilla::StyleSheetHandle::RefPtr& aField, + StyleSheetHandle::RefPtr& aField, const char* aName, uint32_t aFlags = 0) { if (aField && aField->IsGecko()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCallback, aName); aCallback.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, aField->AsGecko())); } } inline void -ImplCycleCollectionUnlink(mozilla::StyleSheetHandle::RefPtr& aField) +ImplCycleCollectionUnlink(StyleSheetHandle::RefPtr& aField) { aField = nullptr; } +} // namespace mozilla + #endif // mozilla_StyleSheetHandleInlines_h