OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_MOUSE_WATCHER_H_ | 5 #ifndef UI_VIEWS_MOUSE_WATCHER_H_ |
6 #define UI_VIEWS_MOUSE_WATCHER_H_ | 6 #define UI_VIEWS_MOUSE_WATCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time.h" |
11 #include "ui/gfx/insets.h" | 12 #include "ui/gfx/insets.h" |
12 #include "ui/views/views_export.h" | 13 #include "ui/views/views_export.h" |
13 | 14 |
14 namespace gfx { | 15 namespace gfx { |
15 class Point; | 16 class Point; |
16 } | 17 } |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
20 // MouseWatcherListener is notified when the mouse moves outside the host. | 21 // MouseWatcherListener is notified when the mouse moves outside the host. |
(...skipping 30 matching lines...) Expand all Loading... |
51 class VIEWS_EXPORT MouseWatcher { | 52 class VIEWS_EXPORT MouseWatcher { |
52 public: | 53 public: |
53 // Creates a new MouseWatcher. The |listener| will be notified when the |host| | 54 // Creates a new MouseWatcher. The |listener| will be notified when the |host| |
54 // determines that the mouse has moved outside its monitored region. | 55 // determines that the mouse has moved outside its monitored region. |
55 // |host| will be owned by the watcher and deleted upon completion. | 56 // |host| will be owned by the watcher and deleted upon completion. |
56 MouseWatcher(MouseWatcherHost* host, MouseWatcherListener* listener); | 57 MouseWatcher(MouseWatcherHost* host, MouseWatcherListener* listener); |
57 ~MouseWatcher(); | 58 ~MouseWatcher(); |
58 | 59 |
59 // Sets the amount to delay before notifying the listener when the mouse exits | 60 // Sets the amount to delay before notifying the listener when the mouse exits |
60 // the host by way of going to another window. | 61 // the host by way of going to another window. |
61 void set_notify_on_exit_time_ms(int time) { notify_on_exit_time_ms_ = time; } | 62 void set_notify_on_exit_time(base::TimeDelta time) { |
| 63 notify_on_exit_time_ = time; |
| 64 } |
62 | 65 |
63 // Starts watching mouse movements. When the mouse moves outside the bounds of | 66 // Starts watching mouse movements. When the mouse moves outside the bounds of |
64 // the host the listener is notified. |Start| may be invoked any number of | 67 // the host the listener is notified. |Start| may be invoked any number of |
65 // times. If the mouse moves outside the bounds of the host the listener is | 68 // times. If the mouse moves outside the bounds of the host the listener is |
66 // notified and watcher stops watching events. | 69 // notified and watcher stops watching events. |
67 void Start(); | 70 void Start(); |
68 | 71 |
69 // Stops watching mouse events. | 72 // Stops watching mouse events. |
70 void Stop(); | 73 void Stop(); |
71 | 74 |
72 private: | 75 private: |
73 class Observer; | 76 class Observer; |
74 | 77 |
75 // Are we currently observing events? | 78 // Are we currently observing events? |
76 bool is_observing() const { return observer_.get() != NULL; } | 79 bool is_observing() const { return observer_.get() != NULL; } |
77 | 80 |
78 // Notifies the listener and stops watching events. | 81 // Notifies the listener and stops watching events. |
79 void NotifyListener(); | 82 void NotifyListener(); |
80 | 83 |
81 // Host we're listening for events over. | 84 // Host we're listening for events over. |
82 scoped_ptr<MouseWatcherHost> host_; | 85 scoped_ptr<MouseWatcherHost> host_; |
83 | 86 |
84 // Our listener. | 87 // Our listener. |
85 MouseWatcherListener* listener_; | 88 MouseWatcherListener* listener_; |
86 | 89 |
87 // Does the actual work of listening for mouse events. | 90 // Does the actual work of listening for mouse events. |
88 scoped_ptr<Observer> observer_; | 91 scoped_ptr<Observer> observer_; |
89 | 92 |
90 // See description above setter. | 93 // See description above setter. |
91 int notify_on_exit_time_ms_; | 94 base::TimeDelta notify_on_exit_time_; |
92 | 95 |
93 DISALLOW_COPY_AND_ASSIGN(MouseWatcher); | 96 DISALLOW_COPY_AND_ASSIGN(MouseWatcher); |
94 }; | 97 }; |
95 | 98 |
96 } // namespace views | 99 } // namespace views |
97 | 100 |
98 #endif // UI_VIEWS_MOUSE_WATCHER_H_ | 101 #endif // UI_VIEWS_MOUSE_WATCHER_H_ |
OLD | NEW |