diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 00:14:27 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 00:14:27 +0000 |
commit | d3dbe56ed8296f5ccd843d2cb361e9b161418638 (patch) | |
tree | 4ce61a74def34bf54d805d1ff43da44da13c3dde | |
parent | 7f516dc959f78ef1b678b73230cf1d38259e8cd1 (diff) | |
download | chromium_src-d3dbe56ed8296f5ccd843d2cb361e9b161418638.zip chromium_src-d3dbe56ed8296f5ccd843d2cb361e9b161418638.tar.gz chromium_src-d3dbe56ed8296f5ccd843d2cb361e9b161418638.tar.bz2 |
views: Stop dispatching scroll-gesture events if the scroll-begin event wasn't handled.
BUG=153359
Review URL: https://codereview.chromium.org/11787042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175616 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/views/widget/root_view.cc | 11 | ||||
-rw-r--r-- | ui/views/widget/widget_unittest.cc | 99 |
2 files changed, 105 insertions, 5 deletions
diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index 12c2d12..2a71020 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -288,6 +288,17 @@ void RootView::DispatchGestureEvent(ui::GestureEvent* event) { return; } + // If there was no handler for a SCROLL_BEGIN event, then subsequent scroll + // events are not dispatched to any views. + switch (event->type()) { + case ui::ET_GESTURE_SCROLL_UPDATE: + case ui::ET_GESTURE_SCROLL_END: + case ui::ET_SCROLL_FLING_START: + return; + default: + break; + } + // Walk up the tree until we find a view that wants the gesture event. for (gesture_handler_ = GetEventHandlerForPoint(event->location()); gesture_handler_ && (gesture_handler_ != this); diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc index dc11612..c23fd0f 100644 --- a/ui/views/widget/widget_unittest.cc +++ b/ui/views/widget/widget_unittest.cc @@ -136,11 +136,7 @@ class EventCountView : public View { event_count_.clear(); } - private: - void RecordEvent(const ui::Event& event) { - ++event_count_[event.type()]; - } - + protected: // Overridden from View: virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { RecordEvent(event); @@ -192,11 +188,42 @@ class EventCountView : public View { RecordEvent(*event); } + private: + void RecordEvent(const ui::Event& event) { + ++event_count_[event.type()]; + } + std::map<ui::EventType, int> event_count_; DISALLOW_COPY_AND_ASSIGN(EventCountView); }; +// A view that keeps track of the events it receives, and consumes all scroll +// gesture events. +class ScrollableEventCountView : public EventCountView { + public: + ScrollableEventCountView() {} + virtual ~ScrollableEventCountView() {} + + private: + // Overridden from ui::EventHandler: + virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { + EventCountView::OnGestureEvent(event); + switch (event->type()) { + case ui::ET_GESTURE_SCROLL_BEGIN: + case ui::ET_GESTURE_SCROLL_UPDATE: + case ui::ET_GESTURE_SCROLL_END: + case ui::ET_SCROLL_FLING_START: + event->SetHandled(); + break; + default: + break; + } + } + + DISALLOW_COPY_AND_ASSIGN(ScrollableEventCountView); +}; + // A view that does a capture on gesture-begin events. class GestureCaptureView : public View { public: @@ -1282,9 +1309,71 @@ TEST_F(WidgetTest, WheelEventsFromScrollEventTarget) { EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_SCROLL)); EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL)); + + widget->CloseNow(); } #endif // defined(USE_AURA) +// Tests that if a scroll-begin gesture is not handled, then subsequent scroll +// events are not dispatched to any view. +TEST_F(WidgetTest, GestureScrollEventDispatching) { + EventCountView* noscroll_view = new EventCountView; + EventCountView* scroll_view = new ScrollableEventCountView; + + noscroll_view->SetBounds(0, 0, 50, 40); + scroll_view->SetBounds(60, 0, 40, 40); + + Widget* widget = CreateTopLevelPlatformWidget(); + widget->GetRootView()->AddChildView(noscroll_view); + widget->GetRootView()->AddChildView(scroll_view); + + { + ui::GestureEvent begin(ui::ET_GESTURE_SCROLL_BEGIN, + 5, 5, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0), + 1); + widget->OnGestureEvent(&begin); + ui::GestureEvent update(ui::ET_GESTURE_SCROLL_UPDATE, + 25, 15, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10), + 1); + widget->OnGestureEvent(&update); + ui::GestureEvent end(ui::ET_GESTURE_SCROLL_END, + 25, 15, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0), + 1); + widget->OnGestureEvent(&end); + + EXPECT_EQ(1, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); + EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); + EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); + } + + { + ui::GestureEvent begin(ui::ET_GESTURE_SCROLL_BEGIN, + 65, 5, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0), + 1); + widget->OnGestureEvent(&begin); + ui::GestureEvent update(ui::ET_GESTURE_SCROLL_UPDATE, + 85, 15, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10), + 1); + widget->OnGestureEvent(&update); + ui::GestureEvent end(ui::ET_GESTURE_SCROLL_END, + 85, 15, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0), + 1); + widget->OnGestureEvent(&end); + + EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); + EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); + EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); + } + + widget->CloseNow(); +} + } // namespace } // namespace views |