diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-09 18:12:48 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-09 18:12:48 +0000 |
commit | f3dc80ce62ecb8fc9eb4de4527cb0c489b219867 (patch) | |
tree | 18441978b4fc3fb1283cf7c982fcd18625925429 | |
parent | efdbdb05c0a56ef6c9d23a78e1586bdc733cb504 (diff) | |
download | chromium_src-f3dc80ce62ecb8fc9eb4de4527cb0c489b219867.zip chromium_src-f3dc80ce62ecb8fc9eb4de4527cb0c489b219867.tar.gz chromium_src-f3dc80ce62ecb8fc9eb4de4527cb0c489b219867.tar.bz2 |
gestures: Generate only either scroll-end or fling-start events at the end of a scroll gesture.
When a fling happens at the end of a scroll, instead of generating both a scroll-end
and a fling-start event, generate only fling-start event. Unfortunately, WebKit still
requires an explicit scroll-end gesture before a fling, so continue to do that as a
special case.
BUG=141460,141309
Review URL: https://chromiumcodereview.appspot.com/10826209
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150852 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/toplevel_window_event_filter.cc | 23 | ||||
-rw-r--r-- | ui/app_list/contents_view.cc | 5 | ||||
-rw-r--r-- | ui/app_list/pagination_model.cc | 18 | ||||
-rw-r--r-- | ui/app_list/pagination_model.h | 2 | ||||
-rw-r--r-- | ui/aura/gestures/gesture_recognizer_unittest.cc | 21 | ||||
-rw-r--r-- | ui/base/gestures/gesture_sequence.cc | 16 | ||||
-rw-r--r-- | ui/views/events/event.h | 5 | ||||
-rw-r--r-- | ui/views/widget/root_view.cc | 8 |
8 files changed, 57 insertions, 41 deletions
diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc index 1f669a5..e896d07 100644 --- a/ash/wm/toplevel_window_event_filter.cc +++ b/ash/wm/toplevel_window_event_filter.cc @@ -149,17 +149,22 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( break; } case ui::ET_GESTURE_SCROLL_END: - if (!in_gesture_resize_) - return ui::GESTURE_STATUS_UNKNOWN; - CompleteDrag(DRAG_COMPLETE, event->flags()); - if (in_move_loop_) { - quit_closure_.Run(); - in_move_loop_ = false; + case ui::ET_SCROLL_FLING_START: { + ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; + if (in_gesture_resize_) { + // If the window was being resized, then just complete the resize. + CompleteDrag(DRAG_COMPLETE, event->flags()); + if (in_move_loop_) { + quit_closure_.Run(); + in_move_loop_ = false; + } + in_gesture_resize_ = false; + status = ui::GESTURE_STATUS_CONSUMED; } - in_gesture_resize_ = false; - break; - case ui::ET_SCROLL_FLING_START: { + if (event->type() == ui::ET_GESTURE_SCROLL_END) + return status; + int component = target->delegate()->GetNonClientComponent(event->location()); if (WindowResizer::GetBoundsChangeForWindowComponent(component) == 0) diff --git a/ui/app_list/contents_view.cc b/ui/app_list/contents_view.cc index 4b4bc77..2ad9887 100644 --- a/ui/app_list/contents_view.cc +++ b/ui/app_list/contents_view.cc @@ -204,13 +204,14 @@ ui::GestureStatus ContentsView::OnGestureEvent( pagination_model_->EndScroll(); return ui::GESTURE_STATUS_CONSUMED; case ui::ET_SCROLL_FLING_START: { + pagination_model_->EndScroll(); if (fabs(event.details().velocity_x()) > kMinHorizVelocityToSwitchPage) { + pagination_model_->ResetTransitionAnimation(); pagination_model_->SelectPageRelative( event.details().velocity_x() < 0 ? 1 : -1, true); - return ui::GESTURE_STATUS_CONSUMED; } - break; + return ui::GESTURE_STATUS_CONSUMED; } default: break; diff --git a/ui/app_list/pagination_model.cc b/ui/app_list/pagination_model.cc index cc9e402..97ba5e8 100644 --- a/ui/app_list/pagination_model.cc +++ b/ui/app_list/pagination_model.cc @@ -56,7 +56,7 @@ void PaginationModel::SelectPage(int page, bool animate) { if (page == selected_page_) return; - ResetTranstionAnimation(); + ResetTransitionAnimation(); int old_selected = selected_page_; selected_page_ = page; @@ -86,6 +86,13 @@ void PaginationModel::SetTransitionDuration(int duration_ms) { transition_duration_ms_ = duration_ms; } +void PaginationModel::ResetTransitionAnimation() { + transition_animation_.reset(); + transition_.target_page = -1; + transition_.progress = 0; + pending_selected_page_ = -1; +} + void PaginationModel::StartScroll() { // Cancels current transition animation (if any). transition_animation_.reset(); @@ -185,13 +192,6 @@ void PaginationModel::CreateTransitionAnimation() { transition_animation_->SetSlideDuration(transition_duration_ms_); } -void PaginationModel::ResetTranstionAnimation() { - transition_animation_.reset(); - transition_.target_page = -1; - transition_.progress = 0; - pending_selected_page_ = -1; -} - void PaginationModel::AnimationProgressed(const ui::Animation* animation) { transition_.progress = transition_animation_->GetCurrentValue(); NotifyTransitionChanged(); @@ -216,7 +216,7 @@ void PaginationModel::AnimationEnded(const ui::Animation* animation) { SelectPage(transition_.target_page, false /* animate */); } else if (transition_animation_->GetCurrentValue() == 0) { // Hiding animation ends. No page change should happen. - ResetTranstionAnimation(); + ResetTransitionAnimation(); } if (next_target >= 0) diff --git a/ui/app_list/pagination_model.h b/ui/app_list/pagination_model.h index abf2100..39f88e0 100644 --- a/ui/app_list/pagination_model.h +++ b/ui/app_list/pagination_model.h @@ -60,6 +60,7 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate { void SetTransition(const Transition& transition); void SetTransitionDuration(int duration_ms); + void ResetTransitionAnimation(); // Starts a scroll transition. If there is a running transition animation, // cancels it but keeps the transition info. @@ -107,7 +108,6 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate { void StartTranstionAnimation(int target_page); void CreateTransitionAnimation(); - void ResetTranstionAnimation(); // ui::AnimationDelegate overrides: virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; diff --git a/ui/aura/gestures/gesture_recognizer_unittest.cc b/ui/aura/gestures/gesture_recognizer_unittest.cc index 00d1302..4391fe7 100644 --- a/ui/aura/gestures/gesture_recognizer_unittest.cc +++ b/ui/aura/gestures/gesture_recognizer_unittest.cc @@ -164,8 +164,10 @@ class GestureEventConsumeDelegate : public TestWindowDelegate { case ui::ET_SCROLL_FLING_START: EXPECT_TRUE(gesture->details().velocity_x() != 0 || gesture->details().velocity_y() != 0); - EXPECT_TRUE(scroll_end_); + EXPECT_FALSE(scroll_end_); fling_ = true; + velocity_x_ = gesture->details().velocity_x(); + velocity_y_ = gesture->details().velocity_y(); break; case ui::ET_GESTURE_TWO_FINGER_TAP: two_finger_tap_ = true; @@ -859,8 +861,9 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { kTouchId, GetTime()); root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); - EXPECT_TRUE(delegate->scroll_end()); - EXPECT_EQ(0, delegate->velocity_x()); + EXPECT_TRUE(delegate->fling()); + EXPECT_FALSE(delegate->scroll_end()); + EXPECT_GT(delegate->velocity_x(), 0); EXPECT_EQ(0, delegate->velocity_y()); } @@ -895,9 +898,10 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { kTouchId, GetTime()); root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); - EXPECT_TRUE(delegate->scroll_end()); + EXPECT_TRUE(delegate->fling()); + EXPECT_FALSE(delegate->scroll_end()); EXPECT_EQ(0, delegate->velocity_x()); - EXPECT_EQ(0, delegate->velocity_y()); + EXPECT_GT(delegate->velocity_y(), 0); } // Check Scroll End Events reports zero velocities @@ -929,9 +933,10 @@ TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { kTouchId, GetTime()); root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); - EXPECT_TRUE(delegate->scroll_end()); - EXPECT_EQ(0, delegate->velocity_x()); - EXPECT_EQ(0, delegate->velocity_y()); + EXPECT_TRUE(delegate->fling()); + EXPECT_FALSE(delegate->scroll_end()); + EXPECT_GT(delegate->velocity_x(), 0); + EXPECT_GT(delegate->velocity_y(), 0); } // Check that appropriate touch events generate long press events diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc index b52babb..2f9b1546 100644 --- a/ui/base/gestures/gesture_sequence.cc +++ b/ui/base/gestures/gesture_sequence.cc @@ -642,15 +642,6 @@ void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point, else if (scroll_type_ == ST_VERTICAL) railed_x_velocity = 0; - // TODO(rjkroege): It is conceivable that we could suppress sending the - // GestureScrollEnd if it is immediately followed by a GestureFlingStart. - gestures->push_back(CreateGestureEvent( - GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0), - location, - flags_, - base::Time::FromDoubleT(point.last_touch_time()), - 1 << point.touch_id())); - if (railed_x_velocity != 0 || railed_y_velocity != 0) { // TODO(sad|rjkroege): fling-curve is currently configured to work well with // touchpad scroll-events. This curve needs to be adjusted to work correctly @@ -666,6 +657,13 @@ void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point, flags_, base::Time::FromDoubleT(point.last_touch_time()), 1 << point.touch_id())); + } else { + gestures->push_back(CreateGestureEvent( + GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0), + location, + flags_, + base::Time::FromDoubleT(point.last_touch_time()), + 1 << point.touch_id())); } } diff --git a/ui/views/events/event.h b/ui/views/events/event.h index 1a518d3..931441d8 100644 --- a/ui/views/events/event.h +++ b/ui/views/events/event.h @@ -91,6 +91,11 @@ class VIEWS_EXPORT Event { type_ == ui::ET_GESTURE_SCROLL_END; } + bool IsFlingScrollEvent() const { + return type_ == ui::ET_SCROLL_FLING_CANCEL || + type_ == ui::ET_SCROLL_FLING_START; + } + protected: Event(ui::EventType type, int flags); Event(const NativeEvent& native_event, ui::EventType type, int flags); diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index 2e799a8..c5a72e4 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -458,8 +458,9 @@ ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { if (gesture_handler_) { // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during // processing. - View* handler = event.IsScrollGestureEvent() && scroll_gesture_handler_ ? - scroll_gesture_handler_ : gesture_handler_; + View* handler = scroll_gesture_handler_ && + (event.IsScrollGestureEvent() || event.IsFlingScrollEvent()) ? + scroll_gesture_handler_ : gesture_handler_; GestureEvent handler_event(event, this, handler); ui::GestureStatus status = handler->ProcessGestureEvent(handler_event); @@ -468,7 +469,8 @@ ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { event.details().touch_points() <= 1) gesture_handler_ = NULL; - if (event.type() == ui::ET_GESTURE_SCROLL_END && scroll_gesture_handler_) + if (scroll_gesture_handler_ && (event.type() == ui::ET_GESTURE_SCROLL_END || + event.type() == ui::ET_SCROLL_FLING_START)) scroll_gesture_handler_ = NULL; if (status == ui::GESTURE_STATUS_CONSUMED) |