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 "chrome/browser/ui/panels/panel_mouse_watcher_gtk.h" | |
6 | |
7 #include "base/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
8 #include "base/time.h" | 6 #include "base/time.h" |
9 #include "base/timer.h" | 7 #include "base/timer.h" |
10 #include "chrome/browser/ui/panels/panel_manager.h" | 8 #include "chrome/browser/ui/panels/panel_manager.h" |
11 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 9 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
12 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
13 | 11 |
14 // A timer based implementation of PanelMouseWatcher. Currently used on Gtk | 12 // A timer based implementation of PanelMouseWatcher. Currently used for Gtk |
15 // but could be used on any platform. | 13 // and Mac panels implementations. |
16 class PanelMouseWatcherGtk : public PanelMouseWatcher { | 14 class PanelMouseWatcherTimer : public PanelMouseWatcher { |
jennb
2011/09/21 21:21:26
Thanks for making this diff-able!
| |
17 public: | 15 public: |
18 // Returns the singleton instance. | 16 // Returns the singleton instance. |
19 static PanelMouseWatcherGtk* GetInstance(); | 17 static PanelMouseWatcherTimer* GetInstance(); |
20 | 18 |
21 virtual ~PanelMouseWatcherGtk(); | 19 virtual ~PanelMouseWatcherTimer(); |
22 | 20 |
23 protected: | 21 protected: |
24 virtual void Start(); | 22 virtual void Start(); |
25 virtual void Stop(); | 23 virtual void Stop(); |
26 | 24 |
27 private: | 25 private: |
28 // Specifies the rate at which we want to sample the mouse position. | 26 // Specifies the rate at which we want to sample the mouse position. |
29 static const int kMousePollingIntervalMs = 250; | 27 static const int kMousePollingIntervalMs = 250; |
30 | 28 |
31 PanelMouseWatcherGtk(); | 29 PanelMouseWatcherTimer(); |
32 friend struct DefaultSingletonTraits<PanelMouseWatcherGtk>; | 30 friend struct DefaultSingletonTraits<PanelMouseWatcherTimer>; |
33 | 31 |
34 // Timer callback function. | 32 // Timer callback function. |
35 void DoWork(); | 33 void DoWork(); |
36 friend class base::RepeatingTimer<PanelMouseWatcherGtk>; | 34 friend class base::RepeatingTimer<PanelMouseWatcherTimer>; |
37 | 35 |
38 // Timer used to track mouse movements. Gtk does not provide an easy way of | 36 // Timer used to track mouse movements. Some OSes do not provide an easy way |
39 // tracking mouse movements across applications. So we use a timer to | 37 // of tracking mouse movements across applications. So we use a timer to |
40 // accomplish the same. This could also be more efficient as you end up | 38 // accomplish the same. This could also be more efficient as you end up |
41 // getting a lot of notifications when tracking mouse movements. | 39 // getting a lot of notifications when tracking mouse movements. |
42 base::RepeatingTimer<PanelMouseWatcherGtk> timer_; | 40 base::RepeatingTimer<PanelMouseWatcherTimer> timer_; |
43 | 41 |
44 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherGtk); | 42 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherTimer); |
45 }; | 43 }; |
46 | 44 |
47 // static | 45 // static |
48 PanelMouseWatcher* PanelMouseWatcher::GetInstance() { | 46 PanelMouseWatcher* PanelMouseWatcher::GetInstance() { |
49 return PanelMouseWatcherGtk::GetInstance(); | 47 return PanelMouseWatcherTimer::GetInstance(); |
50 } | 48 } |
51 | 49 |
52 // static | 50 // static |
53 PanelMouseWatcherGtk* PanelMouseWatcherGtk::GetInstance() { | 51 PanelMouseWatcherTimer* PanelMouseWatcherTimer::GetInstance() { |
54 return Singleton<PanelMouseWatcherGtk>::get(); | 52 return Singleton<PanelMouseWatcherTimer>::get(); |
55 } | 53 } |
56 | 54 |
57 PanelMouseWatcherGtk::PanelMouseWatcherGtk() : PanelMouseWatcher() { | 55 PanelMouseWatcherTimer::PanelMouseWatcherTimer() : PanelMouseWatcher() { |
58 } | 56 } |
59 | 57 |
60 PanelMouseWatcherGtk::~PanelMouseWatcherGtk() { | 58 PanelMouseWatcherTimer::~PanelMouseWatcherTimer() { |
59 DCHECK(!timer_.IsRunning()); | |
61 } | 60 } |
62 | 61 |
63 void PanelMouseWatcherGtk::Start() { | 62 void PanelMouseWatcherTimer::Start() { |
64 DCHECK(!timer_.IsRunning()); | 63 DCHECK(!timer_.IsRunning()); |
65 timer_.Start(FROM_HERE, | 64 timer_.Start(FROM_HERE, |
66 base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs), | 65 base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs), |
67 this, &PanelMouseWatcherGtk::DoWork); | 66 this, &PanelMouseWatcherTimer::DoWork); |
68 } | 67 } |
69 | 68 |
70 void PanelMouseWatcherGtk::Stop() { | 69 void PanelMouseWatcherTimer::Stop() { |
71 DCHECK(timer_.IsRunning()); | 70 DCHECK(timer_.IsRunning()); |
72 timer_.Stop(); | 71 timer_.Stop(); |
73 } | 72 } |
74 | 73 |
75 void PanelMouseWatcherGtk::DoWork() { | 74 void PanelMouseWatcherTimer::DoWork() { |
76 HandleMouseMovement(gfx::Screen::GetCursorScreenPoint()); | 75 HandleMouseMovement(gfx::Screen::GetCursorScreenPoint()); |
77 } | 76 } |
OLD | NEW |