| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/autoclick/autoclick_controller.h" | 5 #include "ash/autoclick/autoclick_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/coordinate_conversion.h" | 8 #include "ash/wm/coordinate_conversion.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 14 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
| 15 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 | 18 |
| 19 namespace { | 19 // static. |
| 20 | 20 const int AutoclickController::kDefaultAutoclickDelayMs = 400; |
| 21 // The default wait time between last mouse movement and sending the autoclick. | |
| 22 int kDefaultClickWaitTimeMs = 500; | |
| 23 | |
| 24 } // namespace | |
| 25 | 21 |
| 26 class AutoclickControllerImpl : public AutoclickController, | 22 class AutoclickControllerImpl : public AutoclickController, |
| 27 public ui::EventHandler { | 23 public ui::EventHandler { |
| 28 public: | 24 public: |
| 29 AutoclickControllerImpl(); | 25 AutoclickControllerImpl(); |
| 30 virtual ~AutoclickControllerImpl(); | 26 virtual ~AutoclickControllerImpl(); |
| 31 | 27 |
| 32 private: | 28 private: |
| 33 // AutoclickController overrides: | 29 // AutoclickController overrides: |
| 34 virtual void SetEnabled(bool enabled) OVERRIDE; | 30 virtual void SetEnabled(bool enabled) OVERRIDE; |
| 35 virtual bool IsEnabled() const OVERRIDE; | 31 virtual bool IsEnabled() const OVERRIDE; |
| 36 virtual void SetClickWaitTime(int wait_time_ms) OVERRIDE; | 32 virtual void SetAutoclickDelay(int delay_ms) OVERRIDE; |
| 37 virtual int GetClickWaitTime() const OVERRIDE; | 33 virtual int GetAutoclickDelay() const OVERRIDE; |
| 38 | 34 |
| 39 // ui::EventHandler overrides: | 35 // ui::EventHandler overrides: |
| 40 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 36 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 41 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 37 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 42 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 38 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 43 | 39 |
| 44 void InitClickTimer(); | 40 void InitClickTimer(); |
| 45 | 41 |
| 46 void DoAutoclick(); | 42 void DoAutoclick(); |
| 47 | 43 |
| 48 bool enabled_; | 44 bool enabled_; |
| 49 int wait_time_ms_; | 45 int delay_ms_; |
| 50 int mouse_event_flags_; | 46 int mouse_event_flags_; |
| 51 scoped_ptr<base::Timer> autoclick_timer_; | 47 scoped_ptr<base::Timer> autoclick_timer_; |
| 52 | 48 |
| 53 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); | 49 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); |
| 54 }; | 50 }; |
| 55 | 51 |
| 56 | 52 |
| 57 AutoclickControllerImpl::AutoclickControllerImpl() | 53 AutoclickControllerImpl::AutoclickControllerImpl() |
| 58 : enabled_(false), | 54 : enabled_(false), |
| 59 wait_time_ms_(kDefaultClickWaitTimeMs), | 55 delay_ms_(kDefaultAutoclickDelayMs), |
| 60 mouse_event_flags_(ui::EF_NONE) { | 56 mouse_event_flags_(ui::EF_NONE) { |
| 61 InitClickTimer(); | 57 InitClickTimer(); |
| 62 } | 58 } |
| 63 | 59 |
| 64 AutoclickControllerImpl::~AutoclickControllerImpl() { | 60 AutoclickControllerImpl::~AutoclickControllerImpl() { |
| 65 } | 61 } |
| 66 | 62 |
| 67 void AutoclickControllerImpl::SetEnabled(bool enabled) { | 63 void AutoclickControllerImpl::SetEnabled(bool enabled) { |
| 68 if (enabled_ == enabled) | 64 if (enabled_ == enabled) |
| 69 return; | 65 return; |
| 70 enabled_ = enabled; | 66 enabled_ = enabled; |
| 71 | 67 |
| 72 if (enabled_) { | 68 if (enabled_) { |
| 73 Shell::GetInstance()->AddPreTargetHandler(this); | 69 Shell::GetInstance()->AddPreTargetHandler(this); |
| 74 autoclick_timer_->Stop(); | 70 autoclick_timer_->Stop(); |
| 75 } else { | 71 } else { |
| 76 Shell::GetInstance()->RemovePreTargetHandler(this); | 72 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 77 } | 73 } |
| 78 } | 74 } |
| 79 | 75 |
| 80 bool AutoclickControllerImpl::IsEnabled() const { | 76 bool AutoclickControllerImpl::IsEnabled() const { |
| 81 return enabled_; | 77 return enabled_; |
| 82 } | 78 } |
| 83 | 79 |
| 84 void AutoclickControllerImpl::SetClickWaitTime(int wait_time_ms) { | 80 void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) { |
| 85 wait_time_ms_ = wait_time_ms; | 81 delay_ms_ = delay_ms; |
| 86 InitClickTimer(); | 82 InitClickTimer(); |
| 87 } | 83 } |
| 88 | 84 |
| 89 int AutoclickControllerImpl::GetClickWaitTime() const { | 85 int AutoclickControllerImpl::GetAutoclickDelay() const { |
| 90 return wait_time_ms_; | 86 return delay_ms_; |
| 91 } | 87 } |
| 92 | 88 |
| 93 void AutoclickControllerImpl::InitClickTimer() { | 89 void AutoclickControllerImpl::InitClickTimer() { |
| 94 autoclick_timer_.reset(new base::Timer( | 90 autoclick_timer_.reset(new base::Timer( |
| 95 FROM_HERE, | 91 FROM_HERE, |
| 96 base::TimeDelta::FromMilliseconds(wait_time_ms_), | 92 base::TimeDelta::FromMilliseconds(delay_ms_), |
| 97 base::Bind(&AutoclickControllerImpl::DoAutoclick, | 93 base::Bind(&AutoclickControllerImpl::DoAutoclick, |
| 98 base::Unretained(this)), | 94 base::Unretained(this)), |
| 99 false)); | 95 false)); |
| 100 } | 96 } |
| 101 | 97 |
| 102 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { | 98 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { |
| 103 if (event->type() == ui::ET_MOUSE_MOVED) { | 99 if (event->type() == ui::ET_MOUSE_MOVED) { |
| 104 mouse_event_flags_ = event->flags(); | 100 mouse_event_flags_ = event->flags(); |
| 105 autoclick_timer_->Reset(); | 101 autoclick_timer_->Reset(); |
| 106 } else if (event->type() == ui::ET_MOUSE_PRESSED) { | 102 } else if (event->type() == ui::ET_MOUSE_PRESSED) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event); | 144 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event); |
| 149 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event); | 145 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event); |
| 150 } | 146 } |
| 151 | 147 |
| 152 // static. | 148 // static. |
| 153 AutoclickController* AutoclickController::CreateInstance() { | 149 AutoclickController* AutoclickController::CreateInstance() { |
| 154 return new AutoclickControllerImpl(); | 150 return new AutoclickControllerImpl(); |
| 155 } | 151 } |
| 156 | 152 |
| 157 } // namespace ash | 153 } // namespace ash |
| OLD | NEW |