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.mm10
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]);