diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 21:18:20 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 21:18:20 +0000 |
commit | f2c9df50f8acaa7818758f4fdb0b95ab41ee2706 (patch) | |
tree | f0fcea13abda28604065094e1cfe375e62ff9237 /views/mouse_watcher.h | |
parent | 41ef4508ee9980a2945514ba2f913d1bf64ee326 (diff) | |
download | chromium_src-f2c9df50f8acaa7818758f4fdb0b95ab41ee2706.zip chromium_src-f2c9df50f8acaa7818758f4fdb0b95ab41ee2706.tar.gz chromium_src-f2c9df50f8acaa7818758f4fdb0b95ab41ee2706.tar.bz2 |
Refactors mouse watching out of TabStrip into a standalone class.
BUG=27797
TEST=none
Review URL: http://codereview.chromium.org/3140008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/mouse_watcher.h')
-rw-r--r-- | views/mouse_watcher.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/views/mouse_watcher.h b/views/mouse_watcher.h new file mode 100644 index 0000000..7037487 --- /dev/null +++ b/views/mouse_watcher.h @@ -0,0 +1,75 @@ +// Copyright (c) 2010 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. + +#ifndef VIEWS_MOUSE_WATCHER_H_ +#define VIEWS_MOUSE_WATCHER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "gfx/insets.h" + +namespace views { + +class View; + +// MouseWatcherListener is notified when the mouse moves outside the view. +class MouseWatcherListener { + public: + virtual void MouseMovedOutOfView() = 0; + + protected: + virtual ~MouseWatcherListener(); +}; + +// MouseWatcher is used to watch mouse movement and notify its listener when the +// mouse moves outside the bounds of a view. +class MouseWatcher { + public: + // Creates a new MouseWatcher. |hot_zone_insets| is added to the bounds of + // the view to determine the active zone. For example, if + // |hot_zone_insets.bottom()| is 10, then the listener is not notified if + // the y coordinate is between the origin of the view and height of the view + // plus 10. + MouseWatcher(views::View* host, + MouseWatcherListener* listener, + const gfx::Insets& hot_zone_insets); + ~MouseWatcher(); + + // Starts watching mouse movements. When the mouse moves outside the bounds of + // the view the listener is notified. |Start| may be invoked any number of + // times. If the mouse moves outside the bounds of the view the listener is + // notified and watcher stops watching events. + void Start(); + + // Stops watching mouse events. + void Stop(); + + private: + class Observer; + + // Are we currently observing events? + bool is_observing() const { return observer_.get() != NULL; } + + // Notifies the listener and stops watching events. + void NotifyListener(); + + // View we're listening for events over. + views::View* host_; + + // Our listener. + MouseWatcherListener* listener_; + + // Insets added to the bounds of the view. + const gfx::Insets hot_zone_insets_; + + // Does the actual work of listening for mouse events. + scoped_ptr<Observer> observer_; + + DISALLOW_COPY_AND_ASSIGN(MouseWatcher); +}; + +} // namespace views + +#endif // VIEWS_MOUSE_WATCHER_H_ |