Bug 1260651 part.27 Rename PlaceholderTxn to mozilla::PlaceholderTransaction (and their files too) r=mccr8

MozReview-Commit-ID: F6DeWadjTmP

--HG--
rename : editor/libeditor/PlaceholderTxn.cpp => editor/libeditor/PlaceholderTransaction.cpp
rename : editor/libeditor/PlaceholderTxn.h => editor/libeditor/PlaceholderTransaction.h
This commit is contained in:
Masayuki Nakano 2016-07-07 16:27:23 +09:00
Родитель 658478a3fc
Коммит 9a3758b103
5 изменённых файлов: 148 добавлений и 121 удалений

Просмотреть файл

@ -3,7 +3,7 @@
* 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"
@ -11,10 +11,11 @@
#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)
@ -23,13 +24,13 @@ PlaceholderTxn::PlaceholderTxn()
{
}
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);
@ -37,7 +38,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PlaceholderTxn,
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);
@ -45,16 +46,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PlaceholderTxn,
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,
PlaceholderTransaction::Init(nsIAtom* aName,
nsSelectionState* aSelState,
nsEditor* aEditor)
{
NS_ENSURE_TRUE(aEditor && aSelState, NS_ERROR_NULL_POINTER);
@ -65,12 +67,14 @@ PlaceholderTxn::Init(nsIAtom* aName, nsSelectionState* aSelState,
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();
@ -84,8 +88,8 @@ NS_IMETHODIMP PlaceholderTxn::UndoTransaction(void)
return mStartSel->RestoreSelection(selection);
}
NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void)
NS_IMETHODIMP
PlaceholderTransaction::RedoTransaction()
{
// redo txns
nsresult res = EditAggregateTxn::RedoTransaction();
@ -98,7 +102,9 @@ NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void)
}
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);
@ -193,9 +199,10 @@ NS_IMETHODIMP PlaceholderTxn::Merge(nsITransaction *aTransaction, bool *aDidMerg
return NS_OK;
}
NS_IMETHODIMP PlaceholderTxn::GetTxnDescription(nsAString& aString)
NS_IMETHODIMP
PlaceholderTransaction::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("PlaceholderTxn: ");
aString.AssignLiteral("PlaceholderTransaction: ");
if (mName)
{
@ -207,12 +214,15 @@ NS_IMETHODIMP PlaceholderTxn::GetTxnDescription(nsAString& aString)
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.
@ -226,7 +236,8 @@ NS_IMETHODIMP PlaceholderTxn::StartSelectionEquals(nsSelectionState *aSelState,
return NS_OK;
}
NS_IMETHODIMP PlaceholderTxn::EndPlaceHolderBatch()
NS_IMETHODIMP
PlaceholderTransaction::EndPlaceHolderBatch()
{
mAbsorb = false;
@ -240,19 +251,23 @@ NS_IMETHODIMP PlaceholderTxn::EndPlaceHolderBatch()
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);
@ -260,3 +275,4 @@ nsresult PlaceholderTxn::RememberEndingSelection()
return NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -0,0 +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 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;
/**
* 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 PlaceholderTransaction final : public EditAggregateTxn,
public nsIAbsorbingTransaction,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS_INHERITED
PlaceholderTransaction();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
EditAggregateTxn)
// ------------ EditAggregateTxn -----------------------
NS_DECL_EDITTXN
NS_IMETHOD RedoTransaction() 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 StartSelectionEquals(nsSelectionState* aSelState,
bool* aResult) override;
NS_IMETHOD EndPlaceHolderBatch() override;
NS_IMETHOD ForwardEndBatchTo(
nsIAbsorbingTransaction* aForwardingAddress) override;
NS_IMETHOD Commit() override;
nsresult RememberEndingSelection();
protected:
virtual ~PlaceholderTransaction();
// 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;
// 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 // #ifndef PlaceholderTransaction_h

Просмотреть файл

@ -1,83 +0,0 @@
/* -*- 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__
#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
{
public:
NS_DECL_ISUPPORTS_INHERITED
PlaceholderTxn();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTxn, EditAggregateTxn)
// ------------ EditAggregateTxn -----------------------
NS_DECL_EDITTXN
NS_IMETHOD RedoTransaction() 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 StartSelectionEquals(nsSelectionState *aSelState, bool *aResult) override;
NS_IMETHOD EndPlaceHolderBatch() override;
NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress) override;
NS_IMETHOD Commit() override;
nsresult RememberEndingSelection();
protected:
virtual ~PlaceholderTxn();
/** the presentation shell, which we'll need to get the selection */
bool mAbsorb; // do we auto absorb any and all transaction?
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 */
};
#endif

Просмотреть файл

@ -52,7 +52,7 @@ UNIFIED_SOURCES += [
'nsTextEditRules.cpp',
'nsTextEditRulesBidi.cpp',
'nsWSRunObject.cpp',
'PlaceholderTxn.cpp',
'PlaceholderTransaction.cpp',
'SetDocTitleTxn.cpp',
'SplitNodeTxn.cpp',
'TextEditorTest.cpp',

Просмотреть файл

@ -22,7 +22,7 @@
#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
@ -672,29 +672,31 @@ NS_IMETHODIMP
nsEditor::DoTransaction(nsITransaction* aTxn)
{
if (mPlaceHolderBatch && !mPlaceHolderTxn) {
nsCOMPtr<nsIAbsorbingTransaction> plcTxn = new PlaceholderTxn();
nsCOMPtr<nsIAbsorbingTransaction> placeholderTransaction =
new PlaceholderTransaction();
// save off weak reference to placeholder txn
mPlaceHolderTxn = do_GetWeakReference(plcTxn);
plcTxn->Init(mPlaceHolderName, mSelState, this);
// 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);
}
}
}