Index: chrome/browser/ui/views/frame/browser_view.cc |
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc |
index 81ee794955a704d2ce8c6a9e623651216a538499..934caa5e48edb9328a578a8badbd66f8837c6642 100644 |
--- a/chrome/browser/ui/views/frame/browser_view.cc |
+++ b/chrome/browser/ui/views/frame/browser_view.cc |
@@ -1145,13 +1145,18 @@ void BrowserView::ShowAppMenu() { |
bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
bool* is_keyboard_shortcut) { |
- if (event.type != WebKit::WebInputEvent::RawKeyDown) |
+ *is_keyboard_shortcut = false; |
+ |
+ if ((event.type != WebKit::WebInputEvent::RawKeyDown) && |
+ (event.type != WebKit::WebInputEvent::KeyUp)) { |
return false; |
+ } |
#if defined(OS_WIN) && !defined(USE_AURA) |
// As Alt+F4 is the close-app keyboard shortcut, it needs processing |
// immediately. |
if (event.windowsKeyCode == ui::VKEY_F4 && |
+ event.type == WebKit::WebInputEvent::RawKeyDown && |
event.modifiers == NativeWebKeyboardEvent::AltKey) { |
DefWindowProc(event.os_event.hwnd, event.os_event.message, |
event.os_event.wParam, event.os_event.lParam); |
@@ -1170,16 +1175,25 @@ bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
NativeWebKeyboardEvent::ControlKey, |
(event.modifiers & NativeWebKeyboardEvent::AltKey) == |
NativeWebKeyboardEvent::AltKey); |
+ if (event.type == WebKit::WebInputEvent::KeyUp) |
+ accelerator.set_type(ui::ET_KEY_RELEASED); |
+ |
+ // What we have to do here is as follows: |
+ // - If the |browser_| is for an app, do nothing. |
+ // - If the |browser_| is not for an app, and the |accelerator| is not |
+ // associated with the browser (e.g. an Ash shortcut), process it. |
+ // - If the |browser_| is not for an app, and the |accelerator| is associated |
+ // with the browser, and it is a reserved one (e.g. Ctrl-t), process it. |
+ // - If the |browser_| is not for an app, and the |accelerator| is associated |
+ // with the browser, and it is not a reserved one, do nothing. |
- // We first find out the browser command associated to the |event|. |
- // Then if the command is a reserved one, and should be processed |
- // immediately according to the |event|, the command will be executed |
- // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and |
- // return false. |
+ if (browser_->is_app()) { |
+ // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app |
+ // might not be able to see a subsequent Char event. See OnHandleInputEvent |
+ // in content/renderer/render_widget.cc for details. |
+ return false; |
+ } |
- // This piece of code is based on the fact that accelerators registered |
- // into the |focus_manager| may only trigger a browser command execution. |
- // |
// Here we need to retrieve the command id (if any) associated to the |
// keyboard event. Instead of looking up the command id in the |
// |accelerator_table_| by ourselves, we block the command execution of |
@@ -1187,21 +1201,27 @@ bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
// |focus_manager| as if we are activating an accelerator key. |
// Then we can retrieve the command id from the |browser_| object. |
browser_->SetBlockCommandExecution(true); |
- focus_manager->ProcessAccelerator(accelerator); |
- int id = browser_->GetLastBlockedCommand(NULL); |
+ // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the |
+ // command execution cannot be blocked and true is returned. However, it is |
+ // okay as long as is_app() is false. See comments in this function. |
+ const bool processed = focus_manager->ProcessAccelerator(accelerator); |
+ const int id = browser_->GetLastBlockedCommand(NULL); |
browser_->SetBlockCommandExecution(false); |
- if (id == -1) |
- return false; |
- |
// Executing the command may cause |this| object to be destroyed. |
if (browser_->IsReservedCommandOrKey(id, event)) { |
UpdateAcceleratorMetrics(accelerator, id); |
return browser_->ExecuteCommandIfEnabled(id); |
} |
- DCHECK(is_keyboard_shortcut != NULL); |
- *is_keyboard_shortcut = true; |
+ if (id != -1) { |
+ // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+t). |
+ if (event.type == WebKit::WebInputEvent::RawKeyDown) |
+ *is_keyboard_shortcut = true; |
+ } else if (processed) { |
+ // |accelerator| is a non-browser shortcut (e.g. F5-F10 on Ash). |
+ return true; |
+ } |
return false; |
} |