Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: ui/views/mouse_watcher.cc

Issue 9309110: Refactored MouseWatcher to allow regions other than Views to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/mouse_watcher.cc
diff --git a/ui/views/mouse_watcher.cc b/ui/views/mouse_watcher.cc
index 1115901276dcb68e6e53f4fdaba1dd31f1a3ac70..2222d124dcc3d21b922bb86c9eaf53b933a38231 100644
--- a/ui/views/mouse_watcher.cc
+++ b/ui/views/mouse_watcher.cc
@@ -11,12 +11,10 @@
#include "base/message_loop.h"
#include "ui/base/events.h"
#include "ui/gfx/screen.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
namespace views {
-// Amount of time between when the mouse moves outside the view's zone and when
+// Amount of time between when the mouse moves outside the Host's zone and when
// the listener is notified.
const int kNotifyListenerTimeMs = 300;
@@ -41,7 +39,7 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer {
virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE {
// We spy on three different Windows messages here to see if the mouse has
- // moved out of the bounds of the view. The messages are:
+ // moved out of the bounds of the current view. The messages are:
//
// WM_MOUSEMOVE:
// For when the mouse moves from the view into the rest of the browser UI,
@@ -115,51 +113,27 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer {
#endif
private:
- View* view() const { return mouse_watcher_->host_; }
-
- // Returns whether or not the cursor is currently in the view's "zone" which
- // is defined as a slightly larger region than the view.
- bool IsCursorInViewZone() {
- gfx::Rect bounds = view()->GetLocalBounds();
- gfx::Point view_topleft(bounds.origin());
- View::ConvertPointToScreen(view(), &view_topleft);
- bounds.set_origin(view_topleft);
- bounds.SetRect(view_topleft.x() - mouse_watcher_->hot_zone_insets_.left(),
- view_topleft.y() - mouse_watcher_->hot_zone_insets_.top(),
- bounds.width() + mouse_watcher_->hot_zone_insets_.width(),
- bounds.height() + mouse_watcher_->hot_zone_insets_.height());
-
- gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint();
-
- return bounds.Contains(cursor_point.x(), cursor_point.y());
- }
-
- // Returns true if the mouse is over the view's window.
- bool IsMouseOverWindow() {
- Widget* widget = view()->GetWidget();
- if (!widget)
- return false;
-
- return gfx::Screen::GetWindowAtCursorScreenPoint() ==
- widget->GetNativeWindow();
- }
+ MouseWatcherHost* host() const { return mouse_watcher_->host_.get(); }
// Called from the message loop observer when a mouse movement has occurred.
void HandleGlobalMouseMoveEvent(bool check_window) {
sky 2012/02/06 16:03:34 Change this to take MouseWatcherHost::MouseEventTy
- bool in_view = IsCursorInViewZone();
- if (!in_view || (check_window && !IsMouseOverWindow())) {
- // Mouse moved outside the view's zone, start a timer to notify the
+ MouseWatcherHost::MouseEventType type = check_window ?
+ MouseWatcherHost::MOUSE_MOVE : MouseWatcherHost::MOUSE_EXITED;
+ bool contained = host()->Contains(
+ gfx::Screen::GetCursorScreenPoint(), type);
+ if (!contained) {
+ // Mouse moved outside the host's zone, start a timer to notify the
// listener.
if (!notify_listener_factory_.HasWeakPtrs()) {
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&Observer::NotifyListener,
notify_listener_factory_.GetWeakPtr()),
- !in_view ? kNotifyListenerTimeMs :
+ !check_window ? kNotifyListenerTimeMs :
mouse_watcher_->notify_on_exit_time_ms_);
}
} else {
- // Mouse moved quickly out of the view and then into it again, so cancel
+ // Mouse moved quickly out of the host and then into it again, so cancel
// the timer.
notify_listener_factory_.InvalidateWeakPtrs();
}
@@ -182,12 +156,13 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer {
MouseWatcherListener::~MouseWatcherListener() {
}
-MouseWatcher::MouseWatcher(View* host,
- MouseWatcherListener* listener,
- const gfx::Insets& hot_zone_insets)
+MouseWatcherHost::~MouseWatcherHost() {
+}
+
+MouseWatcher::MouseWatcher(MouseWatcherHost* host,
+ MouseWatcherListener* listener)
: host_(host),
listener_(listener),
- hot_zone_insets_(hot_zone_insets),
notify_on_exit_time_ms_(kNotifyListenerTimeMs) {
}
@@ -205,7 +180,7 @@ void MouseWatcher::Stop() {
void MouseWatcher::NotifyListener() {
observer_.reset(NULL);
- listener_->MouseMovedOutOfView();
+ listener_->MouseMovedOutOfHost();
}
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698