Chromium Code Reviews| Index: chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| diff --git a/chrome/browser/ui/cocoa/browser_window_touch_bar.mm b/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| index a8400112461baf35401c8cbdb27d6f96eb260726..d87e1399c0a4bf4da419395242deceb49b0f224d 100644 |
| --- a/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| +++ b/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| @@ -6,6 +6,7 @@ |
| #include <memory> |
| +#include "base/mac/foundation_util.h" |
| #include "base/mac/mac_util.h" |
| #import "base/mac/scoped_nsobject.h" |
| #import "base/mac/sdk_forward_declarations.h" |
| @@ -53,16 +54,15 @@ enum TouchBarAction { |
| }; |
| // The touch bar's identifier. |
| -const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = |
| - @"BrowserWindowTouchBarId"; |
| +NSString* const kBrowserWindowTouchBarId = @"browser-window"; |
| // Touch bar items identifiers. |
| -const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; |
| -const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; |
| -const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId"; |
| -const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; |
| -const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; |
| -const NSTouchBarItemIdentifier kNewTabTouchId = @"NewTabTouchId"; |
| +NSString* const kBackForwardTouchId = @"BACK-FWD"; |
|
Robert Sesek
2017/04/17 16:56:23
CamelCase instead of all upper?
spqchan
2017/04/17 17:56:37
It's supposed to be upper, since the format is “co
|
| +NSString* const kReloadOrStopTouchId = @"RELOAD-STOP"; |
| +NSString* const kHomeTouchId = @"HOME"; |
| +NSString* const kSearchTouchId = @"SEARCH"; |
| +NSString* const kStarTouchId = @"BOOKMARK"; |
| +NSString* const kNewTabTouchId = @"NEW-TAB"; |
| // The button indexes in the back and forward segment control. |
| const int kBackSegmentIndex = 0; |
| @@ -75,9 +75,8 @@ const SkColor kTouchBarStarActiveColor = gfx::kGoogleBlue500; |
| // The size of the touch bar icons. |
| const int kTouchBarIconSize = 16; |
| -// The width of the search button in the touch bar. |
| -const int kSearchBtnWidthWithHomeBtn = 205; |
| -const int kSearchBtnWidthWithoutHomeBtn = 280; |
| +// The min width of the search button in the touch bar. |
| +const int kSearchBtnMinWidth = 205; |
| // Creates an NSImage from the given VectorIcon. |
| NSImage* CreateNSImageFromIcon(const gfx::VectorIcon& icon, |
| @@ -102,6 +101,18 @@ NSButton* CreateTouchBarButton(const gfx::VectorIcon& icon, |
| return button; |
| } |
| +NSString* CreateTouchBarId(NSString* const touch_bar_id) { |
|
spqchan
2017/04/14 22:46:57
I'm putting these methods here for now, but I thin
Robert Sesek
2017/04/17 16:56:23
Keeping them local to where they're used is defini
Robert Sesek
2017/04/17 16:56:23
Naming nit: The word "Create" implies strong owner
spqchan
2017/04/17 17:56:37
Done.
spqchan
2017/04/17 17:56:37
I was planning on using it in other files in the f
|
| + NSString* chrome_bundle_id = |
| + base::SysUTF8ToNSString(base::mac::BaseBundleID()); |
| + return [NSString stringWithFormat:@"%@-%@", chrome_bundle_id, touch_bar_id]; |
|
Robert Sesek
2017/04/17 16:56:23
Use dots instead of dashes? And on line 113.
spqchan
2017/04/17 17:56:37
The format is “com.company-name.app-name.alphanume
Robert Sesek
2017/04/17 17:57:54
Is there a dot between the base bundle ID and the
|
| +} |
| + |
| +NSString* CreateTouchBarItemId(NSString* const touch_bar_id, |
| + NSString* const item_id) { |
| + return [NSString |
| + stringWithFormat:@"%@-%@", CreateTouchBarId(touch_bar_id), item_id]; |
| +} |
| + |
| TouchBarAction TouchBarActionFromCommand(int command) { |
| switch (command) { |
| case IDC_BACK: |
| @@ -205,22 +216,30 @@ class HomePrefNotificationBridge { |
| base::scoped_nsobject<NSTouchBar> touchBar( |
| [[NSClassFromString(@"NSTouchBar") alloc] init]); |
| - NSArray* touchBarItemIdentifiers; |
| - if (showHomeButton_.GetValue()) { |
| - touchBarItemIdentifiers = @[ |
| - kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId, |
| - kStarTouchId, kNewTabTouchId |
| - ]; |
| - } else { |
| - touchBarItemIdentifiers = @[ |
| - kBackForwardTouchId, kReloadOrStopTouchId, kSearchTouchId, kStarTouchId, |
| - kNewTabTouchId |
| - ]; |
| + NSMutableArray* customIdentifiers = [NSMutableArray arrayWithCapacity:7]; |
| + NSMutableArray* defaultIdentifiers = [NSMutableArray arrayWithCapacity:6]; |
| + |
| + NSArray* touchBarItems = @[ |
| + kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId, |
| + kStarTouchId, kNewTabTouchId |
| + ]; |
| + |
| + for (NSString* item in touchBarItems) { |
| + NSString* itemIdentifier = |
| + CreateTouchBarItemId(kBrowserWindowTouchBarId, item); |
| + [customIdentifiers addObject:itemIdentifier]; |
| + |
| + // Don't add the home button if it's not shown in the toolbar. |
| + if (showHomeButton_.GetValue() || ![item isEqualTo:kHomeTouchId]) |
| + [defaultIdentifiers addObject:itemIdentifier]; |
| } |
| - [touchBar setCustomizationIdentifier:kBrowserWindowTouchBarId]; |
| - [touchBar setDefaultItemIdentifiers:touchBarItemIdentifiers]; |
| - [touchBar setCustomizationAllowedItemIdentifiers:touchBarItemIdentifiers]; |
| + [customIdentifiers addObject:NSTouchBarItemIdentifierFlexibleSpace]; |
| + |
| + [touchBar |
| + setCustomizationIdentifier:CreateTouchBarId(kBrowserWindowTouchBarId)]; |
| + [touchBar setDefaultItemIdentifiers:defaultIdentifiers]; |
| + [touchBar setCustomizationAllowedItemIdentifiers:customIdentifiers]; |
| [touchBar setDelegate:self]; |
| return touchBar.autorelease(); |
| @@ -233,23 +252,35 @@ class HomePrefNotificationBridge { |
| base::scoped_nsobject<NSCustomTouchBarItem> touchBarItem([[NSClassFromString( |
| @"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); |
| - if ([identifier isEqualTo:kBackForwardTouchId]) { |
| + if ([identifier hasSuffix:kBackForwardTouchId]) { |
| [touchBarItem setView:[self backOrForwardTouchBarView]]; |
| - } else if ([identifier isEqualTo:kReloadOrStopTouchId]) { |
| + [touchBarItem setCustomizationLabel: |
| + l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_BACK_FORWARD_CUSTOMIZATION_LABEL)]; |
| + } else if ([identifier hasSuffix:kReloadOrStopTouchId]) { |
| const gfx::VectorIcon& icon = |
| isPageLoading_ ? kNavigateStopIcon : kNavigateReloadIcon; |
| int commandId = isPageLoading_ ? IDC_STOP : IDC_RELOAD; |
| int tooltipId = isPageLoading_ ? IDS_TOOLTIP_STOP : IDS_TOOLTIP_RELOAD; |
| [touchBarItem |
| setView:CreateTouchBarButton(icon, self, commandId, tooltipId)]; |
| - } else if ([identifier isEqualTo:kHomeTouchId]) { |
| + [touchBarItem setCustomizationLabel: |
| + l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_STOP_RELOAD_CUSTOMIZATION_LABEL)]; |
| + } else if ([identifier hasSuffix:kHomeTouchId]) { |
| [touchBarItem setView:CreateTouchBarButton(kNavigateHomeIcon, self, |
| IDC_HOME, IDS_TOOLTIP_HOME)]; |
| - } else if ([identifier isEqualTo:kNewTabTouchId]) { |
| + [touchBarItem |
| + setCustomizationLabel:l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_HOME_CUSTOMIZATION_LABEL)]; |
| + } else if ([identifier hasSuffix:kNewTabTouchId]) { |
| [touchBarItem |
| setView:CreateTouchBarButton(kNewTabMacTouchbarIcon, self, IDC_NEW_TAB, |
| IDS_TOOLTIP_NEW_TAB)]; |
| - } else if ([identifier isEqualTo:kStarTouchId]) { |
| + [touchBarItem |
| + setCustomizationLabel:l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_NEW_TAB_CUSTOMIZATION_LABEL)]; |
| + } else if ([identifier hasSuffix:kStarTouchId]) { |
| const gfx::VectorIcon& icon = |
| isStarred_ ? toolbar::kStarActiveIcon : toolbar::kStarIcon; |
| SkColor iconColor = |
| @@ -257,8 +288,13 @@ class HomePrefNotificationBridge { |
| int tooltipId = isStarred_ ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR; |
| [touchBarItem setView:CreateTouchBarButton(icon, self, IDC_BOOKMARK_PAGE, |
| tooltipId, iconColor)]; |
| - } else if ([identifier isEqualTo:kSearchTouchId]) { |
| + [touchBarItem |
| + setCustomizationLabel:l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_BOOKMARK_CUSTOMIZATION_LABEL)]; |
| + } else if ([identifier hasSuffix:kSearchTouchId]) { |
| [touchBarItem setView:[self searchTouchBarView]]; |
| + [touchBarItem setCustomizationLabel:l10n_util::GetNSString( |
| + IDS_TOUCH_BAR_GOOGLE_SEARCH)]; |
| } |
| return touchBarItem.autorelease(); |
| @@ -329,9 +365,12 @@ class HomePrefNotificationBridge { |
| action:@selector(executeCommand:)]; |
| searchButton.imageHugsTitle = YES; |
| searchButton.tag = IDC_FOCUS_LOCATION; |
| - int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn |
| - : kSearchBtnWidthWithoutHomeBtn; |
| - [searchButton.widthAnchor constraintEqualToConstant:width].active = YES; |
| + [searchButton.widthAnchor |
| + constraintGreaterThanOrEqualToConstant:kSearchBtnMinWidth] |
| + .active = YES; |
| + [searchButton |
| + setContentHuggingPriority:1.0 |
| + forOrientation:NSLayoutConstraintOrientationHorizontal]; |
| return searchButton; |
| } |