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

Side by Side Diff: ui/views/mouse_watcher.h

Issue 9309110: Refactored MouseWatcher to allow regions other than Views to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review nits 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.cc ('k') | ui/views/mouse_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/gfx/insets.h" 11 #include "ui/gfx/insets.h"
12 #include "ui/views/views_export.h" 12 #include "ui/views/views_export.h"
13 13
14 namespace gfx {
15 class Point;
16 }
17
14 namespace views { 18 namespace views {
15 19
16 class View; 20 // MouseWatcherListener is notified when the mouse moves outside the host.
17
18 // MouseWatcherListener is notified when the mouse moves outside the view.
19 class VIEWS_EXPORT MouseWatcherListener { 21 class VIEWS_EXPORT MouseWatcherListener {
20 public: 22 public:
21 virtual void MouseMovedOutOfView() = 0; 23 virtual void MouseMovedOutOfHost() = 0;
22 24
23 protected: 25 protected:
24 virtual ~MouseWatcherListener(); 26 virtual ~MouseWatcherListener();
25 }; 27 };
26 28
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
40 };
41
42 virtual ~MouseWatcherHost();
43 // Return false when the mouse has moved outside the monitored region.
44 virtual bool Contains(
45 const gfx::Point& screen_point,
46 MouseEventType type) = 0;
47 };
48
27 // MouseWatcher is used to watch mouse movement and notify its listener when the 49 // MouseWatcher is used to watch mouse movement and notify its listener when the
28 // mouse moves outside the bounds of a view. 50 // mouse moves outside the bounds of a MouseWatcherHost.
29 class VIEWS_EXPORT MouseWatcher { 51 class VIEWS_EXPORT MouseWatcher {
30 public: 52 public:
31 // Creates a new MouseWatcher. |hot_zone_insets| is added to the bounds of 53 // Creates a new MouseWatcher. The |listener| will be notified when the |host|
32 // the view to determine the active zone. For example, if 54 // determines that the mouse has moved outside its monitored region.
33 // |hot_zone_insets.bottom()| is 10, then the listener is not notified if 55 // |host| will be owned by the watcher and deleted upon completion.
34 // the y coordinate is between the origin of the view and height of the view 56 MouseWatcher(MouseWatcherHost* host, MouseWatcherListener* listener);
35 // plus 10.
36 MouseWatcher(views::View* host,
37 MouseWatcherListener* listener,
38 const gfx::Insets& hot_zone_insets);
39 ~MouseWatcher(); 57 ~MouseWatcher();
40 58
41 // Sets the amount to delay before notifying the listener when the mouse exits 59 // Sets the amount to delay before notifying the listener when the mouse exits
42 // the view by way of going to another window. 60 // the host by way of going to another window.
43 void set_notify_on_exit_time_ms(int time) { notify_on_exit_time_ms_ = time; } 61 void set_notify_on_exit_time_ms(int time) { notify_on_exit_time_ms_ = time; }
44 62
45 // Starts watching mouse movements. When the mouse moves outside the bounds of 63 // Starts watching mouse movements. When the mouse moves outside the bounds of
46 // the view the listener is notified. |Start| may be invoked any number of 64 // the host the listener is notified. |Start| may be invoked any number of
47 // times. If the mouse moves outside the bounds of the view the listener is 65 // times. If the mouse moves outside the bounds of the host the listener is
48 // notified and watcher stops watching events. 66 // notified and watcher stops watching events.
49 void Start(); 67 void Start();
50 68
51 // Stops watching mouse events. 69 // Stops watching mouse events.
52 void Stop(); 70 void Stop();
53 71
54 private: 72 private:
55 class Observer; 73 class Observer;
56 74
57 // Are we currently observing events? 75 // Are we currently observing events?
58 bool is_observing() const { return observer_.get() != NULL; } 76 bool is_observing() const { return observer_.get() != NULL; }
59 77
60 // Notifies the listener and stops watching events. 78 // Notifies the listener and stops watching events.
61 void NotifyListener(); 79 void NotifyListener();
62 80
63 // View we're listening for events over. 81 // Host we're listening for events over.
64 View* host_; 82 scoped_ptr<MouseWatcherHost> host_;
65 83
66 // Our listener. 84 // Our listener.
67 MouseWatcherListener* listener_; 85 MouseWatcherListener* listener_;
68 86
69 // Insets added to the bounds of the view.
70 const gfx::Insets hot_zone_insets_;
71
72 // Does the actual work of listening for mouse events. 87 // Does the actual work of listening for mouse events.
73 scoped_ptr<Observer> observer_; 88 scoped_ptr<Observer> observer_;
74 89
75 // See description above setter. 90 // See description above setter.
76 int notify_on_exit_time_ms_; 91 int notify_on_exit_time_ms_;
77 92
78 DISALLOW_COPY_AND_ASSIGN(MouseWatcher); 93 DISALLOW_COPY_AND_ASSIGN(MouseWatcher);
79 }; 94 };
80 95
81 } // namespace views 96 } // namespace views
82 97
83 #endif // UI_VIEWS_MOUSE_WATCHER_H_ 98 #endif // UI_VIEWS_MOUSE_WATCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.cc ('k') | ui/views/mouse_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698