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

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: test Created 8 years, 9 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 26 matching lines...) Expand all
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/native_web_keyboard_event.h" 38 #include "content/public/browser/native_web_keyboard_event.h"
39 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 39 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
40 #include "skia/ext/platform_canvas.h" 40 #include "skia/ext/platform_canvas.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h"
45 #import "third_party/mozilla/ComplexTextInputPanel.h" 45 #import "third_party/mozilla/ComplexTextInputPanel.h"
46 #include "third_party/skia/include/core/SkColor.h" 46 #include "third_party/skia/include/core/SkColor.h"
47 #import "ui/base/cocoa/fullscreen_window_manager.h"
48 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
47 #include "ui/gfx/point.h" 49 #include "ui/gfx/point.h"
48 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 50 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
49 #include "ui/gfx/surface/io_surface_support_mac.h" 51 #include "ui/gfx/surface/io_surface_support_mac.h"
50 #include "webkit/glue/webaccessibility.h" 52 #include "webkit/glue/webaccessibility.h"
51 #include "webkit/plugins/npapi/webplugin.h" 53 #include "webkit/plugins/npapi/webplugin.h"
52 54
53 using content::BrowserThread; 55 using content::BrowserThread;
54 using content::RenderWidgetHostView; 56 using content::RenderWidgetHostView;
55 using WebKit::WebInputEvent; 57 using WebKit::WebInputEvent;
56 using WebKit::WebInputEventFactory; 58 using WebKit::WebInputEventFactory;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; 112 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right;
111 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; 113 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar;
112 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 114 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
113 - (void)cancelChildPopups; 115 - (void)cancelChildPopups;
114 - (void)checkForPluginImeCancellation; 116 - (void)checkForPluginImeCancellation;
115 @end 117 @end
116 118
117 // NSEvent subtype for scroll gestures events. 119 // NSEvent subtype for scroll gestures events.
118 static const short kIOHIDEventTypeScroll = 6; 120 static const short kIOHIDEventTypeScroll = 6;
119 121
122 // A window subclass that allows the fullscreen window to become main and gain
123 // keyboard focus. This is only used for pepper flash. Normal fullscreen is
124 // handled by the browser.
125 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow
126 @end
127
128 @implementation PepperFlashFullscreenWindow
129
130 - (BOOL)canBecomeKeyWindow {
131 return YES;
132 }
133
134 - (BOOL)canBecomeMainWindow {
135 return YES;
136 }
137
138 @end
139
140
120 namespace { 141 namespace {
121 142
122 // Maximum number of characters we allow in a tooltip. 143 // Maximum number of characters we allow in a tooltip.
123 const size_t kMaxTooltipLength = 1024; 144 const size_t kMaxTooltipLength = 1024;
124 145
125 // TODO(suzhe): Upstream this function. 146 // TODO(suzhe): Upstream this function.
126 WebKit::WebColor WebColorFromNSColor(NSColor *color) { 147 WebKit::WebColor WebColorFromNSColor(NSColor *color) {
127 CGFloat r, g, b, a; 148 CGFloat r, g, b, a;
128 [color getRed:&r green:&g blue:&b alpha:&a]; 149 [color getRed:&r green:&g blue:&b alpha:&a];
129 150
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 NSPoint origin_view = 307 NSPoint origin_view =
287 [cocoa_view_ convertPoint:origin_window fromView:nil]; 308 [cocoa_view_ convertPoint:origin_window fromView:nil];
288 NSRect initial_frame = NSMakeRect(origin_view.x, 309 NSRect initial_frame = NSMakeRect(origin_view.x,
289 origin_view.y, 310 origin_view.y,
290 pos.width(), 311 pos.width(),
291 pos.height()); 312 pos.height());
292 [cocoa_view_ setFrame:initial_frame]; 313 [cocoa_view_ setFrame:initial_frame];
293 } 314 }
294 315
295 void RenderWidgetHostViewMac::InitAsFullscreen( 316 void RenderWidgetHostViewMac::InitAsFullscreen(
296 RenderWidgetHostView* /*reference_host_view*/) { 317 RenderWidgetHostView* reference_host_view) {
297 NOTIMPLEMENTED() << "Full screen not implemented on Mac"; 318 NSWindow* parent_window = nil;
319 if (reference_host_view)
320 parent_window = [reference_host_view->GetNativeView() window];
321 NSScreen* screen = [parent_window screen];
322 if (!screen)
323 screen = [NSScreen mainScreen];
324
325 NSRect rect = [screen frame];
326 NSRect content_rect = NSMakeRect(0, 0, NSWidth(rect), NSHeight(rect));
Nico 2012/03/23 22:13:27 Doesn't (x, y) have to be NSMinX(), NSMinY()?
sail 2012/03/23 23:05:32 Ooops. Fixed.
327
328 fullscreen_window_.reset([[PepperFlashFullscreenWindow alloc]
329 initWithContentRect:content_rect
330 styleMask:NSBorderlessWindowMask
331 backing:NSBackingStoreBuffered
332 defer:NO]);
333 [fullscreen_window_ setLevel:NSFloatingWindowLevel];
334 [fullscreen_window_ setReleasedWhenClosed:NO];
335 [cocoa_view_ setCanBeKeyView:YES];
336 [cocoa_view_ setFrame:content_rect];
337 [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
338 [[fullscreen_window_ contentView] addSubview:cocoa_view_];
339
340 fullscreen_window_manager_.reset([[FullscreenWindowManager alloc]
341 initWithWindow:fullscreen_window_.get()
342 desiredScreen:screen]);
343 [fullscreen_window_manager_ enterFullscreenMode];
344 [fullscreen_window_ makeKeyAndOrderFront:nil];
298 } 345 }
299 346
300 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { 347 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
301 return render_widget_host_; 348 return render_widget_host_;
302 } 349 }
303 350
304 void RenderWidgetHostViewMac::DidBecomeSelected() { 351 void RenderWidgetHostViewMac::DidBecomeSelected() {
305 if (!is_hidden_) 352 if (!is_hidden_)
306 return; 353 return;
307 354
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 [static_cast<AcceleratedPluginView*>(subview) 672 [static_cast<AcceleratedPluginView*>(subview)
626 onRenderWidgetHostViewGone]; 673 onRenderWidgetHostViewGone];
627 } 674 }
628 } 675 }
629 676
630 // We've been told to destroy. 677 // We've been told to destroy.
631 [cocoa_view_ retain]; 678 [cocoa_view_ retain];
632 [cocoa_view_ removeFromSuperview]; 679 [cocoa_view_ removeFromSuperview];
633 [cocoa_view_ autorelease]; 680 [cocoa_view_ autorelease];
634 681
682 [fullscreen_window_manager_ exitFullscreenMode];
683 fullscreen_window_manager_.reset();
684 [fullscreen_window_ close];
685 fullscreen_window_.reset();
686
635 // We get this call just before |render_widget_host_| deletes 687 // We get this call just before |render_widget_host_| deletes
636 // itself. But we are owned by |cocoa_view_|, which may be retained 688 // itself. But we are owned by |cocoa_view_|, which may be retained
637 // by some other code. Examples are WebContentsViewMac's 689 // by some other code. Examples are WebContentsViewMac's
638 // |latent_focus_view_| and TabWindowController's 690 // |latent_focus_view_| and TabWindowController's
639 // |cachedContentView_|. 691 // |cachedContentView_|.
640 render_widget_host_ = NULL; 692 render_widget_host_ = NULL;
641 } 693 }
642 694
643 // Called from the renderer to tell us what the tooltip text should be. It 695 // Called from the renderer to tell us what the tooltip text should be. It
644 // calls us frequently so we need to cache the value to prevent doing a lot 696 // calls us frequently so we need to cache the value to prevent doing a lot
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 } 1514 }
1463 1515
1464 // Don't cancel child popups; the key events are probably what's triggering 1516 // Don't cancel child popups; the key events are probably what's triggering
1465 // the popup in the first place. 1517 // the popup in the first place.
1466 1518
1467 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; 1519 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_;
1468 DCHECK(widgetHost); 1520 DCHECK(widgetHost);
1469 1521
1470 NativeWebKeyboardEvent event(theEvent); 1522 NativeWebKeyboardEvent event(theEvent);
1471 1523
1524 // When Escape is pressed, force fullscreen windows to close.
1525 if (event.type == NativeWebKeyboardEvent::RawKeyDown &&
1526 event.windowsKeyCode == ui::VKEY_ESCAPE &&
1527 renderWidgetHostView_->fullscreen_window()) {
1528 widgetHost->Shutdown();
1529 return;
1530 }
1531
1472 // We only handle key down events and just simply forward other events. 1532 // We only handle key down events and just simply forward other events.
1473 if ([theEvent type] != NSKeyDown) { 1533 if ([theEvent type] != NSKeyDown) {
1474 widgetHost->ForwardKeyboardEvent(event); 1534 widgetHost->ForwardKeyboardEvent(event);
1475 1535
1476 // Possibly autohide the cursor. 1536 // Possibly autohide the cursor.
1477 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) 1537 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent])
1478 [NSCursor setHiddenUntilMouseMoves:YES]; 1538 [NSCursor setHiddenUntilMouseMoves:YES];
1479 1539
1480 return; 1540 return;
1481 } 1541 }
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 if (!string) return NO; 2827 if (!string) return NO;
2768 2828
2769 // If the user is currently using an IME, confirm the IME input, 2829 // If the user is currently using an IME, confirm the IME input,
2770 // and then insert the text from the service, the same as TextEdit and Safari. 2830 // and then insert the text from the service, the same as TextEdit and Safari.
2771 [self confirmComposition]; 2831 [self confirmComposition];
2772 [self insertText:string]; 2832 [self insertText:string];
2773 return YES; 2833 return YES;
2774 } 2834 }
2775 2835
2776 @end 2836 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698