summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-30 20:45:10 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-30 20:45:10 +0000
commit3e2bfcf0ae9e0e81c091294460fdbeaef51f47ad (patch)
treea83837a4e6f7b5dd475703f5876d472c5e8429ec
parentad1f9bd8c87effc13dd2c1415862d88a9bab2a17 (diff)
downloadchromium_src-3e2bfcf0ae9e0e81c091294460fdbeaef51f47ad.zip
chromium_src-3e2bfcf0ae9e0e81c091294460fdbeaef51f47ad.tar.gz
chromium_src-3e2bfcf0ae9e0e81c091294460fdbeaef51f47ad.tar.bz2
Fix tab dragging to always hide the new tab button while dragging a tab or targeting an existing window. Makes things much nicer.
BUG=14923, 14925, 15667 TEST=dragging tabs in and out of windows, and within windows. Make sure new tab button goes away when it should and always comes back. Review URL: http://codereview.chromium.org/160345 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22092 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm8
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.h6
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm44
-rw-r--r--chrome/browser/cocoa/tab_view.mm8
-rw-r--r--chrome/browser/cocoa/tab_window_controller.h12
-rw-r--r--chrome/browser/cocoa/tab_window_controller.mm7
6 files changed, 63 insertions, 22 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index d8c801b..76dcd09 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -438,7 +438,7 @@ willPositionSheet:(NSWindow*)sheet
break;
}
- // If the item is toggleable, find it's toggle state and
+ // If the item is toggleable, find its toggle state and
// try to update it. This is a little awkward, but the alternative is
// to check after a commandDispatch, which seems worse.
[self updateToggleStateWithTag:tag forItem:item];
@@ -663,17 +663,23 @@ willPositionSheet:(NSWindow*)sheet
- (void)insertPlaceholderForTab:(TabView*)tab
frame:(NSRect)frame
yStretchiness:(CGFloat)yStretchiness {
+ [super insertPlaceholderForTab:tab frame:frame yStretchiness:yStretchiness];
[tabStripController_ insertPlaceholderForTab:tab
frame:frame
yStretchiness:yStretchiness];
}
- (void)removePlaceholder {
+ [super removePlaceholder];
[tabStripController_ insertPlaceholderForTab:nil
frame:NSZeroRect
yStretchiness:0];
}
+- (void)showNewTabButton:(BOOL)show {
+ [tabStripController_ showNewTabButton:show];
+}
+
- (BOOL)isBookmarkBarVisible {
return [[toolbarController_ bookmarkBarController] isBookmarkBarVisible];
diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h
index 46924ef..68c7ce4 100644
--- a/chrome/browser/cocoa/tab_strip_controller.h
+++ b/chrome/browser/cocoa/tab_strip_controller.h
@@ -57,6 +57,8 @@ class ToolbarModel;
// aren't coalesced, so we store frames to avoid redundant calls.
scoped_nsobject<NSMutableDictionary> targetFrames_;
NSRect newTabTargetFrame_;
+ // If YES, do not show the new tab button during layout.
+ BOOL forceNewTabButtonHidden_;
// Width available for resizing the tabs (doesn't include the new tab
// button). Used to restrict the available width when closing many tabs at
@@ -107,6 +109,10 @@ class ToolbarModel;
frame:(NSRect)frame
yStretchiness:(CGFloat)yStretchiness;
+// Show or hide the new tab button. The button is hidden immediately, but
+// waits until the next call to |-layoutTabs| to show it again.
+- (void)showNewTabButton:(BOOL)show;
+
// Force the tabs to rearrange themselves to reflect the current model.
- (void)layoutTabs;
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index a15244f..96a822b 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -225,6 +225,12 @@ static const float kUseFullAvailableWidth = -1.0;
[self layoutTabs];
}
+- (void)showNewTabButton:(BOOL)show {
+ forceNewTabButtonHidden_ = show ? NO : YES;
+ if (forceNewTabButtonHidden_)
+ [newTabButton_ setHidden:YES];
+}
+
// Lay out all tabs in the order of their TabContentsControllers, which matches
// the ordering in the TabStripModel. This call isn't that expensive, though
// it is O(n) in the number of tabs. Tabs will animate to their new position
@@ -358,23 +364,29 @@ static const float kUseFullAvailableWidth = -1.0;
i++;
}
- NSRect newTabNewFrame = [newTabButton_ frame];
- if ([self useFullWidthForLayout])
- newTabNewFrame.origin =
- NSMakePoint(MIN(availableWidth, offset + kNewTabButtonOffset), 0);
- else
- newTabNewFrame.origin = NSMakePoint(offset + kNewTabButtonOffset, 0);
- newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x,
- NSMaxX(placeholderFrame_));
- if (i > 0 && [newTabButton_ isHidden]) {
- id target = animate ? [newTabButton_ animator] : newTabButton_;
- [target setHidden:NO];
- }
+ // Hide the new tab button if we're explicitly told to. It may already
+ // be hidden, doing it again doesn't hurt.
+ if (forceNewTabButtonHidden_) {
+ [newTabButton_ setHidden:YES];
+ } else {
+ NSRect newTabNewFrame = [newTabButton_ frame];
+ if ([self useFullWidthForLayout])
+ newTabNewFrame.origin =
+ NSMakePoint(MIN(availableWidth, offset + kNewTabButtonOffset), 0);
+ else
+ newTabNewFrame.origin = NSMakePoint(offset + kNewTabButtonOffset, 0);
+ newTabNewFrame.origin.x = MAX(newTabNewFrame.origin.x,
+ NSMaxX(placeholderFrame_));
+ if (i > 0 && [newTabButton_ isHidden]) {
+ id target = animate ? [newTabButton_ animator] : newTabButton_;
+ [target setHidden:NO];
+ }
- if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) {
- [newTabButton_ setFrame:newTabNewFrame];
- newTabTargetFrame_ = newTabNewFrame;
- // Move the new tab button into place.
+ if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) {
+ [newTabButton_ setFrame:newTabNewFrame];
+ newTabTargetFrame_ = newTabNewFrame;
+ // Move the new tab button into place.
+ }
}
[NSAnimationContext endGrouping];
diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm
index a8d9fb5..4036b18 100644
--- a/chrome/browser/cocoa/tab_view.mm
+++ b/chrome/browser/cocoa/tab_view.mm
@@ -251,6 +251,8 @@ static const double kDragStartDistance = 3.0;
[dragWindow_ makeMainWindow];
[draggedController_ showOverlay];
dragOverlay_ = [draggedController_ overlayWindow];
+ // Force the new tab button to be hidden. We'll reset it on mouse up.
+ [draggedController_ showNewTabButton:NO];
//if (![targets count])
// [dragOverlay_ setHasShadow:NO];
if (!isTheOnlyTab_) {
@@ -346,6 +348,11 @@ static const double kDragStartDistance = 3.0;
// The drag/click is done. If the user dragged the mouse, finalize the drag
// and clean up.
+ // We are now free to re-display the new tab button in the window we're
+ // dragging. It will show when the next call to -layoutTabs (which happens
+ // indrectly by several of the calls below, such as removing the placeholder).
+ [draggedController_ showNewTabButton:YES];
+
if (draggingWithinTabStrip_) {
if (tabWasDragged_) {
// Move tab to new location.
@@ -370,7 +377,6 @@ static const double kDragStartDistance = 3.0;
[[draggedController_ window] setLevel:NSNormalWindowLevel];
[draggedController_ removePlaceholder];
- [draggedController_ layoutTabs];
}
[sourceController_ removePlaceholder];
chromeIsVisible_ = YES;
diff --git a/chrome/browser/cocoa/tab_window_controller.h b/chrome/browser/cocoa/tab_window_controller.h
index 256732d..46928bd 100644
--- a/chrome/browser/cocoa/tab_window_controller.h
+++ b/chrome/browser/cocoa/tab_window_controller.h
@@ -54,14 +54,22 @@
// new window will be the same size as this window.
- (TabWindowController*)detachTabToNewWindow:(TabView*)tabView;
-// Make room in the tab strip for |tab| at the given x coordinate.
+// Make room in the tab strip for |tab| at the given x coordinate. Will hide the
+// new tab button while there's a placeholder. Subclasses need to call the
+// superclass implementation.
- (void)insertPlaceholderForTab:(TabView*)tab
frame:(NSRect)frame
yStretchiness:(CGFloat)yStretchiness;
-// Removes the placeholder installed by |-insertPlaceholderForTab:atLocation:|.
+// Removes the placeholder installed by |-insertPlaceholderForTab:atLocation:|
+// and restores the new tab button. Subclasses need to call the superclass
+// implementation.
- (void)removePlaceholder;
+// Show or hide the new tab button. The button is hidden immediately, but
+// waits until the next call to |-layoutTabs| to show it again.
+- (void)showNewTabButton:(BOOL)show;
+
// Called to check if the receiver can receive dragged tabs from
// source. Return YES if so. The default implementation returns NO.
- (BOOL)canReceiveFrom:(TabWindowController*)source;
diff --git a/chrome/browser/cocoa/tab_window_controller.mm b/chrome/browser/cocoa/tab_window_controller.mm
index a1a308c..34417a0 100644
--- a/chrome/browser/cocoa/tab_window_controller.mm
+++ b/chrome/browser/cocoa/tab_window_controller.mm
@@ -141,11 +141,14 @@
- (void)insertPlaceholderForTab:(TabView*)tab
frame:(NSRect)frame
yStretchiness:(CGFloat)yStretchiness {
- // subclass must implement
- NOTIMPLEMENTED();
+ [self showNewTabButton:NO];
}
- (void)removePlaceholder {
+ [self showNewTabButton:YES];
+}
+
+- (void)showNewTabButton:(BOOL)show {
// subclass must implement
NOTIMPLEMENTED();
}