third_party: Add OWNERS for re2 library.
[chromium-blink-merge.git] / ash / shelf / shelf_model.h
blob8c683c6e0f045c27b69cd5f6bf1563bde5a3da7f
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.
5 #ifndef ASH_SHELF_SHELF_MODEL_H_
6 #define ASH_SHELF_SHELF_MODEL_H_
8 #include "ash/ash_export.h"
9 #include "ash/shelf/shelf_item_types.h"
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
13 namespace ash {
15 class ShelfModelObserver;
17 // Model used by ShelfView.
18 class ASH_EXPORT ShelfModel {
19 public:
20 enum Status {
21 STATUS_NORMAL,
22 // A status that indicates apps are syncing/loading.
23 STATUS_LOADING,
26 ShelfModel();
27 ~ShelfModel();
29 // Adds a new item to the model. Returns the resulting index.
30 int Add(const ShelfItem& item);
32 // Adds the item. |index| is the requested insertion index, which may be
33 // modified to meet type-based ordering. Returns the actual insertion index.
34 int AddAt(int index, const ShelfItem& item);
36 // Removes the item at |index|.
37 void RemoveItemAt(int index);
39 // Moves the item at |index| to |target_index|. |target_index| is in terms
40 // of the model *after* the item at |index| is removed.
41 void Move(int index, int target_index);
43 // Resets the item at the specified index. The item maintains its existing
44 // id and type.
45 void Set(int index, const ShelfItem& item);
47 // Returns the index of the item by id.
48 int ItemIndexByID(ShelfID id) const;
50 // Returns the |index| of the item matching |type| in |items_|.
51 // Returns -1 if the matching item is not found.
52 // Note: Requires a linear search.
53 int GetItemIndexForType(ShelfItemType type);
55 // Returns the index of the first running application or the index where the
56 // first running application would go if there are no running (non pinned)
57 // applications yet.
58 int FirstRunningAppIndex() const;
60 // Returns the index of the first panel or the index where the first panel
61 // would go if there are no panels.
62 int FirstPanelIndex() const;
64 // Returns the id assigned to the next item added.
65 ShelfID next_id() const { return next_id_; }
67 // Returns a reserved id which will not be used by the |ShelfModel|.
68 ShelfID reserve_external_id() { return next_id_++; }
70 // Returns an iterator into items() for the item with the specified id, or
71 // items().end() if there is no item with the specified id.
72 ShelfItems::const_iterator ItemByID(ShelfID id) const;
74 const ShelfItems& items() const { return items_; }
75 int item_count() const { return static_cast<int>(items_.size()); }
77 void SetStatus(Status status);
78 Status status() const { return status_; }
80 void AddObserver(ShelfModelObserver* observer);
81 void RemoveObserver(ShelfModelObserver* observer);
83 private:
84 // Makes sure |index| is in line with the type-based order of items. If that
85 // is not the case, adjusts index by shifting it to the valid range and
86 // returns the new value.
87 int ValidateInsertionIndex(ShelfItemType type, int index) const;
89 // ID assigned to the next item.
90 ShelfID next_id_;
92 ShelfItems items_;
93 Status status_;
94 base::ObserverList<ShelfModelObserver> observers_;
96 DISALLOW_COPY_AND_ASSIGN(ShelfModel);
99 } // namespace ash
101 #endif // ASH_SHELF_SHELF_MODEL_H_