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