| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
| 6 #define UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "ui/app_list/app_list_export.h" | |
| 10 #include "ui/app_list/pagination_model_observer.h" | |
| 11 #include "ui/base/models/list_model_observer.h" | |
| 12 #include "ui/views/view.h" | |
| 13 | |
| 14 namespace views { | |
| 15 class ButtonListener; | |
| 16 } | |
| 17 | |
| 18 namespace app_list { | |
| 19 | |
| 20 class AppListItemView; | |
| 21 class AppListModel; | |
| 22 class PaginationModel; | |
| 23 | |
| 24 // AppListModelView displays the UI for an AppListModel. | |
| 25 class APP_LIST_EXPORT AppListModelView : public views::View, | |
| 26 public ui::ListModelObserver, | |
| 27 public PaginationModelObserver { | |
| 28 public: | |
| 29 AppListModelView(views::ButtonListener* listener, | |
| 30 PaginationModel* pagination_model); | |
| 31 virtual ~AppListModelView(); | |
| 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 | |
| 42 // is no longer called to dynamically choosing those layout params. | |
| 43 void SetLayout(int icon_size, int cols, int rows_per_page); | |
| 44 | |
| 45 // Sets |model| to use. Note this does not take ownership of |model|. | |
| 46 void SetModel(AppListModel* model); | |
| 47 | |
| 48 void SetSelectedItem(AppListItemView* item); | |
| 49 void ClearSelectedItem(AppListItemView* item); | |
| 50 | |
| 51 int tiles_per_page() const { | |
| 52 return cols_ * rows_per_page_; | |
| 53 } | |
| 54 | |
| 55 bool fixed_layout() const { | |
| 56 return fixed_layout_; | |
| 57 } | |
| 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: | |
| 67 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 68 virtual void Layout() OVERRIDE; | |
| 69 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | |
| 70 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | |
| 71 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | |
| 72 | |
| 73 // Overridden from ListModelObserver: | |
| 74 virtual void ListItemsAdded(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; | |
| 77 | |
| 78 // Overridden from PaginationModelObserver: | |
| 79 virtual void TotalPagesChanged() OVERRIDE; | |
| 80 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; | |
| 81 | |
| 82 AppListModel* model_; // Owned by parent AppListView. | |
| 83 views::ButtonListener* listener_; | |
| 84 PaginationModel* pagination_model_; // Owned by AppListView. | |
| 85 | |
| 86 bool fixed_layout_; | |
| 87 gfx::Size icon_size_; | |
| 88 int cols_; | |
| 89 int rows_per_page_; | |
| 90 | |
| 91 int selected_item_index_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(AppListModelView); | |
| 94 }; | |
| 95 | |
| 96 } // namespace app_list | |
| 97 | |
| 98 #endif // UI_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
| OLD | NEW |