summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/tab_cell.mm
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 23:22:33 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 23:22:33 +0000
commit0735266658f996210b6f43142ce7f4c55f47ae13 (patch)
treed4e2c01970b8c7df5f6428f2aac188515a4ea509 /chrome/browser/cocoa/tab_cell.mm
parent9993401b31ffd1b18f100982f8d75824019f9a11 (diff)
downloadchromium_src-0735266658f996210b6f43142ce7f4c55f47ae13.zip
chromium_src-0735266658f996210b6f43142ce7f4c55f47ae13.tar.gz
chromium_src-0735266658f996210b6f43142ce7f4c55f47ae13.tar.bz2
Initial support for theming on Mac OS X.
Patch by alcor. Original review: http://codereview.chromium.org/149204 BUG=http://crbug.com/14451 TEST=Open a theme, watch it apply. Review URL: http://codereview.chromium.org/155355 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_cell.mm')
-rw-r--r--chrome/browser/cocoa/tab_cell.mm97
1 files changed, 4 insertions, 93 deletions
diff --git a/chrome/browser/cocoa/tab_cell.mm b/chrome/browser/cocoa/tab_cell.mm
index 23719e8..9f89c14 100644
--- a/chrome/browser/cocoa/tab_cell.mm
+++ b/chrome/browser/cocoa/tab_cell.mm
@@ -6,10 +6,6 @@
#import "third_party/GTM/AppKit/GTMTheme.h"
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
-#define INSET_MULTIPLIER 2.0/3.0
-#define CP1_MULTIPLIER 1.0/3.0
-#define CP2_MULTIPLIER 3.0/8.0
-
@implementation TabCell
- (id)initTextCell:(NSString *)aString {
@@ -21,107 +17,22 @@
}
- (NSBackgroundStyle)interiorBackgroundStyle {
- return [[GTMTheme defaultTheme]
- interiorBackgroundStyleForStyle:GTMThemeStyleTabBarSelected
- active:YES];
+ return [[[self controlView] gtm_theme]
+ interiorBackgroundStyleForStyle:GTMThemeStyleTabBarSelected
+ state:GTMThemeStateActiveWindow];
}
// Override drawing the button so that it looks like a Chromium tab instead
// of just a normal MacOS button.
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
- [[NSGraphicsContext currentContext] saveGraphicsState];
- NSRect rect = cellFrame;
- BOOL active =
- [[controlView window] isKeyWindow] || [[controlView window] isMainWindow];
-
- BOOL selected = [(NSButton *)controlView state];
-
- // Inset by 0.5 in order to draw on pixels rather than on borders (which would
- // cause blurry pixels). Decrease height by 1 in order to move away from the
- // edge for the dark shadow.
- rect = NSInsetRect(rect, 0.5, selected ? 0 : -0.5);
- rect.size.height -= 1;
- rect.origin.y += 1;
-
- NSPoint bottomLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect));
- NSPoint bottomRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect));
- NSPoint topRight =
- NSMakePoint(NSMaxX(rect) - INSET_MULTIPLIER * NSHeight(rect),
- NSMinY(rect));
- NSPoint topLeft =
- NSMakePoint(NSMinX(rect) + INSET_MULTIPLIER * NSHeight(rect),
- NSMinY(rect));
-
- float baseControlPointOutset = NSHeight(rect) * CP1_MULTIPLIER;
- float bottomControlPointInset = NSHeight(rect) * CP2_MULTIPLIER;
-
- // Outset many of these values by 1 to cause the fill to bleed outside the
- // clip area
- NSBezierPath *path = [NSBezierPath bezierPath];
- [path moveToPoint:NSMakePoint(bottomLeft.x - 1, bottomLeft.y + 1)];
- [path lineToPoint:NSMakePoint(bottomLeft.x - 1, bottomLeft.y)];
- [path lineToPoint:bottomLeft];
- [path curveToPoint:topLeft
- controlPoint1:NSMakePoint(bottomLeft.x + baseControlPointOutset,
- bottomLeft.y)
- controlPoint2:NSMakePoint(topLeft.x - bottomControlPointInset,
- topLeft.y)];
- [path lineToPoint:topRight];
- [path curveToPoint:bottomRight
- controlPoint1:NSMakePoint(topRight.x + bottomControlPointInset,
- topRight.y)
- controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset,
- bottomRight.y)];
- [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y)];
- [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y + 1)];
-
- GTMTheme *theme = [GTMTheme defaultTheme];
- NSGradient *gradient = nil;
-
- if (selected) {
- gradient = [theme gradientForStyle:GTMThemeStyleTabBarSelected
- active:active];
- // Stroke with a translucent black
- [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.5 : 0.3] set];
- [[NSGraphicsContext currentContext] saveGraphicsState];
- NSShadow *shadow = [[[NSShadow alloc] init] autorelease];
- [shadow setShadowOffset:NSMakeSize(2, -1)];
- [shadow setShadowBlurRadius:2.0];
- [path fill];
- [[NSGraphicsContext currentContext] restoreGraphicsState];
- } else {
- gradient = [theme gradientForStyle:GTMThemeStyleTabBarDeselected
- active:active];
- // Stroke with a translucent black
- [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.3 : 0.1] set];
- }
-
- [[NSGraphicsContext currentContext] saveGraphicsState];
- [[NSBezierPath bezierPathWithRect:NSOffsetRect(cellFrame, 0, -1)] addClip];
- [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set];
- [path setLineWidth:selected ? 2.0 : 1.0];
- [path stroke];
-
- [[NSGraphicsContext currentContext] restoreGraphicsState];
-
- [gradient drawInBezierPath:path angle:90.0];
-
- if (!selected) {
- [path addClip];
- NSRect borderRect, contentRect;
- NSDivideRect(rect, &borderRect, &contentRect, 1, NSMaxYEdge);
- [[NSColor colorWithCalibratedWhite:0.0 alpha:0.4] set];
- NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
- }
- [[NSGraphicsContext currentContext] restoreGraphicsState];
// Inset where the text is drawn to keep it away from the sloping edges of the
// tab, the close box, and the icon view. These constants are derived
// empirically as the cell doesn't know about the surrounding view objects.
// TODO(pinkerton/alcor): Fix this somehow?
const int kIconXOffset = 28;
- const int kCloseBoxXOffset = 16;
+ const int kCloseBoxXOffset = 18;
NSRect frame = NSOffsetRect(cellFrame, kIconXOffset, 0);
frame.size.width -= kCloseBoxXOffset + kIconXOffset;
[self drawInteriorWithFrame:frame