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

Side by Side Diff: ui/aura/window_event_dispatcher_unittest.cc

Issue 684483002: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/aura/window_targeter.h » ('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/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 27 matching lines...) Expand all
38 namespace { 38 namespace {
39 39
40 // A delegate that always returns a non-client component for hit tests. 40 // A delegate that always returns a non-client component for hit tests.
41 class NonClientDelegate : public test::TestWindowDelegate { 41 class NonClientDelegate : public test::TestWindowDelegate {
42 public: 42 public:
43 NonClientDelegate() 43 NonClientDelegate()
44 : non_client_count_(0), 44 : non_client_count_(0),
45 mouse_event_count_(0), 45 mouse_event_count_(0),
46 mouse_event_flags_(0x0) { 46 mouse_event_flags_(0x0) {
47 } 47 }
48 virtual ~NonClientDelegate() {} 48 ~NonClientDelegate() override {}
49 49
50 int non_client_count() const { return non_client_count_; } 50 int non_client_count() const { return non_client_count_; }
51 gfx::Point non_client_location() const { return non_client_location_; } 51 gfx::Point non_client_location() const { return non_client_location_; }
52 int mouse_event_count() const { return mouse_event_count_; } 52 int mouse_event_count() const { return mouse_event_count_; }
53 gfx::Point mouse_event_location() const { return mouse_event_location_; } 53 gfx::Point mouse_event_location() const { return mouse_event_location_; }
54 int mouse_event_flags() const { return mouse_event_flags_; } 54 int mouse_event_flags() const { return mouse_event_flags_; }
55 55
56 virtual int GetNonClientComponent(const gfx::Point& location) const override { 56 int GetNonClientComponent(const gfx::Point& location) const override {
57 NonClientDelegate* self = const_cast<NonClientDelegate*>(this); 57 NonClientDelegate* self = const_cast<NonClientDelegate*>(this);
58 self->non_client_count_++; 58 self->non_client_count_++;
59 self->non_client_location_ = location; 59 self->non_client_location_ = location;
60 return HTTOPLEFT; 60 return HTTOPLEFT;
61 } 61 }
62 virtual void OnMouseEvent(ui::MouseEvent* event) override { 62 void OnMouseEvent(ui::MouseEvent* event) override {
63 mouse_event_count_++; 63 mouse_event_count_++;
64 mouse_event_location_ = event->location(); 64 mouse_event_location_ = event->location();
65 mouse_event_flags_ = event->flags(); 65 mouse_event_flags_ = event->flags();
66 event->SetHandled(); 66 event->SetHandled();
67 } 67 }
68 68
69 private: 69 private:
70 int non_client_count_; 70 int non_client_count_;
71 gfx::Point non_client_location_; 71 gfx::Point non_client_location_;
72 int mouse_event_count_; 72 int mouse_event_count_;
73 gfx::Point mouse_event_location_; 73 gfx::Point mouse_event_location_;
74 int mouse_event_flags_; 74 int mouse_event_flags_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); 76 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate);
77 }; 77 };
78 78
79 // A simple event handler that consumes key events. 79 // A simple event handler that consumes key events.
80 class ConsumeKeyHandler : public ui::test::TestEventHandler { 80 class ConsumeKeyHandler : public ui::test::TestEventHandler {
81 public: 81 public:
82 ConsumeKeyHandler() {} 82 ConsumeKeyHandler() {}
83 virtual ~ConsumeKeyHandler() {} 83 ~ConsumeKeyHandler() override {}
84 84
85 // Overridden from ui::EventHandler: 85 // Overridden from ui::EventHandler:
86 virtual void OnKeyEvent(ui::KeyEvent* event) override { 86 void OnKeyEvent(ui::KeyEvent* event) override {
87 ui::test::TestEventHandler::OnKeyEvent(event); 87 ui::test::TestEventHandler::OnKeyEvent(event);
88 event->StopPropagation(); 88 event->StopPropagation();
89 } 89 }
90 90
91 private: 91 private:
92 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); 92 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler);
93 }; 93 };
94 94
95 bool IsFocusedWindow(aura::Window* window) { 95 bool IsFocusedWindow(aura::Window* window) {
96 return client::GetFocusClient(window)->GetFocusedWindow() == window; 96 return client::GetFocusClient(window)->GetFocusedWindow() == window;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 : root_window_(root_window), 234 : root_window_(root_window),
235 lock_(false) { 235 lock_(false) {
236 client::SetEventClient(root_window_, this); 236 client::SetEventClient(root_window_, this);
237 Window* lock_window = 237 Window* lock_window =
238 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_); 238 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_);
239 lock_window->set_id(kLockWindowId); 239 lock_window->set_id(kLockWindowId);
240 Window* non_lock_window = 240 Window* non_lock_window =
241 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_); 241 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_);
242 non_lock_window->set_id(kNonLockWindowId); 242 non_lock_window->set_id(kNonLockWindowId);
243 } 243 }
244 virtual ~TestEventClient() { 244 ~TestEventClient() override { client::SetEventClient(root_window_, NULL); }
245 client::SetEventClient(root_window_, NULL);
246 }
247 245
248 // Starts/stops locking. Locking prevents windows other than those inside 246 // Starts/stops locking. Locking prevents windows other than those inside
249 // the lock container from receiving events, getting focus etc. 247 // the lock container from receiving events, getting focus etc.
250 void Lock() { 248 void Lock() {
251 lock_ = true; 249 lock_ = true;
252 } 250 }
253 void Unlock() { 251 void Unlock() {
254 lock_ = false; 252 lock_ = false;
255 } 253 }
256 254
257 Window* GetLockWindow() { 255 Window* GetLockWindow() {
258 return const_cast<Window*>( 256 return const_cast<Window*>(
259 static_cast<const TestEventClient*>(this)->GetLockWindow()); 257 static_cast<const TestEventClient*>(this)->GetLockWindow());
260 } 258 }
261 const Window* GetLockWindow() const { 259 const Window* GetLockWindow() const {
262 return root_window_->GetChildById(kLockWindowId); 260 return root_window_->GetChildById(kLockWindowId);
263 } 261 }
264 Window* GetNonLockWindow() { 262 Window* GetNonLockWindow() {
265 return root_window_->GetChildById(kNonLockWindowId); 263 return root_window_->GetChildById(kNonLockWindowId);
266 } 264 }
267 265
268 private: 266 private:
269 // Overridden from client::EventClient: 267 // Overridden from client::EventClient:
270 virtual bool CanProcessEventsWithinSubtree( 268 bool CanProcessEventsWithinSubtree(const Window* window) const override {
271 const Window* window) const override {
272 return lock_ ? 269 return lock_ ?
273 window->Contains(GetLockWindow()) || GetLockWindow()->Contains(window) : 270 window->Contains(GetLockWindow()) || GetLockWindow()->Contains(window) :
274 true; 271 true;
275 } 272 }
276 273
277 virtual ui::EventTarget* GetToplevelEventTarget() override { 274 ui::EventTarget* GetToplevelEventTarget() override { return NULL; }
278 return NULL;
279 }
280 275
281 Window* root_window_; 276 Window* root_window_;
282 bool lock_; 277 bool lock_;
283 278
284 DISALLOW_COPY_AND_ASSIGN(TestEventClient); 279 DISALLOW_COPY_AND_ASSIGN(TestEventClient);
285 }; 280 };
286 281
287 } // namespace 282 } // namespace
288 283
289 TEST_F(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) { 284 TEST_F(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 474
480 void Reset() { 475 void Reset() {
481 events_.clear(); 476 events_.clear();
482 mouse_locations_.clear(); 477 mouse_locations_.clear();
483 touch_locations_.clear(); 478 touch_locations_.clear();
484 gesture_locations_.clear(); 479 gesture_locations_.clear();
485 mouse_event_flags_.clear(); 480 mouse_event_flags_.clear();
486 } 481 }
487 482
488 // ui::EventHandler overrides: 483 // ui::EventHandler overrides:
489 virtual void OnEvent(ui::Event* event) override { 484 void OnEvent(ui::Event* event) override {
490 ui::EventHandler::OnEvent(event); 485 ui::EventHandler::OnEvent(event);
491 events_.push_back(event->type()); 486 events_.push_back(event->type());
492 if (wait_until_event_ == event->type() && run_loop_) { 487 if (wait_until_event_ == event->type() && run_loop_) {
493 run_loop_->Quit(); 488 run_loop_->Quit();
494 wait_until_event_ = ui::ET_UNKNOWN; 489 wait_until_event_ = ui::ET_UNKNOWN;
495 } 490 }
496 } 491 }
497 492
498 virtual void OnMouseEvent(ui::MouseEvent* event) override { 493 void OnMouseEvent(ui::MouseEvent* event) override {
499 mouse_locations_.push_back(event->location()); 494 mouse_locations_.push_back(event->location());
500 mouse_event_flags_.push_back(event->flags()); 495 mouse_event_flags_.push_back(event->flags());
501 } 496 }
502 497
503 virtual void OnTouchEvent(ui::TouchEvent* event) override { 498 void OnTouchEvent(ui::TouchEvent* event) override {
504 touch_locations_.push_back(event->location()); 499 touch_locations_.push_back(event->location());
505 } 500 }
506 501
507 virtual void OnGestureEvent(ui::GestureEvent* event) override { 502 void OnGestureEvent(ui::GestureEvent* event) override {
508 gesture_locations_.push_back(event->location()); 503 gesture_locations_.push_back(event->location());
509 } 504 }
510 505
511 bool HasReceivedEvent(ui::EventType type) { 506 bool HasReceivedEvent(ui::EventType type) {
512 return std::find(events_.begin(), events_.end(), type) != events_.end(); 507 return std::find(events_.begin(), events_.end(), type) != events_.end();
513 } 508 }
514 509
515 private: 510 private:
516 scoped_ptr<base::RunLoop> run_loop_; 511 scoped_ptr<base::RunLoop> run_loop_;
517 ui::EventType wait_until_event_; 512 ui::EventType wait_until_event_;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 822
828 // This event handler requests the dispatcher to start holding pointer-move 823 // This event handler requests the dispatcher to start holding pointer-move
829 // events when it receives the first scroll-update gesture. 824 // events when it receives the first scroll-update gesture.
830 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { 825 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
831 public: 826 public:
832 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, 827 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
833 EventFilterRecorder* filter) 828 EventFilterRecorder* filter)
834 : dispatcher_(dispatcher), 829 : dispatcher_(dispatcher),
835 filter_(filter), 830 filter_(filter),
836 holding_moves_(false) {} 831 holding_moves_(false) {}
837 virtual ~HoldPointerOnScrollHandler() {} 832 ~HoldPointerOnScrollHandler() override {}
838 833
839 private: 834 private:
840 // ui::test::TestEventHandler: 835 // ui::test::TestEventHandler:
841 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { 836 void OnGestureEvent(ui::GestureEvent* gesture) override {
842 if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 837 if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
843 holding_moves_ = true; 838 holding_moves_ = true;
844 dispatcher_->HoldPointerMoves(); 839 dispatcher_->HoldPointerMoves();
845 filter_->Reset(); 840 filter_->Reset();
846 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) { 841 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) {
847 dispatcher_->ReleasePointerMoves(); 842 dispatcher_->ReleasePointerMoves();
848 holding_moves_ = false; 843 holding_moves_ = false;
849 } 844 }
850 } 845 }
851 846
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 int translated_y = mouse_exit_location.y() - window_origin.y(); 1121 int translated_y = mouse_exit_location.y() - window_origin.y();
1127 gfx::Point translated_point(translated_x, translated_y); 1122 gfx::Point translated_point(translated_x, translated_y);
1128 EXPECT_EQ(recorder.mouse_location(0).ToString(), translated_point.ToString()); 1123 EXPECT_EQ(recorder.mouse_location(0).ToString(), translated_point.ToString());
1129 root_window()->RemovePreTargetHandler(&recorder); 1124 root_window()->RemovePreTargetHandler(&recorder);
1130 } 1125 }
1131 1126
1132 class DeletingEventFilter : public ui::EventHandler { 1127 class DeletingEventFilter : public ui::EventHandler {
1133 public: 1128 public:
1134 DeletingEventFilter() 1129 DeletingEventFilter()
1135 : delete_during_pre_handle_(false) {} 1130 : delete_during_pre_handle_(false) {}
1136 virtual ~DeletingEventFilter() {} 1131 ~DeletingEventFilter() override {}
1137 1132
1138 void Reset(bool delete_during_pre_handle) { 1133 void Reset(bool delete_during_pre_handle) {
1139 delete_during_pre_handle_ = delete_during_pre_handle; 1134 delete_during_pre_handle_ = delete_during_pre_handle;
1140 } 1135 }
1141 1136
1142 private: 1137 private:
1143 // Overridden from ui::EventHandler: 1138 // Overridden from ui::EventHandler:
1144 virtual void OnKeyEvent(ui::KeyEvent* event) override { 1139 void OnKeyEvent(ui::KeyEvent* event) override {
1145 if (delete_during_pre_handle_) 1140 if (delete_during_pre_handle_)
1146 delete event->target(); 1141 delete event->target();
1147 } 1142 }
1148 1143
1149 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1144 void OnMouseEvent(ui::MouseEvent* event) override {
1150 if (delete_during_pre_handle_) 1145 if (delete_during_pre_handle_)
1151 delete event->target(); 1146 delete event->target();
1152 } 1147 }
1153 1148
1154 bool delete_during_pre_handle_; 1149 bool delete_during_pre_handle_;
1155 1150
1156 DISALLOW_COPY_AND_ASSIGN(DeletingEventFilter); 1151 DISALLOW_COPY_AND_ASSIGN(DeletingEventFilter);
1157 }; 1152 };
1158 1153
1159 class DeletingWindowDelegate : public test::TestWindowDelegate { 1154 class DeletingWindowDelegate : public test::TestWindowDelegate {
1160 public: 1155 public:
1161 DeletingWindowDelegate() 1156 DeletingWindowDelegate()
1162 : window_(NULL), 1157 : window_(NULL),
1163 delete_during_handle_(false), 1158 delete_during_handle_(false),
1164 got_event_(false) {} 1159 got_event_(false) {}
1165 virtual ~DeletingWindowDelegate() {} 1160 ~DeletingWindowDelegate() override {}
1166 1161
1167 void Reset(Window* window, bool delete_during_handle) { 1162 void Reset(Window* window, bool delete_during_handle) {
1168 window_ = window; 1163 window_ = window;
1169 delete_during_handle_ = delete_during_handle; 1164 delete_during_handle_ = delete_during_handle;
1170 got_event_ = false; 1165 got_event_ = false;
1171 } 1166 }
1172 bool got_event() const { return got_event_; } 1167 bool got_event() const { return got_event_; }
1173 1168
1174 private: 1169 private:
1175 // Overridden from WindowDelegate: 1170 // Overridden from WindowDelegate:
1176 virtual void OnKeyEvent(ui::KeyEvent* event) override { 1171 void OnKeyEvent(ui::KeyEvent* event) override {
1177 if (delete_during_handle_) 1172 if (delete_during_handle_)
1178 delete window_; 1173 delete window_;
1179 got_event_ = true; 1174 got_event_ = true;
1180 } 1175 }
1181 1176
1182 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1177 void OnMouseEvent(ui::MouseEvent* event) override {
1183 if (delete_during_handle_) 1178 if (delete_during_handle_)
1184 delete window_; 1179 delete window_;
1185 got_event_ = true; 1180 got_event_ = true;
1186 } 1181 }
1187 1182
1188 Window* window_; 1183 Window* window_;
1189 bool delete_during_handle_; 1184 bool delete_during_handle_;
1190 bool got_event_; 1185 bool got_event_;
1191 1186
1192 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); 1187 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 EXPECT_FALSE(d11.got_event()); 1227 EXPECT_FALSE(d11.got_event());
1233 } 1228 }
1234 1229
1235 namespace { 1230 namespace {
1236 1231
1237 // A window delegate that detaches the parent of the target's parent window when 1232 // A window delegate that detaches the parent of the target's parent window when
1238 // it receives a tap event. 1233 // it receives a tap event.
1239 class DetachesParentOnTapDelegate : public test::TestWindowDelegate { 1234 class DetachesParentOnTapDelegate : public test::TestWindowDelegate {
1240 public: 1235 public:
1241 DetachesParentOnTapDelegate() {} 1236 DetachesParentOnTapDelegate() {}
1242 virtual ~DetachesParentOnTapDelegate() {} 1237 ~DetachesParentOnTapDelegate() override {}
1243 1238
1244 private: 1239 private:
1245 virtual void OnGestureEvent(ui::GestureEvent* event) override { 1240 void OnGestureEvent(ui::GestureEvent* event) override {
1246 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 1241 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
1247 event->SetHandled(); 1242 event->SetHandled();
1248 return; 1243 return;
1249 } 1244 }
1250 1245
1251 if (event->type() == ui::ET_GESTURE_TAP) { 1246 if (event->type() == ui::ET_GESTURE_TAP) {
1252 Window* parent = static_cast<Window*>(event->target())->parent(); 1247 Window* parent = static_cast<Window*>(event->target())->parent();
1253 parent->parent()->RemoveChild(parent); 1248 parent->parent()->RemoveChild(parent);
1254 event->SetHandled(); 1249 event->SetHandled();
1255 } 1250 }
(...skipping 19 matching lines...) Expand all
1275 namespace { 1270 namespace {
1276 1271
1277 // A window delegate that processes nested gestures on tap. 1272 // A window delegate that processes nested gestures on tap.
1278 class NestedGestureDelegate : public test::TestWindowDelegate { 1273 class NestedGestureDelegate : public test::TestWindowDelegate {
1279 public: 1274 public:
1280 NestedGestureDelegate(ui::test::EventGenerator* generator, 1275 NestedGestureDelegate(ui::test::EventGenerator* generator,
1281 const gfx::Point tap_location) 1276 const gfx::Point tap_location)
1282 : generator_(generator), 1277 : generator_(generator),
1283 tap_location_(tap_location), 1278 tap_location_(tap_location),
1284 gesture_end_count_(0) {} 1279 gesture_end_count_(0) {}
1285 virtual ~NestedGestureDelegate() {} 1280 ~NestedGestureDelegate() override {}
1286 1281
1287 int gesture_end_count() const { return gesture_end_count_; } 1282 int gesture_end_count() const { return gesture_end_count_; }
1288 1283
1289 private: 1284 private:
1290 virtual void OnGestureEvent(ui::GestureEvent* event) override { 1285 void OnGestureEvent(ui::GestureEvent* event) override {
1291 switch (event->type()) { 1286 switch (event->type()) {
1292 case ui::ET_GESTURE_TAP_DOWN: 1287 case ui::ET_GESTURE_TAP_DOWN:
1293 event->SetHandled(); 1288 event->SetHandled();
1294 break; 1289 break;
1295 case ui::ET_GESTURE_TAP: 1290 case ui::ET_GESTURE_TAP:
1296 if (generator_) 1291 if (generator_)
1297 generator_->GestureTapAt(tap_location_); 1292 generator_->GestureTapAt(tap_location_);
1298 event->SetHandled(); 1293 event->SetHandled();
1299 break; 1294 break;
1300 case ui::ET_GESTURE_END: 1295 case ui::ET_GESTURE_END:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 // events after that. 1359 // events after that.
1365 class RepostGestureEventRecorder : public EventFilterRecorder { 1360 class RepostGestureEventRecorder : public EventFilterRecorder {
1366 public: 1361 public:
1367 RepostGestureEventRecorder(aura::Window* repost_source, 1362 RepostGestureEventRecorder(aura::Window* repost_source,
1368 aura::Window* repost_target) 1363 aura::Window* repost_target)
1369 : repost_source_(repost_source), 1364 : repost_source_(repost_source),
1370 repost_target_(repost_target), 1365 repost_target_(repost_target),
1371 reposted_(false), 1366 reposted_(false),
1372 done_cleanup_(false) {} 1367 done_cleanup_(false) {}
1373 1368
1374 virtual ~RepostGestureEventRecorder() {} 1369 ~RepostGestureEventRecorder() override {}
1375 1370
1376 virtual void OnTouchEvent(ui::TouchEvent* event) override { 1371 void OnTouchEvent(ui::TouchEvent* event) override {
1377 if (reposted_ && event->type() == ui::ET_TOUCH_PRESSED) { 1372 if (reposted_ && event->type() == ui::ET_TOUCH_PRESSED) {
1378 done_cleanup_ = true; 1373 done_cleanup_ = true;
1379 Reset(); 1374 Reset();
1380 } 1375 }
1381 EventFilterRecorder::OnTouchEvent(event); 1376 EventFilterRecorder::OnTouchEvent(event);
1382 } 1377 }
1383 1378
1384 virtual void OnGestureEvent(ui::GestureEvent* event) override { 1379 void OnGestureEvent(ui::GestureEvent* event) override {
1385 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target()); 1380 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target());
1386 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 1381 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
1387 if (!reposted_) { 1382 if (!reposted_) {
1388 EXPECT_NE(repost_target_, event->target()); 1383 EXPECT_NE(repost_target_, event->target());
1389 reposted_ = true; 1384 reposted_ = true;
1390 repost_target_->GetHost()->dispatcher()->RepostEvent(*event); 1385 repost_target_->GetHost()->dispatcher()->RepostEvent(*event);
1391 // Ensure that the reposted gesture event above goes to the 1386 // Ensure that the reposted gesture event above goes to the
1392 // repost_target_; 1387 // repost_target_;
1393 repost_source_->GetRootWindow()->RemoveChild(repost_source_); 1388 repost_source_->GetRootWindow()->RemoveChild(repost_source_);
1394 return; 1389 return;
1395 } 1390 }
1396 } 1391 }
1397 EventFilterRecorder::OnGestureEvent(event); 1392 EventFilterRecorder::OnGestureEvent(event);
1398 } 1393 }
1399 1394
1400 // Ignore mouse events as they don't fire at all times. This causes 1395 // Ignore mouse events as they don't fire at all times. This causes
1401 // the GestureRepostEventOrder test to fail randomly. 1396 // the GestureRepostEventOrder test to fail randomly.
1402 virtual void OnMouseEvent(ui::MouseEvent* event) override {} 1397 void OnMouseEvent(ui::MouseEvent* event) override {}
1403 1398
1404 private: 1399 private:
1405 aura::Window* repost_source_; 1400 aura::Window* repost_source_;
1406 aura::Window* repost_target_; 1401 aura::Window* repost_target_;
1407 // set to true if we reposted the ET_GESTURE_TAP_DOWN event. 1402 // set to true if we reposted the ET_GESTURE_TAP_DOWN event.
1408 bool reposted_; 1403 bool reposted_;
1409 // set true if we're done cleaning up after hiding repost_source_; 1404 // set true if we're done cleaning up after hiding repost_source_;
1410 bool done_cleanup_; 1405 bool done_cleanup_;
1411 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder); 1406 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder);
1412 }; 1407 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 EXPECT_EQ(1, tap_down_count); 1461 EXPECT_EQ(1, tap_down_count);
1467 1462
1468 EXPECT_EQ(kExpectedTargetEvents, 1463 EXPECT_EQ(kExpectedTargetEvents,
1469 EventTypesToString(repost_event_recorder.events())); 1464 EventTypesToString(repost_event_recorder.events()));
1470 root_window()->RemovePreTargetHandler(&repost_event_recorder); 1465 root_window()->RemovePreTargetHandler(&repost_event_recorder);
1471 } 1466 }
1472 1467
1473 class OnMouseExitDeletingEventFilter : public EventFilterRecorder { 1468 class OnMouseExitDeletingEventFilter : public EventFilterRecorder {
1474 public: 1469 public:
1475 OnMouseExitDeletingEventFilter() : window_to_delete_(NULL) {} 1470 OnMouseExitDeletingEventFilter() : window_to_delete_(NULL) {}
1476 virtual ~OnMouseExitDeletingEventFilter() {} 1471 ~OnMouseExitDeletingEventFilter() override {}
1477 1472
1478 void set_window_to_delete(Window* window_to_delete) { 1473 void set_window_to_delete(Window* window_to_delete) {
1479 window_to_delete_ = window_to_delete; 1474 window_to_delete_ = window_to_delete;
1480 } 1475 }
1481 1476
1482 private: 1477 private:
1483 // Overridden from ui::EventHandler: 1478 // Overridden from ui::EventHandler:
1484 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1479 void OnMouseEvent(ui::MouseEvent* event) override {
1485 EventFilterRecorder::OnMouseEvent(event); 1480 EventFilterRecorder::OnMouseEvent(event);
1486 if (window_to_delete_) { 1481 if (window_to_delete_) {
1487 delete window_to_delete_; 1482 delete window_to_delete_;
1488 window_to_delete_ = NULL; 1483 window_to_delete_ = NULL;
1489 } 1484 }
1490 } 1485 }
1491 1486
1492 Window* window_to_delete_; 1487 Window* window_to_delete_;
1493 1488
1494 DISALLOW_COPY_AND_ASSIGN(OnMouseExitDeletingEventFilter); 1489 DISALLOW_COPY_AND_ASSIGN(OnMouseExitDeletingEventFilter);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 // RootWindow at such time. 1535 // RootWindow at such time.
1541 class ValidRootDuringDestructionWindowObserver : public aura::WindowObserver { 1536 class ValidRootDuringDestructionWindowObserver : public aura::WindowObserver {
1542 public: 1537 public:
1543 ValidRootDuringDestructionWindowObserver(bool* got_destroying, 1538 ValidRootDuringDestructionWindowObserver(bool* got_destroying,
1544 bool* has_valid_root) 1539 bool* has_valid_root)
1545 : got_destroying_(got_destroying), 1540 : got_destroying_(got_destroying),
1546 has_valid_root_(has_valid_root) { 1541 has_valid_root_(has_valid_root) {
1547 } 1542 }
1548 1543
1549 // WindowObserver: 1544 // WindowObserver:
1550 virtual void OnWindowDestroying(aura::Window* window) override { 1545 void OnWindowDestroying(aura::Window* window) override {
1551 *got_destroying_ = true; 1546 *got_destroying_ = true;
1552 *has_valid_root_ = (window->GetRootWindow() != NULL); 1547 *has_valid_root_ = (window->GetRootWindow() != NULL);
1553 } 1548 }
1554 1549
1555 private: 1550 private:
1556 bool* got_destroying_; 1551 bool* got_destroying_;
1557 bool* has_valid_root_; 1552 bool* has_valid_root_;
1558 1553
1559 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver); 1554 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver);
1560 }; 1555 };
(...skipping 19 matching lines...) Expand all
1580 } 1575 }
1581 1576
1582 namespace { 1577 namespace {
1583 1578
1584 // See description above DontResetHeldEvent for details. 1579 // See description above DontResetHeldEvent for details.
1585 class DontResetHeldEventWindowDelegate : public test::TestWindowDelegate { 1580 class DontResetHeldEventWindowDelegate : public test::TestWindowDelegate {
1586 public: 1581 public:
1587 explicit DontResetHeldEventWindowDelegate(aura::Window* root) 1582 explicit DontResetHeldEventWindowDelegate(aura::Window* root)
1588 : root_(root), 1583 : root_(root),
1589 mouse_event_count_(0) {} 1584 mouse_event_count_(0) {}
1590 virtual ~DontResetHeldEventWindowDelegate() {} 1585 ~DontResetHeldEventWindowDelegate() override {}
1591 1586
1592 int mouse_event_count() const { return mouse_event_count_; } 1587 int mouse_event_count() const { return mouse_event_count_; }
1593 1588
1594 // TestWindowDelegate: 1589 // TestWindowDelegate:
1595 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1590 void OnMouseEvent(ui::MouseEvent* event) override {
1596 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && 1591 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 &&
1597 mouse_event_count_++ == 0) { 1592 mouse_event_count_++ == 0) {
1598 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, 1593 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED,
1599 gfx::Point(10, 10), gfx::Point(10, 10), 1594 gfx::Point(10, 10), gfx::Point(10, 10),
1600 ui::EF_SHIFT_DOWN, 0); 1595 ui::EF_SHIFT_DOWN, 0);
1601 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); 1596 root_->GetHost()->dispatcher()->RepostEvent(mouse_event);
1602 } 1597 }
1603 } 1598 }
1604 1599
1605 private: 1600 private:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 1635
1641 // See description above DeleteHostFromHeldMouseEvent for details. 1636 // See description above DeleteHostFromHeldMouseEvent for details.
1642 class DeleteHostFromHeldMouseEventDelegate 1637 class DeleteHostFromHeldMouseEventDelegate
1643 : public test::TestWindowDelegate { 1638 : public test::TestWindowDelegate {
1644 public: 1639 public:
1645 explicit DeleteHostFromHeldMouseEventDelegate(WindowTreeHost* host) 1640 explicit DeleteHostFromHeldMouseEventDelegate(WindowTreeHost* host)
1646 : host_(host), 1641 : host_(host),
1647 got_mouse_event_(false), 1642 got_mouse_event_(false),
1648 got_destroy_(false) { 1643 got_destroy_(false) {
1649 } 1644 }
1650 virtual ~DeleteHostFromHeldMouseEventDelegate() {} 1645 ~DeleteHostFromHeldMouseEventDelegate() override {}
1651 1646
1652 bool got_mouse_event() const { return got_mouse_event_; } 1647 bool got_mouse_event() const { return got_mouse_event_; }
1653 bool got_destroy() const { return got_destroy_; } 1648 bool got_destroy() const { return got_destroy_; }
1654 1649
1655 // TestWindowDelegate: 1650 // TestWindowDelegate:
1656 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1651 void OnMouseEvent(ui::MouseEvent* event) override {
1657 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0) { 1652 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0) {
1658 got_mouse_event_ = true; 1653 got_mouse_event_ = true;
1659 delete host_; 1654 delete host_;
1660 } 1655 }
1661 } 1656 }
1662 virtual void OnWindowDestroyed(Window* window) override { 1657 void OnWindowDestroyed(Window* window) override { got_destroy_ = true; }
1663 got_destroy_ = true;
1664 }
1665 1658
1666 private: 1659 private:
1667 WindowTreeHost* host_; 1660 WindowTreeHost* host_;
1668 bool got_mouse_event_; 1661 bool got_mouse_event_;
1669 bool got_destroy_; 1662 bool got_destroy_;
1670 1663
1671 DISALLOW_COPY_AND_ASSIGN(DeleteHostFromHeldMouseEventDelegate); 1664 DISALLOW_COPY_AND_ASSIGN(DeleteHostFromHeldMouseEventDelegate);
1672 }; 1665 };
1673 1666
1674 } // namespace 1667 } // namespace
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 EXPECT_TRUE(recorder2.events().empty()); 1798 EXPECT_TRUE(recorder2.events().empty());
1806 } 1799 }
1807 1800
1808 namespace { 1801 namespace {
1809 1802
1810 // This class creates and manages a window which is destroyed as soon as 1803 // This class creates and manages a window which is destroyed as soon as
1811 // capture is lost. This is the case for the drag and drop capture window. 1804 // capture is lost. This is the case for the drag and drop capture window.
1812 class CaptureWindowTracker : public test::TestWindowDelegate { 1805 class CaptureWindowTracker : public test::TestWindowDelegate {
1813 public: 1806 public:
1814 CaptureWindowTracker() {} 1807 CaptureWindowTracker() {}
1815 virtual ~CaptureWindowTracker() {} 1808 ~CaptureWindowTracker() override {}
1816 1809
1817 void CreateCaptureWindow(aura::Window* root_window) { 1810 void CreateCaptureWindow(aura::Window* root_window) {
1818 capture_window_.reset(test::CreateTestWindowWithDelegate( 1811 capture_window_.reset(test::CreateTestWindowWithDelegate(
1819 this, -1234, gfx::Rect(20, 20, 20, 20), root_window)); 1812 this, -1234, gfx::Rect(20, 20, 20, 20), root_window));
1820 capture_window_->SetCapture(); 1813 capture_window_->SetCapture();
1821 } 1814 }
1822 1815
1823 void reset() { 1816 void reset() {
1824 capture_window_.reset(); 1817 capture_window_.reset();
1825 } 1818 }
1826 1819
1827 virtual void OnCaptureLost() override { 1820 void OnCaptureLost() override { capture_window_.reset(); }
1828 capture_window_.reset();
1829 }
1830 1821
1831 virtual void OnWindowDestroyed(Window* window) override { 1822 void OnWindowDestroyed(Window* window) override {
1832 TestWindowDelegate::OnWindowDestroyed(window); 1823 TestWindowDelegate::OnWindowDestroyed(window);
1833 capture_window_.reset(); 1824 capture_window_.reset();
1834 } 1825 }
1835 1826
1836 aura::Window* capture_window() { return capture_window_.get(); } 1827 aura::Window* capture_window() { return capture_window_.get(); }
1837 1828
1838 private: 1829 private:
1839 scoped_ptr<aura::Window> capture_window_; 1830 scoped_ptr<aura::Window> capture_window_;
1840 1831
1841 DISALLOW_COPY_AND_ASSIGN(CaptureWindowTracker); 1832 DISALLOW_COPY_AND_ASSIGN(CaptureWindowTracker);
(...skipping 13 matching lines...) Expand all
1855 TEST_F(WindowEventDispatcherTest, CaptureWindowDestroyed) { 1846 TEST_F(WindowEventDispatcherTest, CaptureWindowDestroyed) {
1856 CaptureWindowTracker capture_window_tracker; 1847 CaptureWindowTracker capture_window_tracker;
1857 capture_window_tracker.CreateCaptureWindow(root_window()); 1848 capture_window_tracker.CreateCaptureWindow(root_window());
1858 capture_window_tracker.reset(); 1849 capture_window_tracker.reset();
1859 EXPECT_EQ(NULL, capture_window_tracker.capture_window()); 1850 EXPECT_EQ(NULL, capture_window_tracker.capture_window());
1860 } 1851 }
1861 1852
1862 class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler { 1853 class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler {
1863 public: 1854 public:
1864 ExitMessageLoopOnMousePress() {} 1855 ExitMessageLoopOnMousePress() {}
1865 virtual ~ExitMessageLoopOnMousePress() {} 1856 ~ExitMessageLoopOnMousePress() override {}
1866 1857
1867 protected: 1858 protected:
1868 virtual void OnMouseEvent(ui::MouseEvent* event) override { 1859 void OnMouseEvent(ui::MouseEvent* event) override {
1869 ui::test::TestEventHandler::OnMouseEvent(event); 1860 ui::test::TestEventHandler::OnMouseEvent(event);
1870 if (event->type() == ui::ET_MOUSE_PRESSED) 1861 if (event->type() == ui::ET_MOUSE_PRESSED)
1871 base::MessageLoopForUI::current()->Quit(); 1862 base::MessageLoopForUI::current()->Quit();
1872 } 1863 }
1873 1864
1874 private: 1865 private:
1875 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress); 1866 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress);
1876 }; 1867 };
1877 1868
1878 class WindowEventDispatcherTestWithMessageLoop 1869 class WindowEventDispatcherTestWithMessageLoop
1879 : public WindowEventDispatcherTest { 1870 : public WindowEventDispatcherTest {
1880 public: 1871 public:
1881 WindowEventDispatcherTestWithMessageLoop() {} 1872 WindowEventDispatcherTestWithMessageLoop() {}
1882 virtual ~WindowEventDispatcherTestWithMessageLoop() {} 1873 ~WindowEventDispatcherTestWithMessageLoop() override {}
1883 1874
1884 void RunTest() { 1875 void RunTest() {
1885 // Reset any event the window may have received when bringing up the window 1876 // Reset any event the window may have received when bringing up the window
1886 // (e.g. mouse-move events if the mouse cursor is over the window). 1877 // (e.g. mouse-move events if the mouse cursor is over the window).
1887 handler_.Reset(); 1878 handler_.Reset();
1888 1879
1889 // Start a nested message-loop, post an event to be dispatched, and then 1880 // Start a nested message-loop, post an event to be dispatched, and then
1890 // terminate the message-loop. When the message-loop unwinds and gets back, 1881 // terminate the message-loop. When the message-loop unwinds and gets back,
1891 // the reposted event should not have fired. 1882 // the reposted event should not have fired.
1892 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent(ui::ET_MOUSE_PRESSED, 1883 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent(ui::ET_MOUSE_PRESSED,
(...skipping 15 matching lines...) Expand all
1908 1899
1909 // Let the current message-loop run. The event-handler will terminate the 1900 // Let the current message-loop run. The event-handler will terminate the
1910 // message-loop when it receives the reposted event. 1901 // message-loop when it receives the reposted event.
1911 } 1902 }
1912 1903
1913 base::MessageLoop* message_loop() { 1904 base::MessageLoop* message_loop() {
1914 return base::MessageLoopForUI::current(); 1905 return base::MessageLoopForUI::current();
1915 } 1906 }
1916 1907
1917 protected: 1908 protected:
1918 virtual void SetUp() override { 1909 void SetUp() override {
1919 WindowEventDispatcherTest::SetUp(); 1910 WindowEventDispatcherTest::SetUp();
1920 window_.reset(CreateNormalWindow(1, root_window(), NULL)); 1911 window_.reset(CreateNormalWindow(1, root_window(), NULL));
1921 window_->AddPreTargetHandler(&handler_); 1912 window_->AddPreTargetHandler(&handler_);
1922 } 1913 }
1923 1914
1924 virtual void TearDown() override { 1915 void TearDown() override {
1925 window_.reset(); 1916 window_.reset();
1926 WindowEventDispatcherTest::TearDown(); 1917 WindowEventDispatcherTest::TearDown();
1927 } 1918 }
1928 1919
1929 private: 1920 private:
1930 // Used to avoid a copying |event| when binding to a closure. 1921 // Used to avoid a copying |event| when binding to a closure.
1931 static void RepostEventHelper(WindowEventDispatcher* dispatcher, 1922 static void RepostEventHelper(WindowEventDispatcher* dispatcher,
1932 scoped_ptr<ui::MouseEvent> event) { 1923 scoped_ptr<ui::MouseEvent> event) {
1933 dispatcher->RepostEvent(*event); 1924 dispatcher->RepostEvent(*event);
1934 } 1925 }
(...skipping 11 matching lines...) Expand all
1946 message_loop()->PostTask( 1937 message_loop()->PostTask(
1947 FROM_HERE, base::Bind( 1938 FROM_HERE, base::Bind(
1948 &WindowEventDispatcherTestWithMessageLoop::RunTest, 1939 &WindowEventDispatcherTestWithMessageLoop::RunTest,
1949 base::Unretained(this))); 1940 base::Unretained(this)));
1950 message_loop()->Run(); 1941 message_loop()->Run();
1951 } 1942 }
1952 1943
1953 class WindowEventDispatcherTestInHighDPI : public WindowEventDispatcherTest { 1944 class WindowEventDispatcherTestInHighDPI : public WindowEventDispatcherTest {
1954 public: 1945 public:
1955 WindowEventDispatcherTestInHighDPI() {} 1946 WindowEventDispatcherTestInHighDPI() {}
1956 virtual ~WindowEventDispatcherTestInHighDPI() {} 1947 ~WindowEventDispatcherTestInHighDPI() override {}
1957 1948
1958 protected: 1949 protected:
1959 virtual void SetUp() override { 1950 void SetUp() override {
1960 WindowEventDispatcherTest::SetUp(); 1951 WindowEventDispatcherTest::SetUp();
1961 test_screen()->SetDeviceScaleFactor(2.f); 1952 test_screen()->SetDeviceScaleFactor(2.f);
1962 } 1953 }
1963 }; 1954 };
1964 1955
1965 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { 1956 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) {
1966 test::TestWindowDelegate delegate; 1957 test::TestWindowDelegate delegate;
1967 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, 1958 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate,
1968 1234, gfx::Rect(20, 20, 100, 100), root_window())); 1959 1234, gfx::Rect(20, 20, 100, 100), root_window()));
1969 child->Show(); 1960 child->Show();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 ASSERT_EQ(2u, recorder.touch_locations().size()); 2016 ASSERT_EQ(2u, recorder.touch_locations().size());
2026 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 2017 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
2027 recorder.touch_locations()[0].ToString()); 2018 recorder.touch_locations()[0].ToString());
2028 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 2019 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
2029 recorder.touch_locations()[1].ToString()); 2020 recorder.touch_locations()[1].ToString());
2030 } 2021 }
2031 2022
2032 class SelfDestructDelegate : public test::TestWindowDelegate { 2023 class SelfDestructDelegate : public test::TestWindowDelegate {
2033 public: 2024 public:
2034 SelfDestructDelegate() {} 2025 SelfDestructDelegate() {}
2035 virtual ~SelfDestructDelegate() {} 2026 ~SelfDestructDelegate() override {}
2036 2027
2037 virtual void OnMouseEvent(ui::MouseEvent* event) override { 2028 void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); }
2038 window_.reset();
2039 }
2040 2029
2041 void set_window(scoped_ptr<aura::Window> window) { 2030 void set_window(scoped_ptr<aura::Window> window) {
2042 window_ = window.Pass(); 2031 window_ = window.Pass();
2043 } 2032 }
2044 bool has_window() const { return !!window_.get(); } 2033 bool has_window() const { return !!window_.get(); }
2045 2034
2046 private: 2035 private:
2047 scoped_ptr<aura::Window> window_; 2036 scoped_ptr<aura::Window> window_;
2048 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); 2037 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate);
2049 }; 2038 };
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 2087
2099 client::CaptureDelegate* capture_delegate = host()->dispatcher(); 2088 client::CaptureDelegate* capture_delegate = host()->dispatcher();
2100 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); 2089 capture_delegate->UpdateCapture(window_first_raw, window_second.get());
2101 EXPECT_FALSE(delegate.has_window()); 2090 EXPECT_FALSE(delegate.has_window());
2102 } 2091 }
2103 2092
2104 class StaticFocusClient : public client::FocusClient { 2093 class StaticFocusClient : public client::FocusClient {
2105 public: 2094 public:
2106 explicit StaticFocusClient(Window* focused) 2095 explicit StaticFocusClient(Window* focused)
2107 : focused_(focused) {} 2096 : focused_(focused) {}
2108 virtual ~StaticFocusClient() {} 2097 ~StaticFocusClient() override {}
2109 2098
2110 private: 2099 private:
2111 // client::FocusClient: 2100 // client::FocusClient:
2112 virtual void AddObserver(client::FocusChangeObserver* observer) override {} 2101 void AddObserver(client::FocusChangeObserver* observer) override {}
2113 virtual void RemoveObserver(client::FocusChangeObserver* observer) override {} 2102 void RemoveObserver(client::FocusChangeObserver* observer) override {}
2114 virtual void FocusWindow(Window* window) override {} 2103 void FocusWindow(Window* window) override {}
2115 virtual void ResetFocusWithinActiveWindow(Window* window) override {} 2104 void ResetFocusWithinActiveWindow(Window* window) override {}
2116 virtual Window* GetFocusedWindow() override { return focused_; } 2105 Window* GetFocusedWindow() override { return focused_; }
2117 2106
2118 Window* focused_; 2107 Window* focused_;
2119 2108
2120 DISALLOW_COPY_AND_ASSIGN(StaticFocusClient); 2109 DISALLOW_COPY_AND_ASSIGN(StaticFocusClient);
2121 }; 2110 };
2122 2111
2123 // Tests that host-cancel-mode event can be dispatched to a dispatcher safely 2112 // Tests that host-cancel-mode event can be dispatched to a dispatcher safely
2124 // when the focused window does not live in the dispatcher's tree. 2113 // when the focused window does not live in the dispatcher's tree.
2125 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { 2114 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) {
2126 test::TestWindowDelegate delegate; 2115 test::TestWindowDelegate delegate;
2127 scoped_ptr<Window> focused(CreateTestWindowWithDelegate(&delegate, 123, 2116 scoped_ptr<Window> focused(CreateTestWindowWithDelegate(&delegate, 123,
2128 gfx::Rect(20, 30, 100, 50), NULL)); 2117 gfx::Rect(20, 30, 100, 50), NULL));
2129 StaticFocusClient focus_client(focused.get()); 2118 StaticFocusClient focus_client(focused.get());
2130 client::SetFocusClient(root_window(), &focus_client); 2119 client::SetFocusClient(root_window(), &focus_client);
2131 EXPECT_FALSE(root_window()->Contains(focused.get())); 2120 EXPECT_FALSE(root_window()->Contains(focused.get()));
2132 EXPECT_EQ(focused.get(), 2121 EXPECT_EQ(focused.get(),
2133 client::GetFocusClient(root_window())->GetFocusedWindow()); 2122 client::GetFocusClient(root_window())->GetFocusedWindow());
2134 host()->dispatcher()->DispatchCancelModeEvent(); 2123 host()->dispatcher()->DispatchCancelModeEvent();
2135 EXPECT_EQ(focused.get(), 2124 EXPECT_EQ(focused.get(),
2136 client::GetFocusClient(root_window())->GetFocusedWindow()); 2125 client::GetFocusClient(root_window())->GetFocusedWindow());
2137 } 2126 }
2138 2127
2139 // Dispatches a mouse-move event to |target| when it receives a mouse-move 2128 // Dispatches a mouse-move event to |target| when it receives a mouse-move
2140 // event. 2129 // event.
2141 class DispatchEventHandler : public ui::EventHandler { 2130 class DispatchEventHandler : public ui::EventHandler {
2142 public: 2131 public:
2143 explicit DispatchEventHandler(Window* target) 2132 explicit DispatchEventHandler(Window* target)
2144 : target_(target), 2133 : target_(target),
2145 dispatched_(false) {} 2134 dispatched_(false) {}
2146 virtual ~DispatchEventHandler() {} 2135 ~DispatchEventHandler() override {}
2147 2136
2148 bool dispatched() const { return dispatched_; } 2137 bool dispatched() const { return dispatched_; }
2149 private: 2138 private:
2150 // ui::EventHandler: 2139 // ui::EventHandler:
2151 virtual void OnMouseEvent(ui::MouseEvent* mouse) override { 2140 void OnMouseEvent(ui::MouseEvent* mouse) override {
2152 if (mouse->type() == ui::ET_MOUSE_MOVED) { 2141 if (mouse->type() == ui::ET_MOUSE_MOVED) {
2153 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), 2142 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(),
2154 target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE); 2143 target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE);
2155 ui::EventDispatchDetails details = 2144 ui::EventDispatchDetails details =
2156 target_->GetHost()->dispatcher()->OnEventFromSource(&move); 2145 target_->GetHost()->dispatcher()->OnEventFromSource(&move);
2157 ASSERT_FALSE(details.dispatcher_destroyed); 2146 ASSERT_FALSE(details.dispatcher_destroyed);
2158 EXPECT_FALSE(details.target_destroyed); 2147 EXPECT_FALSE(details.target_destroyed);
2159 EXPECT_EQ(target_, move.target()); 2148 EXPECT_EQ(target_, move.target());
2160 dispatched_ = true; 2149 dispatched_ = true;
2161 } 2150 }
2162 ui::EventHandler::OnMouseEvent(mouse); 2151 ui::EventHandler::OnMouseEvent(mouse);
2163 } 2152 }
2164 2153
2165 Window* target_; 2154 Window* target_;
2166 bool dispatched_; 2155 bool dispatched_;
2167 2156
2168 DISALLOW_COPY_AND_ASSIGN(DispatchEventHandler); 2157 DISALLOW_COPY_AND_ASSIGN(DispatchEventHandler);
2169 }; 2158 };
2170 2159
2171 // Moves |window| to |root_window| when it receives a mouse-move event. 2160 // Moves |window| to |root_window| when it receives a mouse-move event.
2172 class MoveWindowHandler : public ui::EventHandler { 2161 class MoveWindowHandler : public ui::EventHandler {
2173 public: 2162 public:
2174 MoveWindowHandler(Window* window, Window* root_window) 2163 MoveWindowHandler(Window* window, Window* root_window)
2175 : window_to_move_(window), 2164 : window_to_move_(window),
2176 root_window_to_move_to_(root_window) {} 2165 root_window_to_move_to_(root_window) {}
2177 virtual ~MoveWindowHandler() {} 2166 ~MoveWindowHandler() override {}
2178 2167
2179 private: 2168 private:
2180 // ui::EventHandler: 2169 // ui::EventHandler:
2181 virtual void OnMouseEvent(ui::MouseEvent* mouse) override { 2170 void OnMouseEvent(ui::MouseEvent* mouse) override {
2182 if (mouse->type() == ui::ET_MOUSE_MOVED) { 2171 if (mouse->type() == ui::ET_MOUSE_MOVED) {
2183 root_window_to_move_to_->AddChild(window_to_move_); 2172 root_window_to_move_to_->AddChild(window_to_move_);
2184 } 2173 }
2185 ui::EventHandler::OnMouseEvent(mouse); 2174 ui::EventHandler::OnMouseEvent(mouse);
2186 } 2175 }
2187 2176
2188 Window* window_to_move_; 2177 Window* window_to_move_;
2189 Window* root_window_to_move_to_; 2178 Window* root_window_to_move_to_;
2190 2179
2191 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler); 2180 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 EXPECT_TRUE(dispatch_event.dispatched()); 2222 EXPECT_TRUE(dispatch_event.dispatched());
2234 EXPECT_EQ(second_root, first->GetRootWindow()); 2223 EXPECT_EQ(second_root, first->GetRootWindow());
2235 2224
2236 first->RemovePreTargetHandler(&dispatch_event); 2225 first->RemovePreTargetHandler(&dispatch_event);
2237 second->RemovePreTargetHandler(&move_window); 2226 second->RemovePreTargetHandler(&move_window);
2238 } 2227 }
2239 2228
2240 class AlwaysMouseDownInputStateLookup : public InputStateLookup { 2229 class AlwaysMouseDownInputStateLookup : public InputStateLookup {
2241 public: 2230 public:
2242 AlwaysMouseDownInputStateLookup() {} 2231 AlwaysMouseDownInputStateLookup() {}
2243 virtual ~AlwaysMouseDownInputStateLookup() {} 2232 ~AlwaysMouseDownInputStateLookup() override {}
2244 2233
2245 private: 2234 private:
2246 // InputStateLookup: 2235 // InputStateLookup:
2247 virtual bool IsMouseButtonDown() const override { return true; } 2236 bool IsMouseButtonDown() const override { return true; }
2248 2237
2249 DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup); 2238 DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup);
2250 }; 2239 };
2251 2240
2252 TEST_F(WindowEventDispatcherTest, 2241 TEST_F(WindowEventDispatcherTest,
2253 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { 2242 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) {
2254 test::EventCountDelegate delegate; 2243 test::EventCountDelegate delegate;
2255 scoped_ptr<Window> window(CreateTestWindowWithDelegate(&delegate, 123, 2244 scoped_ptr<Window> window(CreateTestWindowWithDelegate(&delegate, 123,
2256 gfx::Rect(20, 10, 10, 20), root_window())); 2245 gfx::Rect(20, 10, 10, 20), root_window()));
2257 window->Show(); 2246 window->Show();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 2323
2335 class AsyncWindowDelegate : public test::TestWindowDelegate { 2324 class AsyncWindowDelegate : public test::TestWindowDelegate {
2336 public: 2325 public:
2337 AsyncWindowDelegate(WindowEventDispatcher* dispatcher) 2326 AsyncWindowDelegate(WindowEventDispatcher* dispatcher)
2338 : dispatcher_(dispatcher) {} 2327 : dispatcher_(dispatcher) {}
2339 2328
2340 void set_window(Window* window) { 2329 void set_window(Window* window) {
2341 window_ = window; 2330 window_ = window;
2342 } 2331 }
2343 private: 2332 private:
2344 virtual void OnTouchEvent(ui::TouchEvent* event) override { 2333 void OnTouchEvent(ui::TouchEvent* event) override {
2345 // Convert touch event back to root window coordinates. 2334 // Convert touch event back to root window coordinates.
2346 event->ConvertLocationToTarget(window_, window_->GetRootWindow()); 2335 event->ConvertLocationToTarget(window_, window_->GetRootWindow());
2347 dispatcher_->ProcessedTouchEvent(event, window_, ui::ER_UNHANDLED); 2336 dispatcher_->ProcessedTouchEvent(event, window_, ui::ER_UNHANDLED);
2348 event->StopPropagation(); 2337 event->StopPropagation();
2349 } 2338 }
2350 2339
2351 WindowEventDispatcher* dispatcher_; 2340 WindowEventDispatcher* dispatcher_;
2352 Window* window_; 2341 Window* window_;
2353 2342
2354 DISALLOW_COPY_AND_ASSIGN(AsyncWindowDelegate); 2343 DISALLOW_COPY_AND_ASSIGN(AsyncWindowDelegate);
(...skipping 27 matching lines...) Expand all
2382 ASSERT_EQ(1u, recorder.touch_locations().size()); 2371 ASSERT_EQ(1u, recorder.touch_locations().size());
2383 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), 2372 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(),
2384 recorder.touch_locations()[0].ToString()); 2373 recorder.touch_locations()[0].ToString());
2385 2374
2386 ASSERT_EQ(2u, recorder.gesture_locations().size()); 2375 ASSERT_EQ(2u, recorder.gesture_locations().size());
2387 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), 2376 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(),
2388 recorder.gesture_locations()[0].ToString()); 2377 recorder.gesture_locations()[0].ToString());
2389 } 2378 }
2390 2379
2391 } // namespace aura 2380 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/aura/window_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698