diff options
author | calamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 07:27:30 +0000 |
---|---|---|
committer | calamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 07:27:30 +0000 |
commit | 4de9ce62d9bf57d220a9a5fc24353de376730285 (patch) | |
tree | ca7dfe39bc3ae96bcb780c0859609ed39424ff3a /ui/app_list | |
parent | 98cef86fa05d0a8deeabae330881774fb9a826cb (diff) | |
download | chromium_src-4de9ce62d9bf57d220a9a5fc24353de376730285.zip chromium_src-4de9ce62d9bf57d220a9a5fc24353de376730285.tar.gz chromium_src-4de9ce62d9bf57d220a9a5fc24353de376730285.tar.bz2 |
Fix keyboard navigation in app launcher
This causes left/right to page flip on boundary and up/down to do nothing. This
patch also makes out of bounds selections on the last page snap to the last
available item instead of not switching page.
BUG=237092
Review URL: https://chromiumcodereview.appspot.com/15158003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r-- | ui/app_list/views/apps_grid_view.cc | 53 | ||||
-rw-r--r-- | ui/app_list/views/apps_grid_view.h | 2 |
2 files changed, 38 insertions, 17 deletions
diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc index d2fcb92..dd145ca 100644 --- a/ui/app_list/views/apps_grid_view.cc +++ b/ui/app_list/views/apps_grid_view.cc @@ -345,23 +345,23 @@ bool AppsGridView::OnKeyPressed(const ui::KeyEvent& event) { const int forward_dir = base::i18n::IsRTL() ? -1 : 1; switch (event.key_code()) { case ui::VKEY_LEFT: - MoveSelected(0, -forward_dir); + MoveSelected(0, -forward_dir, 0); return true; case ui::VKEY_RIGHT: - MoveSelected(0, forward_dir); + MoveSelected(0, forward_dir, 0); return true; case ui::VKEY_UP: - MoveSelected(0, -cols_); + MoveSelected(0, 0, -1); return true; case ui::VKEY_DOWN: - MoveSelected(0, cols_); + MoveSelected(0, 0, 1); return true; case ui::VKEY_PRIOR: { - MoveSelected(-1, 0); + MoveSelected(-1, 0, 0); return true; } case ui::VKEY_NEXT: { - MoveSelected(1, 0); + MoveSelected(1, 0, 0); return true; } default: @@ -492,20 +492,41 @@ views::View* AppsGridView::GetViewAtIndex(const Index& index) const { return view_model_.view_at(model_index); } -void AppsGridView::MoveSelected(int page_delta, int slot_delta) { +void AppsGridView::MoveSelected(int page_delta, + int slot_x_delta, + int slot_y_delta) { if (!selected_view_) return SetSelectedItemByIndex(Index(pagination_model_->selected_page(), 0)); const Index& selected = GetIndexOfView(selected_view_); - int target_slot = selected.slot + slot_delta; - if (target_slot < 0) { - page_delta += (target_slot + 1) / tiles_per_page() - 1; - if (selected.page > 0) - target_slot = tiles_per_page() + (target_slot + 1) % tiles_per_page() - 1; - } else if (target_slot >= tiles_per_page()) { - page_delta += target_slot / tiles_per_page(); - if (selected.page < pagination_model_->total_pages() - 1) - target_slot %= tiles_per_page(); + int target_slot = selected.slot + slot_x_delta + slot_y_delta * cols_; + + if (selected.slot % cols_ == 0 && slot_x_delta == -1) { + if (selected.page > 0) { + page_delta = -1; + target_slot = selected.slot + cols_ - 1; + } else { + target_slot = selected.slot; + } + } + + if (selected.slot % cols_ == cols_ - 1 && slot_x_delta == 1) { + if (selected.page < pagination_model_->total_pages() - 1) { + page_delta = 1; + target_slot = selected.slot - cols_ + 1; + } else { + target_slot = selected.slot; + } + } + + // Clamp the target slot to the last item if we are moving to the last page + // but our target slot is past the end of the item list. + if (page_delta && + selected.page + page_delta == pagination_model_->total_pages() - 1) { + int last_item_slot = (view_model_.view_size() - 1) % tiles_per_page(); + if (last_item_slot < target_slot) { + target_slot = last_item_slot; + } } int target_page = std::min(pagination_model_->total_pages() - 1, diff --git a/ui/app_list/views/apps_grid_view.h b/ui/app_list/views/apps_grid_view.h index 4fdf481..8a3f090 100644 --- a/ui/app_list/views/apps_grid_view.h +++ b/ui/app_list/views/apps_grid_view.h @@ -147,7 +147,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View, Index GetIndexOfView(const views::View* view) const; views::View* GetViewAtIndex(const Index& index) const; - void MoveSelected(int page_delta, int slot_delta); + void MoveSelected(int page_delta, int slot_x_delta, int slot_y_delta); void CalculateIdealBounds(); void AnimateToIdealBounds(); |