Commit e322f3c3 authored by mgiuca's avatar mgiuca Committed by Commit bot

Make apps grid view scroll vertically in experimental app list.

Scrolling remains horizontal in the normal (and centered) app lists.

BUG=406222
TEST=Run with --enable-experimental-app-list --show-app-list. Apps grid
view should scroll vertically. Normal app list should still scroll
horizontally.

Review URL: https://codereview.chromium.org/491973004

Cr-Commit-Position: refs/heads/master@{#292826}
parent fda1919d
...@@ -509,6 +509,11 @@ void AppListController::TransitionChanged() { ...@@ -509,6 +509,11 @@ void AppListController::TransitionChanged() {
const int shift = kMaxOverScrollShift * progress * dir; const int shift = kMaxOverScrollShift * progress * dir;
gfx::Rect shifted(view_bounds_); gfx::Rect shifted(view_bounds_);
// Experimental app list scrolls vertically, so make the overscroll
// vertical.
if (app_list::switches::IsExperimentalAppListEnabled())
shifted.set_y(shifted.y() + shift);
else
shifted.set_x(shifted.x() + shift); shifted.set_x(shifted.x() + shift);
widget->SetBounds(shifted); widget->SetBounds(shifted);
should_snap_back_ = true; should_snap_back_ = true;
......
...@@ -962,10 +962,17 @@ bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { ...@@ -962,10 +962,17 @@ bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) {
bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) { bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) {
int offset; int offset;
if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
// If the view scrolls horizontally, both horizontal and vertical scroll
// events are valid (since most mouse wheels only have vertical scrolling).
if (abs(event.x_offset()) > abs(event.y_offset())) if (abs(event.x_offset()) > abs(event.y_offset()))
offset = event.x_offset(); offset = event.x_offset();
else else
offset = event.y_offset(); offset = event.y_offset();
} else {
// If the view scrolls vertically, only vertical scroll events are valid.
offset = event.y_offset();
}
if (abs(offset) > kMinMouseWheelToSwitchPage) { if (abs(offset) > kMinMouseWheelToSwitchPage) {
if (!pagination_model_.has_transition()) { if (!pagination_model_.has_transition()) {
...@@ -996,29 +1003,37 @@ void AppsGridView::ViewHierarchyChanged( ...@@ -996,29 +1003,37 @@ void AppsGridView::ViewHierarchyChanged(
} }
void AppsGridView::OnGestureEvent(ui::GestureEvent* event) { void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
const ui::GestureEventDetails& details = event->details();
switch (event->type()) { switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN: case ui::ET_GESTURE_SCROLL_BEGIN:
pagination_model_.StartScroll(); pagination_model_.StartScroll();
event->SetHandled(); event->SetHandled();
return; return;
case ui::ET_GESTURE_SCROLL_UPDATE: case ui::ET_GESTURE_SCROLL_UPDATE: {
// event->details.scroll_x() > 0 means moving contents to right. That is, float scroll = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL
// transitioning to previous page. ? details.scroll_x()
pagination_model_.UpdateScroll(event->details().scroll_x() / : details.scroll_y();
GetContentsBounds().width()); gfx::Rect bounds(GetContentsBounds());
int size = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL ? bounds.width()
: bounds.height();
// scroll > 0 means moving contents right or down. That is, transitioning
// to the previous page.
pagination_model_.UpdateScroll(scroll / size);
event->SetHandled(); event->SetHandled();
return; return;
}
case ui::ET_GESTURE_SCROLL_END: case ui::ET_GESTURE_SCROLL_END:
pagination_model_.EndScroll(pagination_model_.transition().progress < pagination_model_.EndScroll(pagination_model_.transition().progress <
kFinishTransitionThreshold); kFinishTransitionThreshold);
event->SetHandled(); event->SetHandled();
return; return;
case ui::ET_SCROLL_FLING_START: { case ui::ET_SCROLL_FLING_START: {
float velocity = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL
? details.velocity_x()
: details.velocity_y();
pagination_model_.EndScroll(true); pagination_model_.EndScroll(true);
if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
pagination_model_.SelectPageRelative( pagination_model_.SelectPageRelative(velocity < 0 ? 1 : -1, true);
event->details().velocity_x() < 0 ? 1 : -1, true);
}
event->SetHandled(); event->SetHandled();
return; return;
} }
...@@ -1032,10 +1047,17 @@ void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { ...@@ -1032,10 +1047,17 @@ void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
return; return;
float offset; float offset;
if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
// If the view scrolls horizontally, both horizontal and vertical scroll
// events are valid (vertical scroll events simulate mouse wheel).
if (std::abs(event->x_offset()) > std::abs(event->y_offset())) if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
offset = event->x_offset(); offset = event->x_offset();
else else
offset = event->y_offset(); offset = event->y_offset();
} else {
// If the view scrolls vertically, only vertical scroll events are valid.
offset = event->y_offset();
}
if (std::abs(offset) > kMinScrollToSwitchPage) { if (std::abs(offset) > kMinScrollToSwitchPage) {
if (!pagination_model_.has_transition()) { if (!pagination_model_.has_transition()) {
...@@ -1208,9 +1230,10 @@ void AppsGridView::CalculateIdealBounds() { ...@@ -1208,9 +1230,10 @@ void AppsGridView::CalculateIdealBounds() {
tile_size.height() * rows_per_page_)); tile_size.height() * rows_per_page_));
grid_rect.Intersect(rect); grid_rect.Intersect(rect);
// Page width including padding pixels. A tile.x + page_width means the same // Page size including padding pixels. A tile.x + page_width means the same
// tile slot in the next page. // tile slot in the next page; similarly for tile.y + page_height.
const int page_width = grid_rect.width() + kPagePadding; const int page_width = grid_rect.width() + kPagePadding;
const int page_height = grid_rect.height() + kPagePadding;
// If there is a transition, calculates offset for current and target page. // If there is a transition, calculates offset for current and target page.
const int current_page = pagination_model_.selected_page(); const int current_page = pagination_model_.selected_page();
...@@ -1218,10 +1241,8 @@ void AppsGridView::CalculateIdealBounds() { ...@@ -1218,10 +1241,8 @@ void AppsGridView::CalculateIdealBounds() {
pagination_model_.transition(); pagination_model_.transition();
const bool is_valid = pagination_model_.is_valid_page(transition.target_page); const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
// Transition to right means negative offset. // Transition to previous page means negative offset.
const int dir = transition.target_page > current_page ? -1 : 1; const int dir = transition.target_page > current_page ? -1 : 1;
const int transition_offset = is_valid ?
transition.progress * page_width * dir : 0;
const int total_views = const int total_views =
view_model_.view_size() + pulsing_blocks_model_.view_size(); view_model_.view_size() + pulsing_blocks_model_.view_size();
...@@ -1245,8 +1266,11 @@ void AppsGridView::CalculateIdealBounds() { ...@@ -1245,8 +1266,11 @@ void AppsGridView::CalculateIdealBounds() {
} }
} }
// Decides an x_offset for current item. // Decide the x or y offset for current item.
int x_offset = 0; int x_offset = 0;
int y_offset = 0;
if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
if (view_index.page < current_page) if (view_index.page < current_page)
x_offset = -page_width; x_offset = -page_width;
else if (view_index.page > current_page) else if (view_index.page > current_page)
...@@ -1255,7 +1279,20 @@ void AppsGridView::CalculateIdealBounds() { ...@@ -1255,7 +1279,20 @@ void AppsGridView::CalculateIdealBounds() {
if (is_valid) { if (is_valid) {
if (view_index.page == current_page || if (view_index.page == current_page ||
view_index.page == transition.target_page) { view_index.page == transition.target_page) {
x_offset += transition_offset; x_offset += transition.progress * page_width * dir;
}
}
} else {
if (view_index.page < current_page)
y_offset = -page_height;
else if (view_index.page > current_page)
y_offset = page_height;
if (is_valid) {
if (view_index.page == current_page ||
view_index.page == transition.target_page) {
y_offset += transition.progress * page_height * dir;
}
} }
} }
...@@ -1263,7 +1300,7 @@ void AppsGridView::CalculateIdealBounds() { ...@@ -1263,7 +1300,7 @@ void AppsGridView::CalculateIdealBounds() {
const int col = view_index.slot % cols_; const int col = view_index.slot % cols_;
gfx::Rect tile_slot( gfx::Rect tile_slot(
gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset,
grid_rect.y() + row * tile_size.height()), grid_rect.y() + row * tile_size.height() + y_offset),
tile_size); tile_size);
if (i < view_model_.view_size()) { if (i < view_model_.view_size()) {
view_model_.set_ideal_bounds(i, tile_slot); view_model_.set_ideal_bounds(i, tile_slot);
...@@ -2252,4 +2289,12 @@ void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, ...@@ -2252,4 +2289,12 @@ void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
target_view->SetAsAttemptedFolderTarget(is_target_folder); target_view->SetAsAttemptedFolderTarget(is_target_folder);
} }
// static
AppsGridView::ScrollAxis AppsGridView::GetScrollAxis() {
// The experimental app list transitions vertically.
return app_list::switches::IsExperimentalAppListEnabled()
? SCROLL_AXIS_VERTICAL
: SCROLL_AXIS_HORIZONTAL;
}
} // namespace app_list } // namespace app_list
...@@ -224,6 +224,8 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -224,6 +224,8 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
DROP_FOR_FOLDER, DROP_FOR_FOLDER,
}; };
enum ScrollAxis { SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL };
// Represents the index to an item view in the grid. // Represents the index to an item view in the grid.
struct Index { struct Index {
Index() : page(-1), slot(-1) {} Index() : page(-1), slot(-1) {}
...@@ -459,6 +461,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -459,6 +461,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
const base::FilePath& path); const base::FilePath& path);
#endif #endif
// Determines whether the grid view scrolls horizontally or vertically.
static ScrollAxis GetScrollAxis();
AppListModel* model_; // Owned by AppListView. AppListModel* model_; // Owned by AppListView.
AppListItemList* item_list_; // Not owned. AppListItemList* item_list_; // Not owned.
AppsGridViewDelegate* delegate_; AppsGridViewDelegate* delegate_;
......
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