From b99262af329027529e7300f0f08f544a9fc0fe5e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 7 Jul 2014 23:02:46 +0800 Subject: [PATCH] views: Use UnhandledKeyboardEventHandler to handle accelerators. --- atom/browser/native_window_views.cc | 12 +++--------- atom/browser/native_window_views.h | 4 ++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 6cbd506184be..a056d71d81d0 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -18,6 +18,7 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" #include "ui/views/background.h" +#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/window/client_view.h" @@ -56,6 +57,7 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, : NativeWindow(web_contents, options), window_(new views::Widget), web_view_(inspectable_web_contents()->GetView()->GetView()), + keyboard_event_handler_(new views::UnhandledKeyboardEventHandler), resizable_(true) { options.Get(switches::kResizable, &resizable_); options.Get(switches::kTitle, &title_); @@ -369,15 +371,7 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView( void NativeWindowViews::HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent& event) { - if (event.type == blink::WebInputEvent::RawKeyDown) { - ui::Accelerator accelerator( - static_cast(event.windowsKeyCode), - content::GetModifiersFromNativeWebKeyboardEvent(event)); - - if (GetFocusManager()->ProcessAccelerator(accelerator)) { - return; - } - } + keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager()); } bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) { diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index b213159354aa..d060291a6466 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -14,6 +14,7 @@ #include "ui/views/widget/widget_delegate.h" namespace views { +class UnhandledKeyboardEventHandler; class Widget; } @@ -105,6 +106,9 @@ class NativeWindowViews : public NativeWindow, scoped_ptr window_; views::View* web_view_; // Managed by inspectable_web_contents_. + // Handles unhandled keyboard messages coming back from the renderer process. + scoped_ptr keyboard_event_handler_; + // Map from accelerator to menu item's command id. accelerator_util::AcceleratorTable accelerator_table_;