Chromium Code Reviews| Index: ash/autoclick/autoclick_controller.cc |
| diff --git a/ash/autoclick/autoclick_controller.cc b/ash/autoclick/autoclick_controller.cc |
| index 4692f759f8d26aa828817a318b71df091f649032..a547836da1e49b0fff21d2d06386ba8dfed383f8 100644 |
| --- a/ash/autoclick/autoclick_controller.cc |
| +++ b/ash/autoclick/autoclick_controller.cc |
| @@ -51,10 +51,11 @@ class AutoclickControllerImpl : public AutoclickController, |
| private: |
| // AutoclickController overrides: |
| + void SetDelegate(std::unique_ptr<Delegate> delegate) override; |
| void SetEnabled(bool enabled) override; |
| bool IsEnabled() const override; |
| - void SetAutoclickDelay(int delay_ms) override; |
| - int GetAutoclickDelay() const override; |
| + void SetAutoclickDelay(base::TimeDelta delay) override; |
| + base::TimeDelta GetAutoclickDelay() const override; |
| // ui::EventHandler overrides: |
| void OnMouseEvent(ui::MouseEvent* event) override; |
| @@ -63,14 +64,19 @@ class AutoclickControllerImpl : public AutoclickController, |
| void OnGestureEvent(ui::GestureEvent* event) override; |
| void OnScrollEvent(ui::ScrollEvent* event) override; |
| + void StartRingDisplay(); |
| + void StopRingDisplay(); |
| + void ChangeRingDisplayCenter(); |
| + |
| void InitClickTimer(); |
| void DoAutoclick(); |
| bool enabled_; |
| - int delay_ms_; |
| + base::TimeDelta delay_; |
| int mouse_event_flags_; |
| std::unique_ptr<base::Timer> autoclick_timer_; |
| + std::unique_ptr<Delegate> delegate_; |
| // The position in screen coordinates used to determine |
| // the distance the mouse has moved. |
| gfx::Point anchor_location_; |
| @@ -78,11 +84,12 @@ class AutoclickControllerImpl : public AutoclickController, |
| DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); |
| }; |
| - |
| AutoclickControllerImpl::AutoclickControllerImpl() |
| : enabled_(false), |
| - delay_ms_(kDefaultAutoclickDelayMs), |
| + delay_(base::TimeDelta::FromMilliseconds( |
| + static_cast<int64_t>(kDefaultAutoclickDelayMs))), |
|
jdufault
2016/06/09 16:41:26
Make kDefaultAutoclickDelayMs a base::TimeDelta va
sammiequon
2016/06/10 19:30:26
Done.
|
| mouse_event_flags_(ui::EF_NONE), |
| + delegate_(nullptr), |
| anchor_location_(-kMovementThreshold, -kMovementThreshold) { |
| InitClickTimer(); |
| } |
| @@ -90,6 +97,10 @@ AutoclickControllerImpl::AutoclickControllerImpl() |
| AutoclickControllerImpl::~AutoclickControllerImpl() { |
| } |
| +void AutoclickControllerImpl::SetDelegate(std::unique_ptr<Delegate> delegate) { |
| + delegate_ = std::move(delegate); |
| +} |
| + |
| void AutoclickControllerImpl::SetEnabled(bool enabled) { |
| if (enabled_ == enabled) |
| return; |
| @@ -107,21 +118,34 @@ bool AutoclickControllerImpl::IsEnabled() const { |
| return enabled_; |
| } |
| -void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) { |
| - delay_ms_ = delay_ms; |
| +void AutoclickControllerImpl::SetAutoclickDelay(base::TimeDelta delay) { |
| + delay_ = delay; |
| InitClickTimer(); |
| } |
| -int AutoclickControllerImpl::GetAutoclickDelay() const { |
| - return delay_ms_; |
| +base::TimeDelta AutoclickControllerImpl::GetAutoclickDelay() const { |
| + return delay_; |
| +} |
| + |
| +void AutoclickControllerImpl::StartRingDisplay() { |
| + if (delegate_) |
| + delegate_->StartGesture(delay_, anchor_location_); |
| +} |
| + |
| +void AutoclickControllerImpl::StopRingDisplay() { |
| + if (delegate_) |
| + delegate_->StopGesture(); |
| +} |
| + |
| +void AutoclickControllerImpl::ChangeRingDisplayCenter() { |
| + if (delegate_) |
| + delegate_->SetGestureCenter(anchor_location_); |
| } |
| void AutoclickControllerImpl::InitClickTimer() { |
| autoclick_timer_.reset(new base::Timer( |
| - FROM_HERE, |
| - base::TimeDelta::FromMilliseconds(delay_ms_), |
| - base::Bind(&AutoclickControllerImpl::DoAutoclick, |
| - base::Unretained(this)), |
| + FROM_HERE, delay_, |
| + base::Bind(&AutoclickControllerImpl::DoAutoclick, base::Unretained(this)), |
| false)); |
| } |
| @@ -144,12 +168,18 @@ void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { |
| if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { |
| anchor_location_ = mouse_location; |
| autoclick_timer_->Reset(); |
| + StartRingDisplay(); |
| + } else if (autoclick_timer_->IsRunning()) { |
| + anchor_location_ = mouse_location; |
| + ChangeRingDisplayCenter(); |
| } |
| } else if (event->type() == ui::ET_MOUSE_PRESSED) { |
| autoclick_timer_->Stop(); |
| + StopRingDisplay(); |
| } else if (event->type() == ui::ET_MOUSEWHEEL && |
| autoclick_timer_->IsRunning()) { |
| autoclick_timer_->Reset(); |
| + StartRingDisplay(); |
| } |
| } |
| @@ -160,20 +190,25 @@ void AutoclickControllerImpl::OnKeyEvent(ui::KeyEvent* event) { |
| int new_modifiers = event->flags() & modifier_mask; |
| mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; |
| - if (!IsModifierKey(event->key_code())) |
| + if (!IsModifierKey(event->key_code())) { |
| autoclick_timer_->Stop(); |
| + StopRingDisplay(); |
| + } |
| } |
| void AutoclickControllerImpl::OnTouchEvent(ui::TouchEvent* event) { |
| autoclick_timer_->Stop(); |
| + StopRingDisplay(); |
| } |
| void AutoclickControllerImpl::OnGestureEvent(ui::GestureEvent* event) { |
| autoclick_timer_->Stop(); |
| + StopRingDisplay(); |
| } |
| void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { |
| autoclick_timer_->Stop(); |
| + StopRingDisplay(); |
| } |
| void AutoclickControllerImpl::DoAutoclick() { |