Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: ash/autoclick/common/autoclick_controller_common.cc

Issue 2316553003: mash: Add autoclick app. (Closed)
Patch Set: MouseEvent; if etc. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 AutoclickControllerCommon::~AutoclickControllerCommon() {} 44 AutoclickControllerCommon::~AutoclickControllerCommon() {}
45 45
46 void AutoclickControllerCommon::HandleMouseEvent(const ui::MouseEvent& event) { 46 void AutoclickControllerCommon::HandleMouseEvent(const ui::MouseEvent& event) {
47 gfx::Point mouse_location = event.location(); 47 gfx::Point mouse_location = event.location();
48 if (event.type() == ui::ET_MOUSE_MOVED && 48 if (event.type() == ui::ET_MOUSE_MOVED &&
49 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 49 !(event.flags() & ui::EF_IS_SYNTHESIZED)) {
50 mouse_event_flags_ = event.flags(); 50 mouse_event_flags_ = event.flags();
51 51
52 // TODO(riajiang): Make getting screen location work for mus as well. 52 // TODO(riajiang): Make getting screen location work for mus as well.
53 // (crbug.com/608547) 53 // Also switch to take in a PointerEvent instead of a MouseEvent after
54 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event.target()), 54 // this is done. (crbug.com/608547)
55 &mouse_location); 55 if (event.target() != nullptr) {
56 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event.target()),
57 &mouse_location);
58 }
56 UpdateRingWidget(mouse_location); 59 UpdateRingWidget(mouse_location);
57 60
58 // The distance between the mouse location and the anchor location 61 // The distance between the mouse location and the anchor location
59 // must exceed a certain threshold to initiate a new autoclick countdown. 62 // must exceed a certain threshold to initiate a new autoclick countdown.
60 // This ensures that mouse jitter caused by poor motor control does not 63 // This ensures that mouse jitter caused by poor motor control does not
61 // 1. initiate an unwanted autoclick from rest 64 // 1. initiate an unwanted autoclick from rest
62 // 2. prevent the autoclick from ever occuring when the mouse 65 // 2. prevent the autoclick from ever occuring when the mouse
63 // arrives at the target. 66 // arrives at the target.
64 gfx::Vector2d delta = mouse_location - anchor_location_; 67 gfx::Vector2d delta = mouse_location - anchor_location_;
65 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { 68 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) {
66 anchor_location_ = mouse_location; 69 anchor_location_ = mouse_location;
67 autoclick_timer_->Reset(); 70 autoclick_timer_->Reset();
68 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, 71 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_);
69 widget_.get());
70 } else if (autoclick_timer_->IsRunning()) { 72 } else if (autoclick_timer_->IsRunning()) {
71 autoclick_ring_handler_->SetGestureCenter(mouse_location, widget_.get()); 73 autoclick_ring_handler_->SetGestureCenter(mouse_location, widget_);
72 } 74 }
73 } else if (event.type() == ui::ET_MOUSE_PRESSED) { 75 } else if (event.type() == ui::ET_MOUSE_PRESSED) {
74 CancelAutoclick(); 76 CancelAutoclick();
75 } else if (event.type() == ui::ET_MOUSEWHEEL && 77 } else if (event.type() == ui::ET_MOUSEWHEEL &&
76 autoclick_timer_->IsRunning()) { 78 autoclick_timer_->IsRunning()) {
77 autoclick_timer_->Reset(); 79 autoclick_timer_->Reset();
78 UpdateRingWidget(mouse_location); 80 UpdateRingWidget(mouse_location);
79 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, 81 autoclick_ring_handler_->StartGesture(delay_, anchor_location_, widget_);
80 widget_.get());
81 } 82 }
82 } 83 }
83 84
84 void AutoclickControllerCommon::HandleKeyEvent(const ui::KeyEvent& event) { 85 void AutoclickControllerCommon::HandleKeyEvent(const ui::KeyEvent& event) {
85 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | 86 int modifier_mask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
86 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | 87 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN |
87 ui::EF_IS_EXTENDED_KEY; 88 ui::EF_IS_EXTENDED_KEY;
88 int new_modifiers = event.flags() & modifier_mask; 89 int new_modifiers = event.flags() & modifier_mask;
89 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers; 90 mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers;
90 91
(...skipping 22 matching lines...) Expand all
113 void AutoclickControllerCommon::DoAutoclick() { 114 void AutoclickControllerCommon::DoAutoclick() {
114 gfx::Point screen_location = 115 gfx::Point screen_location =
115 display::Screen::GetScreen()->GetCursorScreenPoint(); 116 display::Screen::GetScreen()->GetCursorScreenPoint();
116 anchor_location_ = screen_location; 117 anchor_location_ = screen_location;
117 delegate_->DoAutoclick(screen_location, mouse_event_flags_); 118 delegate_->DoAutoclick(screen_location, mouse_event_flags_);
118 } 119 }
119 120
120 void AutoclickControllerCommon::UpdateRingWidget( 121 void AutoclickControllerCommon::UpdateRingWidget(
121 const gfx::Point& mouse_location) { 122 const gfx::Point& mouse_location) {
122 if (!widget_) { 123 if (!widget_) {
123 widget_.reset( 124 widget_ = delegate_->CreateAutoclickRingWidget(mouse_location);
124 (delegate_->CreateAutoclickRingWidget(mouse_location)).release());
125 } else { 125 } else {
126 delegate_->UpdateAutoclickRingWidget(widget_.get(), mouse_location); 126 delegate_->UpdateAutoclickRingWidget(widget_, mouse_location);
127 } 127 }
128 } 128 }
129 129
130 } // namespace ash 130 } // namespace ash
OLDNEW
« no previous file with comments | « ash/autoclick/common/autoclick_controller_common.h ('k') | ash/autoclick/common/autoclick_controller_common_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698