| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/aura/test/event_generator.h" | 5 #include "ui/aura/test/event_generator.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "ui/aura/root_window.h" | 8 #include "ui/aura/root_window.h" |
| 9 #include "ui/base/events/event.h" | 9 #include "ui/base/events/event.h" |
| 10 #include "ui/gfx/vector2d_conversions.h" |
| 10 | 11 |
| 11 #if defined(USE_X11) | 12 #if defined(USE_X11) |
| 12 #include <X11/Xlib.h> | 13 #include <X11/Xlib.h> |
| 13 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 17 #include "ui/base/keycodes/keyboard_code_conversion.h" | 18 #include "ui/base/keycodes/keyboard_code_conversion.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 current_location_, flags_); | 120 current_location_, flags_); |
| 120 Dispatch(mouseev); | 121 Dispatch(mouseev); |
| 121 flags_ ^= ui::EF_RIGHT_MOUSE_BUTTON; | 122 flags_ ^= ui::EF_RIGHT_MOUSE_BUTTON; |
| 122 } | 123 } |
| 123 } | 124 } |
| 124 | 125 |
| 125 void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) { | 126 void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) { |
| 126 DCHECK_GT(count, 0); | 127 DCHECK_GT(count, 0); |
| 127 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 128 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
| 128 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 129 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
| 129 const gfx::Point diff = point.Subtract(current_location_); | 130 gfx::Vector2dF diff(point - current_location_); |
| 130 for (int i = 1; i <= count; i++) { | 131 for (float i = 1; i <= count; i++) { |
| 131 const gfx::Point move_point = current_location_.Add( | 132 gfx::Vector2dF step(diff); |
| 132 gfx::Point(diff.x() / count * i, diff.y() / count * i)); | 133 step.Scale(i / count); |
| 134 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
| 133 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); | 135 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); |
| 134 Dispatch(mouseev); | 136 Dispatch(mouseev); |
| 135 } | 137 } |
| 136 current_location_ = point; | 138 current_location_ = point; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void EventGenerator::MoveMouseRelativeTo(const Window* window, | 141 void EventGenerator::MoveMouseRelativeTo(const Window* window, |
| 140 const gfx::Point& point) { | 142 const gfx::Point& point) { |
| 141 gfx::Point root_point(point); | 143 gfx::Point root_point(point); |
| 142 Window::ConvertPointToTarget(window, root_window_, &root_point); | 144 Window::ConvertPointToTarget(window, root_window_, &root_point); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 TestKeyEvent keyev(native_event.get(), flags, false); | 337 TestKeyEvent keyev(native_event.get(), flags, false); |
| 336 #else | 338 #else |
| 337 ui::KeyEvent keyev(type, key_code, flags, false); | 339 ui::KeyEvent keyev(type, key_code, flags, false); |
| 338 #endif // USE_X11 | 340 #endif // USE_X11 |
| 339 #endif // OS_WIN | 341 #endif // OS_WIN |
| 340 Dispatch(keyev); | 342 Dispatch(keyev); |
| 341 } | 343 } |
| 342 | 344 |
| 343 } // namespace test | 345 } // namespace test |
| 344 } // namespace aura | 346 } // namespace aura |
| OLD | NEW |