diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-14 00:50:46 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-14 00:50:46 +0000 |
commit | fd4bfad96a43a31d06db35716e7e2fff4863cb94 (patch) | |
tree | 1dc31a7b8070a62db9f57534df74d3aac972a8fe /ui | |
parent | 0d3c156a884405e625bcb78033a38aab7f75e676 (diff) | |
download | chromium_src-fd4bfad96a43a31d06db35716e7e2fff4863cb94.zip chromium_src-fd4bfad96a43a31d06db35716e7e2fff4863cb94.tar.gz chromium_src-fd4bfad96a43a31d06db35716e7e2fff4863cb94.tar.bz2 |
Move UnhandledKeyboardEventHandler closer to WebView.
By doing this we can include it from c/b/chromeos and also from c/b/ui/views/.
That also means that c/b/chromeos/ does not depend on UI stuff from c/b/ui/views/
And allow us to remove another entry from c/b/DEPS file.
BUG=125846
R=xiyuan@chromium.org,ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/13856004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194113 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
5 files changed, 160 insertions, 0 deletions
diff --git a/ui/views/controls/webview/unhandled_keyboard_event_handler.cc b/ui/views/controls/webview/unhandled_keyboard_event_handler.cc new file mode 100644 index 0000000..0a43353 --- /dev/null +++ b/ui/views/controls/webview/unhandled_keyboard_event_handler.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" + +namespace views { + +UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() { +} + +} // namespace views diff --git a/ui/views/controls/webview/unhandled_keyboard_event_handler.h b/ui/views/controls/webview/unhandled_keyboard_event_handler.h new file mode 100644 index 0000000..825fade --- /dev/null +++ b/ui/views/controls/webview/unhandled_keyboard_event_handler.h @@ -0,0 +1,44 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_VIEWS_CONTROLS_WEBVIEW_UNHANDLED_KEYBOARD_EVENT_HANDLER_H_ +#define UI_VIEWS_CONTROLS_WEBVIEW_UNHANDLED_KEYBOARD_EVENT_HANDLER_H_ + +#include "base/basictypes.h" +#include "ui/views/controls/webview/webview_export.h" + +namespace content { +struct NativeWebKeyboardEvent; +} + +namespace views { +class FocusManager; + +// This class handles unhandled keyboard messages coming back from the renderer +// process. +class WEBVIEW_EXPORT UnhandledKeyboardEventHandler { + public: + UnhandledKeyboardEventHandler(); + ~UnhandledKeyboardEventHandler(); + + void HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event, + FocusManager* focus_manager); + + private: +#if defined(OS_WIN) + // Whether to ignore the next Char keyboard event. + // If a RawKeyDown event was handled as a shortcut key, then we're done + // handling it and should eat any Char event that the translate phase may + // have produced from it. (Handling this event may cause undesirable effects, + // such as a beep if DefWindowProc() has no default handling for the given + // Char.) + bool ignore_next_char_event_; +#endif + + DISALLOW_COPY_AND_ASSIGN(UnhandledKeyboardEventHandler); +}; + +} // namespace views + +#endif // UI_VIEWS_CONTROLS_WEBVIEW_UNHANDLED_KEYBOARD_EVENT_HANDLER_H_ diff --git a/ui/views/controls/webview/unhandled_keyboard_event_handler_aurax11.cc b/ui/views/controls/webview/unhandled_keyboard_event_handler_aurax11.cc new file mode 100644 index 0000000..41c90ff --- /dev/null +++ b/ui/views/controls/webview/unhandled_keyboard_event_handler_aurax11.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" + +#include "base/logging.h" +#include "content/public/browser/native_web_keyboard_event.h" +#include "ui/base/events/event.h" +#include "ui/views/focus/focus_manager.h" + +using content::NativeWebKeyboardEvent; + +namespace views { + +UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() { +} + +void UnhandledKeyboardEventHandler::HandleKeyboardEvent( + const NativeWebKeyboardEvent& event, + FocusManager* focus_manager) { + if (!focus_manager) { + NOTREACHED(); + return; + } + if (event.os_event && !event.skip_in_browser) + focus_manager->OnKeyEvent(*static_cast<ui::KeyEvent*>(event.os_event)); +} + +} // namespace views diff --git a/ui/views/controls/webview/unhandled_keyboard_event_handler_win.cc b/ui/views/controls/webview/unhandled_keyboard_event_handler_win.cc new file mode 100644 index 0000000..fd82608 --- /dev/null +++ b/ui/views/controls/webview/unhandled_keyboard_event_handler_win.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" + +#include "base/logging.h" +#include "content/public/browser/native_web_keyboard_event.h" +#include "ui/base/events/event.h" +#include "ui/views/focus/focus_manager.h" + +using content::NativeWebKeyboardEvent; + +namespace views { + +UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() { + ignore_next_char_event_ = false; +} + +void UnhandledKeyboardEventHandler::HandleKeyboardEvent( + const 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 == WebKit::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 == WebKit::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; + } + + // Any unhandled keyboard/character messages should be defproced. + // This allows stuff like F10, etc to work correctly. +#if defined(USE_AURA) + if (!event.os_event) + return; + const MSG& message(event.os_event->native_event()); +#else + const MSG& message(event.os_event); +#endif + DefWindowProc(message.hwnd, message.message, message.wParam, message.lParam); +} + +} // namespace views diff --git a/ui/views/controls/webview/webview.gyp b/ui/views/controls/webview/webview.gyp index 68bd84d..f03edae 100644 --- a/ui/views/controls/webview/webview.gyp +++ b/ui/views/controls/webview/webview.gyp @@ -25,6 +25,10 @@ 'WEBVIEW_IMPLEMENTATION', ], 'sources': [ + 'unhandled_keyboard_event_handler.cc', + 'unhandled_keyboard_event_handler.h', + 'unhandled_keyboard_event_handler_aurax11.cc', + 'unhandled_keyboard_event_handler_win.cc', 'web_dialog_view.cc', 'web_dialog_view.h', 'webview.cc', |