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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_touch_bar.mm

Issue 2921083003: [Mac] Touch Bar Support for Dialogs (Closed)
Patch Set: nits Created 3 years, 6 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
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/foundation_util.h"
10 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
11 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
12 #import "base/mac/sdk_forward_declarations.h" 11 #import "base/mac/sdk_forward_declarations.h"
13 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/app/vector_icons/vector_icons.h" 15 #include "chrome/app/vector_icons/vector_icons.h"
17 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_command_controller.h" 20 #include "chrome/browser/ui/browser_command_controller.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
23 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 22 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
24 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 23 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
25 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 24 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/chrome_features.h" 26 #include "chrome/common/chrome_features.h"
28 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
30 #include "components/omnibox/browser/vector_icons.h" 29 #include "components/omnibox/browser/vector_icons.h"
31 #include "components/prefs/pref_member.h" 30 #include "components/prefs/pref_member.h"
32 #include "components/search_engines/util.h" 31 #include "components/search_engines/util.h"
33 #include "components/strings/grit/components_strings.h" 32 #include "components/strings/grit/components_strings.h"
34 #include "components/toolbar/vector_icons.h" 33 #include "components/toolbar/vector_icons.h"
35 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #import "ui/base/cocoa/touch_bar_util.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/l10n/l10n_util_mac.h" 37 #include "ui/base/l10n/l10n_util_mac.h"
38 #include "ui/gfx/color_palette.h" 38 #include "ui/gfx/color_palette.h"
39 #include "ui/gfx/color_utils.h" 39 #include "ui/gfx/color_utils.h"
40 #include "ui/gfx/image/image.h" 40 #include "ui/gfx/image/image.h"
41 #include "ui/gfx/image/image_skia_util_mac.h" 41 #include "ui/gfx/image/image_skia_util_mac.h"
42 #include "ui/gfx/paint_vector_icon.h" 42 #include "ui/gfx/paint_vector_icon.h"
43 #include "ui/vector_icons/vector_icons.h" 43 #include "ui/vector_icons/vector_icons.h"
44 44
45 namespace { 45 namespace {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 SkColor color = kTouchBarDefaultIconColor) { 102 SkColor color = kTouchBarDefaultIconColor) {
103 NSButton* button = 103 NSButton* button =
104 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 104 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
105 target:owner 105 target:owner
106 action:@selector(executeCommand:)]; 106 action:@selector(executeCommand:)];
107 button.tag = command; 107 button.tag = command;
108 [button setAccessibilityLabel:l10n_util::GetNSString(tooltip_id)]; 108 [button setAccessibilityLabel:l10n_util::GetNSString(tooltip_id)];
109 return button; 109 return button;
110 } 110 }
111 111
112 NSString* GetTouchBarId(NSString* touch_bar_id) {
113 NSString* chrome_bundle_id =
114 base::SysUTF8ToNSString(base::mac::BaseBundleID());
115 return [NSString stringWithFormat:@"%@.%@", chrome_bundle_id, touch_bar_id];
116 }
117
118 TouchBarAction TouchBarActionFromCommand(int command) { 112 TouchBarAction TouchBarActionFromCommand(int command) {
119 switch (command) { 113 switch (command) {
120 case IDC_BACK: 114 case IDC_BACK:
121 return TouchBarAction::BACK; 115 return TouchBarAction::BACK;
122 case IDC_FORWARD: 116 case IDC_FORWARD:
123 return TouchBarAction::FORWARD; 117 return TouchBarAction::FORWARD;
124 case IDC_STOP: 118 case IDC_STOP:
125 return TouchBarAction::STOP; 119 return TouchBarAction::STOP;
126 case IDC_RELOAD: 120 case IDC_RELOAD:
127 return TouchBarAction::RELOAD; 121 return TouchBarAction::RELOAD;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 183
190 // Creates and returns the search button. 184 // Creates and returns the search button.
191 - (NSView*)searchTouchBarView; 185 - (NSView*)searchTouchBarView;
192 @end 186 @end
193 187
194 @implementation BrowserWindowTouchBar 188 @implementation BrowserWindowTouchBar
195 189
196 @synthesize isPageLoading = isPageLoading_; 190 @synthesize isPageLoading = isPageLoading_;
197 @synthesize isStarred = isStarred_; 191 @synthesize isStarred = isStarred_;
198 192
199 + (NSString*)identifierForTouchBarId:(NSString*)touchBarId
200 itemId:(NSString*)itemId {
201 return
202 [NSString stringWithFormat:@"%@-%@", GetTouchBarId(touchBarId), itemId];
203 }
204
205 - (instancetype)initWithBrowser:(Browser*)browser 193 - (instancetype)initWithBrowser:(Browser*)browser
206 browserWindowController:(BrowserWindowController*)bwc { 194 browserWindowController:(BrowserWindowController*)bwc {
207 if ((self = [self init])) { 195 if ((self = [self init])) {
208 DCHECK(browser); 196 DCHECK(browser);
209 commandUpdater_ = browser->command_controller()->command_updater(); 197 commandUpdater_ = browser->command_controller()->command_updater();
210 browser_ = browser; 198 browser_ = browser;
211 bwc_ = bwc; 199 bwc_ = bwc;
212 200
213 notificationBridge_.reset(new HomePrefNotificationBridge(bwc_)); 201 notificationBridge_.reset(new HomePrefNotificationBridge(bwc_));
214 PrefService* prefs = browser->profile()->GetPrefs(); 202 PrefService* prefs = browser->profile()->GetPrefs();
(...skipping 11 matching lines...) Expand all
226 return nil; 214 return nil;
227 215
228 // When in tab fullscreen, we should show a touch bar containing only 216 // When in tab fullscreen, we should show a touch bar containing only
229 // items associated with that mode. Since the toolbar is hidden, only 217 // items associated with that mode. Since the toolbar is hidden, only
230 // the option to exit fullscreen should show up. 218 // the option to exit fullscreen should show up.
231 if ([bwc_ isFullscreenForTabContentOrExtension]) 219 if ([bwc_ isFullscreenForTabContentOrExtension])
232 return [self createTabFullscreenTouchBar]; 220 return [self createTabFullscreenTouchBar];
233 221
234 base::scoped_nsobject<NSTouchBar> touchBar( 222 base::scoped_nsobject<NSTouchBar> touchBar(
235 [[NSClassFromString(@"NSTouchBar") alloc] init]); 223 [[NSClassFromString(@"NSTouchBar") alloc] init]);
236 [touchBar setCustomizationIdentifier:GetTouchBarId(kBrowserWindowTouchBarId)]; 224 [touchBar setCustomizationIdentifier:ui::CreateTouchBarId(
225 kBrowserWindowTouchBarId)];
237 [touchBar setDelegate:self]; 226 [touchBar setDelegate:self];
238 227
239 NSMutableArray* customIdentifiers = [NSMutableArray arrayWithCapacity:7]; 228 NSMutableArray* customIdentifiers = [NSMutableArray arrayWithCapacity:7];
240 NSMutableArray* defaultIdentifiers = [NSMutableArray arrayWithCapacity:6]; 229 NSMutableArray* defaultIdentifiers = [NSMutableArray arrayWithCapacity:6];
241 230
242 NSArray* touchBarItems = @[ 231 NSArray* touchBarItems = @[
243 kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId, 232 kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId,
244 kStarTouchId, kNewTabTouchId 233 kStarTouchId, kNewTabTouchId
245 ]; 234 ];
246 235
247 for (NSString* item in touchBarItems) { 236 for (NSString* item in touchBarItems) {
248 NSString* itemIdentifier = 237 NSString* itemIdentifier =
249 [BrowserWindowTouchBar identifierForTouchBarId:kBrowserWindowTouchBarId 238 ui::CreateTouchBarItemId(kBrowserWindowTouchBarId, item);
250 itemId:item];
251 [customIdentifiers addObject:itemIdentifier]; 239 [customIdentifiers addObject:itemIdentifier];
252 240
253 // Don't add the home button if it's not shown in the toolbar. 241 // Don't add the home button if it's not shown in the toolbar.
254 if (showHomeButton_.GetValue() || ![item isEqualTo:kHomeTouchId]) 242 if (showHomeButton_.GetValue() || ![item isEqualTo:kHomeTouchId])
255 [defaultIdentifiers addObject:itemIdentifier]; 243 [defaultIdentifiers addObject:itemIdentifier];
256 } 244 }
257 245
258 [customIdentifiers addObject:NSTouchBarItemIdentifierFlexibleSpace]; 246 [customIdentifiers addObject:NSTouchBarItemIdentifierFlexibleSpace];
259 247
260 [touchBar setDefaultItemIdentifiers:defaultIdentifiers]; 248 [touchBar setDefaultItemIdentifiers:defaultIdentifiers];
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return touchBarItem.autorelease(); 329 return touchBarItem.autorelease();
342 } 330 }
343 331
344 - (NSTouchBar*)createTabFullscreenTouchBar { 332 - (NSTouchBar*)createTabFullscreenTouchBar {
345 base::scoped_nsobject<NSTouchBar> touchBar( 333 base::scoped_nsobject<NSTouchBar> touchBar(
346 [[NSClassFromString(@"NSTouchBar") alloc] init]); 334 [[NSClassFromString(@"NSTouchBar") alloc] init]);
347 [touchBar setDelegate:self]; 335 [touchBar setDelegate:self];
348 336
349 if ([touchBar respondsToSelector: 337 if ([touchBar respondsToSelector:
350 @selector(setEscapeKeyReplacementItemIdentifier:)]) { 338 @selector(setEscapeKeyReplacementItemIdentifier:)]) {
351 NSString* exitIdentifier = 339 NSString* exitIdentifier = ui::CreateTouchBarItemId(
352 [BrowserWindowTouchBar identifierForTouchBarId:kTabFullscreenTouchBarId 340 kTabFullscreenTouchBarId, kExitFullscreenTouchId);
353 itemId:kExitFullscreenTouchId];
354 [touchBar setEscapeKeyReplacementItemIdentifier:exitIdentifier]; 341 [touchBar setEscapeKeyReplacementItemIdentifier:exitIdentifier];
355 [touchBar setDefaultItemIdentifiers:@[ 342 [touchBar setDefaultItemIdentifiers:@[ ui::CreateTouchBarItemId(
356 [BrowserWindowTouchBar 343 kTabFullscreenTouchBarId,
357 identifierForTouchBarId:kTabFullscreenTouchBarId 344 kFullscreenOriginLabelTouchId) ]];
358 itemId:kFullscreenOriginLabelTouchId]
359 ]];
360 345
361 base::scoped_nsobject<NSCustomTouchBarItem> touchBarItem( 346 base::scoped_nsobject<NSCustomTouchBarItem> touchBarItem(
362 [[NSClassFromString(@"NSCustomTouchBarItem") alloc] 347 [[NSClassFromString(@"NSCustomTouchBarItem") alloc]
363 initWithIdentifier:exitIdentifier]); 348 initWithIdentifier:exitIdentifier]);
364 349
365 [touchBarItem 350 [touchBarItem
366 setView:[NSButton buttonWithTitle:l10n_util::GetNSString( 351 setView:[NSButton buttonWithTitle:l10n_util::GetNSString(
367 IDS_TOUCH_BAR_EXIT_FULLSCREEN) 352 IDS_TOUCH_BAR_EXIT_FULLSCREEN)
368 target:self 353 target:self
369 action:@selector(exitFullscreenForTab:)]]; 354 action:@selector(exitFullscreenForTab:)]];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 ->ExitExclusiveAccessIfNecessary(); 447 ->ExitExclusiveAccessIfNecessary();
463 } 448 }
464 449
465 - (void)executeCommand:(id)sender { 450 - (void)executeCommand:(id)sender {
466 int command = [sender tag]; 451 int command = [sender tag];
467 LogTouchBarUMA(command); 452 LogTouchBarUMA(command);
468 commandUpdater_->ExecuteCommand(command); 453 commandUpdater_->ExecuteCommand(command);
469 } 454 }
470 455
471 @end 456 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698