| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/tab_strip_view.h" | 5 #import "chrome/browser/cocoa/tab_strip_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 @implementation TabStripView | 9 @implementation TabStripView |
| 10 | 10 |
| 11 @synthesize newTabButton = newTabButton_; | 11 @synthesize newTabButton = newTabButton_; |
| 12 @synthesize dropArrowShown = dropArrowShown_; |
| 13 @synthesize dropArrowPosition = dropArrowPosition_; |
| 12 | 14 |
| 13 - (id)initWithFrame:(NSRect)frame { | 15 - (id)initWithFrame:(NSRect)frame { |
| 14 self = [super initWithFrame:frame]; | 16 self = [super initWithFrame:frame]; |
| 15 if (self) { | 17 if (self) { |
| 16 // Set lastMouseUp_ = -1000.0 so that timestamp-lastMouseUp_ is big unless | 18 // Set lastMouseUp_ = -1000.0 so that timestamp-lastMouseUp_ is big unless |
| 17 // lastMouseUp_ has been reset. | 19 // lastMouseUp_ has been reset. |
| 18 lastMouseUp_ = -1000.0; | 20 lastMouseUp_ = -1000.0; |
| 19 | 21 |
| 20 // Register to be an URL drop target. | 22 // Register to be an URL drop target. |
| 21 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); | 23 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); |
| 22 } | 24 } |
| 23 return self; | 25 return self; |
| 24 } | 26 } |
| 25 | 27 |
| 26 - (void)drawRect:(NSRect)rect { | 28 - (void)drawRect:(NSRect)rect { |
| 27 NSRect boundsRect = [self bounds]; | 29 NSRect boundsRect = [self bounds]; |
| 28 NSRect borderRect, contentRect; | 30 NSRect borderRect, contentRect; |
| 29 NSDivideRect(boundsRect, &borderRect, &contentRect, 1, NSMinYEdge); | 31 NSDivideRect(boundsRect, &borderRect, &contentRect, 1, NSMinYEdge); |
| 30 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set]; | 32 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set]; |
| 31 | 33 |
| 32 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 34 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 35 |
| 36 // Draw drop-indicator arrow (if appropriate). |
| 37 // TODO(viettrungluu): this is all a stop-gap measure. |
| 38 if ([self dropArrowShown]) { |
| 39 // Programmer art: an arrow parametrized by many knobs. Note that the arrow |
| 40 // points downwards (so understand "width" and "height" accordingly). |
| 41 |
| 42 // How many (pixels) to inset on the top/bottom. |
| 43 const CGFloat kArrowTopInset = 1.5; |
| 44 const CGFloat kArrowBottomInset = 1; |
| 45 |
| 46 // What proportion of the vertical space is dedicated to the arrow tip, |
| 47 // i.e., (arrow tip height)/(amount of vertical space). |
| 48 const CGFloat kArrowTipProportion = 0.5; |
| 49 |
| 50 // This is a slope, i.e., (arrow tip height)/(0.5 * arrow tip width). |
| 51 const CGFloat kArrowTipSlope = 1.2; |
| 52 |
| 53 // What proportion of the arrow tip width is the stem, i.e., (stem |
| 54 // width)/(arrow tip width). |
| 55 const CGFloat kArrowStemProportion = 0.33; |
| 56 |
| 57 NSPoint arrowTipPos = [self dropArrowPosition]; |
| 58 arrowTipPos.y += kArrowBottomInset; // Inset on the bottom. |
| 59 |
| 60 // Height we have to work with (insetting on the top). |
| 61 CGFloat availableHeight = |
| 62 NSMaxY([self bounds]) - arrowTipPos.y - kArrowTopInset; |
| 63 DCHECK(availableHeight >= 5); |
| 64 |
| 65 // Based on the knobs above, calculate actual dimensions which we'll need |
| 66 // for drawing. |
| 67 CGFloat arrowTipHeight = kArrowTipProportion * availableHeight; |
| 68 CGFloat arrowTipWidth = 2 * arrowTipHeight / kArrowTipSlope; |
| 69 CGFloat arrowStemHeight = availableHeight - arrowTipHeight; |
| 70 CGFloat arrowStemWidth = kArrowStemProportion * arrowTipWidth; |
| 71 CGFloat arrowStemInset = (arrowTipWidth - arrowStemWidth) / 2; |
| 72 |
| 73 // The line width is arbitrary, but our path really should be mitered. |
| 74 NSBezierPath* arrow = [NSBezierPath bezierPath]; |
| 75 [arrow setLineJoinStyle:NSMiterLineJoinStyle]; |
| 76 [arrow setLineWidth:1]; |
| 77 |
| 78 // Define the arrow's shape! We start from the tip and go clockwise. |
| 79 [arrow moveToPoint:arrowTipPos]; |
| 80 [arrow relativeLineToPoint:NSMakePoint(-arrowTipWidth / 2, arrowTipHeight)]; |
| 81 [arrow relativeLineToPoint:NSMakePoint(arrowStemInset, 0)]; |
| 82 [arrow relativeLineToPoint:NSMakePoint(0, arrowStemHeight)]; |
| 83 [arrow relativeLineToPoint:NSMakePoint(arrowStemWidth, 0)]; |
| 84 [arrow relativeLineToPoint:NSMakePoint(0, -arrowStemHeight)]; |
| 85 [arrow relativeLineToPoint:NSMakePoint(arrowStemInset, 0)]; |
| 86 [arrow closePath]; |
| 87 |
| 88 // Draw and fill the arrow. |
| 89 [[NSColor colorWithCalibratedWhite:0 alpha:0.67] set]; |
| 90 [arrow stroke]; |
| 91 [[NSColor colorWithCalibratedWhite:1 alpha:0.67] setFill]; |
| 92 [arrow fill]; |
| 93 } |
| 33 } | 94 } |
| 34 | 95 |
| 35 // We accept first mouse so clicks onto close/zoom/miniaturize buttons and | 96 // We accept first mouse so clicks onto close/zoom/miniaturize buttons and |
| 36 // title bar double-clicks are properly detected even when the window is in the | 97 // title bar double-clicks are properly detected even when the window is in the |
| 37 // background. | 98 // background. |
| 38 - (BOOL)acceptsFirstMouse:(NSEvent*)event { | 99 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| 39 return YES; | 100 return YES; |
| 40 } | 101 } |
| 41 | 102 |
| 42 // Trap double-clicks and make them miniaturize the browser window. | 103 // Trap double-clicks and make them miniaturize the browser window. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 - (void)draggingExited:(id<NSDraggingInfo>)sender { | 150 - (void)draggingExited:(id<NSDraggingInfo>)sender { |
| 90 return [dropHandler_ draggingExited:sender]; | 151 return [dropHandler_ draggingExited:sender]; |
| 91 } | 152 } |
| 92 | 153 |
| 93 // Required by |URLDropTargetHandler|. | 154 // Required by |URLDropTargetHandler|. |
| 94 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 155 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 95 return [dropHandler_ performDragOperation:sender]; | 156 return [dropHandler_ performDragOperation:sender]; |
| 96 } | 157 } |
| 97 | 158 |
| 98 @end | 159 @end |
| OLD | NEW |