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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2681613002: Avoid two targeting phases in aura client-lib and EventProcessor. (Closed)
Patch Set: early return Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/aura_test_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/aura/mus/capture_synchronizer.h" 24 #include "ui/aura/mus/capture_synchronizer.h"
25 #include "ui/aura/mus/property_converter.h" 25 #include "ui/aura/mus/property_converter.h"
26 #include "ui/aura/mus/window_mus.h" 26 #include "ui/aura/mus/window_mus.h"
27 #include "ui/aura/mus/window_tree_client_delegate.h" 27 #include "ui/aura/mus/window_tree_client_delegate.h"
28 #include "ui/aura/mus/window_tree_client_observer.h" 28 #include "ui/aura/mus/window_tree_client_observer.h"
29 #include "ui/aura/mus/window_tree_host_mus.h" 29 #include "ui/aura/mus/window_tree_host_mus.h"
30 #include "ui/aura/test/aura_mus_test_base.h" 30 #include "ui/aura/test/aura_mus_test_base.h"
31 #include "ui/aura/test/mus/test_window_tree.h" 31 #include "ui/aura/test/mus/test_window_tree.h"
32 #include "ui/aura/test/mus/window_tree_client_private.h" 32 #include "ui/aura/test/mus/window_tree_client_private.h"
33 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
34 #include "ui/aura/test/test_window_targeter.h"
34 #include "ui/aura/window.h" 35 #include "ui/aura/window.h"
36 #include "ui/aura/window_targeter.h"
35 #include "ui/aura/window_tracker.h" 37 #include "ui/aura/window_tracker.h"
36 #include "ui/aura/window_tree_host_observer.h" 38 #include "ui/aura/window_tree_host_observer.h"
37 #include "ui/base/class_property.h" 39 #include "ui/base/class_property.h"
38 #include "ui/compositor/compositor.h" 40 #include "ui/compositor/compositor.h"
39 #include "ui/display/display.h" 41 #include "ui/display/display.h"
40 #include "ui/display/display_switches.h" 42 #include "ui/display/display_switches.h"
41 #include "ui/display/screen.h" 43 #include "ui/display/screen.h"
42 #include "ui/events/event.h" 44 #include "ui/events/event.h"
43 #include "ui/events/event_utils.h" 45 #include "ui/events/event_utils.h"
44 #include "ui/gfx/geometry/dip_util.h" 46 #include "ui/gfx/geometry/dip_util.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // Simulate server changing back to original visible. Should take immediately. 494 // Simulate server changing back to original visible. Should take immediately.
493 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()), 495 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()),
494 original_visible); 496 original_visible);
495 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); 497 EXPECT_EQ(original_visible, root_window()->TargetVisibility());
496 } 498 }
497 499
498 namespace { 500 namespace {
499 501
500 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { 502 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
501 public: 503 public:
502 static uint32_t constexpr kEventId = 1;
503
504 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) 504 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree)
505 : test_window_tree_(test_window_tree) {} 505 : test_window_tree_(test_window_tree) {}
506 ~InputEventBasicTestWindowDelegate() override {} 506 ~InputEventBasicTestWindowDelegate() override {}
507 507
508 bool got_move() const { return got_move_; } 508 bool got_move() const { return got_move_; }
509 bool was_acked() const { return was_acked_; } 509 bool was_acked() const { return was_acked_; }
510 const gfx::Point& last_event_location() const { return last_event_location_; } 510 const gfx::Point& last_event_location() const { return last_event_location_; }
511 void set_event_id(uint32_t event_id) { event_id_ = event_id; }
511 512
512 // TestWindowDelegate:: 513 // TestWindowDelegate::
513 void OnMouseEvent(ui::MouseEvent* event) override { 514 void OnMouseEvent(ui::MouseEvent* event) override {
514 was_acked_ = test_window_tree_->WasEventAcked(kEventId); 515 was_acked_ = test_window_tree_->WasEventAcked(event_id_);
515 if (event->type() == ui::ET_MOUSE_MOVED) 516 if (event->type() == ui::ET_MOUSE_MOVED)
516 got_move_ = true; 517 got_move_ = true;
517 last_event_location_ = event->location(); 518 last_event_location_ = event->location();
518 event->SetHandled(); 519 event->SetHandled();
519 } 520 }
520 521
522 void reset() {
523 was_acked_ = false;
524 got_move_ = false;
525 last_event_location_ = gfx::Point();
526 event_id_ = 0;
527 }
528
521 private: 529 private:
522 TestWindowTree* test_window_tree_; 530 TestWindowTree* test_window_tree_;
523 bool was_acked_ = false; 531 bool was_acked_ = false;
524 bool got_move_ = false; 532 bool got_move_ = false;
525 gfx::Point last_event_location_; 533 gfx::Point last_event_location_;
534 uint32_t event_id_ = 0;
526 535
527 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); 536 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
528 }; 537 };
529 538
530 } // namespace 539 } // namespace
531 540
532 TEST_F(WindowTreeClientClientTest, InputEventBasic) { 541 TEST_F(WindowTreeClientClientTest, InputEventBasic) {
533 InputEventBasicTestWindowDelegate window_delegate(window_tree()); 542 InputEventBasicTestWindowDelegate window_delegate(window_tree());
534 WindowTreeHostMus window_tree_host(window_tree_client_impl()); 543 WindowTreeHostMus window_tree_host(window_tree_client_impl());
535 Window* top_level = window_tree_host.window(); 544 Window* top_level = window_tree_host.window();
536 const gfx::Rect bounds(0, 0, 100, 100); 545 const gfx::Rect bounds(0, 0, 100, 100);
537 window_tree_host.SetBoundsInPixels(bounds); 546 window_tree_host.SetBoundsInPixels(bounds);
538 window_tree_host.InitHost(); 547 window_tree_host.InitHost();
539 window_tree_host.Show(); 548 window_tree_host.Show();
540 EXPECT_EQ(bounds, top_level->bounds()); 549 EXPECT_EQ(bounds, top_level->bounds());
541 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); 550 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
542 Window child(&window_delegate); 551 Window child(&window_delegate);
543 child.Init(ui::LAYER_NOT_DRAWN); 552 child.Init(ui::LAYER_NOT_DRAWN);
544 top_level->AddChild(&child); 553 top_level->AddChild(&child);
545 child.SetBounds(gfx::Rect(10, 10, 100, 100)); 554 child.SetBounds(gfx::Rect(10, 10, 100, 100));
546 child.Show(); 555 child.Show();
547 EXPECT_FALSE(window_delegate.got_move()); 556 EXPECT_FALSE(window_delegate.got_move());
548 EXPECT_FALSE(window_delegate.was_acked()); 557 EXPECT_FALSE(window_delegate.was_acked());
549 const gfx::Point event_location_in_child(2, 3); 558 const gfx::Point event_location_in_child(2, 3);
559 const uint32_t event_id = 1;
560 window_delegate.set_event_id(event_id);
550 std::unique_ptr<ui::Event> ui_event( 561 std::unique_ptr<ui::Event> ui_event(
551 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, 562 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child,
552 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); 563 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0));
553 window_tree_client()->OnWindowInputEvent( 564 window_tree_client()->OnWindowInputEvent(
554 InputEventBasicTestWindowDelegate::kEventId, server_id(&child), 565 event_id, server_id(&child), window_tree_host.display_id(),
555 window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); 566 ui::Event::Clone(*ui_event.get()), 0);
556 EXPECT_TRUE(window_tree()->WasEventAcked( 567 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
557 InputEventBasicTestWindowDelegate::kEventId)); 568 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
558 EXPECT_EQ(ui::mojom::EventResult::HANDLED, 569 window_tree()->GetEventResult(event_id));
559 window_tree()->GetEventResult(
560 InputEventBasicTestWindowDelegate::kEventId));
561 EXPECT_TRUE(window_delegate.got_move()); 570 EXPECT_TRUE(window_delegate.got_move());
562 EXPECT_FALSE(window_delegate.was_acked()); 571 EXPECT_FALSE(window_delegate.was_acked());
563 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); 572 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location());
564 } 573 }
565 574
575 TEST_F(WindowTreeClientClientTest, InputEventFindTargetAndConversion) {
576 WindowTreeHostMus window_tree_host(window_tree_client_impl());
577 Window* top_level = window_tree_host.window();
578 const gfx::Rect bounds(0, 0, 100, 100);
579 window_tree_host.SetBoundsInPixels(bounds);
580 window_tree_host.InitHost();
581 window_tree_host.Show();
582 EXPECT_EQ(bounds, top_level->bounds());
583 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
584 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
585 Window child1(&window_delegate1);
586 child1.Init(ui::LAYER_NOT_DRAWN);
587 child1.SetEventTargeter(base::MakeUnique<WindowTargeter>());
588 top_level->AddChild(&child1);
589 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
590 child1.Show();
591 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
592 Window child2(&window_delegate2);
593 child2.Init(ui::LAYER_NOT_DRAWN);
594 child1.AddChild(&child2);
595 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
596 child2.Show();
597
598 EXPECT_FALSE(window_delegate1.got_move());
599 EXPECT_FALSE(window_delegate2.got_move());
600
601 // child1 has a targeter set and event_location is (50, 60), child2
602 // should get the event even though mus-ws wants to send to child1.
603 const gfx::Point event_location(50, 60);
604 uint32_t event_id = 1;
605 window_delegate1.set_event_id(event_id);
606 window_delegate2.set_event_id(event_id);
607 std::unique_ptr<ui::Event> ui_event(
608 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
609 ui::EventTimeForNow(), ui::EF_NONE, 0));
610 window_tree_client()->OnWindowInputEvent(
611 event_id, server_id(&child1), window_tree_host.display_id(),
612 ui::Event::Clone(*ui_event.get()), 0);
613 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
614 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
615 window_tree()->GetEventResult(event_id));
616 EXPECT_FALSE(window_delegate1.got_move());
617 EXPECT_TRUE(window_delegate2.got_move());
618 EXPECT_EQ(gfx::Point(30, 30), window_delegate2.last_event_location());
619 window_delegate1.reset();
620 window_delegate2.reset();
621
622 // Remove the targeter for child1 and specify the event to go to child1. This
623 // time child1 should receive the event not child2.
624 child1.SetEventTargeter(nullptr);
625 event_id = 2;
626 window_delegate1.set_event_id(event_id);
627 window_delegate2.set_event_id(event_id);
628 std::unique_ptr<ui::Event> ui_event1(
629 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
630 ui::EventTimeForNow(), ui::EF_NONE, 0));
631 window_tree_client()->OnWindowInputEvent(
632 event_id, server_id(&child1), window_tree_host.display_id(),
633 ui::Event::Clone(*ui_event1.get()), 0);
634 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
635 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
636 window_tree()->GetEventResult(event_id));
637 EXPECT_TRUE(window_delegate1.got_move());
638 EXPECT_FALSE(window_delegate2.got_move());
639 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location());
640 }
641
642 TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) {
643 WindowTreeHostMus window_tree_host(window_tree_client_impl());
644 Window* top_level = window_tree_host.window();
645 const gfx::Rect bounds(0, 0, 100, 100);
646 window_tree_host.SetBoundsInPixels(bounds);
647 window_tree_host.InitHost();
648 window_tree_host.Show();
649 EXPECT_EQ(bounds, top_level->bounds());
650 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
651 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
652 Window child1(&window_delegate1);
653 child1.Init(ui::LAYER_NOT_DRAWN);
654 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>());
655 top_level->AddChild(&child1);
656 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
657 child1.Show();
658 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
659 Window child2(&window_delegate2);
660 child2.Init(ui::LAYER_NOT_DRAWN);
661 child1.AddChild(&child2);
662 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
663 child2.Show();
664
665 EXPECT_FALSE(window_delegate1.got_move());
666 EXPECT_FALSE(window_delegate2.got_move());
667
668 // child1 has a custom targeter set which would always return itself as the
669 // target window therefore event should go to child1 unlike
670 // WindowTreeClientClientTest.InputEventFindTargetAndConversion.
671 const gfx::Point event_location(50, 60);
672 uint32_t event_id = 1;
673 window_delegate1.set_event_id(event_id);
674 window_delegate2.set_event_id(event_id);
675 std::unique_ptr<ui::Event> ui_event(
676 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
677 ui::EventTimeForNow(), ui::EF_NONE, 0));
678 window_tree_client()->OnWindowInputEvent(
679 event_id, server_id(&child1), window_tree_host.display_id(),
680 ui::Event::Clone(*ui_event.get()), 0);
681 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
682 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
683 window_tree()->GetEventResult(event_id));
684 EXPECT_TRUE(window_delegate1.got_move());
685 EXPECT_FALSE(window_delegate2.got_move());
686 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location());
687 window_delegate1.reset();
688 window_delegate2.reset();
689
690 // child1 should get the event even though mus-ws specifies child2 and it's
691 // actually in child2's space. Event location will be transformed.
692 event_id = 2;
693 window_delegate1.set_event_id(event_id);
694 window_delegate2.set_event_id(event_id);
695 window_tree_client()->OnWindowInputEvent(
696 event_id, server_id(&child2), window_tree_host.display_id(),
697 ui::Event::Clone(*ui_event.get()), 0);
698 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
699 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
700 window_tree()->GetEventResult(event_id));
701 EXPECT_TRUE(window_delegate1.got_move());
702 EXPECT_FALSE(window_delegate2.got_move());
703 EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location());
704 }
705
706 TEST_F(WindowTreeClientClientTest, InputEventCaptureWindow) {
707 std::unique_ptr<WindowTreeHostMus> window_tree_host =
708 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl());
709 Window* top_level = window_tree_host->window();
710 const gfx::Rect bounds(0, 0, 100, 100);
711 window_tree_host->SetBoundsInPixels(bounds);
712 window_tree_host->InitHost();
713 window_tree_host->Show();
714 EXPECT_EQ(bounds, top_level->bounds());
715 EXPECT_EQ(bounds, window_tree_host->GetBoundsInPixels());
716 std::unique_ptr<InputEventBasicTestWindowDelegate> window_delegate1(
717 base::MakeUnique<InputEventBasicTestWindowDelegate>(window_tree()));
718 std::unique_ptr<Window> child1(
719 base::MakeUnique<Window>(window_delegate1.get()));
720 child1->Init(ui::LAYER_NOT_DRAWN);
721 child1->SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>());
722 top_level->AddChild(child1.get());
723 child1->SetBounds(gfx::Rect(10, 10, 100, 100));
724 child1->Show();
725 std::unique_ptr<InputEventBasicTestWindowDelegate> window_delegate2(
726 base::MakeUnique<InputEventBasicTestWindowDelegate>(window_tree()));
727 std::unique_ptr<Window> child2(
728 base::MakeUnique<Window>(window_delegate2.get()));
729 child2->Init(ui::LAYER_NOT_DRAWN);
730 child1->AddChild(child2.get());
731 child2->SetBounds(gfx::Rect(20, 30, 100, 100));
732 child2->Show();
733
734 EXPECT_FALSE(window_delegate1->got_move());
735 EXPECT_FALSE(window_delegate2->got_move());
736
737 // child1 has a custom targeter set which would always return itself as the
738 // target window therefore event should go to child1.
739 const gfx::Point event_location(50, 60);
740 uint32_t event_id = 1;
741 window_delegate1->set_event_id(event_id);
742 window_delegate2->set_event_id(event_id);
743 std::unique_ptr<ui::Event> ui_event(
744 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
745 ui::EventTimeForNow(), ui::EF_NONE, 0));
746 window_tree_client()->OnWindowInputEvent(
747 event_id, server_id(child1.get()), window_tree_host->display_id(),
748 ui::Event::Clone(*ui_event.get()), 0);
749 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
750 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
751 window_tree()->GetEventResult(event_id));
752 EXPECT_TRUE(window_delegate1->got_move());
753 EXPECT_FALSE(window_delegate2->got_move());
754 EXPECT_EQ(gfx::Point(50, 60), window_delegate1->last_event_location());
755 window_delegate1->reset();
756 window_delegate2->reset();
757
758 // The same event should go to child2 if child2 is the capture window.
759 std::unique_ptr<client::DefaultCaptureClient> capture_client(
760 base::MakeUnique<client::DefaultCaptureClient>());
761 client::SetCaptureClient(top_level, capture_client.get());
762 child2->SetCapture();
763 EXPECT_EQ(child2.get(), client::GetCaptureWindow(child2->GetRootWindow()));
764 event_id = 2;
765 window_delegate1->set_event_id(event_id);
766 window_delegate2->set_event_id(event_id);
767 window_tree_client()->OnWindowInputEvent(
768 event_id, server_id(child1.get()), window_tree_host->display_id(),
769 ui::Event::Clone(*ui_event.get()), 0);
770 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
771 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
772 window_tree()->GetEventResult(event_id));
773 EXPECT_FALSE(window_delegate1->got_move());
774 EXPECT_TRUE(window_delegate2->got_move());
775 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location());
776 child2.reset();
777 child1.reset();
778 window_tree_host.reset();
779 capture_client.reset();
780 }
781
566 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { 782 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
567 public: 783 public:
568 WindowTreeClientPointerObserverTest() {} 784 WindowTreeClientPointerObserverTest() {}
569 ~WindowTreeClientPointerObserverTest() override {} 785 ~WindowTreeClientPointerObserverTest() override {}
570 786
571 void DeleteLastEventObserved() { last_event_observed_.reset(); } 787 void DeleteLastEventObserved() { last_event_observed_.reset(); }
572 const ui::PointerEvent* last_event_observed() const { 788 const ui::PointerEvent* last_event_observed() const {
573 return last_event_observed_.get(); 789 return last_event_observed_.get();
574 } 790 }
575 791
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); 1803 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
1588 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 1804 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
1589 display_id, true); 1805 display_id, true);
1590 1806
1591 // aura::Window should operate in DIP and aura::WindowTreeHost should operate 1807 // aura::Window should operate in DIP and aura::WindowTreeHost should operate
1592 // in pixels. 1808 // in pixels.
1593 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); 1809 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
1594 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); 1810 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels());
1595 } 1811 }
1596 1812
1597 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDips) { 1813 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDip) {
1598 display::Screen* screen = display::Screen::GetScreen(); 1814 display::Screen* screen = display::Screen::GetScreen();
1599 const display::Display primary_display = screen->GetPrimaryDisplay(); 1815 const display::Display primary_display = screen->GetPrimaryDisplay();
1600 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); 1816 ASSERT_EQ(2.0f, primary_display.device_scale_factor());
1601 1817
1602 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); 1818 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
1603 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); 1819 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
1604 top_level->Init(ui::LAYER_NOT_DRAWN); 1820 top_level->Init(ui::LAYER_NOT_DRAWN);
1605 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); 1821 top_level->SetBounds(gfx::Rect(0, 0, 100, 100));
1606 top_level->Show(); 1822 top_level->Show();
1607 1823
(...skipping 13 matching lines...) Expand all
1621 1837
1622 // Delegate received the event in Dips. 1838 // Delegate received the event in Dips.
1623 const ui::PointerEvent* last_event = last_event_observed(); 1839 const ui::PointerEvent* last_event = last_event_observed();
1624 ASSERT_TRUE(last_event); 1840 ASSERT_TRUE(last_event);
1625 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), 1841 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels),
1626 last_event->location()); 1842 last_event->location());
1627 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), 1843 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels),
1628 last_event->root_location()); 1844 last_event->root_location());
1629 } 1845 }
1630 1846
1847 TEST_F(WindowTreeClientClientTestHighDPI, InputEventsInDip) {
1848 WindowTreeHostMus window_tree_host(window_tree_client_impl());
1849 display::Screen* screen = display::Screen::GetScreen();
1850 display::Display display;
1851 ASSERT_TRUE(
1852 screen->GetDisplayWithDisplayId(window_tree_host.display_id(), &display));
1853 ASSERT_EQ(2.0f, display.device_scale_factor());
1854
1855 Window* top_level = window_tree_host.window();
1856 const gfx::Rect bounds_in_pixels(0, 0, 100, 100);
1857 window_tree_host.SetBoundsInPixels(bounds_in_pixels);
1858 window_tree_host.InitHost();
1859 window_tree_host.Show();
1860 EXPECT_EQ(gfx::ConvertRectToDIP(2.0f, bounds_in_pixels), top_level->bounds());
1861 EXPECT_EQ(bounds_in_pixels, window_tree_host.GetBoundsInPixels());
1862
1863 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
1864 Window child1(&window_delegate1);
1865 child1.Init(ui::LAYER_NOT_DRAWN);
1866 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>());
1867 top_level->AddChild(&child1);
1868 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
1869 child1.Show();
1870 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
1871 Window child2(&window_delegate2);
1872 child2.Init(ui::LAYER_NOT_DRAWN);
1873 child1.AddChild(&child2);
1874 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
1875 child2.Show();
1876
1877 EXPECT_FALSE(window_delegate1.got_move());
1878 EXPECT_FALSE(window_delegate2.got_move());
1879
1880 // child1 has a custom targeter set which would always return itself as the
1881 // target window therefore event should go to child1 and should be in dip.
1882 const gfx::Point event_location_in_pixels(50, 60);
1883 uint32_t event_id = 1;
1884 window_delegate1.set_event_id(event_id);
1885 window_delegate2.set_event_id(event_id);
1886 std::unique_ptr<ui::Event> ui_event(
1887 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_pixels,
1888 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0));
1889 window_tree_client()->OnWindowInputEvent(
1890 event_id, server_id(&child1), window_tree_host.display_id(),
1891 ui::Event::Clone(*ui_event.get()), 0);
1892 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1893 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
1894 window_tree()->GetEventResult(event_id));
1895 EXPECT_TRUE(window_delegate1.got_move());
1896 EXPECT_FALSE(window_delegate2.got_move());
1897 const gfx::Point event_location_in_dip(25, 30);
1898 EXPECT_EQ(event_location_in_dip, window_delegate1.last_event_location());
1899 window_delegate1.reset();
1900 window_delegate2.reset();
1901
1902 // Event location will be transformed and should be in dip.
1903 event_id = 2;
1904 window_delegate1.set_event_id(event_id);
1905 window_delegate2.set_event_id(event_id);
1906 window_tree_client()->OnWindowInputEvent(
1907 event_id, server_id(&child2), window_tree_host.display_id(),
1908 ui::Event::Clone(*ui_event.get()), 0);
1909 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1910 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
1911 window_tree()->GetEventResult(event_id));
1912 EXPECT_TRUE(window_delegate1.got_move());
1913 EXPECT_FALSE(window_delegate2.got_move());
1914 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20,
1915 event_location_in_dip.y() + 30);
1916 EXPECT_EQ(transformed_event_location_in_dip,
1917 window_delegate1.last_event_location());
1918 }
1919
1631 } // namespace aura 1920 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/aura_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698