OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 ASH_SHELF_SHELF_MODEL_H_ | 5 #ifndef ASH_SHELF_SHELF_MODEL_H_ |
6 #define ASH_SHELF_SHELF_MODEL_H_ | 6 #define ASH_SHELF_SHELF_MODEL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 12 #include "ash/public/cpp/app_launch_id.h" |
12 #include "ash/public/cpp/shelf_item.h" | 13 #include "ash/public/cpp/shelf_item.h" |
13 #include "ash/public/interfaces/shelf.mojom.h" | 14 #include "ash/public/interfaces/shelf.mojom.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 | 19 |
19 class ShelfItemDelegate; | 20 class ShelfItemDelegate; |
20 class ShelfModelObserver; | 21 class ShelfModelObserver; |
21 | 22 |
22 // Model used for shelf items. Owns ShelfItemDelegates but does not create them. | 23 // Model used for shelf items. Owns ShelfItemDelegates but does not create them. |
23 class ASH_EXPORT ShelfModel { | 24 class ASH_EXPORT ShelfModel { |
24 public: | 25 public: |
25 ShelfModel(); | 26 ShelfModel(); |
26 ~ShelfModel(); | 27 ~ShelfModel(); |
27 | 28 |
| 29 // Get the shelf ID from an application ID. Returns kInvalidShelfID if the |
| 30 // app id is unknown, or has no associated ShelfID. |
| 31 ShelfID GetShelfIDForAppID(const std::string& app_id); |
| 32 |
| 33 // Get the shelf ID from an application ID and a launch ID. |
| 34 // The launch ID can be passed to an app when launched in order to support |
| 35 // multiple shelf items per app. This id is used together with the app_id to |
| 36 // uniquely identify each shelf item that has the same app_id. |
| 37 // For example, a single virtualization app might want to show different |
| 38 // shelf icons for different remote apps. Returns kInvalidShelfID if the app |
| 39 // id is unknown or has no associated ShelfID. |
| 40 ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, |
| 41 const std::string& launch_id); |
| 42 |
| 43 // Get the application ID for a given shelf ID. Returns an empty string for |
| 44 // an unknown or invalid ShelfID. |
| 45 const std::string& GetAppIDForShelfID(ShelfID id); |
| 46 |
| 47 // Pins an app with |app_id| to shelf. A running instance will get pinned. |
| 48 // In case there is no running instance a new shelf item is created and |
| 49 // pinned. |
| 50 void PinAppWithID(const std::string& app_id); |
| 51 |
| 52 // Check if the app with |app_id_| is pinned to the shelf. |
| 53 bool IsAppPinned(const std::string& app_id); |
| 54 |
| 55 // Unpins app item with |app_id|. |
| 56 void UnpinAppWithID(const std::string& app_id); |
| 57 |
28 // Cleans up the ShelfItemDelegates. | 58 // Cleans up the ShelfItemDelegates. |
29 void DestroyItemDelegates(); | 59 void DestroyItemDelegates(); |
30 | 60 |
31 // Adds a new item to the model. Returns the resulting index. | 61 // Adds a new item to the model. Returns the resulting index. |
32 int Add(const ShelfItem& item); | 62 int Add(const ShelfItem& item); |
33 | 63 |
34 // Adds the item. |index| is the requested insertion index, which may be | 64 // Adds the item. |index| is the requested insertion index, which may be |
35 // modified to meet type-based ordering. Returns the actual insertion index. | 65 // modified to meet type-based ordering. Returns the actual insertion index. |
36 int AddAt(int index, const ShelfItem& item); | 66 int AddAt(int index, const ShelfItem& item); |
37 | 67 |
(...skipping 21 matching lines...) Expand all Loading... |
59 // applications yet. | 89 // applications yet. |
60 int FirstRunningAppIndex() const; | 90 int FirstRunningAppIndex() const; |
61 | 91 |
62 // Returns the index of the first panel or the index where the first panel | 92 // Returns the index of the first panel or the index where the first panel |
63 // would go if there are no panels. | 93 // would go if there are no panels. |
64 int FirstPanelIndex() const; | 94 int FirstPanelIndex() const; |
65 | 95 |
66 // Returns the id assigned to the next item added. | 96 // Returns the id assigned to the next item added. |
67 ShelfID next_id() const { return next_id_; } | 97 ShelfID next_id() const { return next_id_; } |
68 | 98 |
69 // Returns a reserved id which will not be used by the |ShelfModel|. | |
70 ShelfID reserve_external_id() { return next_id_++; } | |
71 | |
72 // Returns an iterator into items() for the item with the specified id, or | 99 // Returns an iterator into items() for the item with the specified id, or |
73 // items().end() if there is no item with the specified id. | 100 // items().end() if there is no item with the specified id. |
74 ShelfItems::const_iterator ItemByID(ShelfID id) const; | 101 ShelfItems::const_iterator ItemByID(ShelfID id) const; |
75 | 102 |
76 const ShelfItems& items() const { return items_; } | 103 const ShelfItems& items() const { return items_; } |
77 int item_count() const { return static_cast<int>(items_.size()); } | 104 int item_count() const { return static_cast<int>(items_.size()); } |
78 | 105 |
79 // Set |item_delegate| for |id| and takes ownership. | 106 // Set |item_delegate| for |id| and takes ownership. |
80 void SetShelfItemDelegate(ShelfID id, | 107 void SetShelfItemDelegate(ShelfID id, |
81 std::unique_ptr<ShelfItemDelegate> item_delegate); | 108 std::unique_ptr<ShelfItemDelegate> item_delegate); |
(...skipping 18 matching lines...) Expand all Loading... |
100 | 127 |
101 std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>> | 128 std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>> |
102 id_to_item_delegate_map_; | 129 id_to_item_delegate_map_; |
103 | 130 |
104 DISALLOW_COPY_AND_ASSIGN(ShelfModel); | 131 DISALLOW_COPY_AND_ASSIGN(ShelfModel); |
105 }; | 132 }; |
106 | 133 |
107 } // namespace ash | 134 } // namespace ash |
108 | 135 |
109 #endif // ASH_SHELF_SHELF_MODEL_H_ | 136 #endif // ASH_SHELF_SHELF_MODEL_H_ |
OLD | NEW |