palette_tool_manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2016 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_SYSTEM_PALETTE_PALETTE_TOOL_MANAGER_H_
  5. #define ASH_SYSTEM_PALETTE_PALETTE_TOOL_MANAGER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/system/palette/palette_ids.h"
  11. #include "ash/system/palette/palette_tool.h"
  12. #include "base/callback.h"
  13. namespace aura {
  14. class Window;
  15. }
  16. namespace views {
  17. class View;
  18. }
  19. namespace ash {
  20. class PaletteTool;
  21. enum class PaletteGroup;
  22. enum class PaletteToolId;
  23. struct ASH_EXPORT PaletteToolView {
  24. PaletteGroup group;
  25. PaletteToolId tool_id;
  26. views::View* view;
  27. };
  28. class ASH_EXPORT PaletteToolManager : public PaletteTool::Delegate {
  29. public:
  30. class Delegate {
  31. public:
  32. // Hide the palette (if shown).
  33. virtual void HidePalette() = 0;
  34. // Hide the palette immediately, ie, do not display a hide animation.
  35. virtual void HidePaletteImmediately() = 0;
  36. // Called when the active tool has changed.
  37. virtual void OnActiveToolChanged() = 0;
  38. // Return the window associated with this palette.
  39. virtual aura::Window* GetWindow() = 0;
  40. // Record usage of each pen palette option.
  41. virtual void RecordPaletteOptionsUsage(PaletteTrayOptions option,
  42. PaletteInvocationMethod method) = 0;
  43. // Record mode cancellation of pen palette.
  44. virtual void RecordPaletteModeCancellation(PaletteModeCancelType type) = 0;
  45. protected:
  46. virtual ~Delegate() {}
  47. };
  48. // Creates the tool manager.
  49. explicit PaletteToolManager(Delegate* delegate);
  50. PaletteToolManager(const PaletteToolManager&) = delete;
  51. PaletteToolManager& operator=(const PaletteToolManager&) = delete;
  52. ~PaletteToolManager() override;
  53. // Returns true if the given tool has been added to the tool manager.
  54. bool HasTool(PaletteToolId tool_id);
  55. // Adds the given |tool| to the tool manager. The tool is assumed to be in a
  56. // deactivated state. This class takes ownership over |tool|.
  57. void AddTool(std::unique_ptr<PaletteTool> tool);
  58. // Activates tool_id and deactivates any other active tool in the same
  59. // group as tool_id.
  60. void ActivateTool(PaletteToolId tool_id);
  61. // Deactivates the given tool.
  62. void DeactivateTool(PaletteToolId tool_id);
  63. // Returns true if the given tool is active.
  64. bool IsToolActive(PaletteToolId tool_id);
  65. // Returns the active tool for the given group.
  66. PaletteToolId GetActiveTool(PaletteGroup group);
  67. // Fetch the active tray icon for the given tool. Returns an empty icon if
  68. // not available.
  69. const gfx::VectorIcon& GetActiveTrayIcon(PaletteToolId tool_id) const;
  70. // Create views for all of the registered mode tools.
  71. std::vector<PaletteToolView> CreateViews();
  72. // Called when the views returned by CreateViews have been destroyed. This
  73. // should clear any (now) stale references.
  74. void NotifyViewsDestroyed();
  75. // Helper method to disable any active tool in the given |group|.
  76. void DisableActiveTool(PaletteGroup group);
  77. private:
  78. // PaleteTool::Delegate overrides.
  79. void EnableTool(PaletteToolId tool_id) override;
  80. void DisableTool(PaletteToolId tool_id) override;
  81. void HidePalette() override;
  82. void HidePaletteImmediately() override;
  83. aura::Window* GetWindow() override;
  84. void RecordPaletteOptionsUsage(PaletteTrayOptions option,
  85. PaletteInvocationMethod method) override;
  86. void RecordPaletteModeCancellation(PaletteModeCancelType type) override;
  87. PaletteTool* FindToolById(PaletteToolId tool_id) const;
  88. // Unowned pointer to the delegate to provide external functionality.
  89. Delegate* delegate_;
  90. // Unowned pointer to the active tool / group.
  91. std::map<PaletteGroup, PaletteTool*> active_tools_;
  92. // Owned list of all tools.
  93. std::vector<std::unique_ptr<PaletteTool>> tools_;
  94. };
  95. } // namespace ash
  96. #endif // ASH_SYSTEM_PALETTE_PALETTE_TOOL_MANAGER_H_