Add ICU message format support
[chromium-blink-merge.git] / ui / views / mouse_watcher.h
blob592266acfb7434f87d5ef7e21b77514e2a0712f7
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/geometry/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 type of mouse event.
33 enum MouseEventType {
34 MOUSE_MOVE,
35 MOUSE_EXIT,
36 MOUSE_PRESS
39 virtual ~MouseWatcherHost();
41 // Return false when the mouse has moved outside the monitored region.
42 virtual bool Contains(const gfx::Point& screen_point,
43 MouseEventType type) = 0;
46 // MouseWatcher is used to watch mouse movement and notify its listener when the
47 // mouse moves outside the bounds of a MouseWatcherHost.
48 class VIEWS_EXPORT MouseWatcher {
49 public:
50 // Creates a new MouseWatcher. The |listener| will be notified when the |host|
51 // determines that the mouse has moved outside its monitored region.
52 // |host| will be owned by the watcher and deleted upon completion.
53 MouseWatcher(MouseWatcherHost* host, MouseWatcherListener* listener);
54 ~MouseWatcher();
56 // Sets the amount to delay before notifying the listener when the mouse exits
57 // the host by way of going to another window.
58 void set_notify_on_exit_time(base::TimeDelta time) {
59 notify_on_exit_time_ = time;
62 // Starts watching mouse movements. When the mouse moves outside the bounds of
63 // the host the listener is notified. |Start| may be invoked any number of
64 // times. If the mouse moves outside the bounds of the host the listener is
65 // notified and watcher stops watching events.
66 void Start();
68 // Stops watching mouse events.
69 void Stop();
71 private:
72 class Observer;
74 // Are we currently observing events?
75 bool is_observing() const { return observer_.get() != NULL; }
77 // Notifies the listener and stops watching events.
78 void NotifyListener();
80 // Host we're listening for events over.
81 scoped_ptr<MouseWatcherHost> host_;
83 // Our listener.
84 MouseWatcherListener* listener_;
86 // Does the actual work of listening for mouse events.
87 scoped_ptr<Observer> observer_;
89 // See description above setter.
90 base::TimeDelta notify_on_exit_time_;
92 DISALLOW_COPY_AND_ASSIGN(MouseWatcher);
95 } // namespace views
97 #endif // UI_VIEWS_MOUSE_WATCHER_H_