| OLD | NEW |
| 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 "ui/base/test/ui_controls_internal_win.h" | 5 #include "ui/base/test/ui_controls_internal_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "ui/events/keycodes/keyboard_code_conversion_win.h" | 15 #include "ui/events/keycodes/keyboard_code_conversion_win.h" |
| 14 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // InputDispatcher ------------------------------------------------------------ | 20 // InputDispatcher ------------------------------------------------------------ |
| 19 | 21 |
| 20 // InputDispatcher is used to listen for a mouse/keyboard event. When the | 22 // InputDispatcher is used to listen for a mouse/keyboard event. When the |
| 21 // appropriate event is received the task is notified. | 23 // appropriate event is received the task is notified. |
| 22 class InputDispatcher : public base::RefCounted<InputDispatcher> { | 24 class InputDispatcher : public base::RefCounted<InputDispatcher> { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 121 |
| 120 void InputDispatcher::DispatchedMessage(WPARAM message) { | 122 void InputDispatcher::DispatchedMessage(WPARAM message) { |
| 121 if (message == message_waiting_for_) | 123 if (message == message_waiting_for_) |
| 122 MatchingMessageFound(); | 124 MatchingMessageFound(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void InputDispatcher::MatchingMessageFound() { | 127 void InputDispatcher::MatchingMessageFound() { |
| 126 UninstallHook(this); | 128 UninstallHook(this); |
| 127 // At the time we're invoked the event has not actually been processed. | 129 // At the time we're invoked the event has not actually been processed. |
| 128 // Use PostTask to make sure the event has been processed before notifying. | 130 // Use PostTask to make sure the event has been processed before notifying. |
| 129 base::MessageLoop::current()->PostTask( | 131 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 130 FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this)); | 132 FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this)); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void InputDispatcher::NotifyTask() { | 135 void InputDispatcher::NotifyTask() { |
| 134 task_.Run(); | 136 task_.Run(); |
| 135 Release(); | 137 Release(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 // Private functions ---------------------------------------------------------- | 140 // Private functions ---------------------------------------------------------- |
| 139 | 141 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 246 } |
| 245 | 247 |
| 246 bool SendMouseMoveImpl(long screen_x, | 248 bool SendMouseMoveImpl(long screen_x, |
| 247 long screen_y, | 249 long screen_y, |
| 248 const base::Closure& task) { | 250 const base::Closure& task) { |
| 249 // First check if the mouse is already there. | 251 // First check if the mouse is already there. |
| 250 POINT current_pos; | 252 POINT current_pos; |
| 251 ::GetCursorPos(¤t_pos); | 253 ::GetCursorPos(¤t_pos); |
| 252 if (screen_x == current_pos.x && screen_y == current_pos.y) { | 254 if (screen_x == current_pos.x && screen_y == current_pos.y) { |
| 253 if (!task.is_null()) | 255 if (!task.is_null()) |
| 254 base::MessageLoop::current()->PostTask(FROM_HERE, task); | 256 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 255 return true; | 257 return true; |
| 256 } | 258 } |
| 257 | 259 |
| 258 INPUT input = { 0 }; | 260 INPUT input = { 0 }; |
| 259 | 261 |
| 260 int screen_width = ::GetSystemMetrics(SM_CXSCREEN) - 1; | 262 int screen_width = ::GetSystemMetrics(SM_CXSCREEN) - 1; |
| 261 int screen_height = ::GetSystemMetrics(SM_CYSCREEN) - 1; | 263 int screen_height = ::GetSystemMetrics(SM_CYSCREEN) - 1; |
| 262 LONG pixel_x = static_cast<LONG>(screen_x * (65535.0f / screen_width)); | 264 LONG pixel_x = static_cast<LONG>(screen_x * (65535.0f / screen_width)); |
| 263 LONG pixel_y = static_cast<LONG>(screen_y * (65535.0f / screen_height)); | 265 LONG pixel_y = static_cast<LONG>(screen_y * (65535.0f / screen_height)); |
| 264 | 266 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 return false; | 325 return false; |
| 324 | 326 |
| 325 if (dispatcher.get()) | 327 if (dispatcher.get()) |
| 326 dispatcher->AddRef(); | 328 dispatcher->AddRef(); |
| 327 | 329 |
| 328 return true; | 330 return true; |
| 329 } | 331 } |
| 330 | 332 |
| 331 } // namespace internal | 333 } // namespace internal |
| 332 } // namespace ui_controls | 334 } // namespace ui_controls |
| OLD | NEW |