Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 11787042: views: Stop dispatching scroll-gesture events if the scroll-begin event wasn't handled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index dc11612ca052709d91f6dba3c6bd661950d28d24..c23fd0f6d0d6bbdd972abd08e5e0ad3d6f5f26d3 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
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698