Chromium Code Reviews| 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 #include "ash/autoclick/autoclick_ring_handler.h" | |
| 6 | 7 |
| 7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 8 #include "ash/wm/aura/wm_window_aura.h" | 9 #include "ash/wm/aura/wm_window_aura.h" |
| 9 #include "ash/wm/common/root_window_finder.h" | 10 #include "ash/wm/common/root_window_finder.h" |
| 10 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 11 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 12 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 14 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_handler.h" | 16 #include "ui/events/event_handler.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 void SetAutoclickDelay(int delay_ms) override; | 57 void SetAutoclickDelay(int delay_ms) override; |
| 57 int GetAutoclickDelay() const override; | 58 int GetAutoclickDelay() const override; |
| 58 | 59 |
| 59 // ui::EventHandler overrides: | 60 // ui::EventHandler overrides: |
| 60 void OnMouseEvent(ui::MouseEvent* event) override; | 61 void OnMouseEvent(ui::MouseEvent* event) override; |
| 61 void OnKeyEvent(ui::KeyEvent* event) override; | 62 void OnKeyEvent(ui::KeyEvent* event) override; |
| 62 void OnTouchEvent(ui::TouchEvent* event) override; | 63 void OnTouchEvent(ui::TouchEvent* event) override; |
| 63 void OnGestureEvent(ui::GestureEvent* event) override; | 64 void OnGestureEvent(ui::GestureEvent* event) override; |
| 64 void OnScrollEvent(ui::ScrollEvent* event) override; | 65 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 65 | 66 |
| 67 void StartRingDisplay(ui::LocatedEvent* event); | |
| 68 void StopRingDisplay(ui::LocatedEvent* event); | |
| 69 | |
| 66 void InitClickTimer(); | 70 void InitClickTimer(); |
| 67 | 71 |
| 68 void DoAutoclick(); | 72 void DoAutoclick(); |
| 69 | 73 |
| 70 bool enabled_; | 74 bool enabled_; |
| 71 int delay_ms_; | 75 int delay_ms_; |
| 72 int mouse_event_flags_; | 76 int mouse_event_flags_; |
| 73 std::unique_ptr<base::Timer> autoclick_timer_; | 77 std::unique_ptr<base::Timer> autoclick_timer_; |
| 78 std::unique_ptr<LongPressAutoclickRingHandler> autoclick_ring_display_; | |
| 74 // The position in screen coordinates used to determine | 79 // The position in screen coordinates used to determine |
| 75 // the distance the mouse has moved. | 80 // the distance the mouse has moved. |
| 76 gfx::Point anchor_location_; | 81 gfx::Point anchor_location_; |
| 77 | 82 |
| 78 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); | 83 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 | 86 |
| 82 AutoclickControllerImpl::AutoclickControllerImpl() | 87 AutoclickControllerImpl::AutoclickControllerImpl() |
| 83 : enabled_(false), | 88 : enabled_(false), |
| 84 delay_ms_(kDefaultAutoclickDelayMs), | 89 delay_ms_(kDefaultAutoclickDelayMs), |
| 85 mouse_event_flags_(ui::EF_NONE), | 90 mouse_event_flags_(ui::EF_NONE), |
| 86 anchor_location_(-kMovementThreshold, -kMovementThreshold) { | 91 anchor_location_(-kMovementThreshold, -kMovementThreshold) { |
| 87 InitClickTimer(); | 92 InitClickTimer(); |
| 93 autoclick_ring_display_.reset(new LongPressAutoclickRingHandler); | |
|
jdufault
2016/05/31 19:06:15
Use trailing parens with constructors: new LongPre
sammiequon
2016/06/03 21:34:31
Done.
| |
| 88 } | 94 } |
| 89 | 95 |
| 90 AutoclickControllerImpl::~AutoclickControllerImpl() { | 96 AutoclickControllerImpl::~AutoclickControllerImpl() { |
| 91 } | 97 } |
| 92 | 98 |
| 93 void AutoclickControllerImpl::SetEnabled(bool enabled) { | 99 void AutoclickControllerImpl::SetEnabled(bool enabled) { |
| 94 if (enabled_ == enabled) | 100 if (enabled_ == enabled) |
| 95 return; | 101 return; |
| 96 enabled_ = enabled; | 102 enabled_ = enabled; |
| 97 | 103 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 109 | 115 |
| 110 void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) { | 116 void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) { |
| 111 delay_ms_ = delay_ms; | 117 delay_ms_ = delay_ms; |
| 112 InitClickTimer(); | 118 InitClickTimer(); |
| 113 } | 119 } |
| 114 | 120 |
| 115 int AutoclickControllerImpl::GetAutoclickDelay() const { | 121 int AutoclickControllerImpl::GetAutoclickDelay() const { |
| 116 return delay_ms_; | 122 return delay_ms_; |
| 117 } | 123 } |
| 118 | 124 |
| 125 void AutoclickControllerImpl::StartRingDisplay(ui::LocatedEvent* event) { | |
| 126 autoclick_ring_display_->ProcessEvent(event, delay_ms_, true); | |
| 127 } | |
| 128 | |
| 129 void AutoclickControllerImpl::StopRingDisplay(ui::LocatedEvent* event) { | |
| 130 autoclick_ring_display_->ProcessEvent(event, delay_ms_, false); | |
| 131 } | |
| 132 | |
| 119 void AutoclickControllerImpl::InitClickTimer() { | 133 void AutoclickControllerImpl::InitClickTimer() { |
| 120 autoclick_timer_.reset(new base::Timer( | 134 autoclick_timer_.reset(new base::Timer( |
| 121 FROM_HERE, | 135 FROM_HERE, |
| 122 base::TimeDelta::FromMilliseconds(delay_ms_), | 136 base::TimeDelta::FromMilliseconds(delay_ms_), |
| 123 base::Bind(&AutoclickControllerImpl::DoAutoclick, | 137 base::Bind(&AutoclickControllerImpl::DoAutoclick, |
| 124 base::Unretained(this)), | 138 base::Unretained(this)), |
| 125 false)); | 139 false)); |
| 126 } | 140 } |
| 127 | 141 |
| 128 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { | 142 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { |
| 129 if (event->type() == ui::ET_MOUSE_MOVED && | 143 if (event->type() == ui::ET_MOUSE_MOVED && |
| 130 !(event->flags() & ui::EF_IS_SYNTHESIZED)) { | 144 !(event->flags() & ui::EF_IS_SYNTHESIZED)) { |
| 131 mouse_event_flags_ = event->flags(); | 145 mouse_event_flags_ = event->flags(); |
| 132 | 146 |
| 133 gfx::Point mouse_location = event->location(); | 147 gfx::Point mouse_location = event->location(); |
| 134 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), | 148 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), |
| 135 &mouse_location); | 149 &mouse_location); |
| 136 | 150 |
| 137 // The distance between the mouse location and the anchor location | 151 // The distance between the mouse location and the anchor location |
| 138 // must exceed a certain threshold to initiate a new autoclick countdown. | 152 // must exceed a certain threshold to initiate a new autoclick countdown. |
| 139 // This ensures that mouse jitter caused by poor motor control does not | 153 // This ensures that mouse jitter caused by poor motor control does not |
| 140 // 1. initiate an unwanted autoclick from rest | 154 // 1. initiate an unwanted autoclick from rest |
| 141 // 2. prevent the autoclick from ever occuring when the mouse | 155 // 2. prevent the autoclick from ever occuring when the mouse |
| 142 // arrives at the target. | 156 // arrives at the target. |
| 143 gfx::Vector2d delta = mouse_location - anchor_location_; | 157 gfx::Vector2d delta = mouse_location - anchor_location_; |
| 144 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { | 158 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { |
| 145 anchor_location_ = mouse_location; | 159 anchor_location_ = mouse_location; |
| 146 autoclick_timer_->Reset(); | 160 autoclick_timer_->Reset(); |
| 161 StartRingDisplay(event); | |
| 147 } | 162 } |
| 148 } else if (event->type() == ui::ET_MOUSE_PRESSED) { | 163 } else if (event->type() == ui::ET_MOUSE_PRESSED) { |
| 149 autoclick_timer_->Stop(); | 164 autoclick_timer_->Stop(); |
| 165 StopRingDisplay(event); | |
| 150 } else if (event->type() == ui::ET_MOUSEWHEEL && | 166 } else if (event->type() == ui::ET_MOUSEWHEEL && |
| 151 autoclick_timer_->IsRunning()) { | 167 autoclick_timer_->IsRunning()) { |
| 152 autoclick_timer_->Reset(); | 168 autoclick_timer_->Reset(); |
| 169 StartRingDisplay(event); | |
| 153 } | 170 } |
| 154 } | 171 } |
| 155 | 172 |
| 156 void AutoclickControllerImpl::OnKeyEvent(ui::KeyEvent* event) { | 173 void AutoclickControllerImpl::OnKeyEvent(ui::KeyEvent* event) { |
| 157 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 174 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | |
| 158 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | 175 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | |
| 159 ui::EF_IS_EXTENDED_KEY; | 176 ui::EF_IS_EXTENDED_KEY; |
| 160 int new_modifiers = event->flags() & modifier_mask; | 177 int new_modifiers = event->flags() & modifier_mask; |
| 161 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; | 178 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; |
| 162 | 179 |
| 163 if (!IsModifierKey(event->key_code())) | 180 if (!IsModifierKey(event->key_code())) { |
| 164 autoclick_timer_->Stop(); | 181 autoclick_timer_->Stop(); |
| 182 StopRingDisplay(NULL); | |
|
jdufault
2016/05/31 19:06:15
nit: nullptr
sammiequon
2016/06/03 21:34:30
Done.
| |
| 183 } | |
| 165 } | 184 } |
| 166 | 185 |
| 167 void AutoclickControllerImpl::OnTouchEvent(ui::TouchEvent* event) { | 186 void AutoclickControllerImpl::OnTouchEvent(ui::TouchEvent* event) { |
| 168 autoclick_timer_->Stop(); | 187 autoclick_timer_->Stop(); |
| 188 StopRingDisplay(event); | |
| 169 } | 189 } |
| 170 | 190 |
| 171 void AutoclickControllerImpl::OnGestureEvent(ui::GestureEvent* event) { | 191 void AutoclickControllerImpl::OnGestureEvent(ui::GestureEvent* event) { |
| 172 autoclick_timer_->Stop(); | 192 autoclick_timer_->Stop(); |
| 193 StopRingDisplay(event); | |
| 173 } | 194 } |
| 174 | 195 |
| 175 void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { | 196 void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { |
| 176 autoclick_timer_->Stop(); | 197 autoclick_timer_->Stop(); |
| 198 StopRingDisplay(event); | |
| 177 } | 199 } |
| 178 | 200 |
| 179 void AutoclickControllerImpl::DoAutoclick() { | 201 void AutoclickControllerImpl::DoAutoclick() { |
| 180 gfx::Point screen_location = | 202 gfx::Point screen_location = |
| 181 aura::Env::GetInstance()->last_mouse_location(); | 203 aura::Env::GetInstance()->last_mouse_location(); |
| 182 aura::Window* root_window = | 204 aura::Window* root_window = |
| 183 wm::WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(screen_location)); | 205 wm::WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(screen_location)); |
| 184 DCHECK(root_window) << "Root window not found while attempting autoclick."; | 206 DCHECK(root_window) << "Root window not found while attempting autoclick."; |
| 185 | 207 |
| 186 gfx::Point click_location(screen_location); | 208 gfx::Point click_location(screen_location); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 206 if (details.dispatcher_destroyed) | 228 if (details.dispatcher_destroyed) |
| 207 return; | 229 return; |
| 208 } | 230 } |
| 209 | 231 |
| 210 // static. | 232 // static. |
| 211 AutoclickController* AutoclickController::CreateInstance() { | 233 AutoclickController* AutoclickController::CreateInstance() { |
| 212 return new AutoclickControllerImpl(); | 234 return new AutoclickControllerImpl(); |
| 213 } | 235 } |
| 214 | 236 |
| 215 } // namespace ash | 237 } // namespace ash |
| OLD | NEW |