Chromium Code Reviews| Index: ui/views/controls/webview/unhandled_keyboard_event_handler.cc |
| diff --git a/ui/views/controls/webview/unhandled_keyboard_event_handler.cc b/ui/views/controls/webview/unhandled_keyboard_event_handler.cc |
| index 0a43353116e91b401d8a934b45d729f7fc2154c4..7a331d59a9825451d753718aca3771cdceea3662 100644 |
| --- a/ui/views/controls/webview/unhandled_keyboard_event_handler.cc |
| +++ b/ui/views/controls/webview/unhandled_keyboard_event_handler.cc |
| @@ -4,9 +4,58 @@ |
| #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| +#include "content/public/browser/native_web_keyboard_event.h" |
| +#include "ui/views/focus/focus_manager.h" |
| + |
| namespace views { |
| +UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() |
| + : ignore_next_char_event_(false) { |
| +} |
| + |
| UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() { |
| } |
| +void UnhandledKeyboardEventHandler::HandleKeyboardEvent( |
| + const content::NativeWebKeyboardEvent& event, |
| + FocusManager* focus_manager) { |
| + if (!focus_manager) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + // Previous calls to TranslateMessage can generate Char events as well as |
| + // RawKeyDown events, even if the latter triggered an accelerator. In these |
| + // cases, we discard the Char events. |
| + if (event.type == blink::WebInputEvent::Char && ignore_next_char_event_) { |
| + ignore_next_char_event_ = false; |
| + return; |
| + } |
| + // It's necessary to reset this flag, because a RawKeyDown event may not |
| + // always generate a Char event. |
| + ignore_next_char_event_ = false; |
| + |
| + if (event.type == blink::WebInputEvent::RawKeyDown) { |
| + ui::Accelerator accelerator( |
| + static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
| + content::GetModifiersFromNativeWebKeyboardEvent(event)); |
| + |
| + // This is tricky: we want to set ignore_next_char_event_ if |
| + // ProcessAccelerator returns true. But ProcessAccelerator might delete |
| + // |this| if the accelerator is a "close tab" one. So we speculatively |
| + // set the flag and fix it if no event was handled. |
| + ignore_next_char_event_ = true; |
| + |
| + if (focus_manager->ProcessAccelerator(accelerator)) { |
| + return; |
| + } |
| + |
| + // ProcessAccelerator didn't handle the accelerator, so we know both |
| + // that |this| is still valid, and that we didn't want to set the flag. |
| + ignore_next_char_event_ = false; |
| + } |
| + |
| + if (event.os_event && !event.skip_in_browser) |
|
sky
2014/10/24 18:11:19
The win side previously didn't have the !event.ski
Andre
2014/10/24 18:36:02
Right, sorry I should have added a comment about t
|
| + HandleNativeKeyboardEvent(event.os_event, focus_manager); |
| +} |
| + |
| } // namespace views |