Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 5 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| 6 | 6 |
| 7 #include "content/public/browser/native_web_keyboard_event.h" | |
| 8 #include "ui/views/focus/focus_manager.h" | |
| 9 | |
| 7 namespace views { | 10 namespace views { |
| 8 | 11 |
| 12 UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() | |
| 13 : ignore_next_char_event_(false) { | |
| 14 } | |
| 15 | |
| 9 UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() { | 16 UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() { |
| 10 } | 17 } |
| 11 | 18 |
| 19 void UnhandledKeyboardEventHandler::HandleKeyboardEvent( | |
| 20 const content::NativeWebKeyboardEvent& event, | |
| 21 FocusManager* focus_manager) { | |
| 22 if (!focus_manager) { | |
| 23 NOTREACHED(); | |
| 24 return; | |
| 25 } | |
| 26 // Previous calls to TranslateMessage can generate Char events as well as | |
| 27 // RawKeyDown events, even if the latter triggered an accelerator. In these | |
| 28 // cases, we discard the Char events. | |
| 29 if (event.type == blink::WebInputEvent::Char && ignore_next_char_event_) { | |
| 30 ignore_next_char_event_ = false; | |
| 31 return; | |
| 32 } | |
| 33 // It's necessary to reset this flag, because a RawKeyDown event may not | |
| 34 // always generate a Char event. | |
| 35 ignore_next_char_event_ = false; | |
| 36 | |
| 37 if (event.type == blink::WebInputEvent::RawKeyDown) { | |
| 38 ui::Accelerator accelerator( | |
| 39 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | |
| 40 content::GetModifiersFromNativeWebKeyboardEvent(event)); | |
| 41 | |
| 42 // This is tricky: we want to set ignore_next_char_event_ if | |
| 43 // ProcessAccelerator returns true. But ProcessAccelerator might delete | |
| 44 // |this| if the accelerator is a "close tab" one. So we speculatively | |
| 45 // set the flag and fix it if no event was handled. | |
| 46 ignore_next_char_event_ = true; | |
| 47 | |
| 48 if (focus_manager->ProcessAccelerator(accelerator)) { | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 // ProcessAccelerator didn't handle the accelerator, so we know both | |
| 53 // that |this| is still valid, and that we didn't want to set the flag. | |
| 54 ignore_next_char_event_ = false; | |
| 55 } | |
| 56 | |
| 57 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
| |
| 58 HandleNativeKeyboardEvent(event.os_event, focus_manager); | |
| 59 } | |
| 60 | |
| 12 } // namespace views | 61 } // namespace views |
| OLD | NEW |