OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 21 matching lines...) Expand all Loading... |
32 // ui::EventHandler implementation: | 32 // ui::EventHandler implementation: |
33 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 33 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
34 switch (event->type()) { | 34 switch (event->type()) { |
35 case ui::ET_MOUSE_MOVED: | 35 case ui::ET_MOUSE_MOVED: |
36 case ui::ET_MOUSE_DRAGGED: | 36 case ui::ET_MOUSE_DRAGGED: |
37 HandleMouseEvent(MouseWatcherHost::MOUSE_MOVE); | 37 HandleMouseEvent(MouseWatcherHost::MOUSE_MOVE); |
38 break; | 38 break; |
39 case ui::ET_MOUSE_EXITED: | 39 case ui::ET_MOUSE_EXITED: |
40 HandleMouseEvent(MouseWatcherHost::MOUSE_EXIT); | 40 HandleMouseEvent(MouseWatcherHost::MOUSE_EXIT); |
41 break; | 41 break; |
| 42 case ui::ET_MOUSE_PRESSED: |
| 43 HandleMouseEvent(MouseWatcherHost::MOUSE_PRESS); |
| 44 break; |
42 default: | 45 default: |
43 break; | 46 break; |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 private: | 50 private: |
48 MouseWatcherHost* host() const { return mouse_watcher_->host_.get(); } | 51 MouseWatcherHost* host() const { return mouse_watcher_->host_.get(); } |
49 | 52 |
50 // Called when a mouse event we're interested is seen. | 53 // Called when a mouse event we're interested is seen. |
51 void HandleMouseEvent(MouseWatcherHost::MouseEventType event_type) { | 54 void HandleMouseEvent(MouseWatcherHost::MouseEventType event_type) { |
52 // It's safe to use last_mouse_location() here as this function is invoked | 55 // It's safe to use last_mouse_location() here as this function is invoked |
53 // during event dispatching. | 56 // during event dispatching. |
54 if (!host()->Contains(EventMonitor::GetLastMouseLocation(), event_type)) { | 57 if (!host()->Contains(EventMonitor::GetLastMouseLocation(), event_type)) { |
55 // Mouse moved outside the host's zone, start a timer to notify the | 58 if (event_type == MouseWatcherHost::MOUSE_PRESS) { |
56 // listener. | 59 NotifyListener(); |
57 if (!notify_listener_factory_.HasWeakPtrs()) { | 60 } else if (!notify_listener_factory_.HasWeakPtrs()) { |
| 61 // Mouse moved outside the host's zone, start a timer to notify the |
| 62 // listener. |
58 base::MessageLoop::current()->PostDelayedTask( | 63 base::MessageLoop::current()->PostDelayedTask( |
59 FROM_HERE, | 64 FROM_HERE, |
60 base::Bind(&Observer::NotifyListener, | 65 base::Bind(&Observer::NotifyListener, |
61 notify_listener_factory_.GetWeakPtr()), | 66 notify_listener_factory_.GetWeakPtr()), |
62 event_type == MouseWatcherHost::MOUSE_MOVE | 67 event_type == MouseWatcherHost::MOUSE_MOVE |
63 ? base::TimeDelta::FromMilliseconds(kNotifyListenerTimeMs) | 68 ? base::TimeDelta::FromMilliseconds(kNotifyListenerTimeMs) |
64 : mouse_watcher_->notify_on_exit_time_); | 69 : mouse_watcher_->notify_on_exit_time_); |
65 } | 70 } |
66 } else { | 71 } else { |
67 // Mouse moved quickly out of the host and then into it again, so cancel | 72 // Mouse moved quickly out of the host and then into it again, so cancel |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void MouseWatcher::Stop() { | 115 void MouseWatcher::Stop() { |
111 observer_.reset(NULL); | 116 observer_.reset(NULL); |
112 } | 117 } |
113 | 118 |
114 void MouseWatcher::NotifyListener() { | 119 void MouseWatcher::NotifyListener() { |
115 observer_.reset(NULL); | 120 observer_.reset(NULL); |
116 listener_->MouseMovedOutOfHost(); | 121 listener_->MouseMovedOutOfHost(); |
117 } | 122 } |
118 | 123 |
119 } // namespace views | 124 } // namespace views |
OLD | NEW |