Add 'accept-first-mouse' in window's option.
authorCheng Zhao <zcbenz@gmail.com>
Sat, 15 Mar 2014 11:28:23 +0000 (19:28 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 15 Mar 2014 11:28:23 +0000 (19:28 +0800)
browser/native_window_mac.mm
common/options_switches.cc
common/options_switches.h

index 1dca1c6f7069d32723fccb8a60ca29c637819b32..9ef68f42c5159547fdf15bd85786790308fa7e01 100644 (file)
@@ -29,18 +29,26 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 @interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
  @private
   atom::NativeWindowMac* shell_;
+  BOOL acceptsFirstMouse_;
 }
 - (id)initWithShell:(atom::NativeWindowMac*)shell;
+- (void)setAcceptsFirstMouse:(BOOL)accept;
 @end
 
 @implementation AtomNSWindowDelegate
 
 - (id)initWithShell:(atom::NativeWindowMac*)shell {
-  if ((self = [super init]))
+  if ((self = [super init])) {
     shell_ = shell;
+    acceptsFirstMouse_ = NO;
+  }
   return self;
 }
 
+- (void)setAcceptsFirstMouse:(BOOL)accept {
+  acceptsFirstMouse_ = accept;
+}
+
 - (void)windowDidResignMain:(NSNotification*)notification {
   shell_->NotifyWindowBlur();
 }
@@ -50,6 +58,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
     shell_->ClipWebView();
 }
 
+- (void)windowDidExitFullScreen:(NSNotification*)notification {
+  if (!shell_->has_frame()) {
+    NSWindow* window = shell_->GetNativeWindow();
+    [[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
+  }
+}
+
 - (void)windowWillClose:(NSNotification*)notification {
   shell_->window() = nil;
   [self autorelease];
@@ -63,11 +78,8 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
   return NO;
 }
 
-- (void)windowDidExitFullScreen:(NSNotification*)notification {
-  if (!shell_->has_frame()) {
-    NSWindow* window = shell_->GetNativeWindow();
-    [[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
-  }
+- (BOOL)acceptsFirstMouse:(NSEvent*)event {
+  return acceptsFirstMouse_;
 }
 
 @end
@@ -77,7 +89,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
   atom::NativeWindowMac* shell_;
 }
 - (void)setShell:(atom::NativeWindowMac*)shell;
-- (IBAction)showDevTools:(id)sender;
 @end
 
 @implementation AtomNSWindow
@@ -162,7 +173,14 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
   [atomWindow setShell:this];
   window_ = atomWindow;
 
-  [window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]];
+  AtomNSWindowDelegate* delegate =
+      [[AtomNSWindowDelegate alloc] initWithShell:this];
+  [window() setDelegate:delegate];
+
+  // Enable the NSView to accept first mouse event.
+  bool acceptsFirstMouse = false;
+  options->GetBoolean(switches::kAcceptFirstMouse, &acceptsFirstMouse);
+  [delegate setAcceptsFirstMouse:acceptsFirstMouse];
 
   // Disable fullscreen button when 'fullscreen' is specified to false.
   bool fullscreen;
index f3d849ef176c0ea5494c3ef8e7ef8990687d7e94..9e29340276e37e7e38b39265efda85ce17b7fdf5 100644 (file)
@@ -33,6 +33,9 @@ const char kAlwaysOnTop[] = "always-on-top";
 
 const char kNodeIntegration[] = "node-integration";
 
+// Enable the NSView to accept first mouse event.
+const char kAcceptFirstMouse[] = "accept-first-mouse";
+
 }  // namespace switches
 
 }  // namespace atom
index ad6b68b2eaa578e7a220ce86e2e1a1d753c5cba5..b46f46821323252882f273830eae1fe56ee82c2e 100644 (file)
@@ -27,6 +27,7 @@ extern const char kFullscreen[];
 extern const char kKiosk[];
 extern const char kAlwaysOnTop[];
 extern const char kNodeIntegration[];
+extern const char kAcceptFirstMouse[];
 
 }  // namespace switches