diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 19:27:53 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 19:27:53 +0000 |
commit | ad2a42ed351f59d8b5cbe40a68d5631d73f24ac5 (patch) | |
tree | 10aa59c79a1779cc529c8672799188cc43680f3d /chrome | |
parent | fe7bd03eb1139393771b5bbf99fdd1637f494296 (diff) | |
download | chromium_src-ad2a42ed351f59d8b5cbe40a68d5631d73f24ac5.zip chromium_src-ad2a42ed351f59d8b5cbe40a68d5631d73f24ac5.tar.gz chromium_src-ad2a42ed351f59d8b5cbe40a68d5631d73f24ac5.tar.bz2 |
Fix for "Mouseovers follow the cursor even when there's a find bar in the way"
Perform a hit test in the render widget host view to check if the cursor is
actually on top of a different view - such as the find bar. If it is and that
view has a method -[(BOOL)nonWebContentView] that returns YES, then ignore
the event in the render widget host.
Change FindBarView to have the aforementioned method that returns YES.
Patch by Alexei Svitkine <asvitkine@chromium.org>
BUG=22191
TEST=Leave the content area by mousing over a visible find bar. Mouseovers
from the content area should extinguish, and no masked by the find bar
should be triggered.
R=mark@chromium.org
Review URL: http://codereview.chromium.org/6676094
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79438 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 58 insertions, 5 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index 037afe2..652d03c 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -125,6 +125,9 @@ class RWHVMEditCommandHelper; // Whether or not plugin IME is currently enabled active. BOOL pluginImeActive_; + + // Whether the previous mouse event was ignored due to hitTest check. + BOOL mouseEventWasIgnored_; } @property(assign, nonatomic) NSRect caretRect; 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 40ddd67..02b7677 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -1417,8 +1417,6 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { renderWidgetHostView_.reset(r); canBeKeyView_ = YES; - takesFocusOnlyOnMouseDown_ = NO; - closeOnDeactivate_ = NO; focusedPluginIdentifier_ = -1; } return self; @@ -1437,6 +1435,47 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { } - (void)mouseEvent:(NSEvent*)theEvent { + // 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); + NSView* contentView = [[self window] contentView]; + NSView* view = [contentView hitTest:[theEvent locationInWindow]]; + // Traverse the superview hierarchy as the hitTest will return the frontmost + // view, such as an NSTextView, while nonWebContentView may be specified by + // its parent view. + while (view) { + 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; + } + view = [view superview]; + } + + if (mouseEventWasIgnored_) { + // If this is the first mouse event after a previous event that was ignored + // due to the hitTest, send a mouse enter event to the host view. + if (renderWidgetHostView_->render_widget_host_) { + WebMouseEvent enterEvent = + WebInputEventFactory::mouseEvent(theEvent, self); + enterEvent.type = WebInputEvent::MouseMove; + enterEvent.button = WebMouseEvent::ButtonNone; + renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(enterEvent); + } + } + mouseEventWasIgnored_ = NO; + // TODO(rohitrao): Probably need to handle other mouse down events here. if ([theEvent type] == NSLeftMouseDown && takesFocusOnlyOnMouseDown_) { if (renderWidgetHostView_->render_widget_host_) diff --git a/chrome/browser/ui/cocoa/find_bar/find_bar_view.h b/chrome/browser/ui/cocoa/find_bar/find_bar_view.h index a3cc96b..919c67c 100644 --- a/chrome/browser/ui/cocoa/find_bar/find_bar_view.h +++ b/chrome/browser/ui/cocoa/find_bar/find_bar_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 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. @@ -14,6 +14,11 @@ @interface FindBarView : BackgroundGradientView { } + +// Specifies that mouse events over this view should be ignored by the +// render host. +- (BOOL)nonWebContentView; + @end #endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_VIEW_H_ diff --git a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm b/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm index 7883a1f..8657531 100644 --- a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm +++ b/chrome/browser/ui/cocoa/find_bar/find_bar_view.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. @@ -128,4 +128,10 @@ CGFloat kCurveSize = 8; return VIEW_ID_FIND_IN_PAGE; } +// Specifies that mouse events over this view should be ignored by the +// render host. +- (BOOL)nonWebContentView { + return YES; +} + @end |