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 "base/time.h" | 5 #include "base/time.h" |
6 #include "base/timer.h" | 6 #include "base/timer.h" |
7 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 7 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
8 #include "ui/gfx/screen.h" | 8 #include "ui/gfx/screen.h" |
9 | 9 |
10 // A timer based implementation of PanelMouseWatcher. Currently used for Gtk | 10 // A timer based implementation of PanelMouseWatcher. Currently used for Gtk |
11 // and Mac panels implementations. | 11 // and Mac panels implementations. |
12 class PanelMouseWatcherTimer : public PanelMouseWatcher { | 12 class PanelMouseWatcherTimer : public PanelMouseWatcher { |
13 public: | 13 public: |
14 PanelMouseWatcherTimer(); | 14 PanelMouseWatcherTimer(); |
15 virtual ~PanelMouseWatcherTimer(); | 15 virtual ~PanelMouseWatcherTimer(); |
16 | 16 |
17 private: | 17 private: |
18 virtual void Start() OVERRIDE; | 18 virtual void Start() OVERRIDE; |
19 virtual void Stop() OVERRIDE; | 19 virtual void Stop() OVERRIDE; |
20 virtual bool IsActive() const OVERRIDE; | 20 virtual bool IsActive() const OVERRIDE; |
| 21 virtual gfx::Point GetMousePosition() const OVERRIDE; |
21 | 22 |
22 // Specifies the rate at which we want to sample the mouse position. | 23 // Specifies the rate at which we want to sample the mouse position. |
23 static const int kMousePollingIntervalMs = 250; | 24 static const int kMousePollingIntervalMs = 250; |
24 | 25 |
25 // Timer callback function. | 26 // Timer callback function. |
26 void DoWork(); | 27 void DoWork(); |
27 friend class base::RepeatingTimer<PanelMouseWatcherTimer>; | 28 friend class base::RepeatingTimer<PanelMouseWatcherTimer>; |
28 | 29 |
29 // Timer used to track mouse movements. Some OSes do not provide an easy way | 30 // Timer used to track mouse movements. Some OSes do not provide an easy way |
30 // of tracking mouse movements across applications. So we use a timer to | 31 // of tracking mouse movements across applications. So we use a timer to |
(...skipping 25 matching lines...) Expand all Loading... |
56 | 57 |
57 void PanelMouseWatcherTimer::Stop() { | 58 void PanelMouseWatcherTimer::Stop() { |
58 DCHECK(IsActive()); | 59 DCHECK(IsActive()); |
59 timer_.Stop(); | 60 timer_.Stop(); |
60 } | 61 } |
61 | 62 |
62 bool PanelMouseWatcherTimer::IsActive() const { | 63 bool PanelMouseWatcherTimer::IsActive() const { |
63 return timer_.IsRunning(); | 64 return timer_.IsRunning(); |
64 } | 65 } |
65 | 66 |
| 67 gfx::Point PanelMouseWatcherTimer::GetMousePosition() const { |
| 68 return gfx::Screen::GetCursorScreenPoint(); |
| 69 } |
| 70 |
66 void PanelMouseWatcherTimer::DoWork() { | 71 void PanelMouseWatcherTimer::DoWork() { |
67 NotifyMouseMovement(gfx::Screen::GetCursorScreenPoint()); | 72 NotifyMouseMovement(GetMousePosition()); |
68 } | 73 } |
OLD | NEW |