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..d884dd1992323ad1387e200ad8e7949522486b82 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"; |
+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* GetTouchBarId(NSString* const touch_bar_id) { |
+ NSString* chrome_bundle_id = |
+ base::SysUTF8ToNSString(base::mac::BaseBundleID()); |
+ return [NSString stringWithFormat:@"%@.%@", chrome_bundle_id, touch_bar_id]; |
+} |
+ |
+NSString* GetTouchBarItemId(NSString* const touch_bar_id, |
+ NSString* const item_id) { |
+ return [NSString |
+ stringWithFormat:@"%@-%@", GetTouchBarId(touch_bar_id), item_id]; |
+} |
+ |
TouchBarAction TouchBarActionFromCommand(int command) { |
switch (command) { |
case IDC_BACK: |
@@ -205,22 +216,29 @@ 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 = |
+ GetTouchBarItemId(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:GetTouchBarId(kBrowserWindowTouchBarId)]; |
+ [touchBar setDefaultItemIdentifiers:defaultIdentifiers]; |
+ [touchBar setCustomizationAllowedItemIdentifiers:customIdentifiers]; |
[touchBar setDelegate:self]; |
return touchBar.autorelease(); |
@@ -233,23 +251,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 +287,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 +364,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; |
} |