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 ASH_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
6 #define ASH_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include "ash/ash_export.h" | |
10 #include "ash/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 ash { | |
19 | |
20 class AppListItemView; | |
21 class AppListModel; | |
22 class PaginationModel; | |
23 | |
24 // AppListModelView displays the UI for an AppListModel. | |
25 class ASH_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 // 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 | |
37 // Calculate preferred icon size, rows and cols for given |content_size| and | |
38 // |num_of_tiles|. | |
39 static void CalculateLayout(const gfx::Size& content_size, | |
40 int num_of_tiles, | |
41 gfx::Size* icon_size, | |
42 int* rows, | |
43 int* cols); | |
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 private: | |
56 // Updates from model. | |
57 void Update(); | |
58 | |
59 AppListItemView* GetItemViewAtIndex(int index); | |
60 void SetSelectedItemByIndex(int index); | |
61 | |
62 // Overridden from views::View: | |
63 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
64 virtual void Layout() OVERRIDE; | |
65 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | |
66 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | |
67 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | |
68 | |
69 // Overridden from ListModelObserver: | |
70 virtual void ListItemsAdded(int start, int count) OVERRIDE; | |
71 virtual void ListItemsRemoved(int start, int count) OVERRIDE; | |
72 virtual void ListItemsChanged(int start, int count) OVERRIDE; | |
73 | |
74 // Overridden from PaginationModelObserver: | |
75 virtual void TotalPagesChanged() OVERRIDE; | |
76 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; | |
77 | |
78 AppListModel* model_; // Owned by parent AppListView. | |
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_; | |
86 | |
87 int selected_item_index_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(AppListModelView); | |
90 }; | |
91 | |
92 } // namespace ash | |
93 | |
94 #endif // ASH_APP_LIST_APP_LIST_MODEL_VIEW_H_ | |
OLD | NEW |