Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ui/app_list/app_list_model.h

Issue 27438002: Store AppItems as pages in AppListModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_H_ 5 #ifndef UI_APP_LIST_APP_LIST_MODEL_H_
6 #define UI_APP_LIST_APP_LIST_MODEL_H_ 6 #define UI_APP_LIST_APP_LIST_MODEL_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "ui/app_list/app_list_export.h" 15 #include "ui/app_list/app_list_export.h"
16 #include "ui/base/models/list_model.h" 16 #include "ui/base/models/list_model.h"
17 17
18 namespace app_list { 18 namespace app_list {
19 19
20 class AppListItemModel; 20 class AppListItemModel;
21 class AppListModelObserver; 21 class AppListModelObserver;
22 class SearchBoxModel; 22 class SearchBoxModel;
23 class SearchResult; 23 class SearchResult;
24 24
25 // Master model of app list that consists of three sub models: Apps, 25 // Master model of app list that consists of three sub models: AppItems,
26 // SearchBoxModel and SearchResults. The Apps sub model owns a list of 26 // SearchBoxModel and SearchResults. The AppItems sub model owns a list of
27 // AppListItemModel and is displayed in the grid view. SearchBoxModel is 27 // AppListItemModel and is displayed in the grid view. SearchBoxModel is
28 // the model for SearchBoxView. SearchResults owns a list of SearchResult. 28 // the model for SearchBoxView. SearchResults owns a list of SearchResult.
29 class APP_LIST_EXPORT AppListModel { 29 class APP_LIST_EXPORT AppListModel {
30 public: 30 public:
31 // A user of the app list. 31 // A user of the app list.
32 struct APP_LIST_EXPORT User { 32 struct APP_LIST_EXPORT User {
33 User(); 33 User();
34 ~User(); 34 ~User();
35 35
36 // Whether or not this user is the current user of the app list. 36 // Whether or not this user is the current user of the app list.
37 bool active; 37 bool active;
38 38
39 // The name of this user. 39 // The name of this user.
40 base::string16 name; 40 base::string16 name;
41 41
42 // The email address of this user. 42 // The email address of this user.
43 base::string16 email; 43 base::string16 email;
44 44
45 // The path to this user's profile directory. 45 // The path to this user's profile directory.
46 base::FilePath profile_path; 46 base::FilePath profile_path;
47 }; 47 };
48 48
49 enum Status { 49 enum Status {
50 STATUS_NORMAL, 50 STATUS_NORMAL,
51 STATUS_SYNCING, // Syncing apps or installing synced apps. 51 STATUS_SYNCING, // Syncing apps or installing synced apps.
52 }; 52 };
53 53
54 typedef ui::ListModel<AppListItemModel> Apps; 54 typedef ui::ListModel<AppListItemModel> AppItems;
55 typedef ui::ListModel<SearchResult> SearchResults; 55 typedef ui::ListModel<SearchResult> SearchResults;
56 typedef std::vector<User> Users; 56 typedef std::vector<User> Users;
57 57
58 AppListModel(); 58 AppListModel();
59 ~AppListModel(); 59 ~AppListModel();
60 60
61 void AddObserver(AppListModelObserver* observer); 61 void AddObserver(AppListModelObserver* observer);
62 void RemoveObserver(AppListModelObserver* observer); 62 void RemoveObserver(AppListModelObserver* observer);
63 63
64 void SetStatus(Status status); 64 void SetStatus(Status status);
65 void SetUsers(const Users& profile_menu_items); 65 void SetUsers(const Users& profile_menu_items);
66 void SetSignedIn(bool signed_in); 66 void SetSignedIn(bool signed_in);
67 67
68 // Find item matching |id|. NOTE: Requires a linear search. 68 // Find item matching |id|. NOTE: Requires a linear search.
69 AppListItemModel* FindItem(const std::string& id); 69 AppListItemModel* FindItem(const std::string& id);
70 70
71 // Adds |item| to |apps_|. Takes ownership of |item|. Uses item->SortOrder() 71 // Returns the item at |page_idx| and |item_idx| or NULL.
72 // to insert in the correct place. TODO(stevenjb): Use synced app list order 72 AppListItemModel* GetItemAt(size_t page_idx, size_t item_idx);
xiyuan 2013/10/18 23:04:08 Propose to use page id instead of index. It would
stevenjb 2013/10/19 01:04:43 I'll think about that. I can see where it makes se
73 // instead of SortOrder when available: crbug.com/305024.
74 void AddItem(AppListItemModel* item);
75 73
76 // Finds |item| in |apps_| and deletes it. 74 // Adds |item| to a page. Takes ownership of |item|. Uses
75 // item->SortOrder() to insert in the correct page and position.
76 // Returns which page the item was added to.
77 // TODO(stevenjb): Use synced app list order instead of SortOrder.
78 // crbug.com/305024.
79 size_t AddItem(AppListItemModel* item);
80
81 // Similar to AddItem, but adds the item to a specific page. If the page is
82 // full the item will be added to the end of the page and the last item in
83 // the page will be pushed to the next page. Returns the index of the page
84 // that the item was added to (|page_idx| or |page_idx| + 1). |page_idx| must
85 // be <= the number of pages, i.e. at most one new page will be added.
86 size_t AddItemToPage(AppListItemModel* item, size_t page_idx);
87
88 // Finds |item| in the model and deletes it.
77 void DeleteItem(const std::string& id); 89 void DeleteItem(const std::string& id);
78 90
79 Apps* apps() { return apps_.get(); } 91 // Deletes item at |item_idx| from page |page_idx|.
92 void DeleteItemAt(size_t page_idx, size_t item_idx);
93
94 // Move item at |item_idx| in |page_idx| to |target_index|
95 // in |target_page_idx|.
96 void MoveItem(size_t page_idx, size_t item_idx,
97 size_t target_page_idx, size_t target_item_idx);
98
99 // Returns the number of apps per page.
100 static size_t GetNumAppsPerPage();
101
102 // Returns the number of app pages.
103 size_t GetNumAppPages() const;
104
105 // Returns a const reference to the items at page |page_idx| which must be
106 // less than GetAppPages().
107 const AppItems& GetAppItemsForPage(size_t page_idx) const;
108
80 SearchBoxModel* search_box() { return search_box_.get(); } 109 SearchBoxModel* search_box() { return search_box_.get(); }
81 SearchResults* results() { return results_.get(); } 110 SearchResults* results() { return results_.get(); }
82 Status status() const { return status_; } 111 Status status() const { return status_; }
83 bool signed_in() const { return signed_in_; } 112 bool signed_in() const { return signed_in_; }
84 113
85 const Users& users() const { 114 const Users& users() const {
86 return users_; 115 return users_;
87 } 116 }
88 117
89 private: 118 private:
90 scoped_ptr<Apps> apps_; 119 class ItemPage;
120
121 // Gets the list of items fpr |page_idx| from item_pages_ and checks ranges.
122 AppItems* app_items(size_t page_idx);
123
124 // Creates/removes a page of items.
125 void AddPage();
126 void RemovePage(size_t idx);
127
128 // Adds |item| to page |page_idx| at |item_idx| and handles overflow.
129 // Returns the page index for |item| which will differ from |page_idx| only
130 // if |item_idx| == GetNumAppsPerPage().
131 size_t AddItemToPageAtIndex(AppListItemModel* item,
132 size_t page_idx, size_t item_idx);
133
134 // Sets the postion of |item| based on its new index.
135 void SetItemPosition(AppListItemModel* item,
136 size_t page_idx, size_t item_idx);
137
138 ScopedVector<ItemPage> item_pages_;
91 139
92 scoped_ptr<SearchBoxModel> search_box_; 140 scoped_ptr<SearchBoxModel> search_box_;
93 scoped_ptr<SearchResults> results_; 141 scoped_ptr<SearchResults> results_;
94 142
95 Users users_; 143 Users users_;
96 144
97 bool signed_in_; 145 bool signed_in_;
98 Status status_; 146 Status status_;
99 ObserverList<AppListModelObserver> observers_; 147 ObserverList<AppListModelObserver> observers_;
100 148
101 DISALLOW_COPY_AND_ASSIGN(AppListModel); 149 DISALLOW_COPY_AND_ASSIGN(AppListModel);
102 }; 150 };
103 151
104 } // namespace app_list 152 } // namespace app_list
105 153
106 #endif // UI_APP_LIST_APP_LIST_MODEL_H_ 154 #endif // UI_APP_LIST_APP_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698