Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: ash/common/system/chromeos/palette/common_palette_tool.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/system/chromeos/palette/common_palette_tool.h"
6
7 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/system/chromeos/palette/palette_ids.h"
9 #include "ash/common/system/chromeos/palette/palette_tool_manager.h"
10 #include "ash/common/system/tray/hover_highlight_view.h"
11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/view_click_listener.h"
13 #include "ash/resources/grit/ash_resources.h"
14 #include "base/logging.h"
15 #include "base/metrics/histogram_macros.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/color_palette.h"
19 #include "ui/gfx/paint_vector_icon.h"
20 #include "ui/gfx/vector_icons_public.h"
21 #include "ui/views/border.h"
22 #include "ui/views/controls/label.h"
23
24 namespace ash {
25 namespace {
26
27 void AddHistogramTimes(PaletteToolId id, base::TimeDelta duration) {
28 if (id == PaletteToolId::LASER_POINTER) {
29 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InLaserPointerMode", duration,
30 base::TimeDelta::FromMilliseconds(100),
31 base::TimeDelta::FromHours(1), 50);
32 } else if (id == PaletteToolId::MAGNIFY) {
33 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InMagnifyMode", duration,
34 base::TimeDelta::FromMilliseconds(100),
35 base::TimeDelta::FromHours(1), 50);
36 }
37 }
38
39 } // namespace
40
41 CommonPaletteTool::CommonPaletteTool(Delegate* delegate)
42 : PaletteTool(delegate) {}
43
44 CommonPaletteTool::~CommonPaletteTool() {}
45
46 void CommonPaletteTool::OnViewDestroyed() {
47 highlight_view_ = nullptr;
48 }
49
50 void CommonPaletteTool::OnEnable() {
51 PaletteTool::OnEnable();
52 start_time_ = base::TimeTicks::Now();
53
54 if (highlight_view_) {
55 highlight_view_->SetRightViewVisible(true);
56 highlight_view_->SetAccessiblityState(
57 HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
58 }
59 }
60
61 void CommonPaletteTool::OnDisable() {
62 PaletteTool::OnDisable();
63 AddHistogramTimes(GetToolId(), base::TimeTicks::Now() - start_time_);
64
65 if (highlight_view_) {
66 highlight_view_->SetRightViewVisible(false);
67 highlight_view_->SetAccessiblityState(
68 HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
69 }
70 }
71
72 void CommonPaletteTool::OnViewClicked(views::View* sender) {
73 delegate()->RecordPaletteOptionsUsage(
74 PaletteToolIdToPaletteTrayOptions(GetToolId()));
75 if (enabled()) {
76 delegate()->DisableTool(GetToolId());
77 delegate()->RecordPaletteModeCancellation(
78 PaletteToolIdToPaletteModeCancelType(GetToolId(),
79 false /*is_switched*/));
80 } else {
81 delegate()->EnableTool(GetToolId());
82 }
83 }
84
85 views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) {
86 gfx::ImageSkia icon =
87 CreateVectorIcon(GetPaletteIcon(), kMenuIconSize, gfx::kChromeIconGrey);
88 gfx::ImageSkia check = CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE,
89 kMenuIconSize, gfx::kGoogleGreen700);
90
91 highlight_view_ = new HoverHighlightView(this);
92 highlight_view_->SetBorder(views::CreateEmptyBorder(0, 0, 0, 0));
93 const int interior_button_padding = (kMenuButtonSize - kMenuIconSize) / 2;
94 highlight_view_->AddIconAndLabelCustomSize(icon, name, false, kMenuIconSize,
95 interior_button_padding,
96 kTrayPopupPaddingHorizontal);
97 highlight_view_->AddRightIcon(check, kMenuIconSize);
98 highlight_view_->set_custom_height(kMenuButtonSize);
99
100 if (enabled()) {
101 highlight_view_->SetAccessiblityState(
102 HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
103 } else {
104 highlight_view_->SetRightViewVisible(false);
105 highlight_view_->SetAccessiblityState(
106 HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
107 }
108
109 return highlight_view_;
110 }
111
112 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698