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

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

Issue 2860163004: [Mac] Fix for Tab Fullscreen Touch Bar (Closed)
Patch Set: Fix for avi Created 3 years, 7 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" 9 #include "base/mac/foundation_util.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 FORWARD, 51 FORWARD,
52 STOP, 52 STOP,
53 RELOAD, 53 RELOAD,
54 HOME, 54 HOME,
55 SEARCH, 55 SEARCH,
56 STAR, 56 STAR,
57 NEW_TAB, 57 NEW_TAB,
58 TOUCH_BAR_ACTION_COUNT 58 TOUCH_BAR_ACTION_COUNT
59 }; 59 };
60 60
61 // The touch bar's identifier. 61 // Touch bar identifiers.
62 NSString* const kBrowserWindowTouchBarId = @"browser-window"; 62 NSString* const kBrowserWindowTouchBarId = @"browser-window";
63 NSString* const kTabFullscreenTouchBarId = @"tab-fullscreen";
63 64
64 // Touch bar items identifiers. 65 // Touch bar items identifiers.
65 NSString* const kBackForwardTouchId = @"BACK-FWD"; 66 NSString* const kBackForwardTouchId = @"BACK-FWD";
66 NSString* const kReloadOrStopTouchId = @"RELOAD-STOP"; 67 NSString* const kReloadOrStopTouchId = @"RELOAD-STOP";
67 NSString* const kHomeTouchId = @"HOME"; 68 NSString* const kHomeTouchId = @"HOME";
68 NSString* const kSearchTouchId = @"SEARCH"; 69 NSString* const kSearchTouchId = @"SEARCH";
69 NSString* const kStarTouchId = @"BOOKMARK"; 70 NSString* const kStarTouchId = @"BOOKMARK";
70 NSString* const kNewTabTouchId = @"NEW-TAB"; 71 NSString* const kNewTabTouchId = @"NEW-TAB";
71 NSString* const kExitFullscreenTouchId = @"EXIT-FULLSCREEN"; 72 NSString* const kExitFullscreenTouchId = @"EXIT-FULLSCREEN";
72 NSString* const kFullscreenOriginLabelTouchId = @"FULLSCREEN-ORIGIN-LABEL"; 73 NSString* const kFullscreenOriginLabelTouchId = @"FULLSCREEN-ORIGIN-LABEL";
(...skipping 28 matching lines...) Expand all
101 SkColor color = kTouchBarDefaultIconColor) { 102 SkColor color = kTouchBarDefaultIconColor) {
102 NSButton* button = 103 NSButton* button =
103 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 104 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
104 target:owner 105 target:owner
105 action:@selector(executeCommand:)]; 106 action:@selector(executeCommand:)];
106 button.tag = command; 107 button.tag = command;
107 [button setAccessibilityLabel:l10n_util::GetNSString(tooltip_id)]; 108 [button setAccessibilityLabel:l10n_util::GetNSString(tooltip_id)];
108 return button; 109 return button;
109 } 110 }
110 111
111 NSString* GetTouchBarId() { 112 NSString* GetTouchBarId(NSString* touch_bar_id) {
112 NSString* chrome_bundle_id = 113 NSString* chrome_bundle_id =
113 base::SysUTF8ToNSString(base::mac::BaseBundleID()); 114 base::SysUTF8ToNSString(base::mac::BaseBundleID());
114 return [NSString 115 return [NSString stringWithFormat:@"%@.%@", chrome_bundle_id, touch_bar_id];
115 stringWithFormat:@"%@.%@", chrome_bundle_id, kBrowserWindowTouchBarId];
116 } 116 }
117 117
118 TouchBarAction TouchBarActionFromCommand(int command) { 118 TouchBarAction TouchBarActionFromCommand(int command) {
119 switch (command) { 119 switch (command) {
120 case IDC_BACK: 120 case IDC_BACK:
121 return TouchBarAction::BACK; 121 return TouchBarAction::BACK;
122 case IDC_FORWARD: 122 case IDC_FORWARD:
123 return TouchBarAction::FORWARD; 123 return TouchBarAction::FORWARD;
124 case IDC_STOP: 124 case IDC_STOP:
125 return TouchBarAction::STOP; 125 return TouchBarAction::STOP;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 BrowserWindowController* bwc_; // Weak, own us. 175 BrowserWindowController* bwc_; // Weak, own us.
176 176
177 // Used to monitor the optional home button pref. 177 // Used to monitor the optional home button pref.
178 BooleanPrefMember showHomeButton_; 178 BooleanPrefMember showHomeButton_;
179 179
180 // Used to receive and handle notifications for the home button pref. 180 // Used to receive and handle notifications for the home button pref.
181 std::unique_ptr<HomePrefNotificationBridge> notificationBridge_; 181 std::unique_ptr<HomePrefNotificationBridge> notificationBridge_;
182 } 182 }
183 183
184 // Creates and return the back and forward segmented buttons. 184 // Creates and returns a touch bar for tab fullscreen mode.
185 - (NSTouchBar*)createTabFullscreenTouchBar;
186
187 // Creates and returns the back and forward segmented buttons.
185 - (NSView*)backOrForwardTouchBarView; 188 - (NSView*)backOrForwardTouchBarView;
186 189
187 // Creates and returns the search button. 190 // Creates and returns the search button.
188 - (NSView*)searchTouchBarView; 191 - (NSView*)searchTouchBarView;
189 @end 192 @end
190 193
191 @implementation BrowserWindowTouchBar 194 @implementation BrowserWindowTouchBar
192 195
193 @synthesize isPageLoading = isPageLoading_; 196 @synthesize isPageLoading = isPageLoading_;
194 @synthesize isStarred = isStarred_; 197 @synthesize isStarred = isStarred_;
195 198
196 + (NSString*)touchBarIdForItemId:(NSString*)id { 199 + (NSString*)identifierForTouchBarId:(NSString*)touchBarId
197 return [NSString stringWithFormat:@"%@-%@", GetTouchBarId(), id]; 200 itemId:(NSString*)itemId {
201 return
202 [NSString stringWithFormat:@"%@-%@", GetTouchBarId(touchBarId), itemId];
198 } 203 }
199 204
200 - (instancetype)initWithBrowser:(Browser*)browser 205 - (instancetype)initWithBrowser:(Browser*)browser
201 browserWindowController:(BrowserWindowController*)bwc { 206 browserWindowController:(BrowserWindowController*)bwc {
202 if ((self = [self init])) { 207 if ((self = [self init])) {
203 DCHECK(browser); 208 DCHECK(browser);
204 commandUpdater_ = browser->command_controller()->command_updater(); 209 commandUpdater_ = browser->command_controller()->command_updater();
205 browser_ = browser; 210 browser_ = browser;
206 bwc_ = bwc; 211 bwc_ = bwc;
207 212
208 notificationBridge_.reset(new HomePrefNotificationBridge(bwc_)); 213 notificationBridge_.reset(new HomePrefNotificationBridge(bwc_));
209 PrefService* prefs = browser->profile()->GetPrefs(); 214 PrefService* prefs = browser->profile()->GetPrefs();
210 showHomeButton_.Init( 215 showHomeButton_.Init(
211 prefs::kShowHomeButton, prefs, 216 prefs::kShowHomeButton, prefs,
212 base::Bind(&HomePrefNotificationBridge::UpdateTouchBar, 217 base::Bind(&HomePrefNotificationBridge::UpdateTouchBar,
213 base::Unretained(notificationBridge_.get()))); 218 base::Unretained(notificationBridge_.get())));
214 } 219 }
215 220
216 return self; 221 return self;
217 } 222 }
218 223
219 - (NSTouchBar*)makeTouchBar { 224 - (NSTouchBar*)makeTouchBar {
220 if (!base::FeatureList::IsEnabled(features::kBrowserTouchBar)) 225 if (!base::FeatureList::IsEnabled(features::kBrowserTouchBar))
221 return nil; 226 return nil;
222 227
228 // When in tab fullscreen, we should show a touch bar containing only
229 // items associated with that mode. Since the toolbar is hidden, only
230 // the option to exit fullscreen should show up.
231 if ([bwc_ isFullscreenForTabContentOrExtension])
232 return [self createTabFullscreenTouchBar];
233
223 base::scoped_nsobject<NSTouchBar> touchBar( 234 base::scoped_nsobject<NSTouchBar> touchBar(
224 [[NSClassFromString(@"NSTouchBar") alloc] init]); 235 [[NSClassFromString(@"NSTouchBar") alloc] init]);
225 [touchBar setCustomizationIdentifier:GetTouchBarId()]; 236 [touchBar setCustomizationIdentifier:GetTouchBarId(kBrowserWindowTouchBarId)];
226 [touchBar setDelegate:self]; 237 [touchBar setDelegate:self];
227 238
228 // When in tab fullscreen, only the option to exit fullscreen should show up
229 // on the touch bar since the toolbar is hidden in that state.
230 if ([bwc_ isFullscreenForTabContentOrExtension]) {
231 if ([touchBar respondsToSelector:
232 @selector(setEscapeKeyReplacementItemIdentifier:)]) {
233 [touchBar setEscapeKeyReplacementItemIdentifier:
234 [BrowserWindowTouchBar
235 touchBarIdForItemId:kExitFullscreenTouchId]];
236 [touchBar setDefaultItemIdentifiers:@[
237 [BrowserWindowTouchBar
238 touchBarIdForItemId:kFullscreenOriginLabelTouchId]
239 ]];
240 }
241 return touchBar.autorelease();
242 }
243
244 NSMutableArray* customIdentifiers = [NSMutableArray arrayWithCapacity:7]; 239 NSMutableArray* customIdentifiers = [NSMutableArray arrayWithCapacity:7];
245 NSMutableArray* defaultIdentifiers = [NSMutableArray arrayWithCapacity:6]; 240 NSMutableArray* defaultIdentifiers = [NSMutableArray arrayWithCapacity:6];
246 241
247 NSArray* touchBarItems = @[ 242 NSArray* touchBarItems = @[
248 kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId, 243 kBackForwardTouchId, kReloadOrStopTouchId, kHomeTouchId, kSearchTouchId,
249 kStarTouchId, kNewTabTouchId 244 kStarTouchId, kNewTabTouchId
250 ]; 245 ];
251 246
252 for (NSString* item in touchBarItems) { 247 for (NSString* item in touchBarItems) {
253 NSString* itemIdentifier = [BrowserWindowTouchBar touchBarIdForItemId:item]; 248 NSString* itemIdentifier =
249 [BrowserWindowTouchBar identifierForTouchBarId:kBrowserWindowTouchBarId
250 itemId:item];
254 [customIdentifiers addObject:itemIdentifier]; 251 [customIdentifiers addObject:itemIdentifier];
255 252
256 // Don't add the home button if it's not shown in the toolbar. 253 // Don't add the home button if it's not shown in the toolbar.
257 if (showHomeButton_.GetValue() || ![item isEqualTo:kHomeTouchId]) 254 if (showHomeButton_.GetValue() || ![item isEqualTo:kHomeTouchId])
258 [defaultIdentifiers addObject:itemIdentifier]; 255 [defaultIdentifiers addObject:itemIdentifier];
259 } 256 }
260 257
261 [customIdentifiers addObject:NSTouchBarItemIdentifierFlexibleSpace]; 258 [customIdentifiers addObject:NSTouchBarItemIdentifierFlexibleSpace];
262 259
263 [touchBar setDefaultItemIdentifiers:defaultIdentifiers]; 260 [touchBar setDefaultItemIdentifiers:defaultIdentifiers];
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 value:OmniboxViewMac::BaseTextColor(true) 334 value:OmniboxViewMac::BaseTextColor(true)
338 range:NSMakeRange(hostLength, 335 range:NSMakeRange(hostLength,
339 [attributedString length] - hostLength)]; 336 [attributedString length] - hostLength)];
340 [touchBarItem 337 [touchBarItem
341 setView:[NSTextField labelWithAttributedString:attributedString.get()]]; 338 setView:[NSTextField labelWithAttributedString:attributedString.get()]];
342 } 339 }
343 340
344 return touchBarItem.autorelease(); 341 return touchBarItem.autorelease();
345 } 342 }
346 343
344 - (NSTouchBar*)createTabFullscreenTouchBar {
345 base::scoped_nsobject<NSTouchBar> touchBar(
346 [[NSClassFromString(@"NSTouchBar") alloc] init]);
347 [touchBar setDelegate:self];
348
349 if ([touchBar respondsToSelector:@selector
350 (setEscapeKeyReplacementItemIdentifier:)]) {
351 [touchBar setEscapeKeyReplacementItemIdentifier:
352 [BrowserWindowTouchBar
353 identifierForTouchBarId:kTabFullscreenTouchBarId
354 itemId:kExitFullscreenTouchId]];
355 [touchBar setDefaultItemIdentifiers:@[
356 [BrowserWindowTouchBar
357 identifierForTouchBarId:kTabFullscreenTouchBarId
358 itemId:kFullscreenOriginLabelTouchId]
359 ]];
360 }
361
362 return touchBar.autorelease();
363 }
364
347 - (NSView*)backOrForwardTouchBarView { 365 - (NSView*)backOrForwardTouchBarView {
348 NSArray* images = @[ 366 NSArray* images = @[
349 CreateNSImageFromIcon(ui::kBackArrowIcon), 367 CreateNSImageFromIcon(ui::kBackArrowIcon),
350 CreateNSImageFromIcon(ui::kForwardArrowIcon) 368 CreateNSImageFromIcon(ui::kForwardArrowIcon)
351 ]; 369 ];
352 370
353 NSSegmentedControl* control = [NSSegmentedControl 371 NSSegmentedControl* control = [NSSegmentedControl
354 segmentedControlWithImages:images 372 segmentedControlWithImages:images
355 trackingMode:NSSegmentSwitchTrackingMomentary 373 trackingMode:NSSegmentSwitchTrackingMomentary
356 target:self 374 target:self
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 ->ExitExclusiveAccessIfNecessary(); 450 ->ExitExclusiveAccessIfNecessary();
433 } 451 }
434 452
435 - (void)executeCommand:(id)sender { 453 - (void)executeCommand:(id)sender {
436 int command = [sender tag]; 454 int command = [sender tag];
437 LogTouchBarUMA(command); 455 LogTouchBarUMA(command);
438 commandUpdater_->ExecuteCommand(command); 456 commandUpdater_->ExecuteCommand(command);
439 } 457 }
440 458
441 @end 459 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_touch_bar.h ('k') | chrome/browser/ui/cocoa/browser_window_touch_bar_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698