Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: chrome/browser/cocoa/tab_strip_controller.mm

Issue 3204007: Make tabOverlap dynamic depending on the number of non-mini tabs presented on... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/tab_controller.mm ('k') | chrome/browser/cocoa/tab_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/tab_strip_controller.mm
===================================================================
--- chrome/browser/cocoa/tab_strip_controller.mm (revision 57038)
+++ chrome/browser/cocoa/tab_strip_controller.mm (working copy)
@@ -68,6 +68,9 @@
// incognito badge is present.
const CGFloat kIncognitoBadgeTabStripShrink = 18;
+// The minimum offset of the tab over another tab
+const CGFloat minTabOffset = 2.0;
+
// Time (in seconds) in which tabs animate to their final position.
const NSTimeInterval kAnimationDuration = 0.125;
@@ -597,6 +600,13 @@
tabStripModel_->SelectTabContentsAt(index, true);
}
+- (NSView*)selectedTabView {
+ int selectedIndex = tabStripModel_->selected_index();
+ // Take closing tabs into account. They can't ever be selected.
+ selectedIndex = [self indexFromModelIndex:selectedIndex];
+ return [self viewAtIndex:selectedIndex];
+}
+
// Called when the user closes a tab. Asks the model to close the tab. |sender|
// is the TabView that is potentially going away.
- (void)closeTab:(id)sender {
@@ -694,10 +704,11 @@
return;
const CGFloat kMaxTabWidth = [TabController maxTabWidth];
- const CGFloat kMinTabWidth = [TabController minTabWidth];
+ const CGFloat kMinTabWidth = [TabController miniTabWidth];
const CGFloat kMinSelectedTabWidth = [TabController minSelectedTabWidth];
const CGFloat kMiniTabWidth = [TabController miniTabWidth];
const CGFloat kAppTabWidth = [TabController appTabWidth];
+ const CGFloat kHovTabWidth = [TabController maxTabWidth] / 2;
NSRect enclosingRect = NSZeroRect;
ScopedNSAnimationContextGroup mainAnimationGroup(animate);
@@ -739,17 +750,29 @@
// Initialize |nonMiniTabWidth| in case there aren't any non-mini-tabs; this
// value shouldn't actually be used.
CGFloat nonMiniTabWidth = kMaxTabWidth;
+ CGFloat availableSpaceForNewOverlap = availableSpaceForNonMini;
+ CGFloat tabOverlap = kTabOverlap;
const NSInteger numberOfOpenNonMiniTabs = [self numberOfOpenNonMiniTabs];
if (!verticalLayout_ && numberOfOpenNonMiniTabs) {
// Find the width of a non-mini-tab. This only applies to horizontal
// mode. Add in the amount we "get back" from the tabs overlapping.
+
availableSpaceForNonMini += (numberOfOpenNonMiniTabs - 1) * kTabOverlap;
// Divide up the space between the non-mini-tabs.
nonMiniTabWidth = availableSpaceForNonMini / numberOfOpenNonMiniTabs;
+
+ // This is one of the approach to solve the tab overflow problem.
+ // Find new tab overlap for all non-mini-tab
+ CGFloat extraSpace = kMinTabWidth * numberOfOpenNonMiniTabs - availableSpaceForNewOverlap;
+ if (nonMiniTabWidth < kMinTabWidth) {
+ tabOverlap = MIN(kMiniTabWidth - minTabOffset,
+ extraSpace / (numberOfOpenNonMiniTabs - 1));
+ }
+
// Clamp the width between the max and min.
- nonMiniTabWidth = MAX(MIN(nonMiniTabWidth, kMaxTabWidth), kMinTabWidth);
+ nonMiniTabWidth = MAX(MIN(nonMiniTabWidth, kMaxTabWidth), kMinTabWidth);
}
BOOL visible = [[tabStripView_ window] isVisible];
@@ -816,7 +839,7 @@
if (NSMidX(tabFrame) > placeholderMin) {
hasPlaceholderGap = true;
offset += NSWidth(placeholderFrame_);
- offset -= kTabOverlap;
+ offset -= tabOverlap;
tabFrame.origin.x = offset;
}
}
@@ -826,9 +849,13 @@
// small and thus we enforce a different minimum width.
tabFrame.size.width = [tab mini] ?
([tab app] ? kAppTabWidth : kMiniTabWidth) : nonMiniTabWidth;
- if ([tab selected])
- tabFrame.size.width = MAX(tabFrame.size.width, kMinSelectedTabWidth);
+ // Added width for hovered tab
+ tabFrame.size.width = [tab selected] ?
+ MAX(tabFrame.size.width, kMinSelectedTabWidth) :
+ ([tab hovered] && ![tab mini] && ![tab app] ?
+ MAX(tabFrame.size.width, kHovTabWidth) : tabFrame.size.width);
+
// Animate a new tab in by putting it below the horizon unless told to put
// it in a specific location (i.e., from a drop).
// TODO(pinkerton): figure out vertical tab animations.
@@ -858,7 +885,7 @@
offset += NSHeight(tabFrame);
} else {
offset += NSWidth(tabFrame);
- offset -= kTabOverlap;
+ offset -= [tab mini] || [tab app] ? kTabOverlap : tabOverlap;
}
i++;
}
@@ -873,7 +900,7 @@
// We've already ensured there's enough space for the new tab button
// so we don't have to check it against the available space. We do need
// to make sure we put it after any placeholder.
- newTabNewFrame.origin = NSMakePoint(offset, 0);
+ newTabNewFrame.origin = NSMakePoint(offset + (tabOverlap - kTabOverlap) + kNewTabButtonOffset, 0);
newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x,
NSMaxX(placeholderFrame_)) +
kNewTabButtonOffset;
@@ -1339,13 +1366,6 @@
[view setFrame:frame];
}
-- (NSView*)selectedTabView {
- int selectedIndex = tabStripModel_->selected_index();
- // Take closing tabs into account. They can't ever be selected.
- selectedIndex = [self indexFromModelIndex:selectedIndex];
- return [self viewAtIndex:selectedIndex];
-}
-
// Find the model index based on the x coordinate of the placeholder. If there
// is no placeholder, this returns the end of the tab strip. Closing tabs are
// not considered in computing the index.
@@ -1474,7 +1494,8 @@
if (hoveredTab_ != tabView) {
[hoveredTab_ mouseExited:nil]; // We don't pass event because moved events
[tabView mouseEntered:nil]; // don't have valid tracking areas
- hoveredTab_ = tabView;
+ hoveredTab_ = tabView;
+ [self layoutTabsWithAnimation:YES regenerateSubviews:NO];
} else {
[hoveredTab_ mouseMoved:event];
}
@@ -1486,6 +1507,12 @@
mouseInside_ = YES;
[self setTabTrackingAreasEnabled:YES];
[self mouseMoved:event];
+
+
+ NSView* targetView = [tabStripView_ hitTest:[event locationInWindow]];
+ if ([targetView isKindOfClass:[TabView class]]) {
+ [self layoutTabsWithAnimation:YES regenerateSubviews:NO];
+ }
}
}
« no previous file with comments | « chrome/browser/cocoa/tab_controller.mm ('k') | chrome/browser/cocoa/tab_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698