From c654c8ee3144453284f4bc597dcf8352374f367e Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 10 Jun 2019 10:26:04 +0000 Subject: [PATCH] Bug 1529884 - part 5: Make Document::ExecCommand() use EditorCommand directly as far as possible r=smaug Most commands are dispatched only when the `document` has `contenteditable` or in `designMode`. In such case, command context is considered with the following order: 1. `HTMLEditor` for the document. 2. `TextEditor` if the document has focus and it has `TextEditor`. 3. Other command controller table associated with window or DocShell. In the case of #1 and #2, `ExecCommand()` can use `EditorCommand` directly and we only need to send subject principal to the editor only in these cases. In the case of #3, we need to fall back to traditional path. There are 2 paths: 1. If it's "paste" command, handle it with `nsCommandManager` to dispatch "paste" event. 2. If it's "cur" or "copy", handle it with `DocShell` to dispatch "cut" or "copy" event in the window or focused sub-document. Note that clipboard "cut" and "copy" commands are special cases. Only them were handled by `DocShell` instead of `nsCommandManager` This difference caused making active element's `TextEditor` is preferred rather than `HTMLEditor`. Although this behavior is better than our traditional behavior because Chromium works as so. But for now, we should keep our behavior. Finally, this patch makes `ExecCommand()` creates `nsCommandParams` instance since now, `EditorCommand` class can take only necessary parameter without it. Differential Revision: https://phabricator.services.mozilla.com/D29632 --- dom/base/Document.cpp | 224 ++++++++++++++++++++++++------------ dom/base/nsContentUtils.cpp | 34 ++++++ dom/base/nsContentUtils.h | 10 ++ 3 files changed, 195 insertions(+), 73 deletions(-) diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 4e46b84b20925..b9b5ab2d9eeb1 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -32,6 +32,7 @@ #include "mozilla/RestyleManager.h" #include "mozilla/StaticPrefs.h" #include "mozilla/StorageAccess.h" +#include "mozilla/TextEditor.h" #include "mozilla/URLExtraData.h" #include @@ -44,9 +45,6 @@ #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsILoadContext.h" -#include "nsIEditor.h" -#include "nsIEditorStyleSheets.h" -#include "nsIPlaintextEditor.h" #include "nsITextControlFrame.h" #include "nsCommandManager.h" #include "nsCommandParams.h" @@ -4304,95 +4302,175 @@ bool Document::ExecCommand(const nsAString& commandID, bool doShowUI, } } - // special case for cut & copy - // cut & copy are allowed in non editable documents + // Next, consider context of command handling which is automatically resolved + // by order of controllers in `nsCommandManager::GetControllerForCommand()`. + // The order is: + // 1. HTMLEditor for the document, if there is. + // 2. TextEditor if there is an active element and it has TextEditor like + // or