2004-09-08 01:21:48 +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/. */
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
#include "mozilla/WritingModes.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
#include "NativeKeyBindings.h"
|
2004-09-08 01:21:48 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsGtkKeyUtils.h"
|
|
|
|
|
2009-01-03 10:37:52 +03:00
|
|
|
#include <gtk/gtk.h>
|
2004-09-08 01:21:48 +04:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
#include <gdk/gdkkeysyms-compat.h>
|
2009-01-03 10:37:52 +03:00
|
|
|
#include <gdk/gdk.h>
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
static nsTArray<CommandInt>* gCurrentCommands = nullptr;
|
|
|
|
static bool gHandled = false;
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2019-04-30 07:23:24 +03:00
|
|
|
inline void AddCommand(Command aCommand) {
|
|
|
|
MOZ_ASSERT(gCurrentCommands);
|
|
|
|
gCurrentCommands->AppendElement(static_cast<CommandInt>(aCommand));
|
|
|
|
}
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
// Common GtkEntry and GtkTextView signals
|
|
|
|
static void copy_clipboard_cb(GtkWidget* w, gpointer user_data) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::Copy);
|
2004-09-08 01:21:48 +04:00
|
|
|
g_signal_stop_emission_by_name(w, "copy_clipboard");
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = true;
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cut_clipboard_cb(GtkWidget* w, gpointer user_data) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::Cut);
|
2004-09-08 01:21:48 +04:00
|
|
|
g_signal_stop_emission_by_name(w, "cut_clipboard");
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = true;
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GTK distinguishes between display lines (wrapped, as they appear on the
|
|
|
|
// screen) and paragraphs, which are runs of text terminated by a newline.
|
|
|
|
// We don't have this distinction, so we always use editor's notion of
|
|
|
|
// lines, which are newline-terminated.
|
|
|
|
|
2014-03-14 17:13:30 +04:00
|
|
|
static const Command sDeleteCommands[][2] = {
|
2004-09-08 01:21:48 +04:00
|
|
|
// backward, forward
|
2019-04-30 07:23:24 +03:00
|
|
|
// CHARS
|
|
|
|
{Command::DeleteCharBackward, Command::DeleteCharForward},
|
|
|
|
// WORD_ENDS
|
|
|
|
{Command::DeleteWordBackward, Command::DeleteWordForward},
|
|
|
|
// WORDS
|
|
|
|
{Command::DeleteWordBackward, Command::DeleteWordForward},
|
|
|
|
// LINES
|
|
|
|
{Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
|
|
|
|
// LINE_ENDS
|
|
|
|
{Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
|
|
|
|
// PARAGRAPH_ENDS
|
|
|
|
{Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
|
|
|
|
// PARAGRAPHS
|
|
|
|
{Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
|
2004-09-08 01:21:48 +04:00
|
|
|
// This deletes from the end of the previous word to the beginning of the
|
|
|
|
// next word, but only if the caret is not in a word.
|
|
|
|
// XXX need to implement in editor
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::DoNothing, Command::DoNothing} // WHITESPACE
|
2004-09-08 01:21:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void delete_from_cursor_cb(GtkWidget* w, GtkDeleteType del_type,
|
|
|
|
gint count, gpointer user_data) {
|
|
|
|
g_signal_stop_emission_by_name(w, "delete_from_cursor");
|
2017-06-21 03:03:09 +03:00
|
|
|
if (count == 0) {
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forward = count > 0;
|
2015-09-24 22:37:08 +03:00
|
|
|
|
|
|
|
// Ignore GTK's Ctrl-K keybinding introduced in GTK 3.14 and removed in
|
|
|
|
// 3.18 if the user has custom bindings set. See bug 1176929.
|
|
|
|
if (del_type == GTK_DELETE_PARAGRAPH_ENDS && forward && GTK_IS_ENTRY(w) &&
|
|
|
|
!gtk_check_version(3, 14, 1) && gtk_check_version(3, 17, 9)) {
|
|
|
|
GtkStyleContext* context = gtk_widget_get_style_context(w);
|
|
|
|
GtkStateFlags flags = gtk_widget_get_state_flags(w);
|
|
|
|
|
|
|
|
GPtrArray* array;
|
|
|
|
gtk_style_context_get(context, flags, "gtk-key-bindings", &array, nullptr);
|
|
|
|
if (!array) return;
|
|
|
|
g_ptr_array_unref(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
gHandled = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (uint32_t(del_type) >= ArrayLength(sDeleteCommands)) {
|
2004-09-08 01:21:48 +04:00
|
|
|
// unsupported deletion type
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (del_type == GTK_DELETE_WORDS) {
|
|
|
|
// This works like word_ends, except we first move the caret to the
|
|
|
|
// beginning/end of the current word.
|
|
|
|
if (forward) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::WordNext);
|
|
|
|
AddCommand(Command::WordPrevious);
|
2004-09-08 01:21:48 +04:00
|
|
|
} else {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::WordPrevious);
|
|
|
|
AddCommand(Command::WordNext);
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
} else if (del_type == GTK_DELETE_DISPLAY_LINES ||
|
|
|
|
del_type == GTK_DELETE_PARAGRAPHS) {
|
|
|
|
// This works like display_line_ends, except we first move the caret to the
|
|
|
|
// beginning/end of the current line.
|
|
|
|
if (forward) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::BeginLine);
|
2004-09-08 01:21:48 +04:00
|
|
|
} else {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::EndLine);
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:30 +04:00
|
|
|
Command command = sDeleteCommands[del_type][forward];
|
2019-04-30 07:23:24 +03:00
|
|
|
if (command == Command::DoNothing) {
|
|
|
|
return;
|
2014-03-14 17:13:30 +04:00
|
|
|
}
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2013-03-06 03:43:53 +04:00
|
|
|
unsigned int absCount = Abs(count);
|
|
|
|
for (unsigned int i = 0; i < absCount; ++i) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(command);
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:30 +04:00
|
|
|
static const Command sMoveCommands[][2][2] = {
|
2004-09-08 01:21:48 +04:00
|
|
|
// non-extend { backward, forward }, extend { backward, forward }
|
|
|
|
// GTK differentiates between logical position, which is prev/next,
|
|
|
|
// and visual position, which is always left/right.
|
|
|
|
// We should fix this to work the same way for RTL text input.
|
|
|
|
{// LOGICAL_POSITIONS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::CharPrevious, Command::CharNext},
|
|
|
|
{Command::SelectCharPrevious, Command::SelectCharNext}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// VISUAL_POSITIONS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::CharPrevious, Command::CharNext},
|
|
|
|
{Command::SelectCharPrevious, Command::SelectCharNext}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// WORDS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::WordPrevious, Command::WordNext},
|
|
|
|
{Command::SelectWordPrevious, Command::SelectWordNext}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// DISPLAY_LINES
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::LinePrevious, Command::LineNext},
|
|
|
|
{Command::SelectLinePrevious, Command::SelectLineNext}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// DISPLAY_LINE_ENDS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::BeginLine, Command::EndLine},
|
|
|
|
{Command::SelectBeginLine, Command::SelectEndLine}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// PARAGRAPHS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::LinePrevious, Command::LineNext},
|
|
|
|
{Command::SelectLinePrevious, Command::SelectLineNext}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// PARAGRAPH_ENDS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::BeginLine, Command::EndLine},
|
|
|
|
{Command::SelectBeginLine, Command::SelectEndLine}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// PAGES
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::MovePageUp, Command::MovePageDown},
|
|
|
|
{Command::SelectPageUp, Command::SelectPageDown}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// BUFFER_ENDS
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::MoveTop, Command::MoveBottom},
|
|
|
|
{Command::SelectTop, Command::SelectBottom}},
|
2004-09-08 01:21:48 +04:00
|
|
|
{// HORIZONTAL_PAGES (unsupported)
|
2019-04-30 07:23:24 +03:00
|
|
|
{Command::DoNothing, Command::DoNothing},
|
|
|
|
{Command::DoNothing, Command::DoNothing}}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
static void move_cursor_cb(GtkWidget* w, GtkMovementStep step, gint count,
|
|
|
|
gboolean extend_selection, gpointer user_data) {
|
|
|
|
g_signal_stop_emission_by_name(w, "move_cursor");
|
2017-06-21 03:03:09 +03:00
|
|
|
if (count == 0) {
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = true;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forward = count > 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (uint32_t(step) >= ArrayLength(sMoveCommands)) {
|
2004-09-08 01:21:48 +04:00
|
|
|
// unsupported movement type
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:30 +04:00
|
|
|
Command command = sMoveCommands[step][extend_selection][forward];
|
2019-04-30 07:23:24 +03:00
|
|
|
if (command == Command::DoNothing) {
|
|
|
|
return;
|
2014-03-14 17:13:30 +04:00
|
|
|
}
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2013-03-06 03:43:53 +04:00
|
|
|
unsigned int absCount = Abs(count);
|
|
|
|
for (unsigned int i = 0; i < absCount; ++i) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(command);
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void paste_clipboard_cb(GtkWidget* w, gpointer user_data) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::Paste);
|
2004-09-08 01:21:48 +04:00
|
|
|
g_signal_stop_emission_by_name(w, "paste_clipboard");
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = true;
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GtkTextView-only signals
|
|
|
|
static void select_all_cb(GtkWidget* w, gboolean select, gpointer user_data) {
|
2019-04-30 07:23:24 +03:00
|
|
|
AddCommand(Command::SelectAll);
|
2004-09-08 01:21:48 +04:00
|
|
|
g_signal_stop_emission_by_name(w, "select_all");
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = true;
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
NativeKeyBindings* NativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
|
|
|
|
NativeKeyBindings* NativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
|
2014-03-14 17:13:31 +04:00
|
|
|
|
|
|
|
// static
|
2014-03-14 17:13:32 +04:00
|
|
|
NativeKeyBindings* NativeKeyBindings::GetInstance(NativeKeyBindingsType aType) {
|
2014-03-14 17:13:31 +04:00
|
|
|
switch (aType) {
|
|
|
|
case nsIWidget::NativeKeyBindingsForSingleLineEditor:
|
|
|
|
if (!sInstanceForSingleLineEditor) {
|
2014-03-14 17:13:32 +04:00
|
|
|
sInstanceForSingleLineEditor = new NativeKeyBindings();
|
2014-03-14 17:13:31 +04:00
|
|
|
sInstanceForSingleLineEditor->Init(aType);
|
|
|
|
}
|
|
|
|
return sInstanceForSingleLineEditor;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// fallback to multiline editor case in release build
|
2016-03-08 08:30:02 +03:00
|
|
|
MOZ_FALLTHROUGH_ASSERT("aType is invalid or not yet implemented");
|
2014-03-14 17:13:31 +04:00
|
|
|
case nsIWidget::NativeKeyBindingsForMultiLineEditor:
|
|
|
|
case nsIWidget::NativeKeyBindingsForRichTextEditor:
|
|
|
|
if (!sInstanceForMultiLineEditor) {
|
2014-03-14 17:13:32 +04:00
|
|
|
sInstanceForMultiLineEditor = new NativeKeyBindings();
|
2014-03-14 17:13:31 +04:00
|
|
|
sInstanceForMultiLineEditor->Init(aType);
|
|
|
|
}
|
|
|
|
return sInstanceForMultiLineEditor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2014-03-14 17:13:32 +04:00
|
|
|
void NativeKeyBindings::Shutdown() {
|
2014-03-14 17:13:32 +04:00
|
|
|
delete sInstanceForSingleLineEditor;
|
|
|
|
sInstanceForSingleLineEditor = nullptr;
|
|
|
|
delete sInstanceForMultiLineEditor;
|
|
|
|
sInstanceForMultiLineEditor = nullptr;
|
2014-03-14 17:13:31 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
void NativeKeyBindings::Init(NativeKeyBindingsType aType) {
|
2004-09-08 01:21:48 +04:00
|
|
|
switch (aType) {
|
2014-03-14 17:13:31 +04:00
|
|
|
case nsIWidget::NativeKeyBindingsForSingleLineEditor:
|
2004-09-08 01:21:48 +04:00
|
|
|
mNativeTarget = gtk_entry_new();
|
|
|
|
break;
|
2014-03-14 17:13:31 +04:00
|
|
|
default:
|
2004-09-08 01:21:48 +04:00
|
|
|
mNativeTarget = gtk_text_view_new();
|
2004-10-14 00:35:06 +04:00
|
|
|
if (gtk_major_version > 2 ||
|
|
|
|
(gtk_major_version == 2 &&
|
|
|
|
(gtk_minor_version > 2 ||
|
|
|
|
(gtk_minor_version == 2 && gtk_micro_version >= 2)))) {
|
|
|
|
// select_all only exists in gtk >= 2.2.2. Prior to that,
|
|
|
|
// ctrl+a is bound to (move to beginning, select to end).
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "select_all", G_CALLBACK(select_all_cb),
|
2004-10-14 00:35:06 +04:00
|
|
|
this);
|
|
|
|
}
|
2004-09-08 01:21:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-13 19:28:58 +04:00
|
|
|
g_object_ref_sink(mNativeTarget);
|
|
|
|
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "copy_clipboard",
|
2004-09-08 01:21:48 +04:00
|
|
|
G_CALLBACK(copy_clipboard_cb), this);
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "cut_clipboard", G_CALLBACK(cut_clipboard_cb),
|
2004-09-08 01:21:48 +04:00
|
|
|
this);
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "delete_from_cursor",
|
2004-09-08 01:21:48 +04:00
|
|
|
G_CALLBACK(delete_from_cursor_cb), this);
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "move_cursor", G_CALLBACK(move_cursor_cb),
|
2004-09-08 01:21:48 +04:00
|
|
|
this);
|
2011-05-11 17:10:36 +04:00
|
|
|
g_signal_connect(mNativeTarget, "paste_clipboard",
|
2004-09-08 01:21:48 +04:00
|
|
|
G_CALLBACK(paste_clipboard_cb), this);
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
NativeKeyBindings::~NativeKeyBindings() {
|
2004-09-08 01:21:48 +04:00
|
|
|
gtk_widget_destroy(mNativeTarget);
|
2009-04-13 19:28:58 +04:00
|
|
|
g_object_unref(mNativeTarget);
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
void NativeKeyBindings::GetEditCommands(const WidgetKeyboardEvent& aEvent,
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const Maybe<WritingMode>& aWritingMode,
|
2017-05-19 11:49:41 +03:00
|
|
|
nsTArray<CommandInt>& aCommands) {
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
MOZ_ASSERT(!aEvent.mFlags.mIsSynthesizedForTests);
|
|
|
|
MOZ_ASSERT(aCommands.IsEmpty());
|
|
|
|
|
|
|
|
// It must be a DOM event dispached by chrome script.
|
2013-08-24 11:24:32 +04:00
|
|
|
if (!aEvent.mNativeKeyEvent) {
|
2017-05-19 11:49:41 +03:00
|
|
|
return;
|
2013-08-24 11:24:32 +04:00
|
|
|
}
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2013-08-24 11:24:32 +04:00
|
|
|
guint keyval;
|
2016-05-13 10:06:18 +03:00
|
|
|
if (aEvent.mCharCode) {
|
|
|
|
keyval = gdk_unicode_to_keyval(aEvent.mCharCode);
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
} else if (aWritingMode.isSome() && aEvent.NeedsToRemapNavigationKey() &&
|
|
|
|
aWritingMode.ref().IsVertical()) {
|
|
|
|
// TODO: Use KeyNameIndex rather than legacy keyCode.
|
|
|
|
uint32_t remappedGeckoKeyCode =
|
|
|
|
aEvent.GetRemappedKeyCode(aWritingMode.ref());
|
|
|
|
switch (remappedGeckoKeyCode) {
|
|
|
|
case NS_VK_UP:
|
|
|
|
keyval = GDK_Up;
|
|
|
|
break;
|
|
|
|
case NS_VK_DOWN:
|
|
|
|
keyval = GDK_Down;
|
|
|
|
break;
|
|
|
|
case NS_VK_LEFT:
|
|
|
|
keyval = GDK_Left;
|
|
|
|
break;
|
|
|
|
case NS_VK_RIGHT:
|
|
|
|
keyval = GDK_Right;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Add a case for the new remapped key");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-24 11:24:32 +04:00
|
|
|
} else {
|
2013-08-24 11:24:32 +04:00
|
|
|
keyval = static_cast<GdkEventKey*>(aEvent.mNativeKeyEvent)->keyval;
|
2013-08-24 11:24:32 +04:00
|
|
|
}
|
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
if (GetEditCommandsInternal(aEvent, aCommands, keyval)) {
|
|
|
|
return;
|
2013-08-24 11:24:32 +04:00
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2016-05-12 11:57:21 +03:00
|
|
|
for (uint32_t i = 0; i < aEvent.mAlternativeCharCodes.Length(); ++i) {
|
2013-08-24 11:24:32 +04:00
|
|
|
uint32_t ch = aEvent.IsShift()
|
2016-05-12 11:57:21 +03:00
|
|
|
? aEvent.mAlternativeCharCodes[i].mShiftedCharCode
|
|
|
|
: aEvent.mAlternativeCharCodes[i].mUnshiftedCharCode;
|
2016-05-13 10:06:18 +03:00
|
|
|
if (ch && ch != aEvent.mCharCode) {
|
2013-08-24 11:24:32 +04:00
|
|
|
keyval = gdk_unicode_to_keyval(ch);
|
2017-05-19 11:49:41 +03:00
|
|
|
if (GetEditCommandsInternal(aEvent, aCommands, keyval)) {
|
|
|
|
return;
|
2013-08-24 11:24:32 +04:00
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 11:24:32 +04:00
|
|
|
/*
|
|
|
|
gtk_bindings_activate_event is preferable, but it has unresolved bug:
|
|
|
|
http://bugzilla.gnome.org/show_bug.cgi?id=162726
|
|
|
|
The bug was already marked as FIXED. However, somebody reports that the
|
|
|
|
bug still exists.
|
|
|
|
Also gtk_bindings_activate may work with some non-shortcuts operations
|
|
|
|
(todo: check it). See bug 411005 and bug 406407.
|
|
|
|
|
|
|
|
Code, which should be used after fixing GNOME bug 162726:
|
|
|
|
|
|
|
|
gtk_bindings_activate_event(GTK_OBJECT(mNativeTarget),
|
|
|
|
static_cast<GdkEventKey*>(aEvent.mNativeKeyEvent));
|
2008-04-15 08:16:24 +04:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
bool NativeKeyBindings::GetEditCommandsInternal(
|
|
|
|
const WidgetKeyboardEvent& aEvent, nsTArray<CommandInt>& aCommands,
|
|
|
|
guint aKeyval) {
|
2013-08-24 11:24:32 +04:00
|
|
|
guint modifiers = static_cast<GdkEventKey*>(aEvent.mNativeKeyEvent)->state;
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
gCurrentCommands = &aCommands;
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2011-10-03 11:56:21 +04:00
|
|
|
gHandled = false;
|
2012-09-14 05:56:59 +04:00
|
|
|
gtk_bindings_activate(G_OBJECT(mNativeTarget), aKeyval,
|
2013-08-24 11:24:32 +04:00
|
|
|
GdkModifierType(modifiers));
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
gCurrentCommands = nullptr;
|
|
|
|
|
|
|
|
MOZ_ASSERT(!gHandled || !aCommands.IsEmpty());
|
2004-09-08 01:21:48 +04:00
|
|
|
|
2005-05-01 13:44:41 +04:00
|
|
|
return gHandled;
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
2014-03-14 17:13:32 +04:00
|
|
|
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
// static
|
|
|
|
void NativeKeyBindings::GetEditCommandsForTests(
|
|
|
|
NativeKeyBindingsType aType, const WidgetKeyboardEvent& aEvent,
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const Maybe<WritingMode>& aWritingMode, nsTArray<CommandInt>& aCommands) {
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aEvent.IsTrusted());
|
|
|
|
|
|
|
|
if (aEvent.IsAlt() || aEvent.IsMeta() || aEvent.IsOS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const size_t kBackward = 0;
|
|
|
|
static const size_t kForward = 1;
|
|
|
|
const size_t extentSelection = aEvent.IsShift() ? 1 : 0;
|
|
|
|
// https://github.com/GNOME/gtk/blob/1f141c19533f4b3f397c3959ade673ce243b6138/gtk/gtktext.c#L1289
|
|
|
|
// https://github.com/GNOME/gtk/blob/c5dd34344f0c660ceffffb3bf9da43c263db16e1/gtk/gtktextview.c#L1534
|
|
|
|
Command command = Command::DoNothing;
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const KeyNameIndex remappedKeyNameIndex =
|
|
|
|
aWritingMode.isSome() ? aEvent.GetRemappedKeyNameIndex(aWritingMode.ref())
|
|
|
|
: aEvent.mKeyNameIndex;
|
|
|
|
switch (remappedKeyNameIndex) {
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
case KEY_NAME_INDEX_USE_STRING:
|
|
|
|
switch (aEvent.PseudoCharCode()) {
|
|
|
|
case 'a':
|
|
|
|
case 'A':
|
|
|
|
if (aEvent.IsControl()) {
|
|
|
|
command = Command::SelectAll;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
if (aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = Command::Copy;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
case 'U':
|
|
|
|
if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor &&
|
|
|
|
aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = sDeleteCommands[GTK_DELETE_PARAGRAPH_ENDS][kBackward];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
if (aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = Command::Paste;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
if (aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = Command::Cut;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
if (aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = Command::SelectAll;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_NAME_INDEX_Insert:
|
|
|
|
if (aEvent.IsControl() && !aEvent.IsShift()) {
|
|
|
|
command = Command::Copy;
|
|
|
|
} else if (aEvent.IsShift() && !aEvent.IsControl()) {
|
|
|
|
command = Command::Paste;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_NAME_INDEX_Delete:
|
|
|
|
if (aEvent.IsShift()) {
|
|
|
|
command = Command::Cut;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[[fallthrough]];
|
|
|
|
case KEY_NAME_INDEX_Backspace: {
|
|
|
|
const size_t direction =
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
remappedKeyNameIndex == KEY_NAME_INDEX_Delete ? kForward : kBackward;
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
const GtkDeleteType amount =
|
|
|
|
aEvent.IsControl() && aEvent.IsShift()
|
|
|
|
? GTK_DELETE_PARAGRAPH_ENDS
|
|
|
|
// FYI: Shift key for Backspace is ignored to help mis-typing.
|
|
|
|
: (aEvent.IsControl() ? GTK_DELETE_WORD_ENDS : GTK_DELETE_CHARS);
|
|
|
|
command = sDeleteCommands[amount][direction];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_NAME_INDEX_ArrowLeft:
|
|
|
|
case KEY_NAME_INDEX_ArrowRight: {
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const size_t direction = remappedKeyNameIndex == KEY_NAME_INDEX_ArrowRight
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
? kForward
|
|
|
|
: kBackward;
|
|
|
|
const GtkMovementStep amount = aEvent.IsControl()
|
|
|
|
? GTK_MOVEMENT_WORDS
|
|
|
|
: GTK_MOVEMENT_VISUAL_POSITIONS;
|
|
|
|
command = sMoveCommands[amount][extentSelection][direction];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_NAME_INDEX_ArrowUp:
|
|
|
|
case KEY_NAME_INDEX_ArrowDown: {
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const size_t direction = remappedKeyNameIndex == KEY_NAME_INDEX_ArrowDown
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
? kForward
|
|
|
|
: kBackward;
|
|
|
|
const GtkMovementStep amount = aEvent.IsControl()
|
|
|
|
? GTK_MOVEMENT_PARAGRAPHS
|
|
|
|
: GTK_MOVEMENT_DISPLAY_LINES;
|
|
|
|
command = sMoveCommands[amount][extentSelection][direction];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_NAME_INDEX_Home:
|
|
|
|
case KEY_NAME_INDEX_End: {
|
|
|
|
const size_t direction =
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
remappedKeyNameIndex == KEY_NAME_INDEX_End ? kForward : kBackward;
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
const GtkMovementStep amount = aEvent.IsControl()
|
|
|
|
? GTK_MOVEMENT_BUFFER_ENDS
|
|
|
|
: GTK_MOVEMENT_DISPLAY_LINE_ENDS;
|
|
|
|
command = sMoveCommands[amount][extentSelection][direction];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_NAME_INDEX_PageUp:
|
|
|
|
case KEY_NAME_INDEX_PageDown: {
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const size_t direction = remappedKeyNameIndex == KEY_NAME_INDEX_PageDown
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
? kForward
|
|
|
|
: kBackward;
|
|
|
|
const GtkMovementStep amount = aEvent.IsControl()
|
|
|
|
? GTK_MOVEMENT_HORIZONTAL_PAGES
|
|
|
|
: GTK_MOVEMENT_PAGES;
|
|
|
|
command = sMoveCommands[amount][extentSelection][direction];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (command != Command::DoNothing) {
|
|
|
|
aCommands.AppendElement(static_cast<CommandInt>(command));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:13:32 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|