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 #include "ui/views/mouse_watcher.h" | 5 #include "ui/views/mouse_watcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/event_types.h" | 9 #include "base/event_types.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 bool contained = host()->Contains( | 88 bool contained = host()->Contains( |
89 gfx::Screen::GetCursorScreenPoint(), event_type); | 89 gfx::Screen::GetCursorScreenPoint(), event_type); |
90 if (!contained) { | 90 if (!contained) { |
91 // Mouse moved outside the host's zone, start a timer to notify the | 91 // Mouse moved outside the host's zone, start a timer to notify the |
92 // listener. | 92 // listener. |
93 if (!notify_listener_factory_.HasWeakPtrs()) { | 93 if (!notify_listener_factory_.HasWeakPtrs()) { |
94 MessageLoop::current()->PostDelayedTask( | 94 MessageLoop::current()->PostDelayedTask( |
95 FROM_HERE, | 95 FROM_HERE, |
96 base::Bind(&Observer::NotifyListener, | 96 base::Bind(&Observer::NotifyListener, |
97 notify_listener_factory_.GetWeakPtr()), | 97 notify_listener_factory_.GetWeakPtr()), |
98 event_type == | 98 event_type == MouseWatcherHost::MOUSE_MOVE ? |
99 MouseWatcherHost::MOUSE_MOVE ? kNotifyListenerTimeMs : | 99 base::TimeDelta::FromMilliseconds(kNotifyListenerTimeMs) : |
100 mouse_watcher_->notify_on_exit_time_ms_); | 100 mouse_watcher_->notify_on_exit_time_); |
101 } | 101 } |
102 } else { | 102 } else { |
103 // Mouse moved quickly out of the host and then into it again, so cancel | 103 // Mouse moved quickly out of the host and then into it again, so cancel |
104 // the timer. | 104 // the timer. |
105 notify_listener_factory_.InvalidateWeakPtrs(); | 105 notify_listener_factory_.InvalidateWeakPtrs(); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 void NotifyListener() { | 109 void NotifyListener() { |
110 mouse_watcher_->NotifyListener(); | 110 mouse_watcher_->NotifyListener(); |
(...skipping 12 matching lines...) Expand all Loading... |
123 MouseWatcherListener::~MouseWatcherListener() { | 123 MouseWatcherListener::~MouseWatcherListener() { |
124 } | 124 } |
125 | 125 |
126 MouseWatcherHost::~MouseWatcherHost() { | 126 MouseWatcherHost::~MouseWatcherHost() { |
127 } | 127 } |
128 | 128 |
129 MouseWatcher::MouseWatcher(MouseWatcherHost* host, | 129 MouseWatcher::MouseWatcher(MouseWatcherHost* host, |
130 MouseWatcherListener* listener) | 130 MouseWatcherListener* listener) |
131 : host_(host), | 131 : host_(host), |
132 listener_(listener), | 132 listener_(listener), |
133 notify_on_exit_time_ms_(kNotifyListenerTimeMs) { | 133 notify_on_exit_time_(base::TimeDelta::FromMilliseconds( |
| 134 kNotifyListenerTimeMs)) { |
134 } | 135 } |
135 | 136 |
136 MouseWatcher::~MouseWatcher() { | 137 MouseWatcher::~MouseWatcher() { |
137 } | 138 } |
138 | 139 |
139 void MouseWatcher::Start() { | 140 void MouseWatcher::Start() { |
140 if (!is_observing()) | 141 if (!is_observing()) |
141 observer_.reset(new Observer(this)); | 142 observer_.reset(new Observer(this)); |
142 } | 143 } |
143 | 144 |
144 void MouseWatcher::Stop() { | 145 void MouseWatcher::Stop() { |
145 observer_.reset(NULL); | 146 observer_.reset(NULL); |
146 } | 147 } |
147 | 148 |
148 void MouseWatcher::NotifyListener() { | 149 void MouseWatcher::NotifyListener() { |
149 observer_.reset(NULL); | 150 observer_.reset(NULL); |
150 listener_->MouseMovedOutOfHost(); | 151 listener_->MouseMovedOutOfHost(); |
151 } | 152 } |
152 | 153 |
153 } // namespace views | 154 } // namespace views |
OLD | NEW |