shelf_application_menu_model.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_SHELF_SHELF_APPLICATION_MENU_MODEL_H_
  5. #define ASH_SHELF_SHELF_APPLICATION_MENU_MODEL_H_
  6. #include <memory>
  7. #include <utility>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/public/cpp/shelf_item_delegate.h"
  11. #include "base/containers/flat_set.h"
  12. #include "ui/base/models/simple_menu_model.h"
  13. #include "ui/gfx/image/image_skia.h"
  14. namespace ash {
  15. class ShelfItemDelegate;
  16. // A menu model listing open applications associated with a shelf item. Layout:
  17. // +---------------------------+
  18. // | |
  19. // | Shelf Item Title |
  20. // | |
  21. // | [Icon] Menu Item Label |
  22. // | [Icon] Menu Item Label |
  23. // | |
  24. // +---------------------------+
  25. class ASH_EXPORT ShelfApplicationMenuModel
  26. : public ui::SimpleMenuModel,
  27. public ui::SimpleMenuModel::Delegate {
  28. public:
  29. using Items = ShelfItemDelegate::AppMenuItems;
  30. // Makes a menu with a |title|, |items|, and a separator for |delegate|.
  31. // |delegate| may be null in unit tests that do not execute commands.
  32. ShelfApplicationMenuModel(const std::u16string& title,
  33. const Items& items,
  34. ShelfItemDelegate* delegate);
  35. ShelfApplicationMenuModel(const ShelfApplicationMenuModel&) = delete;
  36. ShelfApplicationMenuModel& operator=(const ShelfApplicationMenuModel&) =
  37. delete;
  38. ~ShelfApplicationMenuModel() override;
  39. // ui::SimpleMenuModel::Delegate:
  40. bool IsCommandIdEnabled(int command_id) const override;
  41. void ExecuteCommand(int command_id, int event_flags) override;
  42. private:
  43. friend class ShelfApplicationMenuModelTestAPI;
  44. // Records UMA metrics when a menu item is selected.
  45. void RecordMenuItemSelectedMetrics(int command_id,
  46. int num_menu_items_enabled);
  47. // The shelf item delegate that created the menu and executes its commands.
  48. ShelfItemDelegate* const delegate_;
  49. // A set containing the enabled command IDs.
  50. base::flat_set<int> enabled_commands_;
  51. };
  52. } // namespace ash
  53. #endif // ASH_SHELF_SHELF_APPLICATION_MENU_MODEL_H_