| 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/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/wm/root_window_finder.h" | 8 #include "ash/common/wm/root_window_finder.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // The threshold of mouse movement measured in DIP that will | 26 // The threshold of mouse movement measured in DIP that will |
| 27 // initiate a new autoclick. | 27 // initiate a new autoclick. |
| 28 const int kMovementThreshold = 20; | 28 const int kMovementThreshold = 20; |
| 29 | 29 |
| 30 bool IsModifierKey(ui::KeyboardCode key_code) { | 30 bool IsModifierKey(ui::KeyboardCode key_code) { |
| 31 return key_code == ui::VKEY_SHIFT || | 31 return key_code == ui::VKEY_SHIFT || key_code == ui::VKEY_LSHIFT || |
| 32 key_code == ui::VKEY_LSHIFT || | 32 key_code == ui::VKEY_CONTROL || key_code == ui::VKEY_LCONTROL || |
| 33 key_code == ui::VKEY_CONTROL || | 33 key_code == ui::VKEY_RCONTROL || key_code == ui::VKEY_MENU || |
| 34 key_code == ui::VKEY_LCONTROL || | 34 key_code == ui::VKEY_LMENU || key_code == ui::VKEY_RMENU; |
| 35 key_code == ui::VKEY_RCONTROL || | |
| 36 key_code == ui::VKEY_MENU || | |
| 37 key_code == ui::VKEY_LMENU || | |
| 38 key_code == ui::VKEY_RMENU; | |
| 39 } | 35 } |
| 40 | 36 |
| 41 } // namespace | 37 } // namespace |
| 42 | 38 |
| 43 // static. | 39 // static. |
| 44 base::TimeDelta AutoclickController::GetDefaultAutoclickDelay() { | 40 base::TimeDelta AutoclickController::GetDefaultAutoclickDelay() { |
| 45 return base::TimeDelta::FromMilliseconds(int64_t{kDefaultAutoclickDelayMs}); | 41 return base::TimeDelta::FromMilliseconds(int64_t{kDefaultAutoclickDelayMs}); |
| 46 } | 42 } |
| 47 | 43 |
| 48 const int AutoclickController::kDefaultAutoclickDelayMs = 1000; | 44 const int AutoclickController::kDefaultAutoclickDelayMs = 1000; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 87 |
| 92 AutoclickControllerImpl::AutoclickControllerImpl() | 88 AutoclickControllerImpl::AutoclickControllerImpl() |
| 93 : enabled_(false), | 89 : enabled_(false), |
| 94 delay_(GetDefaultAutoclickDelay()), | 90 delay_(GetDefaultAutoclickDelay()), |
| 95 mouse_event_flags_(ui::EF_NONE), | 91 mouse_event_flags_(ui::EF_NONE), |
| 96 delegate_(nullptr), | 92 delegate_(nullptr), |
| 97 anchor_location_(-kMovementThreshold, -kMovementThreshold) { | 93 anchor_location_(-kMovementThreshold, -kMovementThreshold) { |
| 98 InitClickTimer(); | 94 InitClickTimer(); |
| 99 } | 95 } |
| 100 | 96 |
| 101 AutoclickControllerImpl::~AutoclickControllerImpl() { | 97 AutoclickControllerImpl::~AutoclickControllerImpl() {} |
| 102 } | |
| 103 | 98 |
| 104 void AutoclickControllerImpl::SetDelegate(std::unique_ptr<Delegate> delegate) { | 99 void AutoclickControllerImpl::SetDelegate(std::unique_ptr<Delegate> delegate) { |
| 105 delegate_ = std::move(delegate); | 100 delegate_ = std::move(delegate); |
| 106 } | 101 } |
| 107 | 102 |
| 108 void AutoclickControllerImpl::SetEnabled(bool enabled) { | 103 void AutoclickControllerImpl::SetEnabled(bool enabled) { |
| 109 if (enabled_ == enabled) | 104 if (enabled_ == enabled) |
| 110 return; | 105 return; |
| 111 enabled_ = enabled; | 106 enabled_ = enabled; |
| 112 | 107 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 autoclick_timer_->Stop(); | 204 autoclick_timer_->Stop(); |
| 210 StopRingDisplay(); | 205 StopRingDisplay(); |
| 211 } | 206 } |
| 212 | 207 |
| 213 void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { | 208 void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { |
| 214 autoclick_timer_->Stop(); | 209 autoclick_timer_->Stop(); |
| 215 StopRingDisplay(); | 210 StopRingDisplay(); |
| 216 } | 211 } |
| 217 | 212 |
| 218 void AutoclickControllerImpl::DoAutoclick() { | 213 void AutoclickControllerImpl::DoAutoclick() { |
| 219 gfx::Point screen_location = | 214 gfx::Point screen_location = aura::Env::GetInstance()->last_mouse_location(); |
| 220 aura::Env::GetInstance()->last_mouse_location(); | |
| 221 aura::Window* root_window = | 215 aura::Window* root_window = |
| 222 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(screen_location)); | 216 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(screen_location)); |
| 223 DCHECK(root_window) << "Root window not found while attempting autoclick."; | 217 DCHECK(root_window) << "Root window not found while attempting autoclick."; |
| 224 | 218 |
| 225 gfx::Point click_location(screen_location); | 219 gfx::Point click_location(screen_location); |
| 226 anchor_location_ = click_location; | 220 anchor_location_ = click_location; |
| 227 | 221 |
| 228 ::wm::ConvertPointFromScreen(root_window, &click_location); | 222 ::wm::ConvertPointFromScreen(root_window, &click_location); |
| 229 aura::WindowTreeHost* host = root_window->GetHost(); | 223 aura::WindowTreeHost* host = root_window->GetHost(); |
| 230 host->ConvertPointToHost(&click_location); | 224 host->ConvertPointToHost(&click_location); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 245 if (details.dispatcher_destroyed) | 239 if (details.dispatcher_destroyed) |
| 246 return; | 240 return; |
| 247 } | 241 } |
| 248 | 242 |
| 249 // static. | 243 // static. |
| 250 AutoclickController* AutoclickController::CreateInstance() { | 244 AutoclickController* AutoclickController::CreateInstance() { |
| 251 return new AutoclickControllerImpl(); | 245 return new AutoclickControllerImpl(); |
| 252 } | 246 } |
| 253 | 247 |
| 254 } // namespace ash | 248 } // namespace ash |
| OLD | NEW |