blob: 4f12cda64c98aba999a2426561aefb03589afbcf (
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
|
// Copyright (c) 2012 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/ui/cocoa/chrome_browser_window.h"
#include "base/logging.h"
#include "chrome/browser/themes/theme_properties.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "ui/base/theme_provider.h"
@implementation ChromeBrowserWindow
- (const ui::ThemeProvider*)themeProvider {
id delegate = [self delegate];
if (![delegate respondsToSelector:@selector(themeProvider)])
return NULL;
return [delegate themeProvider];
}
- (ThemedWindowStyle)themedWindowStyle {
id delegate = [self delegate];
if (![delegate respondsToSelector:@selector(themedWindowStyle)])
return THEMED_NORMAL;
return [delegate themedWindowStyle];
}
- (NSPoint)themeImagePositionForAlignment:(ThemeImageAlignment)alignment {
id delegate = [self delegate];
if (![delegate respondsToSelector:@selector(themeImagePositionForAlignment:)])
return NSZeroPoint;
return [delegate themeImagePositionForAlignment:alignment];
}
- (BOOL)inIncognitoMode {
const ui::ThemeProvider* themeProvider = [self themeProvider];
return themeProvider && themeProvider->InIncognitoMode();
}
- (BOOL)inIncognitoModeWithSystemTheme {
const ui::ThemeProvider* themeProvider = [self themeProvider];
return themeProvider && themeProvider->InIncognitoMode() &&
themeProvider->UsingSystemTheme();
}
- (BOOL)hasDarkTheme {
// If a system theme, return YES if Incognito.
const ui::ThemeProvider* themeProvider = [self themeProvider];
if (!themeProvider) {
return NO;
} else if (themeProvider->UsingSystemTheme()) {
return themeProvider->InIncognitoMode();
}
// If the custom theme has a custom toolbar color, return YES if it's
// dark.
if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TOOLBAR)) {
NSColor* theColor =
themeProvider->GetNSColor(ThemeProperties::COLOR_TOOLBAR);
theColor =
[theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace];
if (theColor != nil) {
// The white componement cutoff is an empirical value.
return [theColor whiteComponent] < 0.7;
}
}
// If the custom theme has a custom tab text color, assume that a light
// color means a dark tab background image, and therefore a dark theme.
if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TAB_TEXT)) {
NSColor* theColor =
themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT);
theColor =
[theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace];
if (theColor != nil) {
return [theColor whiteComponent] >= 0.7;
}
}
return NO;
}
@end
|