Commit e77708f2 authored by msw@chromium.org's avatar msw@chromium.org

Fix Textfield::OnKeyPressed command handling for Linux Aura.

Get the default command if there was no Linux Aura command.
Similar to RenderWidgetHostViewAura::ForwardKeyboardEvent
(forwards the raw key event if there is no matching command)

TODO(followup): Add more complete GTK command coverage.
(Elliot noted this might not be worthwhile at the moment)

BUG=377355
TEST=[Shift+]Ctrl+Z invokes Undo/Redo in the Linux Aura omnibox.
R=oshima@chromium.org,erg@chromium.org

Review URL: https://codereview.chromium.org/307783003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273791 0039d316-1c4b-4281-b951-d872f2087c98
parent c047ef0d
...@@ -75,6 +75,7 @@ int GetDragSelectionDelay() { ...@@ -75,6 +75,7 @@ int GetDragSelectionDelay() {
return 100; return 100;
} }
// Get the default command for a given key |event| and selection state.
int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) { int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) {
if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode())
return kNoCommand; return kNoCommand;
...@@ -147,6 +148,7 @@ int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) { ...@@ -147,6 +148,7 @@ int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) {
} }
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Convert a custom text edit |command| to the equivalent views command ID.
int GetViewsCommand(const ui::TextEditCommandAuraLinux& command, bool rtl) { int GetViewsCommand(const ui::TextEditCommandAuraLinux& command, bool rtl) {
const bool select = command.extend_selection(); const bool select = command.extend_selection();
switch (command.command_id()) { switch (command.command_id()) {
...@@ -600,19 +602,15 @@ void Textfield::OnMouseReleased(const ui::MouseEvent& event) { ...@@ -600,19 +602,15 @@ void Textfield::OnMouseReleased(const ui::MouseEvent& event) {
bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
bool handled = controller_ && controller_->HandleKeyEvent(this, event); bool handled = controller_ && controller_->HandleKeyEvent(this, event);
if (handled)
return true;
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
ui::TextEditKeyBindingsDelegateAuraLinux* delegate = ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
ui::GetTextEditKeyBindingsDelegate(); ui::GetTextEditKeyBindingsDelegate();
std::vector<ui::TextEditCommandAuraLinux> commands; std::vector<ui::TextEditCommandAuraLinux> commands;
if (delegate) { if (!handled && delegate && delegate->MatchEvent(event, &commands)) {
if (!delegate->MatchEvent(event, &commands))
return false;
const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
for (size_t i = 0; i < commands.size(); ++i) { for (size_t i = 0; i < commands.size(); ++i) {
int command = GetViewsCommand(commands[i], rtl); const int command = GetViewsCommand(commands[i], rtl);
if (IsCommandIdEnabled(command)) { if (IsCommandIdEnabled(command)) {
ExecuteCommand(command); ExecuteCommand(command);
handled = true; handled = true;
...@@ -623,11 +621,11 @@ bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -623,11 +621,11 @@ bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
#endif #endif
const int command = GetCommandForKeyEvent(event, HasSelection()); const int command = GetCommandForKeyEvent(event, HasSelection());
if (IsCommandIdEnabled(command)) { if (!handled && IsCommandIdEnabled(command)) {
ExecuteCommand(command); ExecuteCommand(command);
return true; handled = true;
} }
return false; return handled;
} }
ui::TextInputClient* Textfield::GetTextInputClient() { ui::TextInputClient* Textfield::GetTextInputClient() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment