OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #import "base/mac/sdk_forward_declarations.h" | 11 #import "base/mac/sdk_forward_declarations.h" |
12 #include "base/metrics/histogram_macros.h" | |
12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/app/vector_icons/vector_icons.h" | 15 #include "chrome/app/vector_icons/vector_icons.h" |
15 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_command_controller.h" | 20 #include "chrome/browser/ui/browser_command_controller.h" |
20 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
21 #include "chrome/common/chrome_features.h" | 22 #include "chrome/common/chrome_features.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "components/omnibox/browser/vector_icons.h" | 25 #include "components/omnibox/browser/vector_icons.h" |
25 #include "components/prefs/pref_member.h" | 26 #include "components/prefs/pref_member.h" |
26 #include "components/search_engines/util.h" | 27 #include "components/search_engines/util.h" |
27 #include "components/toolbar/vector_icons.h" | 28 #include "components/toolbar/vector_icons.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/gfx/color_palette.h" | 30 #include "ui/gfx/color_palette.h" |
30 #include "ui/gfx/color_utils.h" | 31 #include "ui/gfx/color_utils.h" |
31 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
32 #include "ui/gfx/image/image_skia_util_mac.h" | 33 #include "ui/gfx/image/image_skia_util_mac.h" |
33 #include "ui/gfx/paint_vector_icon.h" | 34 #include "ui/gfx/paint_vector_icon.h" |
34 #include "ui/vector_icons/vector_icons.h" | 35 #include "ui/vector_icons/vector_icons.h" |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
39 // The touch bar actions that are being recorded in a histogram. These values | |
40 // should not be re-ordered or removed. | |
41 enum TouchBarAction { | |
42 BACK = 0, | |
43 FORWARD, | |
44 STOP, | |
45 RELOAD, | |
46 HOME, | |
47 SEARCH, | |
48 STAR, | |
49 NEW_TAB, | |
50 TOUCH_BAR_ACTION_COUNT | |
51 }; | |
52 | |
38 // The touch bar's identifier. | 53 // The touch bar's identifier. |
39 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = | 54 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = |
40 @"BrowserWindowTouchBarId"; | 55 @"BrowserWindowTouchBarId"; |
41 | 56 |
42 // Touch bar items identifiers. | 57 // Touch bar items identifiers. |
43 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; | 58 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; |
44 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; | 59 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; |
45 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId"; | 60 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId"; |
46 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; | 61 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; |
47 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; | 62 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; |
(...skipping 28 matching lines...) Expand all Loading... | |
76 int command, | 91 int command, |
77 SkColor color = kTouchBarDefaultIconColor) { | 92 SkColor color = kTouchBarDefaultIconColor) { |
78 NSButton* button = | 93 NSButton* button = |
79 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) | 94 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) |
80 target:owner | 95 target:owner |
81 action:@selector(executeCommand:)]; | 96 action:@selector(executeCommand:)]; |
82 button.tag = command; | 97 button.tag = command; |
83 return button; | 98 return button; |
84 } | 99 } |
85 | 100 |
101 // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram. | |
102 void LogTouchBarUMA(int command) { | |
103 TouchBarAction action; | |
104 if (command == IDC_BACK) | |
Robert Sesek
2017/03/13 21:05:25
Would this be better as a switch?
spqchan
2017/03/14 00:04:33
Done.
| |
105 action = TouchBarAction::BACK; | |
106 else if (command == IDC_FORWARD) | |
107 action = TouchBarAction::FORWARD; | |
108 else if (command == IDC_STOP) | |
109 action = TouchBarAction::STOP; | |
110 else if (command == IDC_RELOAD) | |
111 action = TouchBarAction::RELOAD; | |
112 else if (command == IDC_HOME) | |
113 action = TouchBarAction::HOME; | |
114 else if (command == IDC_FOCUS_LOCATION) | |
115 action = TouchBarAction::SEARCH; | |
116 else if (command == IDC_BOOKMARK_PAGE) | |
117 action = TouchBarAction::STAR; | |
118 else if (command == IDC_NEW_TAB) | |
119 action = TouchBarAction::NEW_TAB; | |
120 else | |
121 action = TouchBarAction::TOUCH_BAR_ACTION_COUNT; | |
122 | |
123 DCHECK_NE(action, TouchBarAction::TOUCH_BAR_ACTION_COUNT); | |
124 UMA_HISTOGRAM_ENUMERATION("TouchBar.Default.Metrics", action, | |
125 TOUCH_BAR_ACTION_COUNT); | |
126 } | |
127 | |
86 // A class registered for C++ notifications. This is used to detect changes in | 128 // A class registered for C++ notifications. This is used to detect changes in |
87 // the home button preferences and update the Touch Bar. | 129 // the home button preferences and update the Touch Bar. |
88 class HomePrefNotificationBridge { | 130 class HomePrefNotificationBridge { |
89 public: | 131 public: |
90 explicit HomePrefNotificationBridge(BrowserWindowController* bwc) | 132 explicit HomePrefNotificationBridge(BrowserWindowController* bwc) |
91 : bwc_(bwc) {} | 133 : bwc_(bwc) {} |
92 | 134 |
93 ~HomePrefNotificationBridge() {} | 135 ~HomePrefNotificationBridge() {} |
94 | 136 |
95 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; } | 137 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 searchButton.imageHugsTitle = YES; | 303 searchButton.imageHugsTitle = YES; |
262 searchButton.tag = IDC_FOCUS_LOCATION; | 304 searchButton.tag = IDC_FOCUS_LOCATION; |
263 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn | 305 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn |
264 : kSearchBtnWidthWithoutHomeBtn; | 306 : kSearchBtnWidthWithoutHomeBtn; |
265 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES; | 307 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES; |
266 return searchButton; | 308 return searchButton; |
267 } | 309 } |
268 | 310 |
269 - (void)backOrForward:(id)sender { | 311 - (void)backOrForward:(id)sender { |
270 NSSegmentedControl* control = sender; | 312 NSSegmentedControl* control = sender; |
271 if ([control selectedSegment] == kBackSegmentIndex) | 313 int command = |
272 commandUpdater_->ExecuteCommand(IDC_BACK); | 314 [control selectedSegment] == kBackSegmentIndex ? IDC_BACK : IDC_FORWARD; |
273 else | 315 LogTouchBarUMA(command); |
274 commandUpdater_->ExecuteCommand(IDC_FORWARD); | 316 commandUpdater_->ExecuteCommand(command); |
275 } | 317 } |
276 | 318 |
277 - (void)executeCommand:(id)sender { | 319 - (void)executeCommand:(id)sender { |
278 commandUpdater_->ExecuteCommand([sender tag]); | 320 int command = [sender tag]; |
321 LogTouchBarUMA(command); | |
322 commandUpdater_->ExecuteCommand(command); | |
279 } | 323 } |
280 | 324 |
281 @end | 325 @end |
OLD | NEW |