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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #import "third_party/mozilla/ComplexTextInputPanel.h" | 48 #import "third_party/mozilla/ComplexTextInputPanel.h" |
49 #include "third_party/skia/include/core/SkColor.h" | 49 #include "third_party/skia/include/core/SkColor.h" |
50 #import "ui/base/cocoa/fullscreen_window_manager.h" | 50 #import "ui/base/cocoa/fullscreen_window_manager.h" |
51 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 51 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
52 #include "ui/base/keycodes/keyboard_codes.h" | 52 #include "ui/base/keycodes/keyboard_codes.h" |
53 #include "ui/base/layout.h" | 53 #include "ui/base/layout.h" |
54 #include "ui/gfx/point.h" | 54 #include "ui/gfx/point.h" |
55 #include "ui/gfx/rect_conversions.h" | 55 #include "ui/gfx/rect_conversions.h" |
56 #include "ui/gfx/size_conversions.h" | 56 #include "ui/gfx/size_conversions.h" |
57 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 57 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
58 #include "ui/gfx/native_widget_types.h" | |
58 #include "ui/surface/io_surface_support_mac.h" | 59 #include "ui/surface/io_surface_support_mac.h" |
59 #include "webkit/plugins/npapi/webplugin.h" | 60 #include "webkit/plugins/npapi/webplugin.h" |
61 #include "content/public/browser/web_contents_view_delegate.h" | |
Avi (use Gerrit)
2012/12/10 20:52:06
alphabetical
keishi
2012/12/11 05:09:14
Done.
| |
60 | 62 |
61 using content::BackingStoreMac; | 63 using content::BackingStoreMac; |
62 using content::BrowserAccessibility; | 64 using content::BrowserAccessibility; |
63 using content::BrowserAccessibilityManager; | 65 using content::BrowserAccessibilityManager; |
64 using content::EditCommand; | 66 using content::EditCommand; |
65 using content::NativeWebKeyboardEvent; | 67 using content::NativeWebKeyboardEvent; |
66 using content::RenderViewHostImpl; | 68 using content::RenderViewHostImpl; |
67 using content::RenderWidgetHostImpl; | 69 using content::RenderWidgetHostImpl; |
68 using content::RenderWidgetHostViewMac; | 70 using content::RenderWidgetHostViewMac; |
69 using content::RenderWidgetHostViewMacEditCommandHelper; | 71 using content::RenderWidgetHostViewMacEditCommandHelper; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 141 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
140 - (void)cancelChildPopups; | 142 - (void)cancelChildPopups; |
141 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 143 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
142 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 144 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
143 - (void)checkForPluginImeCancellation; | 145 - (void)checkForPluginImeCancellation; |
144 - (void)updateTabBackingStoreScaleFactor; | 146 - (void)updateTabBackingStoreScaleFactor; |
145 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 147 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
146 actualRange:(NSRangePointer)actualRange; | 148 actualRange:(NSRangePointer)actualRange; |
147 @end | 149 @end |
148 | 150 |
151 | |
Avi (use Gerrit)
2012/12/10 20:52:06
stray return
keishi
2012/12/11 05:09:14
Done.
| |
149 // NSEvent subtype for scroll gestures events. | 152 // NSEvent subtype for scroll gestures events. |
150 static const short kIOHIDEventTypeScroll = 6; | 153 static const short kIOHIDEventTypeScroll = 6; |
151 | 154 |
152 // A window subclass that allows the fullscreen window to become main and gain | 155 // A window subclass that allows the fullscreen window to become main and gain |
153 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 156 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
154 // handled by the browser. | 157 // handled by the browser. |
155 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 158 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
156 @end | 159 @end |
157 | 160 |
158 @implementation PepperFlashFullscreenWindow | 161 @implementation PepperFlashFullscreenWindow |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 326 |
324 /////////////////////////////////////////////////////////////////////////////// | 327 /////////////////////////////////////////////////////////////////////////////// |
325 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 328 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
326 | 329 |
327 void RenderWidgetHostViewMac::InitAsChild( | 330 void RenderWidgetHostViewMac::InitAsChild( |
328 gfx::NativeView parent_view) { | 331 gfx::NativeView parent_view) { |
329 } | 332 } |
330 | 333 |
331 void RenderWidgetHostViewMac::InitAsPopup( | 334 void RenderWidgetHostViewMac::InitAsPopup( |
332 RenderWidgetHostView* parent_host_view, | 335 RenderWidgetHostView* parent_host_view, |
333 const gfx::Rect& pos) { | 336 const gfx::Rect& pos, |
337 WebContentsViewDelegate* delegate) { | |
334 bool activatable = popup_type_ == WebKit::WebPopupTypeNone; | 338 bool activatable = popup_type_ == WebKit::WebPopupTypeNone; |
335 [cocoa_view_ setCloseOnDeactivate:YES]; | 339 [cocoa_view_ setCloseOnDeactivate:YES]; |
336 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO]; | 340 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO]; |
337 [parent_host_view->GetNativeView() addSubview:cocoa_view_]; | 341 [parent_host_view->GetNativeView() addSubview:cocoa_view_]; |
338 | 342 |
339 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint()); | 343 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint()); |
340 if ([[NSScreen screens] count] > 0) { | 344 if ([[NSScreen screens] count] > 0) { |
341 origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height - | 345 origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height - |
342 pos.height() - origin_global.y; | 346 pos.height() - origin_global.y; |
343 } | 347 } |
344 NSPoint origin_window = | 348 |
345 [[cocoa_view_ window] convertScreenToBase:origin_global]; | 349 popup_window_.reset(delegate->CreatePopupWindow()); |
346 NSPoint origin_view = | 350 [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y, |
347 [cocoa_view_ convertPoint:origin_window fromView:nil]; | 351 pos.width(), pos.height()) display:YES]; |
Avi (use Gerrit)
2012/12/10 20:52:06
Wrap "display:YES" to the next line; it gets lost
keishi
2012/12/11 05:09:14
Done.
| |
348 NSRect initial_frame = NSMakeRect(origin_view.x, | 352 [popup_window_ setLevel:NSPopUpMenuWindowLevel]; |
349 origin_view.y, | 353 [popup_window_ setReleasedWhenClosed:NO]; |
350 pos.width(), | 354 |
351 pos.height()); | 355 [cocoa_view_ setCanBeKeyView:YES]; |
Avi (use Gerrit)
2012/12/10 20:52:06
It seems silly to me to call -setCanBeKeyView abov
keishi
2012/12/11 05:09:14
Done.
| |
352 [cocoa_view_ setFrame:initial_frame]; | 356 [cocoa_view_ setFrame:[[popup_window_ contentView] bounds]]; |
357 [popup_window_ makeKeyAndOrderFront:nil]; | |
358 [[popup_window_ contentView] addSubview:cocoa_view_]; | |
Avi (use Gerrit)
2012/12/10 20:52:06
You may want to set the bindings on the cocoa_view
keishi
2012/12/11 05:09:14
Done.
| |
359 [popup_window_ setParentWindow:[parent_host_view->GetNativeView() window]]; | |
353 } | 360 } |
354 | 361 |
355 // This function creates the fullscreen window and hides the dock and menubar if | 362 // This function creates the fullscreen window and hides the dock and menubar if |
356 // necessary. Note, this codepath is only used for pepper flash when | 363 // necessary. Note, this codepath is only used for pepper flash when |
357 // pp::FlashFullScreen::SetFullscreen() is called. If | 364 // pp::FlashFullScreen::SetFullscreen() is called. If |
358 // pp::FullScreen::SetFullscreen() is called then the entire browser window | 365 // pp::FullScreen::SetFullscreen() is called then the entire browser window |
359 // will enter fullscreen instead. | 366 // will enter fullscreen instead. |
360 void RenderWidgetHostViewMac::InitAsFullscreen( | 367 void RenderWidgetHostViewMac::InitAsFullscreen( |
361 RenderWidgetHostView* reference_host_view) { | 368 RenderWidgetHostView* reference_host_view) { |
362 fullscreen_parent_host_view_ = | 369 fullscreen_parent_host_view_ = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 // consider Cocoa coordinate system is upside-down and also multi-screen. | 466 // consider Cocoa coordinate system is upside-down and also multi-screen. |
460 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint()); | 467 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint()); |
461 if ([[NSScreen screens] count] > 0) { | 468 if ([[NSScreen screens] count] > 0) { |
462 NSSize size = NSMakeSize(rect.width(), rect.height()); | 469 NSSize size = NSMakeSize(rect.width(), rect.height()); |
463 size = [cocoa_view_ convertSize:size toView:nil]; | 470 size = [cocoa_view_ convertSize:size toView:nil]; |
464 NSScreen* screen = | 471 NSScreen* screen = |
465 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]); | 472 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]); |
466 origin_global.y = | 473 origin_global.y = |
467 NSHeight([screen frame]) - size.height - origin_global.y; | 474 NSHeight([screen frame]) - size.height - origin_global.y; |
468 } | 475 } |
469 | 476 [cocoa_view_ setFrame:NSMakeRect(0.0, 0.0, rect.width(), rect.height())]; |
470 // Then |origin_global| is converted to client coordinate system. | 477 [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y, |
471 DCHECK([cocoa_view_ window]); | 478 rect.width(), rect.height()) |
472 NSPoint origin_window = | 479 display:YES]; |
Avi (use Gerrit)
2012/12/10 20:52:06
This is wrong because rect.size() is in view coord
keishi
2012/12/11 05:09:14
When will a view size and a screen size be differe
Avi (use Gerrit)
2012/12/11 05:14:20
Yes, the primary time they differ is on hi-dpi scr
| |
473 [[cocoa_view_ window] convertScreenToBase:origin_global]; | |
474 NSPoint origin_view = | |
475 [[cocoa_view_ superview] convertPoint:origin_window fromView:nil]; | |
476 NSRect frame = NSMakeRect(origin_view.x, origin_view.y, | |
477 rect.width(), rect.height()); | |
478 [cocoa_view_ setFrame:frame]; | |
479 } else { | 480 } else { |
480 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); | 481 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); |
481 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]); | 482 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]); |
482 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]]; | 483 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]]; |
483 rect2.set_width(rect.width()); | 484 rect2.set_width(rect.width()); |
484 rect2.set_height(rect.height()); | 485 rect2.set_height(rect.height()); |
485 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]]; | 486 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]]; |
486 } | 487 } |
487 } | 488 } |
488 | 489 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 [static_cast<AcceleratedPluginView*>(subview) | 724 [static_cast<AcceleratedPluginView*>(subview) |
724 onRenderWidgetHostViewGone]; | 725 onRenderWidgetHostViewGone]; |
725 } | 726 } |
726 } | 727 } |
727 | 728 |
728 // We've been told to destroy. | 729 // We've been told to destroy. |
729 [cocoa_view_ retain]; | 730 [cocoa_view_ retain]; |
730 [cocoa_view_ removeFromSuperview]; | 731 [cocoa_view_ removeFromSuperview]; |
731 [cocoa_view_ autorelease]; | 732 [cocoa_view_ autorelease]; |
732 | 733 |
734 [popup_window_ close]; | |
735 popup_window_.autorelease(); | |
736 | |
733 [fullscreen_window_manager_ exitFullscreenMode]; | 737 [fullscreen_window_manager_ exitFullscreenMode]; |
734 fullscreen_window_manager_.reset(); | 738 fullscreen_window_manager_.reset(); |
735 [pepper_fullscreen_window_ close]; | 739 [pepper_fullscreen_window_ close]; |
736 | 740 |
737 // This can be called as part of processing the window's responder | 741 // This can be called as part of processing the window's responder |
738 // chain, for instance |-performKeyEquivalent:|. In that case the | 742 // chain, for instance |-performKeyEquivalent:|. In that case the |
739 // object needs to survive until the stack unwinds. | 743 // object needs to survive until the stack unwinds. |
740 pepper_fullscreen_window_.autorelease(); | 744 pepper_fullscreen_window_.autorelease(); |
741 | 745 |
742 // We get this call just before |render_widget_host_| deletes | 746 // We get this call just before |render_widget_host_| deletes |
(...skipping 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3377 if (!string) return NO; | 3381 if (!string) return NO; |
3378 | 3382 |
3379 // If the user is currently using an IME, confirm the IME input, | 3383 // If the user is currently using an IME, confirm the IME input, |
3380 // and then insert the text from the service, the same as TextEdit and Safari. | 3384 // and then insert the text from the service, the same as TextEdit and Safari. |
3381 [self confirmComposition]; | 3385 [self confirmComposition]; |
3382 [self insertText:string]; | 3386 [self insertText:string]; |
3383 return YES; | 3387 return YES; |
3384 } | 3388 } |
3385 | 3389 |
3386 @end | 3390 @end |
OLD | NEW |