| 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_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 // A value to indicate tab layout should use the full available width of the | 85 // A value to indicate tab layout should use the full available width of the |
| 86 // view. | 86 // view. |
| 87 const CGFloat kUseFullAvailableWidth = -1.0; | 87 const CGFloat kUseFullAvailableWidth = -1.0; |
| 88 | 88 |
| 89 // The amount by which pinned tabs are separated from normal tabs. | 89 // The amount by which pinned tabs are separated from normal tabs. |
| 90 const CGFloat kLastPinnedTabSpacing = 2.0; | 90 const CGFloat kLastPinnedTabSpacing = 2.0; |
| 91 | 91 |
| 92 // The amount by which the new tab button is offset (from the tabs). | 92 // The amount by which the new tab button is offset (from the tabs). |
| 93 const CGFloat kNewTabButtonOffset = 10.0; | 93 const CGFloat kNewTabButtonOffset = 10.0; |
| 94 const CGFloat kNewTabButtonOffsetNonMD = 8.0; | |
| 95 | 94 |
| 96 // Time (in seconds) in which tabs animate to their final position. | 95 // Time (in seconds) in which tabs animate to their final position. |
| 97 const NSTimeInterval kAnimationDuration = 0.125; | 96 const NSTimeInterval kAnimationDuration = 0.125; |
| 98 | 97 |
| 99 // Helper class for doing NSAnimationContext calls that takes a bool to disable | 98 // Helper class for doing NSAnimationContext calls that takes a bool to disable |
| 100 // all the work. Useful for code that wants to conditionally animate. | 99 // all the work. Useful for code that wants to conditionally animate. |
| 101 class ScopedNSAnimationContextGroup { | 100 class ScopedNSAnimationContextGroup { |
| 102 public: | 101 public: |
| 103 explicit ScopedNSAnimationContextGroup(bool animate) | 102 explicit ScopedNSAnimationContextGroup(bool animate) |
| 104 : animate_(animate) { | 103 : animate_(animate) { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 // window controls. | 562 // window controls. |
| 564 return 70.0; | 563 return 70.0; |
| 565 } | 564 } |
| 566 | 565 |
| 567 + (CGFloat)tabOverlap { | 566 + (CGFloat)tabOverlap { |
| 568 // The overlap value needs to be <= the x position of the favicon within a | 567 // The overlap value needs to be <= the x position of the favicon within a |
| 569 // tab. Else, every time the throbber is painted, the throbber's invalidation | 568 // tab. Else, every time the throbber is painted, the throbber's invalidation |
| 570 // will also invalidate parts of the tab to the left, and two tabs's | 569 // will also invalidate parts of the tab to the left, and two tabs's |
| 571 // backgrounds need to be painted on each throbber frame instead of one. | 570 // backgrounds need to be painted on each throbber frame instead of one. |
| 572 const CGFloat kTabOverlap = 18.0; | 571 const CGFloat kTabOverlap = 18.0; |
| 573 const CGFloat kTabOverlapNonMD = 19.0; | |
| 574 | |
| 575 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 576 return kTabOverlapNonMD; | |
| 577 } | |
| 578 return kTabOverlap; | 572 return kTabOverlap; |
| 579 } | 573 } |
| 580 | 574 |
| 581 // Finds the TabContentsController associated with the given index into the tab | 575 // Finds the TabContentsController associated with the given index into the tab |
| 582 // model and swaps out the sole child of the contentArea to display its | 576 // model and swaps out the sole child of the contentArea to display its |
| 583 // contents. | 577 // contents. |
| 584 - (void)swapInTabAtIndex:(NSInteger)modelIndex { | 578 - (void)swapInTabAtIndex:(NSInteger)modelIndex { |
| 585 DCHECK(modelIndex >= 0 && modelIndex < tabStripModel_->count()); | 579 DCHECK(modelIndex >= 0 && modelIndex < tabStripModel_->count()); |
| 586 NSInteger index = [self indexFromModelIndex:modelIndex]; | 580 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 587 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; | 581 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 // pinned tabs have a fixed width. We may not be able to use the entire width | 918 // pinned tabs have a fixed width. We may not be able to use the entire width |
| 925 // if the user is quickly closing tabs. This may be negative, but that's okay | 919 // if the user is quickly closing tabs. This may be negative, but that's okay |
| 926 // (taken care of by |MAX()| when calculating tab sizes). | 920 // (taken care of by |MAX()| when calculating tab sizes). |
| 927 CGFloat availableSpace = 0; | 921 CGFloat availableSpace = 0; |
| 928 if ([self inRapidClosureMode]) { | 922 if ([self inRapidClosureMode]) { |
| 929 availableSpace = availableResizeWidth_; | 923 availableSpace = availableResizeWidth_; |
| 930 } else { | 924 } else { |
| 931 availableSpace = NSWidth([tabStripView_ frame]); | 925 availableSpace = NSWidth([tabStripView_ frame]); |
| 932 | 926 |
| 933 // Account for the width of the new tab button. | 927 // Account for the width of the new tab button. |
| 934 if (!ui::MaterialDesignController::IsModeMaterial()) { | 928 availableSpace -= |
| 935 availableSpace -= | 929 NSWidth([newTabButton_ frame]) + kNewTabButtonOffset - kTabOverlap; |
| 936 NSWidth([newTabButton_ frame]) + kNewTabButtonOffsetNonMD - | |
| 937 kTabOverlap; | |
| 938 } else { | |
| 939 availableSpace -= | |
| 940 NSWidth([newTabButton_ frame]) + kNewTabButtonOffset - kTabOverlap; | |
| 941 } | |
| 942 // Account for the right-side controls if not in rapid closure mode. | 930 // Account for the right-side controls if not in rapid closure mode. |
| 943 // (In rapid closure mode, the available width is set based on the | 931 // (In rapid closure mode, the available width is set based on the |
| 944 // position of the rightmost tab, not based on the width of the tab strip, | 932 // position of the rightmost tab, not based on the width of the tab strip, |
| 945 // so the right controls have already been accounted for.) | 933 // so the right controls have already been accounted for.) |
| 946 availableSpace -= [self rightIndentForControls]; | 934 availableSpace -= [self rightIndentForControls]; |
| 947 } | 935 } |
| 948 | 936 |
| 949 // Need to leave room for the left-side controls even in rapid closure mode. | 937 // Need to leave room for the left-side controls even in rapid closure mode. |
| 950 availableSpace -= [self leftIndentForControls]; | 938 availableSpace -= [self leftIndentForControls]; |
| 951 | 939 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 tabStripModel_->IsTabPinned(modelIndex); // Always show icon if pinned. | 1547 tabStripModel_->IsTabPinned(modelIndex); // Always show icon if pinned. |
| 1560 | 1548 |
| 1561 TabLoadingState oldState = [tabController loadingState]; | 1549 TabLoadingState oldState = [tabController loadingState]; |
| 1562 TabLoadingState newState = kTabDone; | 1550 TabLoadingState newState = kTabDone; |
| 1563 NSImage* throbberImage = nil; | 1551 NSImage* throbberImage = nil; |
| 1564 if (contents->IsCrashed()) { | 1552 if (contents->IsCrashed()) { |
| 1565 newState = kTabCrashed; | 1553 newState = kTabCrashed; |
| 1566 newHasIcon = true; | 1554 newHasIcon = true; |
| 1567 } else if (contents->IsWaitingForResponse()) { | 1555 } else if (contents->IsWaitingForResponse()) { |
| 1568 newState = kTabWaiting; | 1556 newState = kTabWaiting; |
| 1569 if (ui::MaterialDesignController::IsModeMaterial() && | 1557 if ([[[tabController view] window] hasDarkTheme]) { |
| 1570 [[[tabController view] window] hasDarkTheme]) { | |
| 1571 throbberImage = throbberWaitingIncognitoImage; | 1558 throbberImage = throbberWaitingIncognitoImage; |
| 1572 } else { | 1559 } else { |
| 1573 throbberImage = throbberWaitingImage; | 1560 throbberImage = throbberWaitingImage; |
| 1574 } | 1561 } |
| 1575 } else if (contents->IsLoadingToDifferentDocument()) { | 1562 } else if (contents->IsLoadingToDifferentDocument()) { |
| 1576 newState = kTabLoading; | 1563 newState = kTabLoading; |
| 1577 if (ui::MaterialDesignController::IsModeMaterial() && | 1564 if ([[[tabController view] window] hasDarkTheme]) { |
| 1578 [[[tabController view] window] hasDarkTheme]) { | |
| 1579 throbberImage = throbberLoadingIncognitoImage; | 1565 throbberImage = throbberLoadingIncognitoImage; |
| 1580 } else { | 1566 } else { |
| 1581 throbberImage = throbberLoadingImage; | 1567 throbberImage = throbberLoadingImage; |
| 1582 } | 1568 } |
| 1583 } | 1569 } |
| 1584 | 1570 |
| 1585 if (oldState != newState) | 1571 if (oldState != newState) |
| 1586 [tabController setLoadingState:newState]; | 1572 [tabController setLoadingState:newState]; |
| 1587 | 1573 |
| 1588 // While loading, this function is called repeatedly with the same state. | 1574 // While loading, this function is called repeatedly with the same state. |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 for (int i = 0; i < tabStripModel_->count(); i++) { | 2323 for (int i = 0; i < tabStripModel_->count(); i++) { |
| 2338 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2324 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
| 2339 } | 2325 } |
| 2340 } | 2326 } |
| 2341 | 2327 |
| 2342 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2328 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
| 2343 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2329 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
| 2344 } | 2330 } |
| 2345 | 2331 |
| 2346 @end | 2332 @end |
| OLD | NEW |