Commit c15571bd authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

part 3 of the scrollableshelf view

Implement the gesture fling handler for ScrollableShelfView

Bug: 973481
Change-Id: I1acee6b12cf8beeb55d637ceba1820e3cd088596
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758596Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688326}
parent d867b10b
......@@ -33,6 +33,10 @@ constexpr int kArrowButtonSize = 20;
constexpr int kArrowButtonGroupWidth =
kArrowButtonSize + kArrowButtonEndPadding + kDistanceToArrowButton;
// The gesture fling event with the velocity smaller than the threshold will be
// neglected.
constexpr int kFlingVelocityThreshold = 1000;
// Sum of the shelf button size and the gap between shelf buttons.
int GetUnit() {
return ShelfConstants::button_size() + ShelfConstants::button_spacing();
......@@ -362,9 +366,20 @@ bool ScrollableShelfView::ShouldHandleGestures(const ui::GestureEvent& event) {
// ShelfView.
bool should_handle_gestures = !cross_main_axis_scrolling_;
if (event.type() == ui::ET_GESTURE_END)
if (should_handle_gestures && event.type() == ui::ET_GESTURE_SCROLL_BEGIN) {
scroll_offset_before_main_axis_scrolling_ = scroll_offset_;
layout_strategy_before_main_axis_scrolling_ = layout_strategy_;
}
if (event.type() == ui::ET_GESTURE_END) {
cross_main_axis_scrolling_ = false;
if (should_handle_gestures) {
scroll_offset_before_main_axis_scrolling_ = gfx::Vector2dF();
layout_strategy_before_main_axis_scrolling_ = kNotShowArrowButtons;
}
}
return should_handle_gestures;
}
......@@ -419,6 +434,32 @@ bool ScrollableShelfView::ProcessGestureEvent(const ui::GestureEvent& event) {
return true;
}
if (event.type() == ui::ET_SCROLL_FLING_START) {
const bool is_horizontal_alignment = GetShelf()->IsHorizontalAlignment();
int scroll_velocity = is_horizontal_alignment
? event.details().velocity_x()
: event.details().velocity_y();
if (abs(scroll_velocity) < kFlingVelocityThreshold)
return false;
layout_strategy_ = layout_strategy_before_main_axis_scrolling_;
float page_scrolling_offset =
CalculatePageScrollingOffset(scroll_velocity < 0);
if (is_horizontal_alignment) {
ScrollToXOffset(
scroll_offset_before_main_axis_scrolling_.x() + page_scrolling_offset,
true);
} else {
ScrollToYOffset(
scroll_offset_before_main_axis_scrolling_.y() + page_scrolling_offset,
true);
}
return true;
}
if (event.type() != ui::ET_GESTURE_SCROLL_UPDATE)
return false;
......
......@@ -137,6 +137,14 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
// whether it is scrolling horizontally for left/right shelf.
bool cross_main_axis_scrolling_ = false;
// Gesture states are preserved when the gesture scrolling along the main axis
// (that is, whether it is scrolling horizontally for bottom shelf, or whether
// it is scrolling horizontally for left/right shelf) gets started. They help
// to handle the gesture fling event.
gfx::Vector2dF scroll_offset_before_main_axis_scrolling_;
LayoutStrategy layout_strategy_before_main_axis_scrolling_ =
kNotShowArrowButtons;
DISALLOW_COPY_AND_ASSIGN(ScrollableShelfView);
};
......
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