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

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: . 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);
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, will return the index of the next page. |page_idx| must be
83 // <= the number of pages, i.e. at most one new page will be added.
koz (OOO until 15th September) 2013/10/18 05:17:17 What does it return when the page isn't full? -1?
stevenjb 2013/10/18 22:14:26 Clarified.
84 size_t AddItemToPage(AppListItemModel* item, size_t page_idx);
85
86 // Finds |item| in the model and deletes it.
77 void DeleteItem(const std::string& id); 87 void DeleteItem(const std::string& id);
78 88
79 Apps* apps() { return apps_.get(); } 89 // Deletes item at |item_idx| from page |page_idx|.
90 void DeleteItemAt(size_t page_idx, size_t item_idx);
91
92 // Move item at |item_idx| in |page_idx| to |target_index|
93 // in |target_page_idx|.
94 void MoveItem(size_t page_idx, size_t item_idx,
95 size_t target_page_idx, size_t target_item_idx);
96
97 // Returns the number of apps per page.
98 static size_t GetNumAppsPerPage();
99
100 // Returns the number of app pages.
101 size_t GetNumAppPages() const;
102
103 // Returns a const reference to the items at page |page_idx| which must be
104 // less than GetAppPages().
105 const AppItems& GetAppItems(size_t page_idx) const;
106
80 SearchBoxModel* search_box() { return search_box_.get(); } 107 SearchBoxModel* search_box() { return search_box_.get(); }
81 SearchResults* results() { return results_.get(); } 108 SearchResults* results() { return results_.get(); }
82 Status status() const { return status_; } 109 Status status() const { return status_; }
83 bool signed_in() const { return signed_in_; } 110 bool signed_in() const { return signed_in_; }
84 111
85 const Users& users() const { 112 const Users& users() const {
86 return users_; 113 return users_;
87 } 114 }
88 115
89 private: 116 private:
90 scoped_ptr<Apps> apps_; 117 class ItemPage;
118
119 // Gets the list of items fpr |page_idx| from item_pages_ and checks ranges.
120 AppItems* app_items(size_t page_idx);
121
122 // Creates/removes a page of items.
123 void AddPage();
124 void RemovePage(size_t idx);
125
126 // Adds |item| to page |page_idx| at |item_idx| and handles overflow.
127 // Returns the page index for |item| which will differ from |page_idx| only
128 // if |item_idx| == GetNumAppsPerPage().
129 size_t AddItemToPageAtIndex(AppListItemModel* item,
130 size_t page_idx, size_t item_idx);
131
132 // Sets the postion of |item| based on its new index.
133 void SetItemPosition(AppListItemModel* item,
134 size_t page_idx, size_t item_idx);
135
136 ScopedVector<ItemPage> item_pages_;
91 137
92 scoped_ptr<SearchBoxModel> search_box_; 138 scoped_ptr<SearchBoxModel> search_box_;
93 scoped_ptr<SearchResults> results_; 139 scoped_ptr<SearchResults> results_;
94 140
95 Users users_; 141 Users users_;
96 142
97 bool signed_in_; 143 bool signed_in_;
98 Status status_; 144 Status status_;
99 ObserverList<AppListModelObserver> observers_; 145 ObserverList<AppListModelObserver> observers_;
100 146
101 DISALLOW_COPY_AND_ASSIGN(AppListModel); 147 DISALLOW_COPY_AND_ASSIGN(AppListModel);
102 }; 148 };
103 149
104 } // namespace app_list 150 } // namespace app_list
105 151
106 #endif // UI_APP_LIST_APP_LIST_MODEL_H_ 152 #endif // UI_APP_LIST_APP_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698