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