| 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/infobar_gradient_view.h" | 5 #include "chrome/browser/cocoa/infobar_gradient_view.h" |
| 6 | 6 |
| 7 #include "base/scoped_nsobject.h" |
| 7 #import "chrome/browser/browser_theme_provider.h" | 8 #import "chrome/browser/browser_theme_provider.h" |
| 8 #import "chrome/browser/cocoa/themed_window.h" | 9 #import "chrome/browser/cocoa/themed_window.h" |
| 9 | 10 |
| 11 namespace { |
| 12 |
| 10 const double kBackgroundColorTop[3] = | 13 const double kBackgroundColorTop[3] = |
| 11 {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; | 14 {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; |
| 12 const double kBackgroundColorBottom[3] = | 15 const double kBackgroundColorBottom[3] = |
| 13 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; | 16 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; |
| 17 } |
| 14 | 18 |
| 15 @implementation InfoBarGradientView | 19 @implementation InfoBarGradientView |
| 16 | 20 |
| 17 - (id)initWithFrame:(NSRect)frameRect { | 21 - (id)initWithFrame:(NSRect)frameRect { |
| 18 if ((self = [super initWithFrame:frameRect])) { | 22 if ((self = [super initWithFrame:frameRect])) { |
| 19 NSColor* startingColor = | 23 NSColor* startingColor = |
| 20 [NSColor colorWithCalibratedRed:kBackgroundColorTop[0] | 24 [NSColor colorWithCalibratedRed:kBackgroundColorTop[0] |
| 21 green:kBackgroundColorTop[1] | 25 green:kBackgroundColorTop[1] |
| 22 blue:kBackgroundColorTop[2] | 26 blue:kBackgroundColorTop[2] |
| 23 alpha:1.0]; | 27 alpha:1.0]; |
| 24 NSColor* endingColor = | 28 NSColor* endingColor = |
| 25 [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0] | 29 [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0] |
| 26 green:kBackgroundColorBottom[1] | 30 green:kBackgroundColorBottom[1] |
| 27 blue:kBackgroundColorBottom[2] | 31 blue:kBackgroundColorBottom[2] |
| 28 alpha:1.0]; | 32 alpha:1.0]; |
| 29 gradient_ = | 33 scoped_nsobject<NSGradient> gradient( |
| 30 [[NSGradient alloc] initWithStartingColor:startingColor | 34 [[NSGradient alloc] initWithStartingColor:startingColor |
| 31 endingColor:endingColor]; | 35 endingColor:endingColor]); |
| 36 [self setGradient:gradient]; |
| 32 } | 37 } |
| 33 return self; | 38 return self; |
| 34 } | 39 } |
| 35 | 40 |
| 36 - (void)dealloc { | |
| 37 [gradient_ release]; | |
| 38 [super dealloc]; | |
| 39 } | |
| 40 | |
| 41 - (void)setGradient:(NSGradient*)gradient { | |
| 42 [gradient retain]; | |
| 43 [gradient_ release]; | |
| 44 gradient_ = gradient; | |
| 45 } | |
| 46 | |
| 47 - (NSColor*)strokeColor { | 41 - (NSColor*)strokeColor { |
| 48 ThemeProvider* themeProvider = [[self window] themeProvider]; | 42 ThemeProvider* themeProvider = [[self window] themeProvider]; |
| 49 if (!themeProvider) | 43 if (!themeProvider) |
| 50 return [NSColor blackColor]; | 44 return [NSColor blackColor]; |
| 51 | 45 |
| 52 BOOL active = [[self window] isMainWindow]; | 46 BOOL active = [[self window] isMainWindow]; |
| 53 return themeProvider->GetNSColor( | 47 return themeProvider->GetNSColor( |
| 54 active ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : | 48 active ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : |
| 55 BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, | 49 BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, |
| 56 true); | 50 true); |
| 57 } | 51 } |
| 58 | 52 |
| 59 - (void)drawRect:(NSRect)rect { | |
| 60 [gradient_ drawInRect:[self bounds] angle:270]; | |
| 61 | |
| 62 // Draw bottom stroke | |
| 63 [[self strokeColor] set]; | |
| 64 NSRect borderRect, contentRect; | |
| 65 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); | |
| 66 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | |
| 67 } | |
| 68 | |
| 69 - (BOOL)mouseDownCanMoveWindow { | 53 - (BOOL)mouseDownCanMoveWindow { |
| 70 return NO; | 54 return NO; |
| 71 } | 55 } |
| 72 | 56 |
| 73 // This view is intentionally not opaque because it overlaps with the findbar. | 57 // This view is intentionally not opaque because it overlaps with the findbar. |
| 74 | 58 |
| 75 - (BOOL)accessibilityIsIgnored { | 59 - (BOOL)accessibilityIsIgnored { |
| 76 return NO; | 60 return NO; |
| 77 } | 61 } |
| 78 | 62 |
| 79 - (id)accessibilityAttributeValue:(NSString*)attribute { | 63 - (id)accessibilityAttributeValue:(NSString*)attribute { |
| 80 if ([attribute isEqual:NSAccessibilityRoleAttribute]) | 64 if ([attribute isEqual:NSAccessibilityRoleAttribute]) |
| 81 return NSAccessibilityGroupRole; | 65 return NSAccessibilityGroupRole; |
| 82 | 66 |
| 83 return [super accessibilityAttributeValue:attribute]; | 67 return [super accessibilityAttributeValue:attribute]; |
| 84 } | 68 } |
| 85 | 69 |
| 86 @end | 70 @end |
| OLD | NEW |