| 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_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_TOOL_H_ |
| 6 #define ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_TOOL_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 #include <vector> |
| 11 |
| 12 #include "ash/ash_export.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/optional.h" |
| 16 #include "ui/gfx/vector_icon_types.h" |
| 17 |
| 18 namespace views { |
| 19 class View; |
| 20 } |
| 21 |
| 22 namespace ash { |
| 23 |
| 24 class WmWindow; |
| 25 |
| 26 enum class PaletteGroup; |
| 27 enum class PaletteToolId; |
| 28 class PaletteToolManager; |
| 29 |
| 30 // A PaletteTool is a generalized action inside of the palette menu in the |
| 31 // shelf. Only one tool per group is active at any given time. When the tool is |
| 32 // active, it should be showing some specializied UI. The tool is no longer |
| 33 // active if it completes its action, if the user selects another tool with the |
| 34 // same group, or if the user just cancels the action from the palette. |
| 35 class ASH_EXPORT PaletteTool { |
| 36 public: |
| 37 class Delegate { |
| 38 public: |
| 39 Delegate() {} |
| 40 virtual ~Delegate() {} |
| 41 |
| 42 // Enable or disable a specific tool. |
| 43 virtual void EnableTool(PaletteToolId tool_id) = 0; |
| 44 virtual void DisableTool(PaletteToolId tool_id) = 0; |
| 45 |
| 46 // Hide the entire palette. This should not change any tool state. |
| 47 virtual void HidePalette() = 0; |
| 48 |
| 49 // Returns the root window. |
| 50 virtual WmWindow* GetWindow() = 0; |
| 51 |
| 52 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 54 }; |
| 55 |
| 56 // Adds all available PaletteTool instances to the tool_manager. |
| 57 static void RegisterToolInstances(PaletteToolManager* tool_manager); |
| 58 |
| 59 // |delegate| must outlive this tool instance. |
| 60 explicit PaletteTool(Delegate* delegate); |
| 61 virtual ~PaletteTool(); |
| 62 |
| 63 // The group this tool belongs to. Only one tool per group can be active at |
| 64 // any given time. |
| 65 virtual PaletteGroup GetGroup() const = 0; |
| 66 |
| 67 // The unique identifier for this tool. This should be the only tool that ever |
| 68 // has this ID. |
| 69 virtual PaletteToolId GetToolId() const = 0; |
| 70 |
| 71 // Called when the user activates the tool. Only one tool per group can be |
| 72 // active at any given time. |
| 73 virtual void OnEnable(); |
| 74 |
| 75 // Disable the tool, either because this tool called DisableSelf(), the |
| 76 // user cancelled the tool, or the user activated another tool within the |
| 77 // same group. |
| 78 virtual void OnDisable(); |
| 79 |
| 80 // Create a view that will be used in the palette. The view is owned by the |
| 81 // caller. OnViewDestroyed is called when the view has been deallocated by its |
| 82 // owner. |
| 83 virtual views::View* CreateView() = 0; |
| 84 virtual void OnViewDestroyed() = 0; |
| 85 |
| 86 // Returns an optional icon to use in the tray if this tool is active. Only |
| 87 // one tool should ever have an active icon at any given time. |
| 88 virtual base::Optional<gfx::VectorIconId> GetActiveTrayIcon(); |
| 89 |
| 90 protected: |
| 91 // Enables/disables the tool. |
| 92 bool enabled() const { return enabled_; } |
| 93 |
| 94 Delegate* delegate() { return delegate_; } |
| 95 |
| 96 private: |
| 97 bool enabled_ = false; |
| 98 |
| 99 // Unowned pointer to the delegate. The delegate should outlive this instance. |
| 100 Delegate* delegate_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(PaletteTool); |
| 103 }; |
| 104 |
| 105 } // namespace ash |
| 106 |
| 107 #endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_TOOL_H_ |
| OLD | NEW |