OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/app_list/app_list_model_view.h" | 5 #include "ui/app_list/app_list_model_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/app_list/app_list_item_view.h" | 9 #include "ui/app_list/app_list_item_view.h" |
10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
11 #include "ui/app_list/pagination_model.h" | 11 #include "ui/app_list/pagination_model.h" |
| 12 #include "ui/views/border.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 // Padding space in pixels for fixed layout. |
| 17 const int kTopLeftRightPadding = 15; |
| 18 const int kBottomPadding = 30; |
| 19 |
| 20 // Preferred tile size when showing in fixed layout. |
| 21 const int kPreferredTileWidth = 80; |
| 22 const int kPreferredTileHeight = 88; |
| 23 |
| 24 } // namespace |
12 | 25 |
13 namespace app_list { | 26 namespace app_list { |
14 | 27 |
15 AppListModelView::AppListModelView(views::ButtonListener* listener, | 28 AppListModelView::AppListModelView(views::ButtonListener* listener, |
16 PaginationModel* pagination_model) | 29 PaginationModel* pagination_model) |
17 : model_(NULL), | 30 : model_(NULL), |
18 listener_(listener), | 31 listener_(listener), |
19 pagination_model_(pagination_model), | 32 pagination_model_(pagination_model), |
20 fixed_layout_(false), | 33 fixed_layout_(false), |
21 cols_(0), | 34 cols_(0), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 *cols = std::max(content_size.width() / tile_size.width(), 1); | 94 *cols = std::max(content_size.width() / tile_size.width(), 1); |
82 *rows = (num_of_tiles - 1) / (*cols) + 1; | 95 *rows = (num_of_tiles - 1) / (*cols) + 1; |
83 } | 96 } |
84 | 97 |
85 void AppListModelView::SetLayout(int icon_size, int cols, int rows_per_page) { | 98 void AppListModelView::SetLayout(int icon_size, int cols, int rows_per_page) { |
86 fixed_layout_ = true; | 99 fixed_layout_ = true; |
87 | 100 |
88 icon_size_.SetSize(icon_size, icon_size); | 101 icon_size_.SetSize(icon_size, icon_size); |
89 cols_ = cols; | 102 cols_ = cols; |
90 rows_per_page_ = rows_per_page; | 103 rows_per_page_ = rows_per_page; |
| 104 |
| 105 set_border(views::Border::CreateEmptyBorder(kTopLeftRightPadding, |
| 106 kTopLeftRightPadding, |
| 107 kBottomPadding, |
| 108 kTopLeftRightPadding)); |
91 } | 109 } |
92 | 110 |
93 void AppListModelView::SetModel(AppListModel* model) { | 111 void AppListModelView::SetModel(AppListModel* model) { |
94 if (model_) | 112 if (model_) |
95 model_->RemoveObserver(this); | 113 model_->RemoveObserver(this); |
96 | 114 |
97 model_ = model; | 115 model_ = model; |
98 if (model_) | 116 if (model_) |
99 model_->AddObserver(this); | 117 model_->AddObserver(this); |
100 Update(); | 118 Update(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 162 |
145 if (tiles_per_page()) | 163 if (tiles_per_page()) |
146 pagination_model_->SelectPage(selected_item_index_ / tiles_per_page()); | 164 pagination_model_->SelectPage(selected_item_index_ / tiles_per_page()); |
147 } | 165 } |
148 } | 166 } |
149 | 167 |
150 gfx::Size AppListModelView::GetPreferredSize() { | 168 gfx::Size AppListModelView::GetPreferredSize() { |
151 if (!fixed_layout_) | 169 if (!fixed_layout_) |
152 return gfx::Size(); | 170 return gfx::Size(); |
153 | 171 |
154 gfx::Size tile_size = AppListItemView::GetPreferredSizeForIconSize( | 172 gfx::Insets insets(GetInsets()); |
155 icon_size_); | 173 gfx::Size tile_size = gfx::Size(kPreferredTileWidth, kPreferredTileHeight); |
156 return gfx::Size(tile_size.width() * cols_, | 174 return gfx::Size(tile_size.width() * cols_ + insets.width(), |
157 tile_size.height() * rows_per_page_); | 175 tile_size.height() * rows_per_page_ + insets.height()); |
158 } | 176 } |
159 | 177 |
160 void AppListModelView::Layout() { | 178 void AppListModelView::Layout() { |
161 gfx::Rect rect(GetContentsBounds()); | 179 gfx::Rect rect(GetContentsBounds()); |
162 if (rect.IsEmpty() || child_count() == 0) | 180 if (rect.IsEmpty() || child_count() == 0) |
163 return; | 181 return; |
164 | 182 |
165 gfx::Size tile_size; | 183 gfx::Size tile_size; |
166 if (fixed_layout_) { | 184 if (fixed_layout_) { |
167 tile_size = AppListItemView::GetPreferredSizeForIconSize(icon_size_); | 185 tile_size = gfx::Size(kPreferredTileWidth, kPreferredTileHeight); |
168 } else { | 186 } else { |
169 int rows = 0; | 187 int rows = 0; |
170 CalculateLayout(rect.size(), child_count(), &icon_size_, &rows, &cols_); | 188 CalculateLayout(rect.size(), child_count(), &icon_size_, &rows, &cols_); |
171 | 189 |
172 tile_size = AppListItemView::GetPreferredSizeForIconSize( | 190 tile_size = AppListItemView::GetPreferredSizeForIconSize( |
173 icon_size_); | 191 icon_size_); |
174 rows_per_page_ = tile_size.height() ? | 192 rows_per_page_ = tile_size.height() ? |
175 std::max(rect.height() / tile_size.height(), 1) : 1; | 193 std::max(rect.height() / tile_size.height(), 1) : 1; |
176 | 194 |
177 tile_size.set_width(std::max(rect.width() / (cols_ + 1), | 195 tile_size.set_width(std::max(rect.width() / (cols_ + 1), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 318 } |
301 | 319 |
302 void AppListModelView::TotalPagesChanged() { | 320 void AppListModelView::TotalPagesChanged() { |
303 } | 321 } |
304 | 322 |
305 void AppListModelView::SelectedPageChanged(int old_selected, int new_selected) { | 323 void AppListModelView::SelectedPageChanged(int old_selected, int new_selected) { |
306 Layout(); | 324 Layout(); |
307 } | 325 } |
308 | 326 |
309 } // namespace app_list | 327 } // namespace app_list |
OLD | NEW |