| 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 "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "ui/gfx/vector_icons_public.h" | 12 #include "ui/gfx/vector_icons_public.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() {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 119 } |
| 111 | 120 |
| 112 void PaletteToolManager::HidePalette() { | 121 void PaletteToolManager::HidePalette() { |
| 113 delegate_->HidePalette(); | 122 delegate_->HidePalette(); |
| 114 } | 123 } |
| 115 | 124 |
| 116 WmWindow* PaletteToolManager::GetWindow() { | 125 WmWindow* PaletteToolManager::GetWindow() { |
| 117 return delegate_->GetWindow(); | 126 return delegate_->GetWindow(); |
| 118 } | 127 } |
| 119 | 128 |
| 129 void PaletteToolManager::RecordPaletteOptionsUsage(PaletteTrayOptions option) { |
| 130 return delegate_->RecordPaletteOptionsUsage(option); |
| 131 } |
| 132 |
| 133 void PaletteToolManager::RecordPaletteModeCancellation( |
| 134 PaletteModeCancelType type) { |
| 135 return delegate_->RecordPaletteModeCancellation(type); |
| 136 } |
| 137 |
| 120 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) { | 138 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) { |
| 121 for (std::unique_ptr<PaletteTool>& tool : tools_) { | 139 for (std::unique_ptr<PaletteTool>& tool : tools_) { |
| 122 if (tool->GetToolId() == tool_id) | 140 if (tool->GetToolId() == tool_id) |
| 123 return tool.get(); | 141 return tool.get(); |
| 124 } | 142 } |
| 125 | 143 |
| 126 return nullptr; | 144 return nullptr; |
| 127 } | 145 } |
| 128 | 146 |
| 129 } // namespace ash | 147 } // namespace ash |
| OLD | NEW |