| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/automation/ui_controls.h" | 5 #include "chrome/browser/automation/ui_controls.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 if (rv != i) | 213 if (rv != i) |
| 214 return false; | 214 return false; |
| 215 | 215 |
| 216 if (dispatcher.get()) | 216 if (dispatcher.get()) |
| 217 dispatcher->AddRef(); | 217 dispatcher->AddRef(); |
| 218 return true; | 218 return true; |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool SendMouseMoveImpl(long x, long y, Task* task) { | 221 bool SendMouseMoveImpl(long x, long y, Task* task) { |
| 222 // First check if the mouse is already there. |
| 223 POINT current_pos; |
| 224 ::GetCursorPos(¤t_pos); |
| 225 if (x == current_pos.x && y == current_pos.y) { |
| 226 if (task) |
| 227 MessageLoop::current()->PostTask(FROM_HERE, task); |
| 228 return true; |
| 229 } |
| 230 |
| 222 INPUT input = { 0 }; | 231 INPUT input = { 0 }; |
| 223 | 232 |
| 224 int screen_width = ::GetSystemMetrics(SM_CXSCREEN) - 1; | 233 int screen_width = ::GetSystemMetrics(SM_CXSCREEN) - 1; |
| 225 int screen_height = ::GetSystemMetrics(SM_CYSCREEN) - 1; | 234 int screen_height = ::GetSystemMetrics(SM_CYSCREEN) - 1; |
| 226 LONG pixel_x = static_cast<LONG>(x * (65535.0f / screen_width)); | 235 LONG pixel_x = static_cast<LONG>(x * (65535.0f / screen_width)); |
| 227 LONG pixel_y = static_cast<LONG>(y * (65535.0f / screen_height)); | 236 LONG pixel_y = static_cast<LONG>(y * (65535.0f / screen_height)); |
| 228 | 237 |
| 229 input.type = INPUT_MOUSE; | 238 input.type = INPUT_MOUSE; |
| 230 input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; | 239 input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; |
| 231 input.mi.dx = pixel_x; | 240 input.mi.dx = pixel_x; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 320 } |
| 312 | 321 |
| 313 bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) { | 322 bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) { |
| 314 return SendMouseMoveImpl(x, y, task); | 323 return SendMouseMoveImpl(x, y, task); |
| 315 } | 324 } |
| 316 | 325 |
| 317 bool SendMouseEvents(MouseButton type, int state) { | 326 bool SendMouseEvents(MouseButton type, int state) { |
| 318 return SendMouseEventsImpl(type, state, NULL); | 327 return SendMouseEventsImpl(type, state, NULL); |
| 319 } | 328 } |
| 320 | 329 |
| 321 void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) { | 330 bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) { |
| 322 SendMouseEventsImpl(type, state, task); | 331 return SendMouseEventsImpl(type, state, task); |
| 323 } | 332 } |
| 324 | 333 |
| 325 bool SendMouseClick(const gfx::Point& point, MouseButton type) { | 334 bool SendMouseClick(MouseButton type) { |
| 326 return SendMouseEventsImpl(type, UP | DOWN, NULL); | 335 return SendMouseEventsImpl(type, UP | DOWN, NULL); |
| 327 } | 336 } |
| 328 | 337 |
| 329 void MoveMouseToCenterAndPress(views::View* view, MouseButton button, | 338 void MoveMouseToCenterAndPress(views::View* view, MouseButton button, |
| 330 int state, Task* task) { | 339 int state, Task* task) { |
| 331 DCHECK(view); | 340 DCHECK(view); |
| 332 DCHECK(view->GetWidget()); | 341 DCHECK(view->GetWidget()); |
| 333 gfx::Point view_center(view->width() / 2, view->height() / 2); | 342 gfx::Point view_center(view->width() / 2, view->height() / 2); |
| 334 views::View::ConvertPointToScreen(view, &view_center); | 343 views::View::ConvertPointToScreen(view, &view_center); |
| 335 SendMouseMove(view_center.x(), view_center.y()); | 344 SendMouseMove(view_center.x(), view_center.y()); |
| 336 SendMouseEventsNotifyWhenDone(button, state, task); | 345 SendMouseEventsNotifyWhenDone(button, state, task); |
| 337 } | 346 } |
| 338 | 347 |
| 339 } // ui_controls | 348 } // ui_controls |
| OLD | NEW |