OLD | NEW |
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_manager.h" | 5 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/system/chromeos/palette/palette_tool.h" | 9 #include "ash/common/system/chromeos/palette/palette_tool.h" |
10 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/metrics/histogram_macros.h" |
12 | 13 |
13 namespace ash { | 14 namespace ash { |
14 | 15 |
15 PaletteToolManager::PaletteToolManager(Delegate* delegate) | 16 PaletteToolManager::PaletteToolManager(Delegate* delegate) |
16 : delegate_(delegate) { | 17 : delegate_(delegate) { |
17 DCHECK(delegate_); | 18 DCHECK(delegate_); |
18 } | 19 } |
19 | 20 |
20 PaletteToolManager::~PaletteToolManager() {} | 21 PaletteToolManager::~PaletteToolManager() {} |
21 | 22 |
22 void PaletteToolManager::AddTool(std::unique_ptr<PaletteTool> tool) { | 23 void PaletteToolManager::AddTool(std::unique_ptr<PaletteTool> tool) { |
23 // The same PaletteToolId cannot be registered twice. | 24 // The same PaletteToolId cannot be registered twice. |
24 DCHECK_EQ(0, std::count_if(tools_.begin(), tools_.end(), | 25 DCHECK_EQ(0, std::count_if(tools_.begin(), tools_.end(), |
25 [&tool](const std::unique_ptr<PaletteTool>& t) { | 26 [&tool](const std::unique_ptr<PaletteTool>& t) { |
26 return t->GetToolId() == tool->GetToolId(); | 27 return t->GetToolId() == tool->GetToolId(); |
27 })); | 28 })); |
28 | 29 |
29 tools_.emplace_back(std::move(tool)); | 30 tools_.emplace_back(std::move(tool)); |
30 } | 31 } |
31 | 32 |
32 void PaletteToolManager::ActivateTool(PaletteToolId tool_id) { | 33 void PaletteToolManager::ActivateTool(PaletteToolId tool_id) { |
33 PaletteTool* new_tool = FindToolById(tool_id); | 34 PaletteTool* new_tool = FindToolById(tool_id); |
34 DCHECK(new_tool); | 35 DCHECK(new_tool); |
35 | 36 |
36 PaletteTool* previous_tool = active_tools_[new_tool->GetGroup()]; | 37 PaletteTool* previous_tool = active_tools_[new_tool->GetGroup()]; |
37 | 38 |
38 if (new_tool == previous_tool) | 39 if (new_tool == previous_tool) |
39 return; | 40 return; |
40 | 41 |
41 if (previous_tool) | 42 if (previous_tool) { |
42 previous_tool->OnDisable(); | 43 previous_tool->OnDisable(); |
| 44 if (previous_tool->GetToolId() == PaletteToolId::LASER_POINTER) { |
| 45 RecordPaletteModeCancellation( |
| 46 PaletteModeCancelType::PALETTE_MODE_LASER_POINTER_SWITCHED); |
| 47 } else if (previous_tool->GetToolId() == PaletteToolId::MAGNIFY) { |
| 48 RecordPaletteModeCancellation( |
| 49 PaletteModeCancelType::PALETTE_MODE_MAGNIFY_SWITCHED); |
| 50 } |
| 51 } |
43 | 52 |
44 active_tools_[new_tool->GetGroup()] = new_tool; | 53 active_tools_[new_tool->GetGroup()] = new_tool; |
45 new_tool->OnEnable(); | 54 new_tool->OnEnable(); |
46 | 55 |
47 delegate_->OnActiveToolChanged(); | 56 delegate_->OnActiveToolChanged(); |
48 } | 57 } |
49 | 58 |
50 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { | 59 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { |
51 PaletteTool* tool = FindToolById(tool_id); | 60 PaletteTool* tool = FindToolById(tool_id); |
52 DCHECK(tool); | 61 DCHECK(tool); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 120 } |
112 | 121 |
113 void PaletteToolManager::HidePalette() { | 122 void PaletteToolManager::HidePalette() { |
114 delegate_->HidePalette(); | 123 delegate_->HidePalette(); |
115 } | 124 } |
116 | 125 |
117 WmWindow* PaletteToolManager::GetWindow() { | 126 WmWindow* PaletteToolManager::GetWindow() { |
118 return delegate_->GetWindow(); | 127 return delegate_->GetWindow(); |
119 } | 128 } |
120 | 129 |
| 130 void PaletteToolManager::RecordPaletteOptionsUsage(PaletteTrayOptions option) { |
| 131 return delegate_->RecordPaletteOptionsUsage(option); |
| 132 } |
| 133 |
| 134 void PaletteToolManager::RecordPaletteModeCancellation( |
| 135 PaletteModeCancelType type) { |
| 136 return delegate_->RecordPaletteModeCancellation(type); |
| 137 } |
| 138 |
121 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) const { | 139 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) const { |
122 for (const std::unique_ptr<PaletteTool>& tool : tools_) { | 140 for (const std::unique_ptr<PaletteTool>& tool : tools_) { |
123 if (tool->GetToolId() == tool_id) | 141 if (tool->GetToolId() == tool_id) |
124 return tool.get(); | 142 return tool.get(); |
125 } | 143 } |
126 | 144 |
127 return nullptr; | 145 return nullptr; |
128 } | 146 } |
129 | 147 |
130 } // namespace ash | 148 } // namespace ash |
OLD | NEW |