Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/ui/panels/panel_mouse_watcher_gtk.cc

Issue 7981012: Add Mouse hover behavior to Mac Panels when minimized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cr feedback Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // #include "chrome/browser/ui/panels/panel_mouse_watcher_gtk.h"
6
7 #include "base/memory/singleton.h"
8 #include "base/time.h"
9 #include "base/timer.h"
10 #include "chrome/browser/ui/panels/panel_manager.h"
11 #include "chrome/browser/ui/panels/panel_mouse_watcher.h"
12 #include "ui/gfx/screen.h"
13
14 // A timer based implementation of PanelMouseWatcher. Currently used on Gtk
15 // but could be used on any platform.
16 class PanelMouseWatcherGtk : public PanelMouseWatcher {
17 public:
18 // Returns the singleton instance.
19 static PanelMouseWatcherGtk* GetInstance();
20
21 virtual ~PanelMouseWatcherGtk();
22
23 protected:
24 virtual void Start();
25 virtual void Stop();
26
27 private:
28 // Specifies the rate at which we want to sample the mouse position.
29 static const int kMousePollingIntervalMs = 250;
30
31 PanelMouseWatcherGtk();
32 friend struct DefaultSingletonTraits<PanelMouseWatcherGtk>;
33
34 // Timer callback function.
35 void DoWork();
36 friend class base::RepeatingTimer<PanelMouseWatcherGtk>;
37
38 // Timer used to track mouse movements. Gtk does not provide an easy way of
39 // 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
41 // getting a lot of notifications when tracking mouse movements.
42 base::RepeatingTimer<PanelMouseWatcherGtk> timer_;
43
44 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherGtk);
45 };
46
47 // static
48 PanelMouseWatcher* PanelMouseWatcher::GetInstance() {
49 return PanelMouseWatcherGtk::GetInstance();
50 }
51
52 // static
53 PanelMouseWatcherGtk* PanelMouseWatcherGtk::GetInstance() {
54 return Singleton<PanelMouseWatcherGtk>::get();
55 }
56
57 PanelMouseWatcherGtk::PanelMouseWatcherGtk() : PanelMouseWatcher() {
58 }
59
60 PanelMouseWatcherGtk::~PanelMouseWatcherGtk() {
61 }
62
63 void PanelMouseWatcherGtk::Start() {
64 DCHECK(!timer_.IsRunning());
65 timer_.Start(FROM_HERE,
66 base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs),
67 this, &PanelMouseWatcherGtk::DoWork);
68 }
69
70 void PanelMouseWatcherGtk::Stop() {
71 DCHECK(timer_.IsRunning());
72 timer_.Stop();
73 }
74
75 void PanelMouseWatcherGtk::DoWork() {
76 HandleMouseMovement(gfx::Screen::GetCursorScreenPoint());
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698