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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/app_list/app_list_model.h
diff --git a/ui/app_list/app_list_model.h b/ui/app_list/app_list_model.h
index 2238941415820e1b84f7fa516dea7fe42b226581..018954ebc86edcef107b61085b7503471923be77 100644
--- a/ui/app_list/app_list_model.h
+++ b/ui/app_list/app_list_model.h
@@ -22,8 +22,8 @@ class AppListModelObserver;
class SearchBoxModel;
class SearchResult;
-// Master model of app list that consists of three sub models: Apps,
-// SearchBoxModel and SearchResults. The Apps sub model owns a list of
+// Master model of app list that consists of three sub models: AppItems,
+// SearchBoxModel and SearchResults. The AppItems sub model owns a list of
// AppListItemModel and is displayed in the grid view. SearchBoxModel is
// the model for SearchBoxView. SearchResults owns a list of SearchResult.
class APP_LIST_EXPORT AppListModel {
@@ -51,7 +51,7 @@ class APP_LIST_EXPORT AppListModel {
STATUS_SYNCING, // Syncing apps or installing synced apps.
};
- typedef ui::ListModel<AppListItemModel> Apps;
+ typedef ui::ListModel<AppListItemModel> AppItems;
typedef ui::ListModel<SearchResult> SearchResults;
typedef std::vector<User> Users;
@@ -68,15 +68,44 @@ class APP_LIST_EXPORT AppListModel {
// Find item matching |id|. NOTE: Requires a linear search.
AppListItemModel* FindItem(const std::string& id);
- // Adds |item| to |apps_|. Takes ownership of |item|. Uses item->SortOrder()
- // to insert in the correct place. TODO(stevenjb): Use synced app list order
- // instead of SortOrder when available: crbug.com/305024.
- void AddItem(AppListItemModel* item);
+ // Returns the item at |page_idx| and |item_idx| or NULL.
+ 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
- // Finds |item| in |apps_| and deletes it.
+ // Adds |item| to a page. Takes ownership of |item|. Uses
+ // item->SortOrder() to insert in the correct page and position.
+ // Returns which page the item was added to.
+ // TODO(stevenjb): Use synced app list order instead of SortOrder.
+ // crbug.com/305024.
+ size_t AddItem(AppListItemModel* item);
+
+ // Similar to AddItem, but adds the item to a specific page. If the page is
+ // full the item will be added to the end of the page and the last item in
+ // the page will be pushed to the next page. Returns the index of the page
+ // that the item was added to (|page_idx| or |page_idx| + 1). |page_idx| must
+ // be <= the number of pages, i.e. at most one new page will be added.
+ size_t AddItemToPage(AppListItemModel* item, size_t page_idx);
+
+ // Finds |item| in the model and deletes it.
void DeleteItem(const std::string& id);
- Apps* apps() { return apps_.get(); }
+ // Deletes item at |item_idx| from page |page_idx|.
+ void DeleteItemAt(size_t page_idx, size_t item_idx);
+
+ // Move item at |item_idx| in |page_idx| to |target_index|
+ // in |target_page_idx|.
+ void MoveItem(size_t page_idx, size_t item_idx,
+ size_t target_page_idx, size_t target_item_idx);
+
+ // Returns the number of apps per page.
+ static size_t GetNumAppsPerPage();
+
+ // Returns the number of app pages.
+ size_t GetNumAppPages() const;
+
+ // Returns a const reference to the items at page |page_idx| which must be
+ // less than GetAppPages().
+ const AppItems& GetAppItemsForPage(size_t page_idx) const;
+
SearchBoxModel* search_box() { return search_box_.get(); }
SearchResults* results() { return results_.get(); }
Status status() const { return status_; }
@@ -86,8 +115,27 @@ class APP_LIST_EXPORT AppListModel {
return users_;
}
- private:
- scoped_ptr<Apps> apps_;
+private:
+ class ItemPage;
+
+ // Gets the list of items fpr |page_idx| from item_pages_ and checks ranges.
+ AppItems* app_items(size_t page_idx);
+
+ // Creates/removes a page of items.
+ void AddPage();
+ void RemovePage(size_t idx);
+
+ // Adds |item| to page |page_idx| at |item_idx| and handles overflow.
+ // Returns the page index for |item| which will differ from |page_idx| only
+ // if |item_idx| == GetNumAppsPerPage().
+ size_t AddItemToPageAtIndex(AppListItemModel* item,
+ size_t page_idx, size_t item_idx);
+
+ // Sets the postion of |item| based on its new index.
+ void SetItemPosition(AppListItemModel* item,
+ size_t page_idx, size_t item_idx);
+
+ ScopedVector<ItemPage> item_pages_;
scoped_ptr<SearchBoxModel> search_box_;
scoped_ptr<SearchResults> results_;

Powered by Google App Engine
This is Rietveld 408576698