| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 private: | 51 private: |
| 52 // Overridden from View: | 52 // Overridden from View: |
| 53 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { | 53 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { |
| 54 GetWidget()->Close(); | 54 GetWidget()->Close(); |
| 55 base::MessageLoop::current()->QuitNow(); | 55 base::MessageLoop::current()->QuitNow(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); | 58 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // A view that does a capture on gesture-begin events. | 61 // A view that does a capture on ui::ET_GESTURE_TAP_DOWN events. |
| 62 class GestureCaptureView : public View { | 62 class GestureCaptureView : public View { |
| 63 public: | 63 public: |
| 64 GestureCaptureView() {} | 64 GestureCaptureView() {} |
| 65 virtual ~GestureCaptureView() {} | 65 virtual ~GestureCaptureView() {} |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // Overridden from View: | 68 // Overridden from View: |
| 69 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 69 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 70 if (event->type() == ui::ET_GESTURE_BEGIN) { | 70 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 71 GetWidget()->SetCapture(this); | 71 GetWidget()->SetCapture(this); |
| 72 event->StopPropagation(); | 72 event->StopPropagation(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); | 76 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // A view that always processes all mouse events. | 79 // A view that always processes all mouse events. |
| 80 class MouseView : public View { | 80 class MouseView : public View { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 container->AddChildView(gesture); | 290 container->AddChildView(gesture); |
| 291 | 291 |
| 292 MouseView* mouse = new MouseView; | 292 MouseView* mouse = new MouseView; |
| 293 mouse->SetBounds(30, 0, 30, 30); | 293 mouse->SetBounds(30, 0, 30, 30); |
| 294 container->AddChildView(mouse); | 294 container->AddChildView(mouse); |
| 295 | 295 |
| 296 toplevel->SetSize(gfx::Size(100, 100)); | 296 toplevel->SetSize(gfx::Size(100, 100)); |
| 297 toplevel->Show(); | 297 toplevel->Show(); |
| 298 | 298 |
| 299 // Start a gesture on |gesture|. | 299 // Start a gesture on |gesture|. |
| 300 ui::GestureEvent begin(15, | 300 ui::GestureEvent tap_down(15, |
| 301 15, | 301 15, |
| 302 0, | 302 0, |
| 303 base::TimeDelta(), | 303 base::TimeDelta(), |
| 304 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0)); | 304 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, |
| 305 0, |
| 306 0)); |
| 305 ui::GestureEvent end(15, | 307 ui::GestureEvent end(15, |
| 306 15, | 308 15, |
| 307 0, | 309 0, |
| 308 base::TimeDelta(), | 310 base::TimeDelta(), |
| 309 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); | 311 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); |
| 310 toplevel->OnGestureEvent(&begin); | 312 toplevel->OnGestureEvent(&tap_down); |
| 311 | 313 |
| 312 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| | 314 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| |
| 313 // will not receive the event. | 315 // will not receive the event. |
| 314 gfx::Point click_location(45, 15); | 316 gfx::Point click_location(45, 15); |
| 315 | 317 |
| 316 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 318 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
| 317 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 319 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 318 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 320 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, |
| 319 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 321 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 320 | 322 |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1080 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1079 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1081 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1080 ASSERT_FALSE(details.dispatcher_destroyed); | 1082 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1081 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1083 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1082 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1084 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1083 } | 1085 } |
| 1084 #endif | 1086 #endif |
| 1085 | 1087 |
| 1086 } // namespace test | 1088 } // namespace test |
| 1087 } // namespace views | 1089 } // namespace views |
| OLD | NEW |