1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xpwidgets/nsXPLookAndFeel.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,969 @@ 1.4 +/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/ArrayUtils.h" 1.10 + 1.11 +#include "nscore.h" 1.12 + 1.13 +#include "nsXPLookAndFeel.h" 1.14 +#include "nsLookAndFeel.h" 1.15 +#include "nsCRT.h" 1.16 +#include "nsFont.h" 1.17 +#include "nsThemeConstants.h" 1.18 +#include "mozilla/Preferences.h" 1.19 +#include "mozilla/gfx/2D.h" 1.20 + 1.21 +#include "gfxPlatform.h" 1.22 +#include "qcms.h" 1.23 + 1.24 +#ifdef DEBUG 1.25 +#include "nsSize.h" 1.26 +#endif 1.27 + 1.28 +using namespace mozilla; 1.29 + 1.30 +nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] = 1.31 +{ 1.32 + { "ui.caretBlinkTime", 1.33 + eIntID_CaretBlinkTime, 1.34 + false, 0 }, 1.35 + { "ui.caretWidth", 1.36 + eIntID_CaretWidth, 1.37 + false, 0 }, 1.38 + { "ui.caretVisibleWithSelection", 1.39 + eIntID_ShowCaretDuringSelection, 1.40 + false, 0 }, 1.41 + { "ui.submenuDelay", 1.42 + eIntID_SubmenuDelay, 1.43 + false, 0 }, 1.44 + { "ui.dragThresholdX", 1.45 + eIntID_DragThresholdX, 1.46 + false, 0 }, 1.47 + { "ui.dragThresholdY", 1.48 + eIntID_DragThresholdY, 1.49 + false, 0 }, 1.50 + { "ui.useAccessibilityTheme", 1.51 + eIntID_UseAccessibilityTheme, 1.52 + false, 0 }, 1.53 + { "ui.menusCanOverlapOSBar", 1.54 + eIntID_MenusCanOverlapOSBar, 1.55 + false, 0 }, 1.56 + { "ui.useOverlayScrollbars", 1.57 + eIntID_UseOverlayScrollbars, 1.58 + false, 0 }, 1.59 + { "ui.scrollbarDisplayOnMouseMove", 1.60 + eIntID_ScrollbarDisplayOnMouseMove, 1.61 + false, 0 }, 1.62 + { "ui.scrollbarFadeBeginDelay", 1.63 + eIntID_ScrollbarFadeBeginDelay, 1.64 + false, 0 }, 1.65 + { "ui.scrollbarFadeDuration", 1.66 + eIntID_ScrollbarFadeDuration, 1.67 + false, 0 }, 1.68 + { "ui.showHideScrollbars", 1.69 + eIntID_ShowHideScrollbars, 1.70 + false, 0 }, 1.71 + { "ui.skipNavigatingDisabledMenuItem", 1.72 + eIntID_SkipNavigatingDisabledMenuItem, 1.73 + false, 0 }, 1.74 + { "ui.treeOpenDelay", 1.75 + eIntID_TreeOpenDelay, 1.76 + false, 0 }, 1.77 + { "ui.treeCloseDelay", 1.78 + eIntID_TreeCloseDelay, 1.79 + false, 0 }, 1.80 + { "ui.treeLazyScrollDelay", 1.81 + eIntID_TreeLazyScrollDelay, 1.82 + false, 0 }, 1.83 + { "ui.treeScrollDelay", 1.84 + eIntID_TreeScrollDelay, 1.85 + false, 0 }, 1.86 + { "ui.treeScrollLinesMax", 1.87 + eIntID_TreeScrollLinesMax, 1.88 + false, 0 }, 1.89 + { "accessibility.tabfocus", 1.90 + eIntID_TabFocusModel, 1.91 + false, 0 }, 1.92 + { "ui.alertNotificationOrigin", 1.93 + eIntID_AlertNotificationOrigin, 1.94 + false, 0 }, 1.95 + { "ui.scrollToClick", 1.96 + eIntID_ScrollToClick, 1.97 + false, 0 }, 1.98 + { "ui.IMERawInputUnderlineStyle", 1.99 + eIntID_IMERawInputUnderlineStyle, 1.100 + false, 0 }, 1.101 + { "ui.IMESelectedRawTextUnderlineStyle", 1.102 + eIntID_IMESelectedRawTextUnderlineStyle, 1.103 + false, 0 }, 1.104 + { "ui.IMEConvertedTextUnderlineStyle", 1.105 + eIntID_IMEConvertedTextUnderlineStyle, 1.106 + false, 0 }, 1.107 + { "ui.IMESelectedConvertedTextUnderlineStyle", 1.108 + eIntID_IMESelectedConvertedTextUnderline, 1.109 + false, 0 }, 1.110 + { "ui.SpellCheckerUnderlineStyle", 1.111 + eIntID_SpellCheckerUnderlineStyle, 1.112 + false, 0 }, 1.113 + { "ui.scrollbarButtonAutoRepeatBehavior", 1.114 + eIntID_ScrollbarButtonAutoRepeatBehavior, 1.115 + false, 0 }, 1.116 + { "ui.tooltipDelay", 1.117 + eIntID_TooltipDelay, 1.118 + false, 0 }, 1.119 + { "ui.physicalHomeButton", 1.120 + eIntID_PhysicalHomeButton, 1.121 + false, 0 }, 1.122 +}; 1.123 + 1.124 +nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] = 1.125 +{ 1.126 + { "ui.IMEUnderlineRelativeSize", 1.127 + eFloatID_IMEUnderlineRelativeSize, 1.128 + false, 0 }, 1.129 + { "ui.SpellCheckerUnderlineRelativeSize", 1.130 + eFloatID_SpellCheckerUnderlineRelativeSize, 1.131 + false, 0 }, 1.132 + { "ui.caretAspectRatio", 1.133 + eFloatID_CaretAspectRatio, 1.134 + false, 0 }, 1.135 +}; 1.136 + 1.137 + 1.138 +// This array MUST be kept in the same order as the color list in LookAndFeel.h. 1.139 +/* XXX If you add any strings longer than 1.140 + * "ui.IMESelectedConvertedTextBackground" 1.141 + * to the following array then you MUST update the 1.142 + * sizes of the sColorPrefs array in nsXPLookAndFeel.h 1.143 + */ 1.144 +const char nsXPLookAndFeel::sColorPrefs[][38] = 1.145 +{ 1.146 + "ui.windowBackground", 1.147 + "ui.windowForeground", 1.148 + "ui.widgetBackground", 1.149 + "ui.widgetForeground", 1.150 + "ui.widgetSelectBackground", 1.151 + "ui.widgetSelectForeground", 1.152 + "ui.widget3DHighlight", 1.153 + "ui.widget3DShadow", 1.154 + "ui.textBackground", 1.155 + "ui.textForeground", 1.156 + "ui.textSelectBackground", 1.157 + "ui.textSelectForeground", 1.158 + "ui.textSelectBackgroundDisabled", 1.159 + "ui.textSelectBackgroundAttention", 1.160 + "ui.textHighlightBackground", 1.161 + "ui.textHighlightForeground", 1.162 + "ui.IMERawInputBackground", 1.163 + "ui.IMERawInputForeground", 1.164 + "ui.IMERawInputUnderline", 1.165 + "ui.IMESelectedRawTextBackground", 1.166 + "ui.IMESelectedRawTextForeground", 1.167 + "ui.IMESelectedRawTextUnderline", 1.168 + "ui.IMEConvertedTextBackground", 1.169 + "ui.IMEConvertedTextForeground", 1.170 + "ui.IMEConvertedTextUnderline", 1.171 + "ui.IMESelectedConvertedTextBackground", 1.172 + "ui.IMESelectedConvertedTextForeground", 1.173 + "ui.IMESelectedConvertedTextUnderline", 1.174 + "ui.SpellCheckerUnderline", 1.175 + "ui.activeborder", 1.176 + "ui.activecaption", 1.177 + "ui.appworkspace", 1.178 + "ui.background", 1.179 + "ui.buttonface", 1.180 + "ui.buttonhighlight", 1.181 + "ui.buttonshadow", 1.182 + "ui.buttontext", 1.183 + "ui.captiontext", 1.184 + "ui.graytext", 1.185 + "ui.highlight", 1.186 + "ui.highlighttext", 1.187 + "ui.inactiveborder", 1.188 + "ui.inactivecaption", 1.189 + "ui.inactivecaptiontext", 1.190 + "ui.infobackground", 1.191 + "ui.infotext", 1.192 + "ui.menu", 1.193 + "ui.menutext", 1.194 + "ui.scrollbar", 1.195 + "ui.threeddarkshadow", 1.196 + "ui.threedface", 1.197 + "ui.threedhighlight", 1.198 + "ui.threedlightshadow", 1.199 + "ui.threedshadow", 1.200 + "ui.window", 1.201 + "ui.windowframe", 1.202 + "ui.windowtext", 1.203 + "ui.-moz-buttondefault", 1.204 + "ui.-moz-field", 1.205 + "ui.-moz-fieldtext", 1.206 + "ui.-moz-dialog", 1.207 + "ui.-moz-dialogtext", 1.208 + "ui.-moz-dragtargetzone", 1.209 + "ui.-moz-cellhighlight", 1.210 + "ui.-moz_cellhighlighttext", 1.211 + "ui.-moz-html-cellhighlight", 1.212 + "ui.-moz-html-cellhighlighttext", 1.213 + "ui.-moz-buttonhoverface", 1.214 + "ui.-moz_buttonhovertext", 1.215 + "ui.-moz_menuhover", 1.216 + "ui.-moz_menuhovertext", 1.217 + "ui.-moz_menubartext", 1.218 + "ui.-moz_menubarhovertext", 1.219 + "ui.-moz_eventreerow", 1.220 + "ui.-moz_oddtreerow", 1.221 + "ui.-moz_mac_chrome_active", 1.222 + "ui.-moz_mac_chrome_inactive", 1.223 + "ui.-moz-mac-focusring", 1.224 + "ui.-moz-mac-menuselect", 1.225 + "ui.-moz-mac-menushadow", 1.226 + "ui.-moz-mac-menutextdisable", 1.227 + "ui.-moz-mac-menutextselect", 1.228 + "ui.-moz_mac_disabledtoolbartext", 1.229 + "ui.-moz-mac-secondaryhighlight", 1.230 + "ui.-moz-win-mediatext", 1.231 + "ui.-moz-win-communicationstext", 1.232 + "ui.-moz-nativehyperlinktext", 1.233 + "ui.-moz-comboboxtext", 1.234 + "ui.-moz-combobox" 1.235 +}; 1.236 + 1.237 +int32_t nsXPLookAndFeel::sCachedColors[LookAndFeel::eColorID_LAST_COLOR] = {0}; 1.238 +int32_t nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0}; 1.239 + 1.240 +bool nsXPLookAndFeel::sInitialized = false; 1.241 +bool nsXPLookAndFeel::sUseNativeColors = true; 1.242 + 1.243 +nsLookAndFeel* nsXPLookAndFeel::sInstance = nullptr; 1.244 +bool nsXPLookAndFeel::sShutdown = false; 1.245 + 1.246 +// static 1.247 +nsLookAndFeel* 1.248 +nsXPLookAndFeel::GetInstance() 1.249 +{ 1.250 + if (sInstance) { 1.251 + return sInstance; 1.252 + } 1.253 + 1.254 + NS_ENSURE_TRUE(!sShutdown, nullptr); 1.255 + 1.256 + sInstance = new nsLookAndFeel(); 1.257 + return sInstance; 1.258 +} 1.259 + 1.260 +// static 1.261 +void 1.262 +nsXPLookAndFeel::Shutdown() 1.263 +{ 1.264 + if (sShutdown) { 1.265 + return; 1.266 + } 1.267 + sShutdown = true; 1.268 + delete sInstance; 1.269 + sInstance = nullptr; 1.270 +} 1.271 + 1.272 +nsXPLookAndFeel::nsXPLookAndFeel() : LookAndFeel() 1.273 +{ 1.274 +} 1.275 + 1.276 +// static 1.277 +void 1.278 +nsXPLookAndFeel::IntPrefChanged(nsLookAndFeelIntPref *data) 1.279 +{ 1.280 + if (!data) { 1.281 + return; 1.282 + } 1.283 + 1.284 + int32_t intpref; 1.285 + nsresult rv = Preferences::GetInt(data->name, &intpref); 1.286 + if (NS_FAILED(rv)) { 1.287 + return; 1.288 + } 1.289 + data->intVar = intpref; 1.290 + data->isSet = true; 1.291 +#ifdef DEBUG_akkana 1.292 + printf("====== Changed int pref %s to %d\n", data->name, data->intVar); 1.293 +#endif 1.294 +} 1.295 + 1.296 +// static 1.297 +void 1.298 +nsXPLookAndFeel::FloatPrefChanged(nsLookAndFeelFloatPref *data) 1.299 +{ 1.300 + if (!data) { 1.301 + return; 1.302 + } 1.303 + 1.304 + int32_t intpref; 1.305 + nsresult rv = Preferences::GetInt(data->name, &intpref); 1.306 + if (NS_FAILED(rv)) { 1.307 + return; 1.308 + } 1.309 + data->floatVar = (float)intpref / 100.0f; 1.310 + data->isSet = true; 1.311 +#ifdef DEBUG_akkana 1.312 + printf("====== Changed float pref %s to %f\n", data->name, data->floatVar); 1.313 +#endif 1.314 +} 1.315 + 1.316 +// static 1.317 +void 1.318 +nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName) 1.319 +{ 1.320 + nsAutoString colorStr; 1.321 + nsresult rv = Preferences::GetString(prefName, &colorStr); 1.322 + if (NS_FAILED(rv)) { 1.323 + return; 1.324 + } 1.325 + if (!colorStr.IsEmpty()) { 1.326 + nscolor thecolor; 1.327 + if (colorStr[0] == char16_t('#')) { 1.328 + if (NS_HexToRGB(nsDependentString(colorStr, 1), &thecolor)) { 1.329 + int32_t id = NS_PTR_TO_INT32(index); 1.330 + CACHE_COLOR(id, thecolor); 1.331 + } 1.332 + } else if (NS_ColorNameToRGB(colorStr, &thecolor)) { 1.333 + int32_t id = NS_PTR_TO_INT32(index); 1.334 + CACHE_COLOR(id, thecolor); 1.335 +#ifdef DEBUG_akkana 1.336 + printf("====== Changed color pref %s to 0x%lx\n", 1.337 + prefName, thecolor); 1.338 +#endif 1.339 + } 1.340 + } else { 1.341 + // Reset to the default color, by clearing the cache 1.342 + // to force lookup when the color is next used 1.343 + int32_t id = NS_PTR_TO_INT32(index); 1.344 + CLEAR_COLOR_CACHE(id); 1.345 + } 1.346 +} 1.347 + 1.348 +void 1.349 +nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref) 1.350 +{ 1.351 + int32_t intpref; 1.352 + nsresult rv = Preferences::GetInt(aPref->name, &intpref); 1.353 + if (NS_SUCCEEDED(rv)) { 1.354 + aPref->isSet = true; 1.355 + aPref->intVar = intpref; 1.356 + } 1.357 +} 1.358 + 1.359 +void 1.360 +nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref) 1.361 +{ 1.362 + int32_t intpref; 1.363 + nsresult rv = Preferences::GetInt(aPref->name, &intpref); 1.364 + if (NS_SUCCEEDED(rv)) { 1.365 + aPref->isSet = true; 1.366 + aPref->floatVar = (float)intpref / 100.0f; 1.367 + } 1.368 +} 1.369 + 1.370 +void 1.371 +nsXPLookAndFeel::InitColorFromPref(int32_t i) 1.372 +{ 1.373 + nsAutoString colorStr; 1.374 + nsresult rv = Preferences::GetString(sColorPrefs[i], &colorStr); 1.375 + if (NS_FAILED(rv) || colorStr.IsEmpty()) { 1.376 + return; 1.377 + } 1.378 + nscolor thecolor; 1.379 + if (colorStr[0] == char16_t('#')) { 1.380 + nsAutoString hexString; 1.381 + colorStr.Right(hexString, colorStr.Length() - 1); 1.382 + if (NS_HexToRGB(hexString, &thecolor)) { 1.383 + CACHE_COLOR(i, thecolor); 1.384 + } 1.385 + } else if (NS_ColorNameToRGB(colorStr, &thecolor)) { 1.386 + CACHE_COLOR(i, thecolor); 1.387 + } 1.388 +} 1.389 + 1.390 +// static 1.391 +void 1.392 +nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure) 1.393 +{ 1.394 + 1.395 + // looping in the same order as in ::Init 1.396 + 1.397 + nsDependentCString prefName(aPref); 1.398 + unsigned int i; 1.399 + for (i = 0; i < ArrayLength(sIntPrefs); ++i) { 1.400 + if (prefName.Equals(sIntPrefs[i].name)) { 1.401 + IntPrefChanged(&sIntPrefs[i]); 1.402 + return; 1.403 + } 1.404 + } 1.405 + 1.406 + for (i = 0; i < ArrayLength(sFloatPrefs); ++i) { 1.407 + if (prefName.Equals(sFloatPrefs[i].name)) { 1.408 + FloatPrefChanged(&sFloatPrefs[i]); 1.409 + return; 1.410 + } 1.411 + } 1.412 + 1.413 + for (i = 0; i < ArrayLength(sColorPrefs); ++i) { 1.414 + if (prefName.Equals(sColorPrefs[i])) { 1.415 + ColorPrefChanged(i, sColorPrefs[i]); 1.416 + return; 1.417 + } 1.418 + } 1.419 +} 1.420 + 1.421 +// 1.422 +// Read values from the user's preferences. 1.423 +// This is done once at startup, but since the user's preferences 1.424 +// haven't actually been read yet at that time, we also have to 1.425 +// set a callback to inform us of changes to each pref. 1.426 +// 1.427 +void 1.428 +nsXPLookAndFeel::Init() 1.429 +{ 1.430 + // Say we're already initialized, and take the chance that it might fail; 1.431 + // protects against some other process writing to our static variables. 1.432 + sInitialized = true; 1.433 + 1.434 + // XXX If we could reorganize the pref names, we should separate the branch 1.435 + // for each types. Then, we could reduce the unnecessary loop from 1.436 + // nsXPLookAndFeel::OnPrefChanged(). 1.437 + Preferences::RegisterCallback(OnPrefChanged, "ui."); 1.438 + Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus"); 1.439 + 1.440 + unsigned int i; 1.441 + for (i = 0; i < ArrayLength(sIntPrefs); ++i) { 1.442 + InitFromPref(&sIntPrefs[i]); 1.443 + } 1.444 + 1.445 + for (i = 0; i < ArrayLength(sFloatPrefs); ++i) { 1.446 + InitFromPref(&sFloatPrefs[i]); 1.447 + } 1.448 + 1.449 + for (i = 0; i < ArrayLength(sColorPrefs); ++i) { 1.450 + InitColorFromPref(i); 1.451 + } 1.452 + 1.453 + bool val; 1.454 + if (NS_SUCCEEDED(Preferences::GetBool("ui.use_native_colors", &val))) { 1.455 + sUseNativeColors = val; 1.456 + } 1.457 +} 1.458 + 1.459 +nsXPLookAndFeel::~nsXPLookAndFeel() 1.460 +{ 1.461 + NS_ASSERTION(sInstance == this, 1.462 + "This destroying instance isn't the singleton instance"); 1.463 + sInstance = nullptr; 1.464 +} 1.465 + 1.466 +bool 1.467 +nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor) 1.468 +{ 1.469 + switch (aID) { 1.470 + case eColorID_TextSelectForeground: 1.471 + return (aColor == NS_DONT_CHANGE_COLOR); 1.472 + case eColorID_IMESelectedRawTextBackground: 1.473 + case eColorID_IMESelectedConvertedTextBackground: 1.474 + case eColorID_IMERawInputBackground: 1.475 + case eColorID_IMEConvertedTextBackground: 1.476 + case eColorID_IMESelectedRawTextForeground: 1.477 + case eColorID_IMESelectedConvertedTextForeground: 1.478 + case eColorID_IMERawInputForeground: 1.479 + case eColorID_IMEConvertedTextForeground: 1.480 + case eColorID_IMERawInputUnderline: 1.481 + case eColorID_IMEConvertedTextUnderline: 1.482 + case eColorID_IMESelectedRawTextUnderline: 1.483 + case eColorID_IMESelectedConvertedTextUnderline: 1.484 + case eColorID_SpellCheckerUnderline: 1.485 + return NS_IS_SELECTION_SPECIAL_COLOR(aColor); 1.486 + default: 1.487 + /* 1.488 + * In GetColor(), every color that is not a special color is color 1.489 + * corrected. Use false to make other colors color corrected. 1.490 + */ 1.491 + return false; 1.492 + } 1.493 + return false; 1.494 +} 1.495 + 1.496 +bool 1.497 +nsXPLookAndFeel::ColorIsNotCSSAccessible(ColorID aID) 1.498 +{ 1.499 + bool result = false; 1.500 + 1.501 + switch (aID) { 1.502 + case eColorID_WindowBackground: 1.503 + case eColorID_WindowForeground: 1.504 + case eColorID_WidgetBackground: 1.505 + case eColorID_WidgetForeground: 1.506 + case eColorID_WidgetSelectBackground: 1.507 + case eColorID_WidgetSelectForeground: 1.508 + case eColorID_Widget3DHighlight: 1.509 + case eColorID_Widget3DShadow: 1.510 + case eColorID_TextBackground: 1.511 + case eColorID_TextForeground: 1.512 + case eColorID_TextSelectBackground: 1.513 + case eColorID_TextSelectForeground: 1.514 + case eColorID_TextSelectBackgroundDisabled: 1.515 + case eColorID_TextSelectBackgroundAttention: 1.516 + case eColorID_TextHighlightBackground: 1.517 + case eColorID_TextHighlightForeground: 1.518 + case eColorID_IMERawInputBackground: 1.519 + case eColorID_IMERawInputForeground: 1.520 + case eColorID_IMERawInputUnderline: 1.521 + case eColorID_IMESelectedRawTextBackground: 1.522 + case eColorID_IMESelectedRawTextForeground: 1.523 + case eColorID_IMESelectedRawTextUnderline: 1.524 + case eColorID_IMEConvertedTextBackground: 1.525 + case eColorID_IMEConvertedTextForeground: 1.526 + case eColorID_IMEConvertedTextUnderline: 1.527 + case eColorID_IMESelectedConvertedTextBackground: 1.528 + case eColorID_IMESelectedConvertedTextForeground: 1.529 + case eColorID_IMESelectedConvertedTextUnderline: 1.530 + case eColorID_SpellCheckerUnderline: 1.531 + result = true; 1.532 + break; 1.533 + default: 1.534 + break; 1.535 + } 1.536 + 1.537 + return result; 1.538 +} 1.539 + 1.540 +nscolor 1.541 +nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID) 1.542 +{ 1.543 + nscolor result = NS_RGB(0xFF, 0xFF, 0xFF); 1.544 + 1.545 + // The stand-in colors are taken from the Windows 7 Aero theme 1.546 + // except Mac-specific colors which are taken from Mac OS 10.7. 1.547 + switch (aID) { 1.548 + // CSS 2 colors: 1.549 + case eColorID_activeborder: result = NS_RGB(0xB4, 0xB4, 0xB4); break; 1.550 + case eColorID_activecaption: result = NS_RGB(0x99, 0xB4, 0xD1); break; 1.551 + case eColorID_appworkspace: result = NS_RGB(0xAB, 0xAB, 0xAB); break; 1.552 + case eColorID_background: result = NS_RGB(0x00, 0x00, 0x00); break; 1.553 + case eColorID_buttonface: result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.554 + case eColorID_buttonhighlight: result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.555 + case eColorID_buttonshadow: result = NS_RGB(0xA0, 0xA0, 0xA0); break; 1.556 + case eColorID_buttontext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.557 + case eColorID_captiontext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.558 + case eColorID_graytext: result = NS_RGB(0x6D, 0x6D, 0x6D); break; 1.559 + case eColorID_highlight: result = NS_RGB(0x33, 0x99, 0xFF); break; 1.560 + case eColorID_highlighttext: result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.561 + case eColorID_inactiveborder: result = NS_RGB(0xF4, 0xF7, 0xFC); break; 1.562 + case eColorID_inactivecaption: result = NS_RGB(0xBF, 0xCD, 0xDB); break; 1.563 + case eColorID_inactivecaptiontext: 1.564 + result = NS_RGB(0x43, 0x4E, 0x54); break; 1.565 + case eColorID_infobackground: result = NS_RGB(0xFF, 0xFF, 0xE1); break; 1.566 + case eColorID_infotext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.567 + case eColorID_menu: result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.568 + case eColorID_menutext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.569 + case eColorID_scrollbar: result = NS_RGB(0xC8, 0xC8, 0xC8); break; 1.570 + case eColorID_threeddarkshadow: result = NS_RGB(0x69, 0x69, 0x69); break; 1.571 + case eColorID_threedface: result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.572 + case eColorID_threedhighlight: result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.573 + case eColorID_threedlightshadow: result = NS_RGB(0xE3, 0xE3, 0xE3); break; 1.574 + case eColorID_threedshadow: result = NS_RGB(0xA0, 0xA0, 0xA0); break; 1.575 + case eColorID_window: result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.576 + case eColorID_windowframe: result = NS_RGB(0x64, 0x64, 0x64); break; 1.577 + case eColorID_windowtext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.578 + case eColorID__moz_buttondefault: 1.579 + result = NS_RGB(0x69, 0x69, 0x69); break; 1.580 + case eColorID__moz_field: result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.581 + case eColorID__moz_fieldtext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.582 + case eColorID__moz_dialog: result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.583 + case eColorID__moz_dialogtext: result = NS_RGB(0x00, 0x00, 0x00); break; 1.584 + case eColorID__moz_dragtargetzone: 1.585 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.586 + case eColorID__moz_cellhighlight: 1.587 + result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.588 + case eColorID__moz_cellhighlighttext: 1.589 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.590 + case eColorID__moz_html_cellhighlight: 1.591 + result = NS_RGB(0x33, 0x99, 0xFF); break; 1.592 + case eColorID__moz_html_cellhighlighttext: 1.593 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.594 + case eColorID__moz_buttonhoverface: 1.595 + result = NS_RGB(0xF0, 0xF0, 0xF0); break; 1.596 + case eColorID__moz_buttonhovertext: 1.597 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.598 + case eColorID__moz_menuhover: 1.599 + result = NS_RGB(0x33, 0x99, 0xFF); break; 1.600 + case eColorID__moz_menuhovertext: 1.601 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.602 + case eColorID__moz_menubartext: 1.603 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.604 + case eColorID__moz_menubarhovertext: 1.605 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.606 + case eColorID__moz_oddtreerow: 1.607 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.608 + case eColorID__moz_mac_chrome_active: 1.609 + result = NS_RGB(0xB2, 0xB2, 0xB2); break; 1.610 + case eColorID__moz_mac_chrome_inactive: 1.611 + result = NS_RGB(0xE1, 0xE1, 0xE1); break; 1.612 + case eColorID__moz_mac_focusring: 1.613 + result = NS_RGB(0x60, 0x9D, 0xD7); break; 1.614 + case eColorID__moz_mac_menuselect: 1.615 + result = NS_RGB(0x38, 0x75, 0xD7); break; 1.616 + case eColorID__moz_mac_menushadow: 1.617 + result = NS_RGB(0xA3, 0xA3, 0xA3); break; 1.618 + case eColorID__moz_mac_menutextdisable: 1.619 + result = NS_RGB(0x88, 0x88, 0x88); break; 1.620 + case eColorID__moz_mac_menutextselect: 1.621 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.622 + case eColorID__moz_mac_disabledtoolbartext: 1.623 + result = NS_RGB(0x3F, 0x3F, 0x3F); break; 1.624 + case eColorID__moz_mac_secondaryhighlight: 1.625 + result = NS_RGB(0xD4, 0xD4, 0xD4); break; 1.626 + case eColorID__moz_win_mediatext: 1.627 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.628 + case eColorID__moz_win_communicationstext: 1.629 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.630 + case eColorID__moz_nativehyperlinktext: 1.631 + result = NS_RGB(0x00, 0x66, 0xCC); break; 1.632 + case eColorID__moz_comboboxtext: 1.633 + result = NS_RGB(0x00, 0x00, 0x00); break; 1.634 + case eColorID__moz_combobox: 1.635 + result = NS_RGB(0xFF, 0xFF, 0xFF); break; 1.636 + default: 1.637 + break; 1.638 + } 1.639 + 1.640 + return result; 1.641 +} 1.642 + 1.643 +// 1.644 +// All these routines will return NS_OK if they have a value, 1.645 +// in which case the nsLookAndFeel should use that value; 1.646 +// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the 1.647 +// platform-specific nsLookAndFeel should use its own values instead. 1.648 +// 1.649 +nsresult 1.650 +nsXPLookAndFeel::GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors, 1.651 + nscolor &aResult) 1.652 +{ 1.653 + if (!sInitialized) 1.654 + Init(); 1.655 + 1.656 + // define DEBUG_SYSTEM_COLOR_USE if you want to debug system color 1.657 + // use in a skin that uses them. When set, it will make all system 1.658 + // color pairs that are appropriate for foreground/background 1.659 + // pairing the same. This means if the skin is using system colors 1.660 + // correctly you will not be able to see *any* text. 1.661 +#undef DEBUG_SYSTEM_COLOR_USE 1.662 + 1.663 +#ifdef DEBUG_SYSTEM_COLOR_USE 1.664 + { 1.665 + nsresult rv = NS_OK; 1.666 + switch (aID) { 1.667 + // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors 1.668 + case eColorID_activecaption: 1.669 + // active window caption background 1.670 + case eColorID_captiontext: 1.671 + // text in active window caption 1.672 + aResult = NS_RGB(0xff, 0x00, 0x00); 1.673 + break; 1.674 + 1.675 + case eColorID_highlight: 1.676 + // background of selected item 1.677 + case eColorID_highlighttext: 1.678 + // text of selected item 1.679 + aResult = NS_RGB(0xff, 0xff, 0x00); 1.680 + break; 1.681 + 1.682 + case eColorID_inactivecaption: 1.683 + // inactive window caption 1.684 + case eColorID_inactivecaptiontext: 1.685 + // text in inactive window caption 1.686 + aResult = NS_RGB(0x66, 0x66, 0x00); 1.687 + break; 1.688 + 1.689 + case eColorID_infobackground: 1.690 + // tooltip background color 1.691 + case eColorID_infotext: 1.692 + // tooltip text color 1.693 + aResult = NS_RGB(0x00, 0xff, 0x00); 1.694 + break; 1.695 + 1.696 + case eColorID_menu: 1.697 + // menu background 1.698 + case eColorID_menutext: 1.699 + // menu text 1.700 + aResult = NS_RGB(0x00, 0xff, 0xff); 1.701 + break; 1.702 + 1.703 + case eColorID_threedface: 1.704 + case eColorID_buttonface: 1.705 + // 3-D face color 1.706 + case eColorID_buttontext: 1.707 + // text on push buttons 1.708 + aResult = NS_RGB(0x00, 0x66, 0x66); 1.709 + break; 1.710 + 1.711 + case eColorID_window: 1.712 + case eColorID_windowtext: 1.713 + aResult = NS_RGB(0x00, 0x00, 0xff); 1.714 + break; 1.715 + 1.716 + // from the CSS3 working draft (not yet finalized) 1.717 + // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color 1.718 + 1.719 + case eColorID__moz_field: 1.720 + case eColorID__moz_fieldtext: 1.721 + aResult = NS_RGB(0xff, 0x00, 0xff); 1.722 + break; 1.723 + 1.724 + case eColorID__moz_dialog: 1.725 + case eColorID__moz_dialogtext: 1.726 + aResult = NS_RGB(0x66, 0x00, 0x66); 1.727 + break; 1.728 + 1.729 + default: 1.730 + rv = NS_ERROR_NOT_AVAILABLE; 1.731 + } 1.732 + if (NS_SUCCEEDED(rv)) 1.733 + return rv; 1.734 + } 1.735 +#endif // DEBUG_SYSTEM_COLOR_USE 1.736 + 1.737 + if (aUseStandinsForNativeColors && ColorIsNotCSSAccessible(aID)) 1.738 + aUseStandinsForNativeColors = false; 1.739 + 1.740 + if (!aUseStandinsForNativeColors && IS_COLOR_CACHED(aID)) { 1.741 + aResult = sCachedColors[aID]; 1.742 + return NS_OK; 1.743 + } 1.744 + 1.745 + // There are no system color settings for these, so set them manually 1.746 + if (aID == eColorID_TextSelectBackgroundDisabled) { 1.747 + // This is used to gray out the selection when it's not focused 1.748 + // Used with nsISelectionController::SELECTION_DISABLED 1.749 + aResult = NS_RGB(0xb0, 0xb0, 0xb0); 1.750 + return NS_OK; 1.751 + } 1.752 + 1.753 + if (aID == eColorID_TextSelectBackgroundAttention) { 1.754 + // This makes the selection stand out when typeaheadfind is on 1.755 + // Used with nsISelectionController::SELECTION_ATTENTION 1.756 + aResult = NS_RGB(0x38, 0xd8, 0x78); 1.757 + return NS_OK; 1.758 + } 1.759 + 1.760 + if (aID == eColorID_TextHighlightBackground) { 1.761 + // This makes the matched text stand out when findbar highlighting is on 1.762 + // Used with nsISelectionController::SELECTION_FIND 1.763 + aResult = NS_RGB(0xef, 0x0f, 0xff); 1.764 + return NS_OK; 1.765 + } 1.766 + 1.767 + if (aID == eColorID_TextHighlightForeground) { 1.768 + // The foreground color for the matched text in findbar highlighting 1.769 + // Used with nsISelectionController::SELECTION_FIND 1.770 + aResult = NS_RGB(0xff, 0xff, 0xff); 1.771 + return NS_OK; 1.772 + } 1.773 + 1.774 + if (sUseNativeColors && aUseStandinsForNativeColors) 1.775 + { 1.776 + aResult = GetStandinForNativeColor(aID); 1.777 + return NS_OK; 1.778 + } 1.779 + 1.780 + if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aResult))) { 1.781 + if ((gfxPlatform::GetCMSMode() == eCMSMode_All) && 1.782 + !IsSpecialColor(aID, aResult)) { 1.783 + qcms_transform *transform = gfxPlatform::GetCMSInverseRGBTransform(); 1.784 + if (transform) { 1.785 + uint8_t color[3]; 1.786 + color[0] = NS_GET_R(aResult); 1.787 + color[1] = NS_GET_G(aResult); 1.788 + color[2] = NS_GET_B(aResult); 1.789 + qcms_transform_data(transform, color, color, 1); 1.790 + aResult = NS_RGB(color[0], color[1], color[2]); 1.791 + } 1.792 + } 1.793 + 1.794 + CACHE_COLOR(aID, aResult); 1.795 + return NS_OK; 1.796 + } 1.797 + 1.798 + return NS_ERROR_NOT_AVAILABLE; 1.799 +} 1.800 + 1.801 +nsresult 1.802 +nsXPLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) 1.803 +{ 1.804 + if (!sInitialized) 1.805 + Init(); 1.806 + 1.807 + // Set the default values for these prefs. but allow different platforms 1.808 + // to override them in their nsLookAndFeel if desired. 1.809 + switch (aID) { 1.810 + case eIntID_ScrollButtonLeftMouseButtonAction: 1.811 + aResult = 0; 1.812 + return NS_OK; 1.813 + case eIntID_ScrollButtonMiddleMouseButtonAction: 1.814 + aResult = 3; 1.815 + return NS_OK; 1.816 + case eIntID_ScrollButtonRightMouseButtonAction: 1.817 + aResult = 3; 1.818 + return NS_OK; 1.819 + default: 1.820 + /* 1.821 + * The metrics above are hardcoded platform defaults. All the other 1.822 + * metrics are stored in sIntPrefs and can be changed at runtime. 1.823 + */ 1.824 + break; 1.825 + } 1.826 + 1.827 + for (unsigned int i = 0; i < ArrayLength(sIntPrefs); ++i) { 1.828 + if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID)) { 1.829 + aResult = sIntPrefs[i].intVar; 1.830 + return NS_OK; 1.831 + } 1.832 + } 1.833 + 1.834 + return NS_ERROR_NOT_AVAILABLE; 1.835 +} 1.836 + 1.837 +nsresult 1.838 +nsXPLookAndFeel::GetFloatImpl(FloatID aID, float &aResult) 1.839 +{ 1.840 + if (!sInitialized) 1.841 + Init(); 1.842 + 1.843 + for (unsigned int i = 0; i < ArrayLength(sFloatPrefs); ++i) { 1.844 + if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID) { 1.845 + aResult = sFloatPrefs[i].floatVar; 1.846 + return NS_OK; 1.847 + } 1.848 + } 1.849 + 1.850 + return NS_ERROR_NOT_AVAILABLE; 1.851 +} 1.852 + 1.853 +void 1.854 +nsXPLookAndFeel::RefreshImpl() 1.855 +{ 1.856 + // Wipe out our color cache. 1.857 + uint32_t i; 1.858 + for (i = 0; i < eColorID_LAST_COLOR; i++) 1.859 + sCachedColors[i] = 0; 1.860 + for (i = 0; i < COLOR_CACHE_SIZE; i++) 1.861 + sCachedColorBits[i] = 0; 1.862 +} 1.863 + 1.864 +namespace mozilla { 1.865 + 1.866 +// static 1.867 +nsresult 1.868 +LookAndFeel::GetColor(ColorID aID, nscolor* aResult) 1.869 +{ 1.870 + return nsLookAndFeel::GetInstance()->GetColorImpl(aID, false, *aResult); 1.871 +} 1.872 + 1.873 +nsresult 1.874 +LookAndFeel::GetColor(ColorID aID, bool aUseStandinsForNativeColors, 1.875 + nscolor* aResult) 1.876 +{ 1.877 + return nsLookAndFeel::GetInstance()->GetColorImpl(aID, 1.878 + aUseStandinsForNativeColors, *aResult); 1.879 +} 1.880 + 1.881 +// static 1.882 +nsresult 1.883 +LookAndFeel::GetColorForNativeAppearance(uint8_t aWidgetType, bool aIsDisabled, 1.884 + nscolor* aResult) 1.885 +{ 1.886 + NS_ENSURE_ARG_POINTER(aResult); 1.887 + 1.888 + ColorID colorID = eColorID_LAST_COLOR; 1.889 + switch (aWidgetType) { 1.890 + case NS_THEME_TEXTFIELD: 1.891 + case NS_THEME_TEXTFIELD_MULTILINE: 1.892 + case NS_THEME_LISTBOX: 1.893 + case NS_THEME_DROPDOWN: 1.894 + case NS_THEME_DROPDOWN_TEXTFIELD: 1.895 + case NS_THEME_TREEVIEW: 1.896 + colorID = (aIsDisabled) ? eColorID_graytext : eColorID__moz_fieldtext; 1.897 + break; 1.898 + 1.899 + case NS_THEME_TOOLTIP: 1.900 + colorID = eColorID_infotext; 1.901 + break; 1.902 + 1.903 + case NS_THEME_BUTTON: 1.904 + case NS_THEME_GROUPBOX: 1.905 + case NS_THEME_PROGRESSBAR: 1.906 + case NS_THEME_PROGRESSBAR_VERTICAL: 1.907 + case NS_THEME_TAB_PANEL: 1.908 + case NS_THEME_STATUSBAR: 1.909 + case NS_THEME_STATUSBAR_RESIZER_PANEL: 1.910 + colorID = (aIsDisabled) ? eColorID_graytext : eColorID_buttontext; 1.911 + break; 1.912 + } 1.913 + 1.914 + if (LookAndFeel::eColorID_LAST_COLOR == colorID) 1.915 + return NS_ERROR_FAILURE; 1.916 + 1.917 + *aResult = NS_RGB(0, 0, 0); 1.918 + return nsLookAndFeel::GetInstance()->NativeGetColor(colorID, *aResult); 1.919 +} 1.920 + 1.921 +// static 1.922 +nsresult 1.923 +LookAndFeel::GetInt(IntID aID, int32_t* aResult) 1.924 +{ 1.925 + return nsLookAndFeel::GetInstance()->GetIntImpl(aID, *aResult); 1.926 +} 1.927 + 1.928 +// static 1.929 +nsresult 1.930 +LookAndFeel::GetFloat(FloatID aID, float* aResult) 1.931 +{ 1.932 + return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult); 1.933 +} 1.934 + 1.935 +// static 1.936 +bool 1.937 +LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle, 1.938 + float aDevPixPerCSSPixel) 1.939 +{ 1.940 + return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle, 1.941 + aDevPixPerCSSPixel); 1.942 +} 1.943 + 1.944 +// static 1.945 +char16_t 1.946 +LookAndFeel::GetPasswordCharacter() 1.947 +{ 1.948 + return nsLookAndFeel::GetInstance()->GetPasswordCharacterImpl(); 1.949 +} 1.950 + 1.951 +// static 1.952 +bool 1.953 +LookAndFeel::GetEchoPassword() 1.954 +{ 1.955 + return nsLookAndFeel::GetInstance()->GetEchoPasswordImpl(); 1.956 +} 1.957 + 1.958 +// static 1.959 +uint32_t 1.960 +LookAndFeel::GetPasswordMaskDelay() 1.961 +{ 1.962 + return nsLookAndFeel::GetInstance()->GetPasswordMaskDelayImpl(); 1.963 +} 1.964 + 1.965 +// static 1.966 +void 1.967 +LookAndFeel::Refresh() 1.968 +{ 1.969 + nsLookAndFeel::GetInstance()->RefreshImpl(); 1.970 +} 1.971 + 1.972 +} // namespace mozilla