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