OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ALLOW_THIS_IN_INITIALIZER_LIST(notify_listener_factory_(this)) { | 28 ALLOW_THIS_IN_INITIALIZER_LIST(notify_listener_factory_(this)) { |
29 MessageLoopForUI::current()->AddObserver(this); | 29 MessageLoopForUI::current()->AddObserver(this); |
30 } | 30 } |
31 | 31 |
32 ~Observer() { | 32 ~Observer() { |
33 MessageLoopForUI::current()->RemoveObserver(this); | 33 MessageLoopForUI::current()->RemoveObserver(this); |
34 } | 34 } |
35 | 35 |
36 // MessageLoop::Observer implementation: | 36 // MessageLoop::Observer implementation: |
37 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
38 void WillProcessMessage(const MSG& msg) { | 38 void WillProcessMessage(const MSG& msg) OVERRIDE { |
39 } | 39 } |
40 | 40 |
41 void DidProcessMessage(const MSG& msg) { | 41 void DidProcessMessage(const MSG& msg) OVERRIDE { |
42 // We spy on three different Windows messages here to see if the mouse has | 42 // We spy on three different Windows messages here to see if the mouse has |
43 // moved out of the bounds of the view. The messages are: | 43 // moved out of the bounds of the view. The messages are: |
44 // | 44 // |
45 // WM_MOUSEMOVE: | 45 // WM_MOUSEMOVE: |
46 // For when the mouse moves from the view into the rest of the browser UI, | 46 // For when the mouse moves from the view into the rest of the browser UI, |
47 // i.e. within the bounds of the same windows HWND. | 47 // i.e. within the bounds of the same windows HWND. |
48 // WM_MOUSELEAVE: | 48 // WM_MOUSELEAVE: |
49 // For when the mouse moves out of the bounds of the view's HWND. | 49 // For when the mouse moves out of the bounds of the view's HWND. |
50 // WM_NCMOUSELEAVE: | 50 // WM_NCMOUSELEAVE: |
51 // For notification when the mouse leaves the _non-client_ area. | 51 // For notification when the mouse leaves the _non-client_ area. |
52 // | 52 // |
53 switch (msg.message) { | 53 switch (msg.message) { |
54 case WM_MOUSEMOVE: | 54 case WM_MOUSEMOVE: |
55 HandleGlobalMouseMoveEvent(false); | 55 HandleGlobalMouseMoveEvent(false); |
56 break; | 56 break; |
57 case WM_MOUSELEAVE: | 57 case WM_MOUSELEAVE: |
58 case WM_NCMOUSELEAVE: | 58 case WM_NCMOUSELEAVE: |
59 HandleGlobalMouseMoveEvent(true); | 59 HandleGlobalMouseMoveEvent(true); |
60 break; | 60 break; |
61 } | 61 } |
62 } | 62 } |
63 #elif defined(USE_WAYLAND) | 63 #elif defined(USE_WAYLAND) |
64 MessageLoopForUI::Observer::EventStatus WillProcessEvent( | 64 MessageLoopForUI::Observer::EventStatus WillProcessEvent( |
65 ui::WaylandEvent* event) { | 65 ui::WaylandEvent* event) OVERRIDE { |
66 switch (event->type) { | 66 switch (event->type) { |
67 case ui::WAYLAND_MOTION: | 67 case ui::WAYLAND_MOTION: |
68 HandleGlobalMouseMoveEvent(false); | 68 HandleGlobalMouseMoveEvent(false); |
69 break; | 69 break; |
70 case ui::WAYLAND_POINTER_FOCUS: | 70 case ui::WAYLAND_POINTER_FOCUS: |
71 if (!event->pointer_focus.state) | 71 if (!event->pointer_focus.state) |
72 HandleGlobalMouseMoveEvent(true); | 72 HandleGlobalMouseMoveEvent(true); |
73 break; | 73 break; |
74 default: | 74 default: |
75 break; | 75 break; |
76 } | 76 } |
77 return EVENT_CONTINUE; | 77 return EVENT_CONTINUE; |
78 } | 78 } |
79 #else | 79 #elif defined(TOOLKIT_USES_GTK) |
80 void WillProcessEvent(GdkEvent* event) { | 80 void WillProcessEvent(GdkEvent* event) OVERRIDE { |
81 } | 81 } |
82 | 82 |
83 void DidProcessEvent(GdkEvent* event) { | 83 void DidProcessEvent(GdkEvent* event) OVERRIDE { |
84 switch (event->type) { | 84 switch (event->type) { |
85 case GDK_MOTION_NOTIFY: | 85 case GDK_MOTION_NOTIFY: |
86 HandleGlobalMouseMoveEvent(false); | 86 HandleGlobalMouseMoveEvent(false); |
87 break; | 87 break; |
88 case GDK_LEAVE_NOTIFY: | 88 case GDK_LEAVE_NOTIFY: |
89 HandleGlobalMouseMoveEvent(true); | 89 HandleGlobalMouseMoveEvent(true); |
90 break; | 90 break; |
91 default: | 91 default: |
92 break; | 92 break; |
93 } | 93 } |
94 } | 94 } |
| 95 #else |
| 96 EventStatus WillProcessXEvent(XEvent* event) OVERRIDE { |
| 97 // TODO(davemoore) Implement. |
| 98 return EVENT_CONTINUE; |
| 99 } |
95 #endif | 100 #endif |
96 | 101 |
97 private: | 102 private: |
98 View* view() const { return mouse_watcher_->host_; } | 103 View* view() const { return mouse_watcher_->host_; } |
99 | 104 |
100 // Returns whether or not the cursor is currently in the view's "zone" which | 105 // Returns whether or not the cursor is currently in the view's "zone" which |
101 // is defined as a slightly larger region than the view. | 106 // is defined as a slightly larger region than the view. |
102 bool IsCursorInViewZone() { | 107 bool IsCursorInViewZone() { |
103 gfx::Rect bounds = view()->GetLocalBounds(); | 108 gfx::Rect bounds = view()->GetLocalBounds(); |
104 gfx::Point view_topleft(bounds.origin()); | 109 gfx::Point view_topleft(bounds.origin()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void MouseWatcher::Stop() { | 187 void MouseWatcher::Stop() { |
183 observer_.reset(NULL); | 188 observer_.reset(NULL); |
184 } | 189 } |
185 | 190 |
186 void MouseWatcher::NotifyListener() { | 191 void MouseWatcher::NotifyListener() { |
187 observer_.reset(NULL); | 192 observer_.reset(NULL); |
188 listener_->MouseMovedOutOfView(); | 193 listener_->MouseMovedOutOfView(); |
189 } | 194 } |
190 | 195 |
191 } // namespace views | 196 } // namespace views |
OLD | NEW |