OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ | 5 #ifndef ASH_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ |
6 #define ASH_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ | 6 #define ASH_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ash/public/cpp/ash_public_export.h" | 10 #include "ash/public/cpp/ash_public_export.h" |
11 #include "ash/public/cpp/shelf_types.h" | 11 #include "ash/public/cpp/shelf_types.h" |
12 #include "ash/public/interfaces/shelf.mojom.h" | 12 #include "ash/public/interfaces/shelf.mojom.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
16 | 17 |
17 class AppWindowLauncherItemController; | 18 class AppWindowLauncherItemController; |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 | 21 |
21 using MenuItemList = std::vector<mojom::MenuItemPtr>; | 22 using MenuItemList = std::vector<mojom::MenuItemPtr>; |
22 | 23 |
23 // ShelfItemDelegate tracks some item state and serves as a base class for | 24 // ShelfItemDelegate tracks some item state and serves as a base class for |
24 // various subclasses that implement the mojo interface. | 25 // various subclasses that implement the mojo interface. |
25 class ASH_PUBLIC_EXPORT ShelfItemDelegate : public mojom::ShelfItemDelegate { | 26 class ASH_PUBLIC_EXPORT ShelfItemDelegate : public mojom::ShelfItemDelegate { |
26 public: | 27 public: |
27 explicit ShelfItemDelegate(const ShelfID& shelf_id); | 28 explicit ShelfItemDelegate(const ShelfID& shelf_id); |
28 ~ShelfItemDelegate() override; | 29 ~ShelfItemDelegate() override; |
29 | 30 |
30 const ShelfID& shelf_id() const { return shelf_id_; } | 31 const ShelfID& shelf_id() const { return shelf_id_; } |
31 void set_shelf_id(const ShelfID& shelf_id) { shelf_id_ = shelf_id; } | 32 void set_shelf_id(const ShelfID& shelf_id) { shelf_id_ = shelf_id; } |
32 const std::string& app_id() const { return shelf_id_.app_id; } | 33 const std::string& app_id() const { return shelf_id_.app_id; } |
33 const std::string& launch_id() const { return shelf_id_.launch_id; } | 34 const std::string& launch_id() const { return shelf_id_.launch_id; } |
34 | 35 |
35 bool image_set_by_controller() const { return image_set_by_controller_; } | 36 bool image_set_by_controller() const { return image_set_by_controller_; } |
36 void set_image_set_by_controller(bool image_set_by_controller) { | 37 void set_image_set_by_controller(bool image_set_by_controller) { |
37 image_set_by_controller_ = image_set_by_controller; | 38 image_set_by_controller_ = image_set_by_controller; |
38 } | 39 } |
39 | 40 |
| 41 // Returns a pointer to this instance, to be used by remote shelf models, etc. |
| 42 mojom::ShelfItemDelegatePtr CreateInterfacePtrAndBind(); |
| 43 |
40 // Returns items for the application menu; used for convenience and testing. | 44 // Returns items for the application menu; used for convenience and testing. |
41 virtual MenuItemList GetAppMenuItems(int event_flags); | 45 virtual MenuItemList GetAppMenuItems(int event_flags); |
42 | 46 |
43 // Returns nullptr if class is not AppWindowLauncherItemController. | 47 // Returns nullptr if class is not AppWindowLauncherItemController. |
44 virtual AppWindowLauncherItemController* AsAppWindowLauncherItemController(); | 48 virtual AppWindowLauncherItemController* AsAppWindowLauncherItemController(); |
45 | 49 |
46 private: | 50 private: |
47 // The shelf id; empty if there is no app associated with the item. | 51 // The shelf id; empty if there is no app associated with the item. |
48 // Besides the application id, ShelfID also contains a launch id, which is an | 52 // Besides the application id, ShelfID also contains a launch id, which is an |
49 // id that can be passed to an app when launched in order to support multiple | 53 // id that can be passed to an app when launched in order to support multiple |
50 // shelf items per app. This id is used together with the app_id to uniquely | 54 // shelf items per app. This id is used together with the app_id to uniquely |
51 // identify each shelf item that has the same app_id. | 55 // identify each shelf item that has the same app_id. |
52 ShelfID shelf_id_; | 56 ShelfID shelf_id_; |
53 | 57 |
| 58 // A binding used by remote shelf item delegate users. |
| 59 mojo::Binding<mojom::ShelfItemDelegate> binding_; |
| 60 |
54 // Set to true if the launcher item image has been set by the controller. | 61 // Set to true if the launcher item image has been set by the controller. |
55 bool image_set_by_controller_; | 62 bool image_set_by_controller_; |
56 | 63 |
57 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegate); | 64 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegate); |
58 }; | 65 }; |
59 | 66 |
60 } // namespace ash | 67 } // namespace ash |
61 | 68 |
62 #endif // ASH_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ | 69 #endif // ASH_PUBLIC_CPP_SHELF_ITEM_DELEGATE_H_ |
OLD | NEW |