Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.mm b/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.mm |
| index ca859f8c4349b83b6d11a7ee8a2b69d0702474d6..796ba31721a5e532f1d4eaf0ac21b40073e4db3b 100644 |
| --- a/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.mm |
| +++ b/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.mm |
| @@ -10,6 +10,77 @@ |
| #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| +#import "chrome/browser/chrome_browser_application_mac.h" |
| +#include "content/public/browser/render_widget_host.h" |
| + |
| +@interface RenderWidgetPopupWindow : NSWindow<CrApplicationEventHookProtocol> |
| +@end |
| + |
| +@implementation RenderWidgetPopupWindow |
| + |
| +- (id)initWithContentRect:(NSRect)contentRect |
| + styleMask:(NSUInteger)windowStyle |
| + backing:(NSBackingStoreType)bufferingType |
| + defer:(BOOL)deferCreation { |
| + if (self = [super initWithContentRect:contentRect |
| + styleMask:windowStyle |
| + backing:bufferingType |
| + defer:deferCreation]) { |
| + [self setOpaque:NO]; |
| + [self setBackgroundColor:[NSColor clearColor]]; |
| + [self startObservingClick]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)close { |
| + [self stopObservingClick]; |
| + [super close]; |
| +} |
| + |
| +// Gets called for all events in application. Watching for a click outside the |
| +// window so we can close. |
| +- (void)hookForEvent:(NSEvent*)theEvent { |
| + if ([theEvent window] == self) |
| + return; |
| + NSEventType eventType = [theEvent type]; |
| + if (eventType == NSLeftMouseDown || eventType == NSRightMouseDown) { |
| + [self close]; |
| + } |
| +} |
| + |
| +// Gets called when the menubar is clicked. |
| +// Needed because the hookForEvent method doesn't see the click on the menubar. |
| +- (void)begunTracking:(NSNotification *)notification { |
| + [self close]; |
| +} |
| + |
| +// Install the callback. |
| +- (void)startObservingClick { |
|
Avi (use Gerrit)
2012/12/10 20:52:06
This is a change in behavior; how did we used to c
keishi
2012/12/11 01:53:54
Right now we close the popup when the web view blu
|
| + BrowserCrApplication* app = static_cast<BrowserCrApplication*>( |
| + [BrowserCrApplication sharedApplication]); |
| + [app addEventHook:self]; |
| + |
| + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| + [nc addObserver:self |
| + selector:@selector(begunTracking:) |
| + name:NSMenuDidBeginTrackingNotification |
| + object:[NSApp mainMenu]]; |
| +} |
| + |
| +// Remove the callback. |
| +- (void)stopObservingClick { |
| + BrowserCrApplication* app = static_cast<BrowserCrApplication*>( |
| + [BrowserCrApplication sharedApplication]); |
| + [app removeEventHook:self]; |
| + |
| + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| + [nc removeObserver:self |
| + name:NSMenuDidBeginTrackingNotification |
| + object:[NSApp mainMenu]]; |
| +} |
| + |
| +@end |
| ChromeWebContentsViewDelegateMac::ChromeWebContentsViewDelegateMac( |
| content::WebContents* web_contents) |
| @@ -27,6 +98,14 @@ ChromeWebContentsViewDelegateMac::CreateRenderWidgetHostViewDelegate( |
| initWithRenderWidgetHost:render_widget_host]; |
| } |
| +NSWindow* ChromeWebContentsViewDelegateMac::CreatePopupWindow() { |
| + return [[RenderWidgetPopupWindow alloc] |
| + initWithContentRect:NSZeroRect |
| + styleMask:NSBorderlessWindowMask |
| + backing:NSBackingStoreBuffered |
| + defer:NO]; |
|
Avi (use Gerrit)
2012/12/10 20:52:06
Is there any possible way to move this into conten
keishi
2012/12/11 01:53:54
This was the difficult part. RenderWidgetPopupWind
|
| +} |
| + |
| content::WebDragDestDelegate* |
| ChromeWebContentsViewDelegateMac::GetDragDestDelegate() { |
| return bookmark_handler_.get(); |