Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / panels / panel_mouse_watcher_timer.cc
blob0572eda893c3d477eb5c8d712f74d69c5f78ccaa
1 // Copyright (c) 2012 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.
5 #include "base/time/time.h"
6 #include "base/timer/timer.h"
7 #include "chrome/browser/ui/panels/panel_mouse_watcher.h"
8 #include "ui/gfx/screen.h"
10 // A timer based implementation of PanelMouseWatcher. Currently used for Gtk
11 // and Mac panels implementations.
12 class PanelMouseWatcherTimer : public PanelMouseWatcher {
13 public:
14 PanelMouseWatcherTimer();
15 virtual ~PanelMouseWatcherTimer();
17 private:
18 virtual void Start() OVERRIDE;
19 virtual void Stop() OVERRIDE;
20 virtual bool IsActive() const OVERRIDE;
21 virtual gfx::Point GetMousePosition() const OVERRIDE;
23 // Specifies the rate at which we want to sample the mouse position.
24 static const int kMousePollingIntervalMs = 250;
26 // Timer callback function.
27 void DoWork();
28 friend class base::RepeatingTimer<PanelMouseWatcherTimer>;
30 // Timer used to track mouse movements. Some OSes do not provide an easy way
31 // of tracking mouse movements across applications. So we use a timer to
32 // accomplish the same. This could also be more efficient as you end up
33 // getting a lot of notifications when tracking mouse movements.
34 base::RepeatingTimer<PanelMouseWatcherTimer> timer_;
36 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherTimer);
39 // static
40 PanelMouseWatcher* PanelMouseWatcher::Create() {
41 return new PanelMouseWatcherTimer();
44 PanelMouseWatcherTimer::PanelMouseWatcherTimer() {
47 PanelMouseWatcherTimer::~PanelMouseWatcherTimer() {
48 DCHECK(!IsActive());
51 void PanelMouseWatcherTimer::Start() {
52 DCHECK(!IsActive());
53 timer_.Start(FROM_HERE,
54 base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs),
55 this, &PanelMouseWatcherTimer::DoWork);
58 void PanelMouseWatcherTimer::Stop() {
59 DCHECK(IsActive());
60 timer_.Stop();
63 bool PanelMouseWatcherTimer::IsActive() const {
64 return timer_.IsRunning();
67 gfx::Point PanelMouseWatcherTimer::GetMousePosition() const {
68 // TODO(scottmg): NativeScreen is wrong. http://crbug.com/133312
69 return gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
72 void PanelMouseWatcherTimer::DoWork() {
73 NotifyMouseMovement(GetMousePosition());