Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: ash/common/system/chromeos/palette/palette_tool.cc

Issue 2147783002: Add common palette tray implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stylus-tool-structure
Patch Set: Some palette tool stubs Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/chromeos/palette/palette_tool.h" 5 #include "ash/common/system/chromeos/palette/palette_tool.h"
6 6
7 #include "ash/common/shelf/shelf_constants.h" 7 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/system/chromeos/palette/palette_ids.h" 8 #include "ash/common/system/chromeos/palette/palette_ids.h"
9 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" 9 #include "ash/common/system/chromeos/palette/palette_tool_manager.h"
10 #include "ash/common/system/tray/hover_highlight_view.h" 10 #include "ash/common/system/tray/hover_highlight_view.h"
11 #include "ash/common/system/tray/view_click_listener.h" 11 #include "ash/common/system/tray/view_click_listener.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "grit/ash_resources.h" 13 #include "grit/ash_resources.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/gfx/vector_icons_public.h" 16 #include "ui/gfx/vector_icons_public.h"
17 17
18 namespace ash { 18 namespace ash {
19 19
20 namespace {
21
22 // A PaletteTool implementation with a standard view support.
23 class CommonPaletteTool : public PaletteTool, public ash::ViewClickListener {
24 protected:
25 views::View* CreateDefaultView(const std::string& message) {
26 highlight_view_ = new HoverHighlightView(this);
27
28 gfx::ImageSkia image = CreateVectorIcon(icon_id(), SK_ColorBLACK);
29 gfx::ImageSkia checkbox =
30 CreateVectorIcon(gfx::VectorIconId::CHECK, SK_ColorGREEN);
Evan Stade 2016/07/13 18:33:55 Are these the right colors? If not can you add a T
jdufault 2016/07/13 19:29:01 Added TODO.
31
32 const base::string16& name = base::ASCIIToUTF16(message);
Evan Stade 2016/07/13 18:33:55 this is not right, presumably message can contain
jdufault 2016/07/13 19:29:01 Right, these are stub tool implementations to prov
33
34 highlight_view_->AddIndentedIconAndLabel(image, name, false);
35 highlight_view_->AddRightIcon(checkbox);
36
37 if (enabled())
38 highlight_view_->SetHighlight(true);
39 else
40 highlight_view_->SetRightIconVisible(false);
41
42 return highlight_view_;
43 }
44
45 views::View* CreateView() override {
46 return CreateDefaultView("[TODO] " + PaletteToolIdToString(tool_id()));
47 }
48 void DestroyView() override { highlight_view_ = nullptr; }
49
50 void OnEnable() override {
51 PaletteTool::OnEnable();
52
53 if (highlight_view_) {
54 highlight_view_->SetHighlight(true);
55 highlight_view_->SetRightIconVisible(true);
56 }
57 }
58
59 void OnDisable() override {
60 PaletteTool::OnDisable();
61
62 if (highlight_view_) {
63 highlight_view_->SetHighlight(false);
64 highlight_view_->SetRightIconVisible(false);
65 }
66 }
67
68 // ViewClickListener overrides.
69 void OnViewClicked(views::View* sender) override {
70 if (enabled())
71 DisableSelf();
72 else
73 EnableSelf();
74 }
75
76 protected:
77 virtual gfx::VectorIconId icon_id() = 0;
78
79 private:
80 HoverHighlightView* highlight_view_ = nullptr;
81 };
82
83 class CreateNoteAction : public CommonPaletteTool {
84 public:
85 CreateNoteAction() {}
86 ~CreateNoteAction() override {}
87
88 private:
89 // PaletteTool overrides.
90 PaletteGroup group() const override { return PaletteGroup::ACTION; }
91 PaletteToolId tool_id() const override {
92 return PaletteToolId::CREATE_NEW_NOTE;
93 }
94
95 gfx::VectorIconId icon_id() override {
96 return gfx::VectorIconId::PALETTE_CAPTURE_SCREEN;
97 }
98
99 DISALLOW_COPY_AND_ASSIGN(CreateNoteAction);
100 };
101
102 class CaptureRegionAction : public CommonPaletteTool {
103 public:
104 CaptureRegionAction() {}
105 ~CaptureRegionAction() override {}
106
107 private:
108 // PaletteTool overrides.
109 PaletteGroup group() const override { return PaletteGroup::ACTION; }
110 PaletteToolId tool_id() const override {
111 return PaletteToolId::CAPTURE_REGION;
112 }
113
114 gfx::VectorIconId icon_id() override {
115 return gfx::VectorIconId::PALETTE_CAPTURE_REGION;
116 }
117
118 DISALLOW_COPY_AND_ASSIGN(CaptureRegionAction);
119 };
120
121 class ScreenshotAction : public CommonPaletteTool {
122 public:
123 ScreenshotAction() {}
124 ~ScreenshotAction() override {}
125
126 private:
127 // PaletteTool overrides.
128 PaletteGroup group() const override { return PaletteGroup::ACTION; }
129 PaletteToolId tool_id() const override { return PaletteToolId::SCREENSHOT; }
130 void OnEnable() override {
131 CommonPaletteTool::OnEnable();
132 DisableSelf();
133 }
134
135 gfx::VectorIconId icon_id() override {
136 return gfx::VectorIconId::PALETTE_CAPTURE_SCREEN;
137 }
138
139 DISALLOW_COPY_AND_ASSIGN(ScreenshotAction);
140 };
141
142 class PresentationMode : public CommonPaletteTool {
143 public:
144 PresentationMode() {}
145 ~PresentationMode() override {}
146
147 private:
148 // PaletteTool overrides.
149 PaletteGroup group() const override { return PaletteGroup::MODE; }
150 PaletteToolId tool_id() const override { return PaletteToolId::PRESENTATION; }
151
152 gfx::VectorIconId icon_id() override {
153 return gfx::VectorIconId::PALETTE_PRESENTATION_MODE;
154 }
155
156 DISALLOW_COPY_AND_ASSIGN(PresentationMode);
157 };
158
159 class MagnifierMode : public CommonPaletteTool {
160 public:
161 MagnifierMode() {}
162 ~MagnifierMode() override {}
163
164 private:
165 // PaletteTool overrides.
166 PaletteGroup group() const override { return PaletteGroup::MODE; }
167 PaletteToolId tool_id() const override { return PaletteToolId::MAGNIFY; }
168
169 gfx::VectorIconId icon_id() override {
170 return gfx::VectorIconId::PALETTE_MAGNIFY_MODE;
171 }
172
173 DISALLOW_COPY_AND_ASSIGN(MagnifierMode);
174 };
175
176 } // namespace
177
20 // static 178 // static
21 void PaletteTool::RegisterToolInstances(PaletteToolManager* tool_manager) {} 179 void PaletteTool::RegisterToolInstances(PaletteToolManager* tool_manager) {
180 tool_manager->AddTool(base::WrapUnique(new CreateNoteAction()));
181 tool_manager->AddTool(base::WrapUnique(new CaptureRegionAction()));
182 tool_manager->AddTool(base::WrapUnique(new ScreenshotAction()));
183 tool_manager->AddTool(base::WrapUnique(new PresentationMode()));
184 tool_manager->AddTool(base::WrapUnique(new MagnifierMode()));
185 }
22 186
23 PaletteTool::PaletteTool() {} 187 PaletteTool::PaletteTool() {}
24 188
25 PaletteTool::~PaletteTool() {} 189 PaletteTool::~PaletteTool() {}
26 190
27 void PaletteTool::Initialize(WmWindow* window, 191 void PaletteTool::Initialize(WmWindow* window,
28 const ToolAction& enable_tool, 192 const ToolAction& enable_tool,
29 const ToolAction& disable_tool) { 193 const ToolAction& disable_tool) {
30 window_ = window; 194 window_ = window;
31 enable_tool_ = enable_tool; 195 enable_tool_ = enable_tool;
(...skipping 22 matching lines...) Expand all
54 DCHECK(!disable_tool_.is_null()) << "PaletteTool was not initialized"; 218 DCHECK(!disable_tool_.is_null()) << "PaletteTool was not initialized";
55 219
56 disable_tool_.Run(tool_id()); 220 disable_tool_.Run(tool_id());
57 } 221 }
58 222
59 WmWindow* PaletteTool::window() const { 223 WmWindow* PaletteTool::window() const {
60 return window_; 224 return window_;
61 } 225 }
62 226
63 } // namespace ash 227 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698