Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: ui/aura/test/event_generator.cc

Issue 191153004: Provide access to the WindowEventDispatcher as a ui::EventProcessor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "ui/aura/client/screen_position_client.h" 10 #include "ui/aura/client/screen_position_client.h"
(...skipping 21 matching lines...) Expand all
32 void DummyCallback(ui::EventType, const gfx::Vector2dF&) { 32 void DummyCallback(ui::EventType, const gfx::Vector2dF&) {
33 } 33 }
34 34
35 class DefaultEventGeneratorDelegate : public EventGeneratorDelegate { 35 class DefaultEventGeneratorDelegate : public EventGeneratorDelegate {
36 public: 36 public:
37 explicit DefaultEventGeneratorDelegate(Window* root_window) 37 explicit DefaultEventGeneratorDelegate(Window* root_window)
38 : root_window_(root_window) {} 38 : root_window_(root_window) {}
39 virtual ~DefaultEventGeneratorDelegate() {} 39 virtual ~DefaultEventGeneratorDelegate() {}
40 40
41 // EventGeneratorDelegate overrides: 41 // EventGeneratorDelegate overrides:
42 virtual WindowEventDispatcher* GetDispatcherAt( 42 virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE {
43 const gfx::Point& point) const OVERRIDE { 43 return root_window_->GetHost();
44 return root_window_->GetHost()->dispatcher();
45 } 44 }
46 45
47 virtual client::ScreenPositionClient* GetScreenPositionClient( 46 virtual client::ScreenPositionClient* GetScreenPositionClient(
48 const aura::Window* window) const OVERRIDE { 47 const aura::Window* window) const OVERRIDE {
49 return NULL; 48 return NULL;
50 } 49 }
51 50
52 private: 51 private:
53 Window* root_window_; 52 Window* root_window_;
54 53
(...skipping 21 matching lines...) Expand all
76 private: 75 private:
77 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); 76 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent);
78 }; 77 };
79 78
80 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; 79 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
81 80
82 } // namespace 81 } // namespace
83 82
84 EventGenerator::EventGenerator(Window* root_window) 83 EventGenerator::EventGenerator(Window* root_window)
85 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 84 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
86 current_dispatcher_(delegate_->GetDispatcherAt(current_location_)), 85 current_host_(delegate_->GetHostAt(current_location_)),
87 flags_(0), 86 flags_(0),
88 grab_(false), 87 grab_(false),
89 async_(false) { 88 async_(false) {
90 } 89 }
91 90
92 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point) 91 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point)
93 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 92 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
94 current_location_(point), 93 current_location_(point),
95 current_dispatcher_(delegate_->GetDispatcherAt(current_location_)), 94 current_host_(delegate_->GetHostAt(current_location_)),
96 flags_(0), 95 flags_(0),
97 grab_(false), 96 grab_(false),
98 async_(false) { 97 async_(false) {
99 } 98 }
100 99
101 EventGenerator::EventGenerator(Window* root_window, Window* window) 100 EventGenerator::EventGenerator(Window* root_window, Window* window)
102 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 101 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
103 current_location_(CenterOfWindow(window)), 102 current_location_(CenterOfWindow(window)),
104 current_dispatcher_(delegate_->GetDispatcherAt(current_location_)), 103 current_host_(delegate_->GetHostAt(current_location_)),
105 flags_(0), 104 flags_(0),
106 grab_(false), 105 grab_(false),
107 async_(false) { 106 async_(false) {
108 } 107 }
109 108
110 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) 109 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
111 : delegate_(delegate), 110 : delegate_(delegate),
112 current_dispatcher_(delegate_->GetDispatcherAt(current_location_)), 111 current_host_(delegate_->GetHostAt(current_location_)),
113 flags_(0), 112 flags_(0),
114 grab_(false), 113 grab_(false),
115 async_(false) { 114 async_(false) {
116 } 115 }
117 116
118 EventGenerator::~EventGenerator() { 117 EventGenerator::~EventGenerator() {
119 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); 118 for (std::list<ui::Event*>::iterator i = pending_events_.begin();
120 i != pending_events_.end(); ++i) 119 i != pending_events_.end(); ++i)
121 delete *i; 120 delete *i;
122 pending_events_.clear(); 121 pending_events_.clear();
(...skipping 22 matching lines...) Expand all
145 void EventGenerator::PressRightButton() { 144 void EventGenerator::PressRightButton() {
146 PressButton(ui::EF_RIGHT_MOUSE_BUTTON); 145 PressButton(ui::EF_RIGHT_MOUSE_BUTTON);
147 } 146 }
148 147
149 void EventGenerator::ReleaseRightButton() { 148 void EventGenerator::ReleaseRightButton() {
150 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON); 149 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON);
151 } 150 }
152 151
153 void EventGenerator::SendMouseExit() { 152 void EventGenerator::SendMouseExit() {
154 gfx::Point exit_location(current_location_); 153 gfx::Point exit_location(current_location_);
155 ConvertPointToTarget(current_dispatcher_->window(), &exit_location); 154 ConvertPointToTarget(current_host_->window(), &exit_location);
156 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, 155 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location,
157 flags_, 0); 156 flags_, 0);
158 Dispatch(&mouseev); 157 Dispatch(&mouseev);
159 } 158 }
160 159
161 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { 160 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) {
162 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? 161 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
163 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; 162 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
164 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0); 163 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0);
165 Dispatch(&mouseev); 164 Dispatch(&mouseev);
166 165
167 current_location_ = point_in_host; 166 current_location_ = point_in_host;
168 current_dispatcher_->host()->ConvertPointFromHost(&current_location_); 167 current_host_->ConvertPointFromHost(&current_location_);
169 } 168 }
170 169
171 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, 170 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
172 int count) { 171 int count) {
173 DCHECK_GT(count, 0); 172 DCHECK_GT(count, 0);
174 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? 173 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
175 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; 174 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
176 175
177 gfx::Vector2dF diff(point_in_screen - current_location_); 176 gfx::Vector2dF diff(point_in_screen - current_location_);
178 for (float i = 1; i <= count; i++) { 177 for (float i = 1; i <= count; i++) {
179 gfx::Vector2dF step(diff); 178 gfx::Vector2dF step(diff);
180 step.Scale(i / count); 179 step.Scale(i / count);
181 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); 180 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
182 if (!grab_) 181 if (!grab_)
183 UpdateCurrentDispatcher(move_point); 182 UpdateCurrentDispatcher(move_point);
184 ConvertPointToTarget(current_dispatcher_->window(), &move_point); 183 ConvertPointToTarget(current_host_->window(), &move_point);
185 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0); 184 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0);
186 Dispatch(&mouseev); 185 Dispatch(&mouseev);
187 } 186 }
188 current_location_ = point_in_screen; 187 current_location_ = point_in_screen;
189 } 188 }
190 189
191 void EventGenerator::MoveMouseRelativeTo(const Window* window, 190 void EventGenerator::MoveMouseRelativeTo(const Window* window,
192 const gfx::Point& point_in_parent) { 191 const gfx::Point& point_in_parent) {
193 gfx::Point point(point_in_parent); 192 gfx::Point point(point_in_parent);
194 ConvertPointFromTarget(window, &point); 193 ConvertPointFromTarget(window, &point);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 flags); 517 flags);
519 ui::KeyEvent keyev(xevent, false); 518 ui::KeyEvent keyev(xevent, false);
520 #else 519 #else
521 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; 520 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
522 ui::KeyEvent keyev(type, key_code, flags, false); 521 ui::KeyEvent keyev(type, key_code, flags, false);
523 #endif // OS_WIN 522 #endif // OS_WIN
524 Dispatch(&keyev); 523 Dispatch(&keyev);
525 } 524 }
526 525
527 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { 526 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) {
528 current_dispatcher_ = delegate_->GetDispatcherAt(point); 527 current_host_ = delegate_->GetHostAt(point);
529 } 528 }
530 529
531 void EventGenerator::PressButton(int flag) { 530 void EventGenerator::PressButton(int flag) {
532 if (!(flags_ & flag)) { 531 if (!(flags_ & flag)) {
533 flags_ |= flag; 532 flags_ |= flag;
534 grab_ = flags_ & kAllButtonMask; 533 grab_ = flags_ & kAllButtonMask;
535 gfx::Point location = GetLocationInCurrentRoot(); 534 gfx::Point location = GetLocationInCurrentRoot();
536 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_, 535 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_,
537 flag); 536 flag);
538 Dispatch(&mouseev); 537 Dispatch(&mouseev);
(...skipping 28 matching lines...) Expand all
567 aura::client::ScreenPositionClient* client = 566 aura::client::ScreenPositionClient* client =
568 delegate_->GetScreenPositionClient(target); 567 delegate_->GetScreenPositionClient(target);
569 if (client) 568 if (client)
570 client->ConvertPointFromScreen(target, point); 569 client->ConvertPointFromScreen(target, point);
571 else 570 else
572 aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point); 571 aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point);
573 } 572 }
574 573
575 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { 574 gfx::Point EventGenerator::GetLocationInCurrentRoot() const {
576 gfx::Point p(current_location_); 575 gfx::Point p(current_location_);
577 ConvertPointToTarget(current_dispatcher_->window(), &p); 576 ConvertPointToTarget(current_host_->window(), &p);
578 return p; 577 return p;
579 } 578 }
580 579
581 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { 580 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const {
582 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); 581 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint();
583 ConvertPointFromTarget(window, &center); 582 ConvertPointFromTarget(window, &center);
584 return center; 583 return center;
585 } 584 }
586 585
587 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { 586 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
(...skipping 13 matching lines...) Expand all
601 return; 600 return;
602 } 601 }
603 if (pending_events_.empty()) { 602 if (pending_events_.empty()) {
604 base::MessageLoopProxy::current()->PostTask( 603 base::MessageLoopProxy::current()->PostTask(
605 FROM_HERE, 604 FROM_HERE,
606 base::Bind(&EventGenerator::DispatchNextPendingEvent, 605 base::Bind(&EventGenerator::DispatchNextPendingEvent,
607 base::Unretained(this))); 606 base::Unretained(this)));
608 } 607 }
609 pending_events_.push_back(pending_event); 608 pending_events_.push_back(pending_event);
610 } else { 609 } else {
611 ui::EventDispatchDetails details = current_dispatcher_->OnEventFromSource( 610 ui::EventDispatchDetails details =
612 event); 611 current_host_->event_processor()->OnEventFromSource(event);
613 CHECK(!details.dispatcher_destroyed); 612 CHECK(!details.dispatcher_destroyed);
614 } 613 }
615 } 614 }
616 615
617 void EventGenerator::DispatchNextPendingEvent() { 616 void EventGenerator::DispatchNextPendingEvent() {
618 DCHECK(!pending_events_.empty()); 617 DCHECK(!pending_events_.empty());
619 ui::Event* event = pending_events_.front(); 618 ui::Event* event = pending_events_.front();
620 DoDispatchEvent(event, false); 619 DoDispatchEvent(event, false);
621 pending_events_.pop_front(); 620 pending_events_.pop_front();
622 delete event; 621 delete event;
623 if (!pending_events_.empty()) { 622 if (!pending_events_.empty()) {
624 base::MessageLoopProxy::current()->PostTask( 623 base::MessageLoopProxy::current()->PostTask(
625 FROM_HERE, 624 FROM_HERE,
626 base::Bind(&EventGenerator::DispatchNextPendingEvent, 625 base::Bind(&EventGenerator::DispatchNextPendingEvent,
627 base::Unretained(this))); 626 base::Unretained(this)));
628 } 627 }
629 } 628 }
630 629
631 630
632 } // namespace test 631 } // namespace test
633 } // namespace aura 632 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698