This source file includes following definitions.
- Start
- Stop
- IsActive
- GetMousePosition
- DoWork
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#include "ui/gfx/screen.h"
class PanelMouseWatcherTimer : public PanelMouseWatcher {
public:
PanelMouseWatcherTimer();
virtual ~PanelMouseWatcherTimer();
private:
virtual void Start() OVERRIDE;
virtual void Stop() OVERRIDE;
virtual bool IsActive() const OVERRIDE;
virtual gfx::Point GetMousePosition() const OVERRIDE;
static const int kMousePollingIntervalMs = 250;
void DoWork();
friend class base::RepeatingTimer<PanelMouseWatcherTimer>;
base::RepeatingTimer<PanelMouseWatcherTimer> timer_;
DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherTimer);
};
PanelMouseWatcher* PanelMouseWatcher::Create() {
return new PanelMouseWatcherTimer();
}
PanelMouseWatcherTimer::PanelMouseWatcherTimer() {
}
PanelMouseWatcherTimer::~PanelMouseWatcherTimer() {
DCHECK(!IsActive());
}
void PanelMouseWatcherTimer::Start() {
DCHECK(!IsActive());
timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kMousePollingIntervalMs),
this, &PanelMouseWatcherTimer::DoWork);
}
void PanelMouseWatcherTimer::Stop() {
DCHECK(IsActive());
timer_.Stop();
}
bool PanelMouseWatcherTimer::IsActive() const {
return timer_.IsRunning();
}
gfx::Point PanelMouseWatcherTimer::GetMousePosition() const {
return gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
}
void PanelMouseWatcherTimer::DoWork() {
NotifyMouseMovement(GetMousePosition());
}