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