nsXPLookAndFeel.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/ArrayUtils.h"
  6. #include "nscore.h"
  7. #include "nsXPLookAndFeel.h"
  8. #include "nsLookAndFeel.h"
  9. #include "nsCRT.h"
  10. #include "nsFont.h"
  11. #include "mozilla/dom/ContentChild.h"
  12. #include "mozilla/Preferences.h"
  13. #include "mozilla/gfx/2D.h"
  14. #include "mozilla/widget/WidgetMessageUtils.h"
  15. #include "gfxPlatform.h"
  16. #include "qcms.h"
  17. #ifdef DEBUG
  18. #include "nsSize.h"
  19. #endif
  20. using namespace mozilla;
  21. nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
  22. {
  23. { "ui.caretBlinkTime",
  24. eIntID_CaretBlinkTime,
  25. false, 0 },
  26. { "ui.caretWidth",
  27. eIntID_CaretWidth,
  28. false, 0 },
  29. { "ui.caretVisibleWithSelection",
  30. eIntID_ShowCaretDuringSelection,
  31. false, 0 },
  32. { "ui.submenuDelay",
  33. eIntID_SubmenuDelay,
  34. false, 0 },
  35. { "ui.dragThresholdX",
  36. eIntID_DragThresholdX,
  37. false, 0 },
  38. { "ui.dragThresholdY",
  39. eIntID_DragThresholdY,
  40. false, 0 },
  41. { "ui.useAccessibilityTheme",
  42. eIntID_UseAccessibilityTheme,
  43. false, 0 },
  44. { "ui.menusCanOverlapOSBar",
  45. eIntID_MenusCanOverlapOSBar,
  46. false, 0 },
  47. { "ui.useOverlayScrollbars",
  48. eIntID_UseOverlayScrollbars,
  49. false, 0 },
  50. { "ui.scrollbarDisplayOnMouseMove",
  51. eIntID_ScrollbarDisplayOnMouseMove,
  52. false, 0 },
  53. { "ui.scrollbarFadeBeginDelay",
  54. eIntID_ScrollbarFadeBeginDelay,
  55. false, 0 },
  56. { "ui.scrollbarFadeDuration",
  57. eIntID_ScrollbarFadeDuration,
  58. false, 0 },
  59. { "ui.showHideScrollbars",
  60. eIntID_ShowHideScrollbars,
  61. false, 0 },
  62. { "ui.skipNavigatingDisabledMenuItem",
  63. eIntID_SkipNavigatingDisabledMenuItem,
  64. false, 0 },
  65. { "ui.treeOpenDelay",
  66. eIntID_TreeOpenDelay,
  67. false, 0 },
  68. { "ui.treeCloseDelay",
  69. eIntID_TreeCloseDelay,
  70. false, 0 },
  71. { "ui.treeLazyScrollDelay",
  72. eIntID_TreeLazyScrollDelay,
  73. false, 0 },
  74. { "ui.treeScrollDelay",
  75. eIntID_TreeScrollDelay,
  76. false, 0 },
  77. { "ui.treeScrollLinesMax",
  78. eIntID_TreeScrollLinesMax,
  79. false, 0 },
  80. { "accessibility.tabfocus",
  81. eIntID_TabFocusModel,
  82. false, 0 },
  83. { "ui.alertNotificationOrigin",
  84. eIntID_AlertNotificationOrigin,
  85. false, 0 },
  86. { "ui.scrollToClick",
  87. eIntID_ScrollToClick,
  88. false, 0 },
  89. { "ui.IMERawInputUnderlineStyle",
  90. eIntID_IMERawInputUnderlineStyle,
  91. false, 0 },
  92. { "ui.IMESelectedRawTextUnderlineStyle",
  93. eIntID_IMESelectedRawTextUnderlineStyle,
  94. false, 0 },
  95. { "ui.IMEConvertedTextUnderlineStyle",
  96. eIntID_IMEConvertedTextUnderlineStyle,
  97. false, 0 },
  98. { "ui.IMESelectedConvertedTextUnderlineStyle",
  99. eIntID_IMESelectedConvertedTextUnderline,
  100. false, 0 },
  101. { "ui.SpellCheckerUnderlineStyle",
  102. eIntID_SpellCheckerUnderlineStyle,
  103. false, 0 },
  104. { "ui.scrollbarButtonAutoRepeatBehavior",
  105. eIntID_ScrollbarButtonAutoRepeatBehavior,
  106. false, 0 },
  107. { "ui.tooltipDelay",
  108. eIntID_TooltipDelay,
  109. false, 0 },
  110. { "ui.physicalHomeButton",
  111. eIntID_PhysicalHomeButton,
  112. false, 0 },
  113. { "ui.contextMenuOffsetVertical",
  114. eIntID_ContextMenuOffsetVertical,
  115. false, 0 },
  116. { "ui.contextMenuOffsetHorizontal",
  117. eIntID_ContextMenuOffsetHorizontal,
  118. false, 0 }
  119. };
  120. nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] =
  121. {
  122. { "ui.IMEUnderlineRelativeSize",
  123. eFloatID_IMEUnderlineRelativeSize,
  124. false, 0 },
  125. { "ui.SpellCheckerUnderlineRelativeSize",
  126. eFloatID_SpellCheckerUnderlineRelativeSize,
  127. false, 0 },
  128. { "ui.caretAspectRatio",
  129. eFloatID_CaretAspectRatio,
  130. false, 0 },
  131. };
  132. // This array MUST be kept in the same order as the color list in LookAndFeel.h.
  133. /* XXX If you add any strings longer than
  134. * "ui.IMESelectedConvertedTextBackground"
  135. * to the following array then you MUST update the
  136. * sizes of the sColorPrefs array in nsXPLookAndFeel.h
  137. */
  138. const char nsXPLookAndFeel::sColorPrefs[][38] =
  139. {
  140. "ui.windowBackground",
  141. "ui.windowForeground",
  142. "ui.widgetBackground",
  143. "ui.widgetForeground",
  144. "ui.widgetSelectBackground",
  145. "ui.widgetSelectForeground",
  146. "ui.widget3DHighlight",
  147. "ui.widget3DShadow",
  148. "ui.textBackground",
  149. "ui.textForeground",
  150. "ui.textSelectBackground",
  151. "ui.textSelectForeground",
  152. "ui.textSelectForegroundCustom",
  153. "ui.textSelectBackgroundDisabled",
  154. "ui.textSelectBackgroundAttention",
  155. "ui.textHighlightBackground",
  156. "ui.textHighlightForeground",
  157. "ui.IMERawInputBackground",
  158. "ui.IMERawInputForeground",
  159. "ui.IMERawInputUnderline",
  160. "ui.IMESelectedRawTextBackground",
  161. "ui.IMESelectedRawTextForeground",
  162. "ui.IMESelectedRawTextUnderline",
  163. "ui.IMEConvertedTextBackground",
  164. "ui.IMEConvertedTextForeground",
  165. "ui.IMEConvertedTextUnderline",
  166. "ui.IMESelectedConvertedTextBackground",
  167. "ui.IMESelectedConvertedTextForeground",
  168. "ui.IMESelectedConvertedTextUnderline",
  169. "ui.SpellCheckerUnderline",
  170. "ui.activeborder",
  171. "ui.activecaption",
  172. "ui.appworkspace",
  173. "ui.background",
  174. "ui.buttonface",
  175. "ui.buttonhighlight",
  176. "ui.buttonshadow",
  177. "ui.buttontext",
  178. "ui.captiontext",
  179. "ui.graytext",
  180. "ui.highlight",
  181. "ui.highlighttext",
  182. "ui.inactiveborder",
  183. "ui.inactivecaption",
  184. "ui.inactivecaptiontext",
  185. "ui.infobackground",
  186. "ui.infotext",
  187. "ui.menu",
  188. "ui.menutext",
  189. "ui.scrollbar",
  190. "ui.threeddarkshadow",
  191. "ui.threedface",
  192. "ui.threedhighlight",
  193. "ui.threedlightshadow",
  194. "ui.threedshadow",
  195. "ui.window",
  196. "ui.windowframe",
  197. "ui.windowtext",
  198. "ui.-moz-buttondefault",
  199. "ui.-moz-field",
  200. "ui.-moz-fieldtext",
  201. "ui.-moz-dialog",
  202. "ui.-moz-dialogtext",
  203. "ui.-moz-dragtargetzone",
  204. "ui.-moz-cellhighlight",
  205. "ui.-moz_cellhighlighttext",
  206. "ui.-moz-html-cellhighlight",
  207. "ui.-moz-html-cellhighlighttext",
  208. "ui.-moz-buttonhoverface",
  209. "ui.-moz_buttonhovertext",
  210. "ui.-moz_menuhover",
  211. "ui.-moz_menuhovertext",
  212. "ui.-moz_menubartext",
  213. "ui.-moz_menubarhovertext",
  214. "ui.-moz_eventreerow",
  215. "ui.-moz_oddtreerow",
  216. "ui.-moz-mac-buttonactivetext",
  217. "ui.-moz_mac_chrome_active",
  218. "ui.-moz_mac_chrome_inactive",
  219. "ui.-moz-mac-defaultbuttontext",
  220. "ui.-moz-mac-focusring",
  221. "ui.-moz-mac-menuselect",
  222. "ui.-moz-mac-menushadow",
  223. "ui.-moz-mac-menutextdisable",
  224. "ui.-moz-mac-menutextselect",
  225. "ui.-moz_mac_disabledtoolbartext",
  226. "ui.-moz-mac-secondaryhighlight",
  227. "ui.-moz-win-mediatext",
  228. "ui.-moz-win-communicationstext",
  229. "ui.-moz-nativehyperlinktext",
  230. "ui.-moz-comboboxtext",
  231. "ui.-moz-combobox"
  232. };
  233. int32_t nsXPLookAndFeel::sCachedColors[LookAndFeel::eColorID_LAST_COLOR] = {0};
  234. int32_t nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
  235. bool nsXPLookAndFeel::sInitialized = false;
  236. bool nsXPLookAndFeel::sUseNativeColors = true;
  237. bool nsXPLookAndFeel::sUseStandinsForNativeColors = false;
  238. bool nsXPLookAndFeel::sFindbarModalHighlight = false;
  239. nsLookAndFeel* nsXPLookAndFeel::sInstance = nullptr;
  240. bool nsXPLookAndFeel::sShutdown = false;
  241. // static
  242. nsLookAndFeel*
  243. nsXPLookAndFeel::GetInstance()
  244. {
  245. if (sInstance) {
  246. return sInstance;
  247. }
  248. NS_ENSURE_TRUE(!sShutdown, nullptr);
  249. sInstance = new nsLookAndFeel();
  250. return sInstance;
  251. }
  252. // static
  253. void
  254. nsXPLookAndFeel::Shutdown()
  255. {
  256. if (sShutdown) {
  257. return;
  258. }
  259. sShutdown = true;
  260. delete sInstance;
  261. sInstance = nullptr;
  262. }
  263. nsXPLookAndFeel::nsXPLookAndFeel() : LookAndFeel()
  264. {
  265. }
  266. // static
  267. void
  268. nsXPLookAndFeel::IntPrefChanged(nsLookAndFeelIntPref *data)
  269. {
  270. if (!data) {
  271. return;
  272. }
  273. int32_t intpref;
  274. nsresult rv = Preferences::GetInt(data->name, &intpref);
  275. if (NS_FAILED(rv)) {
  276. return;
  277. }
  278. data->intVar = intpref;
  279. data->isSet = true;
  280. #ifdef DEBUG_akkana
  281. printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
  282. #endif
  283. }
  284. // static
  285. void
  286. nsXPLookAndFeel::FloatPrefChanged(nsLookAndFeelFloatPref *data)
  287. {
  288. if (!data) {
  289. return;
  290. }
  291. int32_t intpref;
  292. nsresult rv = Preferences::GetInt(data->name, &intpref);
  293. if (NS_FAILED(rv)) {
  294. return;
  295. }
  296. data->floatVar = (float)intpref / 100.0f;
  297. data->isSet = true;
  298. #ifdef DEBUG_akkana
  299. printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
  300. #endif
  301. }
  302. // static
  303. void
  304. nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
  305. {
  306. nsAutoString colorStr;
  307. nsresult rv = Preferences::GetString(prefName, &colorStr);
  308. if (NS_FAILED(rv)) {
  309. return;
  310. }
  311. if (!colorStr.IsEmpty()) {
  312. nscolor thecolor;
  313. if (colorStr[0] == char16_t('#')) {
  314. if (NS_HexToRGBA(nsDependentString(colorStr, 1),
  315. nsHexColorType::NoAlpha, &thecolor)) {
  316. int32_t id = NS_PTR_TO_INT32(index);
  317. CACHE_COLOR(id, thecolor);
  318. }
  319. } else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
  320. int32_t id = NS_PTR_TO_INT32(index);
  321. CACHE_COLOR(id, thecolor);
  322. #ifdef DEBUG_akkana
  323. printf("====== Changed color pref %s to 0x%lx\n",
  324. prefName, thecolor);
  325. #endif
  326. }
  327. } else {
  328. // Reset to the default color, by clearing the cache
  329. // to force lookup when the color is next used
  330. int32_t id = NS_PTR_TO_INT32(index);
  331. CLEAR_COLOR_CACHE(id);
  332. }
  333. }
  334. void
  335. nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref)
  336. {
  337. int32_t intpref;
  338. nsresult rv = Preferences::GetInt(aPref->name, &intpref);
  339. if (NS_SUCCEEDED(rv)) {
  340. aPref->isSet = true;
  341. aPref->intVar = intpref;
  342. }
  343. }
  344. void
  345. nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref)
  346. {
  347. int32_t intpref;
  348. nsresult rv = Preferences::GetInt(aPref->name, &intpref);
  349. if (NS_SUCCEEDED(rv)) {
  350. aPref->isSet = true;
  351. aPref->floatVar = (float)intpref / 100.0f;
  352. }
  353. }
  354. void
  355. nsXPLookAndFeel::InitColorFromPref(int32_t i)
  356. {
  357. nsAutoString colorStr;
  358. nsresult rv = Preferences::GetString(sColorPrefs[i], &colorStr);
  359. if (NS_FAILED(rv) || colorStr.IsEmpty()) {
  360. return;
  361. }
  362. nscolor thecolor;
  363. if (colorStr[0] == char16_t('#')) {
  364. nsAutoString hexString;
  365. colorStr.Right(hexString, colorStr.Length() - 1);
  366. if (NS_HexToRGBA(hexString, nsHexColorType::NoAlpha, &thecolor)) {
  367. CACHE_COLOR(i, thecolor);
  368. }
  369. } else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
  370. CACHE_COLOR(i, thecolor);
  371. }
  372. }
  373. // static
  374. void
  375. nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure)
  376. {
  377. // looping in the same order as in ::Init
  378. nsDependentCString prefName(aPref);
  379. unsigned int i;
  380. for (i = 0; i < ArrayLength(sIntPrefs); ++i) {
  381. if (prefName.Equals(sIntPrefs[i].name)) {
  382. IntPrefChanged(&sIntPrefs[i]);
  383. return;
  384. }
  385. }
  386. for (i = 0; i < ArrayLength(sFloatPrefs); ++i) {
  387. if (prefName.Equals(sFloatPrefs[i].name)) {
  388. FloatPrefChanged(&sFloatPrefs[i]);
  389. return;
  390. }
  391. }
  392. for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
  393. if (prefName.Equals(sColorPrefs[i])) {
  394. ColorPrefChanged(i, sColorPrefs[i]);
  395. return;
  396. }
  397. }
  398. }
  399. //
  400. // Read values from the user's preferences.
  401. // This is done once at startup, but since the user's preferences
  402. // haven't actually been read yet at that time, we also have to
  403. // set a callback to inform us of changes to each pref.
  404. //
  405. void
  406. nsXPLookAndFeel::Init()
  407. {
  408. // Say we're already initialized, and take the chance that it might fail;
  409. // protects against some other process writing to our static variables.
  410. sInitialized = true;
  411. // XXX If we could reorganize the pref names, we should separate the branch
  412. // for each types. Then, we could reduce the unnecessary loop from
  413. // nsXPLookAndFeel::OnPrefChanged().
  414. Preferences::RegisterCallback(OnPrefChanged, "ui.");
  415. Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus");
  416. unsigned int i;
  417. for (i = 0; i < ArrayLength(sIntPrefs); ++i) {
  418. InitFromPref(&sIntPrefs[i]);
  419. }
  420. for (i = 0; i < ArrayLength(sFloatPrefs); ++i) {
  421. InitFromPref(&sFloatPrefs[i]);
  422. }
  423. for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
  424. InitColorFromPref(i);
  425. }
  426. Preferences::AddBoolVarCache(&sUseNativeColors,
  427. "ui.use_native_colors",
  428. sUseNativeColors);
  429. Preferences::AddBoolVarCache(&sUseStandinsForNativeColors,
  430. "ui.use_standins_for_native_colors",
  431. sUseStandinsForNativeColors);
  432. Preferences::AddBoolVarCache(&sFindbarModalHighlight,
  433. "findbar.modalHighlight",
  434. sFindbarModalHighlight);
  435. if (XRE_IsContentProcess()) {
  436. mozilla::dom::ContentChild* cc =
  437. mozilla::dom::ContentChild::GetSingleton();
  438. nsTArray<LookAndFeelInt> lookAndFeelIntCache;
  439. cc->SendGetLookAndFeelCache(&lookAndFeelIntCache);
  440. LookAndFeel::SetIntCache(lookAndFeelIntCache);
  441. }
  442. }
  443. nsXPLookAndFeel::~nsXPLookAndFeel()
  444. {
  445. NS_ASSERTION(sInstance == this,
  446. "This destroying instance isn't the singleton instance");
  447. sInstance = nullptr;
  448. }
  449. bool
  450. nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
  451. {
  452. switch (aID) {
  453. case eColorID_TextSelectForeground:
  454. return (aColor == NS_DONT_CHANGE_COLOR);
  455. case eColorID_IMESelectedRawTextBackground:
  456. case eColorID_IMESelectedConvertedTextBackground:
  457. case eColorID_IMERawInputBackground:
  458. case eColorID_IMEConvertedTextBackground:
  459. case eColorID_IMESelectedRawTextForeground:
  460. case eColorID_IMESelectedConvertedTextForeground:
  461. case eColorID_IMERawInputForeground:
  462. case eColorID_IMEConvertedTextForeground:
  463. case eColorID_IMERawInputUnderline:
  464. case eColorID_IMEConvertedTextUnderline:
  465. case eColorID_IMESelectedRawTextUnderline:
  466. case eColorID_IMESelectedConvertedTextUnderline:
  467. case eColorID_SpellCheckerUnderline:
  468. return NS_IS_SELECTION_SPECIAL_COLOR(aColor);
  469. default:
  470. /*
  471. * In GetColor(), every color that is not a special color is color
  472. * corrected. Use false to make other colors color corrected.
  473. */
  474. return false;
  475. }
  476. return false;
  477. }
  478. bool
  479. nsXPLookAndFeel::ColorIsNotCSSAccessible(ColorID aID)
  480. {
  481. bool result = false;
  482. switch (aID) {
  483. case eColorID_WindowBackground:
  484. case eColorID_WindowForeground:
  485. case eColorID_WidgetBackground:
  486. case eColorID_WidgetForeground:
  487. case eColorID_WidgetSelectBackground:
  488. case eColorID_WidgetSelectForeground:
  489. case eColorID_Widget3DHighlight:
  490. case eColorID_Widget3DShadow:
  491. case eColorID_TextBackground:
  492. case eColorID_TextForeground:
  493. case eColorID_TextSelectBackground:
  494. case eColorID_TextSelectForeground:
  495. case eColorID_TextSelectBackgroundDisabled:
  496. case eColorID_TextSelectBackgroundAttention:
  497. case eColorID_TextHighlightBackground:
  498. case eColorID_TextHighlightForeground:
  499. case eColorID_IMERawInputBackground:
  500. case eColorID_IMERawInputForeground:
  501. case eColorID_IMERawInputUnderline:
  502. case eColorID_IMESelectedRawTextBackground:
  503. case eColorID_IMESelectedRawTextForeground:
  504. case eColorID_IMESelectedRawTextUnderline:
  505. case eColorID_IMEConvertedTextBackground:
  506. case eColorID_IMEConvertedTextForeground:
  507. case eColorID_IMEConvertedTextUnderline:
  508. case eColorID_IMESelectedConvertedTextBackground:
  509. case eColorID_IMESelectedConvertedTextForeground:
  510. case eColorID_IMESelectedConvertedTextUnderline:
  511. case eColorID_SpellCheckerUnderline:
  512. result = true;
  513. break;
  514. default:
  515. break;
  516. }
  517. return result;
  518. }
  519. nscolor
  520. nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID)
  521. {
  522. nscolor result = NS_RGB(0xFF, 0xFF, 0xFF);
  523. // The stand-in colors are taken from the Windows 7 Aero theme
  524. // except Mac-specific colors which are taken from Mac OS 10.7.
  525. switch (aID) {
  526. // CSS 2 colors:
  527. case eColorID_activeborder: result = NS_RGB(0xB4, 0xB4, 0xB4); break;
  528. case eColorID_activecaption: result = NS_RGB(0x99, 0xB4, 0xD1); break;
  529. case eColorID_appworkspace: result = NS_RGB(0xAB, 0xAB, 0xAB); break;
  530. case eColorID_background: result = NS_RGB(0x00, 0x00, 0x00); break;
  531. case eColorID_buttonface: result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  532. case eColorID_buttonhighlight: result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  533. case eColorID_buttonshadow: result = NS_RGB(0xA0, 0xA0, 0xA0); break;
  534. case eColorID_buttontext: result = NS_RGB(0x00, 0x00, 0x00); break;
  535. case eColorID_captiontext: result = NS_RGB(0x00, 0x00, 0x00); break;
  536. case eColorID_graytext: result = NS_RGB(0x6D, 0x6D, 0x6D); break;
  537. case eColorID_highlight: result = NS_RGB(0x33, 0x99, 0xFF); break;
  538. case eColorID_highlighttext: result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  539. case eColorID_inactiveborder: result = NS_RGB(0xF4, 0xF7, 0xFC); break;
  540. case eColorID_inactivecaption: result = NS_RGB(0xBF, 0xCD, 0xDB); break;
  541. case eColorID_inactivecaptiontext:
  542. result = NS_RGB(0x43, 0x4E, 0x54); break;
  543. case eColorID_infobackground: result = NS_RGB(0xFF, 0xFF, 0xE1); break;
  544. case eColorID_infotext: result = NS_RGB(0x00, 0x00, 0x00); break;
  545. case eColorID_menu: result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  546. case eColorID_menutext: result = NS_RGB(0x00, 0x00, 0x00); break;
  547. case eColorID_scrollbar: result = NS_RGB(0xC8, 0xC8, 0xC8); break;
  548. case eColorID_threeddarkshadow: result = NS_RGB(0x69, 0x69, 0x69); break;
  549. case eColorID_threedface: result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  550. case eColorID_threedhighlight: result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  551. case eColorID_threedlightshadow: result = NS_RGB(0xE3, 0xE3, 0xE3); break;
  552. case eColorID_threedshadow: result = NS_RGB(0xA0, 0xA0, 0xA0); break;
  553. case eColorID_window: result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  554. case eColorID_windowframe: result = NS_RGB(0x64, 0x64, 0x64); break;
  555. case eColorID_windowtext: result = NS_RGB(0x00, 0x00, 0x00); break;
  556. case eColorID__moz_buttondefault:
  557. result = NS_RGB(0x69, 0x69, 0x69); break;
  558. case eColorID__moz_field: result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  559. case eColorID__moz_fieldtext: result = NS_RGB(0x00, 0x00, 0x00); break;
  560. case eColorID__moz_dialog: result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  561. case eColorID__moz_dialogtext: result = NS_RGB(0x00, 0x00, 0x00); break;
  562. case eColorID__moz_dragtargetzone:
  563. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  564. case eColorID__moz_cellhighlight:
  565. result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  566. case eColorID__moz_cellhighlighttext:
  567. result = NS_RGB(0x00, 0x00, 0x00); break;
  568. case eColorID__moz_html_cellhighlight:
  569. result = NS_RGB(0x33, 0x99, 0xFF); break;
  570. case eColorID__moz_html_cellhighlighttext:
  571. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  572. case eColorID__moz_buttonhoverface:
  573. result = NS_RGB(0xF0, 0xF0, 0xF0); break;
  574. case eColorID__moz_buttonhovertext:
  575. result = NS_RGB(0x00, 0x00, 0x00); break;
  576. case eColorID__moz_menuhover:
  577. result = NS_RGB(0x33, 0x99, 0xFF); break;
  578. case eColorID__moz_menuhovertext:
  579. result = NS_RGB(0x00, 0x00, 0x00); break;
  580. case eColorID__moz_menubartext:
  581. result = NS_RGB(0x00, 0x00, 0x00); break;
  582. case eColorID__moz_menubarhovertext:
  583. result = NS_RGB(0x00, 0x00, 0x00); break;
  584. case eColorID__moz_oddtreerow:
  585. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  586. case eColorID__moz_mac_chrome_active:
  587. result = NS_RGB(0xB2, 0xB2, 0xB2); break;
  588. case eColorID__moz_mac_chrome_inactive:
  589. result = NS_RGB(0xE1, 0xE1, 0xE1); break;
  590. case eColorID__moz_mac_focusring:
  591. result = NS_RGB(0x60, 0x9D, 0xD7); break;
  592. case eColorID__moz_mac_menuselect:
  593. result = NS_RGB(0x38, 0x75, 0xD7); break;
  594. case eColorID__moz_mac_menushadow:
  595. result = NS_RGB(0xA3, 0xA3, 0xA3); break;
  596. case eColorID__moz_mac_menutextdisable:
  597. result = NS_RGB(0x88, 0x88, 0x88); break;
  598. case eColorID__moz_mac_menutextselect:
  599. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  600. case eColorID__moz_mac_disabledtoolbartext:
  601. result = NS_RGB(0x3F, 0x3F, 0x3F); break;
  602. case eColorID__moz_mac_secondaryhighlight:
  603. result = NS_RGB(0xD4, 0xD4, 0xD4); break;
  604. case eColorID__moz_win_accentcolor:
  605. // Seems to be the default color (hardcoded because of bug 1065998)
  606. result = NS_RGB(0x9E, 0x9E, 0x9E); break;
  607. case eColorID__moz_win_accentcolortext:
  608. result = NS_RGB(0x00, 0x00, 0x00); break;
  609. case eColorID__moz_win_mediatext:
  610. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  611. case eColorID__moz_win_communicationstext:
  612. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  613. case eColorID__moz_nativehyperlinktext:
  614. result = NS_RGB(0x00, 0x66, 0xCC); break;
  615. case eColorID__moz_comboboxtext:
  616. result = NS_RGB(0x00, 0x00, 0x00); break;
  617. case eColorID__moz_combobox:
  618. result = NS_RGB(0xFF, 0xFF, 0xFF); break;
  619. default:
  620. break;
  621. }
  622. return result;
  623. }
  624. //
  625. // All these routines will return NS_OK if they have a value,
  626. // in which case the nsLookAndFeel should use that value;
  627. // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
  628. // platform-specific nsLookAndFeel should use its own values instead.
  629. //
  630. nsresult
  631. nsXPLookAndFeel::GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
  632. nscolor &aResult)
  633. {
  634. if (!sInitialized)
  635. Init();
  636. // define DEBUG_SYSTEM_COLOR_USE if you want to debug system color
  637. // use in a skin that uses them. When set, it will make all system
  638. // color pairs that are appropriate for foreground/background
  639. // pairing the same. This means if the skin is using system colors
  640. // correctly you will not be able to see *any* text.
  641. #undef DEBUG_SYSTEM_COLOR_USE
  642. #ifdef DEBUG_SYSTEM_COLOR_USE
  643. {
  644. nsresult rv = NS_OK;
  645. switch (aID) {
  646. // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
  647. case eColorID_activecaption:
  648. // active window caption background
  649. case eColorID_captiontext:
  650. // text in active window caption
  651. aResult = NS_RGB(0xff, 0x00, 0x00);
  652. break;
  653. case eColorID_highlight:
  654. // background of selected item
  655. case eColorID_highlighttext:
  656. // text of selected item
  657. aResult = NS_RGB(0xff, 0xff, 0x00);
  658. break;
  659. case eColorID_inactivecaption:
  660. // inactive window caption
  661. case eColorID_inactivecaptiontext:
  662. // text in inactive window caption
  663. aResult = NS_RGB(0x66, 0x66, 0x00);
  664. break;
  665. case eColorID_infobackground:
  666. // tooltip background color
  667. case eColorID_infotext:
  668. // tooltip text color
  669. aResult = NS_RGB(0x00, 0xff, 0x00);
  670. break;
  671. case eColorID_menu:
  672. // menu background
  673. case eColorID_menutext:
  674. // menu text
  675. aResult = NS_RGB(0x00, 0xff, 0xff);
  676. break;
  677. case eColorID_threedface:
  678. case eColorID_buttonface:
  679. // 3-D face color
  680. case eColorID_buttontext:
  681. // text on push buttons
  682. aResult = NS_RGB(0x00, 0x66, 0x66);
  683. break;
  684. case eColorID_window:
  685. case eColorID_windowtext:
  686. aResult = NS_RGB(0x00, 0x00, 0xff);
  687. break;
  688. // from the CSS3 working draft (not yet finalized)
  689. // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
  690. case eColorID__moz_field:
  691. case eColorID__moz_fieldtext:
  692. aResult = NS_RGB(0xff, 0x00, 0xff);
  693. break;
  694. case eColorID__moz_dialog:
  695. case eColorID__moz_dialogtext:
  696. aResult = NS_RGB(0x66, 0x00, 0x66);
  697. break;
  698. default:
  699. rv = NS_ERROR_NOT_AVAILABLE;
  700. }
  701. if (NS_SUCCEEDED(rv))
  702. return rv;
  703. }
  704. #endif // DEBUG_SYSTEM_COLOR_USE
  705. if (aUseStandinsForNativeColors &&
  706. (ColorIsNotCSSAccessible(aID) || !sUseStandinsForNativeColors)) {
  707. aUseStandinsForNativeColors = false;
  708. }
  709. if (!aUseStandinsForNativeColors && IS_COLOR_CACHED(aID)) {
  710. aResult = sCachedColors[aID];
  711. return NS_OK;
  712. }
  713. // There are no system color settings for these, so set them manually
  714. if (aID == eColorID_TextSelectBackgroundDisabled) {
  715. // This is used to gray out the selection when it's not focused
  716. // Used with nsISelectionController::SELECTION_DISABLED
  717. aResult = NS_RGB(0xb0, 0xb0, 0xb0);
  718. return NS_OK;
  719. }
  720. if (aID == eColorID_TextSelectBackgroundAttention) {
  721. if (sFindbarModalHighlight) {
  722. aResult = NS_RGBA(0, 0, 0, 0);
  723. return NS_OK;
  724. }
  725. // This makes the selection stand out when typeaheadfind is on
  726. // Used with nsISelectionController::SELECTION_ATTENTION
  727. aResult = NS_RGB(0x38, 0xd8, 0x78);
  728. return NS_OK;
  729. }
  730. if (aID == eColorID_TextHighlightBackground) {
  731. // This makes the matched text stand out when findbar highlighting is on
  732. // Used with nsISelectionController::SELECTION_FIND
  733. aResult = NS_RGB(0xef, 0x0f, 0xff);
  734. return NS_OK;
  735. }
  736. if (aID == eColorID_TextHighlightForeground) {
  737. // The foreground color for the matched text in findbar highlighting
  738. // Used with nsISelectionController::SELECTION_FIND
  739. aResult = NS_RGB(0xff, 0xff, 0xff);
  740. return NS_OK;
  741. }
  742. if (sUseNativeColors && aUseStandinsForNativeColors) {
  743. aResult = GetStandinForNativeColor(aID);
  744. return NS_OK;
  745. }
  746. if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aResult))) {
  747. if ((gfxPlatform::GetCMSMode() == eCMSMode_All) &&
  748. !IsSpecialColor(aID, aResult)) {
  749. qcms_transform *transform = gfxPlatform::GetCMSInverseRGBTransform();
  750. if (transform) {
  751. uint8_t color[3];
  752. color[0] = NS_GET_R(aResult);
  753. color[1] = NS_GET_G(aResult);
  754. color[2] = NS_GET_B(aResult);
  755. qcms_transform_data(transform, color, color, 1);
  756. aResult = NS_RGB(color[0], color[1], color[2]);
  757. }
  758. }
  759. CACHE_COLOR(aID, aResult);
  760. return NS_OK;
  761. }
  762. return NS_ERROR_NOT_AVAILABLE;
  763. }
  764. nsresult
  765. nsXPLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
  766. {
  767. if (!sInitialized)
  768. Init();
  769. // Set the default values for these prefs. but allow different platforms
  770. // to override them in their nsLookAndFeel if desired.
  771. switch (aID) {
  772. case eIntID_ScrollButtonLeftMouseButtonAction:
  773. aResult = 0;
  774. return NS_OK;
  775. case eIntID_ScrollButtonMiddleMouseButtonAction:
  776. aResult = 3;
  777. return NS_OK;
  778. case eIntID_ScrollButtonRightMouseButtonAction:
  779. aResult = 3;
  780. return NS_OK;
  781. default:
  782. /*
  783. * The metrics above are hardcoded platform defaults. All the other
  784. * metrics are stored in sIntPrefs and can be changed at runtime.
  785. */
  786. break;
  787. }
  788. for (unsigned int i = 0; i < ArrayLength(sIntPrefs); ++i) {
  789. if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID)) {
  790. aResult = sIntPrefs[i].intVar;
  791. return NS_OK;
  792. }
  793. }
  794. return NS_ERROR_NOT_AVAILABLE;
  795. }
  796. nsresult
  797. nsXPLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
  798. {
  799. if (!sInitialized)
  800. Init();
  801. for (unsigned int i = 0; i < ArrayLength(sFloatPrefs); ++i) {
  802. if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID) {
  803. aResult = sFloatPrefs[i].floatVar;
  804. return NS_OK;
  805. }
  806. }
  807. return NS_ERROR_NOT_AVAILABLE;
  808. }
  809. void
  810. nsXPLookAndFeel::RefreshImpl()
  811. {
  812. // Wipe out our color cache.
  813. uint32_t i;
  814. for (i = 0; i < eColorID_LAST_COLOR; i++)
  815. sCachedColors[i] = 0;
  816. for (i = 0; i < COLOR_CACHE_SIZE; i++)
  817. sCachedColorBits[i] = 0;
  818. }
  819. nsTArray<LookAndFeelInt>
  820. nsXPLookAndFeel::GetIntCacheImpl()
  821. {
  822. return nsTArray<LookAndFeelInt>();
  823. }
  824. namespace mozilla {
  825. // static
  826. nsresult
  827. LookAndFeel::GetColor(ColorID aID, nscolor* aResult)
  828. {
  829. return nsLookAndFeel::GetInstance()->GetColorImpl(aID, false, *aResult);
  830. }
  831. nsresult
  832. LookAndFeel::GetColor(ColorID aID, bool aUseStandinsForNativeColors,
  833. nscolor* aResult)
  834. {
  835. return nsLookAndFeel::GetInstance()->GetColorImpl(aID,
  836. aUseStandinsForNativeColors, *aResult);
  837. }
  838. // static
  839. nsresult
  840. LookAndFeel::GetInt(IntID aID, int32_t* aResult)
  841. {
  842. return nsLookAndFeel::GetInstance()->GetIntImpl(aID, *aResult);
  843. }
  844. // static
  845. nsresult
  846. LookAndFeel::GetFloat(FloatID aID, float* aResult)
  847. {
  848. return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult);
  849. }
  850. // static
  851. bool
  852. LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
  853. float aDevPixPerCSSPixel)
  854. {
  855. return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle,
  856. aDevPixPerCSSPixel);
  857. }
  858. // static
  859. char16_t
  860. LookAndFeel::GetPasswordCharacter()
  861. {
  862. return nsLookAndFeel::GetInstance()->GetPasswordCharacterImpl();
  863. }
  864. // static
  865. bool
  866. LookAndFeel::GetEchoPassword()
  867. {
  868. return nsLookAndFeel::GetInstance()->GetEchoPasswordImpl();
  869. }
  870. // static
  871. uint32_t
  872. LookAndFeel::GetPasswordMaskDelay()
  873. {
  874. return nsLookAndFeel::GetInstance()->GetPasswordMaskDelayImpl();
  875. }
  876. // static
  877. void
  878. LookAndFeel::Refresh()
  879. {
  880. nsLookAndFeel::GetInstance()->RefreshImpl();
  881. }
  882. // static
  883. nsTArray<LookAndFeelInt>
  884. LookAndFeel::GetIntCache()
  885. {
  886. return nsLookAndFeel::GetInstance()->GetIntCacheImpl();
  887. }
  888. // static
  889. void
  890. LookAndFeel::SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache)
  891. {
  892. return nsLookAndFeel::GetInstance()->SetIntCacheImpl(aLookAndFeelIntCache);
  893. }
  894. } // namespace mozilla