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/common_palette_tool.h" | 5 #include "ash/common/system/chromeos/palette/common_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/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/color_palette.h" | 17 #include "ui/gfx/color_palette.h" |
| 17 #include "ui/gfx/paint_vector_icon.h" | 18 #include "ui/gfx/paint_vector_icon.h" |
| 18 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 44 return CreateDefaultView( | 45 return CreateDefaultView( |
| 45 base::ASCIIToUTF16("[TODO] " + PaletteToolIdToString(GetToolId()))); | 46 base::ASCIIToUTF16("[TODO] " + PaletteToolIdToString(GetToolId()))); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void CommonPaletteTool::OnViewDestroyed() { | 49 void CommonPaletteTool::OnViewDestroyed() { |
| 49 highlight_view_ = nullptr; | 50 highlight_view_ = nullptr; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void CommonPaletteTool::OnEnable() { | 53 void CommonPaletteTool::OnEnable() { |
| 53 PaletteTool::OnEnable(); | 54 PaletteTool::OnEnable(); |
| 55 start_time_ = base::TimeTicks::Now(); | |
| 54 | 56 |
| 55 if (highlight_view_) { | 57 if (highlight_view_) { |
| 56 highlight_view_->SetHighlight(true); | 58 highlight_view_->SetHighlight(true); |
| 57 highlight_view_->SetRightIconVisible(true); | 59 highlight_view_->SetRightIconVisible(true); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 | 62 |
| 61 void CommonPaletteTool::OnDisable() { | 63 void CommonPaletteTool::OnDisable() { |
| 62 PaletteTool::OnDisable(); | 64 PaletteTool::OnDisable(); |
| 63 | 65 |
| 66 if (GetToolId() == PaletteToolId::LASER_POINTER) { | |
| 67 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InLaserPointerMode", | |
| 68 base::TimeTicks::Now() - start_time_, | |
| 69 base::TimeDelta::FromMilliseconds(100), | |
| 70 base::TimeDelta::FromHours(1), 50); | |
| 71 } else if (GetToolId() == PaletteToolId::MAGNIFY) { | |
| 72 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InMagnifyMode", | |
| 73 base::TimeTicks::Now() - start_time_, | |
| 74 base::TimeDelta::FromMilliseconds(100), | |
| 75 base::TimeDelta::FromHours(1), 50); | |
| 76 } | |
| 77 | |
| 64 if (highlight_view_) { | 78 if (highlight_view_) { |
| 65 highlight_view_->SetHighlight(false); | 79 highlight_view_->SetHighlight(false); |
| 66 highlight_view_->SetRightIconVisible(false); | 80 highlight_view_->SetRightIconVisible(false); |
| 67 } | 81 } |
| 68 } | 82 } |
| 69 | 83 |
| 70 void CommonPaletteTool::OnViewClicked(views::View* sender) { | 84 void CommonPaletteTool::OnViewClicked(views::View* sender) { |
| 71 if (enabled()) | 85 delegate()->RecordPaletteOptionsUsage( |
| 86 PaletteToolIdToPaletteTrayOptions(GetToolId())); | |
| 87 if (enabled()) { | |
| 72 delegate()->DisableTool(GetToolId()); | 88 delegate()->DisableTool(GetToolId()); |
| 73 else | 89 if (GetToolId() == PaletteToolId::LASER_POINTER) { |
| 90 delegate()->RecordPaletteModeCancellation( | |
| 91 PaletteModeCancelType::PALETTE_MODE_LASER_POINTER_CANCELLED); | |
| 92 } else if (GetToolId() == PaletteToolId::MAGNIFY) { | |
| 93 delegate()->RecordPaletteModeCancellation( | |
| 94 PaletteModeCancelType::PALETTE_MODE_MAGNIFY_CANCELLED); | |
| 95 } | |
| 96 } else | |
| 74 delegate()->EnableTool(GetToolId()); | 97 delegate()->EnableTool(GetToolId()); |
|
Ilya Sherman
2016/09/06 20:45:32
nit: Please add curly braces to the else stmt, sin
xiaoyinh(OOO Sep 11-29)
2016/09/06 22:31:35
Done.
| |
| 75 } | 98 } |
| 76 | 99 |
| 77 views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) { | 100 views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) { |
| 78 gfx::ImageSkia icon = | 101 gfx::ImageSkia icon = |
| 79 CreateVectorIcon(GetPaletteIconId(), kIconSize, gfx::kChromeIconGrey); | 102 CreateVectorIcon(GetPaletteIconId(), kIconSize, gfx::kChromeIconGrey); |
| 80 gfx::ImageSkia check = CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, | 103 gfx::ImageSkia check = CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, |
| 81 kIconSize, gfx::kGoogleGreen700); | 104 kIconSize, gfx::kGoogleGreen700); |
| 82 | 105 |
| 83 highlight_view_ = new HoverHighlightView(this); | 106 highlight_view_ = new HoverHighlightView(this); |
| 84 highlight_view_->SetBorder( | 107 highlight_view_->SetBorder( |
| 85 views::Border::CreateEmptyBorder(0, kExtraMarginFromLeftEdge, 0, 0)); | 108 views::Border::CreateEmptyBorder(0, kExtraMarginFromLeftEdge, 0, 0)); |
| 86 highlight_view_->AddIconAndLabelCustomSize(icon, name, false, kIconSize, | 109 highlight_view_->AddIconAndLabelCustomSize(icon, name, false, kIconSize, |
| 87 kMarginFromEdges, | 110 kMarginFromEdges, |
| 88 kMarginBetweenIconAndText); | 111 kMarginBetweenIconAndText); |
| 89 highlight_view_->AddRightIcon(check, kIconSize); | 112 highlight_view_->AddRightIcon(check, kIconSize); |
| 90 | 113 |
| 91 if (enabled()) | 114 if (enabled()) |
| 92 highlight_view_->SetHighlight(true); | 115 highlight_view_->SetHighlight(true); |
| 93 else | 116 else |
| 94 highlight_view_->SetRightIconVisible(false); | 117 highlight_view_->SetRightIconVisible(false); |
| 95 | 118 |
| 96 return highlight_view_; | 119 return highlight_view_; |
| 97 } | 120 } |
| 98 | 121 |
| 99 } // namespace ash | 122 } // namespace ash |
| OLD | NEW |