summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-05 08:18:27 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-05 08:18:27 +0000
commit802956b3dcaab1ba66c2abadfdf820304ee85796 (patch)
tree2b2fa56f52efd3dce9877e2a2e67dad464e5897f /chrome/browser/cocoa
parentc650cc0144b496ba16b04e3104c4d67a55815e8b (diff)
downloadchromium_src-802956b3dcaab1ba66c2abadfdf820304ee85796.zip
chromium_src-802956b3dcaab1ba66c2abadfdf820304ee85796.tar.gz
chromium_src-802956b3dcaab1ba66c2abadfdf820304ee85796.tar.bz2
Mac: Make a stop-gap visual indicator for dropping URLs on the tab strip.
A.k.a. a present for pkasting. Eventually we'll probably want to do something more sophisticated (at the very least arrows should fade in/out), but for now this doesn't look (much?) worse than what's on Win/Chrome. BUG=25405 TEST=Drag URLs to the tab strip, move around, make sure the ugly arrow appears in the right locations, dropping to confirm. Repeat with various themes to make sure arrow is reasonably visible. Review URL: http://codereview.chromium.org/466051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm25
-rw-r--r--chrome/browser/cocoa/tab_strip_view.h7
-rw-r--r--chrome/browser/cocoa/tab_strip_view.mm61
3 files changed, 84 insertions, 9 deletions
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index 8b151c0..54a21fd 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -1508,42 +1508,49 @@ private:
// Update (possibly showing) the indicator which indicates where an URL drop
// would happen.
- (void)indicateDropURLsAt:(NSPoint)location {
-// TODO(viettrungluu): Make the tabs move around, show an indicator, etc. This
-// requires a re-work of the tabs code....
-#if 0
+ // The minimum y-coordinate at which one should consider place the arrow.
+ const CGFloat arrowBaseY = 25;
+
NSInteger index;
WindowOpenDisposition disposition;
[self droppingURLsAt:location
givesIndex:&index
disposition:&disposition];
+ NSPoint arrowPos = NSMakePoint(0, arrowBaseY);
if (index == -1) {
// Append a tab at the end.
DCHECK(disposition == NEW_FOREGROUND_TAB);
- // TODO(viettrungluu): ...
+ NSInteger lastIndex = [tabArray_ count] - 1;
+ NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame];
+ arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0;
} else {
NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame];
switch (disposition) {
case NEW_FOREGROUND_TAB:
// Insert tab (to the left of the given tab).
- // TODO(viettrungluu): ...
+ arrowPos.x = overRect.origin.x + kTabOverlap / 2.0;
break;
case CURRENT_TAB:
// Overwrite the given tab.
- // TODO(viettrungluu): ...
+ arrowPos.x = overRect.origin.x + overRect.size.width / 2.0;
break;
default:
NOTREACHED();
}
}
- // TODO(viettrungluu): ...
-#endif
+ [tabView_ setDropArrowPosition:arrowPos];
+ [tabView_ setDropArrowShown:YES];
+ [tabView_ setNeedsDisplay:YES];
}
// Hide the indicator which indicates where an URL drop would happen.
- (void)hideDropURLsIndicator {
-// TODO(viettrungluu): See TODO in |-indicateDropURLsAt:| above.
+ if ([tabView_ dropArrowShown]) {
+ [tabView_ setDropArrowShown:NO];
+ [tabView_ setNeedsDisplay:YES];
+ }
}
- (GTMWindowSheetController*)sheetController {
diff --git a/chrome/browser/cocoa/tab_strip_view.h b/chrome/browser/cocoa/tab_strip_view.h
index 29aa0eb..454f2a3 100644
--- a/chrome/browser/cocoa/tab_strip_view.h
+++ b/chrome/browser/cocoa/tab_strip_view.h
@@ -21,9 +21,16 @@
// Weak; the following come from the nib.
NSButton* newTabButton_;
+
+ // Whether the drop-indicator arrow is shown, and if it is, the coordinate of
+ // its tip.
+ BOOL dropArrowShown_;
+ NSPoint dropArrowPosition_;
}
@property(assign, nonatomic) IBOutlet NSButton* newTabButton;
+@property(assign, nonatomic) BOOL dropArrowShown;
+@property(assign, nonatomic) NSPoint dropArrowPosition;
@end
diff --git a/chrome/browser/cocoa/tab_strip_view.mm b/chrome/browser/cocoa/tab_strip_view.mm
index 1dcd746..3eeef0a 100644
--- a/chrome/browser/cocoa/tab_strip_view.mm
+++ b/chrome/browser/cocoa/tab_strip_view.mm
@@ -9,6 +9,8 @@
@implementation TabStripView
@synthesize newTabButton = newTabButton_;
+@synthesize dropArrowShown = dropArrowShown_;
+@synthesize dropArrowPosition = dropArrowPosition_;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
@@ -30,6 +32,65 @@
[[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set];
NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
+
+ // Draw drop-indicator arrow (if appropriate).
+ // TODO(viettrungluu): this is all a stop-gap measure.
+ if ([self dropArrowShown]) {
+ // Programmer art: an arrow parametrized by many knobs. Note that the arrow
+ // points downwards (so understand "width" and "height" accordingly).
+
+ // How many (pixels) to inset on the top/bottom.
+ const CGFloat kArrowTopInset = 1.5;
+ const CGFloat kArrowBottomInset = 1;
+
+ // What proportion of the vertical space is dedicated to the arrow tip,
+ // i.e., (arrow tip height)/(amount of vertical space).
+ const CGFloat kArrowTipProportion = 0.5;
+
+ // This is a slope, i.e., (arrow tip height)/(0.5 * arrow tip width).
+ const CGFloat kArrowTipSlope = 1.2;
+
+ // What proportion of the arrow tip width is the stem, i.e., (stem
+ // width)/(arrow tip width).
+ const CGFloat kArrowStemProportion = 0.33;
+
+ NSPoint arrowTipPos = [self dropArrowPosition];
+ arrowTipPos.y += kArrowBottomInset; // Inset on the bottom.
+
+ // Height we have to work with (insetting on the top).
+ CGFloat availableHeight =
+ NSMaxY([self bounds]) - arrowTipPos.y - kArrowTopInset;
+ DCHECK(availableHeight >= 5);
+
+ // Based on the knobs above, calculate actual dimensions which we'll need
+ // for drawing.
+ CGFloat arrowTipHeight = kArrowTipProportion * availableHeight;
+ CGFloat arrowTipWidth = 2 * arrowTipHeight / kArrowTipSlope;
+ CGFloat arrowStemHeight = availableHeight - arrowTipHeight;
+ CGFloat arrowStemWidth = kArrowStemProportion * arrowTipWidth;
+ CGFloat arrowStemInset = (arrowTipWidth - arrowStemWidth) / 2;
+
+ // The line width is arbitrary, but our path really should be mitered.
+ NSBezierPath* arrow = [NSBezierPath bezierPath];
+ [arrow setLineJoinStyle:NSMiterLineJoinStyle];
+ [arrow setLineWidth:1];
+
+ // Define the arrow's shape! We start from the tip and go clockwise.
+ [arrow moveToPoint:arrowTipPos];
+ [arrow relativeLineToPoint:NSMakePoint(-arrowTipWidth / 2, arrowTipHeight)];
+ [arrow relativeLineToPoint:NSMakePoint(arrowStemInset, 0)];
+ [arrow relativeLineToPoint:NSMakePoint(0, arrowStemHeight)];
+ [arrow relativeLineToPoint:NSMakePoint(arrowStemWidth, 0)];
+ [arrow relativeLineToPoint:NSMakePoint(0, -arrowStemHeight)];
+ [arrow relativeLineToPoint:NSMakePoint(arrowStemInset, 0)];
+ [arrow closePath];
+
+ // Draw and fill the arrow.
+ [[NSColor colorWithCalibratedWhite:0 alpha:0.67] set];
+ [arrow stroke];
+ [[NSColor colorWithCalibratedWhite:1 alpha:0.67] setFill];
+ [arrow fill];
+ }
}
// We accept first mouse so clicks onto close/zoom/miniaturize buttons and