]> khamidou — GitHub mirrors - electron.git/commitdiff
Handle keyboard events with AtomEventProcessingWindow.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 12 Apr 2013 12:31:15 +0000 (20:31 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 12 Apr 2013 12:31:15 +0000 (20:31 +0800)
Some system events like cmd+` will be handled by it automatically.

browser/native_window.cc
browser/native_window.h
browser/native_window_mac.h
browser/native_window_mac.mm
vendor/brightray

index d911e827634c4efd1e9c794599be38bb88155af1..49d77f7d913855648adb022a57a4ae2fdb411508 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "base/values.h"
 #include "brightray/browser/browser_context.h"
-#include "brightray/browser/default_web_contents_delegate.h"
 #include "brightray/browser/inspectable_web_contents.h"
 #include "brightray/browser/inspectable_web_contents_view.h"
 #include "common/options_switches.h"
@@ -22,7 +21,7 @@ NativeWindow::NativeWindow(content::BrowserContext* browser_context,
                            base::DictionaryValue* options)
     : inspectable_web_contents_(brightray::InspectableWebContents::Create(
           content::WebContents::CreateParams(browser_context))) {
-  GetWebContents()->SetDelegate(new brightray::DefaultWebContentsDelegate());
+  GetWebContents()->SetDelegate(this);
 }
 
 NativeWindow::~NativeWindow() {
index 237e7cf37862168557856090dd057a64d554a49d..11a4443c4fafc2a3800f49253ca689ada10c47b2 100644 (file)
@@ -10,6 +10,7 @@
 #include "base/basictypes.h"
 #include "base/compiler_specific.h"
 #include "base/memory/scoped_ptr.h"
+#include "content/public/browser/web_contents_delegate.h"
 
 namespace base {
 class DictionaryValue;
@@ -32,7 +33,7 @@ class Size;
 
 namespace atom {
 
-class NativeWindow {
+class NativeWindow : public content::WebContentsDelegate {
  public:
   virtual ~NativeWindow();
 
index e5fbed18401b6cf084b7d9ff5f37602a36231576..a10f5c74ce68fe00fa4dec06413eb7ade05b0ae9 100644 (file)
@@ -49,6 +49,11 @@ class NativeWindowMac : public NativeWindow {
  protected:
   void SetNonLionFullscreen(bool fullscreen);
 
+  // Implementations of content::WebContentsDelegate.
+  virtual void HandleKeyboardEvent(
+      content::WebContents*,
+      const content::NativeWebKeyboardEvent&) OVERRIDE;
+
  private:
   void InstallView();
   void UninstallView();
index ddf43e93f88c63275f6ce27a52e5293dbf19b914..a9fce7c2ed4e12b15a279150d5d3a9478aa2529d 100644 (file)
 #include "base/mac/mac_util.h"
 #include "base/sys_string_conversions.h"
 #include "base/values.h"
-#include "browser/atom_event_processing_window.h"
+#import "browser/atom_event_processing_window.h"
 #include "brightray/browser/inspectable_web_contents.h"
 #include "brightray/browser/inspectable_web_contents_view.h"
 #include "common/options_switches.h"
+#include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_view.h"
 
@@ -293,6 +294,19 @@ bool NativeWindowMac::IsKiosk() {
   return is_kiosk_;
 }
 
+void NativeWindowMac::HandleKeyboardEvent(
+    content::WebContents*,
+    const content::NativeWebKeyboardEvent& event) {
+  if (event.skip_in_browser ||
+      event.type == content::NativeWebKeyboardEvent::Char)
+    return;
+
+  AtomEventProcessingWindow* event_window =
+      static_cast<AtomEventProcessingWindow*>(window());
+  DCHECK([event_window isKindOfClass:[AtomEventProcessingWindow class]]);
+  [event_window redispatchKeyEvent:event.os_event];
+}
+
 void NativeWindowMac::InstallView() {
   NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
   [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
index 57770d517efe09b0b74e891f5baed0cbb2cad2c1..5a1c81d204ef308cb747ad3b2e4535f6dd456704 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 57770d517efe09b0b74e891f5baed0cbb2cad2c1
+Subproject commit 5a1c81d204ef308cb747ad3b2e4535f6dd456704