| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/chrome_browser_window.h" | 5 #import "chrome/browser/ui/cocoa/chrome_browser_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/themes/theme_properties.h" | 8 #include "chrome/browser/themes/theme_properties.h" |
| 9 #import "chrome/browser/ui/cocoa/themed_window.h" | 9 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 10 #include "ui/base/theme_provider.h" | 10 #include "ui/base/theme_provider.h" |
| 11 | 11 |
| 12 namespace { |
| 13 |
| 14 // Upper and lower bounds for determining if a theme's colors indicate that |
| 15 // it's a "dark" theme. In Material Design, dark themes have controls that are |
| 16 // drawn using transparent white instead of a transparent shade of gray. |
| 17 const CGFloat kDarkThemeToolbarColorUpperBound = 0.55; |
| 18 const CGFloat kDarkThemeTabTextColorLowerBound = 0.7; |
| 19 |
| 20 } // namespace |
| 21 |
| 12 @interface NSWindow (Private) | 22 @interface NSWindow (Private) |
| 13 - (BOOL)hasKeyAppearance; | 23 - (BOOL)hasKeyAppearance; |
| 14 @end | 24 @end |
| 15 | 25 |
| 16 @implementation ChromeBrowserWindow | 26 @implementation ChromeBrowserWindow |
| 17 | 27 |
| 18 - (const ui::ThemeProvider*)themeProvider { | 28 - (const ui::ThemeProvider*)themeProvider { |
| 19 id delegate = [self delegate]; | 29 id delegate = [self delegate]; |
| 20 if (![delegate respondsToSelector:@selector(themeProvider)]) | 30 if (![delegate respondsToSelector:@selector(themeProvider)]) |
| 21 return NULL; | 31 return NULL; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 68 |
| 59 // If the custom theme has a custom toolbar color, return YES if it's | 69 // If the custom theme has a custom toolbar color, return YES if it's |
| 60 // dark. | 70 // dark. |
| 61 if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TOOLBAR)) { | 71 if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TOOLBAR)) { |
| 62 NSColor* theColor = | 72 NSColor* theColor = |
| 63 themeProvider->GetNSColor(ThemeProperties::COLOR_TOOLBAR); | 73 themeProvider->GetNSColor(ThemeProperties::COLOR_TOOLBAR); |
| 64 theColor = | 74 theColor = |
| 65 [theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace]; | 75 [theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace]; |
| 66 if (theColor != nil) { | 76 if (theColor != nil) { |
| 67 // The white componement cutoff is an empirical value. | 77 // The white componement cutoff is an empirical value. |
| 68 return [theColor whiteComponent] < 0.7; | 78 return [theColor whiteComponent] < kDarkThemeToolbarColorUpperBound; |
| 69 } | 79 } |
| 70 } | 80 } |
| 71 | 81 |
| 72 // If the custom theme has a custom tab text color, assume that a light | 82 // If the custom theme has a custom tab text color, assume that a light |
| 73 // color means a dark tab background image, and therefore a dark theme. | 83 // color means a dark tab background image, and therefore a dark theme. |
| 74 if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TAB_TEXT)) { | 84 if (themeProvider->HasCustomColor(ThemeProperties::COLOR_TAB_TEXT)) { |
| 75 NSColor* theColor = | 85 NSColor* theColor = |
| 76 themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); | 86 themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); |
| 77 theColor = | 87 theColor = |
| 78 [theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace]; | 88 [theColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace]; |
| 79 if (theColor != nil) { | 89 if (theColor != nil) { |
| 80 return [theColor whiteComponent] >= 0.7; | 90 return [theColor whiteComponent] >= kDarkThemeTabTextColorLowerBound; |
| 81 } | 91 } |
| 82 } | 92 } |
| 83 | 93 |
| 84 return NO; | 94 return NO; |
| 85 } | 95 } |
| 86 | 96 |
| 87 - (BOOL)hasKeyAppearance { | 97 - (BOOL)hasKeyAppearance { |
| 88 // If not key, but a non-main child window without its own traffic lights _is_ | 98 // If not key, but a non-main child window without its own traffic lights _is_ |
| 89 // key, then show this window with key appearance to keep the traffic lights | 99 // key, then show this window with key appearance to keep the traffic lights |
| 90 // lit. This does not currently handle WebModal dialogs, since they are | 100 // lit. This does not currently handle WebModal dialogs, since they are |
| 91 // children of an overlay window. But WebModals also temporarily lose key | 101 // children of an overlay window. But WebModals also temporarily lose key |
| 92 // status while animating closed, so extra logic is needed to avoid flicker. | 102 // status while animating closed, so extra logic is needed to avoid flicker. |
| 93 // Start with an early exit, since this is called for every mouseMove and | 103 // Start with an early exit, since this is called for every mouseMove and |
| 94 // every cursor blink in an NSTextField. | 104 // every cursor blink in an NSTextField. |
| 95 if (![self isKeyWindow]) { | 105 if (![self isKeyWindow]) { |
| 96 for (NSWindow* child in [self childWindows]) { | 106 for (NSWindow* child in [self childWindows]) { |
| 97 if ([child isKeyWindow] && ![child isMainWindow] && | 107 if ([child isKeyWindow] && ![child isMainWindow] && |
| 98 ([child styleMask] & NSClosableWindowMask) == 0) | 108 ([child styleMask] & NSClosableWindowMask) == 0) |
| 99 return YES; | 109 return YES; |
| 100 } | 110 } |
| 101 } | 111 } |
| 102 return [super hasKeyAppearance]; | 112 return [super hasKeyAppearance]; |
| 103 } | 113 } |
| 104 | 114 |
| 105 @end | 115 @end |
| OLD | NEW |