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-03-15 03:57:32 +03:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
#include "PlaceholderTransaction.h"
|
2016-07-07 09:42:08 +03:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2016-07-07 09:42:08 +03:00
|
|
|
#include "CompositionTransaction.h"
|
2016-07-08 07:10:13 +03:00
|
|
|
#include "mozilla/EditorBase.h"
|
2016-07-07 09:42:08 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2008-03-13 21:54:01 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2012-07-23 14:27:22 +04:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
namespace mozilla {
|
1999-03-15 03:57:32 +03:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
using namespace dom;
|
|
|
|
|
2017-02-09 08:26:10 +03:00
|
|
|
PlaceholderTransaction::PlaceholderTransaction(
|
2020-04-23 13:46:55 +03:00
|
|
|
EditorBase& aEditorBase, nsStaticAtom& aName,
|
|
|
|
Maybe<SelectionState>&& aSelState)
|
2017-12-18 12:08:43 +03:00
|
|
|
: mEditorBase(&aEditorBase),
|
2016-07-07 09:42:08 +03:00
|
|
|
mCompositionTransaction(nullptr),
|
2018-05-30 22:15:35 +03:00
|
|
|
mStartSel(*std::move(aSelState)),
|
2017-12-18 12:08:43 +03:00
|
|
|
mAbsorb(true),
|
2016-07-07 09:42:08 +03:00
|
|
|
mCommitted(false) {
|
2020-04-23 13:46:55 +03:00
|
|
|
mName = &aName;
|
1999-03-15 03:57:32 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(PlaceholderTransaction)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PlaceholderTransaction,
|
2016-07-07 11:11:30 +03:00
|
|
|
EditAggregateTransaction)
|
2017-03-21 13:00:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditorBase);
|
2017-07-29 09:43:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStartSel);
|
2016-03-05 01:11:37 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEndSel);
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PlaceholderTransaction,
|
2016-07-07 11:11:30 +03:00
|
|
|
EditAggregateTransaction)
|
2017-03-21 13:00:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditorBase);
|
2017-07-29 09:43:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartSel);
|
2016-03-05 01:11:37 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndSel);
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PlaceholderTransaction)
|
2016-07-07 11:11:30 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
|
2009-05-09 08:59:25 +04:00
|
|
|
|
2016-07-07 11:11:30 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
|
1999-09-30 00:08:15 +04:00
|
|
|
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_IMETHODIMP PlaceholderTransaction::DoTransaction() { return NS_OK; }
|
1999-03-15 03:57:32 +03:00
|
|
|
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_IMETHODIMP PlaceholderTransaction::UndoTransaction() {
|
2017-03-21 13:00:36 +03:00
|
|
|
if (NS_WARN_IF(!mEditorBase)) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2016-07-07 11:11:30 +03:00
|
|
|
// Undo transactions.
|
|
|
|
nsresult rv = EditAggregateTransaction::UndoTransaction();
|
2020-03-11 05:11:52 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("EditAggregateTransaction::UndoTransaction() failed");
|
|
|
|
return rv;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2000-01-31 13:30:12 +03:00
|
|
|
// now restore selection
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
2020-03-11 05:11:52 +03:00
|
|
|
if (NS_WARN_IF(!selection)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2020-03-16 12:57:58 +03:00
|
|
|
rv = mStartSel.RestoreSelection(*selection);
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SelectionState::RestoreSelection() failed");
|
|
|
|
return rv;
|
2000-01-31 13:30:12 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_IMETHODIMP PlaceholderTransaction::RedoTransaction() {
|
2017-03-21 13:00:36 +03:00
|
|
|
if (NS_WARN_IF(!mEditorBase)) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2016-07-07 11:11:30 +03:00
|
|
|
// Redo transactions.
|
|
|
|
nsresult rv = EditAggregateTransaction::RedoTransaction();
|
2020-03-11 05:11:52 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("EditAggregateTransaction::RedoTransaction() failed");
|
|
|
|
return rv;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2000-01-31 13:30:12 +03:00
|
|
|
// now restore selection
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
2020-03-11 05:11:52 +03:00
|
|
|
if (NS_WARN_IF(!selection)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2020-03-16 12:57:58 +03:00
|
|
|
rv = mEndSel.RestoreSelection(*selection);
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SelectionState::RestoreSelection() failed");
|
|
|
|
return rv;
|
1999-09-30 00:08:15 +04:00
|
|
|
}
|
|
|
|
|
2020-04-23 10:02:16 +03:00
|
|
|
NS_IMETHODIMP PlaceholderTransaction::Merge(nsITransaction* aOtherTransaction,
|
2020-03-11 05:11:52 +03:00
|
|
|
bool* aDidMerge) {
|
2020-04-23 10:02:16 +03:00
|
|
|
if (NS_WARN_IF(!aDidMerge) || NS_WARN_IF(!aOtherTransaction)) {
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-09-30 00:08:15 +04:00
|
|
|
|
1999-03-15 03:57:32 +03:00
|
|
|
// set out param default value
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDidMerge = false;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2020-04-23 13:46:55 +03:00
|
|
|
if (mForwardingTransaction) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"tried to merge into a placeholder that was in "
|
|
|
|
"forwarding mode!");
|
1999-09-30 00:08:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-04-23 10:02:16 +03:00
|
|
|
RefPtr<EditTransactionBase> otherTransactionBase =
|
|
|
|
aOtherTransaction->GetAsEditTransactionBase();
|
|
|
|
if (!otherTransactionBase) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-09 03:06:38 +04:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
// We are absorbing all transactions if mAbsorb is lit.
|
|
|
|
if (mAbsorb) {
|
2020-04-23 13:46:55 +03:00
|
|
|
if (CompositionTransaction* otherCompositionTransaction =
|
|
|
|
otherTransactionBase->GetAsCompositionTransaction()) {
|
2016-07-07 09:42:08 +03:00
|
|
|
// special handling for CompositionTransaction's: they need to merge with
|
|
|
|
// any previous CompositionTransaction in this placeholder, if possible.
|
|
|
|
if (!mCompositionTransaction) {
|
1999-10-26 22:54:47 +04:00
|
|
|
// this is the first IME txn in the placeholder
|
2020-04-23 10:02:16 +03:00
|
|
|
mCompositionTransaction = otherCompositionTransaction;
|
|
|
|
DebugOnly<nsresult> rvIgnored =
|
|
|
|
AppendChild(otherCompositionTransaction);
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rvIgnored),
|
|
|
|
"EditAggregateTransaction::AppendChild() failed, but ignored");
|
2016-07-07 09:42:08 +03:00
|
|
|
} else {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didMerge;
|
2020-04-23 10:02:16 +03:00
|
|
|
mCompositionTransaction->Merge(otherCompositionTransaction, &didMerge);
|
2016-07-07 09:42:08 +03:00
|
|
|
if (!didMerge) {
|
2007-11-10 07:24:42 +03:00
|
|
|
// it wouldn't merge. Earlier IME txn is already committed and will
|
2002-10-09 03:06:38 +04:00
|
|
|
// not absorb further IME txns. So just stack this one after it
|
|
|
|
// and remember it as a candidate for further merges.
|
2020-04-23 10:02:16 +03:00
|
|
|
mCompositionTransaction = otherCompositionTransaction;
|
|
|
|
DebugOnly<nsresult> rvIgnored =
|
|
|
|
AppendChild(otherCompositionTransaction);
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rvIgnored),
|
|
|
|
"EditAggregateTransaction::AppendChild() failed, but ignored");
|
1999-10-26 22:54:47 +04:00
|
|
|
}
|
|
|
|
}
|
2020-03-11 05:11:52 +03:00
|
|
|
} else {
|
2020-04-23 13:46:55 +03:00
|
|
|
PlaceholderTransaction* otherPlaceholderTransaction =
|
|
|
|
otherTransactionBase->GetAsPlaceholderTransaction();
|
|
|
|
if (!otherPlaceholderTransaction) {
|
2020-03-11 05:11:52 +03:00
|
|
|
// See bug 171243: just drop incoming placeholders on the floor.
|
|
|
|
// Their children will be swallowed by this preexisting one.
|
2020-04-23 10:02:16 +03:00
|
|
|
DebugOnly<nsresult> rvIgnored = AppendChild(otherTransactionBase);
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rvIgnored),
|
|
|
|
"EditAggregateTransaction::AppendChild() failed, but ignored");
|
|
|
|
}
|
1999-10-26 22:54:47 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDidMerge = true;
|
2000-01-31 13:30:12 +03:00
|
|
|
// RememberEndingSelection();
|
2015-05-28 18:58:42 +03:00
|
|
|
// efficiency hack: no need to remember selection here, as we haven't yet
|
2007-11-11 05:43:32 +03:00
|
|
|
// finished the initial batch and we know we will be told when the batch
|
2000-01-31 13:30:12 +03:00
|
|
|
// ends. we can remeber the selection then.
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge typing or IME or deletion transactions if the selection matches
|
2020-04-23 13:46:55 +03:00
|
|
|
if (mCommitted ||
|
|
|
|
(mName != nsGkAtoms::TypingTxnName && mName != nsGkAtoms::IMETxnName &&
|
|
|
|
mName != nsGkAtoms::DeleteTxnName)) {
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:46:55 +03:00
|
|
|
PlaceholderTransaction* otherPlaceholderTransaction =
|
|
|
|
otherTransactionBase->GetAsPlaceholderTransaction();
|
|
|
|
if (!otherPlaceholderTransaction) {
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_OK;
|
1999-03-15 03:57:32 +03:00
|
|
|
}
|
2020-03-11 05:11:52 +03:00
|
|
|
|
|
|
|
RefPtr<nsAtom> otherTransactionName;
|
2020-04-23 13:46:55 +03:00
|
|
|
DebugOnly<nsresult> rvIgnored = otherPlaceholderTransaction->GetName(
|
2020-04-23 10:02:16 +03:00
|
|
|
getter_AddRefs(otherTransactionName));
|
2020-04-23 13:46:55 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
|
|
|
"PlaceholderTransaction::GetName() failed, but ignored");
|
|
|
|
if (!otherTransactionName || otherTransactionName == nsGkAtoms::_empty ||
|
|
|
|
otherTransactionName != mName) {
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// check if start selection of next placeholder matches
|
|
|
|
// end selection of this placeholder
|
2020-04-23 13:46:55 +03:00
|
|
|
if (!otherPlaceholderTransaction->StartSelectionEquals(mEndSel)) {
|
2020-03-11 05:11:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mAbsorb = true; // we need to start absorbing again
|
2020-04-23 13:46:55 +03:00
|
|
|
otherPlaceholderTransaction->ForwardEndBatchTo(*this);
|
2020-03-11 05:11:52 +03:00
|
|
|
// AppendChild(editTransactionBase);
|
|
|
|
// see bug 171243: we don't need to merge placeholders
|
|
|
|
// into placeholders. We just reactivate merging in the
|
|
|
|
// pre-existing placeholder and drop the new one on the floor. The
|
|
|
|
// EndPlaceHolderBatch() call on the new placeholder will be
|
|
|
|
// forwarded to this older one.
|
|
|
|
rvIgnored = RememberEndingSelection();
|
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rvIgnored),
|
|
|
|
"PlaceholderTransaction::RememberEndingSelection() failed, but "
|
|
|
|
"ignored");
|
|
|
|
*aDidMerge = true;
|
2003-06-30 18:46:41 +04:00
|
|
|
return NS_OK;
|
1999-09-30 00:08:15 +04:00
|
|
|
}
|
|
|
|
|
2020-04-23 13:46:55 +03:00
|
|
|
bool PlaceholderTransaction::StartSelectionEquals(
|
|
|
|
SelectionState& aSelectionState) {
|
2000-01-31 13:30:12 +03:00
|
|
|
// determine if starting selection matches the given selection state.
|
|
|
|
// note that we only care about collapsed selections.
|
2020-03-11 05:11:52 +03:00
|
|
|
return mStartSel.IsCollapsed() && aSelectionState.IsCollapsed() &&
|
2020-03-16 12:57:58 +03:00
|
|
|
mStartSel.Equals(aSelectionState);
|
1999-09-30 00:08:15 +04:00
|
|
|
}
|
|
|
|
|
2020-04-23 13:46:55 +03:00
|
|
|
nsresult PlaceholderTransaction::EndPlaceHolderBatch() {
|
2011-10-17 18:59:28 +04:00
|
|
|
mAbsorb = false;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2020-04-23 13:46:55 +03:00
|
|
|
if (mForwardingTransaction) {
|
|
|
|
if (mForwardingTransaction) {
|
2020-03-11 05:11:52 +03:00
|
|
|
DebugOnly<nsresult> rvIgnored =
|
2020-04-23 13:46:55 +03:00
|
|
|
mForwardingTransaction->EndPlaceHolderBatch();
|
2020-03-11 05:11:52 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rvIgnored),
|
2020-04-23 13:46:55 +03:00
|
|
|
"PlaceholderTransaction::EndPlaceHolderBatch() failed, but ignored");
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
1999-09-30 00:08:15 +04:00
|
|
|
}
|
2000-01-31 13:30:12 +03:00
|
|
|
// remember our selection state.
|
2020-03-11 05:11:52 +03:00
|
|
|
nsresult rv = RememberEndingSelection();
|
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"PlaceholderTransaction::RememberEndingSelection() failed");
|
|
|
|
return rv;
|
2003-09-08 02:05:34 +04:00
|
|
|
}
|
1999-09-30 00:08:15 +04:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
nsresult PlaceholderTransaction::RememberEndingSelection() {
|
2017-03-21 13:00:36 +03:00
|
|
|
if (NS_WARN_IF(!mEditorBase)) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
2020-03-11 05:11:52 +03:00
|
|
|
if (NS_WARN_IF(!selection)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2020-03-16 12:57:58 +03:00
|
|
|
mEndSel.SaveSelection(*selection);
|
2012-07-23 14:27:22 +04:00
|
|
|
return NS_OK;
|
2000-01-31 13:30:12 +03:00
|
|
|
}
|
1999-09-30 00:08:15 +04:00
|
|
|
|
2016-07-07 10:27:23 +03:00
|
|
|
} // namespace mozilla
|