2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-01-06 23:30:13 +03:00
|
|
|
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/EditTransactionBase.h"
|
2020-04-23 08:46:43 +03:00
|
|
|
|
2021-04-05 14:35:48 +03:00
|
|
|
#include "mozilla/Logging.h"
|
|
|
|
|
2020-04-23 08:46:43 +03:00
|
|
|
#include "ChangeAttributeTransaction.h"
|
|
|
|
#include "ChangeStyleTransaction.h"
|
|
|
|
#include "CompositionTransaction.h"
|
|
|
|
#include "DeleteNodeTransaction.h"
|
|
|
|
#include "DeleteRangeTransaction.h"
|
|
|
|
#include "DeleteTextTransaction.h"
|
|
|
|
#include "EditAggregateTransaction.h"
|
|
|
|
#include "InsertNodeTransaction.h"
|
|
|
|
#include "InsertTextTransaction.h"
|
2022-03-01 02:03:51 +03:00
|
|
|
#include "JoinNodesTransaction.h"
|
Bug 1766355 - part 1: Add `MoveNodeTransaction` to handle delete node and insert node in a transaction class instance r=m_kato
Creating both `DeleteNodeTransaction` and `InsertNodeTransaction` wastes
memory. They should be done in an instance instead.
Fortunately, no edit action listener checks whether the deleted node is still
in the composed document or not, etc. Therefore, we can simply notify them of
both deletion and insertion which were done in
`EditorBase::InsertNodeWithTransaction` and
`EditorBase::DeleteNodeWithTransaction`. Note that previously, the range
updater needs to ignore the notifications from them while the node is being
moved. However, it does not require anymore. Therefore, this patch makes it
stop locking, and that would fix minor problem in the case of legacy mutation
event listeners run another edit action.
On the other hand, this changes some edge cases handling of
`MoveNodeWithTransaction` which are detected by the WPT. According to the
previous result of applying this patch, `nsINode::InsertBefore` fails and that
leads some errors at updating the changed range. I guess that the cause is
that there is some bugs at updating insertion point after deleting the node from
the DOM tree around here:
https://searchfox.org/mozilla-central/rev/0ffae75b690219858e5a45a39f8759a8aee7b9a2/editor/libeditor/HTMLEditor.cpp#5058-5071
However, it's safely fixed by the new code which does not remove the node from
the DOM tree explicitly. So, I think that it's safe to accept this behavior
change for web apps in the wild.
Differential Revision: https://phabricator.services.mozilla.com/D146397
2022-05-20 11:28:08 +03:00
|
|
|
#include "MoveNodeTransaction.h"
|
2020-04-23 08:46:43 +03:00
|
|
|
#include "PlaceholderTransaction.h"
|
2020-05-21 05:30:09 +03:00
|
|
|
#include "ReplaceTextTransaction.h"
|
2020-04-23 08:46:43 +03:00
|
|
|
#include "SplitNodeTransaction.h"
|
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISupportsBase.h"
|
1999-01-06 23:30:13 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
namespace mozilla {
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(EditTransactionBase)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(EditTransactionBase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EditTransactionBase)
|
2013-02-07 14:19:08 +04:00
|
|
|
// We don't have anything to traverse, but some of our subclasses do.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2009-05-09 08:59:25 +04:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditTransactionBase)
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransaction)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITransaction)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(EditTransactionBase)
|
2017-12-18 12:08:43 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(EditTransactionBase)
|
1999-01-06 23:30:13 +03:00
|
|
|
|
2021-04-05 14:35:48 +03:00
|
|
|
NS_IMETHODIMP EditTransactionBase::RedoTransaction() {
|
|
|
|
MOZ_LOG(GetLogModule(), LogLevel::Info, ("%p %s", this, __FUNCTION__));
|
|
|
|
return DoTransaction();
|
|
|
|
}
|
1999-01-06 23:30:13 +03:00
|
|
|
|
2020-03-22 13:46:39 +03:00
|
|
|
NS_IMETHODIMP EditTransactionBase::GetIsTransient(bool* aIsTransient) {
|
2021-04-05 14:35:48 +03:00
|
|
|
MOZ_LOG(GetLogModule(), LogLevel::Verbose,
|
|
|
|
("%p %s returned false", this, __FUNCTION__));
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsTransient = false;
|
1999-01-06 23:30:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-23 10:02:16 +03:00
|
|
|
NS_IMETHODIMP EditTransactionBase::Merge(nsITransaction* aOtherTransaction,
|
2020-03-22 13:46:39 +03:00
|
|
|
bool* aDidMerge) {
|
2021-04-05 14:35:48 +03:00
|
|
|
MOZ_LOG(GetLogModule(), LogLevel::Info,
|
|
|
|
("%p %s(aOtherTransaction=%p) returned false", this, __FUNCTION__,
|
|
|
|
aOtherTransaction));
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDidMerge = false;
|
1999-09-22 02:31:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-07-08 03:48:34 +03:00
|
|
|
|
2021-04-05 14:35:48 +03:00
|
|
|
// static
|
|
|
|
LogModule* EditTransactionBase::GetLogModule() {
|
|
|
|
static LazyLogModule sLog("EditorTransaction");
|
|
|
|
return static_cast<LogModule*>(sLog);
|
|
|
|
}
|
|
|
|
|
2020-04-23 08:46:43 +03:00
|
|
|
#define NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(aClass) \
|
|
|
|
aClass* EditTransactionBase::GetAs##aClass() { return nullptr; } \
|
|
|
|
const aClass* EditTransactionBase::GetAs##aClass() const { return nullptr; }
|
|
|
|
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(ChangeAttributeTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(ChangeStyleTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(CompositionTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(DeleteNodeTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(DeleteRangeTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(DeleteTextTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(EditAggregateTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(InsertNodeTransaction)
|
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(InsertTextTransaction)
|
2022-03-01 02:03:51 +03:00
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(JoinNodesTransaction)
|
Bug 1766355 - part 1: Add `MoveNodeTransaction` to handle delete node and insert node in a transaction class instance r=m_kato
Creating both `DeleteNodeTransaction` and `InsertNodeTransaction` wastes
memory. They should be done in an instance instead.
Fortunately, no edit action listener checks whether the deleted node is still
in the composed document or not, etc. Therefore, we can simply notify them of
both deletion and insertion which were done in
`EditorBase::InsertNodeWithTransaction` and
`EditorBase::DeleteNodeWithTransaction`. Note that previously, the range
updater needs to ignore the notifications from them while the node is being
moved. However, it does not require anymore. Therefore, this patch makes it
stop locking, and that would fix minor problem in the case of legacy mutation
event listeners run another edit action.
On the other hand, this changes some edge cases handling of
`MoveNodeWithTransaction` which are detected by the WPT. According to the
previous result of applying this patch, `nsINode::InsertBefore` fails and that
leads some errors at updating the changed range. I guess that the cause is
that there is some bugs at updating insertion point after deleting the node from
the DOM tree around here:
https://searchfox.org/mozilla-central/rev/0ffae75b690219858e5a45a39f8759a8aee7b9a2/editor/libeditor/HTMLEditor.cpp#5058-5071
However, it's safely fixed by the new code which does not remove the node from
the DOM tree explicitly. So, I think that it's safe to accept this behavior
change for web apps in the wild.
Differential Revision: https://phabricator.services.mozilla.com/D146397
2022-05-20 11:28:08 +03:00
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(MoveNodeTransaction)
|
2020-04-23 08:46:43 +03:00
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(PlaceholderTransaction)
|
2020-05-21 05:30:09 +03:00
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(ReplaceTextTransaction)
|
2020-04-23 08:46:43 +03:00
|
|
|
NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS(SplitNodeTransaction)
|
|
|
|
|
|
|
|
#undef NS_IMPL_EDITTRANSACTIONBASE_GETASMETHODS
|
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
} // namespace mozilla
|