Chromium Code Reviews| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 id<TabControllerTarget> target_; // weak | 57 id<TabControllerTarget> target_; // weak |
| 58 TabController* owner_; // weak, owns me | 58 TabController* owner_; // weak, owns me |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 } // TabControllerInternal namespace | 61 } // TabControllerInternal namespace |
| 62 | 62 |
| 63 + (CGFloat)defaultTabHeight { | 63 + (CGFloat)defaultTabHeight { |
| 64 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 65 return 26; | |
| 66 } | |
| 67 return 29; | 64 return 29; |
| 68 } | 65 } |
| 69 | 66 |
| 70 // The min widths is the smallest number at which the right edge of the right | 67 // The min widths is the smallest number at which the right edge of the right |
| 71 // tab border image is not visibly clipped. It is a bit smaller than the sum | 68 // tab border image is not visibly clipped. It is a bit smaller than the sum |
| 72 // of the two tab edge bitmaps because these bitmaps have a few transparent | 69 // of the two tab edge bitmaps because these bitmaps have a few transparent |
| 73 // pixels on the side. The selected tab width includes the close button width. | 70 // pixels on the side. The selected tab width includes the close button width. |
| 74 + (CGFloat)minTabWidth { return 36; } | 71 + (CGFloat)minTabWidth { return 36; } |
| 75 + (CGFloat)minActiveTabWidth { return 52; } | 72 + (CGFloat)minActiveTabWidth { return 52; } |
| 76 + (CGFloat)maxTabWidth { | 73 + (CGFloat)maxTabWidth { |
| 77 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 78 return 214; | |
| 79 } | |
| 80 return 246; | 74 return 246; |
|
Avi (use Gerrit)
2016/09/22 19:14:05
Style this to match the two functions above.
Elly Fong-Jones
2016/09/23 12:28:16
Done.
| |
| 81 } | 75 } |
| 82 | 76 |
| 83 + (CGFloat)pinnedTabWidth { return 58; } | 77 + (CGFloat)pinnedTabWidth { return 58; } |
| 84 | 78 |
| 85 - (TabView*)tabView { | 79 - (TabView*)tabView { |
| 86 DCHECK([[self view] isKindOfClass:[TabView class]]); | 80 DCHECK([[self view] isKindOfClass:[TabView class]]); |
| 87 return static_cast<TabView*>([self view]); | 81 return static_cast<TabView*>([self view]); |
| 88 } | 82 } |
| 89 | 83 |
| 90 - (id)init { | 84 - (id)init { |
| 91 if ((self = [super init])) { | 85 if ((self = [super init])) { |
| 92 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | |
| 93 // Icon. | 86 // Icon. |
| 94 // Remember the icon's frame, so that if the icon is ever removed, a new | 87 // Remember the icon's frame, so that if the icon is ever removed, a new |
| 95 // one can later replace it in the proper location. | 88 // one can later replace it in the proper location. |
| 96 originalIconFrame_ = NSMakeRect(18, 6, 16, 16); | 89 originalIconFrame_ = NSMakeRect(18, 6, 16, 16); |
| 97 if (!isModeMaterial) { | |
| 98 originalIconFrame_ = NSMakeRect(19, 5, 16, 16); | |
| 99 } | |
| 100 iconView_.reset([[SpriteView alloc] initWithFrame:originalIconFrame_]); | 90 iconView_.reset([[SpriteView alloc] initWithFrame:originalIconFrame_]); |
| 101 [iconView_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; | 91 [iconView_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
| 102 | 92 |
| 103 // When the icon is removed, the title expands to the left to fill the | 93 // When the icon is removed, the title expands to the left to fill the |
| 104 // space left by the icon. When the close button is removed, the title | 94 // space left by the icon. When the close button is removed, the title |
| 105 // expands to the right to fill its space. These are the amounts to expand | 95 // expands to the right to fill its space. These are the amounts to expand |
| 106 // and contract the title frame under those conditions. We don't have to | 96 // and contract the title frame under those conditions. We don't have to |
| 107 // explicilty save the offset between the title and the close button since | 97 // explicilty save the offset between the title and the close button since |
| 108 // we can just get that value for the close button's frame. | 98 // we can just get that value for the close button's frame. |
| 109 NSRect titleFrame = NSMakeRect(35, 6, 92, 17); | 99 NSRect titleFrame = NSMakeRect(35, 6, 92, 17); |
| 110 | 100 |
| 111 // Close button. | 101 // Close button. |
| 112 NSRect closeButtonFrame = NSMakeRect(129, 6, 16, 16); | 102 NSRect closeButtonFrame = NSMakeRect(129, 6, 16, 16); |
| 113 if (!isModeMaterial) { | |
| 114 closeButtonFrame = NSMakeRect(127, 4, 18, 18); | |
| 115 } | |
| 116 closeButton_.reset([[HoverCloseButton alloc] initWithFrame: | 103 closeButton_.reset([[HoverCloseButton alloc] initWithFrame: |
| 117 closeButtonFrame]); | 104 closeButtonFrame]); |
| 118 [closeButton_ setAutoresizingMask:NSViewMinXMargin]; | 105 [closeButton_ setAutoresizingMask:NSViewMinXMargin]; |
| 119 [closeButton_ setTarget:self]; | 106 [closeButton_ setTarget:self]; |
| 120 [closeButton_ setAction:@selector(closeTab:)]; | 107 [closeButton_ setAction:@selector(closeTab:)]; |
| 121 | 108 |
| 122 base::scoped_nsobject<TabView> view([[TabView alloc] | 109 base::scoped_nsobject<TabView> view([[TabView alloc] |
| 123 initWithFrame:NSMakeRect(0, 0, 160, [TabController defaultTabHeight]) | 110 initWithFrame:NSMakeRect(0, 0, 160, [TabController defaultTabHeight]) |
| 124 controller:self | 111 controller:self |
| 125 closeButton:closeButton_]); | 112 closeButton:closeButton_]); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 396 |
| 410 // Adjust the title view based on changes to the icon's and close button's | 397 // Adjust the title view based on changes to the icon's and close button's |
| 411 // visibility. | 398 // visibility. |
| 412 NSRect oldTitleFrame = [tabView titleFrame]; | 399 NSRect oldTitleFrame = [tabView titleFrame]; |
| 413 NSRect newTitleFrame; | 400 NSRect newTitleFrame; |
| 414 newTitleFrame.size.height = oldTitleFrame.size.height; | 401 newTitleFrame.size.height = oldTitleFrame.size.height; |
| 415 newTitleFrame.origin.y = oldTitleFrame.origin.y; | 402 newTitleFrame.origin.y = oldTitleFrame.origin.y; |
| 416 | 403 |
| 417 if (newShowIcon) { | 404 if (newShowIcon) { |
| 418 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; | 405 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; |
| 419 | |
| 420 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 421 newTitleFrame.origin.x -= 4; | |
| 422 } | |
| 423 } else { | 406 } else { |
| 424 newTitleFrame.origin.x = originalIconFrame_.origin.x; | 407 newTitleFrame.origin.x = originalIconFrame_.origin.x; |
| 425 } | 408 } |
| 426 | 409 |
| 427 if (newShowAlertIndicator) { | 410 if (newShowAlertIndicator) { |
| 428 newTitleFrame.size.width = NSMinX([alertIndicatorButton_ frame]) - | 411 newTitleFrame.size.width = NSMinX([alertIndicatorButton_ frame]) - |
| 429 newTitleFrame.origin.x; | 412 newTitleFrame.origin.x; |
| 430 } else if (newShowCloseButton) { | 413 } else if (newShowCloseButton) { |
| 431 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - | 414 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - |
| 432 newTitleFrame.origin.x; | 415 newTitleFrame.origin.x; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 460 YES : NO; | 443 YES : NO; |
| 461 } | 444 } |
| 462 return NO; | 445 return NO; |
| 463 } | 446 } |
| 464 | 447 |
| 465 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { | 448 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { |
| 466 [[target_ dragController] maybeStartDrag:event forTab:tab]; | 449 [[target_ dragController] maybeStartDrag:event forTab:tab]; |
| 467 } | 450 } |
| 468 | 451 |
| 469 @end | 452 @end |
| OLD | NEW |