Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 11498008: RenderWidget popup should be a NSWindow so it can go outside the main window. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Shouldn't be calling setParentWindow Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | ui/base/cocoa/event_hook_application.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_view_mac.mm
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index 724884b8dac50d8a7a6cfd3995adf953bcce0495..2981e3c48c2cb12a19a5d78ced89036e76ae013d 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -40,6 +40,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/native_web_keyboard_event.h"
#import "content/public/browser/render_widget_host_view_mac_delegate.h"
+#include "content/public/browser/web_contents_view_delegate.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
@@ -47,6 +48,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFactory.h"
#import "third_party/mozilla/ComplexTextInputPanel.h"
#include "third_party/skia/include/core/SkColor.h"
+#import "ui/base/cocoa/event_hook_application.h"
#import "ui/base/cocoa/fullscreen_window_manager.h"
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#include "ui/base/keycodes/keyboard_codes.h"
@@ -55,6 +57,7 @@
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
+#include "ui/gfx/native_widget_types.h"
Avi (use Gerrit) 2012/12/12 15:59:49 in alphabetical order
keishi 2012/12/13 07:51:12 Didn't need this. Removed.
#include "ui/surface/io_surface_support_mac.h"
#include "webkit/plugins/npapi/webplugin.h"
@@ -167,6 +170,75 @@ static const short kIOHIDEventTypeScroll = 6;
@end
+@interface RenderWidgetPopupWindow : NSWindow<CrEventHookProtocol>
+@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];
+ }
Avi (use Gerrit) 2012/12/12 15:59:49 You don't need {} for a one-liner. I'm still curi
keishi 2012/12/13 07:51:12 resignFirstResponder isn't enough. For example it
+}
+
+// Gets called when the menubar is clicked.
+// Needed because the hookForEvent method doesn't see the click on the menubar.
+- (void)begunTracking:(NSNotification *)notification {
Avi (use Gerrit) 2012/12/12 15:59:49 No space before *.
keishi 2012/12/13 07:51:12 Done.
+ [self close];
+}
+
+// Install the callback.
+- (void)startObservingClick {
Avi (use Gerrit) 2012/12/12 15:59:49 -startObservingClicks is more grammatical. (And -s
keishi 2012/12/13 07:51:12 Done.
+ CrEventHookApplication* app = static_cast<CrEventHookApplication*>(
+ [CrEventHookApplication sharedApplication]);
+ [app addEventHook:self];
+
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
Avi (use Gerrit) 2012/12/12 15:59:49 Space after, not before *.
keishi 2012/12/13 07:51:12 Done.
+ [nc addObserver:self
+ selector:@selector(begunTracking:)
+ name:NSMenuDidBeginTrackingNotification
+ object:[NSApp mainMenu]];
+}
+
+// Remove the callback.
+- (void)stopObservingClick {
+ CrEventHookApplication* app = static_cast<CrEventHookApplication*>(
+ [CrEventHookApplication sharedApplication]);
+ [app removeEventHook:self];
+
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+ [nc removeObserver:self
+ name:NSMenuDidBeginTrackingNotification
+ object:[NSApp mainMenu]];
+}
+
+@end
+
namespace {
// Maximum number of characters we allow in a tooltip.
@@ -329,8 +401,7 @@ void RenderWidgetHostViewMac::InitAsChild(
}
void RenderWidgetHostViewMac::InitAsPopup(
- RenderWidgetHostView* parent_host_view,
- const gfx::Rect& pos) {
+ RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) {
bool activatable = popup_type_ == WebKit::WebPopupTypeNone;
[cocoa_view_ setCloseOnDeactivate:YES];
[cocoa_view_ setCanBeKeyView:activatable ? YES : NO];
@@ -341,15 +412,24 @@ void RenderWidgetHostViewMac::InitAsPopup(
origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height -
pos.height() - origin_global.y;
}
- NSPoint origin_window =
- [[cocoa_view_ window] convertScreenToBase:origin_global];
- NSPoint origin_view =
- [cocoa_view_ convertPoint:origin_window fromView:nil];
- NSRect initial_frame = NSMakeRect(origin_view.x,
- origin_view.y,
- pos.width(),
- pos.height());
- [cocoa_view_ setFrame:initial_frame];
+
+ popup_window_.reset([[RenderWidgetPopupWindow alloc]
+ initWithContentRect:NSMakeRect(origin_global.x, origin_global.y,
+ pos.width(), pos.height())
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO]);
+ [popup_window_ setLevel:NSPopUpMenuWindowLevel];
+ [popup_window_ setReleasedWhenClosed:NO];
+ [popup_window_ makeKeyAndOrderFront:nil];
+ [[popup_window_ contentView] addSubview:cocoa_view_];
+ [cocoa_view_ setFrame:[[popup_window_ contentView] bounds]];
+ [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:cocoa_view_
+ selector:@selector(popupWindowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:popup_window_];
Avi (use Gerrit) 2012/12/12 15:59:49 What is the case that you are trying to catch here
keishi 2012/12/13 07:51:12 When a click is observed RenderWidgetPopupWindow w
}
// This function creates the fullscreen window and hides the dock and menubar if
@@ -458,24 +538,17 @@ void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) {
// The position of |rect| is screen coordinate system and we have to
// consider Cocoa coordinate system is upside-down and also multi-screen.
NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint());
+ NSSize size = NSMakeSize(rect.width(), rect.height());
+ size = [cocoa_view_ convertSize:size toView:nil];
if ([[NSScreen screens] count] > 0) {
- NSSize size = NSMakeSize(rect.width(), rect.height());
- size = [cocoa_view_ convertSize:size toView:nil];
NSScreen* screen =
static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]);
origin_global.y =
NSHeight([screen frame]) - size.height - origin_global.y;
}
-
- // Then |origin_global| is converted to client coordinate system.
- DCHECK([cocoa_view_ window]);
- NSPoint origin_window =
- [[cocoa_view_ window] convertScreenToBase:origin_global];
- NSPoint origin_view =
- [[cocoa_view_ superview] convertPoint:origin_window fromView:nil];
- NSRect frame = NSMakeRect(origin_view.x, origin_view.y,
- rect.width(), rect.height());
- [cocoa_view_ setFrame:frame];
+ [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y,
+ size.width, size.height)
+ display:YES];
} else {
DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]);
BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]);
@@ -725,11 +798,19 @@ void RenderWidgetHostViewMac::Destroy() {
}
}
+ [[NSNotificationCenter defaultCenter]
+ removeObserver:cocoa_view_
+ name:NSWindowWillCloseNotification
+ object:popup_window_];
+
// We've been told to destroy.
[cocoa_view_ retain];
[cocoa_view_ removeFromSuperview];
[cocoa_view_ autorelease];
+ [popup_window_ close];
+ popup_window_.autorelease();
+
[fullscreen_window_manager_ exitFullscreenMode];
fullscreen_window_manager_.reset();
[pepper_fullscreen_window_ close];
@@ -3353,6 +3434,10 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
[[self window] invalidateCursorRectsForView:self];
}
+- (void)popupWindowWillClose:(NSNotification *)notification {
+ [self resignFirstResponder];
keishi 2012/12/13 07:51:12 Changing this line because cocoa_view_ for a popup
+}
+
@end
//
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | ui/base/cocoa/event_hook_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698