Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
sadrul
2016/08/12 15:00:35
2016
riajiang
2016/08/12 16:31:38
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/autoclick/common/autoclick_controller_common.h" | |
| 6 | |
| 7 #include "ui/aura/env.h" | |
| 8 #include "ui/aura/window.h" | |
| 9 #include "ui/events/event.h" | |
| 10 #include "ui/events/event_constants.h" | |
| 11 #include "ui/gfx/geometry/vector2d.h" | |
| 12 #include "ui/wm/core/coordinate_conversion.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // The threshold of mouse movement measured in DIP that will | |
| 19 // initiate a new autoclick. | |
| 20 const int kMovementThreshold = 20; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 AutoclickControllerCommon::AutoclickControllerCommon(base::TimeDelta delay, | |
| 25 Delegate* delegate) | |
| 26 : delay_(delay), | |
| 27 mouse_event_flags_(ui::EF_NONE), | |
| 28 delegate_(delegate), | |
| 29 widget_(nullptr), | |
| 30 anchor_location_(-kMovementThreshold, -kMovementThreshold), | |
| 31 autoclick_ring_handler_(new AutoclickRingHandler()) { | |
| 32 InitClickTimer(); | |
| 33 } | |
| 34 | |
| 35 AutoclickControllerCommon::~AutoclickControllerCommon() {} | |
| 36 | |
| 37 void AutoclickControllerCommon::HandleMouseEvent(const ui::MouseEvent& event) { | |
| 38 gfx::Point mouse_location = event.location(); | |
| 39 if (event.type() == ui::ET_MOUSE_MOVED && | |
| 40 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { | |
| 41 mouse_event_flags_ = event.flags(); | |
| 42 | |
| 43 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event.target()), | |
| 44 &mouse_location); | |
| 45 GetAutoclickRingWidget(mouse_location); | |
| 46 | |
| 47 // The distance between the mouse location and the anchor location | |
| 48 // must exceed a certain threshold to initiate a new autoclick countdown. | |
| 49 // This ensures that mouse jitter caused by poor motor control does not | |
| 50 // 1. initiate an unwanted autoclick from rest | |
| 51 // 2. prevent the autoclick from ever occuring when the mouse | |
| 52 // arrives at the target. | |
| 53 gfx::Vector2d delta = mouse_location - anchor_location_; | |
| 54 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { | |
| 55 anchor_location_ = mouse_location; | |
| 56 autoclick_timer_->Reset(); | |
| 57 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_); | |
| 58 } else if (autoclick_timer_->IsRunning()) { | |
| 59 autoclick_ring_handler_->SetGestureCenter(mouse_location, widget_); | |
| 60 } | |
| 61 } else if (event.type() == ui::ET_MOUSE_PRESSED) { | |
| 62 StopAutoclickTimer(); | |
| 63 StopGesture(); | |
|
sadrul
2016/08/12 15:00:35
Looks like both StopAutoclickTimer() and StopGestu
riajiang
2016/08/12 16:31:38
Only StopAutoclickTimer() is called in AutoclickCo
sadrul
2016/08/15 15:25:10
I think if you can call both StopTimer and StopGes
riajiang
2016/08/15 17:16:23
Done.
| |
| 64 } else if (event.type() == ui::ET_MOUSEWHEEL && | |
| 65 autoclick_timer_->IsRunning()) { | |
| 66 autoclick_timer_->Reset(); | |
| 67 GetAutoclickRingWidget(mouse_location); | |
| 68 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_); | |
|
sadrul
2016/08/12 15:00:35
Since |autoclick_timer_| is running at this point,
riajiang
2016/08/12 16:31:38
StartGesture() will stop the previous gesture/ rin
| |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void AutoclickControllerCommon::HandleKeyEvent(const ui::KeyEvent& event) { | |
| 73 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | |
| 74 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | |
| 75 ui::EF_IS_EXTENDED_KEY; | |
| 76 int new_modifiers = event.flags() & modifier_mask; | |
| 77 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; | |
| 78 | |
| 79 if (!IsModifierKey(event.key_code())) { | |
| 80 StopAutoclickTimer(); | |
| 81 StopGesture(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void AutoclickControllerCommon::HandleTouchEvent(const ui::TouchEvent& event) { | |
| 86 StopAutoclickTimer(); | |
| 87 StopGesture(); | |
| 88 } | |
| 89 | |
| 90 void AutoclickControllerCommon::HandleGestureEvent( | |
| 91 const ui::GestureEvent& event) { | |
| 92 StopAutoclickTimer(); | |
| 93 StopGesture(); | |
| 94 } | |
| 95 | |
| 96 void AutoclickControllerCommon::HandleScrollEvent( | |
| 97 const ui::ScrollEvent& event) { | |
| 98 StopAutoclickTimer(); | |
| 99 StopGesture(); | |
| 100 } | |
| 101 | |
| 102 void AutoclickControllerCommon::SetAutoclickDelay(const base::TimeDelta delay) { | |
| 103 delay_ = delay; | |
| 104 InitClickTimer(); | |
| 105 } | |
| 106 | |
| 107 void AutoclickControllerCommon::StopAutoclickTimer() { | |
| 108 autoclick_timer_->Stop(); | |
| 109 } | |
| 110 | |
| 111 void AutoclickControllerCommon::StopGesture() { | |
| 112 autoclick_ring_handler_->StopGesture(); | |
| 113 } | |
| 114 | |
| 115 bool AutoclickControllerCommon::IsModifierKey(const ui::KeyboardCode key_code) { | |
|
sadrul
2016/08/12 15:00:35
Move this into a separate function in the anon nam
riajiang
2016/08/12 16:31:38
But it's also being used in AutoclickControllerImp
| |
| 116 return key_code == ui::VKEY_SHIFT || key_code == ui::VKEY_LSHIFT || | |
| 117 key_code == ui::VKEY_CONTROL || key_code == ui::VKEY_LCONTROL || | |
| 118 key_code == ui::VKEY_RCONTROL || key_code == ui::VKEY_MENU || | |
| 119 key_code == ui::VKEY_LMENU || key_code == ui::VKEY_RMENU; | |
| 120 } | |
| 121 | |
| 122 void AutoclickControllerCommon::InitClickTimer() { | |
| 123 autoclick_timer_.reset(new base::Timer( | |
| 124 FROM_HERE, delay_, base::Bind(&AutoclickControllerCommon::DoAutoclick, | |
| 125 base::Unretained(this)), | |
| 126 false)); | |
| 127 } | |
| 128 | |
| 129 void AutoclickControllerCommon::DoAutoclick() { | |
| 130 gfx::Point screen_location = aura::Env::GetInstance()->last_mouse_location(); | |
|
sadrul
2016/08/12 15:00:35
Use Screen::GetCursorScreenPoint() instead.
riajiang
2016/08/12 16:31:38
Done.
| |
| 131 anchor_location_ = screen_location; | |
| 132 delegate_->DoAutoclick(screen_location, mouse_event_flags_); | |
| 133 } | |
| 134 | |
| 135 void AutoclickControllerCommon::GetAutoclickRingWidget( | |
| 136 const gfx::Point& mouse_location) { | |
| 137 if (!widget_) | |
| 138 widget_ = delegate_->CreateAutoclickRingWidget(mouse_location); | |
| 139 else | |
| 140 delegate_->UpdateAutoclickRingWidget(widget_, mouse_location); | |
| 141 } | |
| 142 | |
| 143 } // namespace ash | |
| OLD | NEW |