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

Side by Side Diff: ash/app_list/app_list_model_view.cc

Issue 9479031: aura: Implement new app list mock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compilation error Created 8 years, 10 months 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
« no previous file with comments | « ash/app_list/app_list_model_view.h ('k') | ash/app_list/app_list_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Use of this source code is governed by a BSD-style license that can be
2 // found in the LICENSE file.
3
4 #include "ash/app_list/app_list_model_view.h"
5
6 #include "ash/app_list/app_list_item_view.h"
7 #include "ash/app_list/app_list_model.h"
8 #include "base/utf_string_conversions.h"
9 #include "ui/views/controls/button/text_button.h"
10 #include "ui/views/layout/grid_layout.h"
11
12 namespace ash {
13
14 namespace {
15
16 // Calculate preferred tile size for given |content_size| and |num_of_tiles|.
17 gfx::Size CalculateTileSize(const gfx::Size& content_size, int num_of_tiles) {
18 const int kIconSizes[] = { 128, 96, 64, 48, 32, 16 };
19
20 int tile_height = 0;
21 int tile_width = 0;
22 for (size_t i = 0; i < arraysize(kIconSizes); ++i) {
23 int icon_size = kIconSizes[i];
24 tile_height = icon_size + 2 * AppListItemView::kIconPadding;
25 tile_width = icon_size * 3;
26
27 int rows = content_size.height() / tile_height - 1;
28 int cols = content_size.width() / tile_width;
29 if (rows * cols >= num_of_tiles)
30 break;
31 }
32
33 return gfx::Size(tile_width, tile_height);
34 }
35
36 } // namespace
37
38 AppListModelView::AppListModelView(AppListModel* model,
39 views::ButtonListener* listener)
40 : model_(model),
41 listener_(listener) {
42 model_->AddObserver(this);
43 Update();
44 }
45
46 AppListModelView::~AppListModelView() {
47 model_->RemoveObserver(this);
48 }
49
50 void AppListModelView::Update() {
51 RemoveAllChildViews(true);
52 if (model_->item_count() == 0)
53 return;
54
55 for (int i = 0; i < model_->item_count(); ++i)
56 AddChildView(new AppListItemView(model_->GetItem(i), listener_));
57
58 Layout();
59 }
60
61 void AppListModelView::Layout() {
62 gfx::Rect rect(GetContentsBounds());
63
64 gfx::Size tile_size = CalculateTileSize(rect.size(), child_count());
65
66 bool pad_top = false;
67 int col_bottom = rect.bottom() - (pad_top ? 0 : tile_size.height());
68 gfx::Rect current_tile(rect.x(), rect.y(),
69 tile_size.width(), tile_size.height());
70
71 for (int i = 0; i < child_count(); ++i) {
72 views::View* view = child_at(i);
73 view->SetBoundsRect(current_tile);
74
75 current_tile.Offset(0, tile_size.height());
76 if (current_tile.bottom() >= col_bottom) {
77 pad_top = !pad_top;
78 col_bottom = rect.bottom() - (pad_top ? 0 : tile_size.height());
79 current_tile.set_x(current_tile.x() + tile_size.width());
80 current_tile.set_y(rect.y() + pad_top ? tile_size.height() : 0);
81 }
82 }
83 }
84
85 void AppListModelView::ListItemsAdded(int start, int count) {
86 Update();
87 }
88
89 void AppListModelView::ListItemsRemoved(int start, int count) {
90 Update();
91 }
92
93 void AppListModelView::ListItemsChanged(int start, int count) {
94 NOTREACHED();
95 }
96
97 } // namespace ash
OLDNEW
« no previous file with comments | « ash/app_list/app_list_model_view.h ('k') | ash/app_list/app_list_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698