Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / ui / views / controls / webview / unhandled_keyboard_event_handler_win.cc
blob463ef7e3a05bec59b0ce3ca1aa947a4281c01b1b
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
3 // found in the LICENSE file.
5 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
7 #include "base/logging.h"
8 #include "content/public/browser/native_web_keyboard_event.h"
9 #include "ui/events/event.h"
10 #include "ui/views/focus/focus_manager.h"
12 using content::NativeWebKeyboardEvent;
14 namespace views {
16 UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() {
17 ignore_next_char_event_ = false;
20 void UnhandledKeyboardEventHandler::HandleKeyboardEvent(
21 const NativeWebKeyboardEvent& event,
22 FocusManager* focus_manager) {
23 if (!focus_manager) {
24 NOTREACHED();
25 return;
27 // Previous calls to TranslateMessage can generate Char events as well as
28 // RawKeyDown events, even if the latter triggered an accelerator. In these
29 // cases, we discard the Char events.
30 if (event.type == blink::WebInputEvent::Char && ignore_next_char_event_) {
31 ignore_next_char_event_ = false;
32 return;
34 // It's necessary to reset this flag, because a RawKeyDown event may not
35 // always generate a Char event.
36 ignore_next_char_event_ = false;
38 if (event.type == blink::WebInputEvent::RawKeyDown) {
39 ui::Accelerator accelerator(
40 static_cast<ui::KeyboardCode>(event.windowsKeyCode),
41 content::GetModifiersFromNativeWebKeyboardEvent(event));
43 // This is tricky: we want to set ignore_next_char_event_ if
44 // ProcessAccelerator returns true. But ProcessAccelerator might delete
45 // |this| if the accelerator is a "close tab" one. So we speculatively
46 // set the flag and fix it if no event was handled.
47 ignore_next_char_event_ = true;
49 if (focus_manager->ProcessAccelerator(accelerator)) {
50 return;
53 // ProcessAccelerator didn't handle the accelerator, so we know both
54 // that |this| is still valid, and that we didn't want to set the flag.
55 ignore_next_char_event_ = false;
58 // Any unhandled keyboard/character messages should be defproced.
59 // This allows stuff like F10, etc to work correctly.
60 if (!event.os_event)
61 return;
62 const MSG& message(event.os_event->native_event());
63 DefWindowProc(message.hwnd, message.message, message.wParam, message.lParam);
66 } // namespace views