Merge pull request #215 from atom/first-mouse-event

Add 'accept-first-mouse' to BrowserWindow's creation option
This commit is contained in:
Cheng Zhao 2014-03-15 14:37:22 +00:00
commit 467b9122e9
5 changed files with 33 additions and 9 deletions

View file

@ -29,18 +29,26 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> { @interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
@private @private
atom::NativeWindowMac* shell_; atom::NativeWindowMac* shell_;
BOOL acceptsFirstMouse_;
} }
- (id)initWithShell:(atom::NativeWindowMac*)shell; - (id)initWithShell:(atom::NativeWindowMac*)shell;
- (void)setAcceptsFirstMouse:(BOOL)accept;
@end @end
@implementation AtomNSWindowDelegate @implementation AtomNSWindowDelegate
- (id)initWithShell:(atom::NativeWindowMac*)shell { - (id)initWithShell:(atom::NativeWindowMac*)shell {
if ((self = [super init])) if ((self = [super init])) {
shell_ = shell; shell_ = shell;
acceptsFirstMouse_ = NO;
}
return self; return self;
} }
- (void)setAcceptsFirstMouse:(BOOL)accept {
acceptsFirstMouse_ = accept;
}
- (void)windowDidResignMain:(NSNotification*)notification { - (void)windowDidResignMain:(NSNotification*)notification {
shell_->NotifyWindowBlur(); shell_->NotifyWindowBlur();
} }
@ -50,6 +58,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
shell_->ClipWebView(); shell_->ClipWebView();
} }
- (void)windowDidExitFullScreen:(NSNotification*)notification {
if (!shell_->has_frame()) {
NSWindow* window = shell_->GetNativeWindow();
[[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
}
}
- (void)windowWillClose:(NSNotification*)notification { - (void)windowWillClose:(NSNotification*)notification {
shell_->window() = nil; shell_->window() = nil;
[self autorelease]; [self autorelease];
@ -63,11 +78,8 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
return NO; return NO;
} }
- (void)windowDidExitFullScreen:(NSNotification*)notification { - (BOOL)acceptsFirstMouse:(NSEvent*)event {
if (!shell_->has_frame()) { return acceptsFirstMouse_;
NSWindow* window = shell_->GetNativeWindow();
[[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
}
} }
@end @end
@ -77,7 +89,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
atom::NativeWindowMac* shell_; atom::NativeWindowMac* shell_;
} }
- (void)setShell:(atom::NativeWindowMac*)shell; - (void)setShell:(atom::NativeWindowMac*)shell;
- (IBAction)showDevTools:(id)sender;
@end @end
@implementation AtomNSWindow @implementation AtomNSWindow
@ -162,7 +173,14 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
[atomWindow setShell:this]; [atomWindow setShell:this];
window_ = atomWindow; 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. // Disable fullscreen button when 'fullscreen' is specified to false.
bool fullscreen; bool fullscreen;

View file

@ -33,6 +33,9 @@ const char kAlwaysOnTop[] = "always-on-top";
const char kNodeIntegration[] = "node-integration"; const char kNodeIntegration[] = "node-integration";
// Enable the NSView to accept first mouse event.
const char kAcceptFirstMouse[] = "accept-first-mouse";
} // namespace switches } // namespace switches
} // namespace atom } // namespace atom

View file

@ -27,6 +27,7 @@ extern const char kFullscreen[];
extern const char kKiosk[]; extern const char kKiosk[];
extern const char kAlwaysOnTop[]; extern const char kAlwaysOnTop[];
extern const char kNodeIntegration[]; extern const char kNodeIntegration[];
extern const char kAcceptFirstMouse[];
} // namespace switches } // namespace switches

View file

@ -43,6 +43,8 @@ You can also create a window without chrome by using
[Frameless Window](frameless-window.md) [Frameless Window](frameless-window.md)
* `node-integration` String - Can be `all`, `except-iframe`, * `node-integration` String - Can be `all`, `except-iframe`,
`manual-enable-iframe` or `disable`. `manual-enable-iframe` or `disable`.
* `accept-first-mouse` Boolean - Whether the web view accepts a single
mouse-down event that simultaneously activates the window
Creates a new `BrowserWindow` with native properties set by the `options`. Creates a new `BrowserWindow` with native properties set by the `options`.
Usually you only need to set the `width` and `height`, other properties will Usually you only need to set the `width` and `height`, other properties will

View file

@ -2,4 +2,4 @@
NODE_VERSION = 'v0.11.10' NODE_VERSION = 'v0.11.10'
BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent' BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = '607907aed2c1dcdd3b5968a756a990ba3f47bca7' LIBCHROMIUMCONTENT_COMMIT = '276722e68bb643e3ae3b468b701c276aeb884838'