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

Side by Side Diff: services/ui/ws/event_dispatcher_unittest.cc

Issue 2125883003: Adds ability for pre-target accelerators to not consume events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 5 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
« no previous file with comments | « services/ui/ws/event_dispatcher_delegate.h ('k') | services/ui/ws/test_utils.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/ws/event_dispatcher.h" 5 #include "services/ui/ws/event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 last_accelerator_(0) {} 60 last_accelerator_(0) {}
61 ~TestEventDispatcherDelegate() override {} 61 ~TestEventDispatcherDelegate() override {}
62 62
63 ui::Event* last_event_target_not_found() { 63 ui::Event* last_event_target_not_found() {
64 return last_event_target_not_found_.get(); 64 return last_event_target_not_found_.get();
65 } 65 }
66 66
67 uint32_t GetAndClearLastAccelerator() { 67 uint32_t GetAndClearLastAccelerator() {
68 uint32_t return_value = last_accelerator_; 68 uint32_t return_value = last_accelerator_;
69 last_accelerator_ = 0; 69 last_accelerator_ = 0;
70 last_accelerator_phase_ = AcceleratorPhase::POST;
70 return return_value; 71 return return_value;
71 } 72 }
72 73
74 AcceleratorPhase last_accelerator_phase() const {
75 return last_accelerator_phase_;
76 }
77
73 void set_root(ServerWindow* root) { root_ = root; } 78 void set_root(ServerWindow* root) { root_ = root; }
74 79
75 // Returns the last dispatched event, or null if there are no more. 80 // Returns the last dispatched event, or null if there are no more.
76 std::unique_ptr<DispatchedEventDetails> 81 std::unique_ptr<DispatchedEventDetails>
77 GetAndAdvanceDispatchedEventDetails() { 82 GetAndAdvanceDispatchedEventDetails() {
78 if (dispatched_event_queue_.empty()) 83 if (dispatched_event_queue_.empty())
79 return nullptr; 84 return nullptr;
80 85
81 std::unique_ptr<DispatchedEventDetails> details = 86 std::unique_ptr<DispatchedEventDetails> details =
82 std::move(dispatched_event_queue_.front()); 87 std::move(dispatched_event_queue_.front());
(...skipping 10 matching lines...) Expand all
93 bool has_queued_events() const { return !dispatched_event_queue_.empty(); } 98 bool has_queued_events() const { return !dispatched_event_queue_.empty(); }
94 ServerWindow* lost_capture_window() { return lost_capture_window_; } 99 ServerWindow* lost_capture_window() { return lost_capture_window_; }
95 100
96 // EventDispatcherDelegate: 101 // EventDispatcherDelegate:
97 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override { 102 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override {
98 focused_window_ = window; 103 focused_window_ = window;
99 } 104 }
100 105
101 private: 106 private:
102 // EventDispatcherDelegate: 107 // EventDispatcherDelegate:
103 void OnAccelerator(uint32_t accelerator, const ui::Event& event) override { 108 void OnAccelerator(uint32_t accelerator,
109 const ui::Event& event,
110 AcceleratorPhase phase) override {
104 EXPECT_EQ(0u, last_accelerator_); 111 EXPECT_EQ(0u, last_accelerator_);
105 last_accelerator_ = accelerator; 112 last_accelerator_ = accelerator;
113 last_accelerator_phase_ = phase;
106 } 114 }
107 ServerWindow* GetFocusedWindowForEventDispatcher() override { 115 ServerWindow* GetFocusedWindowForEventDispatcher() override {
108 return focused_window_; 116 return focused_window_;
109 } 117 }
110 void SetNativeCapture(ServerWindow* window) override {} 118 void SetNativeCapture(ServerWindow* window) override {}
111 void ReleaseNativeCapture() override { 119 void ReleaseNativeCapture() override {
112 if (delegate_) 120 if (delegate_)
113 delegate_->ReleaseCapture(); 121 delegate_->ReleaseCapture();
114 } 122 }
115 void OnServerWindowCaptureLost(ServerWindow* window) override { 123 void OnServerWindowCaptureLost(ServerWindow* window) override {
(...skipping 19 matching lines...) Expand all
135 return root_; 143 return root_;
136 } 144 }
137 void OnEventTargetNotFound(const ui::Event& event) override { 145 void OnEventTargetNotFound(const ui::Event& event) override {
138 last_event_target_not_found_ = ui::Event::Clone(event); 146 last_event_target_not_found_ = ui::Event::Clone(event);
139 } 147 }
140 148
141 Delegate* delegate_; 149 Delegate* delegate_;
142 ServerWindow* focused_window_; 150 ServerWindow* focused_window_;
143 ServerWindow* lost_capture_window_; 151 ServerWindow* lost_capture_window_;
144 uint32_t last_accelerator_; 152 uint32_t last_accelerator_;
153 AcceleratorPhase last_accelerator_phase_ = AcceleratorPhase::POST;
145 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_; 154 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_;
146 ServerWindow* root_ = nullptr; 155 ServerWindow* root_ = nullptr;
147 std::unique_ptr<ui::Event> last_event_target_not_found_; 156 std::unique_ptr<ui::Event> last_event_target_not_found_;
148 157
149 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate); 158 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate);
150 }; 159 };
151 160
152 // Used by RunMouseEventTests(). Can identify up to two generated events. The 161 // Used by RunMouseEventTests(). Can identify up to two generated events. The
153 // first ServerWindow and two points identify the first event, the second 162 // first ServerWindow and two points identify the first event, the second
154 // ServerWindow and points identify the second event. If only one event is 163 // ServerWindow and points identify the second event. If only one event is
(...skipping 28 matching lines...) Expand all
183 192
184 void RunMouseEventTests(EventDispatcher* dispatcher, 193 void RunMouseEventTests(EventDispatcher* dispatcher,
185 TestEventDispatcherDelegate* dispatcher_delegate, 194 TestEventDispatcherDelegate* dispatcher_delegate,
186 MouseEventTest* tests, 195 MouseEventTest* tests,
187 size_t test_count) { 196 size_t test_count) {
188 for (size_t i = 0; i < test_count; ++i) { 197 for (size_t i = 0; i < test_count; ++i) {
189 const MouseEventTest& test = tests[i]; 198 const MouseEventTest& test = tests[i];
190 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) 199 ASSERT_FALSE(dispatcher_delegate->has_queued_events())
191 << " unexpected queued events before running " << i; 200 << " unexpected queued events before running " << i;
192 if (test.input_event.IsMouseWheelEvent()) 201 if (test.input_event.IsMouseWheelEvent())
193 dispatcher->ProcessEvent(test.input_event); 202 dispatcher->ProcessEvent(test.input_event,
203 EventDispatcher::AcceleratorMatchPhase::ANY);
194 else 204 else
195 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event)); 205 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event),
206 EventDispatcher::AcceleratorMatchPhase::ANY);
196 207
197 std::unique_ptr<DispatchedEventDetails> details = 208 std::unique_ptr<DispatchedEventDetails> details =
198 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 209 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
199 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( 210 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
200 details.get(), test.expected_target_window1, 211 details.get(), test.expected_target_window1,
201 test.expected_root_location1, test.expected_location1)) 212 test.expected_root_location1, test.expected_location1))
202 << " details don't match " << i; 213 << " details don't match " << i;
203 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 214 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
204 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( 215 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
205 details.get(), test.expected_target_window2, 216 details.get(), test.expected_target_window2,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 TEST_F(EventDispatcherTest, ProcessEvent) { 335 TEST_F(EventDispatcherTest, ProcessEvent) {
325 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 336 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
326 337
327 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 338 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
328 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 339 child->SetBounds(gfx::Rect(10, 10, 20, 20));
329 340
330 // Send event that is over child. 341 // Send event that is over child.
331 const ui::PointerEvent ui_event(ui::MouseEvent( 342 const ui::PointerEvent ui_event(ui::MouseEvent(
332 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 343 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
333 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 344 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
334 event_dispatcher()->ProcessEvent(ui_event); 345 event_dispatcher()->ProcessEvent(ui_event,
346 EventDispatcher::AcceleratorMatchPhase::ANY);
335 347
336 std::unique_ptr<DispatchedEventDetails> details = 348 std::unique_ptr<DispatchedEventDetails> details =
337 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 349 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
338 ASSERT_TRUE(details); 350 ASSERT_TRUE(details);
339 ASSERT_EQ(child.get(), details->window); 351 ASSERT_EQ(child.get(), details->window);
340 352
341 ASSERT_TRUE(details->event); 353 ASSERT_TRUE(details->event);
342 ASSERT_TRUE(details->event->IsPointerEvent()); 354 ASSERT_TRUE(details->event->IsPointerEvent());
343 355
344 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 356 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
345 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); 357 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
346 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); 358 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
347 } 359 }
348 360
349 TEST_F(EventDispatcherTest, ProcessEventNoTarget) { 361 TEST_F(EventDispatcherTest, ProcessEventNoTarget) {
350 // Send event without a target. 362 // Send event without a target.
351 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); 363 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
352 event_dispatcher()->ProcessEvent(key); 364 event_dispatcher()->ProcessEvent(key,
365 EventDispatcher::AcceleratorMatchPhase::ANY);
353 366
354 // Event wasn't dispatched to a target. 367 // Event wasn't dispatched to a target.
355 std::unique_ptr<DispatchedEventDetails> details = 368 std::unique_ptr<DispatchedEventDetails> details =
356 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 369 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
357 EXPECT_FALSE(details); 370 EXPECT_FALSE(details);
358 371
359 // Delegate was informed that there wasn't a target. 372 // Delegate was informed that there wasn't a target.
360 ui::Event* event_out = 373 ui::Event* event_out =
361 test_event_dispatcher_delegate()->last_event_target_not_found(); 374 test_event_dispatcher_delegate()->last_event_target_not_found();
362 ASSERT_TRUE(event_out); 375 ASSERT_TRUE(event_out);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 TestEventDispatcherDelegate* event_dispatcher_delegate = 419 TestEventDispatcherDelegate* event_dispatcher_delegate =
407 test_event_dispatcher_delegate(); 420 test_event_dispatcher_delegate();
408 EventDispatcher* dispatcher = event_dispatcher(); 421 EventDispatcher* dispatcher = event_dispatcher();
409 422
410 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( 423 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
411 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); 424 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
412 uint32_t accelerator_1 = 1; 425 uint32_t accelerator_1 = 1;
413 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); 426 dispatcher->AddAccelerator(accelerator_1, std::move(matcher));
414 427
415 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 428 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
416 dispatcher->ProcessEvent(key); 429 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
417 EXPECT_EQ(accelerator_1, 430 EXPECT_EQ(accelerator_1,
418 event_dispatcher_delegate->GetAndClearLastAccelerator()); 431 event_dispatcher_delegate->GetAndClearLastAccelerator());
419 432
420 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to 433 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to
421 // ignoring. 434 // ignoring.
422 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, 435 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W,
423 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); 436 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON);
424 dispatcher->ProcessEvent(key); 437 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
425 EXPECT_EQ(accelerator_1, 438 EXPECT_EQ(accelerator_1,
426 event_dispatcher_delegate->GetAndClearLastAccelerator()); 439 event_dispatcher_delegate->GetAndClearLastAccelerator());
427 440
428 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); 441 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE);
429 dispatcher->ProcessEvent(key); 442 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
430 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 443 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
431 444
432 uint32_t accelerator_2 = 2; 445 uint32_t accelerator_2 = 2;
433 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, 446 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W,
434 ui::mojom::kEventFlagNone); 447 ui::mojom::kEventFlagNone);
435 dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); 448 dispatcher->AddAccelerator(accelerator_2, std::move(matcher));
436 dispatcher->ProcessEvent(key); 449 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
437 EXPECT_EQ(accelerator_2, 450 EXPECT_EQ(accelerator_2,
438 event_dispatcher_delegate->GetAndClearLastAccelerator()); 451 event_dispatcher_delegate->GetAndClearLastAccelerator());
439 452
440 dispatcher->RemoveAccelerator(accelerator_2); 453 dispatcher->RemoveAccelerator(accelerator_2);
441 dispatcher->ProcessEvent(key); 454 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
442 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 455 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
443 } 456 }
444 457
445 // Tests that a post-target accelerator is not triggered by ProcessEvent. 458 // Tests that a post-target accelerator is not triggered by ProcessEvent.
446 TEST_F(EventDispatcherTest, PostTargetAccelerator) { 459 TEST_F(EventDispatcherTest, PostTargetAccelerator) {
447 TestEventDispatcherDelegate* event_dispatcher_delegate = 460 TestEventDispatcherDelegate* event_dispatcher_delegate =
448 test_event_dispatcher_delegate(); 461 test_event_dispatcher_delegate();
449 EventDispatcher* dispatcher = event_dispatcher(); 462 EventDispatcher* dispatcher = event_dispatcher();
450 463
451 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( 464 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
452 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); 465 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
453 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; 466 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
454 uint32_t accelerator_1 = 1; 467 uint32_t accelerator_1 = 1;
455 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); 468 dispatcher->AddAccelerator(accelerator_1, std::move(matcher));
456 469
457 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 470 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
458 // The post-target accelerator should be fired if there is no focused window. 471 // The post-target accelerator should be fired if there is no focused window.
459 dispatcher->ProcessEvent(key); 472 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
460 EXPECT_EQ(accelerator_1, 473 EXPECT_EQ(accelerator_1,
461 event_dispatcher_delegate->GetAndClearLastAccelerator()); 474 event_dispatcher_delegate->GetAndClearLastAccelerator());
462 std::unique_ptr<DispatchedEventDetails> details = 475 std::unique_ptr<DispatchedEventDetails> details =
463 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 476 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
464 EXPECT_FALSE(details); 477 EXPECT_FALSE(details);
465 478
466 // Set focused window for EventDispatcher dispatches key events. 479 // Set focused window for EventDispatcher dispatches key events.
467 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 480 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
468 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); 481 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get());
469 482
470 // With a focused window the event should be dispatched. 483 // With a focused window the event should be dispatched.
471 dispatcher->ProcessEvent(key); 484 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
472 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 485 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
473 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 486 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
474 EXPECT_TRUE(details); 487 EXPECT_TRUE(details);
475 EXPECT_TRUE(details->accelerator); 488 EXPECT_TRUE(details->accelerator);
476 489
477 base::WeakPtr<Accelerator> accelerator_weak_ptr = 490 base::WeakPtr<Accelerator> accelerator_weak_ptr =
478 details->accelerator->GetWeakPtr(); 491 details->accelerator->GetWeakPtr();
479 dispatcher->RemoveAccelerator(accelerator_1); 492 dispatcher->RemoveAccelerator(accelerator_1);
480 EXPECT_FALSE(accelerator_weak_ptr); 493 EXPECT_FALSE(accelerator_weak_ptr);
481 494
482 // Post deletion there should be no accelerator 495 // Post deletion there should be no accelerator
483 dispatcher->ProcessEvent(key); 496 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
484 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 497 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
485 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 498 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
486 EXPECT_TRUE(details); 499 EXPECT_TRUE(details);
487 EXPECT_FALSE(details->accelerator); 500 EXPECT_FALSE(details->accelerator);
488 } 501 }
489 502
503 TEST_F(EventDispatcherTest, ProcessPost) {
504 TestEventDispatcherDelegate* event_dispatcher_delegate =
505 test_event_dispatcher_delegate();
506 EventDispatcher* dispatcher = event_dispatcher();
507
508 uint32_t pre_id = 1;
509 {
510 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
511 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
512 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET;
513 dispatcher->AddAccelerator(pre_id, std::move(matcher));
514 }
515
516 uint32_t post_id = 2;
517 {
518 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
519 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
520 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
521 dispatcher->AddAccelerator(post_id, std::move(matcher));
522 }
523
524 // Set focused window for EventDispatcher dispatches key events.
525 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
526 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get());
527
528 // Dispatch for ANY, which should trigger PRE and not call
529 // DispatchInputEventToWindow().
530 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
531 dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
532 EXPECT_EQ(EventDispatcherDelegate::AcceleratorPhase::PRE,
533 event_dispatcher_delegate->last_accelerator_phase());
534 EXPECT_EQ(pre_id, event_dispatcher_delegate->GetAndClearLastAccelerator());
535 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
536
537 // Dispatch for POST, which should trigger POST.
538 dispatcher->ProcessEvent(key,
539 EventDispatcher::AcceleratorMatchPhase::POST_ONLY);
540 std::unique_ptr<DispatchedEventDetails> details =
541 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
542 ASSERT_TRUE(details);
543 ASSERT_TRUE(details->accelerator);
544 EXPECT_EQ(post_id, details->accelerator->id());
545 }
546
490 TEST_F(EventDispatcherTest, Capture) { 547 TEST_F(EventDispatcherTest, Capture) {
491 ServerWindow* root = root_window(); 548 ServerWindow* root = root_window();
492 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 549 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
493 550
494 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 551 root->SetBounds(gfx::Rect(0, 0, 100, 100));
495 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 552 child->SetBounds(gfx::Rect(10, 10, 20, 20));
496 553
497 MouseEventTest tests[] = { 554 MouseEventTest tests[] = {
498 // Send a mouse down event over child. 555 // Send a mouse down event over child.
499 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), 556 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); 639 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
583 640
584 TestEventDispatcherDelegate* event_dispatcher_delegate = 641 TestEventDispatcherDelegate* event_dispatcher_delegate =
585 test_event_dispatcher_delegate(); 642 test_event_dispatcher_delegate();
586 EventDispatcher* dispatcher = event_dispatcher(); 643 EventDispatcher* dispatcher = event_dispatcher();
587 644
588 // Start move loop by sending mouse event over non-client area. 645 // Start move loop by sending mouse event over non-client area.
589 const ui::PointerEvent press_event(ui::MouseEvent( 646 const ui::PointerEvent press_event(ui::MouseEvent(
590 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), 647 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
591 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 648 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
592 dispatcher->ProcessEvent(press_event); 649 dispatcher->ProcessEvent(press_event,
650 EventDispatcher::AcceleratorMatchPhase::ANY);
593 651
594 // Events should target child and be in the non-client area. 652 // Events should target child and be in the non-client area.
595 std::unique_ptr<DispatchedEventDetails> details = 653 std::unique_ptr<DispatchedEventDetails> details =
596 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 654 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
597 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 655 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
598 ASSERT_TRUE(details); 656 ASSERT_TRUE(details);
599 ASSERT_EQ(child.get(), details->window); 657 ASSERT_EQ(child.get(), details->window);
600 EXPECT_TRUE(details->IsNonclientArea()); 658 EXPECT_TRUE(details->IsNonclientArea());
601 659
602 // Move the mouse 5,6 pixels and target is the same. 660 // Move the mouse 5,6 pixels and target is the same.
603 const ui::PointerEvent move_event( 661 const ui::PointerEvent move_event(
604 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18), 662 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18),
605 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); 663 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
606 dispatcher->ProcessEvent(move_event); 664 dispatcher->ProcessEvent(move_event,
665 EventDispatcher::AcceleratorMatchPhase::ANY);
607 666
608 // Still same target. 667 // Still same target.
609 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 668 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
610 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 669 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
611 ASSERT_EQ(child.get(), details->window); 670 ASSERT_EQ(child.get(), details->window);
612 EXPECT_TRUE(details->IsNonclientArea()); 671 EXPECT_TRUE(details->IsNonclientArea());
613 672
614 // Release the mouse. 673 // Release the mouse.
615 const ui::PointerEvent release_event(ui::MouseEvent( 674 const ui::PointerEvent release_event(ui::MouseEvent(
616 ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18), 675 ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18),
617 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 676 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
618 dispatcher->ProcessEvent(release_event); 677 dispatcher->ProcessEvent(release_event,
678 EventDispatcher::AcceleratorMatchPhase::ANY);
619 679
620 // The event should not have been dispatched to the delegate. 680 // The event should not have been dispatched to the delegate.
621 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 681 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
622 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 682 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
623 ASSERT_EQ(child.get(), details->window); 683 ASSERT_EQ(child.get(), details->window);
624 EXPECT_TRUE(details->IsNonclientArea()); 684 EXPECT_TRUE(details->IsNonclientArea());
625 685
626 // Press in the client area and verify target/client area. The non-client area 686 // Press in the client area and verify target/client area. The non-client area
627 // should get an exit first. 687 // should get an exit first.
628 const ui::PointerEvent press_event2(ui::MouseEvent( 688 const ui::PointerEvent press_event2(ui::MouseEvent(
629 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), 689 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22),
630 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 690 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
631 dispatcher->ProcessEvent(press_event2); 691 dispatcher->ProcessEvent(press_event2,
692 EventDispatcher::AcceleratorMatchPhase::ANY);
632 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 693 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
633 EXPECT_TRUE(event_dispatcher_delegate->has_queued_events()); 694 EXPECT_TRUE(event_dispatcher_delegate->has_queued_events());
634 ASSERT_EQ(child.get(), details->window); 695 ASSERT_EQ(child.get(), details->window);
635 EXPECT_TRUE(details->IsNonclientArea()); 696 EXPECT_TRUE(details->IsNonclientArea());
636 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); 697 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
637 698
638 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 699 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
639 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 700 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
640 ASSERT_EQ(child.get(), details->window); 701 ASSERT_EQ(child.get(), details->window);
641 EXPECT_TRUE(details->IsClientArea()); 702 EXPECT_TRUE(details->IsClientArea());
642 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 703 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
643 } 704 }
644 705
645 TEST_F(EventDispatcherTest, AdditionalClientArea) { 706 TEST_F(EventDispatcherTest, AdditionalClientArea) {
646 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 707 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
647 708
648 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 709 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
649 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 710 child->SetBounds(gfx::Rect(10, 10, 20, 20));
650 711
651 std::vector<gfx::Rect> additional_client_areas; 712 std::vector<gfx::Rect> additional_client_areas;
652 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); 713 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2));
653 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); 714 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas);
654 715
655 TestEventDispatcherDelegate* event_dispatcher_delegate = 716 TestEventDispatcherDelegate* event_dispatcher_delegate =
656 test_event_dispatcher_delegate(); 717 test_event_dispatcher_delegate();
657 // Press in the additional client area, it should go to the child. 718 // Press in the additional client area, it should go to the child.
658 const ui::PointerEvent press_event(ui::MouseEvent( 719 const ui::PointerEvent press_event(ui::MouseEvent(
659 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), 720 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11),
660 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 721 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
661 event_dispatcher()->ProcessEvent(press_event); 722 event_dispatcher()->ProcessEvent(press_event,
723 EventDispatcher::AcceleratorMatchPhase::ANY);
662 724
663 // Events should target child and be in the client area. 725 // Events should target child and be in the client area.
664 std::unique_ptr<DispatchedEventDetails> details = 726 std::unique_ptr<DispatchedEventDetails> details =
665 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 727 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
666 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 728 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
667 ASSERT_EQ(child.get(), details->window); 729 ASSERT_EQ(child.get(), details->window);
668 EXPECT_TRUE(details->IsClientArea()); 730 EXPECT_TRUE(details->IsClientArea());
669 } 731 }
670 732
671 TEST_F(EventDispatcherTest, HitTestMask) { 733 TEST_F(EventDispatcherTest, HitTestMask) {
672 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 734 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
673 735
674 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 736 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
675 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 737 child->SetBounds(gfx::Rect(10, 10, 20, 20));
676 child->SetHitTestMask(gfx::Rect(2, 2, 16, 16)); 738 child->SetHitTestMask(gfx::Rect(2, 2, 16, 16));
677 739
678 // Move in the masked area. 740 // Move in the masked area.
679 const ui::PointerEvent move1(ui::MouseEvent( 741 const ui::PointerEvent move1(ui::MouseEvent(
680 ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11), 742 ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11),
681 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); 743 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
682 event_dispatcher()->ProcessEvent(move1); 744 event_dispatcher()->ProcessEvent(move1,
745 EventDispatcher::AcceleratorMatchPhase::ANY);
683 746
684 // Event went through the child window and hit the root. 747 // Event went through the child window and hit the root.
685 std::unique_ptr<DispatchedEventDetails> details1 = 748 std::unique_ptr<DispatchedEventDetails> details1 =
686 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 749 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
687 EXPECT_EQ(root_window(), details1->window); 750 EXPECT_EQ(root_window(), details1->window);
688 EXPECT_TRUE(details1->IsClientArea()); 751 EXPECT_TRUE(details1->IsClientArea());
689 752
690 child->ClearHitTestMask(); 753 child->ClearHitTestMask();
691 754
692 // Move right in the same part of the window. 755 // Move right in the same part of the window.
693 const ui::PointerEvent move2(ui::MouseEvent( 756 const ui::PointerEvent move2(ui::MouseEvent(
694 ui::ET_MOUSE_MOVED, gfx::Point(11, 12), gfx::Point(11, 12), 757 ui::ET_MOUSE_MOVED, gfx::Point(11, 12), gfx::Point(11, 12),
695 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); 758 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
696 event_dispatcher()->ProcessEvent(move2); 759 event_dispatcher()->ProcessEvent(move2,
760 EventDispatcher::AcceleratorMatchPhase::ANY);
697 761
698 // Mouse exits the root. 762 // Mouse exits the root.
699 std::unique_ptr<DispatchedEventDetails> details2 = 763 std::unique_ptr<DispatchedEventDetails> details2 =
700 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 764 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
701 EXPECT_EQ(ui::ET_POINTER_EXITED, details2->event->type()); 765 EXPECT_EQ(ui::ET_POINTER_EXITED, details2->event->type());
702 766
703 // Mouse hits the child. 767 // Mouse hits the child.
704 std::unique_ptr<DispatchedEventDetails> details3 = 768 std::unique_ptr<DispatchedEventDetails> details3 =
705 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 769 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
706 EXPECT_EQ(child.get(), details3->window); 770 EXPECT_EQ(child.get(), details3->window);
707 EXPECT_TRUE(details3->IsClientArea()); 771 EXPECT_TRUE(details3->IsClientArea());
708 } 772 }
709 773
710 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { 774 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) {
711 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 775 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
712 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 776 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
713 777
714 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 778 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
715 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 779 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
716 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 780 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
717 781
718 TestEventDispatcherDelegate* event_dispatcher_delegate = 782 TestEventDispatcherDelegate* event_dispatcher_delegate =
719 test_event_dispatcher_delegate(); 783 test_event_dispatcher_delegate();
720 EventDispatcher* dispatcher = event_dispatcher(); 784 EventDispatcher* dispatcher = event_dispatcher();
721 785
722 // Press on child1. First press event should change focus. 786 // Press on child1. First press event should change focus.
723 const ui::PointerEvent press_event(ui::MouseEvent( 787 const ui::PointerEvent press_event(ui::MouseEvent(
724 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), 788 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
725 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 789 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
726 dispatcher->ProcessEvent(press_event); 790 dispatcher->ProcessEvent(press_event,
791 EventDispatcher::AcceleratorMatchPhase::ANY);
727 std::unique_ptr<DispatchedEventDetails> details = 792 std::unique_ptr<DispatchedEventDetails> details =
728 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 793 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
729 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 794 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
730 EXPECT_EQ(child1.get(), details->window); 795 EXPECT_EQ(child1.get(), details->window);
731 EXPECT_EQ(child1.get(), 796 EXPECT_EQ(child1.get(),
732 event_dispatcher_delegate->GetAndClearLastFocusedWindow()); 797 event_dispatcher_delegate->GetAndClearLastFocusedWindow());
733 798
734 // Press (with a different pointer id) on child2. Event should go to child2, 799 // Press (with a different pointer id) on child2. Event should go to child2,
735 // but focus should not change. 800 // but focus should not change.
736 const ui::PointerEvent touch_event(ui::TouchEvent( 801 const ui::PointerEvent touch_event(ui::TouchEvent(
737 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeTicks())); 802 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeTicks()));
738 dispatcher->ProcessEvent(touch_event); 803 dispatcher->ProcessEvent(touch_event,
804 EventDispatcher::AcceleratorMatchPhase::ANY);
739 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 805 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
740 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 806 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
741 EXPECT_EQ(child2.get(), details->window); 807 EXPECT_EQ(child2.get(), details->window);
742 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); 808 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow());
743 } 809 }
744 810
745 TEST_F(EventDispatcherTest, TwoPointersActive) { 811 TEST_F(EventDispatcherTest, TwoPointersActive) {
746 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 812 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
747 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 813 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
748 814
749 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 815 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
750 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 816 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
751 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 817 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
752 818
753 TestEventDispatcherDelegate* event_dispatcher_delegate = 819 TestEventDispatcherDelegate* event_dispatcher_delegate =
754 test_event_dispatcher_delegate(); 820 test_event_dispatcher_delegate();
755 EventDispatcher* dispatcher = event_dispatcher(); 821 EventDispatcher* dispatcher = event_dispatcher();
756 822
757 // Press on child1. 823 // Press on child1.
758 const ui::PointerEvent touch_event1(ui::TouchEvent( 824 const ui::PointerEvent touch_event1(ui::TouchEvent(
759 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks())); 825 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks()));
760 dispatcher->ProcessEvent(touch_event1); 826 dispatcher->ProcessEvent(touch_event1,
827 EventDispatcher::AcceleratorMatchPhase::ANY);
761 std::unique_ptr<DispatchedEventDetails> details = 828 std::unique_ptr<DispatchedEventDetails> details =
762 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 829 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
763 EXPECT_EQ(child1.get(), details->window); 830 EXPECT_EQ(child1.get(), details->window);
764 831
765 // Drag over child2, child1 should get the drag. 832 // Drag over child2, child1 should get the drag.
766 const ui::PointerEvent drag_event1(ui::TouchEvent( 833 const ui::PointerEvent drag_event1(ui::TouchEvent(
767 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeTicks())); 834 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeTicks()));
768 dispatcher->ProcessEvent(drag_event1); 835 dispatcher->ProcessEvent(drag_event1,
836 EventDispatcher::AcceleratorMatchPhase::ANY);
769 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 837 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
770 EXPECT_EQ(child1.get(), details->window); 838 EXPECT_EQ(child1.get(), details->window);
771 839
772 // Press on child2 with a different touch id. 840 // Press on child2 with a different touch id.
773 const ui::PointerEvent touch_event2(ui::TouchEvent( 841 const ui::PointerEvent touch_event2(ui::TouchEvent(
774 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeTicks())); 842 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeTicks()));
775 dispatcher->ProcessEvent(touch_event2); 843 dispatcher->ProcessEvent(touch_event2,
844 EventDispatcher::AcceleratorMatchPhase::ANY);
776 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 845 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
777 EXPECT_EQ(child2.get(), details->window); 846 EXPECT_EQ(child2.get(), details->window);
778 847
779 // Drag over child1 with id 2, child2 should continue to get the drag. 848 // Drag over child1 with id 2, child2 should continue to get the drag.
780 const ui::PointerEvent drag_event2(ui::TouchEvent( 849 const ui::PointerEvent drag_event2(ui::TouchEvent(
781 ui::ET_TOUCH_MOVED, gfx::Point(13, 14), 2, base::TimeTicks())); 850 ui::ET_TOUCH_MOVED, gfx::Point(13, 14), 2, base::TimeTicks()));
782 dispatcher->ProcessEvent(drag_event2); 851 dispatcher->ProcessEvent(drag_event2,
852 EventDispatcher::AcceleratorMatchPhase::ANY);
783 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 853 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
784 EXPECT_EQ(child2.get(), details->window); 854 EXPECT_EQ(child2.get(), details->window);
785 855
786 // Drag again with id 1, child1 should continue to get it. 856 // Drag again with id 1, child1 should continue to get it.
787 dispatcher->ProcessEvent(drag_event1); 857 dispatcher->ProcessEvent(drag_event1,
858 EventDispatcher::AcceleratorMatchPhase::ANY);
788 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 859 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
789 EXPECT_EQ(child1.get(), details->window); 860 EXPECT_EQ(child1.get(), details->window);
790 861
791 // Release touch id 1, and click on 2. 2 should get it. 862 // Release touch id 1, and click on 2. 2 should get it.
792 const ui::PointerEvent touch_release(ui::TouchEvent( 863 const ui::PointerEvent touch_release(ui::TouchEvent(
793 ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), 1, base::TimeTicks())); 864 ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), 1, base::TimeTicks()));
794 dispatcher->ProcessEvent(touch_release); 865 dispatcher->ProcessEvent(touch_release,
866 EventDispatcher::AcceleratorMatchPhase::ANY);
795 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 867 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
796 EXPECT_EQ(child1.get(), details->window); 868 EXPECT_EQ(child1.get(), details->window);
797 const ui::PointerEvent touch_event3(ui::TouchEvent( 869 const ui::PointerEvent touch_event3(ui::TouchEvent(
798 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeTicks())); 870 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeTicks()));
799 dispatcher->ProcessEvent(touch_event3); 871 dispatcher->ProcessEvent(touch_event3,
872 EventDispatcher::AcceleratorMatchPhase::ANY);
800 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 873 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
801 EXPECT_EQ(child2.get(), details->window); 874 EXPECT_EQ(child2.get(), details->window);
802 } 875 }
803 876
804 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { 877 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) {
805 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 878 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
806 879
807 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 880 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
808 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 881 child->SetBounds(gfx::Rect(10, 10, 20, 20));
809 882
810 TestEventDispatcherDelegate* event_dispatcher_delegate = 883 TestEventDispatcherDelegate* event_dispatcher_delegate =
811 test_event_dispatcher_delegate(); 884 test_event_dispatcher_delegate();
812 EventDispatcher* dispatcher = event_dispatcher(); 885 EventDispatcher* dispatcher = event_dispatcher();
813 886
814 // Press on child. 887 // Press on child.
815 const ui::PointerEvent touch_event1(ui::TouchEvent( 888 const ui::PointerEvent touch_event1(ui::TouchEvent(
816 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks())); 889 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks()));
817 dispatcher->ProcessEvent(touch_event1); 890 dispatcher->ProcessEvent(touch_event1,
891 EventDispatcher::AcceleratorMatchPhase::ANY);
818 std::unique_ptr<DispatchedEventDetails> details = 892 std::unique_ptr<DispatchedEventDetails> details =
819 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 893 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
820 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 894 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
821 EXPECT_EQ(child.get(), details->window); 895 EXPECT_EQ(child.get(), details->window);
822 896
823 // Delete child, and continue the drag. Event should not be dispatched. 897 // Delete child, and continue the drag. Event should not be dispatched.
824 child.reset(); 898 child.reset();
825 899
826 const ui::PointerEvent drag_event1(ui::TouchEvent( 900 const ui::PointerEvent drag_event1(ui::TouchEvent(
827 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeTicks())); 901 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeTicks()));
828 dispatcher->ProcessEvent(drag_event1); 902 dispatcher->ProcessEvent(drag_event1,
903 EventDispatcher::AcceleratorMatchPhase::ANY);
829 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 904 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
830 EXPECT_EQ(nullptr, details.get()); 905 EXPECT_EQ(nullptr, details.get());
831 } 906 }
832 907
833 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { 908 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) {
834 ServerWindow* root = root_window(); 909 ServerWindow* root = root_window();
835 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 910 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
836 911
837 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 912 root->SetBounds(gfx::Rect(0, 0, 100, 100));
838 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 913 child->SetBounds(gfx::Rect(10, 10, 20, 20));
839 914
840 TestEventDispatcherDelegate* event_dispatcher_delegate = 915 TestEventDispatcherDelegate* event_dispatcher_delegate =
841 test_event_dispatcher_delegate(); 916 test_event_dispatcher_delegate();
842 EventDispatcher* dispatcher = event_dispatcher(); 917 EventDispatcher* dispatcher = event_dispatcher();
843 918
844 // Send event that is not over child. 919 // Send event that is not over child.
845 const ui::PointerEvent ui_event(ui::MouseEvent( 920 const ui::PointerEvent ui_event(ui::MouseEvent(
846 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9), 921 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9),
847 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 922 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
848 dispatcher->ProcessEvent(ui_event); 923 dispatcher->ProcessEvent(ui_event,
924 EventDispatcher::AcceleratorMatchPhase::ANY);
849 std::unique_ptr<DispatchedEventDetails> details = 925 std::unique_ptr<DispatchedEventDetails> details =
850 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 926 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
851 ASSERT_EQ(root, details->window); 927 ASSERT_EQ(root, details->window);
852 928
853 // Release the mouse. 929 // Release the mouse.
854 const ui::PointerEvent release_event(ui::MouseEvent( 930 const ui::PointerEvent release_event(ui::MouseEvent(
855 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9), 931 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9),
856 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 932 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
857 dispatcher->ProcessEvent(release_event); 933 dispatcher->ProcessEvent(release_event,
934 EventDispatcher::AcceleratorMatchPhase::ANY);
858 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 935 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
859 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 936 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
860 ASSERT_EQ(root, details->window); 937 ASSERT_EQ(root, details->window);
861 EXPECT_TRUE(details->IsClientArea()); 938 EXPECT_TRUE(details->IsClientArea());
862 939
863 // Change the extended hit test region and send event in extended hit test 940 // Change the extended hit test region and send event in extended hit test
864 // region. Should result in exit for root, followed by press for child. 941 // region. Should result in exit for root, followed by press for child.
865 child->set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5)); 942 child->set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5));
866 dispatcher->ProcessEvent(ui_event); 943 dispatcher->ProcessEvent(ui_event,
944 EventDispatcher::AcceleratorMatchPhase::ANY);
867 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 945 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
868 EXPECT_EQ(root, details->window); 946 EXPECT_EQ(root, details->window);
869 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); 947 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
870 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 948 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
871 ASSERT_TRUE(details); 949 ASSERT_TRUE(details);
872 950
873 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 951 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
874 EXPECT_TRUE(details->IsNonclientArea()); 952 EXPECT_TRUE(details->IsNonclientArea());
875 ASSERT_EQ(child.get(), details->window); 953 ASSERT_EQ(child.get(), details->window);
876 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 954 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 999
922 { 1000 {
923 // Send all pointer events to the child. 1001 // Send all pointer events to the child.
924 dispatcher->SetCaptureWindow(child.get(), kClientAreaId); 1002 dispatcher->SetCaptureWindow(child.get(), kClientAreaId);
925 1003
926 // The mouse press should go to the child even though its outside its 1004 // The mouse press should go to the child even though its outside its
927 // bounds. 1005 // bounds.
928 const ui::PointerEvent left_press_event(ui::MouseEvent( 1006 const ui::PointerEvent left_press_event(ui::MouseEvent(
929 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 1007 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
930 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1008 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
931 dispatcher->ProcessEvent(left_press_event); 1009 dispatcher->ProcessEvent(left_press_event,
1010 EventDispatcher::AcceleratorMatchPhase::ANY);
932 1011
933 // Events should target child. 1012 // Events should target child.
934 std::unique_ptr<DispatchedEventDetails> details = 1013 std::unique_ptr<DispatchedEventDetails> details =
935 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1014 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
936 1015
937 ASSERT_TRUE(details); 1016 ASSERT_TRUE(details);
938 ASSERT_EQ(child.get(), details->window); 1017 ASSERT_EQ(child.get(), details->window);
939 EXPECT_TRUE(details->IsClientArea()); 1018 EXPECT_TRUE(details->IsClientArea());
940 EXPECT_TRUE(IsMouseButtonDown()); 1019 EXPECT_TRUE(IsMouseButtonDown());
941 1020
942 // The mouse down state should update while capture is set. 1021 // The mouse down state should update while capture is set.
943 const ui::PointerEvent right_press_event(ui::MouseEvent( 1022 const ui::PointerEvent right_press_event(ui::MouseEvent(
944 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 1023 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
945 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 1024 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
946 ui::EF_RIGHT_MOUSE_BUTTON)); 1025 ui::EF_RIGHT_MOUSE_BUTTON));
947 dispatcher->ProcessEvent(right_press_event); 1026 dispatcher->ProcessEvent(right_press_event,
1027 EventDispatcher::AcceleratorMatchPhase::ANY);
948 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1028 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
949 EXPECT_TRUE(IsMouseButtonDown()); 1029 EXPECT_TRUE(IsMouseButtonDown());
950 1030
951 // One button released should not clear mouse down 1031 // One button released should not clear mouse down
952 const ui::PointerEvent left_release_event(ui::MouseEvent( 1032 const ui::PointerEvent left_release_event(ui::MouseEvent(
953 ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5), 1033 ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5),
954 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 1034 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
955 ui::EF_LEFT_MOUSE_BUTTON)); 1035 ui::EF_LEFT_MOUSE_BUTTON));
956 dispatcher->ProcessEvent(left_release_event); 1036 dispatcher->ProcessEvent(left_release_event,
1037 EventDispatcher::AcceleratorMatchPhase::ANY);
957 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1038 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
958 EXPECT_TRUE(IsMouseButtonDown()); 1039 EXPECT_TRUE(IsMouseButtonDown());
959 1040
960 // Touch Event while mouse is down should not affect state. 1041 // Touch Event while mouse is down should not affect state.
961 const ui::PointerEvent touch_event(ui::TouchEvent( 1042 const ui::PointerEvent touch_event(ui::TouchEvent(
962 ui::ET_TOUCH_PRESSED, gfx::Point(15, 15), 2, base::TimeTicks())); 1043 ui::ET_TOUCH_PRESSED, gfx::Point(15, 15), 2, base::TimeTicks()));
963 dispatcher->ProcessEvent(touch_event); 1044 dispatcher->ProcessEvent(touch_event,
1045 EventDispatcher::AcceleratorMatchPhase::ANY);
964 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1046 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
965 EXPECT_TRUE(IsMouseButtonDown()); 1047 EXPECT_TRUE(IsMouseButtonDown());
966 1048
967 // Move event should not affect down 1049 // Move event should not affect down
968 const ui::PointerEvent move_event( 1050 const ui::PointerEvent move_event(
969 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 5), gfx::Point(15, 5), 1051 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 5), gfx::Point(15, 5),
970 base::TimeTicks(), ui::EF_RIGHT_MOUSE_BUTTON, 1052 base::TimeTicks(), ui::EF_RIGHT_MOUSE_BUTTON,
971 ui::EF_RIGHT_MOUSE_BUTTON)); 1053 ui::EF_RIGHT_MOUSE_BUTTON));
972 dispatcher->ProcessEvent(move_event); 1054 dispatcher->ProcessEvent(move_event,
1055 EventDispatcher::AcceleratorMatchPhase::ANY);
973 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1056 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
974 EXPECT_TRUE(IsMouseButtonDown()); 1057 EXPECT_TRUE(IsMouseButtonDown());
975 1058
976 // All mouse buttons up should clear mouse down. 1059 // All mouse buttons up should clear mouse down.
977 const ui::PointerEvent right_release_event( 1060 const ui::PointerEvent right_release_event(
978 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), 1061 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5),
979 gfx::Point(5, 5), base::TimeTicks(), 1062 gfx::Point(5, 5), base::TimeTicks(),
980 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); 1063 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
981 dispatcher->ProcessEvent(right_release_event); 1064 dispatcher->ProcessEvent(right_release_event,
1065 EventDispatcher::AcceleratorMatchPhase::ANY);
982 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1066 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
983 EXPECT_FALSE(IsMouseButtonDown()); 1067 EXPECT_FALSE(IsMouseButtonDown());
984 } 1068 }
985 1069
986 { 1070 {
987 // Releasing capture and sending the same event will go to the root. 1071 // Releasing capture and sending the same event will go to the root.
988 dispatcher->SetCaptureWindow(nullptr, kClientAreaId); 1072 dispatcher->SetCaptureWindow(nullptr, kClientAreaId);
989 const ui::PointerEvent press_event(ui::MouseEvent( 1073 const ui::PointerEvent press_event(ui::MouseEvent(
990 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 1074 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
991 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1075 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
992 dispatcher->ProcessEvent(press_event); 1076 dispatcher->ProcessEvent(press_event,
1077 EventDispatcher::AcceleratorMatchPhase::ANY);
993 1078
994 // Events should target the root. 1079 // Events should target the root.
995 std::unique_ptr<DispatchedEventDetails> details = 1080 std::unique_ptr<DispatchedEventDetails> details =
996 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1081 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
997 1082
998 ASSERT_TRUE(details); 1083 ASSERT_TRUE(details);
999 ASSERT_EQ(root, details->window); 1084 ASSERT_EQ(root, details->window);
1000 } 1085 }
1001 } 1086 }
1002 1087
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 child.get(), gfx::Point(50, 50), gfx::Point(40, 40)}, 1125 child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
1041 1126
1042 }; 1127 };
1043 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests, 1128 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests,
1044 arraysize(tests)); 1129 arraysize(tests));
1045 1130
1046 // Add a second pointer target to the child. 1131 // Add a second pointer target to the child.
1047 { 1132 {
1048 const ui::PointerEvent touch_event(ui::TouchEvent( 1133 const ui::PointerEvent touch_event(ui::TouchEvent(
1049 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks())); 1134 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks()));
1050 dispatcher->ProcessEvent(touch_event); 1135 dispatcher->ProcessEvent(touch_event,
1136 EventDispatcher::AcceleratorMatchPhase::ANY);
1051 } 1137 }
1052 1138
1053 std::unique_ptr<DispatchedEventDetails> details = 1139 std::unique_ptr<DispatchedEventDetails> details =
1054 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1140 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1055 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 1141 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
1056 EXPECT_EQ(child.get(), details->window); 1142 EXPECT_EQ(child.get(), details->window);
1057 1143
1058 // Verify that no window has explicit capture and hence we did indeed do 1144 // Verify that no window has explicit capture and hence we did indeed do
1059 // implicit capture. 1145 // implicit capture.
1060 ASSERT_EQ(nullptr, dispatcher->capture_window()); 1146 ASSERT_EQ(nullptr, dispatcher->capture_window());
(...skipping 11 matching lines...) Expand all
1072 1158
1073 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1159 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1074 ASSERT_TRUE(details); 1160 ASSERT_TRUE(details);
1075 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 1161 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
1076 EXPECT_EQ(child.get(), details->window); 1162 EXPECT_EQ(child.get(), details->window);
1077 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); 1163 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
1078 1164
1079 const ui::PointerEvent press_event(ui::MouseEvent( 1165 const ui::PointerEvent press_event(ui::MouseEvent(
1080 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1166 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1081 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1167 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1082 dispatcher->ProcessEvent(press_event); 1168 dispatcher->ProcessEvent(press_event,
1169 EventDispatcher::AcceleratorMatchPhase::ANY);
1083 1170
1084 // Events should target the root. 1171 // Events should target the root.
1085 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1172 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1086 ASSERT_TRUE(details); 1173 ASSERT_TRUE(details);
1087 ASSERT_EQ(root, details->window); 1174 ASSERT_EQ(root, details->window);
1088 ASSERT_TRUE(details->IsNonclientArea()); 1175 ASSERT_TRUE(details->IsNonclientArea());
1089 } 1176 }
1090 1177
1091 // Tests that setting capture does delete active pointer targets for the capture 1178 // Tests that setting capture does delete active pointer targets for the capture
1092 // window. 1179 // window.
1093 TEST_F(EventDispatcherTest, CaptureUpdatesActivePointerTargets) { 1180 TEST_F(EventDispatcherTest, CaptureUpdatesActivePointerTargets) {
1094 ServerWindow* root = root_window(); 1181 ServerWindow* root = root_window();
1095 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 1182 root->SetBounds(gfx::Rect(0, 0, 100, 100));
1096 1183
1097 EventDispatcher* dispatcher = event_dispatcher(); 1184 EventDispatcher* dispatcher = event_dispatcher();
1098 { 1185 {
1099 const ui::PointerEvent press_event(ui::MouseEvent( 1186 const ui::PointerEvent press_event(ui::MouseEvent(
1100 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 1187 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
1101 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1188 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1102 dispatcher->ProcessEvent(press_event); 1189 dispatcher->ProcessEvent(press_event,
1190 EventDispatcher::AcceleratorMatchPhase::ANY);
1103 1191
1104 std::unique_ptr<DispatchedEventDetails> details = 1192 std::unique_ptr<DispatchedEventDetails> details =
1105 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1193 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1106 ASSERT_TRUE(details); 1194 ASSERT_TRUE(details);
1107 ASSERT_EQ(root, details->window); 1195 ASSERT_EQ(root, details->window);
1108 } 1196 }
1109 { 1197 {
1110 const ui::PointerEvent touch_event(ui::TouchEvent( 1198 const ui::PointerEvent touch_event(ui::TouchEvent(
1111 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks())); 1199 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeTicks()));
1112 dispatcher->ProcessEvent(touch_event); 1200 dispatcher->ProcessEvent(touch_event,
1201 EventDispatcher::AcceleratorMatchPhase::ANY);
1113 } 1202 }
1114 1203
1115 ASSERT_TRUE(AreAnyPointersDown()); 1204 ASSERT_TRUE(AreAnyPointersDown());
1116 ASSERT_TRUE(IsWindowPointerTarget(root)); 1205 ASSERT_TRUE(IsWindowPointerTarget(root));
1117 EXPECT_EQ(2, NumberPointerTargetsForWindow(root)); 1206 EXPECT_EQ(2, NumberPointerTargetsForWindow(root));
1118 1207
1119 // Setting the capture should clear the implicit pointers for the specified 1208 // Setting the capture should clear the implicit pointers for the specified
1120 // window. 1209 // window.
1121 dispatcher->SetCaptureWindow(root, kNonclientAreaId); 1210 dispatcher->SetCaptureWindow(root, kNonclientAreaId);
1122 EXPECT_FALSE(AreAnyPointersDown()); 1211 EXPECT_FALSE(AreAnyPointersDown());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); 1261 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
1173 EventDispatcher* dispatcher = event_dispatcher(); 1262 EventDispatcher* dispatcher = event_dispatcher();
1174 dispatcher->SetCaptureWindow(root, kNonclientAreaId); 1263 dispatcher->SetCaptureWindow(root, kNonclientAreaId);
1175 1264
1176 TestEventDispatcherDelegate* event_dispatcher_delegate = 1265 TestEventDispatcherDelegate* event_dispatcher_delegate =
1177 test_event_dispatcher_delegate(); 1266 test_event_dispatcher_delegate();
1178 // Press in the client area, it should be marked as non client. 1267 // Press in the client area, it should be marked as non client.
1179 const ui::PointerEvent press_event(ui::MouseEvent( 1268 const ui::PointerEvent press_event(ui::MouseEvent(
1180 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6), 1269 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6),
1181 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1270 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1182 event_dispatcher()->ProcessEvent(press_event); 1271 event_dispatcher()->ProcessEvent(press_event,
1272 EventDispatcher::AcceleratorMatchPhase::ANY);
1183 1273
1184 // Events should target child and be in the client area. 1274 // Events should target child and be in the client area.
1185 std::unique_ptr<DispatchedEventDetails> details = 1275 std::unique_ptr<DispatchedEventDetails> details =
1186 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1276 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1187 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 1277 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
1188 ASSERT_EQ(root, details->window); 1278 ASSERT_EQ(root, details->window);
1189 EXPECT_TRUE(details->IsNonclientArea()); 1279 EXPECT_TRUE(details->IsNonclientArea());
1190 } 1280 }
1191 1281
1192 TEST_F(EventDispatcherTest, ProcessPointerEvents) { 1282 TEST_F(EventDispatcherTest, ProcessPointerEvents) {
1193 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1283 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1194 1284
1195 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1285 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1196 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1286 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1197 1287
1198 { 1288 {
1199 const ui::PointerEvent pointer_event(ui::MouseEvent( 1289 const ui::PointerEvent pointer_event(ui::MouseEvent(
1200 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 1290 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
1201 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1291 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1202 event_dispatcher()->ProcessEvent(pointer_event); 1292 event_dispatcher()->ProcessEvent(
1293 pointer_event, EventDispatcher::AcceleratorMatchPhase::ANY);
1203 1294
1204 std::unique_ptr<DispatchedEventDetails> details = 1295 std::unique_ptr<DispatchedEventDetails> details =
1205 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1296 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1206 ASSERT_TRUE(details); 1297 ASSERT_TRUE(details);
1207 ASSERT_EQ(child.get(), details->window); 1298 ASSERT_EQ(child.get(), details->window);
1208 1299
1209 ASSERT_TRUE(details->event); 1300 ASSERT_TRUE(details->event);
1210 ASSERT_TRUE(details->event->IsPointerEvent()); 1301 ASSERT_TRUE(details->event->IsPointerEvent());
1211 1302
1212 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1303 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1213 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); 1304 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
1214 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); 1305 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
1215 } 1306 }
1216 1307
1217 { 1308 {
1218 const int touch_id = 3; 1309 const int touch_id = 3;
1219 const ui::PointerEvent pointer_event( 1310 const ui::PointerEvent pointer_event(
1220 ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), touch_id, 1311 ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), touch_id,
1221 base::TimeTicks())); 1312 base::TimeTicks()));
1222 event_dispatcher()->ProcessEvent(pointer_event); 1313 event_dispatcher()->ProcessEvent(
1314 pointer_event, EventDispatcher::AcceleratorMatchPhase::ANY);
1223 1315
1224 std::unique_ptr<DispatchedEventDetails> details = 1316 std::unique_ptr<DispatchedEventDetails> details =
1225 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1317 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1226 ASSERT_TRUE(details); 1318 ASSERT_TRUE(details);
1227 ASSERT_EQ(child.get(), details->window); 1319 ASSERT_EQ(child.get(), details->window);
1228 1320
1229 ASSERT_TRUE(details->event); 1321 ASSERT_TRUE(details->event);
1230 ASSERT_TRUE(details->event->IsPointerEvent()); 1322 ASSERT_TRUE(details->event->IsPointerEvent());
1231 1323
1232 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1324 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1233 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); 1325 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location());
1234 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); 1326 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location());
1235 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); 1327 EXPECT_EQ(touch_id, dispatched_event->pointer_id());
1236 } 1328 }
1237 } 1329 }
1238 1330
1239 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { 1331 TEST_F(EventDispatcherTest, ResetClearsPointerDown) {
1240 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1332 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1241 1333
1242 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1334 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1243 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1335 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1244 1336
1245 // Send event that is over child. 1337 // Send event that is over child.
1246 const ui::PointerEvent ui_event(ui::MouseEvent( 1338 const ui::PointerEvent ui_event(ui::MouseEvent(
1247 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 1339 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
1248 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1340 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1249 event_dispatcher()->ProcessEvent(ui_event); 1341 event_dispatcher()->ProcessEvent(ui_event,
1342 EventDispatcher::AcceleratorMatchPhase::ANY);
1250 1343
1251 std::unique_ptr<DispatchedEventDetails> details = 1344 std::unique_ptr<DispatchedEventDetails> details =
1252 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1345 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1253 ASSERT_TRUE(details); 1346 ASSERT_TRUE(details);
1254 ASSERT_EQ(child.get(), details->window); 1347 ASSERT_EQ(child.get(), details->window);
1255 1348
1256 EXPECT_TRUE(AreAnyPointersDown()); 1349 EXPECT_TRUE(AreAnyPointersDown());
1257 1350
1258 event_dispatcher()->Reset(); 1351 event_dispatcher()->Reset();
1259 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); 1352 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
(...skipping 22 matching lines...) Expand all
1282 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1375 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1283 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1376 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1284 1377
1285 w1->AddTransientWindow(w2.get()); 1378 w1->AddTransientWindow(w2.get());
1286 w2->SetModal(); 1379 w2->SetModal();
1287 1380
1288 // Send event that is over |w1|. 1381 // Send event that is over |w1|.
1289 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1382 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1290 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1383 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1291 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1384 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1292 event_dispatcher()->ProcessEvent(mouse_pressed); 1385 event_dispatcher()->ProcessEvent(mouse_pressed,
1386 EventDispatcher::AcceleratorMatchPhase::ANY);
1293 1387
1294 std::unique_ptr<DispatchedEventDetails> details = 1388 std::unique_ptr<DispatchedEventDetails> details =
1295 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1389 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1296 ASSERT_TRUE(details); 1390 ASSERT_TRUE(details);
1297 EXPECT_EQ(w2.get(), details->window); 1391 EXPECT_EQ(w2.get(), details->window);
1298 EXPECT_TRUE(details->IsNonclientArea()); 1392 EXPECT_TRUE(details->IsNonclientArea());
1299 1393
1300 ASSERT_TRUE(details->event); 1394 ASSERT_TRUE(details->event);
1301 ASSERT_TRUE(details->event->IsPointerEvent()); 1395 ASSERT_TRUE(details->event->IsPointerEvent());
1302 1396
(...skipping 11 matching lines...) Expand all
1314 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1408 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1315 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1409 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1316 1410
1317 w1->AddTransientWindow(w2.get()); 1411 w1->AddTransientWindow(w2.get());
1318 w2->SetModal(); 1412 w2->SetModal();
1319 1413
1320 // Send event that is over |w2|. 1414 // Send event that is over |w2|.
1321 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1415 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1322 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15), 1416 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15),
1323 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1417 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1324 event_dispatcher()->ProcessEvent(mouse_pressed); 1418 event_dispatcher()->ProcessEvent(mouse_pressed,
1419 EventDispatcher::AcceleratorMatchPhase::ANY);
1325 1420
1326 std::unique_ptr<DispatchedEventDetails> details = 1421 std::unique_ptr<DispatchedEventDetails> details =
1327 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1422 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1328 ASSERT_TRUE(details); 1423 ASSERT_TRUE(details);
1329 EXPECT_EQ(w2.get(), details->window); 1424 EXPECT_EQ(w2.get(), details->window);
1330 EXPECT_TRUE(details->IsClientArea()); 1425 EXPECT_TRUE(details->IsClientArea());
1331 1426
1332 ASSERT_TRUE(details->event); 1427 ASSERT_TRUE(details->event);
1333 ASSERT_TRUE(details->event->IsPointerEvent()); 1428 ASSERT_TRUE(details->event->IsPointerEvent());
1334 1429
(...skipping 14 matching lines...) Expand all
1349 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1444 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1350 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); 1445 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1351 1446
1352 w1->AddTransientWindow(w2.get()); 1447 w1->AddTransientWindow(w2.get());
1353 w2->SetModal(); 1448 w2->SetModal();
1354 1449
1355 // Send event that is over |w3|. 1450 // Send event that is over |w3|.
1356 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1451 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1357 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15), 1452 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15),
1358 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1453 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1359 event_dispatcher()->ProcessEvent(mouse_pressed); 1454 event_dispatcher()->ProcessEvent(mouse_pressed,
1455 EventDispatcher::AcceleratorMatchPhase::ANY);
1360 1456
1361 std::unique_ptr<DispatchedEventDetails> details = 1457 std::unique_ptr<DispatchedEventDetails> details =
1362 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1458 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1363 ASSERT_TRUE(details); 1459 ASSERT_TRUE(details);
1364 EXPECT_EQ(w3.get(), details->window); 1460 EXPECT_EQ(w3.get(), details->window);
1365 EXPECT_TRUE(details->IsClientArea()); 1461 EXPECT_TRUE(details->IsClientArea());
1366 1462
1367 ASSERT_TRUE(details->event); 1463 ASSERT_TRUE(details->event);
1368 ASSERT_TRUE(details->event->IsPointerEvent()); 1464 ASSERT_TRUE(details->event->IsPointerEvent());
1369 1465
(...skipping 15 matching lines...) Expand all
1385 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1481 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1386 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1482 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1387 1483
1388 w1->AddTransientWindow(w2.get()); 1484 w1->AddTransientWindow(w2.get());
1389 w2->SetModal(); 1485 w2->SetModal();
1390 1486
1391 // Send event that is over |w11|. 1487 // Send event that is over |w11|.
1392 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1488 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1393 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25), 1489 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25),
1394 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1490 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1395 event_dispatcher()->ProcessEvent(mouse_pressed); 1491 event_dispatcher()->ProcessEvent(mouse_pressed,
1492 EventDispatcher::AcceleratorMatchPhase::ANY);
1396 1493
1397 std::unique_ptr<DispatchedEventDetails> details = 1494 std::unique_ptr<DispatchedEventDetails> details =
1398 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1495 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1399 ASSERT_TRUE(details); 1496 ASSERT_TRUE(details);
1400 EXPECT_EQ(w2.get(), details->window); 1497 EXPECT_EQ(w2.get(), details->window);
1401 EXPECT_TRUE(details->IsNonclientArea()); 1498 EXPECT_TRUE(details->IsNonclientArea());
1402 1499
1403 ASSERT_TRUE(details->event); 1500 ASSERT_TRUE(details->event);
1404 ASSERT_TRUE(details->event->IsPointerEvent()); 1501 ASSERT_TRUE(details->event->IsPointerEvent());
1405 1502
1406 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1503 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1407 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); 1504 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
1408 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); 1505 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
1409 } 1506 }
1410 1507
1411 // Tests that events on a system modal window target the modal window itself. 1508 // Tests that events on a system modal window target the modal window itself.
1412 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) { 1509 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) {
1413 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1510 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1414 1511
1415 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1512 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1416 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1513 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1417 w1->SetModal(); 1514 w1->SetModal();
1418 1515
1419 // Send event that is over |w1|. 1516 // Send event that is over |w1|.
1420 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1517 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1421 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1518 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1422 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1519 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1423 event_dispatcher()->ProcessEvent(mouse_pressed); 1520 event_dispatcher()->ProcessEvent(mouse_pressed,
1521 EventDispatcher::AcceleratorMatchPhase::ANY);
1424 1522
1425 std::unique_ptr<DispatchedEventDetails> details = 1523 std::unique_ptr<DispatchedEventDetails> details =
1426 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1524 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1427 ASSERT_TRUE(details); 1525 ASSERT_TRUE(details);
1428 EXPECT_EQ(w1.get(), details->window); 1526 EXPECT_EQ(w1.get(), details->window);
1429 EXPECT_TRUE(details->IsClientArea()); 1527 EXPECT_TRUE(details->IsClientArea());
1430 1528
1431 ASSERT_TRUE(details->event); 1529 ASSERT_TRUE(details->event);
1432 ASSERT_TRUE(details->event->IsPointerEvent()); 1530 ASSERT_TRUE(details->event->IsPointerEvent());
1433 1531
1434 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1532 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1435 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); 1533 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
1436 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); 1534 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1437 } 1535 }
1438 1536
1439 // Tests that events outside of system modal window target the modal window. 1537 // Tests that events outside of system modal window target the modal window.
1440 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) { 1538 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) {
1441 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1539 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1442 1540
1443 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1541 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1444 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1542 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1445 w1->SetModal(); 1543 w1->SetModal();
1446 event_dispatcher()->AddSystemModalWindow(w1.get()); 1544 event_dispatcher()->AddSystemModalWindow(w1.get());
1447 1545
1448 // Send event that is over |w1|. 1546 // Send event that is over |w1|.
1449 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1547 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1450 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15), 1548 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
1451 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1549 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1452 event_dispatcher()->ProcessEvent(mouse_pressed); 1550 event_dispatcher()->ProcessEvent(mouse_pressed,
1551 EventDispatcher::AcceleratorMatchPhase::ANY);
1453 1552
1454 std::unique_ptr<DispatchedEventDetails> details = 1553 std::unique_ptr<DispatchedEventDetails> details =
1455 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1554 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1456 ASSERT_TRUE(details); 1555 ASSERT_TRUE(details);
1457 EXPECT_EQ(w1.get(), details->window); 1556 EXPECT_EQ(w1.get(), details->window);
1458 EXPECT_TRUE(details->IsNonclientArea()); 1557 EXPECT_TRUE(details->IsNonclientArea());
1459 1558
1460 ASSERT_TRUE(details->event); 1559 ASSERT_TRUE(details->event);
1461 ASSERT_TRUE(details->event->IsPointerEvent()); 1560 ASSERT_TRUE(details->event->IsPointerEvent());
1462 1561
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 1669
1571 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1670 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1572 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 1671 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
1573 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1672 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1574 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); 1673 w2->SetBounds(gfx::Rect(0, 0, 100, 100));
1575 1674
1576 // Send event that is over |w11|. 1675 // Send event that is over |w11|.
1577 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1676 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1578 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1677 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1579 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1678 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1580 event_dispatcher()->ProcessEvent(mouse_pressed); 1679 event_dispatcher()->ProcessEvent(mouse_pressed,
1680 EventDispatcher::AcceleratorMatchPhase::ANY);
1581 event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId); 1681 event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId);
1582 1682
1583 std::unique_ptr<DispatchedEventDetails> details = 1683 std::unique_ptr<DispatchedEventDetails> details =
1584 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1684 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1585 ASSERT_TRUE(details); 1685 ASSERT_TRUE(details);
1586 EXPECT_EQ(w11.get(), details->window); 1686 EXPECT_EQ(w11.get(), details->window);
1587 EXPECT_TRUE(details->IsClientArea()); 1687 EXPECT_TRUE(details->IsClientArea());
1588 1688
1589 // Move |w11| to |w2| and verify the mouse is still down, and |w11| has 1689 // Move |w11| to |w2| and verify the mouse is still down, and |w11| has
1590 // capture. 1690 // capture.
(...skipping 14 matching lines...) Expand all
1605 // The delegate can decide if it really wants to forward the event or not. 1705 // The delegate can decide if it really wants to forward the event or not.
1606 EXPECT_EQ(child.get(), 1706 EXPECT_EQ(child.get(),
1607 test_event_dispatcher_delegate()->lost_capture_window()); 1707 test_event_dispatcher_delegate()->lost_capture_window());
1608 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); 1708 EXPECT_EQ(child.get(), event_dispatcher()->capture_window());
1609 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); 1709 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id());
1610 } 1710 }
1611 1711
1612 } // namespace test 1712 } // namespace test
1613 } // namespace ws 1713 } // namespace ws
1614 } // namespace ui 1714 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/event_dispatcher_delegate.h ('k') | services/ui/ws/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698