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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 9838071: Implement pepper flash fullscreen on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #include <QuartzCore/QuartzCore.h> 7 #include <QuartzCore/QuartzCore.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 25 matching lines...) Expand all
36 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/native_web_keyboard_event.h" 37 #include "content/public/browser/native_web_keyboard_event.h"
38 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 38 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
39 #include "skia/ext/platform_canvas.h" 39 #include "skia/ext/platform_canvas.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h"
44 #import "third_party/mozilla/ComplexTextInputPanel.h" 44 #import "third_party/mozilla/ComplexTextInputPanel.h"
45 #include "third_party/skia/include/core/SkColor.h" 45 #include "third_party/skia/include/core/SkColor.h"
46 #import "ui/base/cocoa/fullscreen_window_manager.h"
47 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
46 #include "ui/gfx/point.h" 48 #include "ui/gfx/point.h"
47 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 49 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
48 #include "ui/gfx/surface/io_surface_support_mac.h" 50 #include "ui/gfx/surface/io_surface_support_mac.h"
49 #include "webkit/glue/webaccessibility.h" 51 #include "webkit/glue/webaccessibility.h"
50 #include "webkit/plugins/npapi/webplugin.h" 52 #include "webkit/plugins/npapi/webplugin.h"
51 53
52 using content::BrowserThread; 54 using content::BrowserThread;
53 using content::RenderViewHostImpl; 55 using content::RenderViewHostImpl;
54 using content::RenderWidgetHost; 56 using content::RenderWidgetHost;
55 using content::RenderWidgetHostImpl; 57 using content::RenderWidgetHostImpl;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; 114 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right;
113 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; 115 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar;
114 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 116 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
115 - (void)cancelChildPopups; 117 - (void)cancelChildPopups;
116 - (void)checkForPluginImeCancellation; 118 - (void)checkForPluginImeCancellation;
117 @end 119 @end
118 120
119 // NSEvent subtype for scroll gestures events. 121 // NSEvent subtype for scroll gestures events.
120 static const short kIOHIDEventTypeScroll = 6; 122 static const short kIOHIDEventTypeScroll = 6;
121 123
124 // A window subclass that allows the fullscreen window to become main and gain
125 // keyboard focus. This is only used for pepper flash. Normal fullscreen is
126 // handled by the browser.
127 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow
128 @end
129
130 @implementation PepperFlashFullscreenWindow
131
132 - (BOOL)canBecomeKeyWindow {
133 return YES;
134 }
135
136 - (BOOL)canBecomeMainWindow {
137 return YES;
138 }
139
140 @end
141
142
122 namespace { 143 namespace {
123 144
124 // Maximum number of characters we allow in a tooltip. 145 // Maximum number of characters we allow in a tooltip.
125 const size_t kMaxTooltipLength = 1024; 146 const size_t kMaxTooltipLength = 1024;
126 147
127 // TODO(suzhe): Upstream this function. 148 // TODO(suzhe): Upstream this function.
128 WebKit::WebColor WebColorFromNSColor(NSColor *color) { 149 WebKit::WebColor WebColorFromNSColor(NSColor *color) {
129 CGFloat r, g, b, a; 150 CGFloat r, g, b, a;
130 [color getRed:&r green:&g blue:&b alpha:&a]; 151 [color getRed:&r green:&g blue:&b alpha:&a];
131 152
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 [[cocoa_view_ window] convertScreenToBase:origin_global]; 307 [[cocoa_view_ window] convertScreenToBase:origin_global];
287 NSPoint origin_view = 308 NSPoint origin_view =
288 [cocoa_view_ convertPoint:origin_window fromView:nil]; 309 [cocoa_view_ convertPoint:origin_window fromView:nil];
289 NSRect initial_frame = NSMakeRect(origin_view.x, 310 NSRect initial_frame = NSMakeRect(origin_view.x,
290 origin_view.y, 311 origin_view.y,
291 pos.width(), 312 pos.width(),
292 pos.height()); 313 pos.height());
293 [cocoa_view_ setFrame:initial_frame]; 314 [cocoa_view_ setFrame:initial_frame];
294 } 315 }
295 316
317 // This function creates the fullscreen window and hides the dock and menubar if
318 // necessary. Note, this codepath is only used for pepper flash when
319 // pp::FlashFullScreen::SetFullscreen() is called. If
320 // pp::FullScreen::SetFullscreen() is called then the entire browser window
321 // will enter fullscreen instead.
296 void RenderWidgetHostViewMac::InitAsFullscreen( 322 void RenderWidgetHostViewMac::InitAsFullscreen(
297 RenderWidgetHostView* /*reference_host_view*/) { 323 RenderWidgetHostView* reference_host_view) {
298 NOTIMPLEMENTED() << "Full screen not implemented on Mac"; 324 NSWindow* parent_window = nil;
325 if (reference_host_view)
326 parent_window = [reference_host_view->GetNativeView() window];
327 NSScreen* screen = [parent_window screen];
328 if (!screen)
329 screen = [NSScreen mainScreen];
330
331 pepper_fullscreen_window_.reset([[PepperFlashFullscreenWindow alloc]
332 initWithContentRect:[screen frame]
333 styleMask:NSBorderlessWindowMask
334 backing:NSBackingStoreBuffered
335 defer:NO]);
336 [pepper_fullscreen_window_ setLevel:NSFloatingWindowLevel];
337 [pepper_fullscreen_window_ setReleasedWhenClosed:NO];
338 [cocoa_view_ setCanBeKeyView:YES];
339 [cocoa_view_ setFrame:[[pepper_fullscreen_window_ contentView] bounds]];
340 [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
341 [[pepper_fullscreen_window_ contentView] addSubview:cocoa_view_];
342
343 fullscreen_window_manager_.reset([[FullscreenWindowManager alloc]
344 initWithWindow:pepper_fullscreen_window_.get()
345 desiredScreen:screen]);
346 [fullscreen_window_manager_ enterFullscreenMode];
347 [pepper_fullscreen_window_ makeKeyAndOrderFront:nil];
299 } 348 }
300 349
301 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { 350 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
302 return render_widget_host_; 351 return render_widget_host_;
303 } 352 }
304 353
305 void RenderWidgetHostViewMac::DidBecomeSelected() { 354 void RenderWidgetHostViewMac::DidBecomeSelected() {
306 if (!is_hidden_) 355 if (!is_hidden_)
307 return; 356 return;
308 357
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 [static_cast<AcceleratedPluginView*>(subview) 675 [static_cast<AcceleratedPluginView*>(subview)
627 onRenderWidgetHostViewGone]; 676 onRenderWidgetHostViewGone];
628 } 677 }
629 } 678 }
630 679
631 // We've been told to destroy. 680 // We've been told to destroy.
632 [cocoa_view_ retain]; 681 [cocoa_view_ retain];
633 [cocoa_view_ removeFromSuperview]; 682 [cocoa_view_ removeFromSuperview];
634 [cocoa_view_ autorelease]; 683 [cocoa_view_ autorelease];
635 684
685 [fullscreen_window_manager_ exitFullscreenMode];
686 fullscreen_window_manager_.reset();
687 [pepper_fullscreen_window_ close];
688 pepper_fullscreen_window_.reset();
689
636 // We get this call just before |render_widget_host_| deletes 690 // We get this call just before |render_widget_host_| deletes
637 // itself. But we are owned by |cocoa_view_|, which may be retained 691 // itself. But we are owned by |cocoa_view_|, which may be retained
638 // by some other code. Examples are WebContentsViewMac's 692 // by some other code. Examples are WebContentsViewMac's
639 // |latent_focus_view_| and TabWindowController's 693 // |latent_focus_view_| and TabWindowController's
640 // |cachedContentView_|. 694 // |cachedContentView_|.
641 render_widget_host_ = NULL; 695 render_widget_host_ = NULL;
642 } 696 }
643 697
644 // Called from the renderer to tell us what the tooltip text should be. It 698 // Called from the renderer to tell us what the tooltip text should be. It
645 // calls us frequently so we need to cache the value to prevent doing a lot 699 // calls us frequently so we need to cache the value to prevent doing a lot
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 } 1534 }
1481 1535
1482 // Don't cancel child popups; the key events are probably what's triggering 1536 // Don't cancel child popups; the key events are probably what's triggering
1483 // the popup in the first place. 1537 // the popup in the first place.
1484 1538
1485 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; 1539 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_;
1486 DCHECK(widgetHost); 1540 DCHECK(widgetHost);
1487 1541
1488 NativeWebKeyboardEvent event(theEvent); 1542 NativeWebKeyboardEvent event(theEvent);
1489 1543
1544 // Force fullscreen windows to close on Escape so they won't keep the keyboard
1545 // grabbed or be stuck onscreen if the renderer is hanging.
1546 if (event.type == NativeWebKeyboardEvent::RawKeyDown &&
1547 event.windowsKeyCode == ui::VKEY_ESCAPE &&
1548 renderWidgetHostView_->pepper_fullscreen_window()) {
1549 widgetHost->Shutdown();
1550 return;
1551 }
1552
1490 // We only handle key down events and just simply forward other events. 1553 // We only handle key down events and just simply forward other events.
1491 if ([theEvent type] != NSKeyDown) { 1554 if ([theEvent type] != NSKeyDown) {
1492 widgetHost->ForwardKeyboardEvent(event); 1555 widgetHost->ForwardKeyboardEvent(event);
1493 1556
1494 // Possibly autohide the cursor. 1557 // Possibly autohide the cursor.
1495 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) 1558 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent])
1496 [NSCursor setHiddenUntilMouseMoves:YES]; 1559 [NSCursor setHiddenUntilMouseMoves:YES];
1497 1560
1498 return; 1561 return;
1499 } 1562 }
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 if (!string) return NO; 2847 if (!string) return NO;
2785 2848
2786 // If the user is currently using an IME, confirm the IME input, 2849 // If the user is currently using an IME, confirm the IME input,
2787 // and then insert the text from the service, the same as TextEdit and Safari. 2850 // and then insert the text from the service, the same as TextEdit and Safari.
2788 [self confirmComposition]; 2851 [self confirmComposition];
2789 [self insertText:string]; 2852 [self insertText:string];
2790 return YES; 2853 return YES;
2791 } 2854 }
2792 2855
2793 @end 2856 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698