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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/app_list/app_list_model_view.cc
diff --git a/ash/app_list/app_list_model_view.cc b/ash/app_list/app_list_model_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c78ae239ac1690aa07cf49e2004f4c21185832d2
--- /dev/null
+++ b/ash/app_list/app_list_model_view.cc
@@ -0,0 +1,97 @@
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/app_list/app_list_model_view.h"
+
+#include "ash/app_list/app_list_item_view.h"
+#include "ash/app_list/app_list_model.h"
+#include "base/utf_string_conversions.h"
+#include "ui/views/controls/button/text_button.h"
+#include "ui/views/layout/grid_layout.h"
+
+namespace ash {
+
+namespace {
+
+// Calculate preferred tile size for given |content_size| and |num_of_tiles|.
+gfx::Size CalculateTileSize(const gfx::Size& content_size, int num_of_tiles) {
+ const int kIconSizes[] = { 128, 96, 64, 48, 32, 16 };
+
+ int tile_height = 0;
+ int tile_width = 0;
+ for (size_t i = 0; i < arraysize(kIconSizes); ++i) {
+ int icon_size = kIconSizes[i];
+ tile_height = icon_size + 2 * AppListItemView::kIconPadding;
+ tile_width = icon_size * 3;
+
+ int rows = content_size.height() / tile_height - 1;
+ int cols = content_size.width() / tile_width;
+ if (rows * cols >= num_of_tiles)
+ break;
+ }
+
+ return gfx::Size(tile_width, tile_height);
+}
+
+} // namespace
+
+AppListModelView::AppListModelView(AppListModel* model,
+ views::ButtonListener* listener)
+ : model_(model),
+ listener_(listener) {
+ model_->AddObserver(this);
+ Update();
+}
+
+AppListModelView::~AppListModelView() {
+ model_->RemoveObserver(this);
+}
+
+void AppListModelView::Update() {
+ RemoveAllChildViews(true);
+ if (model_->item_count() == 0)
+ return;
+
+ for (int i = 0; i < model_->item_count(); ++i)
+ AddChildView(new AppListItemView(model_->GetItem(i), listener_));
+
+ Layout();
+}
+
+void AppListModelView::Layout() {
+ gfx::Rect rect(GetContentsBounds());
+
+ gfx::Size tile_size = CalculateTileSize(rect.size(), child_count());
+
+ bool pad_top = false;
+ int col_bottom = rect.bottom() - (pad_top ? 0 : tile_size.height());
+ gfx::Rect current_tile(rect.x(), rect.y(),
+ tile_size.width(), tile_size.height());
+
+ for (int i = 0; i < child_count(); ++i) {
+ views::View* view = child_at(i);
+ view->SetBoundsRect(current_tile);
+
+ current_tile.Offset(0, tile_size.height());
+ if (current_tile.bottom() >= col_bottom) {
+ pad_top = !pad_top;
+ col_bottom = rect.bottom() - (pad_top ? 0 : tile_size.height());
+ current_tile.set_x(current_tile.x() + tile_size.width());
+ current_tile.set_y(rect.y() + pad_top ? tile_size.height() : 0);
+ }
+ }
+}
+
+void AppListModelView::ListItemsAdded(int start, int count) {
+ Update();
+}
+
+void AppListModelView::ListItemsRemoved(int start, int count) {
+ Update();
+}
+
+void AppListModelView::ListItemsChanged(int start, int count) {
+ NOTREACHED();
+}
+
+} // namespace ash
« 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