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