Commit 2c96e49c authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Fix the crash issue when scrolling the shelf by gesture

There is a loophole in scrollable shelf's code: if the incoming gesture
event is not handled by neither scrollable shelf nor shelf view, the
scroll status is not reset. Because resetting the scroll status relies
on the gesture end event while the scrollable shelf view will not
receive the gesture end event if it is not the correct event handler.

This CL fixes such an issue.

Bug: 1012888
Change-Id: I98927dd068b6dd75008936eb8bee9f5249091f56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1882560Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709965}
parent 85a678bf
......@@ -738,10 +738,18 @@ void ScrollableShelfView::OnMouseEvent(ui::MouseEvent* event) {
}
void ScrollableShelfView::OnGestureEvent(ui::GestureEvent* event) {
if (ShouldHandleGestures(*event))
HandleGestureEvent(event);
else if (shelf_view_->HandleGestureEvent(event))
if (ShouldHandleGestures(*event) && ProcessGestureEvent(*event)) {
// |event| is consumed by ScrollableShelfView.
event->SetHandled();
} else if (shelf_view_->HandleGestureEvent(event)) {
// |event| is consumed by ShelfView.
event->StopPropagation();
} else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
// |event| is consumed by neither ScrollableShelfView nor ShelfView. So the
// gesture end event will not be propagated to this view. Then we need to
// reset the class members related with scroll status explicitly.
ResetScrollStatus();
}
}
const char* ScrollableShelfView::GetClassName() const {
......@@ -1005,21 +1013,16 @@ bool ScrollableShelfView::ShouldHandleGestures(const ui::GestureEvent& event) {
layout_strategy_before_main_axis_scrolling_ = layout_strategy_;
}
if (event.type() == ui::ET_GESTURE_END) {
scroll_status_ = kNotInScroll;
if (should_handle_gestures) {
scroll_offset_before_main_axis_scrolling_ = gfx::Vector2dF();
layout_strategy_before_main_axis_scrolling_ = kNotShowArrowButtons;
}
}
if (event.type() == ui::ET_GESTURE_END)
ResetScrollStatus();
return should_handle_gestures;
}
void ScrollableShelfView::HandleGestureEvent(ui::GestureEvent* event) {
if (ProcessGestureEvent(*event))
event->SetHandled();
void ScrollableShelfView::ResetScrollStatus() {
scroll_status_ = kNotInScroll;
scroll_offset_before_main_axis_scrolling_ = gfx::Vector2dF();
layout_strategy_before_main_axis_scrolling_ = kNotShowArrowButtons;
}
bool ScrollableShelfView::ProcessGestureEvent(const ui::GestureEvent& event) {
......
......@@ -219,8 +219,8 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// Returns whether the received gesture event should be handled here.
bool ShouldHandleGestures(const ui::GestureEvent& event);
// Handles the gesture event.
void HandleGestureEvent(ui::GestureEvent* event);
// Resets the attributes related with gesture scroll to their default values.
void ResetScrollStatus();
// Handles events for scrolling the shelf. Returns whether the event has been
// consumed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment