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 { return 246; } |
77 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
78 return 214; | |
79 } | |
80 return 246; | |
81 } | |
82 | 74 |
83 + (CGFloat)pinnedTabWidth { return 58; } | 75 + (CGFloat)pinnedTabWidth { return 58; } |
84 | 76 |
85 - (TabView*)tabView { | 77 - (TabView*)tabView { |
86 DCHECK([[self view] isKindOfClass:[TabView class]]); | 78 DCHECK([[self view] isKindOfClass:[TabView class]]); |
87 return static_cast<TabView*>([self view]); | 79 return static_cast<TabView*>([self view]); |
88 } | 80 } |
89 | 81 |
90 - (id)init { | 82 - (id)init { |
91 if ((self = [super init])) { | 83 if ((self = [super init])) { |
92 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | |
93 // Icon. | 84 // Icon. |
94 // Remember the icon's frame, so that if the icon is ever removed, a new | 85 // 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. | 86 // one can later replace it in the proper location. |
96 originalIconFrame_ = NSMakeRect(18, 6, 16, 16); | 87 originalIconFrame_ = NSMakeRect(18, 6, 16, 16); |
97 if (!isModeMaterial) { | |
98 originalIconFrame_ = NSMakeRect(19, 5, 16, 16); | |
99 } | |
100 iconView_.reset([[SpriteView alloc] initWithFrame:originalIconFrame_]); | 88 iconView_.reset([[SpriteView alloc] initWithFrame:originalIconFrame_]); |
101 [iconView_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; | 89 [iconView_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
102 | 90 |
103 // When the icon is removed, the title expands to the left to fill the | 91 // 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 | 92 // 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 | 93 // 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 | 94 // 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 | 95 // 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. | 96 // we can just get that value for the close button's frame. |
109 NSRect titleFrame = NSMakeRect(35, 6, 92, 17); | 97 NSRect titleFrame = NSMakeRect(35, 6, 92, 17); |
110 | 98 |
111 // Close button. | 99 // Close button. |
112 NSRect closeButtonFrame = NSMakeRect(129, 6, 16, 16); | 100 NSRect closeButtonFrame = NSMakeRect(129, 6, 16, 16); |
113 if (!isModeMaterial) { | |
114 closeButtonFrame = NSMakeRect(127, 4, 18, 18); | |
115 } | |
116 closeButton_.reset([[HoverCloseButton alloc] initWithFrame: | 101 closeButton_.reset([[HoverCloseButton alloc] initWithFrame: |
117 closeButtonFrame]); | 102 closeButtonFrame]); |
118 [closeButton_ setAutoresizingMask:NSViewMinXMargin]; | 103 [closeButton_ setAutoresizingMask:NSViewMinXMargin]; |
119 [closeButton_ setTarget:self]; | 104 [closeButton_ setTarget:self]; |
120 [closeButton_ setAction:@selector(closeTab:)]; | 105 [closeButton_ setAction:@selector(closeTab:)]; |
121 | 106 |
122 base::scoped_nsobject<TabView> view([[TabView alloc] | 107 base::scoped_nsobject<TabView> view([[TabView alloc] |
123 initWithFrame:NSMakeRect(0, 0, 160, [TabController defaultTabHeight]) | 108 initWithFrame:NSMakeRect(0, 0, 160, [TabController defaultTabHeight]) |
124 controller:self | 109 controller:self |
125 closeButton:closeButton_]); | 110 closeButton:closeButton_]); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 394 |
410 // Adjust the title view based on changes to the icon's and close button's | 395 // Adjust the title view based on changes to the icon's and close button's |
411 // visibility. | 396 // visibility. |
412 NSRect oldTitleFrame = [tabView titleFrame]; | 397 NSRect oldTitleFrame = [tabView titleFrame]; |
413 NSRect newTitleFrame; | 398 NSRect newTitleFrame; |
414 newTitleFrame.size.height = oldTitleFrame.size.height; | 399 newTitleFrame.size.height = oldTitleFrame.size.height; |
415 newTitleFrame.origin.y = oldTitleFrame.origin.y; | 400 newTitleFrame.origin.y = oldTitleFrame.origin.y; |
416 | 401 |
417 if (newShowIcon) { | 402 if (newShowIcon) { |
418 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; | 403 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; |
419 | |
420 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
421 newTitleFrame.origin.x -= 4; | |
422 } | |
423 } else { | 404 } else { |
424 newTitleFrame.origin.x = originalIconFrame_.origin.x; | 405 newTitleFrame.origin.x = originalIconFrame_.origin.x; |
425 } | 406 } |
426 | 407 |
427 if (newShowAlertIndicator) { | 408 if (newShowAlertIndicator) { |
428 newTitleFrame.size.width = NSMinX([alertIndicatorButton_ frame]) - | 409 newTitleFrame.size.width = NSMinX([alertIndicatorButton_ frame]) - |
429 newTitleFrame.origin.x; | 410 newTitleFrame.origin.x; |
430 } else if (newShowCloseButton) { | 411 } else if (newShowCloseButton) { |
431 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - | 412 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - |
432 newTitleFrame.origin.x; | 413 newTitleFrame.origin.x; |
(...skipping 27 matching lines...) Expand all Loading... |
460 YES : NO; | 441 YES : NO; |
461 } | 442 } |
462 return NO; | 443 return NO; |
463 } | 444 } |
464 | 445 |
465 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { | 446 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { |
466 [[target_ dragController] maybeStartDrag:event forTab:tab]; | 447 [[target_ dragController] maybeStartDrag:event forTab:tab]; |
467 } | 448 } |
468 | 449 |
469 @end | 450 @end |
OLD | NEW |