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