| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 // A View that closes the Widget and exits the current message-loop when it | 41 // A View that closes the Widget and exits the current message-loop when it |
| 42 // receives a mouse-release event. | 42 // receives a mouse-release event. |
| 43 class ExitLoopOnRelease : public View { | 43 class ExitLoopOnRelease : public View { |
| 44 public: | 44 public: |
| 45 ExitLoopOnRelease() {} | 45 ExitLoopOnRelease() {} |
| 46 virtual ~ExitLoopOnRelease() {} | 46 virtual ~ExitLoopOnRelease() {} |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // Overridden from View: | 49 // Overridden from View: |
| 50 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { | 50 virtual void OnMouseReleased(const ui::MouseEvent& event) override { |
| 51 GetWidget()->Close(); | 51 GetWidget()->Close(); |
| 52 base::MessageLoop::current()->QuitNow(); | 52 base::MessageLoop::current()->QuitNow(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); | 55 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // A view that does a capture on ui::ET_GESTURE_TAP_DOWN events. | 58 // A view that does a capture on ui::ET_GESTURE_TAP_DOWN events. |
| 59 class GestureCaptureView : public View { | 59 class GestureCaptureView : public View { |
| 60 public: | 60 public: |
| 61 GestureCaptureView() {} | 61 GestureCaptureView() {} |
| 62 virtual ~GestureCaptureView() {} | 62 virtual ~GestureCaptureView() {} |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // Overridden from View: | 65 // Overridden from View: |
| 66 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 66 virtual void OnGestureEvent(ui::GestureEvent* event) override { |
| 67 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 67 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 68 GetWidget()->SetCapture(this); | 68 GetWidget()->SetCapture(this); |
| 69 event->StopPropagation(); | 69 event->StopPropagation(); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); | 73 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // A view that always processes all mouse events. | 76 // A view that always processes all mouse events. |
| 77 class MouseView : public View { | 77 class MouseView : public View { |
| 78 public: | 78 public: |
| 79 MouseView() | 79 MouseView() |
| 80 : View(), | 80 : View(), |
| 81 entered_(0), | 81 entered_(0), |
| 82 exited_(0), | 82 exited_(0), |
| 83 pressed_(0) { | 83 pressed_(0) { |
| 84 } | 84 } |
| 85 virtual ~MouseView() {} | 85 virtual ~MouseView() {} |
| 86 | 86 |
| 87 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | 87 virtual bool OnMousePressed(const ui::MouseEvent& event) override { |
| 88 pressed_++; | 88 pressed_++; |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { | 92 virtual void OnMouseEntered(const ui::MouseEvent& event) override { |
| 93 entered_++; | 93 entered_++; |
| 94 } | 94 } |
| 95 | 95 |
| 96 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { | 96 virtual void OnMouseExited(const ui::MouseEvent& event) override { |
| 97 exited_++; | 97 exited_++; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Return the number of OnMouseEntered calls and reset the counter. | 100 // Return the number of OnMouseEntered calls and reset the counter. |
| 101 int EnteredCalls() { | 101 int EnteredCalls() { |
| 102 int i = entered_; | 102 int i = entered_; |
| 103 entered_ = 0; | 103 entered_ = 0; |
| 104 return i; | 104 return i; |
| 105 } | 105 } |
| 106 | 106 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 124 | 124 |
| 125 // A View that shows a different widget, sets capture on that widget, and | 125 // A View that shows a different widget, sets capture on that widget, and |
| 126 // initiates a nested message-loop when it receives a mouse-press event. | 126 // initiates a nested message-loop when it receives a mouse-press event. |
| 127 class NestedLoopCaptureView : public View { | 127 class NestedLoopCaptureView : public View { |
| 128 public: | 128 public: |
| 129 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {} | 129 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {} |
| 130 virtual ~NestedLoopCaptureView() {} | 130 virtual ~NestedLoopCaptureView() {} |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 // Overridden from View: | 133 // Overridden from View: |
| 134 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | 134 virtual bool OnMousePressed(const ui::MouseEvent& event) override { |
| 135 // Start a nested loop. | 135 // Start a nested loop. |
| 136 widget_->Show(); | 136 widget_->Show(); |
| 137 widget_->SetCapture(widget_->GetContentsView()); | 137 widget_->SetCapture(widget_->GetContentsView()); |
| 138 EXPECT_TRUE(widget_->HasCapture()); | 138 EXPECT_TRUE(widget_->HasCapture()); |
| 139 | 139 |
| 140 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 140 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 141 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 141 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 142 | 142 |
| 143 base::RunLoop run_loop; | 143 base::RunLoop run_loop; |
| 144 run_loop.Run(); | 144 run_loop.Run(); |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 Widget* widget_; | 148 Widget* widget_; |
| 149 | 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView); | 150 DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView); |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 class WidgetTestInteractive : public WidgetTest { | 155 class WidgetTestInteractive : public WidgetTest { |
| 156 public: | 156 public: |
| 157 WidgetTestInteractive() {} | 157 WidgetTestInteractive() {} |
| 158 virtual ~WidgetTestInteractive() {} | 158 virtual ~WidgetTestInteractive() {} |
| 159 | 159 |
| 160 virtual void SetUp() OVERRIDE { | 160 virtual void SetUp() override { |
| 161 gfx::GLSurface::InitializeOneOffForTests(); | 161 gfx::GLSurface::InitializeOneOffForTests(); |
| 162 ui::RegisterPathProvider(); | 162 ui::RegisterPathProvider(); |
| 163 base::FilePath ui_test_pak_path; | 163 base::FilePath ui_test_pak_path; |
| 164 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | 164 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
| 165 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 165 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
| 166 WidgetTest::SetUp(); | 166 WidgetTest::SetUp(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 protected: | 169 protected: |
| 170 static void ShowQuickMenuImmediately( | 170 static void ShowQuickMenuImmediately( |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // active. Previously we would activate the widget in the WM_NCACTIVATE | 580 // active. Previously we would activate the widget in the WM_NCACTIVATE |
| 581 // message which is incorrect because APIs like FlashWindowEx flash the | 581 // message which is incorrect because APIs like FlashWindowEx flash the |
| 582 // window caption by sending fake WM_NCACTIVATE messages. | 582 // window caption by sending fake WM_NCACTIVATE messages. |
| 583 class WidgetActivationTest : public Widget { | 583 class WidgetActivationTest : public Widget { |
| 584 public: | 584 public: |
| 585 WidgetActivationTest() | 585 WidgetActivationTest() |
| 586 : active_(false) {} | 586 : active_(false) {} |
| 587 | 587 |
| 588 virtual ~WidgetActivationTest() {} | 588 virtual ~WidgetActivationTest() {} |
| 589 | 589 |
| 590 virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE { | 590 virtual void OnNativeWidgetActivationChanged(bool active) override { |
| 591 active_ = active; | 591 active_ = active; |
| 592 } | 592 } |
| 593 | 593 |
| 594 bool active() const { return active_; } | 594 bool active() const { return active_; } |
| 595 | 595 |
| 596 private: | 596 private: |
| 597 bool active_; | 597 bool active_; |
| 598 | 598 |
| 599 DISALLOW_COPY_AND_ASSIGN(WidgetActivationTest); | 599 DISALLOW_COPY_AND_ASSIGN(WidgetActivationTest); |
| 600 }; | 600 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 #endif // defined(OS_WIN) | 633 #endif // defined(OS_WIN) |
| 634 | 634 |
| 635 #if !defined(OS_CHROMEOS) | 635 #if !defined(OS_CHROMEOS) |
| 636 // Provides functionality to create a window modal dialog. | 636 // Provides functionality to create a window modal dialog. |
| 637 class ModalDialogDelegate : public DialogDelegateView { | 637 class ModalDialogDelegate : public DialogDelegateView { |
| 638 public: | 638 public: |
| 639 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} | 639 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} |
| 640 virtual ~ModalDialogDelegate() {} | 640 virtual ~ModalDialogDelegate() {} |
| 641 | 641 |
| 642 // WidgetDelegate overrides. | 642 // WidgetDelegate overrides. |
| 643 virtual ui::ModalType GetModalType() const OVERRIDE { | 643 virtual ui::ModalType GetModalType() const override { |
| 644 return type_; | 644 return type_; |
| 645 } | 645 } |
| 646 | 646 |
| 647 private: | 647 private: |
| 648 ui::ModalType type_; | 648 ui::ModalType type_; |
| 649 | 649 |
| 650 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); | 650 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); |
| 651 }; | 651 }; |
| 652 | 652 |
| 653 // Tests whether the focused window is set correctly when a modal window is | 653 // Tests whether the focused window is set correctly when a modal window is |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 CaptureLostTrackingWidget() : got_capture_lost_(false) {} | 860 CaptureLostTrackingWidget() : got_capture_lost_(false) {} |
| 861 virtual ~CaptureLostTrackingWidget() {} | 861 virtual ~CaptureLostTrackingWidget() {} |
| 862 | 862 |
| 863 bool GetAndClearGotCaptureLost() { | 863 bool GetAndClearGotCaptureLost() { |
| 864 bool value = got_capture_lost_; | 864 bool value = got_capture_lost_; |
| 865 got_capture_lost_ = false; | 865 got_capture_lost_ = false; |
| 866 return value; | 866 return value; |
| 867 } | 867 } |
| 868 | 868 |
| 869 // Widget: | 869 // Widget: |
| 870 virtual void OnMouseCaptureLost() OVERRIDE { | 870 virtual void OnMouseCaptureLost() override { |
| 871 got_capture_lost_ = true; | 871 got_capture_lost_ = true; |
| 872 Widget::OnMouseCaptureLost(); | 872 Widget::OnMouseCaptureLost(); |
| 873 } | 873 } |
| 874 | 874 |
| 875 private: | 875 private: |
| 876 bool got_capture_lost_; | 876 bool got_capture_lost_; |
| 877 | 877 |
| 878 DISALLOW_COPY_AND_ASSIGN(CaptureLostTrackingWidget); | 878 DISALLOW_COPY_AND_ASSIGN(CaptureLostTrackingWidget); |
| 879 }; | 879 }; |
| 880 | 880 |
| 881 } // namespace | 881 } // namespace |
| 882 | 882 |
| 883 class WidgetCaptureTest : public ViewsTestBase { | 883 class WidgetCaptureTest : public ViewsTestBase { |
| 884 public: | 884 public: |
| 885 WidgetCaptureTest() { | 885 WidgetCaptureTest() { |
| 886 } | 886 } |
| 887 | 887 |
| 888 virtual ~WidgetCaptureTest() { | 888 virtual ~WidgetCaptureTest() { |
| 889 } | 889 } |
| 890 | 890 |
| 891 virtual void SetUp() OVERRIDE { | 891 virtual void SetUp() override { |
| 892 gfx::GLSurface::InitializeOneOffForTests(); | 892 gfx::GLSurface::InitializeOneOffForTests(); |
| 893 ui::RegisterPathProvider(); | 893 ui::RegisterPathProvider(); |
| 894 base::FilePath ui_test_pak_path; | 894 base::FilePath ui_test_pak_path; |
| 895 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | 895 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
| 896 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 896 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
| 897 ViewsTestBase::SetUp(); | 897 ViewsTestBase::SetUp(); |
| 898 } | 898 } |
| 899 | 899 |
| 900 // Verifies Widget::SetCapture() results in updating native capture along with | 900 // Verifies Widget::SetCapture() results in updating native capture along with |
| 901 // invoking the right Widget function. | 901 // invoking the right Widget function. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1041 |
| 1042 // Widget observer which grabs capture when the widget is activated. | 1042 // Widget observer which grabs capture when the widget is activated. |
| 1043 class CaptureOnActivationObserver : public WidgetObserver { | 1043 class CaptureOnActivationObserver : public WidgetObserver { |
| 1044 public: | 1044 public: |
| 1045 CaptureOnActivationObserver() { | 1045 CaptureOnActivationObserver() { |
| 1046 } | 1046 } |
| 1047 virtual ~CaptureOnActivationObserver() { | 1047 virtual ~CaptureOnActivationObserver() { |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 // WidgetObserver: | 1050 // WidgetObserver: |
| 1051 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE { | 1051 virtual void OnWidgetActivationChanged(Widget* widget, bool active) override { |
| 1052 if (active) | 1052 if (active) |
| 1053 widget->SetCapture(NULL); | 1053 widget->SetCapture(NULL); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 private: | 1056 private: |
| 1057 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); | 1057 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); |
| 1058 }; | 1058 }; |
| 1059 | 1059 |
| 1060 } // namespace | 1060 } // namespace |
| 1061 | 1061 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 MouseEventTrackingWidget() : got_mouse_event_(false) {} | 1094 MouseEventTrackingWidget() : got_mouse_event_(false) {} |
| 1095 virtual ~MouseEventTrackingWidget() {} | 1095 virtual ~MouseEventTrackingWidget() {} |
| 1096 | 1096 |
| 1097 bool GetAndClearGotMouseEvent() { | 1097 bool GetAndClearGotMouseEvent() { |
| 1098 bool value = got_mouse_event_; | 1098 bool value = got_mouse_event_; |
| 1099 got_mouse_event_ = false; | 1099 got_mouse_event_ = false; |
| 1100 return value; | 1100 return value; |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 // Widget: | 1103 // Widget: |
| 1104 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 1104 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
| 1105 got_mouse_event_ = true; | 1105 got_mouse_event_ = true; |
| 1106 Widget::OnMouseEvent(event); | 1106 Widget::OnMouseEvent(event); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 private: | 1109 private: |
| 1110 bool got_mouse_event_; | 1110 bool got_mouse_event_; |
| 1111 | 1111 |
| 1112 DISALLOW_COPY_AND_ASSIGN(MouseEventTrackingWidget); | 1112 DISALLOW_COPY_AND_ASSIGN(MouseEventTrackingWidget); |
| 1113 }; | 1113 }; |
| 1114 | 1114 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1148 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1149 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1149 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1150 ASSERT_FALSE(details.dispatcher_destroyed); | 1150 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1151 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1151 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1152 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1152 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1153 } | 1153 } |
| 1154 #endif // defined(OS_WIN) | 1154 #endif // defined(OS_WIN) |
| 1155 | 1155 |
| 1156 } // namespace test | 1156 } // namespace test |
| 1157 } // namespace views | 1157 } // namespace views |
| OLD | NEW |