Revert 284234 "Pass signin_scoped_device_id to DeviceInfoSpecifics."
[chromium-blink-merge.git] / ui / views / mouse_watcher.h
blob9327fe64995ca559d03fb8be6950b6858f6db7be
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_MOUSE_WATCHER_H_
6 #define UI_VIEWS_MOUSE_WATCHER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "ui/gfx/insets.h"
12 #include "ui/views/views_export.h"
14 namespace gfx {
15 class Point;
18 namespace views {
20 // MouseWatcherListener is notified when the mouse moves outside the host.
21 class VIEWS_EXPORT MouseWatcherListener {
22 public:
23 virtual void MouseMovedOutOfHost() = 0;
25 protected:
26 virtual ~MouseWatcherListener();
29 // The MouseWatcherHost determines what region is to be monitored.
30 class VIEWS_EXPORT MouseWatcherHost {
31 public:
32 // The MouseEventType can be used as a hint.
33 enum MouseEventType {
34 // The mouse moved within the window which was current when the MouseWatcher
35 // was created.
36 MOUSE_MOVE,
37 // The mouse moved exited the window which was current when the MouseWatcher
38 // was created.
39 MOUSE_EXIT
42 virtual ~MouseWatcherHost();
44 // Return false when the mouse has moved outside the monitored region.
45 virtual bool Contains(const gfx::Point& screen_point,
46 MouseEventType type) = 0;
49 // MouseWatcher is used to watch mouse movement and notify its listener when the
50 // mouse moves outside the bounds of a MouseWatcherHost.
51 class VIEWS_EXPORT MouseWatcher {
52 public:
53 // Creates a new MouseWatcher. The |listener| will be notified when the |host|
54 // determines that the mouse has moved outside its monitored region.
55 // |host| will be owned by the watcher and deleted upon completion.
56 MouseWatcher(MouseWatcherHost* host, MouseWatcherListener* listener);
57 ~MouseWatcher();
59 // Sets the amount to delay before notifying the listener when the mouse exits
60 // the host by way of going to another window.
61 void set_notify_on_exit_time(base::TimeDelta time) {
62 notify_on_exit_time_ = time;
65 // Starts watching mouse movements. When the mouse moves outside the bounds of
66 // the host the listener is notified. |Start| may be invoked any number of
67 // times. If the mouse moves outside the bounds of the host the listener is
68 // notified and watcher stops watching events.
69 void Start();
71 // Stops watching mouse events.
72 void Stop();
74 private:
75 class Observer;
77 // Are we currently observing events?
78 bool is_observing() const { return observer_.get() != NULL; }
80 // Notifies the listener and stops watching events.
81 void NotifyListener();
83 // Host we're listening for events over.
84 scoped_ptr<MouseWatcherHost> host_;
86 // Our listener.
87 MouseWatcherListener* listener_;
89 // Does the actual work of listening for mouse events.
90 scoped_ptr<Observer> observer_;
92 // See description above setter.
93 base::TimeDelta notify_on_exit_time_;
95 DISALLOW_COPY_AND_ASSIGN(MouseWatcher);
98 } // namespace views
100 #endif // UI_VIEWS_MOUSE_WATCHER_H_