| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 | 1694 |
| 1695 delete v1; | 1695 delete v1; |
| 1696 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1696 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1697 v2->SetBounds(5, 5, 10, 10); | 1697 v2->SetBounds(5, 5, 10, 10); |
| 1698 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1698 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1699 | 1699 |
| 1700 widget->SynthesizeMouseMoveEvent(); | 1700 widget->SynthesizeMouseMoveEvent(); |
| 1701 EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1701 EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 // No touch on desktop Mac. Tracked in http://crbug.com/445520. | |
| 1705 #if !defined(OS_MACOSX) || defined(USE_AURA) | |
| 1706 | |
| 1707 namespace { | 1704 namespace { |
| 1708 | 1705 |
| 1709 // ui::EventHandler which handles all mouse press events. | 1706 // ui::EventHandler which handles all mouse press events. |
| 1710 class MousePressEventConsumer : public ui::EventHandler { | 1707 class MousePressEventConsumer : public ui::EventHandler { |
| 1711 public: | 1708 public: |
| 1712 MousePressEventConsumer() {} | 1709 MousePressEventConsumer() {} |
| 1713 | 1710 |
| 1714 private: | 1711 private: |
| 1715 // ui::EventHandler: | 1712 // ui::EventHandler: |
| 1716 void OnMouseEvent(ui::MouseEvent* event) override { | 1713 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1717 if (event->type() == ui::ET_MOUSE_PRESSED) | 1714 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 1718 event->SetHandled(); | 1715 event->SetHandled(); |
| 1719 } | 1716 } |
| 1720 | 1717 |
| 1721 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer); | 1718 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer); |
| 1722 }; | 1719 }; |
| 1723 | 1720 |
| 1724 } // namespace | 1721 } // namespace |
| 1725 | 1722 |
| 1723 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
| 1724 #if !defined(OS_MACOSX) || defined(USE_AURA) |
| 1725 |
| 1726 // Test that mouse presses and mouse releases are dispatched normally when a | 1726 // Test that mouse presses and mouse releases are dispatched normally when a |
| 1727 // touch is down. | 1727 // touch is down. |
| 1728 TEST_F(WidgetTest, MouseEventDispatchWhileTouchIsDown) { | 1728 TEST_F(WidgetTest, MouseEventDispatchWhileTouchIsDown) { |
| 1729 Widget* widget = CreateTopLevelNativeWidget(); | 1729 Widget* widget = CreateTopLevelNativeWidget(); |
| 1730 widget->Show(); | 1730 widget->Show(); |
| 1731 widget->SetSize(gfx::Size(300, 300)); | 1731 widget->SetSize(gfx::Size(300, 300)); |
| 1732 | 1732 |
| 1733 EventCountView* event_count_view = new EventCountView(); | 1733 EventCountView* event_count_view = new EventCountView(); |
| 1734 event_count_view->SetBounds(0, 0, 300, 300); | 1734 event_count_view->SetBounds(0, 0, 300, 300); |
| 1735 widget->GetRootView()->AddChildView(event_count_view); | 1735 widget->GetRootView()->AddChildView(event_count_view); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1746 | 1746 |
| 1747 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 1747 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 1748 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED)); | 1748 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED)); |
| 1749 | 1749 |
| 1750 // For mus it's important we destroy the widget before the EventGenerator. | 1750 // For mus it's important we destroy the widget before the EventGenerator. |
| 1751 widget->CloseNow(); | 1751 widget->CloseNow(); |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 #endif // !defined(OS_MACOSX) || defined(USE_AURA) | 1754 #endif // !defined(OS_MACOSX) || defined(USE_AURA) |
| 1755 | 1755 |
| 1756 // Tests that when there is no active capture, that a mouse press causes capture |
| 1757 // to be set. |
| 1758 TEST_F(WidgetTest, MousePressCausesCapture) { |
| 1759 Widget* widget = CreateTopLevelNativeWidget(); |
| 1760 widget->Show(); |
| 1761 widget->SetSize(gfx::Size(300, 300)); |
| 1762 |
| 1763 EventCountView* event_count_view = new EventCountView(); |
| 1764 event_count_view->SetBounds(0, 0, 300, 300); |
| 1765 widget->GetRootView()->AddChildView(event_count_view); |
| 1766 |
| 1767 // No capture has been set. |
| 1768 EXPECT_EQ(nullptr, |
| 1769 internal::NativeWidgetPrivate::GetCapture(widget->GetNativeView())); |
| 1770 |
| 1771 MousePressEventConsumer consumer; |
| 1772 event_count_view->AddPostTargetHandler(&consumer); |
| 1773 std::unique_ptr<ui::test::EventGenerator> generator( |
| 1774 new ui::test::EventGenerator( |
| 1775 IsMus() ? widget->GetNativeWindow() : GetContext(), |
| 1776 widget->GetNativeWindow())); |
| 1777 generator->PressLeftButton(); |
| 1778 |
| 1779 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 1780 EXPECT_EQ(widget->GetNativeView(), |
| 1781 internal::NativeWidgetPrivate::GetCapture(widget->GetNativeView())); |
| 1782 |
| 1783 // For mus it's important we destroy the widget before the EventGenerator. |
| 1784 widget->CloseNow(); |
| 1785 } |
| 1786 |
| 1787 namespace { |
| 1788 |
| 1789 // An EventHandler which shows a Wiget upon receiving a mouse event. The Widget |
| 1790 // proceeds to take capture. |
| 1791 class CaptureEventConsumer : public ui::EventHandler { |
| 1792 public: |
| 1793 CaptureEventConsumer(Widget* widget) |
| 1794 : event_count_view_(new EventCountView()), widget_(widget) {} |
| 1795 ~CaptureEventConsumer() override { widget_->CloseNow(); } |
| 1796 |
| 1797 private: |
| 1798 // ui::EventHandler: |
| 1799 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1800 if (event->type() == ui::ET_MOUSE_PRESSED) { |
| 1801 event->SetHandled(); |
| 1802 widget_->Show(); |
| 1803 widget_->SetSize(gfx::Size(200, 200)); |
| 1804 |
| 1805 event_count_view_->SetBounds(0, 0, 200, 200); |
| 1806 widget_->GetRootView()->AddChildView(event_count_view_); |
| 1807 widget_->SetCapture(event_count_view_); |
| 1808 } |
| 1809 } |
| 1810 |
| 1811 EventCountView* event_count_view_; |
| 1812 Widget* widget_; |
| 1813 DISALLOW_COPY_AND_ASSIGN(CaptureEventConsumer); |
| 1814 }; |
| 1815 |
| 1816 } // namespace |
| 1817 |
| 1818 // Tests that if explicit capture occurs during a mouse press, that implicit |
| 1819 // capture is not applied. |
| 1820 TEST_F(WidgetTest, CaptureDuringMousePressNotOverridden) { |
| 1821 Widget* widget = CreateTopLevelNativeWidget(); |
| 1822 widget->Show(); |
| 1823 widget->SetSize(gfx::Size(300, 300)); |
| 1824 |
| 1825 EventCountView* event_count_view = new EventCountView(); |
| 1826 event_count_view->SetBounds(0, 0, 300, 300); |
| 1827 widget->GetRootView()->AddChildView(event_count_view); |
| 1828 |
| 1829 EXPECT_EQ(nullptr, |
| 1830 internal::NativeWidgetPrivate::GetCapture(widget->GetNativeView())); |
| 1831 |
| 1832 Widget* widget2 = CreateTopLevelNativeWidget(); |
| 1833 // Gives explicit capture to |widget2| |
| 1834 CaptureEventConsumer consumer(widget2); |
| 1835 event_count_view->AddPostTargetHandler(&consumer); |
| 1836 std::unique_ptr<ui::test::EventGenerator> generator( |
| 1837 new ui::test::EventGenerator( |
| 1838 IsMus() ? widget->GetNativeWindow() : GetContext(), |
| 1839 widget->GetNativeWindow())); |
| 1840 // This event should implicitly give capture to |widget|, except that |
| 1841 // |consumer| will explicitly set capture on |widget2|. |
| 1842 generator->PressLeftButton(); |
| 1843 |
| 1844 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 1845 EXPECT_NE(widget->GetNativeView(), |
| 1846 internal::NativeWidgetPrivate::GetCapture(widget->GetNativeView())); |
| 1847 EXPECT_EQ(widget2->GetNativeView(), |
| 1848 internal::NativeWidgetPrivate::GetCapture(widget->GetNativeView())); |
| 1849 |
| 1850 // For mus it's important we destroy the widget before the EventGenerator. |
| 1851 widget->CloseNow(); |
| 1852 } |
| 1853 |
| 1756 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget | 1854 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget |
| 1757 // is closed. | 1855 // is closed. |
| 1758 TEST_F(WidgetTest, SingleWindowClosing) { | 1856 TEST_F(WidgetTest, SingleWindowClosing) { |
| 1759 TestDesktopWidgetDelegate delegate; | 1857 TestDesktopWidgetDelegate delegate; |
| 1760 delegate.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW)); | 1858 delegate.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW)); |
| 1761 EXPECT_EQ(0, delegate.window_closing_count()); | 1859 EXPECT_EQ(0, delegate.window_closing_count()); |
| 1762 delegate.GetWidget()->CloseNow(); | 1860 delegate.GetWidget()->CloseNow(); |
| 1763 EXPECT_EQ(1, delegate.window_closing_count()); | 1861 EXPECT_EQ(1, delegate.window_closing_count()); |
| 1764 } | 1862 } |
| 1765 | 1863 |
| (...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3515 // Moving the child to a different widget should call the removals observer. | 3613 // Moving the child to a different widget should call the removals observer. |
| 3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); | 3614 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); |
| 3517 widget2->client_view()->AddChildView(child); | 3615 widget2->client_view()->AddChildView(child); |
| 3518 EXPECT_TRUE(removals_observer.DidRemoveView(child)); | 3616 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
| 3519 | 3617 |
| 3520 widget->RemoveRemovalsObserver(&removals_observer); | 3618 widget->RemoveRemovalsObserver(&removals_observer); |
| 3521 } | 3619 } |
| 3522 | 3620 |
| 3523 } // namespace test | 3621 } // namespace test |
| 3524 } // namespace views | 3622 } // namespace views |
| OLD | NEW |