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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
// Copyright (c) 2010 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.
#import "chrome/browser/cocoa/browser_theme_provider_init.h"
#import <Cocoa/Cocoa.h>
#include <map>
#include <string>
#include <utility>
#import "base/scoped_nsobject.h"
#include "chrome/browser/browser_theme_provider.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
@implementation GTMTheme(BrowserThemeProviderInitialization)
+ (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider
isOffTheRecord:(BOOL)isOffTheRecord {
// First check if it's in the cache.
typedef std::pair<std::string, BOOL> ThemeKey;
static std::map<ThemeKey, GTMTheme*> cache;
ThemeKey key(provider->GetThemeID(), isOffTheRecord);
GTMTheme* theme = cache[key];
if (theme)
return theme;
theme = [[GTMTheme alloc] init]; // "Leak" it in the cache.
cache[key] = theme;
// TODO(pinkerton): Need to be able to theme the entire incognito window
// http://crbug.com/18568 The hardcoding of the colors here will need to be
// removed when that bug is addressed, but are here in order for things to be
// usable in the meantime.
if (isOffTheRecord) {
NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0
green:108.0/255.0
blue:140/255.0
alpha:1.0];
[theme setBackgroundColor:incognitoColor];
[theme setValue:[NSColor blackColor]
forAttribute:@"textColor"
style:GTMThemeStyleTabBarSelected
state:GTMThemeStateActiveWindow];
[theme setValue:[NSColor blackColor]
forAttribute:@"textColor"
style:GTMThemeStyleTabBarDeselected
state:GTMThemeStateActiveWindow];
[theme setValue:[NSColor blackColor]
forAttribute:@"textColor"
style:GTMThemeStyleBookmarksBarButton
state:GTMThemeStateActiveWindow];
[theme setValue:[NSColor blackColor]
forAttribute:@"iconColor"
style:GTMThemeStyleToolBarButton
state:GTMThemeStateActiveWindow];
return theme;
}
NSImage* frameImage = provider->GetNSImageNamed(IDR_THEME_FRAME, false);
if (frameImage) {
NSImage* frameInactiveImage =
provider->GetNSImageNamed(IDR_THEME_FRAME_INACTIVE, true);
[theme setValue:frameImage
forAttribute:@"backgroundImage"
style:GTMThemeStyleWindow
state:GTMThemeStateActiveWindow];
[theme setValue:frameInactiveImage
forAttribute:@"backgroundImage"
style:GTMThemeStyleWindow
state:0];
}
NSColor* tabTextColor =
provider->GetNSColor(BrowserThemeProvider::COLOR_TAB_TEXT, false);
[theme setValue:tabTextColor
forAttribute:@"textColor"
style:GTMThemeStyleTabBarSelected
state:GTMThemeStateActiveWindow];
NSColor* tabInactiveTextColor =
provider->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT,
false);
[theme setValue:tabInactiveTextColor
forAttribute:@"textColor"
style:GTMThemeStyleTabBarDeselected
state:GTMThemeStateActiveWindow];
NSColor* bookmarkBarTextColor =
provider->GetNSColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, false);
[theme setValue:bookmarkBarTextColor
forAttribute:@"textColor"
style:GTMThemeStyleBookmarksBarButton
state:GTMThemeStateActiveWindow];
NSImage* toolbarImage = provider->GetNSImageNamed(IDR_THEME_TOOLBAR, false);
[theme setValue:toolbarImage
forAttribute:@"backgroundImage"
style:GTMThemeStyleToolBar
state:GTMThemeStateActiveWindow];
NSImage* toolbarBackgroundImage =
provider->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND, false);
[theme setValue:toolbarBackgroundImage
forAttribute:@"backgroundImage"
style:GTMThemeStyleTabBarDeselected
state:GTMThemeStateActiveWindow];
NSImage* toolbarButtonImage =
provider->GetNSImageNamed(IDR_THEME_BUTTON_BACKGROUND, false);
if (toolbarButtonImage) {
[theme setValue:toolbarButtonImage
forAttribute:@"backgroundImage"
style:GTMThemeStyleToolBarButton
state:GTMThemeStateActiveWindow];
} else {
NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.0];
NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.3];
scoped_nsobject<NSGradient> gradient([[NSGradient alloc]
initWithStartingColor:startColor
endingColor:endColor]);
[theme setValue:gradient
forAttribute:@"gradient"
style:GTMThemeStyleToolBarButton
state:GTMThemeStateActiveWindow];
[theme setValue:gradient
forAttribute:@"gradient"
style:GTMThemeStyleToolBarButton
state:GTMThemeStateActiveWindow];
}
NSColor* toolbarButtonIconColor =
provider->GetNSColorTint(BrowserThemeProvider::TINT_BUTTONS, false);
[theme setValue:toolbarButtonIconColor
forAttribute:@"iconColor"
style:GTMThemeStyleToolBarButton
state:GTMThemeStateActiveWindow];
NSColor* toolbarButtonBorderColor = toolbarButtonIconColor;
[theme setValue:toolbarButtonBorderColor
forAttribute:@"borderColor"
style:GTMThemeStyleToolBar
state:GTMThemeStateActiveWindow];
NSColor* toolbarBackgroundColor =
provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR, false);
[theme setValue:toolbarBackgroundColor
forAttribute:@"backgroundColor"
style:GTMThemeStyleToolBar
state:GTMThemeStateActiveWindow];
NSImage* frameOverlayImage =
provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY, false);
if (frameOverlayImage) {
[theme setValue:frameOverlayImage
forAttribute:@"overlay"
style:GTMThemeStyleWindow
state:GTMThemeStateActiveWindow];
NSImage* frameOverlayInactiveImage =
provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY_INACTIVE, true);
if (frameOverlayInactiveImage) {
[theme setValue:frameOverlayInactiveImage
forAttribute:@"overlay"
style:GTMThemeStyleWindow
state:GTMThemeStateInactiveWindow];
}
}
return theme;
}
@end // @implementation GTMTheme(BrowserThemeProviderInitialization)
|