summaryrefslogtreecommitdiffstats
path: root/ash/drag_drop
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-01 14:05:10 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-01 14:05:10 +0000
commit7ddcd4293d9ad4336dbaebd102af12c1690abd68 (patch)
treec3cf01f88cfa7eace22c00b6c49fb22fecf19502 /ash/drag_drop
parent4aedf2df4153b0deb3b7d9139e7daf854c1e31c7 (diff)
downloadchromium_src-7ddcd4293d9ad4336dbaebd102af12c1690abd68.zip
chromium_src-7ddcd4293d9ad4336dbaebd102af12c1690abd68.tar.gz
chromium_src-7ddcd4293d9ad4336dbaebd102af12c1690abd68.tar.bz2
ash: SystemGestureEventFilter should not process gestures while a drag drop is
in progress. BUG=236493 Review URL: https://chromiumcodereview.appspot.com/14184010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/drag_drop')
-rw-r--r--ash/drag_drop/drag_drop_controller.cc6
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc78
2 files changed, 84 insertions, 0 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index 933c0d1..90d3010 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -226,6 +226,12 @@ int DragDropController::StartDragAndDrop(
if (cancel_animation_)
cancel_animation_->End();
+ // Become the first event handler since we should get first shot at handling
+ // any events during the drag drop session.
+ Shell::GetInstance()->RemovePreTargetHandler(this);
+ Shell::GetInstance()->PrependPreTargetHandler(this);
+
+
#if !defined(OS_MACOSX)
if (should_block_during_drag_drop_) {
base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index df87dfc..822dede 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -1082,5 +1082,83 @@ TEST_F(DragDropControllerTest, MAYBE_DragCancelAcrossDisplays) {
}
}
+class SimpleEventHandler : public ui::EventHandler {
+ public:
+ SimpleEventHandler()
+ : handled_event_received_(false),
+ unhandled_event_received_(false) {
+ ash::Shell::GetInstance()->PrependPreTargetHandler(this);
+ }
+
+ virtual ~SimpleEventHandler() {
+ ash::Shell::GetInstance()->RemovePreTargetHandler(this);
+ }
+
+ bool handled_event_received() { return handled_event_received_; }
+ bool unhandled_event_received() { return unhandled_event_received_; }
+
+ void Reset() {
+ handled_event_received_ = false;
+ unhandled_event_received_ = false;
+ }
+
+ private:
+ // Overridden from ui::EventHandler.
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ if (event->handled())
+ handled_event_received_ = true;
+ else
+ unhandled_event_received_ = true;
+ }
+
+ bool handled_event_received_;
+ bool unhandled_event_received_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler);
+};
+
+TEST_F(DragDropControllerTest,
+ DragDropControllerReceivesAllEventsDuringDragDrop) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableTouchDragDrop);
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
+ DragTestView* drag_view = new DragTestView;
+ AddViewToWidgetAndResize(widget.get(), drag_view);
+ aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
+ widget->GetNativeView());
+ ui::OSExchangeData data;
+ data.SetString(UTF8ToUTF16("I am being dragged"));
+ SimpleEventHandler handler;
+
+ // Since we are not in drag/drop, |handler| should receive unhandled events.
+ generator.PressTouch();
+ gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
+ handler.Reset();
+ DispatchGesture(ui::ET_GESTURE_LONG_PRESS, point);
+ EXPECT_TRUE(handler.unhandled_event_received());
+ EXPECT_FALSE(handler.handled_event_received());
+
+ EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
+
+ // Since dragging has started, |handler| should not receive unhandled events.
+ UpdateDragData(&data);
+ gfx::Point gesture_location = point;
+ int num_drags = drag_view->width();
+ for (int i = 0; i < num_drags; ++i) {
+ gesture_location.Offset(1, 0);
+ handler.Reset();
+ DispatchGesture(ui::ET_GESTURE_SCROLL_UPDATE, gesture_location);
+ EXPECT_TRUE(handler.handled_event_received());
+ EXPECT_FALSE(handler.unhandled_event_received());
+
+ // Execute any scheduled draws to process deferred mouse events.
+ RunAllPendingInMessageLoop();
+ }
+
+ // End dragging.
+ DispatchGesture(ui::ET_GESTURE_SCROLL_END, gesture_location);
+ EXPECT_TRUE(drag_drop_controller_->drop_received_);
+}
+
} // namespace test
} // namespace aura