| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/common/autoclick_controller_common.h" | 5 #include "ash/autoclick/common/autoclick_controller_common.h" |
| 6 | 6 |
| 7 #include "ash/autoclick/common/autoclick_controller_common_delegate.h" | 7 #include "ash/autoclick/common/autoclick_controller_common_delegate.h" |
| 8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 9 #include "ui/display/screen.h" | 9 #include "ui/display/screen.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 mouse_event_flags_(ui::EF_NONE), | 36 mouse_event_flags_(ui::EF_NONE), |
| 37 delegate_(delegate), | 37 delegate_(delegate), |
| 38 widget_(nullptr), | 38 widget_(nullptr), |
| 39 anchor_location_(-kMovementThreshold, -kMovementThreshold), | 39 anchor_location_(-kMovementThreshold, -kMovementThreshold), |
| 40 autoclick_ring_handler_(new AutoclickRingHandler()) { | 40 autoclick_ring_handler_(new AutoclickRingHandler()) { |
| 41 InitClickTimer(); | 41 InitClickTimer(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 AutoclickControllerCommon::~AutoclickControllerCommon() {} | 44 AutoclickControllerCommon::~AutoclickControllerCommon() {} |
| 45 | 45 |
| 46 void AutoclickControllerCommon::HandleMouseEvent(const ui::MouseEvent& event) { | 46 void AutoclickControllerCommon::HandleMouseEvent( |
| 47 const ui::PointerEvent& event) { |
| 48 DCHECK(event.IsMousePointerEvent()); |
| 47 gfx::Point mouse_location = event.location(); | 49 gfx::Point mouse_location = event.location(); |
| 48 if (event.type() == ui::ET_MOUSE_MOVED && | 50 if (event.type() == ui::ET_POINTER_MOVED && |
| 49 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { | 51 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
| 50 mouse_event_flags_ = event.flags(); | 52 mouse_event_flags_ = event.flags(); |
| 51 | 53 |
| 52 // TODO(riajiang): Make getting screen location work for mus as well. | 54 // TODO(riajiang): Make getting screen location work for mus as well. |
| 53 // (crbug.com/608547) | 55 // (crbug.com/608547) |
| 54 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event.target()), | 56 if (event.target() != nullptr) { |
| 55 &mouse_location); | 57 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event.target()), |
| 58 &mouse_location); |
| 59 } |
| 56 UpdateRingWidget(mouse_location); | 60 UpdateRingWidget(mouse_location); |
| 57 | 61 |
| 58 // The distance between the mouse location and the anchor location | 62 // The distance between the mouse location and the anchor location |
| 59 // must exceed a certain threshold to initiate a new autoclick countdown. | 63 // must exceed a certain threshold to initiate a new autoclick countdown. |
| 60 // This ensures that mouse jitter caused by poor motor control does not | 64 // This ensures that mouse jitter caused by poor motor control does not |
| 61 // 1. initiate an unwanted autoclick from rest | 65 // 1. initiate an unwanted autoclick from rest |
| 62 // 2. prevent the autoclick from ever occuring when the mouse | 66 // 2. prevent the autoclick from ever occuring when the mouse |
| 63 // arrives at the target. | 67 // arrives at the target. |
| 64 gfx::Vector2d delta = mouse_location - anchor_location_; | 68 gfx::Vector2d delta = mouse_location - anchor_location_; |
| 65 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { | 69 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { |
| 66 anchor_location_ = mouse_location; | 70 anchor_location_ = mouse_location; |
| 67 autoclick_timer_->Reset(); | 71 autoclick_timer_->Reset(); |
| 68 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, | 72 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_); |
| 69 widget_.get()); | |
| 70 } else if (autoclick_timer_->IsRunning()) { | 73 } else if (autoclick_timer_->IsRunning()) { |
| 71 autoclick_ring_handler_->SetGestureCenter(mouse_location, widget_.get()); | 74 autoclick_ring_handler_->SetGestureCenter(mouse_location, widget_); |
| 72 } | 75 } |
| 73 } else if (event.type() == ui::ET_MOUSE_PRESSED) { | 76 } else if (event.type() == ui::ET_POINTER_DOWN) { |
| 74 CancelAutoclick(); | 77 CancelAutoclick(); |
| 75 } else if (event.type() == ui::ET_MOUSEWHEEL && | 78 } else if (event.type() == ui::ET_POINTER_WHEEL_CHANGED && |
| 76 autoclick_timer_->IsRunning()) { | 79 autoclick_timer_->IsRunning()) { |
| 77 autoclick_timer_->Reset(); | 80 autoclick_timer_->Reset(); |
| 78 UpdateRingWidget(mouse_location); | 81 UpdateRingWidget(mouse_location); |
| 79 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, | 82 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_); |
| 80 widget_.get()); | |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 84 void AutoclickControllerCommon::HandleKeyEvent(const ui::KeyEvent& event) { | 86 void AutoclickControllerCommon::HandleKeyEvent(const ui::KeyEvent& event) { |
| 85 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 87 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | |
| 86 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | 88 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | |
| 87 ui::EF_IS_EXTENDED_KEY; | 89 ui::EF_IS_EXTENDED_KEY; |
| 88 int new_modifiers = event.flags() & modifier_mask; | 90 int new_modifiers = event.flags() & modifier_mask; |
| 89 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; | 91 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; |
| 90 | 92 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 void AutoclickControllerCommon::DoAutoclick() { | 115 void AutoclickControllerCommon::DoAutoclick() { |
| 114 gfx::Point screen_location = | 116 gfx::Point screen_location = |
| 115 display::Screen::GetScreen()->GetCursorScreenPoint(); | 117 display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 116 anchor_location_ = screen_location; | 118 anchor_location_ = screen_location; |
| 117 delegate_->DoAutoclick(screen_location, mouse_event_flags_); | 119 delegate_->DoAutoclick(screen_location, mouse_event_flags_); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void AutoclickControllerCommon::UpdateRingWidget( | 122 void AutoclickControllerCommon::UpdateRingWidget( |
| 121 const gfx::Point& mouse_location) { | 123 const gfx::Point& mouse_location) { |
| 122 if (!widget_) { | 124 if (!widget_) { |
| 123 widget_.reset( | 125 widget_ = delegate_->CreateAutoclickRingWidget(mouse_location); |
| 124 (delegate_->CreateAutoclickRingWidget(mouse_location)).release()); | |
| 125 } else { | 126 } else { |
| 126 delegate_->UpdateAutoclickRingWidget(widget_.get(), mouse_location); | 127 delegate_->UpdateAutoclickRingWidget(widget_, mouse_location); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 } // namespace ash | 131 } // namespace ash |
| OLD | NEW |