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() {
return 100;
}
// Get the default command for a given key |event| and selection state.
int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) {
if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode())
return kNoCommand;
......@@ -147,6 +148,7 @@ int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) {
}
#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) {
const bool select = command.extend_selection();
switch (command.command_id()) {
......@@ -600,19 +602,15 @@ void Textfield::OnMouseReleased(const ui::MouseEvent& event) {
bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
bool handled = controller_ && controller_->HandleKeyEvent(this, event);
if (handled)
return true;
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
ui::GetTextEditKeyBindingsDelegate();
std::vector<ui::TextEditCommandAuraLinux> commands;
if (delegate) {
if (!delegate->MatchEvent(event, &commands))
return false;
if (!handled && delegate && delegate->MatchEvent(event, &commands)) {
const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
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)) {
ExecuteCommand(command);
handled = true;
......@@ -623,11 +621,11 @@ bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
#endif
const int command = GetCommandForKeyEvent(event, HasSelection());
if (IsCommandIdEnabled(command)) {
if (!handled && IsCommandIdEnabled(command)) {
ExecuteCommand(command);
return true;
handled = true;
}
return false;
return handled;
}
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