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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "mozilla/Util.h"
39 :
40 : #include "nscore.h"
41 :
42 : #include "nsXPLookAndFeel.h"
43 : #include "nsLookAndFeel.h"
44 : #include "nsCRT.h"
45 : #include "nsFont.h"
46 : #include "mozilla/Preferences.h"
47 :
48 : #include "gfxPlatform.h"
49 : #include "qcms.h"
50 :
51 : #ifdef DEBUG
52 : #include "nsSize.h"
53 : #endif
54 :
55 : using namespace mozilla;
56 :
57 : nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
58 : {
59 : { "ui.caretBlinkTime",
60 : eIntID_CaretBlinkTime,
61 : false, 0 },
62 : { "ui.caretWidth",
63 : eIntID_CaretWidth,
64 : false, 0 },
65 : { "ui.caretVisibleWithSelection",
66 : eIntID_ShowCaretDuringSelection,
67 : false, 0 },
68 : { "ui.submenuDelay",
69 : eIntID_SubmenuDelay,
70 : false, 0 },
71 : { "ui.dragThresholdX",
72 : eIntID_DragThresholdX,
73 : false, 0 },
74 : { "ui.dragThresholdY",
75 : eIntID_DragThresholdY,
76 : false, 0 },
77 : { "ui.useAccessibilityTheme",
78 : eIntID_UseAccessibilityTheme,
79 : false, 0 },
80 : { "ui.menusCanOverlapOSBar",
81 : eIntID_MenusCanOverlapOSBar,
82 : false, 0 },
83 : { "ui.skipNavigatingDisabledMenuItem",
84 : eIntID_SkipNavigatingDisabledMenuItem,
85 : false, 0 },
86 : { "ui.treeOpenDelay",
87 : eIntID_TreeOpenDelay,
88 : false, 0 },
89 : { "ui.treeCloseDelay",
90 : eIntID_TreeCloseDelay,
91 : false, 0 },
92 : { "ui.treeLazyScrollDelay",
93 : eIntID_TreeLazyScrollDelay,
94 : false, 0 },
95 : { "ui.treeScrollDelay",
96 : eIntID_TreeScrollDelay,
97 : false, 0 },
98 : { "ui.treeScrollLinesMax",
99 : eIntID_TreeScrollLinesMax,
100 : false, 0 },
101 : { "accessibility.tabfocus",
102 : eIntID_TabFocusModel,
103 : false, 0 },
104 : { "ui.alertNotificationOrigin",
105 : eIntID_AlertNotificationOrigin,
106 : false, 0 },
107 : { "ui.scrollToClick",
108 : eIntID_ScrollToClick,
109 : false, 0 },
110 : { "ui.IMERawInputUnderlineStyle",
111 : eIntID_IMERawInputUnderlineStyle,
112 : false, 0 },
113 : { "ui.IMESelectedRawTextUnderlineStyle",
114 : eIntID_IMESelectedRawTextUnderlineStyle,
115 : false, 0 },
116 : { "ui.IMEConvertedTextUnderlineStyle",
117 : eIntID_IMEConvertedTextUnderlineStyle,
118 : false, 0 },
119 : { "ui.IMESelectedConvertedTextUnderlineStyle",
120 : eIntID_IMESelectedConvertedTextUnderline,
121 : false, 0 },
122 : { "ui.SpellCheckerUnderlineStyle",
123 : eIntID_SpellCheckerUnderlineStyle,
124 : false, 0 },
125 : { "ui.scrollbarButtonAutoRepeatBehavior",
126 : eIntID_ScrollbarButtonAutoRepeatBehavior,
127 : false, 0 },
128 : { "ui.tooltipDelay",
129 : eIntID_TooltipDelay,
130 : false, 0 },
131 : };
132 :
133 : nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] =
134 : {
135 : { "ui.IMEUnderlineRelativeSize",
136 : eFloatID_IMEUnderlineRelativeSize,
137 : false, 0 },
138 : { "ui.SpellCheckerUnderlineRelativeSize",
139 : eFloatID_SpellCheckerUnderlineRelativeSize,
140 : false, 0 },
141 : { "ui.caretAspectRatio",
142 : eFloatID_CaretAspectRatio,
143 : false, 0 },
144 : };
145 :
146 :
147 : // This array MUST be kept in the same order as the color list in LookAndFeel.h.
148 : /* XXX If you add any strings longer than
149 : * "ui.IMESelectedConvertedTextBackground"
150 : * to the following array then you MUST update the
151 : * sizes of the sColorPrefs array in nsXPLookAndFeel.h
152 : */
153 : const char nsXPLookAndFeel::sColorPrefs[][38] =
154 : {
155 : "ui.windowBackground",
156 : "ui.windowForeground",
157 : "ui.widgetBackground",
158 : "ui.widgetForeground",
159 : "ui.widgetSelectBackground",
160 : "ui.widgetSelectForeground",
161 : "ui.widget3DHighlight",
162 : "ui.widget3DShadow",
163 : "ui.textBackground",
164 : "ui.textForeground",
165 : "ui.textSelectBackground",
166 : "ui.textSelectForeground",
167 : "ui.textSelectBackgroundDisabled",
168 : "ui.textSelectBackgroundAttention",
169 : "ui.textHighlightBackground",
170 : "ui.textHighlightForeground",
171 : "ui.IMERawInputBackground",
172 : "ui.IMERawInputForeground",
173 : "ui.IMERawInputUnderline",
174 : "ui.IMESelectedRawTextBackground",
175 : "ui.IMESelectedRawTextForeground",
176 : "ui.IMESelectedRawTextUnderline",
177 : "ui.IMEConvertedTextBackground",
178 : "ui.IMEConvertedTextForeground",
179 : "ui.IMEConvertedTextUnderline",
180 : "ui.IMESelectedConvertedTextBackground",
181 : "ui.IMESelectedConvertedTextForeground",
182 : "ui.IMESelectedConvertedTextUnderline",
183 : "ui.SpellCheckerUnderline",
184 : "ui.activeborder",
185 : "ui.activecaption",
186 : "ui.appworkspace",
187 : "ui.background",
188 : "ui.buttonface",
189 : "ui.buttonhighlight",
190 : "ui.buttonshadow",
191 : "ui.buttontext",
192 : "ui.captiontext",
193 : "ui.graytext",
194 : "ui.highlight",
195 : "ui.highlighttext",
196 : "ui.inactiveborder",
197 : "ui.inactivecaption",
198 : "ui.inactivecaptiontext",
199 : "ui.infobackground",
200 : "ui.infotext",
201 : "ui.menu",
202 : "ui.menutext",
203 : "ui.scrollbar",
204 : "ui.threeddarkshadow",
205 : "ui.threedface",
206 : "ui.threedhighlight",
207 : "ui.threedlightshadow",
208 : "ui.threedshadow",
209 : "ui.window",
210 : "ui.windowframe",
211 : "ui.windowtext",
212 : "ui.-moz-buttondefault",
213 : "ui.-moz-field",
214 : "ui.-moz-fieldtext",
215 : "ui.-moz-dialog",
216 : "ui.-moz-dialogtext",
217 : "ui.-moz-dragtargetzone",
218 : "ui.-moz-cellhighlight",
219 : "ui.-moz_cellhighlighttext",
220 : "ui.-moz-html-cellhighlight",
221 : "ui.-moz-html-cellhighlighttext",
222 : "ui.-moz-buttonhoverface",
223 : "ui.-moz_buttonhovertext",
224 : "ui.-moz_menuhover",
225 : "ui.-moz_menuhovertext",
226 : "ui.-moz_menubartext",
227 : "ui.-moz_menubarhovertext",
228 : "ui.-moz_eventreerow",
229 : "ui.-moz_oddtreerow",
230 : "ui.-moz_mac_chrome_active",
231 : "ui.-moz_mac_chrome_inactive",
232 : "ui.-moz-mac-focusring",
233 : "ui.-moz-mac-menuselect",
234 : "ui.-moz-mac-menushadow",
235 : "ui.-moz-mac-menutextdisable",
236 : "ui.-moz-mac-menutextselect",
237 : "ui.-moz_mac_disabledtoolbartext",
238 : "ui.-moz-mac-alternateprimaryhighlight",
239 : "ui.-moz-mac-secondaryhighlight",
240 : "ui.-moz-win-mediatext",
241 : "ui.-moz-win-communicationstext",
242 : "ui.-moz-nativehyperlinktext",
243 : "ui.-moz-comboboxtext",
244 : "ui.-moz-combobox"
245 : };
246 :
247 : PRInt32 nsXPLookAndFeel::sCachedColors[LookAndFeel::eColorID_LAST_COLOR] = {0};
248 : PRInt32 nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
249 :
250 : bool nsXPLookAndFeel::sInitialized = false;
251 : bool nsXPLookAndFeel::sUseNativeColors = true;
252 :
253 : nsLookAndFeel* nsXPLookAndFeel::sInstance = nsnull;
254 : bool nsXPLookAndFeel::sShutdown = false;
255 :
256 : // static
257 : nsLookAndFeel*
258 0 : nsXPLookAndFeel::GetInstance()
259 : {
260 0 : if (sInstance) {
261 0 : return sInstance;
262 : }
263 :
264 0 : NS_ENSURE_TRUE(!sShutdown, nsnull);
265 :
266 0 : sInstance = new nsLookAndFeel();
267 0 : return sInstance;
268 : }
269 :
270 : // static
271 : void
272 1387 : nsXPLookAndFeel::Shutdown()
273 : {
274 1387 : if (sShutdown) {
275 0 : return;
276 : }
277 1387 : sShutdown = true;
278 1387 : delete sInstance;
279 1387 : sInstance = nsnull;
280 : }
281 :
282 0 : nsXPLookAndFeel::nsXPLookAndFeel() : LookAndFeel()
283 : {
284 0 : }
285 :
286 : // static
287 : void
288 0 : nsXPLookAndFeel::IntPrefChanged(nsLookAndFeelIntPref *data)
289 : {
290 0 : if (!data) {
291 0 : return;
292 : }
293 :
294 : PRInt32 intpref;
295 0 : nsresult rv = Preferences::GetInt(data->name, &intpref);
296 0 : if (NS_FAILED(rv)) {
297 0 : return;
298 : }
299 0 : data->intVar = intpref;
300 0 : data->isSet = true;
301 : #ifdef DEBUG_akkana
302 : printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
303 : #endif
304 : }
305 :
306 : // static
307 : void
308 0 : nsXPLookAndFeel::FloatPrefChanged(nsLookAndFeelFloatPref *data)
309 : {
310 0 : if (!data) {
311 0 : return;
312 : }
313 :
314 : PRInt32 intpref;
315 0 : nsresult rv = Preferences::GetInt(data->name, &intpref);
316 0 : if (NS_FAILED(rv)) {
317 0 : return;
318 : }
319 0 : data->floatVar = (float)intpref / 100.0f;
320 0 : data->isSet = true;
321 : #ifdef DEBUG_akkana
322 : printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
323 : #endif
324 : }
325 :
326 : // static
327 : void
328 0 : nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
329 : {
330 0 : nsAutoString colorStr;
331 0 : nsresult rv = Preferences::GetString(prefName, &colorStr);
332 0 : if (NS_FAILED(rv)) {
333 : return;
334 : }
335 0 : if (!colorStr.IsEmpty()) {
336 : nscolor thecolor;
337 0 : if (colorStr[0] == PRUnichar('#')) {
338 0 : if (NS_HexToRGB(nsDependentString(colorStr, 1), &thecolor)) {
339 0 : PRInt32 id = NS_PTR_TO_INT32(index);
340 0 : CACHE_COLOR(id, thecolor);
341 : }
342 0 : } else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
343 0 : PRInt32 id = NS_PTR_TO_INT32(index);
344 0 : CACHE_COLOR(id, thecolor);
345 : #ifdef DEBUG_akkana
346 : printf("====== Changed color pref %s to 0x%lx\n",
347 : prefName, thecolor);
348 : #endif
349 : }
350 : } else {
351 : // Reset to the default color, by clearing the cache
352 : // to force lookup when the color is next used
353 0 : PRInt32 id = NS_PTR_TO_INT32(index);
354 0 : CLEAR_COLOR_CACHE(id);
355 : }
356 : }
357 :
358 : void
359 0 : nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref)
360 : {
361 : PRInt32 intpref;
362 0 : nsresult rv = Preferences::GetInt(aPref->name, &intpref);
363 0 : if (NS_SUCCEEDED(rv)) {
364 0 : aPref->isSet = true;
365 0 : aPref->intVar = intpref;
366 : }
367 0 : }
368 :
369 : void
370 0 : nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref)
371 : {
372 : PRInt32 intpref;
373 0 : nsresult rv = Preferences::GetInt(aPref->name, &intpref);
374 0 : if (NS_SUCCEEDED(rv)) {
375 0 : aPref->isSet = true;
376 0 : aPref->floatVar = (float)intpref / 100.0f;
377 : }
378 0 : }
379 :
380 : void
381 0 : nsXPLookAndFeel::InitColorFromPref(PRInt32 i)
382 : {
383 0 : nsAutoString colorStr;
384 0 : nsresult rv = Preferences::GetString(sColorPrefs[i], &colorStr);
385 0 : if (NS_FAILED(rv) || colorStr.IsEmpty()) {
386 : return;
387 : }
388 : nscolor thecolor;
389 0 : if (colorStr[0] == PRUnichar('#')) {
390 0 : nsAutoString hexString;
391 0 : colorStr.Right(hexString, colorStr.Length() - 1);
392 0 : if (NS_HexToRGB(hexString, &thecolor)) {
393 0 : CACHE_COLOR(i, thecolor);
394 : }
395 0 : } else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
396 0 : CACHE_COLOR(i, thecolor);
397 : }
398 : }
399 :
400 : // static
401 : int
402 0 : nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure)
403 : {
404 :
405 : // looping in the same order as in ::Init
406 :
407 0 : nsDependentCString prefName(aPref);
408 : unsigned int i;
409 0 : for (i = 0; i < ArrayLength(sIntPrefs); ++i) {
410 0 : if (prefName.Equals(sIntPrefs[i].name)) {
411 0 : IntPrefChanged(&sIntPrefs[i]);
412 0 : return 0;
413 : }
414 : }
415 :
416 0 : for (i = 0; i < ArrayLength(sFloatPrefs); ++i) {
417 0 : if (prefName.Equals(sFloatPrefs[i].name)) {
418 0 : FloatPrefChanged(&sFloatPrefs[i]);
419 0 : return 0;
420 : }
421 : }
422 :
423 0 : for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
424 0 : if (prefName.Equals(sColorPrefs[i])) {
425 0 : ColorPrefChanged(i, sColorPrefs[i]);
426 0 : return 0;
427 : }
428 : }
429 :
430 0 : return 0;
431 : }
432 :
433 : //
434 : // Read values from the user's preferences.
435 : // This is done once at startup, but since the user's preferences
436 : // haven't actually been read yet at that time, we also have to
437 : // set a callback to inform us of changes to each pref.
438 : //
439 : void
440 0 : nsXPLookAndFeel::Init()
441 : {
442 : // Say we're already initialized, and take the chance that it might fail;
443 : // protects against some other process writing to our static variables.
444 0 : sInitialized = true;
445 :
446 : // XXX If we could reorganize the pref names, we should separate the branch
447 : // for each types. Then, we could reduce the unnecessary loop from
448 : // nsXPLookAndFeel::OnPrefChanged().
449 0 : Preferences::RegisterCallback(OnPrefChanged, "ui.");
450 0 : Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus");
451 :
452 : unsigned int i;
453 0 : for (i = 0; i < ArrayLength(sIntPrefs); ++i) {
454 0 : InitFromPref(&sIntPrefs[i]);
455 : }
456 :
457 0 : for (i = 0; i < ArrayLength(sFloatPrefs); ++i) {
458 0 : InitFromPref(&sFloatPrefs[i]);
459 : }
460 :
461 0 : for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
462 0 : InitColorFromPref(i);
463 : }
464 :
465 : bool val;
466 0 : if (NS_SUCCEEDED(Preferences::GetBool("ui.use_native_colors", &val))) {
467 0 : sUseNativeColors = val;
468 : }
469 0 : }
470 :
471 0 : nsXPLookAndFeel::~nsXPLookAndFeel()
472 : {
473 0 : NS_ASSERTION(sInstance == this,
474 : "This destroying instance isn't the singleton instance");
475 0 : sInstance = nsnull;
476 0 : }
477 :
478 : bool
479 0 : nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
480 : {
481 0 : switch (aID) {
482 : case eColorID_TextSelectForeground:
483 0 : return (aColor == NS_DONT_CHANGE_COLOR);
484 : case eColorID_IMESelectedRawTextBackground:
485 : case eColorID_IMESelectedConvertedTextBackground:
486 : case eColorID_IMERawInputBackground:
487 : case eColorID_IMEConvertedTextBackground:
488 : case eColorID_IMESelectedRawTextForeground:
489 : case eColorID_IMESelectedConvertedTextForeground:
490 : case eColorID_IMERawInputForeground:
491 : case eColorID_IMEConvertedTextForeground:
492 : case eColorID_IMERawInputUnderline:
493 : case eColorID_IMEConvertedTextUnderline:
494 : case eColorID_IMESelectedRawTextUnderline:
495 : case eColorID_IMESelectedConvertedTextUnderline:
496 : case eColorID_SpellCheckerUnderline:
497 0 : return NS_IS_SELECTION_SPECIAL_COLOR(aColor);
498 : default:
499 : /*
500 : * In GetColor(), every color that is not a special color is color
501 : * corrected. Use false to make other colors color corrected.
502 : */
503 0 : return false;
504 : }
505 : return false;
506 : }
507 :
508 : //
509 : // All these routines will return NS_OK if they have a value,
510 : // in which case the nsLookAndFeel should use that value;
511 : // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
512 : // platform-specific nsLookAndFeel should use its own values instead.
513 : //
514 : nsresult
515 0 : nsXPLookAndFeel::GetColorImpl(ColorID aID, nscolor &aResult)
516 : {
517 0 : if (!sInitialized)
518 0 : Init();
519 :
520 : // define DEBUG_SYSTEM_COLOR_USE if you want to debug system color
521 : // use in a skin that uses them. When set, it will make all system
522 : // color pairs that are appropriate for foreground/background
523 : // pairing the same. This means if the skin is using system colors
524 : // correctly you will not be able to see *any* text.
525 : #undef DEBUG_SYSTEM_COLOR_USE
526 :
527 : #ifdef DEBUG_SYSTEM_COLOR_USE
528 : {
529 : nsresult rv = NS_OK;
530 : switch (aID) {
531 : // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
532 : case eColorID_activecaption:
533 : // active window caption background
534 : case eColorID_captiontext:
535 : // text in active window caption
536 : aResult = NS_RGB(0xff, 0x00, 0x00);
537 : break;
538 :
539 : case eColorID_highlight:
540 : // background of selected item
541 : case eColorID_highlighttext:
542 : // text of selected item
543 : aResult = NS_RGB(0xff, 0xff, 0x00);
544 : break;
545 :
546 : case eColorID_inactivecaption:
547 : // inactive window caption
548 : case eColorID_inactivecaptiontext:
549 : // text in inactive window caption
550 : aResult = NS_RGB(0x66, 0x66, 0x00);
551 : break;
552 :
553 : case eColorID_infobackground:
554 : // tooltip background color
555 : case eColorID_infotext:
556 : // tooltip text color
557 : aResult = NS_RGB(0x00, 0xff, 0x00);
558 : break;
559 :
560 : case eColorID_menu:
561 : // menu background
562 : case eColorID_menutext:
563 : // menu text
564 : aResult = NS_RGB(0x00, 0xff, 0xff);
565 : break;
566 :
567 : case eColorID_threedface:
568 : case eColorID_buttonface:
569 : // 3-D face color
570 : case eColorID_buttontext:
571 : // text on push buttons
572 : aResult = NS_RGB(0x00, 0x66, 0x66);
573 : break;
574 :
575 : case eColorID_window:
576 : case eColorID_windowtext:
577 : aResult = NS_RGB(0x00, 0x00, 0xff);
578 : break;
579 :
580 : // from the CSS3 working draft (not yet finalized)
581 : // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
582 :
583 : case eColorID__moz_field:
584 : case eColorID__moz_fieldtext:
585 : aResult = NS_RGB(0xff, 0x00, 0xff);
586 : break;
587 :
588 : case eColorID__moz_dialog:
589 : case eColorID__moz_dialogtext:
590 : aResult = NS_RGB(0x66, 0x00, 0x66);
591 : break;
592 :
593 : default:
594 : rv = NS_ERROR_NOT_AVAILABLE;
595 : }
596 : if (NS_SUCCEEDED(rv))
597 : return rv;
598 : }
599 : #endif // DEBUG_SYSTEM_COLOR_USE
600 :
601 0 : if (IS_COLOR_CACHED(aID)) {
602 0 : aResult = sCachedColors[aID];
603 0 : return NS_OK;
604 : }
605 :
606 : // There are no system color settings for these, so set them manually
607 0 : if (aID == eColorID_TextSelectBackgroundDisabled) {
608 : // This is used to gray out the selection when it's not focused
609 : // Used with nsISelectionController::SELECTION_DISABLED
610 0 : aResult = NS_RGB(0xb0, 0xb0, 0xb0);
611 0 : return NS_OK;
612 : }
613 :
614 0 : if (aID == eColorID_TextSelectBackgroundAttention) {
615 : // This makes the selection stand out when typeaheadfind is on
616 : // Used with nsISelectionController::SELECTION_ATTENTION
617 0 : aResult = NS_RGB(0x38, 0xd8, 0x78);
618 0 : return NS_OK;
619 : }
620 :
621 0 : if (aID == eColorID_TextHighlightBackground) {
622 : // This makes the matched text stand out when findbar highlighting is on
623 : // Used with nsISelectionController::SELECTION_FIND
624 0 : aResult = NS_RGB(0xef, 0x0f, 0xff);
625 0 : return NS_OK;
626 : }
627 :
628 0 : if (aID == eColorID_TextHighlightForeground) {
629 : // The foreground color for the matched text in findbar highlighting
630 : // Used with nsISelectionController::SELECTION_FIND
631 0 : aResult = NS_RGB(0xff, 0xff, 0xff);
632 0 : return NS_OK;
633 : }
634 :
635 0 : if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aResult))) {
636 0 : if ((gfxPlatform::GetCMSMode() == eCMSMode_All) &&
637 0 : !IsSpecialColor(aID, aResult)) {
638 0 : qcms_transform *transform = gfxPlatform::GetCMSInverseRGBTransform();
639 0 : if (transform) {
640 : PRUint8 color[3];
641 0 : color[0] = NS_GET_R(aResult);
642 0 : color[1] = NS_GET_G(aResult);
643 0 : color[2] = NS_GET_B(aResult);
644 0 : qcms_transform_data(transform, color, color, 1);
645 0 : aResult = NS_RGB(color[0], color[1], color[2]);
646 : }
647 : }
648 :
649 0 : CACHE_COLOR(aID, aResult);
650 0 : return NS_OK;
651 : }
652 :
653 0 : return NS_ERROR_NOT_AVAILABLE;
654 : }
655 :
656 : nsresult
657 0 : nsXPLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
658 : {
659 0 : if (!sInitialized)
660 0 : Init();
661 :
662 : // Set the default values for these prefs. but allow different platforms
663 : // to override them in their nsLookAndFeel if desired.
664 0 : switch (aID) {
665 : case eIntID_ScrollButtonLeftMouseButtonAction:
666 0 : aResult = 0;
667 0 : return NS_OK;
668 : case eIntID_ScrollButtonMiddleMouseButtonAction:
669 0 : aResult = 3;
670 0 : return NS_OK;
671 : case eIntID_ScrollButtonRightMouseButtonAction:
672 0 : aResult = 3;
673 0 : return NS_OK;
674 : default:
675 : /*
676 : * The metrics above are hardcoded platform defaults. All the other
677 : * metrics are stored in sIntPrefs and can be changed at runtime.
678 : */
679 : break;
680 : }
681 :
682 0 : for (unsigned int i = 0; i < ArrayLength(sIntPrefs); ++i) {
683 0 : if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID)) {
684 0 : aResult = sIntPrefs[i].intVar;
685 0 : return NS_OK;
686 : }
687 : }
688 :
689 0 : return NS_ERROR_NOT_AVAILABLE;
690 : }
691 :
692 : nsresult
693 0 : nsXPLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
694 : {
695 0 : if (!sInitialized)
696 0 : Init();
697 :
698 0 : for (unsigned int i = 0; i < ArrayLength(sFloatPrefs); ++i) {
699 0 : if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID) {
700 0 : aResult = sFloatPrefs[i].floatVar;
701 0 : return NS_OK;
702 : }
703 : }
704 :
705 0 : return NS_ERROR_NOT_AVAILABLE;
706 : }
707 :
708 : void
709 0 : nsXPLookAndFeel::RefreshImpl()
710 : {
711 : // Wipe out our color cache.
712 : PRUint32 i;
713 0 : for (i = 0; i < eColorID_LAST_COLOR; i++)
714 0 : sCachedColors[i] = 0;
715 0 : for (i = 0; i < COLOR_CACHE_SIZE; i++)
716 0 : sCachedColorBits[i] = 0;
717 0 : }
718 :
719 : namespace mozilla {
720 :
721 : // static
722 : nsresult
723 0 : LookAndFeel::GetColor(ColorID aID, nscolor* aResult)
724 : {
725 0 : return nsLookAndFeel::GetInstance()->GetColorImpl(aID, *aResult);
726 : }
727 :
728 : // static
729 : nsresult
730 0 : LookAndFeel::GetInt(IntID aID, PRInt32* aResult)
731 : {
732 0 : return nsLookAndFeel::GetInstance()->GetIntImpl(aID, *aResult);
733 : }
734 :
735 : // static
736 : nsresult
737 0 : LookAndFeel::GetFloat(FloatID aID, float* aResult)
738 : {
739 0 : return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult);
740 : }
741 :
742 : // static
743 : bool
744 0 : LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle)
745 : {
746 0 : return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle);
747 : }
748 :
749 : // static
750 : PRUnichar
751 0 : LookAndFeel::GetPasswordCharacter()
752 : {
753 0 : return nsLookAndFeel::GetInstance()->GetPasswordCharacterImpl();
754 : }
755 :
756 : // static
757 : bool
758 0 : LookAndFeel::GetEchoPassword()
759 : {
760 0 : return nsLookAndFeel::GetInstance()->GetEchoPasswordImpl();
761 : }
762 :
763 : // static
764 : void
765 0 : LookAndFeel::Refresh()
766 : {
767 0 : nsLookAndFeel::GetInstance()->RefreshImpl();
768 0 : }
769 :
770 : } // namespace mozilla
|