Chromium Code Reviews| 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 #ifndef UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | 5 #ifndef UI_APP_LIST_APPS_GRID_VIEW_H_ |
| 6 #define UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | 6 #define UI_APP_LIST_APPS_GRID_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "ui/app_list/app_list_export.h" | 9 #include "ui/app_list/app_list_export.h" |
| 10 #include "ui/app_list/app_list_model.h" | |
| 10 #include "ui/app_list/pagination_model_observer.h" | 11 #include "ui/app_list/pagination_model_observer.h" |
| 11 #include "ui/base/models/list_model_observer.h" | 12 #include "ui/base/models/list_model_observer.h" |
| 12 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 class ButtonListener; | 16 class ButtonListener; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace app_list { | 19 namespace app_list { |
| 19 | 20 |
| 20 class AppListItemView; | 21 class AppListItemView; |
| 21 class AppListModel; | |
| 22 class PaginationModel; | 22 class PaginationModel; |
| 23 | 23 |
| 24 // AppListModelView displays the UI for an AppListModel. | 24 // AppsGridView displays a grid for AppListModel::Apps sub model. |
| 25 class APP_LIST_EXPORT AppListModelView : public views::View, | 25 class APP_LIST_EXPORT AppsGridView : public views::View, |
| 26 public ui::ListModelObserver, | 26 public ui::ListModelObserver, |
| 27 public PaginationModelObserver { | 27 public PaginationModelObserver { |
| 28 public: | 28 public: |
| 29 AppListModelView(views::ButtonListener* listener, | 29 AppsGridView(views::ButtonListener* listener, |
| 30 PaginationModel* pagination_model); | 30 PaginationModel* pagination_model); |
|
tfarina
2012/05/25 19:17:23
nit: fix indent here.
| |
| 31 virtual ~AppListModelView(); | 31 virtual ~AppsGridView(); |
| 32 | 32 |
| 33 // Calculate preferred icon size, rows and cols for given |content_size| and | 33 // Calculate preferred icon size, rows and cols for given |content_size| and |
| 34 // |num_of_tiles|. | 34 // |num_of_tiles|. |
| 35 static void CalculateLayout(const gfx::Size& content_size, | 35 static void CalculateLayout(const gfx::Size& content_size, |
| 36 int num_of_tiles, | 36 int num_of_tiles, |
| 37 gfx::Size* icon_size, | 37 gfx::Size* icon_size, |
| 38 int* rows, | 38 int* rows, |
| 39 int* cols); | 39 int* cols); |
| 40 | 40 |
| 41 // Sets fixed layout parameters. After setting this, CalculateLayout below | 41 // Sets fixed layout parameters. After setting this, CalculateLayout below |
| 42 // is no longer called to dynamically choosing those layout params. | 42 // is no longer called to dynamically choosing those layout params. |
| 43 void SetLayout(int icon_size, int cols, int rows_per_page); | 43 void SetLayout(int icon_size, int cols, int rows_per_page); |
| 44 | 44 |
| 45 // Sets |model| to use. Note this does not take ownership of |model|. | 45 // Sets |model| to use. Note this does not take ownership of |model|. |
| 46 void SetModel(AppListModel* model); | 46 void SetModel(AppListModel::Apps* model); |
| 47 | 47 |
| 48 void SetSelectedItem(AppListItemView* item); | 48 void SetSelectedItem(AppListItemView* item); |
| 49 void ClearSelectedItem(AppListItemView* item); | 49 void ClearSelectedItem(AppListItemView* item); |
| 50 | 50 |
| 51 int tiles_per_page() const { | 51 int tiles_per_page() const { |
| 52 return cols_ * rows_per_page_; | 52 return cols_ * rows_per_page_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool fixed_layout() const { | 55 bool fixed_layout() const { |
| 56 return fixed_layout_; | 56 return fixed_layout_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 private: | |
| 60 // Updates from model. | |
| 61 void Update(); | |
| 62 | |
| 63 AppListItemView* GetItemViewAtIndex(int index); | |
| 64 void SetSelectedItemByIndex(int index); | |
| 65 | |
| 66 // Overridden from views::View: | 59 // Overridden from views::View: |
| 67 virtual gfx::Size GetPreferredSize() OVERRIDE; | 60 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 68 virtual void Layout() OVERRIDE; | 61 virtual void Layout() OVERRIDE; |
| 69 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | 62 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; |
| 70 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | 63 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; |
| 71 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | 64 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; |
| 72 | 65 |
| 66 private: | |
| 67 // Updates from model. | |
| 68 void Update(); | |
| 69 | |
| 70 AppListItemView* GetItemViewAtIndex(int index); | |
| 71 void SetSelectedItemByIndex(int index); | |
| 72 | |
| 73 // Overridden from ListModelObserver: | 73 // Overridden from ListModelObserver: |
| 74 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; | 74 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; |
| 75 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; | 75 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; |
| 76 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; | 76 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; |
| 77 | 77 |
| 78 // Overridden from PaginationModelObserver: | 78 // Overridden from PaginationModelObserver: |
| 79 virtual void TotalPagesChanged() OVERRIDE; | 79 virtual void TotalPagesChanged() OVERRIDE; |
| 80 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; | 80 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; |
| 81 | 81 |
| 82 AppListModel* model_; // Owned by parent AppListView. | 82 AppListModel::Apps* model_; // Owned by AppListModel. |
| 83 views::ButtonListener* listener_; | 83 views::ButtonListener* listener_; |
| 84 PaginationModel* pagination_model_; // Owned by AppListView. | 84 PaginationModel* pagination_model_; // Owned by AppListView. |
| 85 | 85 |
| 86 bool fixed_layout_; | 86 bool fixed_layout_; |
| 87 gfx::Size icon_size_; | 87 gfx::Size icon_size_; |
| 88 int cols_; | 88 int cols_; |
| 89 int rows_per_page_; | 89 int rows_per_page_; |
| 90 | 90 |
| 91 int selected_item_index_; | 91 int selected_item_index_; |
| 92 | 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(AppListModelView); | 93 DISALLOW_COPY_AND_ASSIGN(AppsGridView); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace app_list | 96 } // namespace app_list |
| 97 | 97 |
| 98 #endif // UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | 98 #endif // UI_APP_LIST_APPS_GRID_VIEW_H_ |
| OLD | NEW |