| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabs/tab_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #import "chrome/browser/themes/theme_properties.h" | 12 #import "chrome/browser/themes/theme_properties.h" |
| 13 #import "chrome/browser/themes/theme_service.h" | 13 #import "chrome/browser/themes/theme_service.h" |
| 14 #include "chrome/browser/ui/cocoa/l10n_util.h" | |
| 15 #import "chrome/browser/ui/cocoa/sprite_view.h" | 14 #import "chrome/browser/ui/cocoa/sprite_view.h" |
| 16 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h" | 15 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h" |
| 17 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 16 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
| 18 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 17 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 19 #import "chrome/browser/ui/cocoa/themed_window.h" | 18 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 20 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 21 #import "extensions/common/extension.h" | 20 #import "extensions/common/extension.h" |
| 22 #import "ui/base/cocoa/menu_controller.h" | 21 #import "ui/base/cocoa/menu_controller.h" |
| 22 #import "ui/base/cocoa/rtl_feature.h" |
| 23 #include "ui/base/material_design/material_design_controller.h" | 23 #include "ui/base/material_design/material_design_controller.h" |
| 24 | 24 |
| 25 @implementation TabController | 25 @implementation TabController |
| 26 | 26 |
| 27 @synthesize action = action_; | 27 @synthesize action = action_; |
| 28 @synthesize loadingState = loadingState_; | 28 @synthesize loadingState = loadingState_; |
| 29 @synthesize pinned = pinned_; | 29 @synthesize pinned = pinned_; |
| 30 @synthesize target = target_; | 30 @synthesize target = target_; |
| 31 @synthesize url = url_; | 31 @synthesize url = url_; |
| 32 | 32 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 + (CGFloat)pinnedTabWidth { return 58; } | 87 + (CGFloat)pinnedTabWidth { return 58; } |
| 88 | 88 |
| 89 - (TabView*)tabView { | 89 - (TabView*)tabView { |
| 90 DCHECK([[self view] isKindOfClass:[TabView class]]); | 90 DCHECK([[self view] isKindOfClass:[TabView class]]); |
| 91 return static_cast<TabView*>([self view]); | 91 return static_cast<TabView*>([self view]); |
| 92 } | 92 } |
| 93 | 93 |
| 94 - (id)init { | 94 - (id)init { |
| 95 if ((self = [super init])) { | 95 if ((self = [super init])) { |
| 96 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 96 BOOL isRTL = ui::ShouldDoExperimentalRTLLayout(); |
| 97 // Icon. | 97 // Icon. |
| 98 const CGFloat iconOrigin = | 98 const CGFloat iconOrigin = |
| 99 isRTL ? kInitialTabWidth - kTabLeadingPadding - kIconSize | 99 isRTL ? kInitialTabWidth - kTabLeadingPadding - kIconSize |
| 100 : kTabLeadingPadding; | 100 : kTabLeadingPadding; |
| 101 NSRect iconFrame = | 101 NSRect iconFrame = |
| 102 NSMakeRect(iconOrigin, kTabElementYOrigin, kIconSize, kIconSize); | 102 NSMakeRect(iconOrigin, kTabElementYOrigin, kIconSize, kIconSize); |
| 103 iconView_.reset([[SpriteView alloc] initWithFrame:iconFrame]); | 103 iconView_.reset([[SpriteView alloc] initWithFrame:iconFrame]); |
| 104 [iconView_ setAutoresizingMask:isRTL ? NSViewMinXMargin | NSViewMinYMargin | 104 [iconView_ setAutoresizingMask:isRTL ? NSViewMinXMargin | NSViewMinYMargin |
| 105 : NSViewMaxXMargin | NSViewMinYMargin]; | 105 : NSViewMaxXMargin | NSViewMinYMargin]; |
| 106 | 106 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 338 } |
| 339 | 339 |
| 340 - (void)setIconImage:(NSImage*)image { | 340 - (void)setIconImage:(NSImage*)image { |
| 341 [self setIconImage:image withToastAnimation:NO]; | 341 [self setIconImage:image withToastAnimation:NO]; |
| 342 } | 342 } |
| 343 | 343 |
| 344 - (void)setIconImage:(NSImage*)image withToastAnimation:(BOOL)animate { | 344 - (void)setIconImage:(NSImage*)image withToastAnimation:(BOOL)animate { |
| 345 if (image == nil) { | 345 if (image == nil) { |
| 346 [self setIconView:nil]; | 346 [self setIconView:nil]; |
| 347 } else { | 347 } else { |
| 348 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 348 BOOL isRTL = ui::ShouldDoExperimentalRTLLayout(); |
| 349 if (iconView_.get() == nil) { | 349 if (iconView_.get() == nil) { |
| 350 base::scoped_nsobject<SpriteView> iconView([[SpriteView alloc] init]); | 350 base::scoped_nsobject<SpriteView> iconView([[SpriteView alloc] init]); |
| 351 [iconView setAutoresizingMask:isRTL | 351 [iconView setAutoresizingMask:isRTL |
| 352 ? NSViewMinXMargin | NSViewMinYMargin | 352 ? NSViewMinXMargin | NSViewMinYMargin |
| 353 : NSViewMaxXMargin | NSViewMinYMargin]; | 353 : NSViewMaxXMargin | NSViewMinYMargin]; |
| 354 [self setIconView:iconView]; | 354 [self setIconView:iconView]; |
| 355 } | 355 } |
| 356 | 356 |
| 357 [iconView_ setImage:image withToastAnimation:animate]; | 357 [iconView_ setImage:image withToastAnimation:animate]; |
| 358 | 358 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 [tabView setTitleHidden:[self pinned]]; | 391 [tabView setTitleHidden:[self pinned]]; |
| 392 | 392 |
| 393 BOOL newShowCloseButton = [self shouldShowCloseButton]; | 393 BOOL newShowCloseButton = [self shouldShowCloseButton]; |
| 394 | 394 |
| 395 [closeButton_ setHidden:!newShowCloseButton]; | 395 [closeButton_ setHidden:!newShowCloseButton]; |
| 396 | 396 |
| 397 BOOL newShowAlertIndicator = [self shouldShowAlertIndicator]; | 397 BOOL newShowAlertIndicator = [self shouldShowAlertIndicator]; |
| 398 | 398 |
| 399 [alertIndicatorButton_ setHidden:!newShowAlertIndicator]; | 399 [alertIndicatorButton_ setHidden:!newShowAlertIndicator]; |
| 400 | 400 |
| 401 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 401 BOOL isRTL = ui::ShouldDoExperimentalRTLLayout(); |
| 402 | 402 |
| 403 if (newShowAlertIndicator) { | 403 if (newShowAlertIndicator) { |
| 404 NSRect newFrame = [alertIndicatorButton_ frame]; | 404 NSRect newFrame = [alertIndicatorButton_ frame]; |
| 405 newFrame.size = [[alertIndicatorButton_ image] size]; | 405 newFrame.size = [[alertIndicatorButton_ image] size]; |
| 406 if ([self pinned]) { | 406 if ([self pinned]) { |
| 407 // Tab is pinned: Position the alert indicator in the center. | 407 // Tab is pinned: Position the alert indicator in the center. |
| 408 const CGFloat tabWidth = [TabController pinnedTabWidth]; | 408 const CGFloat tabWidth = [TabController pinnedTabWidth]; |
| 409 newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2); | 409 newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2); |
| 410 newFrame.origin.y = | 410 newFrame.origin.y = |
| 411 kTabElementYOrigin - std::floor((NSHeight(newFrame) - kIconSize) / 2); | 411 kTabElementYOrigin - std::floor((NSHeight(newFrame) - kIconSize) / 2); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 YES : NO; | 484 YES : NO; |
| 485 } | 485 } |
| 486 return NO; | 486 return NO; |
| 487 } | 487 } |
| 488 | 488 |
| 489 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { | 489 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { |
| 490 [[target_ dragController] maybeStartDrag:event forTab:tab]; | 490 [[target_ dragController] maybeStartDrag:event forTab:tab]; |
| 491 } | 491 } |
| 492 | 492 |
| 493 @end | 493 @end |
| OLD | NEW |