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

Side by Side Diff: ash/common/shelf/shelf_model.h

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
« no previous file with comments | « ash/common/shelf/shelf_locking_manager_unittest.cc ('k') | ash/common/shelf/shelf_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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_COMMON_SHELF_SHELF_MODEL_H_
6 #define ASH_COMMON_SHELF_SHELF_MODEL_H_
7
8 #include <map>
9 #include <memory>
10
11 #include "ash/ash_export.h"
12 #include "ash/common/shelf/shelf_item_types.h"
13 #include "base/macros.h"
14 #include "base/observer_list.h"
15
16 namespace ash {
17
18 class ShelfItemDelegate;
19 class ShelfModelObserver;
20
21 // Model used for shelf items. Owns ShelfItemDelegates but does not create them.
22 class ASH_EXPORT ShelfModel {
23 public:
24 ShelfModel();
25 ~ShelfModel();
26
27 // Cleans up the ShelfItemDelegates.
28 void DestroyItemDelegates();
29
30 // Adds a new item to the model. Returns the resulting index.
31 int Add(const ShelfItem& item);
32
33 // Adds the item. |index| is the requested insertion index, which may be
34 // modified to meet type-based ordering. Returns the actual insertion index.
35 int AddAt(int index, const ShelfItem& item);
36
37 // Removes the item at |index|.
38 void RemoveItemAt(int index);
39
40 // Moves the item at |index| to |target_index|. |target_index| is in terms
41 // of the model *after* the item at |index| is removed.
42 void Move(int index, int target_index);
43
44 // Resets the item at the specified index. The item maintains its existing
45 // id and type.
46 void Set(int index, const ShelfItem& item);
47
48 // Returns the index of the item by id.
49 int ItemIndexByID(ShelfID id) const;
50
51 // Returns the |index| of the item matching |type| in |items_|.
52 // Returns -1 if the matching item is not found.
53 // Note: Requires a linear search.
54 int GetItemIndexForType(ShelfItemType type);
55
56 // Returns the index of the first running application or the index where the
57 // first running application would go if there are no running (non pinned)
58 // applications yet.
59 int FirstRunningAppIndex() const;
60
61 // Returns the index of the first panel or the index where the first panel
62 // would go if there are no panels.
63 int FirstPanelIndex() const;
64
65 // Returns the id assigned to the next item added.
66 ShelfID next_id() const { return next_id_; }
67
68 // Returns a reserved id which will not be used by the |ShelfModel|.
69 ShelfID reserve_external_id() { return next_id_++; }
70
71 // Returns an iterator into items() for the item with the specified id, or
72 // items().end() if there is no item with the specified id.
73 ShelfItems::const_iterator ItemByID(ShelfID id) const;
74
75 const ShelfItems& items() const { return items_; }
76 int item_count() const { return static_cast<int>(items_.size()); }
77
78 // Set |item_delegate| for |id| and takes ownership.
79 void SetShelfItemDelegate(ShelfID id,
80 std::unique_ptr<ShelfItemDelegate> item_delegate);
81
82 // Returns ShelfItemDelegate for |id|, or null if none exists.
83 ShelfItemDelegate* GetShelfItemDelegate(ShelfID id);
84
85 void AddObserver(ShelfModelObserver* observer);
86 void RemoveObserver(ShelfModelObserver* observer);
87
88 private:
89 // Makes sure |index| is in line with the type-based order of items. If that
90 // is not the case, adjusts index by shifting it to the valid range and
91 // returns the new value.
92 int ValidateInsertionIndex(ShelfItemType type, int index) const;
93
94 // Remove and destroy ShelfItemDelegate for |id|.
95 void RemoveShelfItemDelegate(ShelfID id);
96
97 // ID assigned to the next item.
98 ShelfID next_id_;
99
100 ShelfItems items_;
101 base::ObserverList<ShelfModelObserver> observers_;
102
103 std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>>
104 id_to_item_delegate_map_;
105
106 DISALLOW_COPY_AND_ASSIGN(ShelfModel);
107 };
108
109 } // namespace ash
110
111 #endif // ASH_COMMON_SHELF_SHELF_MODEL_H_
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_locking_manager_unittest.cc ('k') | ash/common/shelf/shelf_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698