diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 01:22:27 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 01:22:27 +0000 |
commit | 8951767d9e03f6c2bdfdc4841a3e45a6697de566 (patch) | |
tree | b5f74b14e60a04cb52445c044ee9cc6ee11bc302 /chrome/browser/renderer_host | |
parent | b7f4422f074031c809e60f873cbb51e553b3bbca (diff) | |
download | chromium_src-8951767d9e03f6c2bdfdc4841a3e45a6697de566.zip chromium_src-8951767d9e03f6c2bdfdc4841a3e45a6697de566.tar.gz chromium_src-8951767d9e03f6c2bdfdc4841a3e45a6697de566.tar.bz2 |
[Mac] Don't route mouse events to the render view host if window is not frontmost.
This change makes Mac Chrome match the behaviour of other browsers on the Mac
(tested Firefox and Safari) as well as other Mac applications such as iTunes.
Additionally, this fixes a number of bugs, including:
- Mouse cursor changing when hovering over web content in background windows
yet clicks in this case would be eaten to bring the window to the front.
- Mouse cursor NOT changing when hovering web content in background windows when
Chrome is not the active application - resulting in inconsistent behaviour.
- http://crbug.com/77928 - resulting in wrong cursor persisting after moving out
of the web content area of a background window.
Also, change related unit tests to make the test window the keyWindow so that the
tests continue to pass.
BUG=77928
TEST=Open two windows, A and B. Open a webpage in A, then make B the foreground
window. Now, hover the cursor over web content in A. The cursor should not
change and mouse-over actions should not occur.
R=mark@chromium.org
Review URL: http://codereview.chromium.org/6720023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80563 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 36 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm | 10 |
2 files changed, 30 insertions, 16 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 0954456..dadf293 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -1456,7 +1456,12 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { closeOnDeactivate_ = b; } -- (void)mouseEvent:(NSEvent*)theEvent { +- (BOOL)shouldIgnoreMouseEvent:(NSEvent*)theEvent { + // If this is a background window, don't handle mouse events. This is + // the expected behavior on the Mac as evidenced by other applications. + if (![[self window] isKeyWindow]) + return YES; + // Use hitTest to check whether the mouse is over a nonWebContentView - in // which case the mouse event should not be handled by the render host. const SEL nonWebContentViewSelector = @selector(nonWebContentView); @@ -1469,21 +1474,26 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { if ([view respondsToSelector:nonWebContentViewSelector] && [view performSelector:nonWebContentViewSelector]) { // The cursor is over a nonWebContentView - ignore this mouse event. - // If this is the first such event, send a mouse exit to the host view. - if (!mouseEventWasIgnored_ && - renderWidgetHostView_->render_widget_host_) { - WebMouseEvent exitEvent = - WebInputEventFactory::mouseEvent(theEvent, self); - exitEvent.type = WebInputEvent::MouseLeave; - exitEvent.button = WebMouseEvent::ButtonNone; - renderWidgetHostView_->render_widget_host_->ForwardMouseEvent( - exitEvent); - } - mouseEventWasIgnored_ = YES; - return; + return YES; } view = [view superview]; } + return NO; +} + +- (void)mouseEvent:(NSEvent*)theEvent { + if ([self shouldIgnoreMouseEvent:theEvent]) { + // If this is the first such event, send a mouse exit to the host view. + if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { + WebMouseEvent exitEvent = + WebInputEventFactory::mouseEvent(theEvent, self); + exitEvent.type = WebInputEvent::MouseLeave; + exitEvent.button = WebMouseEvent::ButtonNone; + renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(exitEvent); + } + mouseEventWasIgnored_ = YES; + return; + } if (mouseEventWasIgnored_) { // If this is the first mouse event after a previous event that was ignored diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm index 933d89c..deb84e0 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -141,11 +141,13 @@ TEST_F(RenderWidgetHostViewMacTest, AcceptsFirstResponder) { } TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDown) { - scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); + scoped_nsobject<CocoaTestHelperWindow> + window([[CocoaTestHelperWindow alloc] init]); [[window contentView] addSubview:rwhv_cocoa_.get()]; // Even if the RWHVCocoa disallows first responder, clicking on it gives it // focus. + [window setPretendIsKeyWindow:YES]; [window makeFirstResponder:nil]; ASSERT_NE(rwhv_cocoa_.get(), [window firstResponder]); @@ -172,8 +174,10 @@ TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDownWithAcceleratedView) { EXPECT_FALSE([accelerated_view isHidden]); // Add the RWHVCocoa to the window and remove first responder status. - scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); + scoped_nsobject<CocoaTestHelperWindow> + window([[CocoaTestHelperWindow alloc] init]); [[window contentView] addSubview:rwhv_cocoa_.get()]; + [window setPretendIsKeyWindow:YES]; [window makeFirstResponder:nil]; EXPECT_NE(rwhv_cocoa_.get(), [window firstResponder]); |