| 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/background_gradient_view.h" |
| 6 | 6 |
| 7 #import "chrome/browser/browser_theme_provider.h" | 7 #import "chrome/browser/browser_theme_provider.h" |
| 8 #import "chrome/browser/cocoa/themed_window.h" | 8 #import "chrome/browser/cocoa/themed_window.h" |
| 9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 - (void)awakeFromNib { | 25 - (void)awakeFromNib { |
| 26 showsDivider_ = YES; | 26 showsDivider_ = YES; |
| 27 } | 27 } |
| 28 | 28 |
| 29 - (void)setShowsDivider:(BOOL)show { | 29 - (void)setShowsDivider:(BOOL)show { |
| 30 showsDivider_ = show; | 30 showsDivider_ = show; |
| 31 [self setNeedsDisplay:YES]; | 31 [self setNeedsDisplay:YES]; |
| 32 } | 32 } |
| 33 | 33 |
| 34 - (BOOL)drawsAsKey { |
| 35 return [[self window] isKeyWindow]; |
| 36 } |
| 37 |
| 34 - (void)drawBackground { | 38 - (void)drawBackground { |
| 35 BOOL isKey = [[self window] isKeyWindow]; | 39 BOOL isKey = [self drawsAsKey]; |
| 36 ThemeProvider* themeProvider = [[self window] themeProvider]; | 40 ThemeProvider* themeProvider = [[self window] themeProvider]; |
| 37 if (themeProvider) { | 41 if (themeProvider) { |
| 38 NSColor* backgroundImageColor = | 42 NSColor* backgroundImageColor = |
| 39 themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); | 43 themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); |
| 40 if (backgroundImageColor) { | 44 if (backgroundImageColor) { |
| 41 [backgroundImageColor set]; | 45 [backgroundImageColor set]; |
| 42 NSRectFill([self bounds]); | 46 NSRectFill([self bounds]); |
| 43 } else { | 47 } else { |
| 44 CGFloat winHeight = NSHeight([[self window] frame]); | 48 CGFloat winHeight = NSHeight([[self window] frame]); |
| 49 if ([[self window] parentWindow]) |
| 50 winHeight = NSHeight([[[self window] parentWindow] frame]); |
| 45 NSGradient* gradient = themeProvider->GetNSGradient( | 51 NSGradient* gradient = themeProvider->GetNSGradient( |
| 46 isKey ? BrowserThemeProvider::GRADIENT_TOOLBAR : | 52 isKey ? BrowserThemeProvider::GRADIENT_TOOLBAR : |
| 47 BrowserThemeProvider::GRADIENT_TOOLBAR_INACTIVE); | 53 BrowserThemeProvider::GRADIENT_TOOLBAR_INACTIVE); |
| 48 NSPoint startPoint = | 54 NSPoint startPoint = |
| 49 [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) | 55 [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) |
| 50 fromView:nil]; | 56 fromView:nil]; |
| 51 NSPoint endPoint = | 57 NSPoint endPoint = |
| 52 NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight); | 58 NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight); |
| 53 endPoint = [self convertPoint:endPoint fromView:nil]; | 59 endPoint = [self convertPoint:endPoint fromView:nil]; |
| 54 | 60 |
| 55 [gradient drawFromPoint:startPoint | 61 [gradient drawFromPoint:startPoint |
| 56 toPoint:endPoint | 62 toPoint:endPoint |
| 57 options:(NSGradientDrawsBeforeStartingLocation | | 63 options:(NSGradientDrawsBeforeStartingLocation | |
| 58 NSGradientDrawsAfterEndingLocation)]; | 64 NSGradientDrawsAfterEndingLocation)]; |
| 59 } | 65 } |
| 60 | 66 |
| 61 if (showsDivider_) { | 67 if (showsDivider_) { |
| 62 // Draw bottom stroke | 68 // Draw bottom stroke |
| 63 [[self strokeColor] set]; | 69 [[self strokeColor] set]; |
| 64 NSRect borderRect, contentRect; | 70 NSRect borderRect, contentRect; |
| 65 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); | 71 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); |
| 66 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 72 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 67 } | 73 } |
| 68 } | 74 } |
| 69 } | 75 } |
| 70 | 76 |
| 71 - (NSColor*)strokeColor { | 77 - (NSColor*)strokeColor { |
| 72 BOOL isKey = [[self window] isKeyWindow]; | 78 BOOL isKey = [self drawsAsKey]; |
| 73 ThemeProvider* themeProvider = [[self window] themeProvider]; | 79 ThemeProvider* themeProvider = [[self window] themeProvider]; |
| 74 if (!themeProvider) | 80 if (!themeProvider) |
| 75 return [NSColor blackColor]; | 81 return [NSColor blackColor]; |
| 76 return themeProvider->GetNSColor( | 82 return themeProvider->GetNSColor( |
| 77 isKey ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : | 83 isKey ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : |
| 78 BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, true); | 84 BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, true); |
| 79 } | 85 } |
| 80 | 86 |
| 81 @end | 87 @end |
| OLD | NEW |