Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 fullscreen_window_.reset([[PepperFlashFullscreenWindow alloc] | |
| 326 initWithContentRect:[screen frame] | |
| 327 styleMask:NSBorderlessWindowMask | |
| 328 backing:NSBackingStoreBuffered | |
|
Robert Sesek
2012/03/27 19:47:50
nit: align colons
sail
2012/03/27 20:19:51
Done.
| |
| 329 defer:NO]); | |
| 330 [fullscreen_window_ setLevel:NSFloatingWindowLevel]; | |
| 331 [fullscreen_window_ setReleasedWhenClosed:NO]; | |
| 332 [cocoa_view_ setCanBeKeyView:YES]; | |
| 333 [cocoa_view_ setFrame:[[fullscreen_window_ contentView] bounds]]; | |
| 334 [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
| 335 [[fullscreen_window_ contentView] addSubview:cocoa_view_]; | |
| 336 | |
| 337 fullscreen_window_manager_.reset([[FullscreenWindowManager alloc] | |
| 338 initWithWindow:fullscreen_window_.get() | |
| 339 desiredScreen:screen]); | |
| 340 [fullscreen_window_manager_ enterFullscreenMode]; | |
| 341 [fullscreen_window_ makeKeyAndOrderFront:nil]; | |
| 298 } | 342 } |
| 299 | 343 |
| 300 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 344 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
| 301 return render_widget_host_; | 345 return render_widget_host_; |
| 302 } | 346 } |
| 303 | 347 |
| 304 void RenderWidgetHostViewMac::DidBecomeSelected() { | 348 void RenderWidgetHostViewMac::DidBecomeSelected() { |
| 305 if (!is_hidden_) | 349 if (!is_hidden_) |
| 306 return; | 350 return; |
| 307 | 351 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 [static_cast<AcceleratedPluginView*>(subview) | 669 [static_cast<AcceleratedPluginView*>(subview) |
| 626 onRenderWidgetHostViewGone]; | 670 onRenderWidgetHostViewGone]; |
| 627 } | 671 } |
| 628 } | 672 } |
| 629 | 673 |
| 630 // We've been told to destroy. | 674 // We've been told to destroy. |
| 631 [cocoa_view_ retain]; | 675 [cocoa_view_ retain]; |
| 632 [cocoa_view_ removeFromSuperview]; | 676 [cocoa_view_ removeFromSuperview]; |
| 633 [cocoa_view_ autorelease]; | 677 [cocoa_view_ autorelease]; |
| 634 | 678 |
| 679 [fullscreen_window_manager_ exitFullscreenMode]; | |
| 680 fullscreen_window_manager_.reset(); | |
| 681 [fullscreen_window_ close]; | |
| 682 fullscreen_window_.reset(); | |
| 683 | |
| 635 // We get this call just before |render_widget_host_| deletes | 684 // We get this call just before |render_widget_host_| deletes |
| 636 // itself. But we are owned by |cocoa_view_|, which may be retained | 685 // itself. But we are owned by |cocoa_view_|, which may be retained |
| 637 // by some other code. Examples are WebContentsViewMac's | 686 // by some other code. Examples are WebContentsViewMac's |
| 638 // |latent_focus_view_| and TabWindowController's | 687 // |latent_focus_view_| and TabWindowController's |
| 639 // |cachedContentView_|. | 688 // |cachedContentView_|. |
| 640 render_widget_host_ = NULL; | 689 render_widget_host_ = NULL; |
| 641 } | 690 } |
| 642 | 691 |
| 643 // Called from the renderer to tell us what the tooltip text should be. It | 692 // 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 | 693 // 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 Loading... | |
| 1462 } | 1511 } |
| 1463 | 1512 |
| 1464 // Don't cancel child popups; the key events are probably what's triggering | 1513 // Don't cancel child popups; the key events are probably what's triggering |
| 1465 // the popup in the first place. | 1514 // the popup in the first place. |
| 1466 | 1515 |
| 1467 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; | 1516 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; |
| 1468 DCHECK(widgetHost); | 1517 DCHECK(widgetHost); |
| 1469 | 1518 |
| 1470 NativeWebKeyboardEvent event(theEvent); | 1519 NativeWebKeyboardEvent event(theEvent); |
| 1471 | 1520 |
| 1521 // When Escape is pressed, force fullscreen windows to close. | |
| 1522 if (event.type == NativeWebKeyboardEvent::RawKeyDown && | |
| 1523 event.windowsKeyCode == ui::VKEY_ESCAPE && | |
| 1524 renderWidgetHostView_->fullscreen_window()) { | |
| 1525 widgetHost->Shutdown(); | |
| 1526 return; | |
| 1527 } | |
| 1528 | |
| 1472 // We only handle key down events and just simply forward other events. | 1529 // We only handle key down events and just simply forward other events. |
| 1473 if ([theEvent type] != NSKeyDown) { | 1530 if ([theEvent type] != NSKeyDown) { |
| 1474 widgetHost->ForwardKeyboardEvent(event); | 1531 widgetHost->ForwardKeyboardEvent(event); |
| 1475 | 1532 |
| 1476 // Possibly autohide the cursor. | 1533 // Possibly autohide the cursor. |
| 1477 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 1534 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
| 1478 [NSCursor setHiddenUntilMouseMoves:YES]; | 1535 [NSCursor setHiddenUntilMouseMoves:YES]; |
| 1479 | 1536 |
| 1480 return; | 1537 return; |
| 1481 } | 1538 } |
| (...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2767 if (!string) return NO; | 2824 if (!string) return NO; |
| 2768 | 2825 |
| 2769 // If the user is currently using an IME, confirm the IME input, | 2826 // 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. | 2827 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2771 [self confirmComposition]; | 2828 [self confirmComposition]; |
| 2772 [self insertText:string]; | 2829 [self insertText:string]; |
| 2773 return YES; | 2830 return YES; |
| 2774 } | 2831 } |
| 2775 | 2832 |
| 2776 @end | 2833 @end |
| OLD | NEW |