Chromium Code Reviews| 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() == ash::PaletteToolId::LASER_POINTER) { | |
|
jdufault
2016/09/02 21:54:30
nit: drop ash:: (already in the ash namespace)
jdufault
2016/09/02 21:54:30
The only time we can cancel if is if we click the
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
| |
| 45 UMA_HISTOGRAM_ENUMERATION( | |
| 46 "Ash.Shelf.Palette.ModeCancellation", | |
| 47 ash::PaletteModeCancelType::PALETTE_MODE_LASER_POINTER_SWITCHED, | |
| 48 ash::PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
| 49 } else if (previous_tool->GetToolId() == ash::PaletteToolId::MAGNIFY) { | |
| 50 UMA_HISTOGRAM_ENUMERATION( | |
| 51 "Ash.Shelf.Palette.ModeCancellation", | |
| 52 ash::PaletteModeCancelType::PALETTE_MODE_MAGNIFY_SWITCHED, | |
| 53 ash::PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
|
Ilya Sherman
2016/09/02 21:39:30
Please create a wrapper function for emitting to t
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
| |
| 54 } | |
| 55 } | |
| 43 | 56 |
| 44 active_tools_[new_tool->GetGroup()] = new_tool; | 57 active_tools_[new_tool->GetGroup()] = new_tool; |
| 45 new_tool->OnEnable(); | 58 new_tool->OnEnable(); |
| 46 | 59 |
| 47 delegate_->OnActiveToolChanged(); | 60 delegate_->OnActiveToolChanged(); |
| 48 } | 61 } |
| 49 | 62 |
| 50 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { | 63 void PaletteToolManager::DeactivateTool(PaletteToolId tool_id) { |
| 51 PaletteTool* tool = FindToolById(tool_id); | 64 PaletteTool* tool = FindToolById(tool_id); |
| 52 DCHECK(tool); | 65 DCHECK(tool); |
| 53 | 66 |
| 54 active_tools_[tool->GetGroup()] = nullptr; | 67 active_tools_[tool->GetGroup()] = nullptr; |
| 55 tool->OnDisable(); | 68 tool->OnDisable(); |
| 69 if (tool->GetToolId() == ash::PaletteToolId::LASER_POINTER) { | |
| 70 UMA_HISTOGRAM_ENUMERATION( | |
|
jdufault
2016/09/02 21:54:30
Should these UMA stats also have the AutoOpen chec
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
AutoOpen factor are not specified for mode cancell
| |
| 71 "Ash.Shelf.Palette.ModeCancellation", | |
| 72 ash::PaletteModeCancelType::PALETTE_MODE_LASER_POINTER_CANCELLED, | |
| 73 ash::PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
| 74 } else if (tool->GetToolId() == ash::PaletteToolId::MAGNIFY) { | |
| 75 UMA_HISTOGRAM_ENUMERATION( | |
| 76 "Ash.Shelf.Palette.ModeCancellation", | |
| 77 ash::PaletteModeCancelType::PALETTE_MODE_MAGNIFY_CANCELLED, | |
| 78 ash::PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
| 79 } | |
| 56 | 80 |
| 57 delegate_->OnActiveToolChanged(); | 81 delegate_->OnActiveToolChanged(); |
| 58 } | 82 } |
| 59 | 83 |
| 60 bool PaletteToolManager::IsToolActive(PaletteToolId tool_id) { | 84 bool PaletteToolManager::IsToolActive(PaletteToolId tool_id) { |
| 61 PaletteTool* tool = FindToolById(tool_id); | 85 PaletteTool* tool = FindToolById(tool_id); |
| 62 DCHECK(tool); | 86 DCHECK(tool); |
| 63 | 87 |
| 64 return active_tools_[tool->GetGroup()] == tool; | 88 return active_tools_[tool->GetGroup()] == tool; |
| 65 } | 89 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 134 } |
| 111 | 135 |
| 112 void PaletteToolManager::HidePalette() { | 136 void PaletteToolManager::HidePalette() { |
| 113 delegate_->HidePalette(); | 137 delegate_->HidePalette(); |
| 114 } | 138 } |
| 115 | 139 |
| 116 WmWindow* PaletteToolManager::GetWindow() { | 140 WmWindow* PaletteToolManager::GetWindow() { |
| 117 return delegate_->GetWindow(); | 141 return delegate_->GetWindow(); |
| 118 } | 142 } |
| 119 | 143 |
| 144 void PaletteToolManager::RecordPaletteMetrics(ash::PaletteTrayOptions option) { | |
| 145 return delegate_->RecordPaletteMetrics(option); | |
| 146 } | |
| 147 | |
| 120 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) { | 148 PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) { |
| 121 for (std::unique_ptr<PaletteTool>& tool : tools_) { | 149 for (std::unique_ptr<PaletteTool>& tool : tools_) { |
| 122 if (tool->GetToolId() == tool_id) | 150 if (tool->GetToolId() == tool_id) |
| 123 return tool.get(); | 151 return tool.get(); |
| 124 } | 152 } |
| 125 | 153 |
| 126 return nullptr; | 154 return nullptr; |
| 127 } | 155 } |
| 128 | 156 |
| 129 } // namespace ash | 157 } // namespace ash |
| OLD | NEW |