OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/events/test/event_generator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/time/default_tick_clock.h" | 11 #include "base/time/default_tick_clock.h" |
11 #include "ui/aura/client/screen_position_client.h" | |
12 #include "ui/aura/window_event_dispatcher.h" | |
13 #include "ui/aura/window_tree_host.h" | |
14 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
15 #include "ui/events/event_source.h" | 13 #include "ui/events/event_source.h" |
16 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
17 #include "ui/events/test/events_test_utils.h" | 15 #include "ui/events/test/events_test_utils.h" |
18 #include "ui/gfx/vector2d_conversions.h" | 16 #include "ui/gfx/vector2d_conversions.h" |
19 | 17 |
20 #if defined(USE_X11) | 18 #if defined(USE_X11) |
21 #include <X11/Xlib.h> | 19 #include <X11/Xlib.h> |
22 #include "ui/base/x/x11_util.h" | |
23 #include "ui/events/event_utils.h" | |
24 #include "ui/events/test/events_test_utils_x11.h" | 20 #include "ui/events/test/events_test_utils_x11.h" |
25 #endif | 21 #endif |
26 | 22 |
27 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
28 #include "ui/events/keycodes/keyboard_code_conversion.h" | 24 #include "ui/events/keycodes/keyboard_code_conversion.h" |
29 #endif | 25 #endif |
30 | 26 |
31 namespace aura { | 27 namespace ui { |
32 namespace test { | 28 namespace test { |
33 namespace { | 29 namespace { |
34 | 30 |
35 void DummyCallback(ui::EventType, const gfx::Vector2dF&) { | 31 void DummyCallback(EventType, const gfx::Vector2dF&) { |
36 } | 32 } |
37 | 33 |
38 class DefaultEventGeneratorDelegate : public EventGeneratorDelegate { | |
39 public: | |
40 explicit DefaultEventGeneratorDelegate(Window* root_window) | |
41 : root_window_(root_window) {} | |
42 virtual ~DefaultEventGeneratorDelegate() {} | |
43 | |
44 // EventGeneratorDelegate overrides: | |
45 virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE { | |
46 return root_window_->GetHost(); | |
47 } | |
48 | |
49 virtual client::ScreenPositionClient* GetScreenPositionClient( | |
50 const aura::Window* window) const OVERRIDE { | |
51 return NULL; | |
52 } | |
53 | |
54 private: | |
55 Window* root_window_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate); | |
58 }; | |
59 | |
60 class TestKeyEvent : public ui::KeyEvent { | 34 class TestKeyEvent : public ui::KeyEvent { |
61 public: | 35 public: |
62 TestKeyEvent(const base::NativeEvent& native_event, int flags, bool is_char) | 36 TestKeyEvent(const base::NativeEvent& native_event, int flags, bool is_char) |
63 : KeyEvent(native_event, is_char) { | 37 : KeyEvent(native_event, is_char) { |
64 set_flags(flags); | 38 set_flags(flags); |
65 } | 39 } |
66 }; | 40 }; |
67 | 41 |
68 class TestTouchEvent : public ui::TouchEvent { | 42 class TestTouchEvent : public ui::TouchEvent { |
69 public: | 43 public: |
70 TestTouchEvent(ui::EventType type, | 44 TestTouchEvent(ui::EventType type, |
71 const gfx::Point& root_location, | 45 const gfx::Point& root_location, |
72 int touch_id, | 46 int touch_id, |
73 int flags, | 47 int flags, |
74 base::TimeDelta timestamp) | 48 base::TimeDelta timestamp) |
75 : TouchEvent(type, root_location, flags, touch_id, timestamp, | 49 : TouchEvent(type, root_location, flags, touch_id, timestamp, |
76 1.0f, 1.0f, 1.0f, 1.0f) { | 50 1.0f, 1.0f, 1.0f, 1.0f) { |
77 } | 51 } |
78 | 52 |
79 private: | 53 private: |
80 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); | 54 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); |
81 }; | 55 }; |
82 | 56 |
83 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 57 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
84 | 58 |
85 } // namespace | 59 } // namespace |
86 | 60 |
87 EventGenerator::EventGenerator(Window* root_window) | 61 EventGenerator::EventGenerator(gfx::NativeWindow root_window) |
88 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 62 : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)), |
tfarina
2014/07/31 00:20:19
So now, with this, events_test_support depends on
tfarina
2014/07/31 00:49:24
And if we try to depend on either it will create a
| |
89 current_host_(delegate_->GetHostAt(current_location_)), | 63 current_target_(delegate_->GetTargetAt(current_location_)), |
90 flags_(0), | 64 flags_(0), |
91 grab_(false), | 65 grab_(false), |
92 async_(false), | 66 async_(false), |
93 tick_clock_(new base::DefaultTickClock()) { | 67 tick_clock_(new base::DefaultTickClock()) { |
94 } | 68 } |
95 | 69 |
96 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point) | 70 EventGenerator::EventGenerator(gfx::NativeWindow root_window, |
97 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 71 const gfx::Point& point) |
72 : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)), | |
98 current_location_(point), | 73 current_location_(point), |
99 current_host_(delegate_->GetHostAt(current_location_)), | 74 current_target_(delegate_->GetTargetAt(current_location_)), |
100 flags_(0), | 75 flags_(0), |
101 grab_(false), | 76 grab_(false), |
102 async_(false), | 77 async_(false), |
103 tick_clock_(new base::DefaultTickClock()) { | 78 tick_clock_(new base::DefaultTickClock()) { |
104 } | 79 } |
105 | 80 |
106 EventGenerator::EventGenerator(Window* root_window, Window* window) | 81 EventGenerator::EventGenerator(gfx::NativeWindow root_window, |
107 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 82 gfx::NativeWindow window) |
108 current_location_(CenterOfWindow(window)), | 83 : delegate_(CreateDefaultPlatformDelegate(this, root_window, window)), |
109 current_host_(delegate_->GetHostAt(current_location_)), | 84 current_location_(delegate_->CenterOfWindow(window)), |
85 current_target_(delegate_->GetTargetAt(current_location_)), | |
110 flags_(0), | 86 flags_(0), |
111 grab_(false), | 87 grab_(false), |
112 async_(false), | 88 async_(false), |
113 tick_clock_(new base::DefaultTickClock()) { | 89 tick_clock_(new base::DefaultTickClock()) { |
114 } | 90 } |
115 | 91 |
116 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) | 92 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) |
117 : delegate_(delegate), | 93 : delegate_(delegate), |
118 current_host_(delegate_->GetHostAt(current_location_)), | 94 current_target_(delegate_->GetTargetAt(current_location_)), |
119 flags_(0), | 95 flags_(0), |
120 grab_(false), | 96 grab_(false), |
121 async_(false), | 97 async_(false), |
122 tick_clock_(new base::DefaultTickClock()) { | 98 tick_clock_(new base::DefaultTickClock()) { |
123 } | 99 } |
124 | 100 |
125 EventGenerator::~EventGenerator() { | 101 EventGenerator::~EventGenerator() { |
126 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); | 102 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); |
127 i != pending_events_.end(); ++i) | 103 i != pending_events_.end(); ++i) |
128 delete *i; | 104 delete *i; |
(...skipping 30 matching lines...) Expand all Loading... | |
159 | 135 |
160 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { | 136 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { |
161 gfx::Point location = GetLocationInCurrentRoot(); | 137 gfx::Point location = GetLocationInCurrentRoot(); |
162 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, flags_, 0); | 138 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, flags_, 0); |
163 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); | 139 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); |
164 Dispatch(&wheelev); | 140 Dispatch(&wheelev); |
165 } | 141 } |
166 | 142 |
167 void EventGenerator::SendMouseExit() { | 143 void EventGenerator::SendMouseExit() { |
168 gfx::Point exit_location(current_location_); | 144 gfx::Point exit_location(current_location_); |
169 ConvertPointToTarget(current_host_->window(), &exit_location); | 145 delegate_->ConvertPointToTarget(current_target_, &exit_location); |
170 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, | 146 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, |
171 flags_, 0); | 147 flags_, 0); |
172 Dispatch(&mouseev); | 148 Dispatch(&mouseev); |
173 } | 149 } |
174 | 150 |
175 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { | 151 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { |
176 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 152 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
177 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 153 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
178 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0); | 154 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0); |
179 Dispatch(&mouseev); | 155 Dispatch(&mouseev); |
180 | 156 |
181 current_location_ = point_in_host; | 157 current_location_ = point_in_host; |
182 current_host_->ConvertPointFromHost(¤t_location_); | 158 delegate_->ConvertPointFromHost(current_target_, ¤t_location_); |
183 } | 159 } |
184 | 160 |
185 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, | 161 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, |
186 int count) { | 162 int count) { |
187 DCHECK_GT(count, 0); | 163 DCHECK_GT(count, 0); |
188 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 164 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
189 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 165 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
190 | 166 |
191 gfx::Vector2dF diff(point_in_screen - current_location_); | 167 gfx::Vector2dF diff(point_in_screen - current_location_); |
192 for (float i = 1; i <= count; i++) { | 168 for (float i = 1; i <= count; i++) { |
193 gfx::Vector2dF step(diff); | 169 gfx::Vector2dF step(diff); |
194 step.Scale(i / count); | 170 step.Scale(i / count); |
195 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); | 171 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
196 if (!grab_) | 172 if (!grab_) |
197 UpdateCurrentDispatcher(move_point); | 173 UpdateCurrentDispatcher(move_point); |
198 ConvertPointToTarget(current_host_->window(), &move_point); | 174 delegate_->ConvertPointToTarget(current_target_, &move_point); |
199 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0); | 175 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0); |
200 Dispatch(&mouseev); | 176 Dispatch(&mouseev); |
201 } | 177 } |
202 current_location_ = point_in_screen; | 178 current_location_ = point_in_screen; |
203 } | 179 } |
204 | 180 |
205 void EventGenerator::MoveMouseRelativeTo(const Window* window, | 181 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, |
206 const gfx::Point& point_in_parent) { | 182 const gfx::Point& point_in_parent) { |
207 gfx::Point point(point_in_parent); | 183 gfx::Point point(point_in_parent); |
208 ConvertPointFromTarget(window, &point); | 184 delegate_->ConvertPointFromTarget(window, &point); |
209 MoveMouseTo(point); | 185 MoveMouseTo(point); |
210 } | 186 } |
211 | 187 |
212 void EventGenerator::DragMouseTo(const gfx::Point& point) { | 188 void EventGenerator::DragMouseTo(const gfx::Point& point) { |
213 PressLeftButton(); | 189 PressLeftButton(); |
214 MoveMouseTo(point); | 190 MoveMouseTo(point); |
215 ReleaseLeftButton(); | 191 ReleaseLeftButton(); |
216 } | 192 } |
217 | 193 |
218 void EventGenerator::MoveMouseToCenterOf(Window* window) { | 194 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { |
219 MoveMouseTo(CenterOfWindow(window)); | 195 MoveMouseTo(CenterOfWindow(window)); |
220 } | 196 } |
221 | 197 |
222 void EventGenerator::PressTouch() { | 198 void EventGenerator::PressTouch() { |
223 PressTouchId(0); | 199 PressTouchId(0); |
224 } | 200 } |
225 | 201 |
226 void EventGenerator::PressTouchId(int touch_id) { | 202 void EventGenerator::PressTouchId(int touch_id) { |
227 TestTouchEvent touchev( | 203 TestTouchEvent touchev( |
228 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, | 204 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, |
(...skipping 26 matching lines...) Expand all Loading... | |
255 Now()); | 231 Now()); |
256 Dispatch(&touchev); | 232 Dispatch(&touchev); |
257 } | 233 } |
258 | 234 |
259 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { | 235 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { |
260 PressTouch(); | 236 PressTouch(); |
261 MoveTouch(point); | 237 MoveTouch(point); |
262 ReleaseTouch(); | 238 ReleaseTouch(); |
263 } | 239 } |
264 | 240 |
265 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { | 241 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(EventTarget* window) { |
266 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); | 242 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); |
267 } | 243 } |
268 | 244 |
269 void EventGenerator::GestureEdgeSwipe() { | 245 void EventGenerator::GestureEdgeSwipe() { |
270 ui::GestureEvent gesture( | 246 ui::GestureEvent gesture( |
271 0, | 247 0, |
272 0, | 248 0, |
273 0, | 249 0, |
274 Now(), | 250 Now(), |
275 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0)); | 251 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0)); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 x_offset, y_offset, | 431 x_offset, y_offset, |
456 x_offset, y_offset, | 432 x_offset, y_offset, |
457 num_fingers); | 433 num_fingers); |
458 Dispatch(&fling_start); | 434 Dispatch(&fling_start); |
459 } | 435 } |
460 | 436 |
461 void EventGenerator::ScrollSequence(const gfx::Point& start, | 437 void EventGenerator::ScrollSequence(const gfx::Point& start, |
462 const base::TimeDelta& step_delay, | 438 const base::TimeDelta& step_delay, |
463 const std::vector<gfx::Point>& offsets, | 439 const std::vector<gfx::Point>& offsets, |
464 int num_fingers) { | 440 int num_fingers) { |
465 int steps = offsets.size(); | 441 size_t steps = offsets.size(); |
466 base::TimeDelta timestamp = Now(); | 442 base::TimeDelta timestamp = Now(); |
467 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 443 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
468 start, | 444 start, |
469 timestamp, | 445 timestamp, |
470 0, | 446 0, |
471 0, 0, | 447 0, 0, |
472 0, 0, | 448 0, 0, |
473 num_fingers); | 449 num_fingers); |
474 Dispatch(&fling_cancel); | 450 Dispatch(&fling_cancel); |
475 | 451 |
476 for (int i = 0; i < steps; ++i) { | 452 for (size_t i = 0; i < steps; ++i) { |
477 timestamp += step_delay; | 453 timestamp += step_delay; |
478 ui::ScrollEvent scroll(ui::ET_SCROLL, | 454 ui::ScrollEvent scroll(ui::ET_SCROLL, |
479 start, | 455 start, |
480 timestamp, | 456 timestamp, |
481 0, | 457 0, |
482 offsets[i].x(), offsets[i].y(), | 458 offsets[i].x(), offsets[i].y(), |
483 offsets[i].x(), offsets[i].y(), | 459 offsets[i].x(), offsets[i].y(), |
484 num_fingers); | 460 num_fingers); |
485 Dispatch(&scroll); | 461 Dispatch(&scroll); |
486 } | 462 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 flags); | 519 flags); |
544 ui::KeyEvent keyev(xevent, false); | 520 ui::KeyEvent keyev(xevent, false); |
545 #else | 521 #else |
546 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 522 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
547 ui::KeyEvent keyev(type, key_code, flags, false); | 523 ui::KeyEvent keyev(type, key_code, flags, false); |
548 #endif // OS_WIN | 524 #endif // OS_WIN |
549 Dispatch(&keyev); | 525 Dispatch(&keyev); |
550 } | 526 } |
551 | 527 |
552 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 528 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
553 current_host_ = delegate_->GetHostAt(point); | 529 current_target_ = delegate_->GetTargetAt(point); |
554 } | 530 } |
555 | 531 |
556 void EventGenerator::PressButton(int flag) { | 532 void EventGenerator::PressButton(int flag) { |
557 if (!(flags_ & flag)) { | 533 if (!(flags_ & flag)) { |
558 flags_ |= flag; | 534 flags_ |= flag; |
559 grab_ = flags_ & kAllButtonMask; | 535 grab_ = (flags_ & kAllButtonMask) != 0; |
560 gfx::Point location = GetLocationInCurrentRoot(); | 536 gfx::Point location = GetLocationInCurrentRoot(); |
561 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_, | 537 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_, |
562 flag); | 538 flag); |
563 Dispatch(&mouseev); | 539 Dispatch(&mouseev); |
564 } | 540 } |
565 } | 541 } |
566 | 542 |
567 void EventGenerator::ReleaseButton(int flag) { | 543 void EventGenerator::ReleaseButton(int flag) { |
568 if (flags_ & flag) { | 544 if (flags_ & flag) { |
569 gfx::Point location = GetLocationInCurrentRoot(); | 545 gfx::Point location = GetLocationInCurrentRoot(); |
570 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, | 546 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, |
571 location, flags_, flag); | 547 location, flags_, flag); |
572 Dispatch(&mouseev); | 548 Dispatch(&mouseev); |
573 flags_ ^= flag; | 549 flags_ ^= flag; |
574 } | 550 } |
575 grab_ = flags_ & kAllButtonMask; | 551 grab_ = (flags_ & kAllButtonMask) != 0; |
576 } | |
577 | |
578 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, | |
579 gfx::Point* point) const { | |
580 DCHECK(point); | |
581 aura::client::ScreenPositionClient* client = | |
582 delegate_->GetScreenPositionClient(target); | |
583 if (client) | |
584 client->ConvertPointToScreen(target, point); | |
585 else | |
586 aura::Window::ConvertPointToTarget(target, target->GetRootWindow(), point); | |
587 } | |
588 | |
589 void EventGenerator::ConvertPointToTarget(const aura::Window* target, | |
590 gfx::Point* point) const { | |
591 DCHECK(point); | |
592 aura::client::ScreenPositionClient* client = | |
593 delegate_->GetScreenPositionClient(target); | |
594 if (client) | |
595 client->ConvertPointFromScreen(target, point); | |
596 else | |
597 aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point); | |
598 } | 552 } |
599 | 553 |
600 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { | 554 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { |
601 gfx::Point p(current_location_); | 555 gfx::Point p(current_location_); |
602 ConvertPointToTarget(current_host_->window(), &p); | 556 delegate_->ConvertPointToTarget(current_target_, &p); |
603 return p; | 557 return p; |
604 } | 558 } |
605 | 559 |
606 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { | 560 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { |
607 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); | 561 return delegate_->CenterOfTarget(window); |
608 ConvertPointFromTarget(window, ¢er); | |
609 return center; | |
610 } | 562 } |
611 | 563 |
612 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { | 564 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { |
613 if (async) { | 565 if (async) { |
614 ui::Event* pending_event; | 566 ui::Event* pending_event; |
615 if (event->IsKeyEvent()) { | 567 if (event->IsKeyEvent()) { |
616 pending_event = new ui::KeyEvent(*static_cast<ui::KeyEvent*>(event)); | 568 pending_event = new ui::KeyEvent(*static_cast<ui::KeyEvent*>(event)); |
617 } else if (event->IsMouseEvent()) { | 569 } else if (event->IsMouseEvent()) { |
618 pending_event = new ui::MouseEvent(*static_cast<ui::MouseEvent*>(event)); | 570 pending_event = new ui::MouseEvent(*static_cast<ui::MouseEvent*>(event)); |
619 } else if (event->IsTouchEvent()) { | 571 } else if (event->IsTouchEvent()) { |
620 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event)); | 572 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event)); |
621 } else if (event->IsScrollEvent()) { | 573 } else if (event->IsScrollEvent()) { |
622 pending_event = | 574 pending_event = |
623 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event)); | 575 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event)); |
624 } else { | 576 } else { |
625 NOTREACHED() << "Invalid event type"; | 577 NOTREACHED() << "Invalid event type"; |
626 return; | 578 return; |
627 } | 579 } |
628 if (pending_events_.empty()) { | 580 if (pending_events_.empty()) { |
629 base::MessageLoopProxy::current()->PostTask( | 581 base::MessageLoopProxy::current()->PostTask( |
630 FROM_HERE, | 582 FROM_HERE, |
631 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 583 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
632 base::Unretained(this))); | 584 base::Unretained(this))); |
633 } | 585 } |
634 pending_events_.push_back(pending_event); | 586 pending_events_.push_back(pending_event); |
635 } else { | 587 } else { |
636 ui::EventSource* event_source = current_host_->GetEventSource(); | 588 ui::EventSource* event_source = delegate_->GetEventSource(current_target_); |
637 ui::EventSourceTestApi event_source_test(event_source); | 589 ui::EventSourceTestApi event_source_test(event_source); |
638 ui::EventDispatchDetails details = | 590 ui::EventDispatchDetails details = |
639 event_source_test.SendEventToProcessor(event); | 591 event_source_test.SendEventToProcessor(event); |
640 CHECK(!details.dispatcher_destroyed); | 592 CHECK(!details.dispatcher_destroyed); |
641 } | 593 } |
642 } | 594 } |
643 | 595 |
644 void EventGenerator::DispatchNextPendingEvent() { | 596 void EventGenerator::DispatchNextPendingEvent() { |
645 DCHECK(!pending_events_.empty()); | 597 DCHECK(!pending_events_.empty()); |
646 ui::Event* event = pending_events_.front(); | 598 ui::Event* event = pending_events_.front(); |
647 DoDispatchEvent(event, false); | 599 DoDispatchEvent(event, false); |
648 pending_events_.pop_front(); | 600 pending_events_.pop_front(); |
649 delete event; | 601 delete event; |
650 if (!pending_events_.empty()) { | 602 if (!pending_events_.empty()) { |
651 base::MessageLoopProxy::current()->PostTask( | 603 base::MessageLoopProxy::current()->PostTask( |
652 FROM_HERE, | 604 FROM_HERE, |
653 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 605 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
654 base::Unretained(this))); | 606 base::Unretained(this))); |
655 } | 607 } |
656 } | 608 } |
657 | 609 |
658 } // namespace test | 610 } // namespace test |
659 } // namespace aura | 611 } // namespace ui |
OLD | NEW |