blob: fc65b86164cb1c10cdbc471555e37ac8000f6915 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/cocoa/background_gradient_view.h"
#import "chrome/browser/themes/theme_service.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "grit/theme_resources.h"
#include "grit/theme_resources_standard.h"
@interface BackgroundGradientView (Private)
- (NSColor*)backgroundImageColor;
@end
@implementation BackgroundGradientView
@synthesize showsDivider = showsDivider_;
- (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) {
showsDivider_ = YES;
}
return self;
}
- (id)initWithCoder:(NSCoder*)decoder {
if ((self = [super initWithCoder:decoder])) {
showsDivider_ = YES;
}
return self;
}
- (void)setShowsDivider:(BOOL)show {
showsDivider_ = show;
[self setNeedsDisplay:YES];
}
- (void)drawBackgroundWithOpaque:(BOOL)opaque {
const NSRect bounds = [self bounds];
if (opaque) {
// If the background image is semi transparent then we need something
// to blend against. Using 20% black gives us a color similar to Windows.
[[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set];
NSRectFill(bounds);
}
[[self backgroundImageColor] set];
NSRectFillUsingOperation(bounds, NSCompositeSourceOver);
if (showsDivider_) {
// Draw bottom stroke
[[self strokeColor] set];
NSRect borderRect, contentRect;
NSDivideRect(bounds, &borderRect, &contentRect, [self cr_lineWidth],
NSMinYEdge);
NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
}
}
- (NSColor*)strokeColor {
BOOL isActive = [[self window] isMainWindow];
ui::ThemeProvider* themeProvider = [[self window] themeProvider];
if (!themeProvider)
return [NSColor blackColor];
return themeProvider->GetNSColor(
isActive ? ThemeService::COLOR_TOOLBAR_STROKE :
ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, true);
}
- (NSColor*)backgroundImageColor {
ThemeService* themeProvider =
static_cast<ThemeService*>([[self window] themeProvider]);
if (!themeProvider)
return [[self window] backgroundColor];
// Themes don't have an inactive image so only look for one if there's no
// theme.
if (![[self window] isMainWindow] && themeProvider->UsingDefaultTheme()) {
NSColor* color = themeProvider->GetNSImageColorNamed(
IDR_THEME_TOOLBAR_INACTIVE, true);
if (color)
return color;
}
return themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, true);
}
@end
|