Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: ui/aura_shell/app_list/tiles_page_view.cc

Issue 8890049: [Aura] Implement views-based applist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and refactored Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura_shell/app_list/tiles_page_view.h"
6
7 #include "ui/aura_shell/app_list/app_list_item_group_model.h"
8 #include "ui/aura_shell/app_list/tile_view.h"
9 #include "ui/views/layout/grid_layout.h"
10
11 namespace aura_shell {
12
13 TilesPageView::TilesPageView(AppListItemGroupModel* model)
14 : model_(model),
15 tiles_per_row_(0),
16 focused_index_(0) {
17 Update();
18 }
19
20 TilesPageView::~TilesPageView() {
21 }
22
23 void TilesPageView::SetTilesPerRow(int tiles_per_row) {
24 if (tiles_per_row_ == tiles_per_row)
25 return;
26
27 tiles_per_row_ = tiles_per_row;
28 Update();
29 }
30
31 void TilesPageView::Update() {
32 RemoveAllChildViews(true);
33 if (model_->item_count() == 0 || tiles_per_row_ == 0)
34 return;
35
36 views::GridLayout* layout = new views::GridLayout(this);
37 SetLayoutManager(layout);
38
39 const int kTileColumnSetId = 0;
40 views::ColumnSet* column_set = layout->AddColumnSet(kTileColumnSetId);
41 for (int i = 0; i < tiles_per_row_; ++i) {
42 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
43 views::GridLayout::USE_PREF, 0, 0);
44 }
45
46 for (int i = 0; i < model_->item_count(); ++i) {
47 if (i % tiles_per_row_ == 0)
48 layout->StartRow(0, kTileColumnSetId);
49
50 layout->AddView(new TileView(model_->item_at(i)));
51 }
52 }
53
54 views::View* TilesPageView::GetFocusedTile() {
55 return focused_index_ < child_count() ? child_at(focused_index_) : NULL;
56 }
57
58 void TilesPageView::UpdateFocusedTile(views::View* tile) {
59 for (int i = 0; i < child_count(); ++i) {
60 if (child_at(i) == tile) {
61 focused_index_ = i;
62 break;
63 }
64 }
65 }
66
67 void TilesPageView::SetFocusedTileByIndex(int index) {
68 index = std::max(0, std::min(child_count() - 1, index));
69 if (index != focused_index_)
70 child_at(index)->RequestFocus();
71 }
72
73 bool TilesPageView::OnKeyPressed(const views::KeyEvent& event) {
74 if (!event.IsControlDown() && !event.IsShiftDown() && !event.IsAltDown()) {
75 // Arrow keys navigates in tile grid.
76 switch (event.key_code()) {
77 case ui::VKEY_LEFT:
78 if (focused_index_ > 0)
79 SetFocusedTileByIndex(focused_index_ - 1);
80 return true;
81 case ui::VKEY_RIGHT:
82 if (focused_index_ + 1 < child_count())
83 SetFocusedTileByIndex(focused_index_ + 1);
84 return true;
85 case ui::VKEY_UP:
86 if (focused_index_ - tiles_per_row_ >= 0)
87 SetFocusedTileByIndex(focused_index_ - tiles_per_row_);
88 return true;
89 case ui::VKEY_DOWN:
90 if (focused_index_ + tiles_per_row_ < child_count())
91 SetFocusedTileByIndex(focused_index_ + tiles_per_row_);
92 return true;
93 default:
94 break;
95 }
96 }
97
98 return false;
99 }
100
101 void TilesPageView::ListItemsAdded(int start, int count) {
102 Update();
103 }
104
105 void TilesPageView::ListItemsRemoved(int start, int count) {
106 Update();
107 }
108
109 void TilesPageView::ListItemsChanged(int start, int count) {
110 NOTREACHED();
111 }
112
113 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698