summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm36
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm4
2 files changed, 26 insertions, 14 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 2dbcf68..ad8048e 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -1454,7 +1454,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);
@@ -1467,21 +1472,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..b4a9b09 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.
@@ -146,6 +146,7 @@ TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDown) {
// 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]);
@@ -174,6 +175,7 @@ TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDownWithAcceleratedView) {
// Add the RWHVCocoa to the window and remove first responder status.
scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]);
[[window contentView] addSubview:rwhv_cocoa_.get()];
+ [window setPretendIsKeyWindow:YES];
[window makeFirstResponder:nil];
EXPECT_NE(rwhv_cocoa_.get(), [window firstResponder]);