From f4f233c9e7af32600890d35420448e50e33f7901 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Wed, 27 Aug 2008 18:07:36 +0200 Subject: [PATCH] Bug 449833 - Need a platform color for chrome background on Mac OS X. r=josh, sr=roc. --- layout/style/nsCSSKeywordList.h | 2 + layout/style/nsCSSProps.cpp | 2 + widget/public/nsILookAndFeel.h | 4 +- widget/src/cocoa/nsCocoaWindow.h | 15 ++----- widget/src/cocoa/nsCocoaWindow.mm | 4 +- widget/src/cocoa/nsLookAndFeel.mm | 7 ++++ widget/src/cocoa/nsNativeThemeCocoa.mm | 4 +- widget/src/cocoa/nsNativeThemeColors.h | 73 ++++++++++++++++++++++++++++++++++ 8 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 widget/src/cocoa/nsNativeThemeColors.h diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h index c920ce19ec..bbf5b41253 100644 --- a/layout/style/nsCSSKeywordList.h +++ b/layout/style/nsCSSKeywordList.h @@ -139,6 +139,8 @@ CSS_KEY(-moz-mac-accentlightshadow, _moz_mac_accentlightshadow) CSS_KEY(-moz-mac-accentregularhighlight, _moz_mac_accentregularhighlight) CSS_KEY(-moz-mac-accentregularshadow, _moz_mac_accentregularshadow) CSS_KEY(-moz-mac-alternateprimaryhighlight, _moz_mac_alternateprimaryhighlight) +CSS_KEY(-moz-mac-chrome-active, _moz_mac_chrome_active) +CSS_KEY(-moz-mac-chrome-inactive, _moz_mac_chrome_inactive) CSS_KEY(-moz-mac-focusring, _moz_mac_focusring) CSS_KEY(-moz-mac-menuselect, _moz_mac_menuselect) CSS_KEY(-moz-mac-menushadow, _moz_mac_menushadow) diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index 08ecc5f8c0..f118ce6deb 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -513,6 +513,8 @@ const PRInt32 nsCSSProps::kColorKTable[] = { eCSSKeyword__moz_hyperlinktext, NS_COLOR_MOZ_HYPERLINKTEXT, eCSSKeyword__moz_html_cellhighlight, nsILookAndFeel::eColor__moz_html_cellhighlight, eCSSKeyword__moz_html_cellhighlighttext, nsILookAndFeel::eColor__moz_html_cellhighlighttext, + eCSSKeyword__moz_mac_chrome_active, nsILookAndFeel::eColor__moz_mac_chrome_active, + eCSSKeyword__moz_mac_chrome_inactive, nsILookAndFeel::eColor__moz_mac_chrome_inactive, eCSSKeyword__moz_mac_focusring, nsILookAndFeel::eColor__moz_mac_focusring, eCSSKeyword__moz_mac_menuselect, nsILookAndFeel::eColor__moz_mac_menuselect, eCSSKeyword__moz_mac_menushadow, nsILookAndFeel::eColor__moz_mac_menushadow, diff --git a/widget/public/nsILookAndFeel.h b/widget/public/nsILookAndFeel.h index e37734fc30..5ec5b4086b 100644 --- a/widget/public/nsILookAndFeel.h +++ b/widget/public/nsILookAndFeel.h @@ -142,7 +142,9 @@ public: eColor__moz_eventreerow, eColor__moz_oddtreerow, - //colours needed by Mac Classic skin + // colors needed by the Mac OS X theme + eColor__moz_mac_chrome_active, // background color of chrome toolbars in active windows + eColor__moz_mac_chrome_inactive, // background color of chrome toolbars in inactive windows eColor__moz_mac_focusring, //ring around text fields and lists eColor__moz_mac_menuselect, //colour used when mouse is over a menu item eColor__moz_mac_menushadow, //colour used to do shadows on menu items diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h index 5a5359c5ab..45933a507e 100644 --- a/widget/src/cocoa/nsCocoaWindow.h +++ b/widget/src/cocoa/nsCocoaWindow.h @@ -47,6 +47,7 @@ #include "nsBaseWidget.h" #include "nsPIWidgetCocoa.h" #include "nsAutoPtr.h" +#include "nsNativeThemeColors.h" class nsCocoaWindow; class nsChildView; @@ -118,16 +119,6 @@ typedef struct _nsCocoaWindowList { - (void)sendToplevelDeactivateEvents; @end -// These are the start and end greys for the unified titlebar and toolbar gradient. -static const float sLeopardHeaderStartGrey = 197/255.0f; -static const float sLeopardHeaderEndGrey = 150/255.0f; -static const float sLeopardHeaderBackgroundStartGrey = 233/255.0f; -static const float sLeopardHeaderBackgroundEndGrey = 207/255.0f; - -// This is the grey for the border at the bottom of the titlebar / toolbar. -static const float sLeopardTitlebarBorderGrey = 64/255.0f; -static const float sLeopardTitlebarBackgroundBorderGrey = 135/255.0f; - struct UnifiedGradientInfo { float titlebarHeight; float toolbarHeight; @@ -142,8 +133,8 @@ static void unifiedShading(void* aInfo, const float* aIn, float* aOut) UnifiedGradientInfo* info = (UnifiedGradientInfo*)aInfo; // The gradient percentage at the bottom of the titlebar / top of the toolbar float start = info->titlebarHeight / (info->titlebarHeight + info->toolbarHeight - 1); - const float startGrey = info->windowIsMain ? sLeopardHeaderStartGrey : sLeopardHeaderBackgroundStartGrey; - const float endGrey = info->windowIsMain ? sLeopardHeaderEndGrey : sLeopardHeaderBackgroundEndGrey; + const float startGrey = NativeGreyColorAsFloat(headerStartGrey, info->windowIsMain); + const float endGrey = NativeGreyColorAsFloat(headerEndGrey, info->windowIsMain); // *aIn is the gradient percentage of the titlebar or toolbar gradient, // a is the gradient percentage of the whole unified gradient. float a = info->drawTitlebar ? *aIn * start : start + *aIn * (1 - start); diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 8c29fa23f2..9ca2a4e253 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -1951,9 +1951,7 @@ void patternDraw(void* aInfo, CGContextRef aContext) // Draw the one pixel border at the bottom of the titlebar. if ([window unifiedToolbarHeight] == 0) { - float borderGrey = isMain ? sLeopardTitlebarBorderGrey : - sLeopardTitlebarBackgroundBorderGrey; - [[NSColor colorWithDeviceWhite:borderGrey alpha:1.0f] set]; + [NativeGreyColorAsNSColor(headerBorderGrey, isMain) set]; NSRectFill(NSMakeRect(0.0f, titlebarOrigin, sPatternWidth, 1.0f)); } } else { diff --git a/widget/src/cocoa/nsLookAndFeel.mm b/widget/src/cocoa/nsLookAndFeel.mm index 2f26c0b289..d384d6aed1 100644 --- a/widget/src/cocoa/nsLookAndFeel.mm +++ b/widget/src/cocoa/nsLookAndFeel.mm @@ -40,6 +40,7 @@ #include "nsObjCExceptions.h" #include "nsIInternetConfigService.h" #include "nsIServiceManager.h" +#include "nsNativeThemeColors.h" #import @@ -285,6 +286,12 @@ nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor) //default to lavender if not available res = GetMacBrushColor(kThemeBrushDragHilite, aColor, NS_RGB(0x63,0x63,0xCE)); break; + case eColor__moz_mac_chrome_active: + case eColor__moz_mac_chrome_inactive: { + int grey = NativeGreyColorAsInt(headerEndGrey, (aID == eColor__moz_mac_chrome_active)); + aColor = NS_RGB(grey, grey, grey); + } + break; case eColor__moz_mac_focusring: //default to lavender if not available res = GetMacBrushColor(kThemeBrushFocusHighlight, aColor, NS_RGB(0x63,0x63,0xCE)); diff --git a/widget/src/cocoa/nsNativeThemeCocoa.mm b/widget/src/cocoa/nsNativeThemeCocoa.mm index b2b88e2376..64e8f8d30c 100644 --- a/widget/src/cocoa/nsNativeThemeCocoa.mm +++ b/widget/src/cocoa/nsNativeThemeCocoa.mm @@ -1035,9 +1035,7 @@ nsNativeThemeCocoa::DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inB CGShadingRelease(shading); // Draw the border at the bottom of the toolbar. - float borderGrey = isMain ? sLeopardTitlebarBorderGrey : - sLeopardTitlebarBackgroundBorderGrey; - [[NSColor colorWithDeviceWhite:borderGrey alpha:1.0f] set]; + [NativeGreyColorAsNSColor(headerBorderGrey, isMain) set]; NSRectFill(NSMakeRect(inBoxRect.origin.x, inBoxRect.origin.y + inBoxRect.size.height - 1.0f, inBoxRect.size.width, 1.0f)); diff --git a/widget/src/cocoa/nsNativeThemeColors.h b/widget/src/cocoa/nsNativeThemeColors.h new file mode 100644 index 0000000000..abf6b02d19 --- /dev/null +++ b/widget/src/cocoa/nsNativeThemeColors.h @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Markus Stange. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsNativeThemeColors_h_ +#define nsNativeThemeColors_h_ + +#import + +enum ColorName { + headerStartGrey, + headerEndGrey, + headerBorderGrey +}; + +static const int sLeopardThemeColors[][2] = { + /* { active window, inactive window } */ + // unified titlebar and toolbar gradient: + { 0xC5, 0xE9 }, // start grey + { 0x96, 0xCA }, // end grey + { 0x42, 0x89 } // separator line +}; + + +static int NativeGreyColorAsInt(ColorName name, BOOL isMain) +{ + return sLeopardThemeColors[name][isMain ? 0 : 1]; +} + +static float NativeGreyColorAsFloat(ColorName name, BOOL isMain) +{ + return NativeGreyColorAsInt(name, isMain) / 255.0f; +} + +static NSColor* NativeGreyColorAsNSColor(ColorName name, BOOL isMain) +{ + return [NSColor colorWithDeviceWhite:NativeGreyColorAsFloat(name, isMain) alpha:1.0f]; +} + +#endif // nsNativeThemeColors_h_ -- 2.11.4.GIT