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

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

Issue 14061025: ui: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « ui/views/focus/accelerator_handler.h ('k') | ui/views/view_unittest.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) 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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "ui/base/events/event_constants.h" 12 #include "ui/base/events/event_constants.h"
13 #include "ui/base/events/event_utils.h" 13 #include "ui/base/events/event_utils.h"
14 #include "ui/gfx/screen.h" 14 #include "ui/gfx/screen.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 // Amount of time between when the mouse moves outside the Host's zone and when 18 // Amount of time between when the mouse moves outside the Host's zone and when
19 // the listener is notified. 19 // the listener is notified.
20 const int kNotifyListenerTimeMs = 300; 20 const int kNotifyListenerTimeMs = 300;
21 21
22 class MouseWatcher::Observer : public MessageLoopForUI::Observer { 22 class MouseWatcher::Observer : public base::MessageLoopForUI::Observer {
23 public: 23 public:
24 explicit Observer(MouseWatcher* mouse_watcher) 24 explicit Observer(MouseWatcher* mouse_watcher)
25 : mouse_watcher_(mouse_watcher), 25 : mouse_watcher_(mouse_watcher),
26 notify_listener_factory_(this) { 26 notify_listener_factory_(this) {
27 MessageLoopForUI::current()->AddObserver(this); 27 base::MessageLoopForUI::current()->AddObserver(this);
28 } 28 }
29 29
30 virtual ~Observer() { 30 virtual ~Observer() {
31 MessageLoopForUI::current()->RemoveObserver(this); 31 base::MessageLoopForUI::current()->RemoveObserver(this);
32 } 32 }
33 33
34 // MessageLoop::Observer implementation: 34 // MessageLoop::Observer implementation:
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 virtual base::EventStatus WillProcessEvent( 36 virtual base::EventStatus WillProcessEvent(
37 const base::NativeEvent& event) OVERRIDE { 37 const base::NativeEvent& event) OVERRIDE {
38 return base::EVENT_CONTINUE; 38 return base::EVENT_CONTINUE;
39 } 39 }
40 40
41 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { 41 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Called from the message loop observer when a mouse movement has occurred. 87 // Called from the message loop observer when a mouse movement has occurred.
88 void HandleGlobalMouseMoveEvent(MouseWatcherHost::MouseEventType event_type) { 88 void HandleGlobalMouseMoveEvent(MouseWatcherHost::MouseEventType event_type) {
89 bool contained = host()->Contains( 89 bool contained = host()->Contains(
90 // TODO(scottmg): Native is wrong http://crbug.com/133312 90 // TODO(scottmg): Native is wrong http://crbug.com/133312
91 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(), 91 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(),
92 event_type); 92 event_type);
93 if (!contained) { 93 if (!contained) {
94 // Mouse moved outside the host's zone, start a timer to notify the 94 // Mouse moved outside the host's zone, start a timer to notify the
95 // listener. 95 // listener.
96 if (!notify_listener_factory_.HasWeakPtrs()) { 96 if (!notify_listener_factory_.HasWeakPtrs()) {
97 MessageLoop::current()->PostDelayedTask( 97 base::MessageLoop::current()->PostDelayedTask(
98 FROM_HERE, 98 FROM_HERE,
99 base::Bind(&Observer::NotifyListener, 99 base::Bind(&Observer::NotifyListener,
100 notify_listener_factory_.GetWeakPtr()), 100 notify_listener_factory_.GetWeakPtr()),
101 event_type == MouseWatcherHost::MOUSE_MOVE ? 101 event_type == MouseWatcherHost::MOUSE_MOVE
102 base::TimeDelta::FromMilliseconds(kNotifyListenerTimeMs) : 102 ? base::TimeDelta::FromMilliseconds(kNotifyListenerTimeMs)
103 mouse_watcher_->notify_on_exit_time_); 103 : mouse_watcher_->notify_on_exit_time_);
104 } 104 }
105 } else { 105 } else {
106 // Mouse moved quickly out of the host and then into it again, so cancel 106 // Mouse moved quickly out of the host and then into it again, so cancel
107 // the timer. 107 // the timer.
108 notify_listener_factory_.InvalidateWeakPtrs(); 108 notify_listener_factory_.InvalidateWeakPtrs();
109 } 109 }
110 } 110 }
111 111
112 void NotifyListener() { 112 void NotifyListener() {
113 mouse_watcher_->NotifyListener(); 113 mouse_watcher_->NotifyListener();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void MouseWatcher::Stop() { 148 void MouseWatcher::Stop() {
149 observer_.reset(NULL); 149 observer_.reset(NULL);
150 } 150 }
151 151
152 void MouseWatcher::NotifyListener() { 152 void MouseWatcher::NotifyListener() {
153 observer_.reset(NULL); 153 observer_.reset(NULL);
154 listener_->MouseMovedOutOfHost(); 154 listener_->MouseMovedOutOfHost();
155 } 155 }
156 156
157 } // namespace views 157 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/accelerator_handler.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698