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

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: . 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..0bf3cf07781d957f1787e2a9081d2ef86e78802f 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,42 @@ 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);
- // 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, will return the index of the next page. |page_idx| must be
+ // <= 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.
+ 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& GetAppItems(size_t page_idx) const;
+
SearchBoxModel* search_box() { return search_box_.get(); }
SearchResults* results() { return results_.get(); }
Status status() const { return status_; }
@@ -86,8 +113,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