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