]> khamidou — GitHub mirrors - electron.git/commitdiff
views: Use UnhandledKeyboardEventHandler to handle accelerators.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 7 Jul 2014 15:02:46 +0000 (23:02 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 7 Jul 2014 15:02:46 +0000 (23:02 +0800)
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index 6cbd506184be854561ae7f45c55cf21ec842d81c..a056d71d81d086ead6e7fe15ebf32cc8b00c12e2 100644 (file)
@@ -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<ui::KeyboardCode>(event.windowsKeyCode),
-        content::GetModifiersFromNativeWebKeyboardEvent(event));
-
-    if (GetFocusManager()->ProcessAccelerator(accelerator)) {
-      return;
-    }
-  }
+  keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
 }
 
 bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
index b213159354aa92bbaf8bebcff4e34299c11d21f2..d060291a64662ff514696c782bd076a8d58a4023 100644 (file)
@@ -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<views::Widget> window_;
   views::View* web_view_;  // Managed by inspectable_web_contents_.
 
+  // Handles unhandled keyboard messages coming back from the renderer process.
+  scoped_ptr<views::UnhandledKeyboardEventHandler> keyboard_event_handler_;
+
   // Map from accelerator to menu item's command id.
   accelerator_util::AcceleratorTable accelerator_table_;