| 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 #include "chrome/browser/cocoa/background_gradient_view.h" | 5 #include "chrome/browser/cocoa/infobar_gradient_view.h" |
| 6 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 6 | 7 |
| 7 #define kToolbarTopOffset 12 | 8 const double kBackgroundColorTop[3] = |
| 8 #define kToolbarMaxHeight 128 | 9 {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; |
| 10 const double kBackgroundColorBottom[3] = |
| 11 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; |
| 9 | 12 |
| 10 @implementation BackgroundGradientView | 13 @implementation InfoBarGradientView |
| 11 @synthesize showsDivider = showsDivider_; | |
| 12 | |
| 13 - (id)initWithFrame:(NSRect)frameRect { | |
| 14 self = [super initWithFrame:frameRect]; | |
| 15 if (self != nil) { | |
| 16 showsDivider_ = YES; | |
| 17 } | |
| 18 return self; | |
| 19 } | |
| 20 | |
| 21 - (void)awakeFromNib { | |
| 22 showsDivider_ = YES; | |
| 23 } | |
| 24 | |
| 25 - (void)setShowsDivider:(BOOL)show { | |
| 26 showsDivider_ = show; | |
| 27 [self setNeedsDisplay:YES]; | |
| 28 } | |
| 29 | |
| 30 // The offset of this pattern to make it line up with the top of the window. | |
| 31 - (NSPoint)patternPhase { | |
| 32 NSPoint phase = NSZeroPoint; | |
| 33 phase.y += NSHeight([[self window] frame]) - kToolbarTopOffset; | |
| 34 return phase; | |
| 35 } | |
| 36 | |
| 37 - (void)drawRect:(NSRect)rect { | |
| 38 BOOL isKey = [[self window] isKeyWindow]; | |
| 39 | |
| 40 GTMTheme *theme = [self gtm_theme]; | |
| 41 | |
| 42 NSImage *backgroundImage = [theme backgroundImageForStyle:GTMThemeStyleToolBar | |
| 43 state:GTMThemeStateActiveWindow]; | |
| 44 if (backgroundImage) { | |
| 45 NSPoint phase = [self patternPhase]; | |
| 46 [[NSGraphicsContext currentContext] setPatternPhase:phase]; | |
| 47 | |
| 48 NSColor *color = [NSColor colorWithPatternImage:backgroundImage]; | |
| 49 [color set]; | |
| 50 NSRectFill([self bounds]); | |
| 51 } else { | |
| 52 CGFloat winHeight = NSHeight([[self window] frame]); | |
| 53 NSGradient *gradient = [theme gradientForStyle:GTMThemeStyleToolBar | |
| 54 state:isKey]; | |
| 55 NSPoint startPoint = [self convertPointFromBase: | |
| 56 NSMakePoint(0, winHeight - kToolbarTopOffset)]; | |
| 57 NSPoint endPoint = [self convertPointFromBase: | |
| 58 NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight)]; | |
| 59 | |
| 60 [gradient drawFromPoint:startPoint | |
| 61 toPoint:endPoint | |
| 62 options:NSGradientDrawsBeforeStartingLocation | | |
| 63 NSGradientDrawsAfterEndingLocation]; | |
| 64 } | |
| 65 | |
| 66 if (showsDivider_) { | |
| 67 // Draw bottom stroke | |
| 68 [[self strokeColor] set]; | |
| 69 NSRect borderRect, contentRect; | |
| 70 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); | |
| 71 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 - (NSColor*)strokeColor { | 14 - (NSColor*)strokeColor { |
| 76 return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar | 15 return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar |
| 77 state:[[self window] isKeyWindow]]; | 16 state:[[self window] isKeyWindow]]; |
| 78 } | 17 } |
| 79 | 18 |
| 19 - (void)drawRect:(NSRect)rect { |
| 20 NSColor* startingColor = |
| 21 [NSColor colorWithCalibratedRed:kBackgroundColorTop[0] |
| 22 green:kBackgroundColorTop[1] |
| 23 blue:kBackgroundColorTop[2] |
| 24 alpha:1.0]; |
| 25 NSColor* endingColor = |
| 26 [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0] |
| 27 green:kBackgroundColorBottom[1] |
| 28 blue:kBackgroundColorBottom[2] |
| 29 alpha:1.0]; |
| 30 NSGradient* gradient = |
| 31 [[[NSGradient alloc] initWithStartingColor:startingColor |
| 32 endingColor:endingColor] autorelease]; |
| 33 [gradient drawInRect:[self bounds] angle:270]; |
| 34 |
| 35 // Draw bottom stroke |
| 36 [[self strokeColor] set]; |
| 37 NSRect borderRect, contentRect; |
| 38 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); |
| 39 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 40 } |
| 41 |
| 42 - (BOOL)mouseDownCanMoveWindow { |
| 43 return NO; |
| 44 } |
| 45 |
| 46 // This view is intentionally not opaque because it overlaps with the findbar. |
| 47 |
| 80 @end | 48 @end |
| OLD | NEW |