2007-03-22 10:30:00 -07:00
|
|
|
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** 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
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
#include "nsXPLookAndFeel.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPrefBranch2.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsFont.h"
|
|
|
|
|
2007-08-30 09:21:16 -07:00
|
|
|
#include "gfxPlatform.h"
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2007-08-30 09:21:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsSize.h"
|
|
|
|
#endif
|
2009-02-10 11:25:00 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(nsXPLookAndFeel, nsILookAndFeel, nsIObserver)
|
|
|
|
|
|
|
|
nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
|
|
|
|
{
|
|
|
|
{ "ui.caretBlinkTime", eMetric_CaretBlinkTime, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.caretWidth", eMetric_CaretWidth, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.caretVisibleWithSelection", eMetric_ShowCaretDuringSelection, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.submenuDelay", eMetric_SubmenuDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.dragThresholdX", eMetric_DragThresholdX, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.dragThresholdY", eMetric_DragThresholdY, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.useAccessibilityTheme", eMetric_UseAccessibilityTheme, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2010-10-21 05:07:55 -07:00
|
|
|
{ "ui.scrollbarsCanOverlapContent", eMetric_ScrollbarsCanOverlapContent,
|
|
|
|
PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ "ui.menusCanOverlapOSBar", eMetric_MenusCanOverlapOSBar,
|
|
|
|
PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.skipNavigatingDisabledMenuItem", eMetric_SkipNavigatingDisabledMenuItem, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.treeOpenDelay",
|
|
|
|
eMetric_TreeOpenDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.treeCloseDelay",
|
|
|
|
eMetric_TreeCloseDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.treeLazyScrollDelay",
|
|
|
|
eMetric_TreeLazyScrollDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.treeScrollDelay",
|
|
|
|
eMetric_TreeScrollDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.treeScrollLinesMax",
|
|
|
|
eMetric_TreeScrollLinesMax, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "accessibility.tabfocus",
|
|
|
|
eMetric_TabFocusModel, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.alertNotificationOrigin",
|
|
|
|
eMetric_AlertNotificationOrigin, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2007-04-11 17:36:40 -07:00
|
|
|
{ "ui.scrollToClick",
|
|
|
|
eMetric_ScrollToClick, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2007-08-16 13:35:18 -07:00
|
|
|
{ "ui.IMERawInputUnderlineStyle",
|
|
|
|
eMetric_IMERawInputUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.IMESelectedRawTextUnderlineStyle",
|
|
|
|
eMetric_IMESelectedRawTextUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.IMEConvertedTextUnderlineStyle",
|
|
|
|
eMetric_IMEConvertedTextUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
|
|
|
{ "ui.IMESelectedConvertedTextUnderlineStyle",
|
|
|
|
eMetric_IMESelectedConvertedTextUnderline, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2009-04-03 00:26:28 -07:00
|
|
|
{ "ui.SpellCheckerUnderlineStyle",
|
|
|
|
eMetric_SpellCheckerUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] =
|
|
|
|
{
|
|
|
|
{ "ui.IMEUnderlineRelativeSize", eMetricFloat_IMEUnderlineRelativeSize,
|
|
|
|
PR_FALSE, nsLookAndFeelTypeFloat, 0 },
|
2009-04-03 00:26:28 -07:00
|
|
|
{ "ui.SpellCheckerUnderlineRelativeSize",
|
|
|
|
eMetricFloat_SpellCheckerUnderlineRelativeSize, PR_FALSE,
|
|
|
|
nsLookAndFeelTypeFloat, 0 },
|
2008-06-23 01:50:52 -07:00
|
|
|
{ "ui.caretAspectRatio", eMetricFloat_CaretAspectRatio, PR_FALSE,
|
|
|
|
nsLookAndFeelTypeFloat, 0 },
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This array MUST be kept in the same order as the color list in nsILookAndFeel.h.
|
|
|
|
/* XXX If you add any strings longer than
|
2008-01-24 01:31:44 -08:00
|
|
|
* "ui.IMESelectedConvertedTextBackground"
|
2007-03-22 10:30:00 -07:00
|
|
|
* to the following array then you MUST update the
|
|
|
|
* sizes of the sColorPrefs array in nsXPLookAndFeel.h
|
|
|
|
*/
|
|
|
|
const char nsXPLookAndFeel::sColorPrefs[][38] =
|
|
|
|
{
|
|
|
|
"ui.windowBackground",
|
|
|
|
"ui.windowForeground",
|
|
|
|
"ui.widgetBackground",
|
|
|
|
"ui.widgetForeground",
|
|
|
|
"ui.widgetSelectBackground",
|
|
|
|
"ui.widgetSelectForeground",
|
|
|
|
"ui.widget3DHighlight",
|
|
|
|
"ui.widget3DShadow",
|
|
|
|
"ui.textBackground",
|
|
|
|
"ui.textForeground",
|
|
|
|
"ui.textSelectBackground",
|
|
|
|
"ui.textSelectForeground",
|
|
|
|
"ui.textSelectBackgroundDisabled",
|
|
|
|
"ui.textSelectBackgroundAttention",
|
2008-07-30 13:48:56 -07:00
|
|
|
"ui.textHighlightBackground",
|
2008-09-01 23:28:44 -07:00
|
|
|
"ui.textHighlightForeground",
|
2007-03-22 10:30:00 -07:00
|
|
|
"ui.IMERawInputBackground",
|
|
|
|
"ui.IMERawInputForeground",
|
|
|
|
"ui.IMERawInputUnderline",
|
|
|
|
"ui.IMESelectedRawTextBackground",
|
|
|
|
"ui.IMESelectedRawTextForeground",
|
|
|
|
"ui.IMESelectedRawTextUnderline",
|
|
|
|
"ui.IMEConvertedTextBackground",
|
|
|
|
"ui.IMEConvertedTextForeground",
|
|
|
|
"ui.IMEConvertedTextUnderline",
|
|
|
|
"ui.IMESelectedConvertedTextBackground",
|
|
|
|
"ui.IMESelectedConvertedTextForeground",
|
|
|
|
"ui.IMESelectedConvertedTextUnderline",
|
2009-04-03 00:26:28 -07:00
|
|
|
"ui.SpellCheckerUnderline",
|
2007-03-22 10:30:00 -07:00
|
|
|
"ui.activeborder",
|
|
|
|
"ui.activecaption",
|
|
|
|
"ui.appworkspace",
|
|
|
|
"ui.background",
|
|
|
|
"ui.buttonface",
|
|
|
|
"ui.buttonhighlight",
|
|
|
|
"ui.buttonshadow",
|
|
|
|
"ui.buttontext",
|
|
|
|
"ui.captiontext",
|
|
|
|
"ui.graytext",
|
|
|
|
"ui.highlight",
|
|
|
|
"ui.highlighttext",
|
|
|
|
"ui.inactiveborder",
|
|
|
|
"ui.inactivecaption",
|
|
|
|
"ui.inactivecaptiontext",
|
|
|
|
"ui.infobackground",
|
|
|
|
"ui.infotext",
|
|
|
|
"ui.menu",
|
|
|
|
"ui.menutext",
|
|
|
|
"ui.scrollbar",
|
|
|
|
"ui.threeddarkshadow",
|
|
|
|
"ui.threedface",
|
|
|
|
"ui.threedhighlight",
|
|
|
|
"ui.threedlightshadow",
|
|
|
|
"ui.threedshadow",
|
|
|
|
"ui.window",
|
|
|
|
"ui.windowframe",
|
|
|
|
"ui.windowtext",
|
|
|
|
"ui.-moz-buttondefault",
|
|
|
|
"ui.-moz-field",
|
|
|
|
"ui.-moz-fieldtext",
|
|
|
|
"ui.-moz-dialog",
|
|
|
|
"ui.-moz-dialogtext",
|
|
|
|
"ui.-moz-dragtargetzone",
|
2008-04-24 01:08:33 -07:00
|
|
|
"ui.-moz-cellhighlight",
|
|
|
|
"ui.-moz_cellhighlighttext",
|
2008-01-24 01:31:44 -08:00
|
|
|
"ui.-moz-html-cellhighlight",
|
|
|
|
"ui.-moz-html-cellhighlighttext",
|
2008-04-24 01:08:33 -07:00
|
|
|
"ui.-moz-buttonhoverface",
|
|
|
|
"ui.-moz_buttonhovertext",
|
|
|
|
"ui.-moz_menuhover",
|
|
|
|
"ui.-moz_menuhovertext",
|
2009-06-14 14:58:14 -07:00
|
|
|
"ui.-moz_menubartext",
|
2008-04-24 01:08:33 -07:00
|
|
|
"ui.-moz_menubarhovertext",
|
|
|
|
"ui.-moz_eventreerow",
|
|
|
|
"ui.-moz_oddtreerow",
|
2009-03-31 13:02:55 -07:00
|
|
|
"ui.-moz_mac_chrome_active",
|
|
|
|
"ui.-moz_mac_chrome_inactive",
|
2007-03-22 10:30:00 -07:00
|
|
|
"ui.-moz-mac-focusring",
|
|
|
|
"ui.-moz-mac-menuselect",
|
|
|
|
"ui.-moz-mac-menushadow",
|
|
|
|
"ui.-moz-mac-menutextdisable",
|
|
|
|
"ui.-moz-mac-menutextselect",
|
2009-03-31 13:02:55 -07:00
|
|
|
"ui.-moz_mac_disabledtoolbartext",
|
2008-04-24 01:08:33 -07:00
|
|
|
"ui.-moz-mac-alternateprimaryhighlight",
|
2008-04-29 12:27:23 -07:00
|
|
|
"ui.-moz-mac-secondaryhighlight",
|
|
|
|
"ui.-moz-win-mediatext",
|
2008-07-11 11:34:53 -07:00
|
|
|
"ui.-moz-win-communicationstext",
|
2009-01-16 00:18:49 -08:00
|
|
|
"ui.-moz-nativehyperlinktext",
|
|
|
|
"ui.-moz-comboboxtext",
|
|
|
|
"ui.-moz-combobox"
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
PRInt32 nsXPLookAndFeel::sCachedColors[nsILookAndFeel::eColor_LAST_COLOR] = {0};
|
|
|
|
PRInt32 nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
|
|
|
|
|
|
|
|
PRBool nsXPLookAndFeel::sInitialized = PR_FALSE;
|
2009-02-10 11:25:00 -08:00
|
|
|
PRBool nsXPLookAndFeel::sUseNativeColors = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (prefService)
|
|
|
|
{
|
|
|
|
PRInt32 intpref;
|
|
|
|
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
data->intVar = intpref;
|
|
|
|
data->isSet = PR_TRUE;
|
|
|
|
#ifdef DEBUG_akkana
|
|
|
|
printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (prefService)
|
|
|
|
{
|
|
|
|
PRInt32 intpref;
|
|
|
|
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
data->floatVar = (float)intpref / 100.;
|
|
|
|
data->isSet = PR_TRUE;
|
|
|
|
#ifdef DEBUG_akkana
|
|
|
|
printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (prefService) {
|
|
|
|
nsXPIDLCString colorStr;
|
|
|
|
nsresult rv = prefService->GetCharPref(prefName, getter_Copies(colorStr));
|
|
|
|
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty()) {
|
|
|
|
nscolor thecolor;
|
|
|
|
if (colorStr[0] == '#') {
|
2010-06-21 17:01:43 -07:00
|
|
|
if (NS_HexToRGB(NS_ConvertASCIItoUTF16(Substring(colorStr, 1, colorStr.Length() - 1)),
|
|
|
|
&thecolor)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 id = NS_PTR_TO_INT32(index);
|
|
|
|
CACHE_COLOR(id, thecolor);
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 17:01:43 -07:00
|
|
|
else if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(colorStr), &thecolor)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 id = NS_PTR_TO_INT32(index);
|
|
|
|
CACHE_COLOR(id, thecolor);
|
|
|
|
#ifdef DEBUG_akkana
|
|
|
|
printf("====== Changed color pref %s to 0x%lx\n",
|
|
|
|
prefName, thecolor);
|
|
|
|
#endif
|
|
|
|
}
|
2008-09-05 02:57:52 -07:00
|
|
|
} else if (colorStr.IsEmpty()) {
|
|
|
|
// Reset to the default color, by clearing the cache
|
|
|
|
// to force lookup when the color is next used
|
|
|
|
PRInt32 id = NS_PTR_TO_INT32(index);
|
|
|
|
CLEAR_COLOR_CACHE(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch)
|
|
|
|
{
|
|
|
|
PRInt32 intpref;
|
|
|
|
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
aPref->isSet = PR_TRUE;
|
|
|
|
aPref->intVar = intpref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch)
|
|
|
|
{
|
|
|
|
PRInt32 intpref;
|
|
|
|
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
aPref->isSet = PR_TRUE;
|
|
|
|
aPref->floatVar = (float)intpref / 100.;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPrefBranch* aPrefBranch)
|
|
|
|
{
|
|
|
|
nsXPIDLCString colorStr;
|
|
|
|
nsresult rv = aPrefBranch->GetCharPref(sColorPrefs[i], getter_Copies(colorStr));
|
|
|
|
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty())
|
|
|
|
{
|
|
|
|
nsAutoString colorNSStr; colorNSStr.AssignWithConversion(colorStr);
|
|
|
|
nscolor thecolor;
|
|
|
|
if (colorNSStr[0] == '#') {
|
|
|
|
nsAutoString hexString;
|
|
|
|
colorNSStr.Right(hexString, colorNSStr.Length() - 1);
|
2010-06-21 17:01:43 -07:00
|
|
|
if (NS_HexToRGB(hexString, &thecolor)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
CACHE_COLOR(i, thecolor);
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 17:01:43 -07:00
|
|
|
else if (NS_ColorNameToRGB(colorNSStr, &thecolor))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
CACHE_COLOR(i, thecolor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
|
|
|
|
// looping in the same order as in ::Init
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
|
|
|
if (nsDependentString(aData).EqualsASCII(sIntPrefs[i].name)) {
|
|
|
|
IntPrefChanged(&sIntPrefs[i]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
|
|
|
if (nsDependentString(aData).EqualsASCII(sFloatPrefs[i].name)) {
|
|
|
|
FloatPrefChanged(&sFloatPrefs[i]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
|
|
|
|
if (nsDependentString(aData).EqualsASCII(sColorPrefs[i])) {
|
|
|
|
ColorPrefChanged(i, sColorPrefs[i]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Read values from the user's preferences.
|
|
|
|
// This is done once at startup, but since the user's preferences
|
|
|
|
// haven't actually been read yet at that time, we also have to
|
|
|
|
// set a callback to inform us of changes to each pref.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsXPLookAndFeel::Init()
|
|
|
|
{
|
|
|
|
// Say we're already initialized, and take the chance that it might fail;
|
|
|
|
// protects against some other process writing to our static variables.
|
|
|
|
sInitialized = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (!prefs)
|
|
|
|
return;
|
|
|
|
nsCOMPtr<nsIPrefBranch2> prefBranchInternal(do_QueryInterface(prefs));
|
|
|
|
if (!prefBranchInternal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
|
|
|
InitFromPref(&sIntPrefs[i], prefs);
|
|
|
|
prefBranchInternal->AddObserver(sIntPrefs[i].name, this, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
|
|
|
InitFromPref(&sFloatPrefs[i], prefs);
|
|
|
|
prefBranchInternal->AddObserver(sFloatPrefs[i].name, this, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
|
|
|
|
InitColorFromPref(i, prefs);
|
|
|
|
prefBranchInternal->AddObserver(sColorPrefs[i], this, PR_FALSE);
|
|
|
|
}
|
2009-02-10 11:25:00 -08:00
|
|
|
|
|
|
|
PRBool val;
|
|
|
|
if (NS_SUCCEEDED(prefs->GetBoolPref("ui.use_native_colors", &val))) {
|
|
|
|
sUseNativeColors = val;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXPLookAndFeel::~nsXPLookAndFeel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-04 04:28:12 -07:00
|
|
|
PRBool
|
|
|
|
nsXPLookAndFeel::IsSpecialColor(const nsColorID aID, nscolor &aColor)
|
|
|
|
{
|
|
|
|
switch (aID) {
|
|
|
|
case eColor_TextSelectForeground:
|
|
|
|
return (aColor == NS_DONT_CHANGE_COLOR);
|
|
|
|
case eColor_IMESelectedRawTextBackground:
|
|
|
|
case eColor_IMESelectedConvertedTextBackground:
|
|
|
|
case eColor_IMERawInputBackground:
|
|
|
|
case eColor_IMEConvertedTextBackground:
|
|
|
|
case eColor_IMESelectedRawTextForeground:
|
|
|
|
case eColor_IMESelectedConvertedTextForeground:
|
|
|
|
case eColor_IMERawInputForeground:
|
|
|
|
case eColor_IMEConvertedTextForeground:
|
|
|
|
case eColor_IMERawInputUnderline:
|
|
|
|
case eColor_IMEConvertedTextUnderline:
|
|
|
|
case eColor_IMESelectedRawTextUnderline:
|
|
|
|
case eColor_IMESelectedConvertedTextUnderline:
|
2009-04-03 00:26:28 -07:00
|
|
|
case eColor_SpellCheckerUnderline:
|
|
|
|
return NS_IS_SELECTION_SPECIAL_COLOR(aColor);
|
2008-09-16 04:32:03 -07:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* In GetColor(), every color that is not a special color is color
|
|
|
|
* corrected. Use PR_FALSE to make other colors color corrected.
|
|
|
|
*/
|
|
|
|
return PR_FALSE;
|
2007-09-04 04:28:12 -07:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// All these routines will return NS_OK if they have a value,
|
|
|
|
// in which case the nsLookAndFeel should use that value;
|
|
|
|
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
|
|
|
|
// platform-specific nsLookAndFeel should use its own values instead.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
|
|
|
{
|
|
|
|
if (!sInitialized)
|
|
|
|
Init();
|
|
|
|
|
|
|
|
// define DEBUG_SYSTEM_COLOR_USE if you want to debug system color
|
|
|
|
// use in a skin that uses them. When set, it will make all system
|
|
|
|
// color pairs that are appropriate for foreground/background
|
|
|
|
// pairing the same. This means if the skin is using system colors
|
|
|
|
// correctly you will not be able to see *any* text.
|
|
|
|
#undef DEBUG_SYSTEM_COLOR_USE
|
|
|
|
|
|
|
|
#ifdef DEBUG_SYSTEM_COLOR_USE
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch (aID) {
|
|
|
|
// css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
|
|
|
|
case eColor_activecaption:
|
|
|
|
// active window caption background
|
|
|
|
case eColor_captiontext:
|
|
|
|
// text in active window caption
|
|
|
|
aColor = NS_RGB(0xff, 0x00, 0x00);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_highlight:
|
|
|
|
// background of selected item
|
|
|
|
case eColor_highlighttext:
|
|
|
|
// text of selected item
|
|
|
|
aColor = NS_RGB(0xff, 0xff, 0x00);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_inactivecaption:
|
|
|
|
// inactive window caption
|
|
|
|
case eColor_inactivecaptiontext:
|
|
|
|
// text in inactive window caption
|
|
|
|
aColor = NS_RGB(0x66, 0x66, 0x00);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_infobackground:
|
|
|
|
// tooltip background color
|
|
|
|
case eColor_infotext:
|
|
|
|
// tooltip text color
|
|
|
|
aColor = NS_RGB(0x00, 0xff, 0x00);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_menu:
|
|
|
|
// menu background
|
|
|
|
case eColor_menutext:
|
|
|
|
// menu text
|
|
|
|
aColor = NS_RGB(0x00, 0xff, 0xff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_threedface:
|
|
|
|
case eColor_buttonface:
|
|
|
|
// 3-D face color
|
|
|
|
case eColor_buttontext:
|
|
|
|
// text on push buttons
|
|
|
|
aColor = NS_RGB(0x00, 0x66, 0x66);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor_window:
|
|
|
|
case eColor_windowtext:
|
|
|
|
aColor = NS_RGB(0x00, 0x00, 0xff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// from the CSS3 working draft (not yet finalized)
|
|
|
|
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
|
|
|
|
|
|
|
|
case eColor__moz_field:
|
|
|
|
case eColor__moz_fieldtext:
|
|
|
|
aColor = NS_RGB(0xff, 0x00, 0xff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eColor__moz_dialog:
|
|
|
|
case eColor__moz_dialogtext:
|
|
|
|
aColor = NS_RGB(0x66, 0x00, 0x66);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif // DEBUG_SYSTEM_COLOR_USE
|
|
|
|
|
|
|
|
if (IS_COLOR_CACHED(aID)) {
|
|
|
|
aColor = sCachedColors[aID];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are no system color settings for these, so set them manually
|
|
|
|
if (aID == eColor_TextSelectBackgroundDisabled) {
|
|
|
|
// This is used to gray out the selection when it's not focused
|
|
|
|
// Used with nsISelectionController::SELECTION_DISABLED
|
|
|
|
aColor = NS_RGB(0xb0, 0xb0, 0xb0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aID == eColor_TextSelectBackgroundAttention) {
|
|
|
|
// This makes the selection stand out when typeaheadfind is on
|
|
|
|
// Used with nsISelectionController::SELECTION_ATTENTION
|
|
|
|
aColor = NS_RGB(0x38, 0xd8, 0x78);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-30 13:48:56 -07:00
|
|
|
if (aID == eColor_TextHighlightBackground) {
|
|
|
|
// This makes the matched text stand out when findbar highlighting is on
|
|
|
|
// Used with nsISelectionController::SELECTION_FIND
|
2008-11-10 14:10:25 -08:00
|
|
|
aColor = NS_RGB(0xef, 0x0f, 0xff);
|
2008-07-30 13:48:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-01 23:28:44 -07:00
|
|
|
if (aID == eColor_TextHighlightForeground) {
|
|
|
|
// The foreground color for the matched text in findbar highlighting
|
|
|
|
// Used with nsISelectionController::SELECTION_FIND
|
2008-11-10 14:10:25 -08:00
|
|
|
aColor = NS_RGB(0xff, 0xff, 0xff);
|
2008-09-01 23:28:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 11:25:00 -08:00
|
|
|
if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aColor))) {
|
2008-08-11 21:55:36 -07:00
|
|
|
if ((gfxPlatform::GetCMSMode() == eCMSMode_All) && !IsSpecialColor(aID, aColor)) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform *transform = gfxPlatform::GetCMSInverseRGBTransform();
|
2007-08-30 09:21:16 -07:00
|
|
|
if (transform) {
|
|
|
|
PRUint8 color[3];
|
|
|
|
color[0] = NS_GET_R(aColor);
|
|
|
|
color[1] = NS_GET_G(aColor);
|
|
|
|
color[2] = NS_GET_B(aColor);
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_data(transform, color, color, 1);
|
2007-08-30 09:21:16 -07:00
|
|
|
aColor = NS_RGB(color[0], color[1], color[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
CACHE_COLOR(aID, aColor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::GetMetric(const nsMetricID aID, PRInt32& aMetric)
|
|
|
|
{
|
|
|
|
if (!sInitialized)
|
|
|
|
Init();
|
|
|
|
|
|
|
|
// Set the default values for these prefs. but allow different platforms
|
|
|
|
// to override them in their nsLookAndFeel if desired.
|
|
|
|
switch (aID) {
|
|
|
|
case eMetric_ScrollButtonLeftMouseButtonAction:
|
|
|
|
aMetric = 0;
|
|
|
|
return NS_OK;
|
|
|
|
case eMetric_ScrollButtonMiddleMouseButtonAction:
|
|
|
|
aMetric = 3;
|
|
|
|
return NS_OK;
|
|
|
|
case eMetric_ScrollButtonRightMouseButtonAction:
|
|
|
|
aMetric = 3;
|
|
|
|
return NS_OK;
|
2008-09-16 04:32:03 -07:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* The metrics above are hardcoded platform defaults. All the other
|
|
|
|
* metrics are stored in sIntPrefs and can be changed at runtime.
|
|
|
|
*/
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < ((sizeof (sIntPrefs) / sizeof (*sIntPrefs))); ++i)
|
|
|
|
if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID))
|
|
|
|
{
|
|
|
|
aMetric = sIntPrefs[i].intVar;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::GetMetric(const nsMetricFloatID aID, float& aMetric)
|
|
|
|
{
|
|
|
|
if (!sInitialized)
|
|
|
|
Init();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < ((sizeof (sFloatPrefs) / sizeof (*sFloatPrefs))); ++i)
|
|
|
|
if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID)
|
|
|
|
{
|
|
|
|
aMetric = sFloatPrefs[i].floatVar;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::LookAndFeelChanged()
|
|
|
|
{
|
|
|
|
// Wipe out our color cache.
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < nsILookAndFeel::eColor_LAST_COLOR; i++)
|
|
|
|
sCachedColors[i] = 0;
|
|
|
|
for (i = 0; i < COLOR_CACHE_SIZE; i++)
|
|
|
|
sCachedColorBits[i] = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// This method returns the actual (or nearest estimate)
|
|
|
|
// of the Navigator size for a given form control for a given font
|
|
|
|
// and font size. This is used in NavQuirks mode to see how closely
|
|
|
|
// we match its size
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPLookAndFeel::GetNavSize(const nsMetricNavWidgetID aWidgetID,
|
|
|
|
const nsMetricNavFontID aFontID,
|
|
|
|
const PRInt32 aFontSize,
|
|
|
|
nsSize &aSize)
|
|
|
|
{
|
|
|
|
aSize.width = 0;
|
|
|
|
aSize.height = 0;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
#endif
|