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 for (int i = 1; i <= count; i++) { | 130 for (int i = 1; i <= count; i++) { |
131 const gfx::Point move_point = current_location_.Add( | 131 gfx::Vector2dF diff = point - current_location_; |
Peter Kasting
2012/10/30 21:41:23
This is wrong if one of the mouse dispatch event p
danakj
2012/10/30 21:49:10
ya, ok!
| |
132 gfx::Point(diff.x() / count * i, diff.y() / count * i)); | 132 diff.Scale(static_cast<float>(i) / count); |
133 gfx::Point move_point = current_location_ + gfx::ToFlooredVector2d(diff); | |
133 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); | 134 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); |
134 Dispatch(mouseev); | 135 Dispatch(mouseev); |
135 } | 136 } |
136 current_location_ = point; | 137 current_location_ = point; |
137 } | 138 } |
138 | 139 |
139 void EventGenerator::MoveMouseRelativeTo(const Window* window, | 140 void EventGenerator::MoveMouseRelativeTo(const Window* window, |
140 const gfx::Point& point) { | 141 const gfx::Point& point) { |
141 gfx::Point root_point(point); | 142 gfx::Point root_point(point); |
142 Window::ConvertPointToTarget(window, root_window_, &root_point); | 143 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); | 336 TestKeyEvent keyev(native_event.get(), flags, false); |
336 #else | 337 #else |
337 ui::KeyEvent keyev(type, key_code, flags, false); | 338 ui::KeyEvent keyev(type, key_code, flags, false); |
338 #endif // USE_X11 | 339 #endif // USE_X11 |
339 #endif // OS_WIN | 340 #endif // OS_WIN |
340 Dispatch(keyev); | 341 Dispatch(keyev); |
341 } | 342 } |
342 | 343 |
343 } // namespace test | 344 } // namespace test |
344 } // namespace aura | 345 } // namespace aura |
OLD | NEW |