summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 17:32:34 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 17:32:34 +0000
commit1e2172ff39484f471335a27aab380ab8e6a24016 (patch)
tree42537429251e253312efe8b20a1fa4c5120e2470 /ui
parentf34c91a9caea22faa15f2af5832aaeb3a84ec218 (diff)
downloadchromium_src-1e2172ff39484f471335a27aab380ab8e6a24016.zip
chromium_src-1e2172ff39484f471335a27aab380ab8e6a24016.tar.gz
chromium_src-1e2172ff39484f471335a27aab380ab8e6a24016.tar.bz2
linux_aura: Port GtkKeybindingsHandler to Aura.
This is a quick hack to move the current GtkKeybindingsHandler code into aura builds. This is necessary so that Linux users who have set custom keybindings can use them in edit fields. This only works in the content area; further patches are needed for this to work in views. This redoes the interface so that instead of being hard coded into content, we have a general interface set in ui/wm/. This should allow views to also use this code in ui/views/, as well as its current usage in content/. BUG=319437, 358297 R=piman@chromium.org, sadrul@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/213283004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/events/events.gyp16
-rw-r--r--ui/events/x/text_edit_command_x11.cc125
-rw-r--r--ui/events/x/text_edit_command_x11.h82
-rw-r--r--ui/events/x/text_edit_key_bindings_delegate_x11.cc22
-rw-r--r--ui/events/x/text_edit_key_bindings_delegate_x11.h42
-rw-r--r--ui/views/linux_ui/linux_ui.cc1
-rw-r--r--ui/views/linux_ui/linux_ui.h4
7 files changed, 289 insertions, 3 deletions
diff --git a/ui/events/events.gyp b/ui/events/events.gyp
index bb8107f..979b2e3 100644
--- a/ui/events/events.gyp
+++ b/ui/events/events.gyp
@@ -54,10 +54,10 @@
'keycodes/keyboard_codes.h',
'latency_info.cc',
'latency_info.h',
- 'x/device_list_cache_x.cc',
- 'x/device_list_cache_x.h',
'x/device_data_manager.cc',
'x/device_data_manager.h',
+ 'x/device_list_cache_x.cc',
+ 'x/device_list_cache_x.h',
'x/touch_factory_x11.cc',
'x/touch_factory_x11.h',
],
@@ -148,6 +148,10 @@
'platform/x11/x11_event_source.h',
'win/events_win.cc',
'x/events_x.cc',
+ 'x/text_edit_command_x11.cc',
+ 'x/text_edit_command_x11.h',
+ 'x/text_edit_key_bindings_delegate_x11.cc',
+ 'x/text_edit_key_bindings_delegate_x11.h',
],
'conditions': [
# We explicitly enumerate the platforms we _do_ provide native cracking
@@ -157,6 +161,14 @@
'events_stub.cc',
],
}],
+ ['chromeos==1', {
+ 'sources!': [
+ 'x/text_edit_command_x11.cc',
+ 'x/text_edit_command_x11.h',
+ 'x/text_edit_key_bindings_delegate_x11.cc',
+ 'x/text_edit_key_bindings_delegate_x11.h',
+ ],
+ }],
['use_x11==1', {
'dependencies': [
'<(DEPTH)/build/linux/system.gyp:x11',
diff --git a/ui/events/x/text_edit_command_x11.cc b/ui/events/x/text_edit_command_x11.cc
new file mode 100644
index 0000000..1a39ff8
--- /dev/null
+++ b/ui/events/x/text_edit_command_x11.cc
@@ -0,0 +1,125 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/x/text_edit_command_x11.h"
+
+#include "base/logging.h"
+
+namespace ui {
+
+std::string TextEditCommandX11::GetCommandString() const {
+ std::string base_name;
+ switch (command_id_) {
+ case COPY:
+ base_name = "Copy";
+ break;
+ case CUT:
+ base_name = "Cut";
+ break;
+ case DELETE_BACKWARD:
+ base_name = "DeleteBackward";
+ break;
+ case DELETE_FORWARD:
+ base_name = "DeleteForward";
+ break;
+ case DELETE_TO_BEGINING_OF_LINE:
+ base_name = "DeleteToBeginningOfLine";
+ break;
+ case DELETE_TO_BEGINING_OF_PARAGRAPH:
+ base_name = "DeleteToBeginningOfParagraph";
+ break;
+ case DELETE_TO_END_OF_LINE:
+ base_name = "DeleteToEndOfLine";
+ break;
+ case DELETE_TO_END_OF_PARAGRAPH:
+ base_name = "DeleteToEndOfParagraph";
+ break;
+ case DELETE_WORD_BACKWARD:
+ base_name = "DeleteWordBackward";
+ break;
+ case DELETE_WORD_FORWARD:
+ base_name = "DeleteWordForward";
+ break;
+ case INSERT_TEXT:
+ base_name = "InsertText";
+ break;
+ case MOVE_BACKWARD:
+ base_name = "MoveBackward";
+ break;
+ case MOVE_DOWN:
+ base_name = "MoveDown";
+ break;
+ case MOVE_FORWARD:
+ base_name = "MoveForward";
+ break;
+ case MOVE_LEFT:
+ base_name = "MoveLeft";
+ break;
+ case MOVE_PAGE_DOWN:
+ base_name = "MovePageDown";
+ break;
+ case MOVE_PAGE_UP:
+ base_name = "MovePageUp";
+ break;
+ case MOVE_RIGHT:
+ base_name = "MoveRight";
+ break;
+ case MOVE_TO_BEGINING_OF_DOCUMENT:
+ base_name = "MoveToBeginningOfDocument";
+ break;
+ case MOVE_TO_BEGINING_OF_LINE:
+ base_name = "MoveToBeginningOfLine";
+ break;
+ case MOVE_TO_BEGINING_OF_PARAGRAPH:
+ base_name = "MoveToBeginningOfParagraph";
+ break;
+ case MOVE_TO_END_OF_DOCUMENT:
+ base_name = "MoveToEndOfDocument";
+ break;
+ case MOVE_TO_END_OF_LINE:
+ base_name = "MoveToEndOfLine";
+ break;
+ case MOVE_TO_END_OF_PARAGRAPH:
+ base_name = "MoveToEndOfParagraph";
+ break;
+ case MOVE_UP:
+ base_name = "MoveUp";
+ break;
+ case MOVE_WORD_BACKWARD:
+ base_name = "MoveWordBackward";
+ break;
+ case MOVE_WORD_FORWARD:
+ base_name = "MoveWordForward";
+ break;
+ case MOVE_WORD_LEFT:
+ base_name = "MoveWordLeft";
+ break;
+ case MOVE_WORD_RIGHT:
+ base_name = "MoveWordRight";
+ break;
+ case PASTE:
+ base_name = "Paste";
+ break;
+ case SELECT_ALL:
+ base_name = "SelectAll";
+ break;
+ case SET_MARK:
+ base_name = "SetMark";
+ break;
+ case UNSELECT:
+ base_name = "Unselect";
+ break;
+ case INVALID_COMMAND:
+ NOTREACHED();
+ return std::string();
+ }
+
+ if (extend_selection())
+ base_name += "AndModifySelection";
+
+ return base_name;
+}
+
+} // namespace ui
+
diff --git a/ui/events/x/text_edit_command_x11.h b/ui/events/x/text_edit_command_x11.h
new file mode 100644
index 0000000..ff4ace1d
--- /dev/null
+++ b/ui/events/x/text_edit_command_x11.h
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_EVENTS_X_TEXT_EDIT_COMMAND_X11_H_
+#define UI_EVENTS_X_TEXT_EDIT_COMMAND_X11_H_
+
+#include <string>
+
+#include "ui/events/events_export.h"
+
+namespace ui {
+
+// Represents a command that performs a specific operation on text.
+// Copy and assignment are explicitly allowed; these objects live in vectors.
+class EVENTS_EXPORT TextEditCommandX11 {
+ public:
+ enum CommandId {
+ COPY,
+ CUT,
+ DELETE_BACKWARD,
+ DELETE_FORWARD,
+ DELETE_TO_BEGINING_OF_LINE,
+ DELETE_TO_BEGINING_OF_PARAGRAPH,
+ DELETE_TO_END_OF_LINE,
+ DELETE_TO_END_OF_PARAGRAPH,
+ DELETE_WORD_BACKWARD,
+ DELETE_WORD_FORWARD,
+ INSERT_TEXT,
+ MOVE_BACKWARD,
+ MOVE_DOWN,
+ MOVE_FORWARD,
+ MOVE_LEFT,
+ MOVE_PAGE_DOWN,
+ MOVE_PAGE_UP,
+ MOVE_RIGHT,
+ MOVE_TO_BEGINING_OF_DOCUMENT,
+ MOVE_TO_BEGINING_OF_LINE,
+ MOVE_TO_BEGINING_OF_PARAGRAPH,
+ MOVE_TO_END_OF_DOCUMENT,
+ MOVE_TO_END_OF_LINE,
+ MOVE_TO_END_OF_PARAGRAPH,
+ MOVE_UP,
+ MOVE_WORD_BACKWARD,
+ MOVE_WORD_FORWARD,
+ MOVE_WORD_LEFT,
+ MOVE_WORD_RIGHT,
+ PASTE,
+ SELECT_ALL,
+ SET_MARK,
+ UNSELECT,
+ INVALID_COMMAND
+ };
+
+ TextEditCommandX11(CommandId command_id,
+ const std::string& argument,
+ bool extend_selection)
+ : command_id_(command_id),
+ argument_(argument),
+ extend_selection_(extend_selection) {}
+
+ CommandId command_id() const { return command_id_; }
+ const std::string& argument() const { return argument_; }
+ bool extend_selection() const { return extend_selection_; }
+
+ // We communicate these commands back to blink with a string representation.
+ // This will combine the base command name with "AndModifySelection" if we
+ // have |extend_selection_| set.
+ std::string GetCommandString() const;
+
+ private:
+ CommandId command_id_;
+
+ std::string argument_;
+
+ // In addition to executing the command, modify the selection.
+ bool extend_selection_;
+};
+
+} // namespace ui
+
+#endif // UI_EVENTS_X_TEXT_EDIT_COMMAND_X11_H_
diff --git a/ui/events/x/text_edit_key_bindings_delegate_x11.cc b/ui/events/x/text_edit_key_bindings_delegate_x11.cc
new file mode 100644
index 0000000..33e8c58
--- /dev/null
+++ b/ui/events/x/text_edit_key_bindings_delegate_x11.cc
@@ -0,0 +1,22 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/x/text_edit_key_bindings_delegate_x11.h"
+
+namespace ui {
+
+namespace {
+// Optional delegate. Unowned pointer.
+TextEditKeyBindingsDelegateX11* text_edit_keybinding_delegate_ = 0;
+}
+
+void SetTextEditKeyBindingsDelegate(TextEditKeyBindingsDelegateX11* delegate) {
+ text_edit_keybinding_delegate_ = delegate;
+}
+
+TextEditKeyBindingsDelegateX11* GetTextEditKeyBindingsDelegate() {
+ return text_edit_keybinding_delegate_;
+}
+
+} // namespace ui
diff --git a/ui/events/x/text_edit_key_bindings_delegate_x11.h b/ui/events/x/text_edit_key_bindings_delegate_x11.h
new file mode 100644
index 0000000..7cfe66a
--- /dev/null
+++ b/ui/events/x/text_edit_key_bindings_delegate_x11.h
@@ -0,0 +1,42 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_EVENTS_X_TEXT_EDIT_KEY_BINDINGS_DELEGATE_X11_H_
+#define UI_EVENTS_X_TEXT_EDIT_KEY_BINDINGS_DELEGATE_X11_H_
+
+#include <vector>
+
+#include "ui/events/events_export.h"
+
+namespace ui {
+class Event;
+class TextEditCommandX11;
+
+// An interface which can interpret various text editing commands out of key
+// events.
+//
+// On desktop Linux, we've traditionally supported the user's custom
+// keybindings. We need to support this in both content/ and in views/.
+class EVENTS_EXPORT TextEditKeyBindingsDelegateX11 {
+ public:
+ // Matches a key event against the users' platform specific key bindings,
+ // false will be returned if the key event doesn't correspond to a predefined
+ // key binding. Edit commands matched with |event| will be stored in
+ // |edit_commands|, if |edit_commands| is non-NULL.
+ virtual bool MatchEvent(const ui::Event& event,
+ std::vector<TextEditCommandX11>* commands) = 0;
+
+ protected:
+ virtual ~TextEditKeyBindingsDelegateX11() {}
+};
+
+// Sets/Gets the global TextEditKeyBindingsDelegateX11. No ownership
+// changes. Can be NULL.
+EVENTS_EXPORT void SetTextEditKeyBindingsDelegate(
+ TextEditKeyBindingsDelegateX11* delegate);
+EVENTS_EXPORT TextEditKeyBindingsDelegateX11* GetTextEditKeyBindingsDelegate();
+
+} // namespace ui
+
+#endif // UI_EVENTS_X_TEXT_EDIT_KEY_BINDINGS_DELEGATE_X11_H_
diff --git a/ui/views/linux_ui/linux_ui.cc b/ui/views/linux_ui/linux_ui.cc
index 20a4997..63c7402 100644
--- a/ui/views/linux_ui/linux_ui.cc
+++ b/ui/views/linux_ui/linux_ui.cc
@@ -22,6 +22,7 @@ void LinuxUI::SetInstance(LinuxUI* instance) {
LinuxInputMethodContextFactory::SetInstance(instance);
LinuxFontDelegate::SetInstance(instance);
LinuxShellDialog::SetInstance(instance);
+ ui::SetTextEditKeyBindingsDelegate(instance);
}
LinuxUI* LinuxUI::instance() {
diff --git a/ui/views/linux_ui/linux_ui.h b/ui/views/linux_ui/linux_ui.h
index 15ac6a2..5a2ea10 100644
--- a/ui/views/linux_ui/linux_ui.h
+++ b/ui/views/linux_ui/linux_ui.h
@@ -9,6 +9,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/ime/linux/linux_input_method_context_factory.h"
+#include "ui/events/x/text_edit_key_bindings_delegate_x11.h"
#include "ui/gfx/linux_font_delegate.h"
#include "ui/shell_dialogs/linux_shell_dialog.h"
#include "ui/views/controls/button/button.h"
@@ -42,7 +43,8 @@ class WindowButtonOrderObserver;
// liuigtk3.so, etc.
class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
public gfx::LinuxFontDelegate,
- public ui::LinuxShellDialog {
+ public ui::LinuxShellDialog,
+ public ui::TextEditKeyBindingsDelegateX11 {
public:
virtual ~LinuxUI() {}