OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/mouse_watcher.h" | 5 #include "views/mouse_watcher.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "views/screen.h" | 10 #include "views/screen.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bounds.width() + mouse_watcher_->hot_zone_insets_.width(), | 89 bounds.width() + mouse_watcher_->hot_zone_insets_.width(), |
90 bounds.height() + mouse_watcher_->hot_zone_insets_.height()); | 90 bounds.height() + mouse_watcher_->hot_zone_insets_.height()); |
91 | 91 |
92 gfx::Point cursor_point = Screen::GetCursorScreenPoint(); | 92 gfx::Point cursor_point = Screen::GetCursorScreenPoint(); |
93 | 93 |
94 return bounds.Contains(cursor_point.x(), cursor_point.y()); | 94 return bounds.Contains(cursor_point.x(), cursor_point.y()); |
95 } | 95 } |
96 | 96 |
97 // Returns true if the mouse is over the view's window. | 97 // Returns true if the mouse is over the view's window. |
98 bool IsMouseOverWindow() { | 98 bool IsMouseOverWindow() { |
99 Window* window = view()->GetWindow(); | 99 Widget* widget = view()->GetWidget(); |
100 if (!window) | 100 if (!widget) |
101 return false; | 101 return false; |
102 | 102 |
103 return Screen::GetWindowAtCursorScreenPoint() == | 103 return Screen::GetWindowAtCursorScreenPoint() == |
104 window->GetNativeWindow(); | 104 widget->GetNativeWindow(); |
105 } | 105 } |
106 | 106 |
107 // Called from the message loop observer when a mouse movement has occurred. | 107 // Called from the message loop observer when a mouse movement has occurred. |
108 void HandleGlobalMouseMoveEvent(bool check_window) { | 108 void HandleGlobalMouseMoveEvent(bool check_window) { |
109 bool in_view = IsCursorInViewZone(); | 109 bool in_view = IsCursorInViewZone(); |
110 if (!in_view || (check_window && !IsMouseOverWindow())) { | 110 if (!in_view || (check_window && !IsMouseOverWindow())) { |
111 // Mouse moved outside the view's zone, start a timer to notify the | 111 // Mouse moved outside the view's zone, start a timer to notify the |
112 // listener. | 112 // listener. |
113 if (notify_listener_factory_.empty()) { | 113 if (notify_listener_factory_.empty()) { |
114 MessageLoop::current()->PostDelayedTask( | 114 MessageLoop::current()->PostDelayedTask( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void MouseWatcher::Stop() { | 162 void MouseWatcher::Stop() { |
163 observer_.reset(NULL); | 163 observer_.reset(NULL); |
164 } | 164 } |
165 | 165 |
166 void MouseWatcher::NotifyListener() { | 166 void MouseWatcher::NotifyListener() { |
167 observer_.reset(NULL); | 167 observer_.reset(NULL); |
168 listener_->MouseMovedOutOfView(); | 168 listener_->MouseMovedOutOfView(); |
169 } | 169 } |
170 | 170 |
171 } // namespace views | 171 } // namespace views |
OLD | NEW |