OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tab_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_strip_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 // Divide up the space between the non-mini-tabs. | 784 // Divide up the space between the non-mini-tabs. |
785 nonMiniTabWidth = availableSpaceForNonMini / numberOfOpenNonMiniTabs; | 785 nonMiniTabWidth = availableSpaceForNonMini / numberOfOpenNonMiniTabs; |
786 | 786 |
787 // Clamp the width between the max and min. | 787 // Clamp the width between the max and min. |
788 nonMiniTabWidth = MAX(MIN(nonMiniTabWidth, kMaxTabWidth), kMinTabWidth); | 788 nonMiniTabWidth = MAX(MIN(nonMiniTabWidth, kMaxTabWidth), kMinTabWidth); |
789 } | 789 } |
790 | 790 |
791 BOOL visible = [[tabStripView_ window] isVisible]; | 791 BOOL visible = [[tabStripView_ window] isVisible]; |
792 | 792 |
793 CGFloat offset = [self indentForControls]; | 793 CGFloat offset = [self indentForControls]; |
794 NSUInteger i = 0; | |
795 bool hasPlaceholderGap = false; | 794 bool hasPlaceholderGap = false; |
796 for (TabController* tab in tabArray_.get()) { | 795 for (TabController* tab in tabArray_.get()) { |
797 // Ignore a tab that is going through a close animation. | 796 // Ignore a tab that is going through a close animation. |
798 if ([closingControllers_ containsObject:tab]) | 797 if ([closingControllers_ containsObject:tab]) |
799 continue; | 798 continue; |
800 | 799 |
801 BOOL isPlaceholder = [[tab view] isEqual:placeholderTab_]; | 800 BOOL isPlaceholder = [[tab view] isEqual:placeholderTab_]; |
802 NSRect tabFrame = [[tab view] frame]; | 801 NSRect tabFrame = [[tab view] frame]; |
803 tabFrame.size.height = [[self class] defaultTabHeight] + 1; | 802 tabFrame.size.height = [[self class] defaultTabHeight] + 1; |
804 if (verticalLayout_) { | 803 if (verticalLayout_) { |
805 tabFrame.origin.y = availableSpace - tabFrame.size.height - offset; | 804 tabFrame.origin.y = availableSpace - tabFrame.size.height - offset; |
806 tabFrame.origin.x = 0; | 805 tabFrame.origin.x = 0; |
807 } else { | 806 } else { |
808 tabFrame.origin.y = 0; | 807 tabFrame.origin.y = 0; |
809 tabFrame.origin.x = offset; | 808 tabFrame.origin.x = offset; |
810 } | 809 } |
811 // If the tab is hidden, we consider it a new tab. We make it visible | 810 // If the tab is hidden, we consider it a new tab. We make it visible |
812 // and animate it in. | 811 // and animate it in. |
813 BOOL newTab = [[tab view] isHidden]; | 812 BOOL newTab = [[tab view] isHidden]; |
814 if (newTab) { | 813 if (newTab) |
815 [[tab view] setHidden:NO]; | 814 [[tab view] setHidden:NO]; |
816 } | |
817 | 815 |
818 if (isPlaceholder) { | 816 if (isPlaceholder) { |
819 // Move the current tab to the correct location instantly. | 817 // Move the current tab to the correct location instantly. |
820 // We need a duration or else it doesn't cancel an inflight animation. | 818 // We need a duration or else it doesn't cancel an inflight animation. |
821 ScopedNSAnimationContextGroup localAnimationGroup(animate); | 819 ScopedNSAnimationContextGroup localAnimationGroup(animate); |
822 localAnimationGroup.SetCurrentContextShortestDuration(); | 820 localAnimationGroup.SetCurrentContextShortestDuration(); |
823 if (verticalLayout_) | 821 if (verticalLayout_) |
824 tabFrame.origin.y = availableSpace - tabFrame.size.height - offset; | 822 tabFrame.origin.y = availableSpace - tabFrame.size.height - offset; |
825 else | 823 else |
826 tabFrame.origin.x = placeholderFrame_.origin.x; | 824 tabFrame.origin.x = placeholderFrame_.origin.x; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 } | 887 } |
890 | 888 |
891 enclosingRect = NSUnionRect(tabFrame, enclosingRect); | 889 enclosingRect = NSUnionRect(tabFrame, enclosingRect); |
892 | 890 |
893 if (verticalLayout_) { | 891 if (verticalLayout_) { |
894 offset += NSHeight(tabFrame); | 892 offset += NSHeight(tabFrame); |
895 } else { | 893 } else { |
896 offset += NSWidth(tabFrame); | 894 offset += NSWidth(tabFrame); |
897 offset -= kTabOverlap; | 895 offset -= kTabOverlap; |
898 } | 896 } |
899 i++; | |
900 } | 897 } |
901 | 898 |
902 // Hide the new tab button if we're explicitly told to. It may already | 899 // Hide the new tab button if we're explicitly told to. It may already |
903 // be hidden, doing it again doesn't hurt. Otherwise position it | 900 // be hidden, doing it again doesn't hurt. Otherwise position it |
904 // appropriately, showing it if necessary. | 901 // appropriately, showing it if necessary. |
905 if (forceNewTabButtonHidden_) { | 902 if (forceNewTabButtonHidden_) { |
906 [newTabButton_ setHidden:YES]; | 903 [newTabButton_ setHidden:YES]; |
907 } else { | 904 } else { |
908 NSRect newTabNewFrame = [newTabButton_ frame]; | 905 NSRect newTabNewFrame = [newTabButton_ frame]; |
909 // We've already ensured there's enough space for the new tab button | 906 // We've already ensured there's enough space for the new tab button |
910 // so we don't have to check it against the available space. We do need | 907 // so we don't have to check it against the available space. We do need |
911 // to make sure we put it after any placeholder. | 908 // to make sure we put it after any placeholder. |
912 newTabNewFrame.origin = NSMakePoint(offset, 0); | 909 newTabNewFrame.origin = |
913 newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x, | 910 NSMakePoint(MAX(offset, NSMaxX(placeholderFrame_) - kTabOverlap) + |
Nico
2010/12/30 03:56:06
As you would say, "I hate this formatting". Maybe
viettrungluu
2010/12/30 05:07:21
Done. I hated the formatting too. Ironically, intr
| |
914 NSMaxX(placeholderFrame_)) + | 911 kNewTabButtonOffset, 0); |
915 kNewTabButtonOffset; | |
916 if ([tabContentsArray_ count]) | 912 if ([tabContentsArray_ count]) |
917 [newTabButton_ setHidden:NO]; | 913 [newTabButton_ setHidden:NO]; |
918 | 914 |
919 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { | 915 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { |
920 // Set the new tab button image correctly based on where the cursor is. | 916 // Set the new tab button image correctly based on where the cursor is. |
921 NSWindow* window = [tabStripView_ window]; | 917 NSWindow* window = [tabStripView_ window]; |
922 NSPoint currentMouse = [window mouseLocationOutsideOfEventStream]; | 918 NSPoint currentMouse = [window mouseLocationOutsideOfEventStream]; |
923 currentMouse = [tabStripView_ convertPoint:currentMouse fromView:nil]; | 919 currentMouse = [tabStripView_ convertPoint:currentMouse fromView:nil]; |
924 | 920 |
925 BOOL shouldShowHover = [newTabButton_ pointIsOverButton:currentMouse]; | 921 BOOL shouldShowHover = [newTabButton_ pointIsOverButton:currentMouse]; |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1896 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1892 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1897 BrowserWindowController* controller = | 1893 BrowserWindowController* controller = |
1898 (BrowserWindowController*)[[switchView_ window] windowController]; | 1894 (BrowserWindowController*)[[switchView_ window] windowController]; |
1899 DCHECK(index >= 0); | 1895 DCHECK(index >= 0); |
1900 if (index >= 0) { | 1896 if (index >= 0) { |
1901 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1897 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
1902 } | 1898 } |
1903 } | 1899 } |
1904 | 1900 |
1905 @end | 1901 @end |
OLD | NEW |