| 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 RecordPaletteModeCancellation(PaletteToolIdToPaletteModeCancelType( |
| 45 previous_tool->GetToolId(), true /*is_switched*/)); |
| 46 } |
| 43 | 47 |
| 44 active_tools_[new_tool->GetGroup()] = new_tool; | 48 active_tools_[new_tool->GetGroup()] = new_tool; |
| 45 new_tool->OnEnable(); | 49 new_tool->OnEnable(); |
| 46 | 50 |
| 47 delegate_->OnActiveToolChanged(); | 51 delegate_->OnActiveToolChanged(); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { | 54 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { |
| 51 PaletteTool* tool = FindToolById(tool_id); | 55 PaletteTool* tool = FindToolById(tool_id); |
| 52 DCHECK(tool); | 56 DCHECK(tool); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 115 } |
| 112 | 116 |
| 113 void PaletteToolManager::HidePalette() { | 117 void PaletteToolManager::HidePalette() { |
| 114 delegate_->HidePalette(); | 118 delegate_->HidePalette(); |
| 115 } | 119 } |
| 116 | 120 |
| 117 WmWindow* PaletteToolManager::GetWindow() { | 121 WmWindow* PaletteToolManager::GetWindow() { |
| 118 return delegate_->GetWindow(); | 122 return delegate_->GetWindow(); |
| 119 } | 123 } |
| 120 | 124 |
| 125 void PaletteToolManager::RecordPaletteOptionsUsage(PaletteTrayOptions option) { |
| 126 return delegate_->RecordPaletteOptionsUsage(option); |
| 127 } |
| 128 |
| 129 void PaletteToolManager::RecordPaletteModeCancellation( |
| 130 PaletteModeCancelType type) { |
| 131 return delegate_->RecordPaletteModeCancellation(type); |
| 132 } |
| 133 |
| 121 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) const { | 134 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) const { |
| 122 for (const std::unique_ptr<PaletteTool>& tool : tools_) { | 135 for (const std::unique_ptr<PaletteTool>& tool : tools_) { |
| 123 if (tool->GetToolId() == tool_id) | 136 if (tool->GetToolId() == tool_id) |
| 124 return tool.get(); | 137 return tool.get(); |
| 125 } | 138 } |
| 126 | 139 |
| 127 return nullptr; | 140 return nullptr; |
| 128 } | 141 } |
| 129 | 142 |
| 130 } // namespace ash | 143 } // namespace ash |
| OLD | NEW |