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

Side by Side Diff: ash/autoclick/autoclick_controller.cc

Issue 425363002: Moving coordinate conversion methods from ash/wm to ui/wm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 6 years, 4 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
« no previous file with comments | « no previous file | ash/display/event_transformation_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/coordinate_conversion.h" 8 #include "ash/wm/coordinate_conversion.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
11 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/events/event_constants.h" 13 #include "ui/events/event_constants.h"
14 #include "ui/events/event_handler.h" 14 #include "ui/events/event_handler.h"
15 #include "ui/events/event_processor.h" 15 #include "ui/events/event_processor.h"
16 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
17 #include "ui/gfx/vector2d.h" 17 #include "ui/gfx/vector2d.h"
18 #include "ui/wm/core/coordinate_conversion.h"
18 19
19 namespace ash { 20 namespace ash {
20 21
21 namespace { 22 namespace {
22 23
23 // The threshold of mouse movement measured in DIP that will 24 // The threshold of mouse movement measured in DIP that will
24 // initiate a new autoclick. 25 // initiate a new autoclick.
25 const int kMovementThreshold = 20; 26 const int kMovementThreshold = 20;
26 27
27 bool IsModifierKey(ui::KeyboardCode key_code) { 28 bool IsModifierKey(ui::KeyboardCode key_code) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::Unretained(this)), 122 base::Unretained(this)),
122 false)); 123 false));
123 } 124 }
124 125
125 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { 126 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
126 if (event->type() == ui::ET_MOUSE_MOVED && 127 if (event->type() == ui::ET_MOUSE_MOVED &&
127 !(event->flags() & ui::EF_IS_SYNTHESIZED)) { 128 !(event->flags() & ui::EF_IS_SYNTHESIZED)) {
128 mouse_event_flags_ = event->flags(); 129 mouse_event_flags_ = event->flags();
129 130
130 gfx::Point mouse_location = event->root_location(); 131 gfx::Point mouse_location = event->root_location();
131 ash::wm::ConvertPointToScreen( 132 ::wm::ConvertPointToScreen(wm::GetRootWindowAt(mouse_location),
132 wm::GetRootWindowAt(mouse_location), 133 &mouse_location);
133 &mouse_location);
134 134
135 // The distance between the mouse location and the anchor location 135 // The distance between the mouse location and the anchor location
136 // must exceed a certain threshold to initiate a new autoclick countdown. 136 // must exceed a certain threshold to initiate a new autoclick countdown.
137 // This ensures that mouse jitter caused by poor motor control does not 137 // This ensures that mouse jitter caused by poor motor control does not
138 // 1. initiate an unwanted autoclick from rest 138 // 1. initiate an unwanted autoclick from rest
139 // 2. prevent the autoclick from ever occuring when the mouse 139 // 2. prevent the autoclick from ever occuring when the mouse
140 // arrives at the target. 140 // arrives at the target.
141 gfx::Vector2d delta = mouse_location - anchor_location_; 141 gfx::Vector2d delta = mouse_location - anchor_location_;
142 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) { 142 if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) {
143 anchor_location_ = event->root_location(); 143 anchor_location_ = event->root_location();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 void AutoclickControllerImpl::DoAutoclick() { 180 void AutoclickControllerImpl::DoAutoclick() {
181 gfx::Point screen_location = 181 gfx::Point screen_location =
182 aura::Env::GetInstance()->last_mouse_location(); 182 aura::Env::GetInstance()->last_mouse_location();
183 aura::Window* root_window = wm::GetRootWindowAt(screen_location); 183 aura::Window* root_window = wm::GetRootWindowAt(screen_location);
184 DCHECK(root_window) << "Root window not found while attempting autoclick."; 184 DCHECK(root_window) << "Root window not found while attempting autoclick.";
185 185
186 gfx::Point click_location(screen_location); 186 gfx::Point click_location(screen_location);
187 anchor_location_ = click_location; 187 anchor_location_ = click_location;
188 wm::ConvertPointFromScreen(root_window, &click_location); 188 ::wm::ConvertPointFromScreen(root_window, &click_location);
189 189
190 aura::WindowTreeHost* host = root_window->GetHost(); 190 aura::WindowTreeHost* host = root_window->GetHost();
191 host->ConvertPointToHost(&click_location); 191 host->ConvertPointToHost(&click_location);
192 192
193 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, 193 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED,
194 click_location, 194 click_location,
195 click_location, 195 click_location,
196 mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON, 196 mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON,
197 ui::EF_LEFT_MOUSE_BUTTON); 197 ui::EF_LEFT_MOUSE_BUTTON);
198 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, 198 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
199 click_location, 199 click_location,
200 click_location, 200 click_location,
201 mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON, 201 mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON,
202 ui::EF_LEFT_MOUSE_BUTTON); 202 ui::EF_LEFT_MOUSE_BUTTON);
203 203
204 ui::EventDispatchDetails details = 204 ui::EventDispatchDetails details =
205 host->event_processor()->OnEventFromSource(&press_event); 205 host->event_processor()->OnEventFromSource(&press_event);
206 if (!details.dispatcher_destroyed) 206 if (!details.dispatcher_destroyed)
207 details = host->event_processor()->OnEventFromSource(&release_event); 207 details = host->event_processor()->OnEventFromSource(&release_event);
208 if (details.dispatcher_destroyed) 208 if (details.dispatcher_destroyed)
209 return; 209 return;
210 } 210 }
211 211
212 // static. 212 // static.
213 AutoclickController* AutoclickController::CreateInstance() { 213 AutoclickController* AutoclickController::CreateInstance() {
214 return new AutoclickControllerImpl(); 214 return new AutoclickControllerImpl();
215 } 215 }
216 216
217 } // namespace ash 217 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/display/event_transformation_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698