Bug 1260651 part.27 Rename PlaceholderTxn to mozilla::PlaceholderTransaction (and their files too) r=mccr8
MozReview-Commit-ID: F6DeWadjTmP
rename from editor/libeditor/PlaceholderTxn.cpp
rename to editor/libeditor/PlaceholderTransaction.cpp
--- a/editor/libeditor/PlaceholderTxn.cpp
+++ b/editor/libeditor/PlaceholderTransaction.cpp
@@ -1,109 +1,115 @@
/* -*- 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 "PlaceholderTxn.h"
+#include "PlaceholderTransaction.h"
#include "CompositionTransaction.h"
#include "mozilla/dom/Selection.h"
#include "nsEditor.h"
#include "nsGkAtoms.h"
#include "nsQueryObject.h"
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
-PlaceholderTxn::PlaceholderTxn()
+using namespace dom;
+
+PlaceholderTransaction::PlaceholderTransaction()
: mAbsorb(true)
, mForwarding(nullptr)
, mCompositionTransaction(nullptr)
, mCommitted(false)
, mEditor(nullptr)
{
}
-PlaceholderTxn::~PlaceholderTxn()
+PlaceholderTransaction::~PlaceholderTransaction()
{
}
-NS_IMPL_CYCLE_COLLECTION_CLASS(PlaceholderTxn)
+NS_IMPL_CYCLE_COLLECTION_CLASS(PlaceholderTransaction)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PlaceholderTxn,
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PlaceholderTransaction,
EditAggregateTxn)
if (tmp->mStartSel) {
ImplCycleCollectionUnlink(*tmp->mStartSel);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEndSel);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PlaceholderTxn,
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PlaceholderTransaction,
EditAggregateTxn)
if (tmp->mStartSel) {
ImplCycleCollectionTraverse(cb, *tmp->mStartSel, "mStartSel", 0);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndSel);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PlaceholderTxn)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PlaceholderTransaction)
NS_INTERFACE_MAP_ENTRY(nsIAbsorbingTransaction)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTxn)
-NS_IMPL_ADDREF_INHERITED(PlaceholderTxn, EditAggregateTxn)
-NS_IMPL_RELEASE_INHERITED(PlaceholderTxn, EditAggregateTxn)
+NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTxn)
+NS_IMPL_RELEASE_INHERITED(PlaceholderTransaction, EditAggregateTxn)
NS_IMETHODIMP
-PlaceholderTxn::Init(nsIAtom* aName, nsSelectionState* aSelState,
- nsEditor* aEditor)
+PlaceholderTransaction::Init(nsIAtom* aName,
+ nsSelectionState* aSelState,
+ nsEditor* aEditor)
{
NS_ENSURE_TRUE(aEditor && aSelState, NS_ERROR_NULL_POINTER);
mName = aName;
mStartSel = aSelState;
mEditor = aEditor;
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::DoTransaction(void)
+NS_IMETHODIMP
+PlaceholderTransaction::DoTransaction()
{
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::UndoTransaction(void)
+NS_IMETHODIMP
+PlaceholderTransaction::UndoTransaction()
{
// undo txns
nsresult res = EditAggregateTxn::UndoTransaction();
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER);
// now restore selection
RefPtr<Selection> selection = mEditor->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
return mStartSel->RestoreSelection(selection);
}
-
-NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void)
+NS_IMETHODIMP
+PlaceholderTransaction::RedoTransaction()
{
// redo txns
nsresult res = EditAggregateTxn::RedoTransaction();
NS_ENSURE_SUCCESS(res, res);
// now restore selection
RefPtr<Selection> selection = mEditor->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
return mEndSel.RestoreSelection(selection);
}
-NS_IMETHODIMP PlaceholderTxn::Merge(nsITransaction *aTransaction, bool *aDidMerge)
+NS_IMETHODIMP
+PlaceholderTransaction::Merge(nsITransaction* aTransaction,
+ bool* aDidMerge)
{
NS_ENSURE_TRUE(aDidMerge && aTransaction, NS_ERROR_NULL_POINTER);
// set out param default value
*aDidMerge=false;
if (mForwarding)
{
@@ -188,75 +194,85 @@ NS_IMETHODIMP PlaceholderTxn::Merge(nsIT
}
}
}
}
}
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::GetTxnDescription(nsAString& aString)
+NS_IMETHODIMP
+PlaceholderTransaction::GetTxnDescription(nsAString& aString)
{
- aString.AssignLiteral("PlaceholderTxn: ");
+ aString.AssignLiteral("PlaceholderTransaction: ");
if (mName)
{
nsAutoString name;
mName->ToString(name);
aString += name;
}
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::GetTxnName(nsIAtom **aName)
+NS_IMETHODIMP
+PlaceholderTransaction::GetTxnName(nsIAtom** aName)
{
return GetName(aName);
}
-NS_IMETHODIMP PlaceholderTxn::StartSelectionEquals(nsSelectionState *aSelState, bool *aResult)
+NS_IMETHODIMP
+PlaceholderTransaction::StartSelectionEquals(nsSelectionState* aSelState,
+ bool* aResult)
{
// determine if starting selection matches the given selection state.
// note that we only care about collapsed selections.
NS_ENSURE_TRUE(aResult && aSelState, NS_ERROR_NULL_POINTER);
if (!mStartSel->IsCollapsed() || !aSelState->IsCollapsed())
{
*aResult = false;
return NS_OK;
}
*aResult = mStartSel->IsEqual(aSelState);
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::EndPlaceHolderBatch()
+NS_IMETHODIMP
+PlaceholderTransaction::EndPlaceHolderBatch()
{
mAbsorb = false;
if (mForwarding)
{
nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryReferent(mForwarding);
if (plcTxn) plcTxn->EndPlaceHolderBatch();
}
// remember our selection state.
return RememberEndingSelection();
}
-NS_IMETHODIMP PlaceholderTxn::ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress)
+NS_IMETHODIMP
+PlaceholderTransaction::ForwardEndBatchTo(
+ nsIAbsorbingTransaction* aForwardingAddress)
{
mForwarding = do_GetWeakReference(aForwardingAddress);
return NS_OK;
}
-NS_IMETHODIMP PlaceholderTxn::Commit()
+NS_IMETHODIMP
+PlaceholderTransaction::Commit()
{
mCommitted = true;
return NS_OK;
}
-nsresult PlaceholderTxn::RememberEndingSelection()
+nsresult
+PlaceholderTransaction::RememberEndingSelection()
{
RefPtr<Selection> selection = mEditor->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
mEndSel.SaveSelection(selection);
return NS_OK;
}
+} // namespace mozilla
rename from editor/libeditor/PlaceholderTxn.h
rename to editor/libeditor/PlaceholderTransaction.h
--- a/editor/libeditor/PlaceholderTxn.h
+++ b/editor/libeditor/PlaceholderTransaction.h
@@ -1,83 +1,92 @@
/* -*- 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 AggregatePlaceholderTxn_h__
-#define AggregatePlaceholderTxn_h__
+#ifndef PlaceholderTransaction_h
+#define PlaceholderTransaction_h
#include "EditAggregateTxn.h"
#include "EditorUtils.h"
#include "nsIAbsorbingTransaction.h"
#include "nsIDOMNode.h"
#include "nsCOMPtr.h"
#include "nsWeakPtr.h"
#include "nsWeakReference.h"
#include "nsAutoPtr.h"
namespace mozilla {
+
class CompositionTransaction;
-} // namespace mozilla
/**
* An aggregate transaction that knows how to absorb all subsequent
* transactions with the same name. This transaction does not "Do" anything.
* But it absorbs other transactions via merge, and can undo/redo the
* transactions it has absorbed.
*/
-class PlaceholderTxn : public EditAggregateTxn,
- public nsIAbsorbingTransaction,
- public nsSupportsWeakReference
+class PlaceholderTransaction final : public EditAggregateTxn,
+ public nsIAbsorbingTransaction,
+ public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS_INHERITED
- PlaceholderTxn();
+ PlaceholderTransaction();
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTxn, EditAggregateTxn)
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
+ EditAggregateTxn)
// ------------ EditAggregateTxn -----------------------
NS_DECL_EDITTXN
NS_IMETHOD RedoTransaction() override;
- NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge) override;
+ NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
// ------------ nsIAbsorbingTransaction -----------------------
NS_IMETHOD Init(nsIAtom* aName, nsSelectionState* aSelState,
nsEditor* aEditor) override;
- NS_IMETHOD GetTxnName(nsIAtom **aName) override;
+ NS_IMETHOD GetTxnName(nsIAtom** aName) override;
- NS_IMETHOD StartSelectionEquals(nsSelectionState *aSelState, bool *aResult) override;
+ NS_IMETHOD StartSelectionEquals(nsSelectionState* aSelState,
+ bool* aResult) override;
NS_IMETHOD EndPlaceHolderBatch() override;
- NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress) override;
+ NS_IMETHOD ForwardEndBatchTo(
+ nsIAbsorbingTransaction* aForwardingAddress) override;
NS_IMETHOD Commit() override;
nsresult RememberEndingSelection();
protected:
- virtual ~PlaceholderTxn();
+ virtual ~PlaceholderTransaction();
- /** the presentation shell, which we'll need to get the selection */
- bool mAbsorb; // do we auto absorb any and all transaction?
- nsWeakPtr mForwarding;
+ // Do we auto absorb any and all transaction?
+ bool mAbsorb;
+ nsWeakPtr mForwarding;
// First IME txn in this placeholder - used for IME merging.
mozilla::CompositionTransaction* mCompositionTransaction;
- // non-owning for now - can't nsCOMPtr it due to broken transaction interfaces
- bool mCommitted; // do we stop auto absorbing any matching placeholder txns?
- // these next two members store the state of the selection in a safe way.
- // selection at the start of the txn is stored, as is the selection at the end.
- // This is so that UndoTransaction() and RedoTransaction() can restore the
- // selection properly.
- nsAutoPtr<nsSelectionState> mStartSel; // use a pointer because this is constructed before we exist
- nsSelectionState mEndSel;
- nsEditor* mEditor; /** the editor for this transaction */
+ // Do we stop auto absorbing any matching placeholder transactions?
+ bool mCommitted;
+
+ // These next two members store the state of the selection in a safe way.
+ // Selection at the start of the transaction is stored, as is the selection
+ // at the end. This is so that UndoTransaction() and RedoTransaction() can
+ // restore the selection properly.
+
+ // Use a pointer because this is constructed before we exist.
+ nsAutoPtr<nsSelectionState> mStartSel;
+ nsSelectionState mEndSel;
+
+ // The editor for this transaction.
+ nsEditor* mEditor;
};
+} // namespace mozilla
-#endif
+#endif // #ifndef PlaceholderTransaction_h
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -47,17 +47,17 @@ UNIFIED_SOURCES += [
'nsPlaintextDataTransfer.cpp',
'nsPlaintextEditor.cpp',
'nsSelectionState.cpp',
'nsStyleSheetTxns.cpp',
'nsTableEditor.cpp',
'nsTextEditRules.cpp',
'nsTextEditRulesBidi.cpp',
'nsWSRunObject.cpp',
- 'PlaceholderTxn.cpp',
+ 'PlaceholderTransaction.cpp',
'SetDocTitleTxn.cpp',
'SplitNodeTxn.cpp',
'TextEditorTest.cpp',
'TextEditUtils.cpp',
'TypeInState.cpp',
]
LOCAL_INCLUDES += [
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -17,17 +17,17 @@
#include "DeleteRangeTransaction.h" // for DeleteRangeTransaction
#include "DeleteTextTransaction.h" // for DeleteTextTransaction
#include "EditAggregateTxn.h" // for EditAggregateTxn
#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 "PlaceholderTxn.h" // for PlaceholderTxn
+#include "PlaceholderTransaction.h" // for PlaceholderTransaction
#include "SplitNodeTxn.h" // for SplitNodeTxn
#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
@@ -667,39 +667,41 @@ nsEditor::GetSelection(SelectionType aSe
return sel->AsSelection();
}
NS_IMETHODIMP
nsEditor::DoTransaction(nsITransaction* aTxn)
{
if (mPlaceHolderBatch && !mPlaceHolderTxn) {
- nsCOMPtr<nsIAbsorbingTransaction> plcTxn = new PlaceholderTxn();
-
- // save off weak reference to placeholder txn
- mPlaceHolderTxn = do_GetWeakReference(plcTxn);
- plcTxn->Init(mPlaceHolderName, mSelState, this);
+ nsCOMPtr<nsIAbsorbingTransaction> placeholderTransaction =
+ new PlaceholderTransaction();
+
+ // Save off weak reference to placeholder transaction
+ mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
+ placeholderTransaction->Init(mPlaceHolderName, mSelState, this);
// placeholder txn took ownership of this pointer
mSelState = nullptr;
// QI to an nsITransaction since that's what DoTransaction() expects
- nsCOMPtr<nsITransaction> theTxn = do_QueryInterface(plcTxn);
- // we will recurse, but will not hit this case in the nested call
- DoTransaction(theTxn);
+ nsCOMPtr<nsITransaction> transaction =
+ do_QueryInterface(placeholderTransaction);
+ // We will recurse, but will not hit this case in the nested call
+ DoTransaction(transaction);
if (mTxnMgr) {
nsCOMPtr<nsITransaction> topTxn = mTxnMgr->PeekUndoStack();
if (topTxn) {
- plcTxn = do_QueryInterface(topTxn);
- if (plcTxn) {
+ placeholderTransaction = do_QueryInterface(topTxn);
+ if (placeholderTransaction) {
// there is a placeholder transaction on top of the undo stack. It
// is either the one we just created, or an earlier one that we are
// now merging into. From here on out remember this placeholder
// instead of the one we just created.
- mPlaceHolderTxn = do_GetWeakReference(plcTxn);
+ mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
}
}
}
}
if (aTxn) {
// XXX: Why are we doing selection specific batching stuff here?
// XXX: Most entry points into the editor have auto variables that