Chromium Code Reviews| 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 a60d6af388764464b211a9055ec17c21531b8c2a..6ed3b423c852858213311c668161cc4b33f2ea21 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_mac.mm |
| +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm |
| @@ -44,6 +44,8 @@ |
| #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/fullscreen_window_manager.h" |
| +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| #include "ui/gfx/point.h" |
| #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| #include "ui/gfx/surface/io_surface_support_mac.h" |
| @@ -117,6 +119,25 @@ static inline int ToWebKitModifiers(NSUInteger flags) { |
| // NSEvent subtype for scroll gestures events. |
| static const short kIOHIDEventTypeScroll = 6; |
| +// A window subclass that allows the fullscreen window to become main and gain |
| +// keyboard focus. This is only used for pepper flash. Normal fullscreen is |
| +// handled by the browser. |
| +@interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
| +@end |
| + |
| +@implementation PepperFlashFullscreenWindow |
| + |
| +- (BOOL)canBecomeKeyWindow { |
| + return YES; |
| +} |
| + |
| +- (BOOL)canBecomeMainWindow { |
| + return YES; |
| +} |
| + |
| +@end |
| + |
| + |
| namespace { |
| // Maximum number of characters we allow in a tooltip. |
| @@ -293,8 +314,31 @@ void RenderWidgetHostViewMac::InitAsPopup( |
| } |
| void RenderWidgetHostViewMac::InitAsFullscreen( |
| - RenderWidgetHostView* /*reference_host_view*/) { |
| - NOTIMPLEMENTED() << "Full screen not implemented on Mac"; |
| + RenderWidgetHostView* reference_host_view) { |
| + NSWindow* parent_window = nil; |
| + if (reference_host_view) |
| + parent_window = [reference_host_view->GetNativeView() window]; |
| + NSScreen* screen = [parent_window screen]; |
| + if (!screen) |
| + screen = [NSScreen mainScreen]; |
| + |
| + fullscreen_window_.reset([[PepperFlashFullscreenWindow alloc] |
| + initWithContentRect:[screen frame] |
| + styleMask:NSBorderlessWindowMask |
| + backing:NSBackingStoreBuffered |
|
Robert Sesek
2012/03/27 19:47:50
nit: align colons
sail
2012/03/27 20:19:51
Done.
|
| + defer:NO]); |
| + [fullscreen_window_ setLevel:NSFloatingWindowLevel]; |
| + [fullscreen_window_ setReleasedWhenClosed:NO]; |
| + [cocoa_view_ setCanBeKeyView:YES]; |
| + [cocoa_view_ setFrame:[[fullscreen_window_ contentView] bounds]]; |
| + [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| + [[fullscreen_window_ contentView] addSubview:cocoa_view_]; |
| + |
| + fullscreen_window_manager_.reset([[FullscreenWindowManager alloc] |
| + initWithWindow:fullscreen_window_.get() |
| + desiredScreen:screen]); |
| + [fullscreen_window_manager_ enterFullscreenMode]; |
| + [fullscreen_window_ makeKeyAndOrderFront:nil]; |
| } |
| RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
| @@ -632,6 +676,11 @@ void RenderWidgetHostViewMac::Destroy() { |
| [cocoa_view_ removeFromSuperview]; |
| [cocoa_view_ autorelease]; |
| + [fullscreen_window_manager_ exitFullscreenMode]; |
| + fullscreen_window_manager_.reset(); |
| + [fullscreen_window_ close]; |
| + fullscreen_window_.reset(); |
| + |
| // We get this call just before |render_widget_host_| deletes |
| // itself. But we are owned by |cocoa_view_|, which may be retained |
| // by some other code. Examples are WebContentsViewMac's |
| @@ -1469,6 +1518,14 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| NativeWebKeyboardEvent event(theEvent); |
| + // When Escape is pressed, force fullscreen windows to close. |
| + if (event.type == NativeWebKeyboardEvent::RawKeyDown && |
| + event.windowsKeyCode == ui::VKEY_ESCAPE && |
| + renderWidgetHostView_->fullscreen_window()) { |
| + widgetHost->Shutdown(); |
| + return; |
| + } |
| + |
| // We only handle key down events and just simply forward other events. |
| if ([theEvent type] != NSKeyDown) { |
| widgetHost->ForwardKeyboardEvent(event); |