| 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 "base/scoped_nsobject.h" | |
| 6 #import "chrome/browser/cocoa/tab_cell.h" | 5 #import "chrome/browser/cocoa/tab_cell.h" |
| 7 #import "third_party/GTM/AppKit/GTMTheme.h" | 6 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 8 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 7 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
| 9 | 8 |
| 10 | |
| 11 @implementation TabCell | 9 @implementation TabCell |
| 12 | 10 |
| 13 - (id)initTextCell:(NSString *)aString { | 11 - (id)initTextCell:(NSString *)aString { |
| 14 self = [super initTextCell:aString]; | 12 self = [super initTextCell:aString]; |
| 15 if (self != nil) { | 13 if (self != nil) { |
| 16 // nothing for now... | 14 // nothing for now... |
| 17 } | 15 } |
| 18 return self; | 16 return self; |
| 19 } | 17 } |
| 20 | 18 |
| 21 - (NSBackgroundStyle)interiorBackgroundStyle { | 19 - (NSBackgroundStyle)interiorBackgroundStyle { |
| 22 return [[[self controlView] gtm_theme] | 20 return [[[self controlView] gtm_theme] |
| 23 interiorBackgroundStyleForStyle:GTMThemeStyleToolBar | 21 interiorBackgroundStyleForStyle:GTMThemeStyleTabBarSelected |
| 24 state:GTMThemeStateActiveWindow]; | 22 state:GTMThemeStateActiveWindow]; |
| 25 } | 23 } |
| 26 | 24 |
| 27 // Override drawing the button so that it looks like a Chromium tab instead | 25 // Override drawing the button so that it looks like a Chromium tab instead |
| 28 // of just a normal MacOS button. | 26 // of just a normal MacOS button. |
| 29 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { | 27 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { |
| 30 // Inset where the text is drawn to keep it away from the sloping edges of the | 28 // Inset where the text is drawn to keep it away from the sloping edges of the |
| 31 // tab, the close box, and the icon view. These constants are derived | 29 // tab, the close box, and the icon view. These constants are derived |
| 32 // empirically as the cell doesn't know about the surrounding view objects. | 30 // empirically as the cell doesn't know about the surrounding view objects. |
| 33 // TODO(pinkerton/alcor): Fix this somehow? | 31 // TODO(pinkerton/alcor): Fix this somehow? |
| 34 const int kIconXOffset = 28; | 32 const int kIconXOffset = 28; |
| 35 const int kCloseBoxXOffset = 21; | 33 const int kCloseBoxXOffset = 21; |
| 36 NSRect frame = NSOffsetRect(cellFrame, kIconXOffset, 0); | 34 NSRect frame = NSOffsetRect(cellFrame, kIconXOffset, 0); |
| 37 frame.size.width -= kCloseBoxXOffset + kIconXOffset; | 35 frame.size.width -= kCloseBoxXOffset + kIconXOffset; |
| 38 [self drawInteriorWithFrame:frame | 36 [self drawInteriorWithFrame:frame |
| 39 inView:controlView]; | 37 inView:controlView]; |
| 40 } | 38 } |
| 41 | 39 |
| 42 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { | |
| 43 GTMTheme* theme = [[self controlView] gtm_theme]; | |
| 44 NSColor* textColor = [theme textColorForStyle:GTMThemeStyleToolBar | |
| 45 state:[self isHighlighted]]; | |
| 46 | |
| 47 scoped_nsobject<NSShadow> textShadow([[NSShadow alloc] init]); | |
| 48 [textShadow setShadowBlurRadius:0.0f]; | |
| 49 [textShadow setShadowColor:[textColor gtm_legibleTextColor]]; | |
| 50 [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)]; | |
| 51 | |
| 52 NSDictionary* attributes = | |
| 53 [NSDictionary dictionaryWithObjectsAndKeys: | |
| 54 [self font], NSFontAttributeName, | |
| 55 textColor, NSForegroundColorAttributeName, | |
| 56 textShadow.get(), NSShadowAttributeName, | |
| 57 nil]; | |
| 58 | |
| 59 [[self title] drawInRect:[self titleRectForBounds:cellFrame] | |
| 60 withAttributes:attributes]; | |
| 61 | |
| 62 NSRect imageBounds = NSZeroRect; | |
| 63 imageBounds.size = [[self image] size]; | |
| 64 [[self image] drawInRect:[self imageRectForBounds:cellFrame] | |
| 65 fromRect:imageBounds | |
| 66 operation:NSCompositeSourceOver | |
| 67 fraction:1.0]; | |
| 68 } | |
| 69 | |
| 70 - (void)highlight:(BOOL)flag | 40 - (void)highlight:(BOOL)flag |
| 71 withFrame:(NSRect)cellFrame | 41 withFrame:(NSRect)cellFrame |
| 72 inView:(NSView *)controlView { | 42 inView:(NSView *)controlView { |
| 73 // Don't do normal highlighting | 43 // Don't do normal highlighting |
| 74 } | 44 } |
| 75 | 45 |
| 76 @end | 46 @end |
| OLD | NEW |