summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 21:46:44 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 21:46:44 +0000
commitc086babf8788773e9f632c0c8a7623d7f85cbf13 (patch)
tree518f7c21e8d01380410efba7853819a5a9179802
parentfdfb270bc229a55c2a5042139f03f9d8a5438fef (diff)
downloadchromium_src-c086babf8788773e9f632c0c8a7623d7f85cbf13.zip
chromium_src-c086babf8788773e9f632c0c8a7623d7f85cbf13.tar.gz
chromium_src-c086babf8788773e9f632c0c8a7623d7f85cbf13.tar.bz2
Change ordering of Shell event handlers:
crrev.com/14184010 made the DragDropController to be the first handler everytime a drag starts. That was done under the assumption that once we are in a drag drop session, no other handler needs to see the event. This assumption turned out to be false because the MouseCursorEventFilter needs to handle events even during a drag drop session so that the cursor can move across displays (causing the bug listed below). Hence, we make the DragDropController the second event handler while MouseCursorEvedntFilter becomes the first. BUG=244508 Review URL: https://chromiumcodereview.appspot.com/16463002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204612 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/drag_drop/drag_drop_controller.cc8
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc100
-rw-r--r--ash/shell.cc4
-rw-r--r--ash/shell_unittest.cc13
-rw-r--r--ash/test/shell_test_api.cc4
-rw-r--r--ash/test/shell_test_api.h2
6 files changed, 22 insertions, 109 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index 98e41d9..40c7cec 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -148,7 +148,7 @@ DragDropController::DragDropController()
drag_drop_window_delegate_(new DragDropTrackerDelegate(this)),
current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE),
weak_factory_(this) {
- Shell::GetInstance()->AddPreTargetHandler(this);
+ Shell::GetInstance()->PrependPreTargetHandler(this);
}
DragDropController::~DragDropController() {
@@ -226,12 +226,6 @@ 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 91cb67c..e27f19c 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -1108,105 +1108,5 @@ 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_FALSE(handler.handled_event_received());
- EXPECT_FALSE(handler.unhandled_event_received());
-
- // Execute any scheduled draws to process deferred mouse events.
- RunAllPendingInMessageLoop();
- }
-
- // Handler should not receive any other gestures that DragDropController
- // does not care about.
- std::set<ui::EventType> drag_drop_gestures;
- drag_drop_gestures.insert(ui::ET_GESTURE_SCROLL_UPDATE);
- drag_drop_gestures.insert(ui::ET_GESTURE_SCROLL_END);
- drag_drop_gestures.insert(ui::ET_GESTURE_LONG_TAP);
- drag_drop_gestures.insert(ui::ET_SCROLL_FLING_START);
- for (ui::EventType type = ui::ET_UNKNOWN; type < ui::ET_LAST;
- type = static_cast<ui::EventType>(type + 1)) {
- if (!IsGestureEventType(type) ||
- drag_drop_gestures.find(type) != drag_drop_gestures.end())
- continue;
-
- handler.Reset();
- DispatchGesture(ui::ET_GESTURE_SCROLL_UPDATE, gesture_location);
- EXPECT_FALSE(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
diff --git a/ash/shell.cc b/ash/shell.cc
index b9aa55e..76b4638 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -537,14 +537,14 @@ void Shell::Init() {
lock_state_controller_.get()));
AddShellObserver(lock_state_controller_.get());
+ drag_drop_controller_.reset(new internal::DragDropController);
mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter());
- AddPreTargetHandler(mouse_cursor_filter_.get());
+ PrependPreTargetHandler(mouse_cursor_filter_.get());
// Create Controllers that may need root window.
// TODO(oshima): Move as many controllers before creating
// RootWindowController as possible.
visibility_controller_.reset(new AshVisibilityController);
- drag_drop_controller_.reset(new internal::DragDropController);
user_action_client_.reset(delegate_->CreateUserActionClient());
window_modality_controller_.reset(
new views::corewm::WindowModalityController);
diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc
index be1d1cd..d059091 100644
--- a/ash/shell_unittest.cc
+++ b/ash/shell_unittest.cc
@@ -9,6 +9,8 @@
#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_widget_controller.h"
+#include "ash/display/mouse_cursor_event_filter.h"
+#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/root_window_controller.h"
#include "ash/session_state_delegate.h"
@@ -16,6 +18,7 @@
#include "ash/shelf/shelf_widget.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
+#include "ash/test/shell_test_api.h"
#include "ash/wm/root_window_layout_manager.h"
#include "ash/wm/window_util.h"
#include "base/utf_string_conversions.h"
@@ -423,6 +426,16 @@ TEST_F(ShellTest, ToggleAutoHide) {
shell->GetShelfAutoHideBehavior(root_window));
}
+TEST_F(ShellTest, TestPreTargetHandlerOrder) {
+ Shell* shell = Shell::GetInstance();
+ Shell::TestApi test_api(shell);
+ test::ShellTestApi shell_test_api(shell);
+
+ const ui::EventHandlerList& handlers = test_api.pre_target_handlers();
+ EXPECT_EQ(handlers[0], shell->mouse_cursor_filter());
+ EXPECT_EQ(handlers[1], shell_test_api.drag_drop_controller());
+}
+
// This verifies WindowObservers are removed when a window is destroyed after
// the Shell is destroyed. This scenario (aura::Windows being deleted after the
// Shell) occurs if someone is holding a reference to an unparented Window, as
diff --git a/ash/test/shell_test_api.cc b/ash/test/shell_test_api.cc
index 126beab..b921535 100644
--- a/ash/test/shell_test_api.cc
+++ b/ash/test/shell_test_api.cc
@@ -48,6 +48,10 @@ LauncherModel* ShellTestApi::launcher_model() {
return shell_->launcher_model_.get();
}
+internal::DragDropController* ShellTestApi::drag_drop_controller() {
+ return shell_->drag_drop_controller_.get();
+}
+
void ShellTestApi::DisableOutputConfiguratorAnimation() {
#if defined(OS_CHROMEOS)
if (shell_->output_configurator_animation_) {
diff --git a/ash/test/shell_test_api.h b/ash/test/shell_test_api.h
index f36716a..926d1dd 100644
--- a/ash/test/shell_test_api.h
+++ b/ash/test/shell_test_api.h
@@ -19,6 +19,7 @@ class Shell;
class LauncherModel;
namespace internal {
+class DragDropController;
class RootWindowLayoutManager;
class ScreenPositionController;
class SystemGestureEventFilter;
@@ -39,6 +40,7 @@ public:
internal::ScreenPositionController* screen_position_controller();
AshNativeCursorManager* ash_native_cursor_manager();
LauncherModel* launcher_model();
+ internal::DragDropController* drag_drop_controller();
void DisableOutputConfiguratorAnimation();