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 22 matching lines...) Expand all Loading... | |
33 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" | 33 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" |
34 #import "content/browser/renderer_host/text_input_client_mac.h" | 34 #import "content/browser/renderer_host/text_input_client_mac.h" |
35 #include "content/common/accessibility_messages.h" | 35 #include "content/common/accessibility_messages.h" |
36 #include "content/common/edit_command.h" | 36 #include "content/common/edit_command.h" |
37 #include "content/common/gpu/gpu_messages.h" | 37 #include "content/common/gpu/gpu_messages.h" |
38 #include "content/common/plugin_messages.h" | 38 #include "content/common/plugin_messages.h" |
39 #include "content/common/view_messages.h" | 39 #include "content/common/view_messages.h" |
40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/native_web_keyboard_event.h" | 41 #include "content/public/browser/native_web_keyboard_event.h" |
42 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 42 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
43 #include "content/public/browser/web_contents_view_delegate.h" | |
43 #include "skia/ext/platform_canvas.h" | 44 #include "skia/ext/platform_canvas.h" |
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h" |
48 #import "third_party/mozilla/ComplexTextInputPanel.h" | 49 #import "third_party/mozilla/ComplexTextInputPanel.h" |
49 #include "third_party/skia/include/core/SkColor.h" | 50 #include "third_party/skia/include/core/SkColor.h" |
51 #import "ui/base/cocoa/event_hook_application.h" | |
50 #import "ui/base/cocoa/fullscreen_window_manager.h" | 52 #import "ui/base/cocoa/fullscreen_window_manager.h" |
51 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 53 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
52 #include "ui/base/keycodes/keyboard_codes.h" | 54 #include "ui/base/keycodes/keyboard_codes.h" |
53 #include "ui/base/layout.h" | 55 #include "ui/base/layout.h" |
54 #include "ui/gfx/point.h" | 56 #include "ui/gfx/point.h" |
55 #include "ui/gfx/rect_conversions.h" | 57 #include "ui/gfx/rect_conversions.h" |
56 #include "ui/gfx/size_conversions.h" | 58 #include "ui/gfx/size_conversions.h" |
57 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 59 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
58 #include "ui/surface/io_surface_support_mac.h" | 60 #include "ui/surface/io_surface_support_mac.h" |
59 #include "webkit/plugins/npapi/webplugin.h" | 61 #include "webkit/plugins/npapi/webplugin.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 @property(nonatomic, assign) NSRange selectedRange; | 132 @property(nonatomic, assign) NSRange selectedRange; |
131 @property(nonatomic, assign) NSRange markedRange; | 133 @property(nonatomic, assign) NSRange markedRange; |
132 | 134 |
133 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 135 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
134 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 136 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
135 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 137 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
136 - (void)gotUnhandledWheelEvent; | 138 - (void)gotUnhandledWheelEvent; |
137 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | 139 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; |
138 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | 140 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; |
139 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 141 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
140 - (void)cancelChildPopups; | |
141 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 142 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
142 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 143 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
143 - (void)checkForPluginImeCancellation; | 144 - (void)checkForPluginImeCancellation; |
144 - (void)updateTabBackingStoreScaleFactor; | 145 - (void)updateTabBackingStoreScaleFactor; |
145 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 146 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
146 actualRange:(NSRangePointer)actualRange; | 147 actualRange:(NSRangePointer)actualRange; |
147 @end | 148 @end |
148 | 149 |
149 // NSEvent subtype for scroll gestures events. | 150 // NSEvent subtype for scroll gestures events. |
150 static const short kIOHIDEventTypeScroll = 6; | 151 static const short kIOHIDEventTypeScroll = 6; |
151 | 152 |
152 // A window subclass that allows the fullscreen window to become main and gain | 153 // 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 | 154 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
154 // handled by the browser. | 155 // handled by the browser. |
155 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 156 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
156 @end | 157 @end |
157 | 158 |
158 @implementation PepperFlashFullscreenWindow | 159 @implementation PepperFlashFullscreenWindow |
159 | 160 |
160 - (BOOL)canBecomeKeyWindow { | 161 - (BOOL)canBecomeKeyWindow { |
161 return YES; | 162 return YES; |
162 } | 163 } |
163 | 164 |
164 - (BOOL)canBecomeMainWindow { | 165 - (BOOL)canBecomeMainWindow { |
165 return YES; | 166 return YES; |
166 } | 167 } |
167 | 168 |
168 @end | 169 @end |
169 | 170 |
171 @interface RenderWidgetPopupWindow : NSWindow<CrEventHookProtocol> | |
172 @end | |
173 | |
174 @implementation RenderWidgetPopupWindow | |
175 | |
176 - (id)initWithContentRect:(NSRect)contentRect | |
177 styleMask:(NSUInteger)windowStyle | |
178 backing:(NSBackingStoreType)bufferingType | |
179 defer:(BOOL)deferCreation { | |
180 if (self = [super initWithContentRect:contentRect | |
181 styleMask:windowStyle | |
182 backing:bufferingType | |
183 defer:deferCreation]) { | |
184 [self setOpaque:NO]; | |
185 [self setBackgroundColor:[NSColor clearColor]]; | |
186 [self startObservingClicks]; | |
187 } | |
188 return self; | |
189 } | |
190 | |
191 - (void)close { | |
192 [self stopObservingClicks]; | |
193 [super close]; | |
194 } | |
195 | |
196 // Gets called for all events in application. Watching for a click outside the | |
197 // window so we can close. | |
198 - (void)hookForEvent:(NSEvent*)theEvent { | |
199 if ([theEvent window] == self) | |
200 return; | |
201 NSEventType eventType = [theEvent type]; | |
202 if (eventType == NSLeftMouseDown || eventType == NSRightMouseDown) | |
203 [self close]; | |
204 } | |
Avi (use Gerrit)
2012/12/13 16:04:01
You could fix WebKit to close popups on scroll eve
keishi
2012/12/14 02:23:27
Hiding popups on scroll wheel event is a webview s
| |
205 | |
206 // Gets called when the menubar is clicked. | |
207 // Needed because the hookForEvent method doesn't see the click on the menubar. | |
208 - (void)begunTracking:(NSNotification*)notification { | |
209 [self close]; | |
210 } | |
211 | |
212 // Install the callback. | |
213 - (void)startObservingClicks { | |
214 CrEventHookApplication* app = static_cast<CrEventHookApplication*>( | |
215 [CrEventHookApplication sharedApplication]); | |
216 [app addEventHook:self]; | |
217 | |
218 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | |
219 [nc addObserver:self | |
220 selector:@selector(begunTracking:) | |
221 name:NSMenuDidBeginTrackingNotification | |
222 object:[NSApp mainMenu]]; | |
223 } | |
224 | |
225 // Remove the callback. | |
226 - (void)stopObservingClicks { | |
227 CrEventHookApplication* app = static_cast<CrEventHookApplication*>( | |
228 [CrEventHookApplication sharedApplication]); | |
229 [app removeEventHook:self]; | |
230 | |
231 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | |
232 [nc removeObserver:self | |
233 name:NSMenuDidBeginTrackingNotification | |
234 object:[NSApp mainMenu]]; | |
235 } | |
236 | |
237 @end | |
238 | |
170 namespace { | 239 namespace { |
171 | 240 |
172 // Maximum number of characters we allow in a tooltip. | 241 // Maximum number of characters we allow in a tooltip. |
173 const size_t kMaxTooltipLength = 1024; | 242 const size_t kMaxTooltipLength = 1024; |
174 | 243 |
175 // TODO(suzhe): Upstream this function. | 244 // TODO(suzhe): Upstream this function. |
176 WebKit::WebColor WebColorFromNSColor(NSColor *color) { | 245 WebKit::WebColor WebColorFromNSColor(NSColor *color) { |
177 CGFloat r, g, b, a; | 246 CGFloat r, g, b, a; |
178 [color getRed:&r green:&g blue:&b alpha:&a]; | 247 [color getRed:&r green:&g blue:&b alpha:&a]; |
179 | 248 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 391 } |
323 | 392 |
324 /////////////////////////////////////////////////////////////////////////////// | 393 /////////////////////////////////////////////////////////////////////////////// |
325 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 394 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
326 | 395 |
327 void RenderWidgetHostViewMac::InitAsChild( | 396 void RenderWidgetHostViewMac::InitAsChild( |
328 gfx::NativeView parent_view) { | 397 gfx::NativeView parent_view) { |
329 } | 398 } |
330 | 399 |
331 void RenderWidgetHostViewMac::InitAsPopup( | 400 void RenderWidgetHostViewMac::InitAsPopup( |
332 RenderWidgetHostView* parent_host_view, | 401 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
333 const gfx::Rect& pos) { | |
334 bool activatable = popup_type_ == WebKit::WebPopupTypeNone; | 402 bool activatable = popup_type_ == WebKit::WebPopupTypeNone; |
335 [cocoa_view_ setCloseOnDeactivate:YES]; | 403 [cocoa_view_ setCloseOnDeactivate:YES]; |
336 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO]; | 404 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO]; |
337 [parent_host_view->GetNativeView() addSubview:cocoa_view_]; | |
338 | 405 |
339 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint()); | 406 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint()); |
340 if ([[NSScreen screens] count] > 0) { | 407 if ([[NSScreen screens] count] > 0) { |
341 origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height - | 408 origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height - |
342 pos.height() - origin_global.y; | 409 pos.height() - origin_global.y; |
343 } | 410 } |
344 NSPoint origin_window = | 411 |
345 [[cocoa_view_ window] convertScreenToBase:origin_global]; | 412 popup_window_.reset([[RenderWidgetPopupWindow alloc] |
346 NSPoint origin_view = | 413 initWithContentRect:NSMakeRect(origin_global.x, origin_global.y, |
347 [cocoa_view_ convertPoint:origin_window fromView:nil]; | 414 pos.width(), pos.height()) |
348 NSRect initial_frame = NSMakeRect(origin_view.x, | 415 styleMask:NSBorderlessWindowMask |
349 origin_view.y, | 416 backing:NSBackingStoreBuffered |
350 pos.width(), | 417 defer:NO]); |
351 pos.height()); | 418 [popup_window_ setLevel:NSPopUpMenuWindowLevel]; |
352 [cocoa_view_ setFrame:initial_frame]; | 419 [popup_window_ setReleasedWhenClosed:NO]; |
420 [popup_window_ makeKeyAndOrderFront:nil]; | |
421 [[popup_window_ contentView] addSubview:cocoa_view_]; | |
422 [cocoa_view_ setFrame:[[popup_window_ contentView] bounds]]; | |
423 [cocoa_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
424 [[NSNotificationCenter defaultCenter] | |
425 addObserver:cocoa_view_ | |
426 selector:@selector(popupWindowWillClose:) | |
427 name:NSWindowWillCloseNotification | |
428 object:popup_window_]; | |
353 } | 429 } |
354 | 430 |
355 // This function creates the fullscreen window and hides the dock and menubar if | 431 // 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 | 432 // necessary. Note, this codepath is only used for pepper flash when |
357 // pp::FlashFullScreen::SetFullscreen() is called. If | 433 // pp::FlashFullScreen::SetFullscreen() is called. If |
358 // pp::FullScreen::SetFullscreen() is called then the entire browser window | 434 // pp::FullScreen::SetFullscreen() is called then the entire browser window |
359 // will enter fullscreen instead. | 435 // will enter fullscreen instead. |
360 void RenderWidgetHostViewMac::InitAsFullscreen( | 436 void RenderWidgetHostViewMac::InitAsFullscreen( |
361 RenderWidgetHostView* reference_host_view) { | 437 RenderWidgetHostView* reference_host_view) { |
362 fullscreen_parent_host_view_ = | 438 fullscreen_parent_host_view_ = |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 if (rect.size().IsEmpty()) | 527 if (rect.size().IsEmpty()) |
452 return; | 528 return; |
453 | 529 |
454 // Ignore the position of |rect| for non-popup rwhvs. This is because | 530 // Ignore the position of |rect| for non-popup rwhvs. This is because |
455 // background tabs do not have a window, but the window is required for the | 531 // background tabs do not have a window, but the window is required for the |
456 // coordinate conversions. Popups are always for a visible tab. | 532 // coordinate conversions. Popups are always for a visible tab. |
457 if (IsPopup()) { | 533 if (IsPopup()) { |
458 // The position of |rect| is screen coordinate system and we have to | 534 // The position of |rect| is screen coordinate system and we have to |
459 // consider Cocoa coordinate system is upside-down and also multi-screen. | 535 // consider Cocoa coordinate system is upside-down and also multi-screen. |
460 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint()); | 536 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint()); |
537 NSSize size = NSMakeSize(rect.width(), rect.height()); | |
538 size = [cocoa_view_ convertSize:size toView:nil]; | |
461 if ([[NSScreen screens] count] > 0) { | 539 if ([[NSScreen screens] count] > 0) { |
462 NSSize size = NSMakeSize(rect.width(), rect.height()); | |
463 size = [cocoa_view_ convertSize:size toView:nil]; | |
464 NSScreen* screen = | 540 NSScreen* screen = |
465 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]); | 541 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]); |
466 origin_global.y = | 542 origin_global.y = |
467 NSHeight([screen frame]) - size.height - origin_global.y; | 543 NSHeight([screen frame]) - size.height - origin_global.y; |
468 } | 544 } |
469 | 545 [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y, |
470 // Then |origin_global| is converted to client coordinate system. | 546 size.width, size.height) |
471 DCHECK([cocoa_view_ window]); | 547 display:YES]; |
472 NSPoint origin_window = | |
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 { | 548 } else { |
480 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); | 549 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); |
481 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]); | 550 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]); |
482 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]]; | 551 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]]; |
483 rect2.set_width(rect.width()); | 552 rect2.set_width(rect.width()); |
484 rect2.set_height(rect.height()); | 553 rect2.set_height(rect.height()); |
485 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]]; | 554 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]]; |
486 } | 555 } |
487 } | 556 } |
488 | 557 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 // outside of themselves. On Windows, if Destroy is being called on a view, | 780 // outside of themselves. On Windows, if Destroy is being called on a view, |
712 // then the event causing the destroy had also cancelled any popups by the | 781 // then the event causing the destroy had also cancelled any popups by the |
713 // time Destroy() was called. On the Mac we have to destroy all the popups | 782 // time Destroy() was called. On the Mac we have to destroy all the popups |
714 // ourselves. | 783 // ourselves. |
715 | 784 |
716 // Depth-first destroy all popups. Use ShutdownHost() to enforce | 785 // Depth-first destroy all popups. Use ShutdownHost() to enforce |
717 // deepest-first ordering. | 786 // deepest-first ordering. |
718 for (NSView* subview in [cocoa_view_ subviews]) { | 787 for (NSView* subview in [cocoa_view_ subviews]) { |
719 if ([subview isKindOfClass:[RenderWidgetHostViewCocoa class]]) { | 788 if ([subview isKindOfClass:[RenderWidgetHostViewCocoa class]]) { |
720 [static_cast<RenderWidgetHostViewCocoa*>(subview) | 789 [static_cast<RenderWidgetHostViewCocoa*>(subview) |
721 renderWidgetHostViewMac]->ShutdownHost(); | 790 renderWidgetHostViewMac]->ShutdownHost(); |
Avi (use Gerrit)
2012/12/14 04:08:36
All the RenderWidgetHostViewCocoa objects used as
| |
722 } else if ([subview isKindOfClass:[AcceleratedPluginView class]]) { | 791 } else if ([subview isKindOfClass:[AcceleratedPluginView class]]) { |
723 [static_cast<AcceleratedPluginView*>(subview) | 792 [static_cast<AcceleratedPluginView*>(subview) |
724 onRenderWidgetHostViewGone]; | 793 onRenderWidgetHostViewGone]; |
725 } | 794 } |
726 } | 795 } |
727 | 796 |
797 [[NSNotificationCenter defaultCenter] | |
798 removeObserver:cocoa_view_ | |
799 name:NSWindowWillCloseNotification | |
800 object:popup_window_]; | |
801 | |
728 // We've been told to destroy. | 802 // We've been told to destroy. |
729 [cocoa_view_ retain]; | 803 [cocoa_view_ retain]; |
730 [cocoa_view_ removeFromSuperview]; | 804 [cocoa_view_ removeFromSuperview]; |
731 [cocoa_view_ autorelease]; | 805 [cocoa_view_ autorelease]; |
Avi (use Gerrit)
2012/12/13 16:04:01
Is it necessary to remove the view from the window
keishi
2012/12/14 02:23:27
I think cocoa_view_ is used for non popup widgets
Avi (use Gerrit)
2012/12/14 04:08:36
Ah, yes, this is the general case Destroy.
| |
732 | 806 |
807 [popup_window_ close]; | |
808 popup_window_.autorelease(); | |
809 | |
733 [fullscreen_window_manager_ exitFullscreenMode]; | 810 [fullscreen_window_manager_ exitFullscreenMode]; |
734 fullscreen_window_manager_.reset(); | 811 fullscreen_window_manager_.reset(); |
735 [pepper_fullscreen_window_ close]; | 812 [pepper_fullscreen_window_ close]; |
736 | 813 |
737 // This can be called as part of processing the window's responder | 814 // This can be called as part of processing the window's responder |
738 // chain, for instance |-performKeyEquivalent:|. In that case the | 815 // chain, for instance |-performKeyEquivalent:|. In that case the |
739 // object needs to survive until the stack unwinds. | 816 // object needs to survive until the stack unwinds. |
740 pepper_fullscreen_window_.autorelease(); | 817 pepper_fullscreen_window_.autorelease(); |
741 | 818 |
742 // We get this call just before |render_widget_host_| deletes | 819 // We get this call just before |render_widget_host_| deletes |
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2095 widgetHost->ForwardKeyboardEvent(event); | 2172 widgetHost->ForwardKeyboardEvent(event); |
2096 } | 2173 } |
2097 } | 2174 } |
2098 | 2175 |
2099 // Possibly autohide the cursor. | 2176 // Possibly autohide the cursor. |
2100 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2177 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
2101 [NSCursor setHiddenUntilMouseMoves:YES]; | 2178 [NSCursor setHiddenUntilMouseMoves:YES]; |
2102 } | 2179 } |
2103 | 2180 |
2104 - (void)scrollWheel:(NSEvent*)theEvent { | 2181 - (void)scrollWheel:(NSEvent*)theEvent { |
2105 // Cancel popups before calling the delegate because even if the delegate eats | |
2106 // the event, it's still an explicit user action outside the popup. | |
2107 [self cancelChildPopups]; | |
2108 | |
2109 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { | 2182 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { |
2110 BOOL handled = [delegate_ handleEvent:theEvent]; | 2183 BOOL handled = [delegate_ handleEvent:theEvent]; |
2111 if (handled) | 2184 if (handled) |
2112 return; | 2185 return; |
2113 } | 2186 } |
2114 | 2187 |
2115 const WebMouseWheelEvent& event = | 2188 const WebMouseWheelEvent& event = |
2116 WebInputEventFactory::mouseWheelEvent(theEvent, self); | 2189 WebInputEventFactory::mouseWheelEvent(theEvent, self); |
2117 if (renderWidgetHostView_->render_widget_host_) | 2190 if (renderWidgetHostView_->render_widget_host_) |
2118 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(event); | 2191 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(event); |
2119 } | 2192 } |
2120 | 2193 |
2121 // See the comment in RenderWidgetHostViewMac::Destroy() about cancellation | |
2122 // events. On the Mac we must kill popups on outside events, thus this lovely | |
2123 // case of filicide caused by events on parent views. | |
2124 - (void)cancelChildPopups { | |
2125 // If this view can be the key view, it is not a popup. Therefore, if it has | |
2126 // any children, they are popups that need to be canceled. | |
2127 if (canBeKeyView_) { | |
2128 for (NSView* subview in [self subviews]) { | |
2129 if (![subview isKindOfClass:[RenderWidgetHostViewCocoa class]]) | |
2130 continue; // Skip plugin views. | |
2131 | |
2132 [static_cast<RenderWidgetHostViewCocoa*>(subview) | |
2133 renderWidgetHostViewMac]->KillSelf(); | |
2134 } | |
2135 } | |
2136 } | |
2137 | |
2138 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 2194 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
2139 // We're messing with the window, so do this to ensure no flashes. This one | 2195 // We're messing with the window, so do this to ensure no flashes. This one |
2140 // prevents a flash when the current tab is closed. | 2196 // prevents a flash when the current tab is closed. |
2141 NSWindow* oldWindow = [self window]; | 2197 NSWindow* oldWindow = [self window]; |
2142 [oldWindow disableScreenUpdatesUntilFlush]; | 2198 [oldWindow disableScreenUpdatesUntilFlush]; |
2143 | 2199 |
2144 NSNotificationCenter* notificationCenter = | 2200 NSNotificationCenter* notificationCenter = |
2145 [NSNotificationCenter defaultCenter]; | 2201 [NSNotificationCenter defaultCenter]; |
2146 if (oldWindow) { | 2202 if (oldWindow) { |
2147 [notificationCenter | 2203 [notificationCenter |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3346 } | 3402 } |
3347 | 3403 |
3348 - (void)updateCursor:(NSCursor*)cursor { | 3404 - (void)updateCursor:(NSCursor*)cursor { |
3349 if (currentCursor_ == cursor) | 3405 if (currentCursor_ == cursor) |
3350 return; | 3406 return; |
3351 | 3407 |
3352 currentCursor_.reset(cursor, base::scoped_policy::RETAIN); | 3408 currentCursor_.reset(cursor, base::scoped_policy::RETAIN); |
3353 [[self window] invalidateCursorRectsForView:self]; | 3409 [[self window] invalidateCursorRectsForView:self]; |
3354 } | 3410 } |
3355 | 3411 |
3412 - (void)popupWindowWillClose:(NSNotification *)notification { | |
3413 renderWidgetHostView_->KillSelf(); | |
3414 } | |
3415 | |
3356 @end | 3416 @end |
3357 | 3417 |
3358 // | 3418 // |
3359 // Supporting application services | 3419 // Supporting application services |
3360 // | 3420 // |
3361 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) | 3421 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) |
3362 | 3422 |
3363 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard | 3423 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard |
3364 types:(NSArray*)types { | 3424 types:(NSArray*)types { |
3365 const std::string& str = renderWidgetHostView_->selected_text(); | 3425 const std::string& str = renderWidgetHostView_->selected_text(); |
(...skipping 11 matching lines...) Expand all Loading... | |
3377 if (!string) return NO; | 3437 if (!string) return NO; |
3378 | 3438 |
3379 // If the user is currently using an IME, confirm the IME input, | 3439 // 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. | 3440 // and then insert the text from the service, the same as TextEdit and Safari. |
3381 [self confirmComposition]; | 3441 [self confirmComposition]; |
3382 [self insertText:string]; | 3442 [self insertText:string]; |
3383 return YES; | 3443 return YES; |
3384 } | 3444 } |
3385 | 3445 |
3386 @end | 3446 @end |
OLD | NEW |