CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / xpwidgets / nsXPLookAndFeel.cpp
blobd91fab5b42835e029cd2713452b1d035421c5222
1 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nscore.h"
40 #include "nsXPLookAndFeel.h"
41 #include "nsIServiceManager.h"
42 #include "nsIPrefBranch2.h"
43 #include "nsIPrefBranch.h"
44 #include "nsIPrefService.h"
45 #include "nsIObserver.h"
46 #include "nsCRT.h"
47 #include "nsFont.h"
49 #include "gfxPlatform.h"
50 #include "qcms.h"
52 #ifdef DEBUG
53 #include "nsSize.h"
54 #endif
56 NS_IMPL_ISUPPORTS2(nsXPLookAndFeel, nsILookAndFeel, nsIObserver)
58 nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
60 { "ui.caretBlinkTime", eMetric_CaretBlinkTime, PR_FALSE, nsLookAndFeelTypeInt, 0 },
61 { "ui.caretWidth", eMetric_CaretWidth, PR_FALSE, nsLookAndFeelTypeInt, 0 },
62 { "ui.caretVisibleWithSelection", eMetric_ShowCaretDuringSelection, PR_FALSE, nsLookAndFeelTypeInt, 0 },
63 { "ui.submenuDelay", eMetric_SubmenuDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
64 { "ui.dragThresholdX", eMetric_DragThresholdX, PR_FALSE, nsLookAndFeelTypeInt, 0 },
65 { "ui.dragThresholdY", eMetric_DragThresholdY, PR_FALSE, nsLookAndFeelTypeInt, 0 },
66 { "ui.useAccessibilityTheme", eMetric_UseAccessibilityTheme, PR_FALSE, nsLookAndFeelTypeInt, 0 },
67 { "ui.scrollbarsCanOverlapContent", eMetric_ScrollbarsCanOverlapContent,
68 PR_FALSE, nsLookAndFeelTypeInt, 0 },
69 { "ui.menusCanOverlapOSBar", eMetric_MenusCanOverlapOSBar,
70 PR_FALSE, nsLookAndFeelTypeInt, 0 },
71 { "ui.skipNavigatingDisabledMenuItem", eMetric_SkipNavigatingDisabledMenuItem, PR_FALSE, nsLookAndFeelTypeInt, 0 },
72 { "ui.treeOpenDelay",
73 eMetric_TreeOpenDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
74 { "ui.treeCloseDelay",
75 eMetric_TreeCloseDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
76 { "ui.treeLazyScrollDelay",
77 eMetric_TreeLazyScrollDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
78 { "ui.treeScrollDelay",
79 eMetric_TreeScrollDelay, PR_FALSE, nsLookAndFeelTypeInt, 0 },
80 { "ui.treeScrollLinesMax",
81 eMetric_TreeScrollLinesMax, PR_FALSE, nsLookAndFeelTypeInt, 0 },
82 { "accessibility.tabfocus",
83 eMetric_TabFocusModel, PR_FALSE, nsLookAndFeelTypeInt, 0 },
84 { "ui.alertNotificationOrigin",
85 eMetric_AlertNotificationOrigin, PR_FALSE, nsLookAndFeelTypeInt, 0 },
86 { "ui.scrollToClick",
87 eMetric_ScrollToClick, PR_FALSE, nsLookAndFeelTypeInt, 0 },
88 { "ui.IMERawInputUnderlineStyle",
89 eMetric_IMERawInputUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
90 { "ui.IMESelectedRawTextUnderlineStyle",
91 eMetric_IMESelectedRawTextUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
92 { "ui.IMEConvertedTextUnderlineStyle",
93 eMetric_IMEConvertedTextUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
94 { "ui.IMESelectedConvertedTextUnderlineStyle",
95 eMetric_IMESelectedConvertedTextUnderline, PR_FALSE, nsLookAndFeelTypeInt, 0 },
96 { "ui.SpellCheckerUnderlineStyle",
97 eMetric_SpellCheckerUnderlineStyle, PR_FALSE, nsLookAndFeelTypeInt, 0 },
100 nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] =
102 { "ui.IMEUnderlineRelativeSize", eMetricFloat_IMEUnderlineRelativeSize,
103 PR_FALSE, nsLookAndFeelTypeFloat, 0 },
104 { "ui.SpellCheckerUnderlineRelativeSize",
105 eMetricFloat_SpellCheckerUnderlineRelativeSize, PR_FALSE,
106 nsLookAndFeelTypeFloat, 0 },
107 { "ui.caretAspectRatio", eMetricFloat_CaretAspectRatio, PR_FALSE,
108 nsLookAndFeelTypeFloat, 0 },
112 // This array MUST be kept in the same order as the color list in nsILookAndFeel.h.
113 /* XXX If you add any strings longer than
114 * "ui.IMESelectedConvertedTextBackground"
115 * to the following array then you MUST update the
116 * sizes of the sColorPrefs array in nsXPLookAndFeel.h
118 const char nsXPLookAndFeel::sColorPrefs[][38] =
120 "ui.windowBackground",
121 "ui.windowForeground",
122 "ui.widgetBackground",
123 "ui.widgetForeground",
124 "ui.widgetSelectBackground",
125 "ui.widgetSelectForeground",
126 "ui.widget3DHighlight",
127 "ui.widget3DShadow",
128 "ui.textBackground",
129 "ui.textForeground",
130 "ui.textSelectBackground",
131 "ui.textSelectForeground",
132 "ui.textSelectBackgroundDisabled",
133 "ui.textSelectBackgroundAttention",
134 "ui.textHighlightBackground",
135 "ui.textHighlightForeground",
136 "ui.IMERawInputBackground",
137 "ui.IMERawInputForeground",
138 "ui.IMERawInputUnderline",
139 "ui.IMESelectedRawTextBackground",
140 "ui.IMESelectedRawTextForeground",
141 "ui.IMESelectedRawTextUnderline",
142 "ui.IMEConvertedTextBackground",
143 "ui.IMEConvertedTextForeground",
144 "ui.IMEConvertedTextUnderline",
145 "ui.IMESelectedConvertedTextBackground",
146 "ui.IMESelectedConvertedTextForeground",
147 "ui.IMESelectedConvertedTextUnderline",
148 "ui.SpellCheckerUnderline",
149 "ui.activeborder",
150 "ui.activecaption",
151 "ui.appworkspace",
152 "ui.background",
153 "ui.buttonface",
154 "ui.buttonhighlight",
155 "ui.buttonshadow",
156 "ui.buttontext",
157 "ui.captiontext",
158 "ui.graytext",
159 "ui.highlight",
160 "ui.highlighttext",
161 "ui.inactiveborder",
162 "ui.inactivecaption",
163 "ui.inactivecaptiontext",
164 "ui.infobackground",
165 "ui.infotext",
166 "ui.menu",
167 "ui.menutext",
168 "ui.scrollbar",
169 "ui.threeddarkshadow",
170 "ui.threedface",
171 "ui.threedhighlight",
172 "ui.threedlightshadow",
173 "ui.threedshadow",
174 "ui.window",
175 "ui.windowframe",
176 "ui.windowtext",
177 "ui.-moz-buttondefault",
178 "ui.-moz-field",
179 "ui.-moz-fieldtext",
180 "ui.-moz-dialog",
181 "ui.-moz-dialogtext",
182 "ui.-moz-dragtargetzone",
183 "ui.-moz-cellhighlight",
184 "ui.-moz_cellhighlighttext",
185 "ui.-moz-html-cellhighlight",
186 "ui.-moz-html-cellhighlighttext",
187 "ui.-moz-buttonhoverface",
188 "ui.-moz_buttonhovertext",
189 "ui.-moz_menuhover",
190 "ui.-moz_menuhovertext",
191 "ui.-moz_menubartext",
192 "ui.-moz_menubarhovertext",
193 "ui.-moz_eventreerow",
194 "ui.-moz_oddtreerow",
195 "ui.-moz_mac_chrome_active",
196 "ui.-moz_mac_chrome_inactive",
197 "ui.-moz-mac-focusring",
198 "ui.-moz-mac-menuselect",
199 "ui.-moz-mac-menushadow",
200 "ui.-moz-mac-menutextdisable",
201 "ui.-moz-mac-menutextselect",
202 "ui.-moz_mac_disabledtoolbartext",
203 "ui.-moz-mac-alternateprimaryhighlight",
204 "ui.-moz-mac-secondaryhighlight",
205 "ui.-moz-win-mediatext",
206 "ui.-moz-win-communicationstext",
207 "ui.-moz-nativehyperlinktext",
208 "ui.-moz-comboboxtext",
209 "ui.-moz-combobox"
212 PRInt32 nsXPLookAndFeel::sCachedColors[nsILookAndFeel::eColor_LAST_COLOR] = {0};
213 PRInt32 nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
215 PRBool nsXPLookAndFeel::sInitialized = PR_FALSE;
216 PRBool nsXPLookAndFeel::sUseNativeColors = PR_TRUE;
218 nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()
222 void
223 nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data)
225 if (data)
227 nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
228 if (prefService)
230 PRInt32 intpref;
231 nsresult rv = prefService->GetIntPref(data->name, &intpref);
232 if (NS_SUCCEEDED(rv))
234 data->intVar = intpref;
235 data->isSet = PR_TRUE;
236 #ifdef DEBUG_akkana
237 printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
238 #endif
244 void
245 nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data)
247 if (data)
249 nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
250 if (prefService)
252 PRInt32 intpref;
253 nsresult rv = prefService->GetIntPref(data->name, &intpref);
254 if (NS_SUCCEEDED(rv))
256 data->floatVar = (float)intpref / 100.;
257 data->isSet = PR_TRUE;
258 #ifdef DEBUG_akkana
259 printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
260 #endif
266 void
267 nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
269 nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
270 if (prefService) {
271 nsXPIDLCString colorStr;
272 nsresult rv = prefService->GetCharPref(prefName, getter_Copies(colorStr));
273 if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty()) {
274 nscolor thecolor;
275 if (colorStr[0] == '#') {
276 if (NS_HexToRGB(NS_ConvertASCIItoUTF16(Substring(colorStr, 1, colorStr.Length() - 1)),
277 &thecolor)) {
278 PRInt32 id = NS_PTR_TO_INT32(index);
279 CACHE_COLOR(id, thecolor);
282 else if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(colorStr), &thecolor)) {
283 PRInt32 id = NS_PTR_TO_INT32(index);
284 CACHE_COLOR(id, thecolor);
285 #ifdef DEBUG_akkana
286 printf("====== Changed color pref %s to 0x%lx\n",
287 prefName, thecolor);
288 #endif
290 } else if (colorStr.IsEmpty()) {
291 // Reset to the default color, by clearing the cache
292 // to force lookup when the color is next used
293 PRInt32 id = NS_PTR_TO_INT32(index);
294 CLEAR_COLOR_CACHE(id);
299 void
300 nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch)
302 PRInt32 intpref;
303 nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
304 if (NS_SUCCEEDED(rv))
306 aPref->isSet = PR_TRUE;
307 aPref->intVar = intpref;
311 void
312 nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch)
314 PRInt32 intpref;
315 nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
316 if (NS_SUCCEEDED(rv))
318 aPref->isSet = PR_TRUE;
319 aPref->floatVar = (float)intpref / 100.;
323 void
324 nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPrefBranch* aPrefBranch)
326 nsXPIDLCString colorStr;
327 nsresult rv = aPrefBranch->GetCharPref(sColorPrefs[i], getter_Copies(colorStr));
328 if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty())
330 nsAutoString colorNSStr; colorNSStr.AssignWithConversion(colorStr);
331 nscolor thecolor;
332 if (colorNSStr[0] == '#') {
333 nsAutoString hexString;
334 colorNSStr.Right(hexString, colorNSStr.Length() - 1);
335 if (NS_HexToRGB(hexString, &thecolor)) {
336 CACHE_COLOR(i, thecolor);
339 else if (NS_ColorNameToRGB(colorNSStr, &thecolor))
341 CACHE_COLOR(i, thecolor);
346 NS_IMETHODIMP
347 nsXPLookAndFeel::Observe(nsISupports* aSubject,
348 const char* aTopic,
349 const PRUnichar* aData)
352 // looping in the same order as in ::Init
354 unsigned int i;
355 for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
356 if (nsDependentString(aData).EqualsASCII(sIntPrefs[i].name)) {
357 IntPrefChanged(&sIntPrefs[i]);
358 return NS_OK;
362 for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
363 if (nsDependentString(aData).EqualsASCII(sFloatPrefs[i].name)) {
364 FloatPrefChanged(&sFloatPrefs[i]);
365 return NS_OK;
369 for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
370 if (nsDependentString(aData).EqualsASCII(sColorPrefs[i])) {
371 ColorPrefChanged(i, sColorPrefs[i]);
372 return NS_OK;
376 return NS_OK;
380 // Read values from the user's preferences.
381 // This is done once at startup, but since the user's preferences
382 // haven't actually been read yet at that time, we also have to
383 // set a callback to inform us of changes to each pref.
385 void
386 nsXPLookAndFeel::Init()
388 // Say we're already initialized, and take the chance that it might fail;
389 // protects against some other process writing to our static variables.
390 sInitialized = PR_TRUE;
392 nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
393 if (!prefs)
394 return;
395 nsCOMPtr<nsIPrefBranch2> prefBranchInternal(do_QueryInterface(prefs));
396 if (!prefBranchInternal)
397 return;
399 unsigned int i;
400 for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
401 InitFromPref(&sIntPrefs[i], prefs);
402 prefBranchInternal->AddObserver(sIntPrefs[i].name, this, PR_FALSE);
405 for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
406 InitFromPref(&sFloatPrefs[i], prefs);
407 prefBranchInternal->AddObserver(sFloatPrefs[i].name, this, PR_FALSE);
410 for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
411 InitColorFromPref(i, prefs);
412 prefBranchInternal->AddObserver(sColorPrefs[i], this, PR_FALSE);
415 PRBool val;
416 if (NS_SUCCEEDED(prefs->GetBoolPref("ui.use_native_colors", &val))) {
417 sUseNativeColors = val;
421 nsXPLookAndFeel::~nsXPLookAndFeel()
425 PRBool
426 nsXPLookAndFeel::IsSpecialColor(const nsColorID aID, nscolor &aColor)
428 switch (aID) {
429 case eColor_TextSelectForeground:
430 return (aColor == NS_DONT_CHANGE_COLOR);
431 case eColor_IMESelectedRawTextBackground:
432 case eColor_IMESelectedConvertedTextBackground:
433 case eColor_IMERawInputBackground:
434 case eColor_IMEConvertedTextBackground:
435 case eColor_IMESelectedRawTextForeground:
436 case eColor_IMESelectedConvertedTextForeground:
437 case eColor_IMERawInputForeground:
438 case eColor_IMEConvertedTextForeground:
439 case eColor_IMERawInputUnderline:
440 case eColor_IMEConvertedTextUnderline:
441 case eColor_IMESelectedRawTextUnderline:
442 case eColor_IMESelectedConvertedTextUnderline:
443 case eColor_SpellCheckerUnderline:
444 return NS_IS_SELECTION_SPECIAL_COLOR(aColor);
445 default:
447 * In GetColor(), every color that is not a special color is color
448 * corrected. Use PR_FALSE to make other colors color corrected.
450 return PR_FALSE;
452 return PR_FALSE;
456 // All these routines will return NS_OK if they have a value,
457 // in which case the nsLookAndFeel should use that value;
458 // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
459 // platform-specific nsLookAndFeel should use its own values instead.
461 NS_IMETHODIMP
462 nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
464 if (!sInitialized)
465 Init();
467 // define DEBUG_SYSTEM_COLOR_USE if you want to debug system color
468 // use in a skin that uses them. When set, it will make all system
469 // color pairs that are appropriate for foreground/background
470 // pairing the same. This means if the skin is using system colors
471 // correctly you will not be able to see *any* text.
472 #undef DEBUG_SYSTEM_COLOR_USE
474 #ifdef DEBUG_SYSTEM_COLOR_USE
476 nsresult rv = NS_OK;
477 switch (aID) {
478 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
479 case eColor_activecaption:
480 // active window caption background
481 case eColor_captiontext:
482 // text in active window caption
483 aColor = NS_RGB(0xff, 0x00, 0x00);
484 break;
486 case eColor_highlight:
487 // background of selected item
488 case eColor_highlighttext:
489 // text of selected item
490 aColor = NS_RGB(0xff, 0xff, 0x00);
491 break;
493 case eColor_inactivecaption:
494 // inactive window caption
495 case eColor_inactivecaptiontext:
496 // text in inactive window caption
497 aColor = NS_RGB(0x66, 0x66, 0x00);
498 break;
500 case eColor_infobackground:
501 // tooltip background color
502 case eColor_infotext:
503 // tooltip text color
504 aColor = NS_RGB(0x00, 0xff, 0x00);
505 break;
507 case eColor_menu:
508 // menu background
509 case eColor_menutext:
510 // menu text
511 aColor = NS_RGB(0x00, 0xff, 0xff);
512 break;
514 case eColor_threedface:
515 case eColor_buttonface:
516 // 3-D face color
517 case eColor_buttontext:
518 // text on push buttons
519 aColor = NS_RGB(0x00, 0x66, 0x66);
520 break;
522 case eColor_window:
523 case eColor_windowtext:
524 aColor = NS_RGB(0x00, 0x00, 0xff);
525 break;
527 // from the CSS3 working draft (not yet finalized)
528 // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
530 case eColor__moz_field:
531 case eColor__moz_fieldtext:
532 aColor = NS_RGB(0xff, 0x00, 0xff);
533 break;
535 case eColor__moz_dialog:
536 case eColor__moz_dialogtext:
537 aColor = NS_RGB(0x66, 0x00, 0x66);
538 break;
540 default:
541 rv = NS_ERROR_NOT_AVAILABLE;
543 if (NS_SUCCEEDED(rv))
544 return rv;
546 #endif // DEBUG_SYSTEM_COLOR_USE
548 if (IS_COLOR_CACHED(aID)) {
549 aColor = sCachedColors[aID];
550 return NS_OK;
553 // There are no system color settings for these, so set them manually
554 if (aID == eColor_TextSelectBackgroundDisabled) {
555 // This is used to gray out the selection when it's not focused
556 // Used with nsISelectionController::SELECTION_DISABLED
557 aColor = NS_RGB(0xb0, 0xb0, 0xb0);
558 return NS_OK;
561 if (aID == eColor_TextSelectBackgroundAttention) {
562 // This makes the selection stand out when typeaheadfind is on
563 // Used with nsISelectionController::SELECTION_ATTENTION
564 aColor = NS_RGB(0x38, 0xd8, 0x78);
565 return NS_OK;
568 if (aID == eColor_TextHighlightBackground) {
569 // This makes the matched text stand out when findbar highlighting is on
570 // Used with nsISelectionController::SELECTION_FIND
571 aColor = NS_RGB(0xef, 0x0f, 0xff);
572 return NS_OK;
575 if (aID == eColor_TextHighlightForeground) {
576 // The foreground color for the matched text in findbar highlighting
577 // Used with nsISelectionController::SELECTION_FIND
578 aColor = NS_RGB(0xff, 0xff, 0xff);
579 return NS_OK;
582 if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aColor))) {
583 if ((gfxPlatform::GetCMSMode() == eCMSMode_All) && !IsSpecialColor(aID, aColor)) {
584 qcms_transform *transform = gfxPlatform::GetCMSInverseRGBTransform();
585 if (transform) {
586 PRUint8 color[3];
587 color[0] = NS_GET_R(aColor);
588 color[1] = NS_GET_G(aColor);
589 color[2] = NS_GET_B(aColor);
590 qcms_transform_data(transform, color, color, 1);
591 aColor = NS_RGB(color[0], color[1], color[2]);
595 CACHE_COLOR(aID, aColor);
596 return NS_OK;
599 return NS_ERROR_NOT_AVAILABLE;
602 NS_IMETHODIMP
603 nsXPLookAndFeel::GetMetric(const nsMetricID aID, PRInt32& aMetric)
605 if (!sInitialized)
606 Init();
608 // Set the default values for these prefs. but allow different platforms
609 // to override them in their nsLookAndFeel if desired.
610 switch (aID) {
611 case eMetric_ScrollButtonLeftMouseButtonAction:
612 aMetric = 0;
613 return NS_OK;
614 case eMetric_ScrollButtonMiddleMouseButtonAction:
615 aMetric = 3;
616 return NS_OK;
617 case eMetric_ScrollButtonRightMouseButtonAction:
618 aMetric = 3;
619 return NS_OK;
620 default:
622 * The metrics above are hardcoded platform defaults. All the other
623 * metrics are stored in sIntPrefs and can be changed at runtime.
625 break;
628 for (unsigned int i = 0; i < ((sizeof (sIntPrefs) / sizeof (*sIntPrefs))); ++i)
629 if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID))
631 aMetric = sIntPrefs[i].intVar;
632 return NS_OK;
635 return NS_ERROR_NOT_AVAILABLE;
638 NS_IMETHODIMP
639 nsXPLookAndFeel::GetMetric(const nsMetricFloatID aID, float& aMetric)
641 if (!sInitialized)
642 Init();
644 for (unsigned int i = 0; i < ((sizeof (sFloatPrefs) / sizeof (*sFloatPrefs))); ++i)
645 if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID)
647 aMetric = sFloatPrefs[i].floatVar;
648 return NS_OK;
651 return NS_ERROR_NOT_AVAILABLE;
654 NS_IMETHODIMP
655 nsXPLookAndFeel::LookAndFeelChanged()
657 // Wipe out our color cache.
658 PRUint32 i;
659 for (i = 0; i < nsILookAndFeel::eColor_LAST_COLOR; i++)
660 sCachedColors[i] = 0;
661 for (i = 0; i < COLOR_CACHE_SIZE; i++)
662 sCachedColorBits[i] = 0;
663 return NS_OK;
667 #ifdef DEBUG
668 // This method returns the actual (or nearest estimate)
669 // of the Navigator size for a given form control for a given font
670 // and font size. This is used in NavQuirks mode to see how closely
671 // we match its size
672 NS_IMETHODIMP
673 nsXPLookAndFeel::GetNavSize(const nsMetricNavWidgetID aWidgetID,
674 const nsMetricNavFontID aFontID,
675 const PRInt32 aFontSize,
676 nsSize &aSize)
678 aSize.width = 0;
679 aSize.height = 0;
680 return NS_ERROR_NOT_IMPLEMENTED;
682 #endif