| 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/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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 target:self | 368 target:self |
| 369 action:@selector(exitFullscreenForTab:)]]; | 369 action:@selector(exitFullscreenForTab:)]]; |
| 370 [touchBar | 370 [touchBar |
| 371 setTemplateItems:[NSSet setWithObject:touchBarItem.autorelease()]]; | 371 setTemplateItems:[NSSet setWithObject:touchBarItem.autorelease()]]; |
| 372 } | 372 } |
| 373 | 373 |
| 374 return touchBar.autorelease(); | 374 return touchBar.autorelease(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 - (NSView*)backOrForwardTouchBarView { | 377 - (NSView*)backOrForwardTouchBarView { |
| 378 NSArray* images = @[ | 378 NSMutableArray* images = [NSMutableArray arrayWithArray:@[ |
| 379 CreateNSImageFromIcon(ui::kBackArrowIcon), | 379 CreateNSImageFromIcon(ui::kBackArrowIcon), |
| 380 CreateNSImageFromIcon(ui::kForwardArrowIcon) | 380 CreateNSImageFromIcon(ui::kForwardArrowIcon) |
| 381 ]; | 381 ]]; |
| 382 |
| 383 // Offset the icons so that it matches the height of the other Touch Bar |
| 384 // items. |
| 385 const int kIconYOffset = 2; |
| 386 for (NSUInteger i = 0; i < [images count]; i++) { |
| 387 NSImage* image = [images objectAtIndex:i]; |
| 388 NSSize size = [image size]; |
| 389 size.height += kIconYOffset; |
| 390 |
| 391 NSImage* offsettedImage = [[[NSImage alloc] initWithSize:size] autorelease]; |
| 392 [offsettedImage lockFocus]; |
| 393 [image drawInRect:NSMakeRect(0, 0, size.width, size.height - kIconYOffset)]; |
| 394 [offsettedImage unlockFocus]; |
| 395 [images replaceObjectAtIndex:i withObject:offsettedImage]; |
| 396 } |
| 382 | 397 |
| 383 NSSegmentedControl* control = [NSSegmentedControl | 398 NSSegmentedControl* control = [NSSegmentedControl |
| 384 segmentedControlWithImages:images | 399 segmentedControlWithImages:images |
| 385 trackingMode:NSSegmentSwitchTrackingMomentary | 400 trackingMode:NSSegmentSwitchTrackingMomentary |
| 386 target:self | 401 target:self |
| 387 action:@selector(backOrForward:)]; | 402 action:@selector(backOrForward:)]; |
| 388 control.segmentStyle = NSSegmentStyleSeparated; | 403 control.segmentStyle = NSSegmentStyleSeparated; |
| 389 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_BACK) | 404 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_BACK) |
| 390 forSegment:kBackSegmentIndex]; | 405 forSegment:kBackSegmentIndex]; |
| 391 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_FORWARD) | 406 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_FORWARD) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 ->ExitExclusiveAccessIfNecessary(); | 477 ->ExitExclusiveAccessIfNecessary(); |
| 463 } | 478 } |
| 464 | 479 |
| 465 - (void)executeCommand:(id)sender { | 480 - (void)executeCommand:(id)sender { |
| 466 int command = [sender tag]; | 481 int command = [sender tag]; |
| 467 LogTouchBarUMA(command); | 482 LogTouchBarUMA(command); |
| 468 commandUpdater_->ExecuteCommand(command); | 483 commandUpdater_->ExecuteCommand(command); |
| 469 } | 484 } |
| 470 | 485 |
| 471 @end | 486 @end |
| OLD | NEW |