2001-09-29 00:14:13 +04:00
|
|
|
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2001-11-06 11:23:51 +03:00
|
|
|
#include "nscore.h"
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
#include "nsXPLookAndFeel.h"
|
2011-09-09 06:27:11 +04:00
|
|
|
#include "nsLookAndFeel.h"
|
2017-04-04 17:22:00 +03:00
|
|
|
#include "HeadlessLookAndFeel.h"
|
2020-12-16 07:17:36 +03:00
|
|
|
#include "RemoteLookAndFeel.h"
|
2020-07-15 15:45:07 +03:00
|
|
|
#include "nsContentUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2004-10-25 23:34:45 +04:00
|
|
|
#include "nsFont.h"
|
2021-04-02 15:22:14 +03:00
|
|
|
#include "nsIFrame.h"
|
2020-06-09 02:00:21 +03:00
|
|
|
#include "nsIXULRuntime.h"
|
2021-02-10 03:47:38 +03:00
|
|
|
#include "nsNativeBasicTheme.h"
|
2015-05-07 20:32:01 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2011-05-23 18:54:03 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-09-19 22:05:01 +03:00
|
|
|
#include "mozilla/Services.h"
|
2017-03-23 05:52:53 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2021-04-02 20:43:08 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2021-06-08 05:01:10 +03:00
|
|
|
#include "mozilla/StaticPrefs_browser.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_editor.h"
|
2019-08-27 03:09:29 +03:00
|
|
|
#include "mozilla/StaticPrefs_findbar.h"
|
2019-08-27 03:07:34 +03:00
|
|
|
#include "mozilla/StaticPrefs_ui.h"
|
2020-12-22 22:26:41 +03:00
|
|
|
#include "mozilla/StaticPrefs_widget.h"
|
2021-04-02 15:22:14 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
|
|
|
#include "mozilla/PreferenceSheet.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-04-22 17:58:15 +03:00
|
|
|
#include "mozilla/widget/WidgetMessageUtils.h"
|
2019-12-20 22:05:12 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TelemetryScalarEnums.h"
|
2001-11-06 05:41:04 +03:00
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
#include "gfxPlatform.h"
|
2021-03-25 01:57:36 +03:00
|
|
|
#include "gfxFont.h"
|
2019-05-26 17:31:53 +03:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2007-08-30 20:21:16 +04:00
|
|
|
|
2002-01-24 04:18:36 +03:00
|
|
|
#ifdef DEBUG
|
2001-11-06 05:41:04 +03:00
|
|
|
# include "nsSize.h"
|
|
|
|
#endif
|
2009-02-10 22:25:00 +03:00
|
|
|
|
2011-05-23 18:54:03 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2021-03-18 21:00:26 +03:00
|
|
|
using IntID = mozilla::LookAndFeel::IntID;
|
|
|
|
using FloatID = mozilla::LookAndFeel::FloatID;
|
|
|
|
using ColorID = mozilla::LookAndFeel::ColorID;
|
2021-03-25 01:57:36 +03:00
|
|
|
using FontID = mozilla::LookAndFeel::FontID;
|
2021-03-18 21:00:26 +03:00
|
|
|
|
2021-03-25 01:57:36 +03:00
|
|
|
template <typename Index, typename Value, Index kEnd>
|
2021-03-19 00:04:52 +03:00
|
|
|
class EnumeratedCache {
|
|
|
|
static constexpr uint32_t ChunkFor(Index aIndex) {
|
2021-04-02 15:22:14 +03:00
|
|
|
return uint32_t(aIndex) >> 5; // >> 5 is the same as / 32.
|
2021-03-19 00:04:52 +03:00
|
|
|
}
|
|
|
|
static constexpr uint32_t BitFor(Index aIndex) {
|
|
|
|
return 1u << (uint32_t(aIndex) & 31);
|
|
|
|
}
|
|
|
|
static constexpr uint32_t kChunks = ChunkFor(kEnd) + 1;
|
|
|
|
|
|
|
|
mozilla::EnumeratedArray<Index, kEnd, Value> mEntries;
|
|
|
|
uint32_t mValidity[kChunks] = {0};
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr EnumeratedCache() = default;
|
|
|
|
|
|
|
|
bool IsValid(Index aIndex) const {
|
|
|
|
return mValidity[ChunkFor(aIndex)] & BitFor(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value* Get(Index aIndex) const {
|
|
|
|
return IsValid(aIndex) ? &mEntries[aIndex] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Insert(Index aIndex, Value aValue) {
|
|
|
|
mValidity[ChunkFor(aIndex)] |= BitFor(aIndex);
|
|
|
|
mEntries[aIndex] = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remove(Index aIndex) {
|
|
|
|
mValidity[ChunkFor(aIndex)] &= ~BitFor(aIndex);
|
|
|
|
mEntries[aIndex] = Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
for (auto& chunk : mValidity) {
|
|
|
|
chunk = 0;
|
|
|
|
}
|
|
|
|
for (auto& entry : mEntries) {
|
|
|
|
entry = Value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-03 01:17:55 +03:00
|
|
|
static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sLightColorCache;
|
|
|
|
static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sDarkColorCache;
|
2021-04-02 19:34:35 +03:00
|
|
|
static EnumeratedCache<FloatID, Maybe<float>, FloatID::End> sFloatCache;
|
|
|
|
static EnumeratedCache<IntID, Maybe<int32_t>, IntID::End> sIntCache;
|
2021-03-25 01:57:36 +03:00
|
|
|
static EnumeratedCache<FontID, widget::LookAndFeelFont, FontID::End> sFontCache;
|
2021-03-18 21:00:26 +03:00
|
|
|
|
2020-07-29 23:27:42 +03:00
|
|
|
// To make one of these prefs toggleable from a reftest add a user
|
|
|
|
// pref in testing/profiles/reftest/user.js. For example, to make
|
|
|
|
// ui.useAccessibilityTheme toggleable, add:
|
|
|
|
//
|
|
|
|
// user_pref("ui.useAccessibilityTheme", 0);
|
|
|
|
//
|
2021-04-02 19:34:35 +03:00
|
|
|
// This needs to be of the same length and in the same order as
|
|
|
|
// LookAndFeel::IntID values.
|
2021-08-25 17:32:13 +03:00
|
|
|
static const char sIntPrefs[][43] = {
|
2021-04-02 19:34:35 +03:00
|
|
|
"ui.caretBlinkTime",
|
2021-08-10 17:39:27 +03:00
|
|
|
"ui.caretBlinkCount",
|
2021-04-02 19:34:35 +03:00
|
|
|
"ui.caretWidth",
|
|
|
|
"ui.caretVisibleWithSelection",
|
|
|
|
"ui.selectTextfieldsOnKeyFocus",
|
|
|
|
"ui.submenuDelay",
|
|
|
|
"ui.menusCanOverlapOSBar",
|
|
|
|
"ui.useOverlayScrollbars",
|
|
|
|
"ui.allowOverlayScrollbarsOverlap",
|
|
|
|
"ui.skipNavigatingDisabledMenuItem",
|
|
|
|
"ui.dragThresholdX",
|
|
|
|
"ui.dragThresholdY",
|
|
|
|
"ui.useAccessibilityTheme",
|
|
|
|
"ui.scrollArrowStyle",
|
|
|
|
"ui.scrollSliderStyle",
|
|
|
|
"ui.scrollButtonLeftMouseButtonAction",
|
|
|
|
"ui.scrollButtonMiddleMouseButtonAction",
|
|
|
|
"ui.scrollButtonRightMouseButtonAction",
|
|
|
|
"ui.treeOpenDelay",
|
|
|
|
"ui.treeCloseDelay",
|
|
|
|
"ui.treeLazyScrollDelay",
|
|
|
|
"ui.treeScrollDelay",
|
|
|
|
"ui.treeScrollLinesMax",
|
|
|
|
"accessibility.tabfocus", // Weird one...
|
|
|
|
"ui.chosenMenuItemsShouldBlink",
|
|
|
|
"ui.windowsAccentColorInTitlebar",
|
|
|
|
"ui.windowsDefaultTheme",
|
|
|
|
"ui.dwmCompositor",
|
|
|
|
"ui.windowsClassic",
|
|
|
|
"ui.windowsGlass",
|
|
|
|
"ui.macGraphiteTheme",
|
|
|
|
"ui.macBigSurTheme",
|
2021-09-22 21:51:20 +03:00
|
|
|
"ui.macRTL",
|
2021-04-02 19:34:35 +03:00
|
|
|
"ui.alertNotificationOrigin",
|
|
|
|
"ui.scrollToClick",
|
|
|
|
"ui.IMERawInputUnderlineStyle",
|
|
|
|
"ui.IMESelectedRawTextUnderlineStyle",
|
|
|
|
"ui.IMEConvertedTextUnderlineStyle",
|
|
|
|
"ui.IMESelectedConvertedTextUnderlineStyle",
|
|
|
|
"ui.SpellCheckerUnderlineStyle",
|
|
|
|
"ui.menuBarDrag",
|
|
|
|
"ui.operatingSystemVersionIdentifier",
|
|
|
|
"ui.scrollbarButtonAutoRepeatBehavior",
|
|
|
|
"ui.tooltipDelay",
|
|
|
|
"ui.swipeAnimationEnabled",
|
|
|
|
"ui.scrollbarDisplayOnMouseMove",
|
|
|
|
"ui.scrollbarFadeBeginDelay",
|
|
|
|
"ui.scrollbarFadeDuration",
|
|
|
|
"ui.contextMenuOffsetVertical",
|
|
|
|
"ui.contextMenuOffsetHorizontal",
|
|
|
|
"ui.GtkCSDAvailable",
|
|
|
|
"ui.GtkCSDMinimizeButton",
|
|
|
|
"ui.GtkCSDMaximizeButton",
|
|
|
|
"ui.GtkCSDCloseButton",
|
|
|
|
"ui.GtkCSDMinimizeButtonPosition",
|
|
|
|
"ui.GtkCSDMaximizeButtonPosition",
|
|
|
|
"ui.GtkCSDCloseButtonPosition",
|
|
|
|
"ui.GtkCSDReversedPlacement",
|
|
|
|
"ui.systemUsesDarkTheme",
|
|
|
|
"ui.prefersReducedMotion",
|
|
|
|
"ui.primaryPointerCapabilities",
|
|
|
|
"ui.allPointerCapabilities",
|
|
|
|
"ui.systemVerticalScrollbarWidth",
|
|
|
|
"ui.systemHorizontalScrollbarHeight",
|
2021-08-25 17:32:13 +03:00
|
|
|
"ui.touchDeviceSupportPresent",
|
2021-10-20 21:01:02 +03:00
|
|
|
"ui.titlebarRadius",
|
2021-10-28 13:52:31 +03:00
|
|
|
"ui.GtkMenuRadius",
|
2000-03-31 02:32:18 +04:00
|
|
|
};
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static_assert(ArrayLength(sIntPrefs) == size_t(LookAndFeel::IntID::End),
|
|
|
|
"Should have a pref for each int value");
|
|
|
|
|
|
|
|
// This array MUST be kept in the same order as the float id list in
|
|
|
|
// LookAndFeel.h
|
2021-10-18 19:22:13 +03:00
|
|
|
// clang-format off
|
2021-04-02 19:34:35 +03:00
|
|
|
static const char sFloatPrefs[][37] = {
|
|
|
|
"ui.IMEUnderlineRelativeSize",
|
|
|
|
"ui.SpellCheckerUnderlineRelativeSize",
|
|
|
|
"ui.caretAspectRatio",
|
|
|
|
"ui.textScaleFactor",
|
2021-10-28 15:25:23 +03:00
|
|
|
"ui.cursorScale",
|
2000-04-12 02:34:55 +04:00
|
|
|
};
|
2021-10-18 19:22:13 +03:00
|
|
|
// clang-format on
|
2000-04-12 02:34:55 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static_assert(ArrayLength(sFloatPrefs) == size_t(LookAndFeel::FloatID::End),
|
|
|
|
"Should have a pref for each float value");
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
// This array MUST be kept in the same order as the color list in
|
|
|
|
// specified/color.rs
|
2021-03-18 21:00:26 +03:00
|
|
|
static const char sColorPrefs[][41] = {
|
2021-11-11 14:14:13 +03:00
|
|
|
"ui.textSelectDisabledBackground",
|
|
|
|
"ui.textSelectAttentionBackground",
|
|
|
|
"ui.textSelectAttentionForeground",
|
2008-07-31 00:48:56 +04:00
|
|
|
"ui.textHighlightBackground",
|
2008-09-02 10:28:44 +04:00
|
|
|
"ui.textHighlightForeground",
|
2005-09-17 15:34:27 +04:00
|
|
|
"ui.IMERawInputBackground",
|
|
|
|
"ui.IMERawInputForeground",
|
|
|
|
"ui.IMERawInputUnderline",
|
|
|
|
"ui.IMESelectedRawTextBackground",
|
|
|
|
"ui.IMESelectedRawTextForeground",
|
|
|
|
"ui.IMESelectedRawTextUnderline",
|
|
|
|
"ui.IMEConvertedTextBackground",
|
|
|
|
"ui.IMEConvertedTextForeground",
|
|
|
|
"ui.IMEConvertedTextUnderline",
|
|
|
|
"ui.IMESelectedConvertedTextBackground",
|
|
|
|
"ui.IMESelectedConvertedTextForeground",
|
|
|
|
"ui.IMESelectedConvertedTextUnderline",
|
2009-04-03 11:26:28 +04:00
|
|
|
"ui.SpellCheckerUnderline",
|
2020-10-16 15:49:47 +03:00
|
|
|
"ui.themedScrollbar",
|
|
|
|
"ui.themedScrollbarInactive",
|
|
|
|
"ui.themedScrollbarThumb",
|
|
|
|
"ui.themedScrollbarThumbHover",
|
|
|
|
"ui.themedScrollbarThumbActive",
|
|
|
|
"ui.themedScrollbarThumbInactive",
|
2001-11-06 05:41:04 +03:00
|
|
|
"ui.activeborder",
|
|
|
|
"ui.activecaption",
|
|
|
|
"ui.appworkspace",
|
|
|
|
"ui.background",
|
|
|
|
"ui.buttonface",
|
|
|
|
"ui.buttonhighlight",
|
|
|
|
"ui.buttonshadow",
|
|
|
|
"ui.buttontext",
|
|
|
|
"ui.captiontext",
|
2019-11-03 00:28:49 +03:00
|
|
|
"ui.-moz-field",
|
2021-10-05 17:40:52 +03:00
|
|
|
"ui.-moz-disabledfield",
|
2019-11-03 00:28:49 +03:00
|
|
|
"ui.-moz-fieldtext",
|
2001-11-06 05:41:04 +03:00
|
|
|
"ui.graytext",
|
|
|
|
"ui.highlight",
|
|
|
|
"ui.highlighttext",
|
|
|
|
"ui.inactiveborder",
|
|
|
|
"ui.inactivecaption",
|
|
|
|
"ui.inactivecaptiontext",
|
|
|
|
"ui.infobackground",
|
|
|
|
"ui.infotext",
|
|
|
|
"ui.menu",
|
|
|
|
"ui.menutext",
|
|
|
|
"ui.scrollbar",
|
|
|
|
"ui.threeddarkshadow",
|
|
|
|
"ui.threedface",
|
|
|
|
"ui.threedhighlight",
|
|
|
|
"ui.threedlightshadow",
|
|
|
|
"ui.threedshadow",
|
|
|
|
"ui.window",
|
|
|
|
"ui.windowframe",
|
|
|
|
"ui.windowtext",
|
2003-06-19 01:16:29 +04:00
|
|
|
"ui.-moz-buttondefault",
|
2019-11-14 03:17:23 +03:00
|
|
|
"ui.-moz-default-color",
|
|
|
|
"ui.-moz-default-background-color",
|
2001-11-06 05:41:04 +03:00
|
|
|
"ui.-moz-dialog",
|
|
|
|
"ui.-moz-dialogtext",
|
|
|
|
"ui.-moz-dragtargetzone",
|
2008-04-24 12:08:33 +04:00
|
|
|
"ui.-moz-cellhighlight",
|
|
|
|
"ui.-moz_cellhighlighttext",
|
2021-09-02 14:38:01 +03:00
|
|
|
"ui.selecteditem",
|
|
|
|
"ui.selecteditemtext",
|
2008-04-24 12:08:33 +04:00
|
|
|
"ui.-moz-buttonhoverface",
|
|
|
|
"ui.-moz_buttonhovertext",
|
|
|
|
"ui.-moz_menuhover",
|
|
|
|
"ui.-moz_menuhovertext",
|
2009-06-15 01:58:14 +04:00
|
|
|
"ui.-moz_menubartext",
|
2008-04-24 12:08:33 +04:00
|
|
|
"ui.-moz_menubarhovertext",
|
|
|
|
"ui.-moz_eventreerow",
|
|
|
|
"ui.-moz_oddtreerow",
|
2021-10-01 22:42:16 +03:00
|
|
|
"ui.-moz-buttonactivetext",
|
|
|
|
"ui.-moz-buttonactiveface",
|
2021-10-05 17:40:52 +03:00
|
|
|
"ui.-moz-buttondisabledface",
|
2009-04-01 00:02:55 +04:00
|
|
|
"ui.-moz_mac_chrome_active",
|
|
|
|
"ui.-moz_mac_chrome_inactive",
|
2014-09-12 03:31:15 +04:00
|
|
|
"ui.-moz-mac-defaultbuttontext",
|
2001-11-06 05:41:04 +03:00
|
|
|
"ui.-moz-mac-focusring",
|
|
|
|
"ui.-moz-mac-menuselect",
|
|
|
|
"ui.-moz-mac-menushadow",
|
2006-07-14 23:54:08 +04:00
|
|
|
"ui.-moz-mac-menutextdisable",
|
2001-11-06 05:41:04 +03:00
|
|
|
"ui.-moz-mac-menutextselect",
|
2009-04-01 00:02:55 +04:00
|
|
|
"ui.-moz_mac_disabledtoolbartext",
|
2008-04-29 23:27:23 +04:00
|
|
|
"ui.-moz-mac-secondaryhighlight",
|
2017-11-16 19:50:09 +03:00
|
|
|
"ui.-moz-mac-vibrant-titlebar-light",
|
|
|
|
"ui.-moz-mac-vibrant-titlebar-dark",
|
2017-09-13 14:48:07 +03:00
|
|
|
"ui.-moz-mac-menupopup",
|
|
|
|
"ui.-moz-mac-menuitem",
|
|
|
|
"ui.-moz-mac-active-menuitem",
|
|
|
|
"ui.-moz-mac-source-list",
|
|
|
|
"ui.-moz-mac-source-list-selection",
|
|
|
|
"ui.-moz-mac-active-source-list-selection",
|
|
|
|
"ui.-moz-mac-tooltip",
|
2021-02-11 19:36:54 +03:00
|
|
|
"ui.-moz-accent-color",
|
|
|
|
"ui.-moz-accent-color-foreground",
|
2021-11-01 00:28:58 +03:00
|
|
|
"ui.-moz-autofill-background",
|
2008-04-29 23:27:23 +04:00
|
|
|
"ui.-moz-win-mediatext",
|
2008-07-11 22:34:53 +04:00
|
|
|
"ui.-moz-win-communicationstext",
|
2009-01-16 11:18:49 +03:00
|
|
|
"ui.-moz-nativehyperlinktext",
|
2021-07-28 20:25:58 +03:00
|
|
|
"ui.-moz-nativevisitedhyperlinktext",
|
2019-11-14 03:17:23 +03:00
|
|
|
"ui.-moz-hyperlinktext",
|
|
|
|
"ui.-moz-activehyperlinktext",
|
|
|
|
"ui.-moz-visitedhyperlinktext",
|
2009-01-16 11:18:49 +03:00
|
|
|
"ui.-moz-comboboxtext",
|
2019-01-09 19:37:34 +03:00
|
|
|
"ui.-moz-combobox",
|
2020-06-03 23:52:55 +03:00
|
|
|
"ui.-moz-colheadertext",
|
2021-05-13 01:52:28 +03:00
|
|
|
"ui.-moz-colheaderhovertext",
|
|
|
|
};
|
2020-06-03 23:52:55 +03:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static_assert(ArrayLength(sColorPrefs) == size_t(LookAndFeel::ColorID::End),
|
|
|
|
"Should have a pref for each color value");
|
|
|
|
|
2021-06-16 17:13:43 +03:00
|
|
|
const char* nsXPLookAndFeel::GetColorPrefName(ColorID aId) {
|
|
|
|
return sColorPrefs[size_t(aId)];
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsXPLookAndFeel::sInitialized = false;
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2017-04-04 17:22:00 +03:00
|
|
|
nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsXPLookAndFeel::sShutdown = false;
|
2011-09-09 06:27:11 +04:00
|
|
|
|
|
|
|
// static
|
|
|
|
nsXPLookAndFeel* nsXPLookAndFeel::GetInstance() {
|
|
|
|
if (sInstance) {
|
2011-09-09 06:27:13 +04:00
|
|
|
return sInstance;
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(!sShutdown, nullptr);
|
2011-09-09 06:27:11 +04:00
|
|
|
|
2020-12-16 07:17:36 +03:00
|
|
|
// If we're in a content process, then the parent process will have supplied
|
2021-03-31 01:58:22 +03:00
|
|
|
// us with an initial FullLookAndFeel object.
|
|
|
|
// We grab this data from the ContentChild,
|
2020-12-16 07:17:36 +03:00
|
|
|
// where it's been temporarily stashed, and initialize our new LookAndFeel
|
|
|
|
// object with it.
|
|
|
|
|
2021-03-31 01:58:22 +03:00
|
|
|
FullLookAndFeel* lnf = nullptr;
|
2020-12-16 07:17:36 +03:00
|
|
|
|
|
|
|
if (auto* cc = mozilla::dom::ContentChild::GetSingleton()) {
|
2021-03-31 01:58:22 +03:00
|
|
|
lnf = &cc->BorrowLookAndFeelData();
|
2020-12-16 07:17:36 +03:00
|
|
|
}
|
|
|
|
|
2021-03-31 01:58:22 +03:00
|
|
|
if (lnf) {
|
|
|
|
sInstance = new widget::RemoteLookAndFeel(std::move(*lnf));
|
2020-12-16 07:17:36 +03:00
|
|
|
} else if (gfxPlatform::IsHeadless()) {
|
2021-03-31 01:58:22 +03:00
|
|
|
sInstance = new widget::HeadlessLookAndFeel();
|
2017-04-04 17:22:00 +03:00
|
|
|
} else {
|
2021-03-31 01:58:22 +03:00
|
|
|
sInstance = new nsLookAndFeel();
|
2020-12-16 07:17:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is only ever used once during initialization, and can be cleared now.
|
2021-03-31 01:58:22 +03:00
|
|
|
if (lnf) {
|
|
|
|
*lnf = {};
|
2017-04-04 17:22:00 +03:00
|
|
|
}
|
2020-12-16 07:17:36 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
nsNativeBasicTheme::Init();
|
2011-09-09 06:27:13 +04:00
|
|
|
return sInstance;
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void nsXPLookAndFeel::Shutdown() {
|
|
|
|
if (sShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-25 01:57:36 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
sShutdown = true;
|
2011-09-09 06:27:13 +04:00
|
|
|
delete sInstance;
|
2012-07-30 18:20:58 +04:00
|
|
|
sInstance = nullptr;
|
2021-03-25 01:57:36 +03:00
|
|
|
|
|
|
|
// This keeps strings alive, so need to clear to make leak checking happy.
|
|
|
|
sFontCache.Clear();
|
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
nsNativeBasicTheme::Shutdown();
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static void IntPrefChanged() {
|
2020-10-27 13:24:40 +03:00
|
|
|
// Int prefs can't change our system colors or fonts.
|
2021-03-18 21:00:26 +03:00
|
|
|
LookAndFeel::NotifyChangedAllWindows(
|
|
|
|
widget::ThemeChangeKind::MediaQueriesOnly);
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static void FloatPrefChanged() {
|
2020-10-27 13:24:40 +03:00
|
|
|
// Float prefs can't change our system colors or fonts.
|
2021-03-18 21:00:26 +03:00
|
|
|
LookAndFeel::NotifyChangedAllWindows(
|
|
|
|
widget::ThemeChangeKind::MediaQueriesOnly);
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
static void ColorPrefChanged() {
|
2020-10-27 13:24:40 +03:00
|
|
|
// Color prefs affect style, because they by definition change system colors.
|
2021-03-18 21:00:26 +03:00
|
|
|
LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind::Style);
|
2000-04-12 02:34:55 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
// static
|
|
|
|
void nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure) {
|
|
|
|
nsDependentCString prefName(aPref);
|
2021-04-02 19:34:35 +03:00
|
|
|
for (const char* pref : sIntPrefs) {
|
|
|
|
if (prefName.Equals(pref)) {
|
|
|
|
IntPrefChanged();
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2005-09-12 16:36:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
for (const char* pref : sFloatPrefs) {
|
|
|
|
if (prefName.Equals(pref)) {
|
|
|
|
FloatPrefChanged();
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2005-09-12 16:36:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
for (const char* pref : sColorPrefs) {
|
2021-11-01 00:29:21 +03:00
|
|
|
// We use StringBeginsWith to handle .dark prefs too.
|
|
|
|
if (StringBeginsWith(prefName, nsDependentCString(pref))) {
|
2021-04-02 19:34:35 +03:00
|
|
|
ColorPrefChanged();
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2000-04-12 02:34:55 +04:00
|
|
|
}
|
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2021-07-02 10:55:24 +03:00
|
|
|
static constexpr struct {
|
|
|
|
nsLiteralCString mName;
|
|
|
|
widget::ThemeChangeKind mChangeKind =
|
|
|
|
widget::ThemeChangeKind::MediaQueriesOnly;
|
|
|
|
} kMediaQueryPrefs[] = {
|
|
|
|
{"browser.display.windows.native_menus"_ns},
|
2021-09-21 02:39:55 +03:00
|
|
|
{"browser.proton.places-tooltip.enabled"_ns},
|
2021-10-17 16:32:02 +03:00
|
|
|
{"layout.css.prefers-color-scheme.content-override"_ns},
|
2021-07-02 10:55:24 +03:00
|
|
|
// This affects not only the media query, but also the native theme, so we
|
|
|
|
// need to re-layout.
|
|
|
|
{"browser.theme.toolbar-theme"_ns, widget::ThemeChangeKind::AllBits},
|
2021-10-20 11:25:57 +03:00
|
|
|
{"browser.theme.content-theme"_ns},
|
|
|
|
{"layout.css.color-scheme.content-override"_ns},
|
2021-04-05 23:48:05 +03:00
|
|
|
};
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
// Read values from the user's preferences.
|
|
|
|
// This is done once at startup, but since the user's preferences
|
|
|
|
// haven't actually been read yet at that time, we also have to
|
|
|
|
// set a callback to inform us of changes to each pref.
|
|
|
|
void nsXPLookAndFeel::Init() {
|
2017-03-23 05:52:53 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
// Say we're already initialized, and take the chance that it might fail;
|
|
|
|
// protects against some other process writing to our static variables.
|
2011-10-17 18:59:28 +04:00
|
|
|
sInitialized = true;
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2021-10-20 11:25:57 +03:00
|
|
|
RecomputeColorSchemes();
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
// XXX If we could reorganize the pref names, we should separate the branch
|
|
|
|
// for each types. Then, we could reduce the unnecessary loop from
|
|
|
|
// nsXPLookAndFeel::OnPrefChanged().
|
2017-03-21 21:59:02 +03:00
|
|
|
Preferences::RegisterPrefixCallback(OnPrefChanged, "ui.");
|
|
|
|
// We really do just want the accessibility.tabfocus pref, not other prefs
|
|
|
|
// that start with that string.
|
2011-09-09 06:27:11 +04:00
|
|
|
Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus");
|
2021-04-05 23:48:05 +03:00
|
|
|
|
2021-04-27 19:20:35 +03:00
|
|
|
for (auto& pref : kMediaQueryPrefs) {
|
2021-04-05 23:48:05 +03:00
|
|
|
Preferences::RegisterCallback(
|
2021-07-02 10:55:24 +03:00
|
|
|
[](const char*, void* aChangeKind) {
|
|
|
|
auto changeKind =
|
|
|
|
widget::ThemeChangeKind(reinterpret_cast<uintptr_t>(aChangeKind));
|
|
|
|
LookAndFeel::NotifyChangedAllWindows(changeKind);
|
2021-04-05 23:48:05 +03:00
|
|
|
},
|
2021-07-02 10:55:24 +03:00
|
|
|
pref.mName, reinterpret_cast<void*>(uintptr_t(pref.mChangeKind)));
|
2021-04-05 23:48:05 +03:00
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXPLookAndFeel::~nsXPLookAndFeel() {
|
2011-09-09 06:27:11 +04:00
|
|
|
NS_ASSERTION(sInstance == this,
|
|
|
|
"This destroying instance isn't the singleton instance");
|
2012-07-30 18:20:58 +04:00
|
|
|
sInstance = nullptr;
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2021-02-13 06:59:22 +03:00
|
|
|
static bool IsSpecialColor(LookAndFeel::ColorID aID, nscolor aColor) {
|
|
|
|
using ColorID = LookAndFeel::ColorID;
|
|
|
|
|
2021-09-02 14:38:01 +03:00
|
|
|
if (aColor == NS_SAME_AS_FOREGROUND_COLOR) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-04 15:28:12 +04:00
|
|
|
switch (aID) {
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::IMESelectedRawTextBackground:
|
|
|
|
case ColorID::IMESelectedConvertedTextBackground:
|
|
|
|
case ColorID::IMERawInputBackground:
|
|
|
|
case ColorID::IMEConvertedTextBackground:
|
|
|
|
case ColorID::IMESelectedRawTextForeground:
|
|
|
|
case ColorID::IMESelectedConvertedTextForeground:
|
|
|
|
case ColorID::IMERawInputForeground:
|
|
|
|
case ColorID::IMEConvertedTextForeground:
|
|
|
|
case ColorID::IMERawInputUnderline:
|
|
|
|
case ColorID::IMEConvertedTextUnderline:
|
|
|
|
case ColorID::IMESelectedRawTextUnderline:
|
|
|
|
case ColorID::IMESelectedConvertedTextUnderline:
|
|
|
|
case ColorID::SpellCheckerUnderline:
|
2009-04-03 11:26:28 +04:00
|
|
|
return NS_IS_SELECTION_SPECIAL_COLOR(aColor);
|
2008-09-16 15:32:03 +04:00
|
|
|
default:
|
2021-02-13 06:59:22 +03:00
|
|
|
break;
|
2007-09-04 15:28:12 +04:00
|
|
|
}
|
2021-02-13 06:59:22 +03:00
|
|
|
/*
|
|
|
|
* In GetColor(), every color that is not a special color is color
|
|
|
|
* corrected. Use false to make other colors color corrected.
|
|
|
|
*/
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-09-04 15:28:12 +04:00
|
|
|
}
|
|
|
|
|
2021-09-29 13:20:56 +03:00
|
|
|
nscolor nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID,
|
|
|
|
ColorScheme aScheme) {
|
|
|
|
if (aScheme == ColorScheme::Dark) {
|
|
|
|
if (auto color = GenericDarkColor(aID)) {
|
|
|
|
return *color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 17:40:52 +03:00
|
|
|
// The stand-in colors are taken from what the non-native theme needs (for
|
|
|
|
// field/button colors), the Windows 7 Aero theme except Mac-specific colors
|
|
|
|
// which are taken from Mac OS 10.7.
|
2021-02-13 06:59:22 +03:00
|
|
|
|
|
|
|
#define COLOR(name_, r, g, b) \
|
|
|
|
case ColorID::name_: \
|
|
|
|
return NS_RGB(r, g, b);
|
|
|
|
|
2021-10-05 17:40:52 +03:00
|
|
|
#define COLORA(name_, r, g, b, a) \
|
|
|
|
case ColorID::name_: \
|
|
|
|
return NS_RGBA(r, g, b, a);
|
|
|
|
|
2015-09-25 01:59:00 +03:00
|
|
|
switch (aID) {
|
2021-11-17 04:24:20 +03:00
|
|
|
// These are here for the purposes of headless mode.
|
|
|
|
case ColorID::IMESelectedRawTextBackground:
|
|
|
|
case ColorID::IMESelectedConvertedTextBackground:
|
|
|
|
case ColorID::IMERawInputBackground:
|
|
|
|
case ColorID::IMEConvertedTextBackground:
|
|
|
|
return NS_TRANSPARENT;
|
|
|
|
case ColorID::IMESelectedRawTextForeground:
|
|
|
|
case ColorID::IMESelectedConvertedTextForeground:
|
|
|
|
case ColorID::IMERawInputForeground:
|
|
|
|
case ColorID::IMEConvertedTextForeground:
|
|
|
|
return NS_SAME_AS_FOREGROUND_COLOR;
|
|
|
|
case ColorID::IMERawInputUnderline:
|
|
|
|
case ColorID::IMEConvertedTextUnderline:
|
|
|
|
return NS_40PERCENT_FOREGROUND_COLOR;
|
|
|
|
COLOR(MozAccentColor, 53, 132, 228)
|
|
|
|
COLOR(MozAccentColorForeground, 0xff, 0xff, 0xff)
|
|
|
|
COLOR(SpellCheckerUnderline, 0xff, 0x00, 0x00)
|
|
|
|
COLOR(TextSelectDisabledBackground, 0xaa, 0xaa, 0xaa)
|
|
|
|
|
2015-09-25 01:59:00 +03:00
|
|
|
// CSS 2 colors:
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(Activeborder, 0xB4, 0xB4, 0xB4)
|
|
|
|
COLOR(Activecaption, 0x99, 0xB4, 0xD1)
|
|
|
|
COLOR(Appworkspace, 0xAB, 0xAB, 0xAB)
|
|
|
|
COLOR(Background, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(Buttonhighlight, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(Buttonshadow, 0xA0, 0xA0, 0xA0)
|
2021-10-05 17:40:52 +03:00
|
|
|
|
|
|
|
// Buttons and comboboxes should be kept in sync since they are drawn with
|
|
|
|
// the same colors by the non-native theme.
|
|
|
|
COLOR(Buttonface, 0xe9, 0xe9, 0xed)
|
|
|
|
COLORA(MozButtondisabledface, 0xe9, 0xe9, 0xed, 128)
|
|
|
|
|
|
|
|
COLOR(MozCombobox, 0xe9, 0xe9, 0xed)
|
|
|
|
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(Buttontext, 0x00, 0x00, 0x00)
|
2021-10-05 17:40:52 +03:00
|
|
|
COLOR(MozComboboxtext, 0x00, 0x00, 0x00)
|
|
|
|
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(Captiontext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(Graytext, 0x6D, 0x6D, 0x6D)
|
|
|
|
COLOR(Highlight, 0x33, 0x99, 0xFF)
|
|
|
|
COLOR(Highlighttext, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(Inactiveborder, 0xF4, 0xF7, 0xFC)
|
|
|
|
COLOR(Inactivecaption, 0xBF, 0xCD, 0xDB)
|
|
|
|
COLOR(Inactivecaptiontext, 0x43, 0x4E, 0x54)
|
|
|
|
COLOR(Infobackground, 0xFF, 0xFF, 0xE1)
|
|
|
|
COLOR(Infotext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(Menu, 0xF0, 0xF0, 0xF0)
|
|
|
|
COLOR(Menutext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(Scrollbar, 0xC8, 0xC8, 0xC8)
|
|
|
|
COLOR(Threeddarkshadow, 0x69, 0x69, 0x69)
|
|
|
|
COLOR(Threedface, 0xF0, 0xF0, 0xF0)
|
|
|
|
COLOR(Threedhighlight, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(Threedlightshadow, 0xE3, 0xE3, 0xE3)
|
|
|
|
COLOR(Threedshadow, 0xA0, 0xA0, 0xA0)
|
|
|
|
COLOR(Window, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(Windowframe, 0x64, 0x64, 0x64)
|
|
|
|
COLOR(Windowtext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozButtondefault, 0x69, 0x69, 0x69)
|
|
|
|
COLOR(Field, 0xFF, 0xFF, 0xFF)
|
2021-10-05 17:40:52 +03:00
|
|
|
COLORA(MozDisabledfield, 0xFF, 0xFF, 0xFF, 128)
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(Fieldtext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozDialog, 0xF0, 0xF0, 0xF0)
|
|
|
|
COLOR(MozDialogtext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozColheadertext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozColheaderhovertext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozDragtargetzone, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(MozCellhighlight, 0xF0, 0xF0, 0xF0)
|
|
|
|
COLOR(MozCellhighlighttext, 0x00, 0x00, 0x00)
|
2021-09-02 14:38:01 +03:00
|
|
|
COLOR(Selecteditem, 0x33, 0x99, 0xFF)
|
|
|
|
COLOR(Selecteditemtext, 0xFF, 0xFF, 0xFF)
|
2021-10-05 17:40:52 +03:00
|
|
|
COLOR(MozButtonhoverface, 0xd0, 0xd0, 0xd7)
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(MozButtonhovertext, 0x00, 0x00, 0x00)
|
2021-10-05 17:40:52 +03:00
|
|
|
COLOR(MozButtonactiveface, 0xb1, 0xb1, 0xb9)
|
2021-10-01 22:42:16 +03:00
|
|
|
COLOR(MozButtonactivetext, 0x00, 0x00, 0x00)
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(MozMenuhover, 0x33, 0x99, 0xFF)
|
|
|
|
COLOR(MozMenuhovertext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozMenubartext, 0x00, 0x00, 0x00)
|
|
|
|
COLOR(MozMenubarhovertext, 0x00, 0x00, 0x00)
|
2021-11-17 04:24:20 +03:00
|
|
|
COLOR(MozEventreerow, 0xFF, 0xFF, 0xFF)
|
2021-02-13 06:59:22 +03:00
|
|
|
COLOR(MozOddtreerow, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(MozMacChromeActive, 0xB2, 0xB2, 0xB2)
|
|
|
|
COLOR(MozMacChromeInactive, 0xE1, 0xE1, 0xE1)
|
|
|
|
COLOR(MozMacFocusring, 0x60, 0x9D, 0xD7)
|
|
|
|
COLOR(MozMacMenuselect, 0x38, 0x75, 0xD7)
|
|
|
|
COLOR(MozMacMenushadow, 0xA3, 0xA3, 0xA3)
|
|
|
|
COLOR(MozMacMenutextdisable, 0x88, 0x88, 0x88)
|
|
|
|
COLOR(MozMacMenutextselect, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(MozMacDisabledtoolbartext, 0x3F, 0x3F, 0x3F)
|
|
|
|
COLOR(MozMacSecondaryhighlight, 0xD4, 0xD4, 0xD4)
|
|
|
|
COLOR(MozMacVibrantTitlebarLight, 0xf7, 0xf7, 0xf7)
|
|
|
|
COLOR(MozMacVibrantTitlebarDark, 0x28, 0x28, 0x28)
|
|
|
|
COLOR(MozMacMenupopup, 0xe6, 0xe6, 0xe6)
|
|
|
|
COLOR(MozMacMenuitem, 0xe6, 0xe6, 0xe6)
|
|
|
|
COLOR(MozMacActiveMenuitem, 0x0a, 0x64, 0xdc)
|
|
|
|
COLOR(MozMacSourceList, 0xf7, 0xf7, 0xf7)
|
|
|
|
COLOR(MozMacSourceListSelection, 0xc8, 0xc8, 0xc8)
|
|
|
|
COLOR(MozMacActiveSourceListSelection, 0x0a, 0x64, 0xdc)
|
|
|
|
COLOR(MozMacTooltip, 0xf7, 0xf7, 0xf7)
|
|
|
|
// Seems to be the default color (hardcoded because of bug 1065998)
|
|
|
|
COLOR(MozWinMediatext, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(MozWinCommunicationstext, 0xFF, 0xFF, 0xFF)
|
|
|
|
COLOR(MozNativehyperlinktext, 0x00, 0x66, 0xCC)
|
2021-07-28 20:25:58 +03:00
|
|
|
COLOR(MozNativevisitedhyperlinktext, 0x55, 0x1A, 0x8B)
|
2021-02-13 06:59:22 +03:00
|
|
|
default:
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
}
|
|
|
|
return NS_RGB(0xFF, 0xFF, 0xFF);
|
|
|
|
}
|
|
|
|
|
2021-09-29 13:20:56 +03:00
|
|
|
#undef COLOR
|
2021-10-05 17:40:52 +03:00
|
|
|
#undef COLORA
|
2021-09-29 13:20:56 +03:00
|
|
|
|
|
|
|
// Taken from in-content/common.inc.css's dark theme.
|
|
|
|
Maybe<nscolor> nsXPLookAndFeel::GenericDarkColor(ColorID aID) {
|
|
|
|
nscolor color = NS_RGB(0, 0, 0);
|
2021-10-05 17:40:52 +03:00
|
|
|
static constexpr nscolor kWindowBackground = NS_RGB(28, 27, 34);
|
|
|
|
static constexpr nscolor kWindowText = NS_RGB(251, 251, 254);
|
2021-09-29 13:20:56 +03:00
|
|
|
switch (aID) {
|
|
|
|
case ColorID::Window: // --in-content-page-background
|
|
|
|
case ColorID::Background:
|
2021-11-01 13:53:36 +03:00
|
|
|
case ColorID::Menu:
|
2021-10-05 17:40:52 +03:00
|
|
|
color = kWindowBackground;
|
2021-09-29 13:20:56 +03:00
|
|
|
break;
|
2021-10-08 13:53:12 +03:00
|
|
|
case ColorID::MozOddtreerow:
|
2021-09-29 13:20:56 +03:00
|
|
|
case ColorID::MozDialog: // --in-content-box-background
|
|
|
|
color = NS_RGB(35, 34, 43);
|
|
|
|
break;
|
|
|
|
case ColorID::Windowtext: // --in-content-page-color
|
2021-11-01 13:53:36 +03:00
|
|
|
case ColorID::Menutext:
|
2021-10-01 22:27:17 +03:00
|
|
|
case ColorID::MozDialogtext:
|
2021-09-29 13:20:56 +03:00
|
|
|
case ColorID::Fieldtext:
|
|
|
|
case ColorID::Buttontext: // --in-content-button-text-color (via
|
|
|
|
// --in-content-page-color)
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::MozComboboxtext:
|
2021-10-01 22:42:16 +03:00
|
|
|
case ColorID::MozButtonhovertext:
|
|
|
|
case ColorID::MozButtonactivetext:
|
2021-10-05 17:40:52 +03:00
|
|
|
color = kWindowText;
|
2021-09-29 13:20:56 +03:00
|
|
|
break;
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::Threedlightshadow: // --in-content-box-border-color computed
|
|
|
|
// with kWindowText above
|
|
|
|
// kWindowBackground.
|
|
|
|
case ColorID::Graytext: // opacity: 0.4 of kWindowText blended over the
|
|
|
|
// "Window" background color, which happens to be
|
|
|
|
// the same :-)
|
|
|
|
color = NS_ComposeColors(kWindowBackground, NS_RGBA(251, 251, 254, 102));
|
2021-09-29 13:20:56 +03:00
|
|
|
break;
|
2021-10-08 13:53:12 +03:00
|
|
|
case ColorID::MozCellhighlight:
|
2021-09-29 13:20:56 +03:00
|
|
|
case ColorID::Selecteditem: // --in-content-primary-button-background /
|
|
|
|
// --in-content-item-selected
|
|
|
|
color = NS_RGB(0, 221, 255);
|
|
|
|
break;
|
|
|
|
case ColorID::Field:
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::Buttonface: // --in-content-button-background
|
|
|
|
case ColorID::MozCombobox:
|
2021-10-08 13:53:12 +03:00
|
|
|
case ColorID::MozCellhighlighttext:
|
2021-09-29 13:20:56 +03:00
|
|
|
case ColorID::Selecteditemtext: // --in-content-primary-button-text-color /
|
|
|
|
// --in-content-item-selected-text
|
|
|
|
color = NS_RGB(43, 42, 51);
|
|
|
|
break;
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::Threeddarkshadow: // Same as Threedlightshadow but with the
|
|
|
|
// background.
|
|
|
|
case ColorID::MozDisabledfield: // opacity: 0.4 of the face above blended
|
|
|
|
// over the "Window" background color.
|
|
|
|
case ColorID::MozButtondisabledface:
|
|
|
|
color = NS_ComposeColors(kWindowBackground, NS_RGBA(43, 42, 51, 102));
|
|
|
|
break;
|
2021-10-01 22:42:16 +03:00
|
|
|
case ColorID::MozButtonhoverface: // --in-content-button-background-hover
|
|
|
|
color = NS_RGB(82, 82, 94);
|
|
|
|
break;
|
|
|
|
case ColorID::MozButtonactiveface: // --in-content-button-background-active
|
|
|
|
color = NS_RGB(91, 91, 102);
|
|
|
|
break;
|
2021-10-01 19:23:13 +03:00
|
|
|
case ColorID::Highlight:
|
|
|
|
color = NS_RGBA(0, 221, 255, 153);
|
|
|
|
break;
|
|
|
|
case ColorID::Highlighttext:
|
|
|
|
color = NS_SAME_AS_FOREGROUND_COLOR;
|
|
|
|
break;
|
2021-11-02 13:45:04 +03:00
|
|
|
case ColorID::MozNativehyperlinktext:
|
|
|
|
// If you change this color, you probably also want to change the default
|
|
|
|
// value of browser.anchor_color.dark.
|
2021-11-09 17:33:53 +03:00
|
|
|
color = NS_RGB(0x8c, 0x8c, 0xff);
|
2021-11-02 13:45:04 +03:00
|
|
|
break;
|
|
|
|
case ColorID::MozNativevisitedhyperlinktext:
|
|
|
|
// If you change this color, you probably also want to change the default
|
|
|
|
// value of browser.visited_color.dark.
|
2021-11-09 17:33:53 +03:00
|
|
|
color = NS_RGB(0xff, 0xad, 0xff);
|
2021-11-02 13:45:04 +03:00
|
|
|
break;
|
|
|
|
|
2021-09-29 13:20:56 +03:00
|
|
|
default:
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
return Some(color);
|
|
|
|
}
|
|
|
|
|
2021-02-13 06:59:22 +03:00
|
|
|
// Uncomment the #define below if you want to debug system color use in a skin
|
|
|
|
// that uses them. When set, it will make all system color pairs that are
|
|
|
|
// appropriate for foreground/background pairing the same. This means if the
|
|
|
|
// skin is using system colors correctly you will not be able to see *any* text.
|
|
|
|
//
|
|
|
|
// #define DEBUG_SYSTEM_COLOR_USE
|
|
|
|
|
|
|
|
#ifdef DEBUG_SYSTEM_COLOR_USE
|
|
|
|
static nsresult SystemColorUseDebuggingColor(LookAndFeel::ColorID aID,
|
|
|
|
nscolor& aResult) {
|
|
|
|
using ColorID = LookAndFeel::ColorID;
|
|
|
|
|
|
|
|
switch (aID) {
|
|
|
|
// css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Activecaption:
|
2021-02-13 06:59:22 +03:00
|
|
|
// active window caption background
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Captiontext:
|
2021-02-13 06:59:22 +03:00
|
|
|
// text in active window caption
|
|
|
|
aResult = NS_RGB(0xff, 0x00, 0x00);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Highlight:
|
2021-02-13 06:59:22 +03:00
|
|
|
// background of selected item
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Highlighttext:
|
2021-02-13 06:59:22 +03:00
|
|
|
// text of selected item
|
|
|
|
aResult = NS_RGB(0xff, 0xff, 0x00);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Inactivecaption:
|
2021-02-13 06:59:22 +03:00
|
|
|
// inactive window caption
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Inactivecaptiontext:
|
2021-02-13 06:59:22 +03:00
|
|
|
// text in inactive window caption
|
|
|
|
aResult = NS_RGB(0x66, 0x66, 0x00);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Infobackground:
|
2021-02-13 06:59:22 +03:00
|
|
|
// tooltip background color
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Infotext:
|
2021-02-13 06:59:22 +03:00
|
|
|
// tooltip text color
|
|
|
|
aResult = NS_RGB(0x00, 0xff, 0x00);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Menu:
|
2021-02-13 06:59:22 +03:00
|
|
|
// menu background
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Menutext:
|
2021-02-13 06:59:22 +03:00
|
|
|
// menu text
|
|
|
|
aResult = NS_RGB(0x00, 0xff, 0xff);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threedface:
|
2021-02-13 06:59:22 +03:00
|
|
|
case ColorID::Buttonface:
|
|
|
|
// 3-D face color
|
|
|
|
case ColorID::Buttontext:
|
|
|
|
// text on push buttons
|
|
|
|
aResult = NS_RGB(0x00, 0x66, 0x66);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Window:
|
|
|
|
case ColorID::Windowtext:
|
2021-02-13 06:59:22 +03:00
|
|
|
aResult = NS_RGB(0x00, 0x00, 0xff);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
|
|
|
// from the CSS3 working draft (not yet finalized)
|
|
|
|
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
|
|
|
|
|
2019-11-03 00:28:49 +03:00
|
|
|
case ColorID::Field:
|
|
|
|
case ColorID::Fieldtext:
|
2021-02-13 06:59:22 +03:00
|
|
|
aResult = NS_RGB(0xff, 0x00, 0xff);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozDialog:
|
|
|
|
case ColorID::MozDialogtext:
|
2021-02-13 06:59:22 +03:00
|
|
|
aResult = NS_RGB(0x66, 0x00, 0x66);
|
2015-09-25 01:59:00 +03:00
|
|
|
break;
|
2021-02-13 06:59:22 +03:00
|
|
|
|
2015-09-25 01:59:00 +03:00
|
|
|
default:
|
2021-02-13 06:59:22 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2015-09-25 01:59:00 +03:00
|
|
|
}
|
|
|
|
|
2021-02-13 06:59:22 +03:00
|
|
|
return NS_OK;
|
2015-09-25 01:59:00 +03:00
|
|
|
}
|
2021-02-13 06:59:22 +03:00
|
|
|
#endif
|
2015-09-25 01:59:00 +03:00
|
|
|
|
2021-11-01 00:29:21 +03:00
|
|
|
static nsresult GetPrefColor(const char* aPref, nscolor& aResult) {
|
2021-04-02 20:43:08 +03:00
|
|
|
nsAutoCString colorStr;
|
2021-11-01 00:29:21 +03:00
|
|
|
MOZ_TRY(Preferences::GetCString(aPref, colorStr));
|
2021-04-02 20:43:08 +03:00
|
|
|
if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), colorStr,
|
|
|
|
&aResult)) {
|
2021-04-02 19:34:35 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2021-04-02 20:43:08 +03:00
|
|
|
return NS_OK;
|
2021-04-02 19:34:35 +03:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:29:21 +03:00
|
|
|
static nsresult GetColorFromPref(LookAndFeel::ColorID aID, ColorScheme aScheme,
|
|
|
|
nscolor& aResult) {
|
|
|
|
const char* prefName = sColorPrefs[size_t(aID)];
|
|
|
|
if (aScheme == ColorScheme::Dark) {
|
|
|
|
nsAutoCString darkPrefName(prefName);
|
|
|
|
darkPrefName.Append(".dark");
|
|
|
|
if (NS_SUCCEEDED(GetPrefColor(darkPrefName.get(), aResult))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GetPrefColor(prefName, aResult);
|
|
|
|
}
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
// All these routines will return NS_OK if they have a value,
|
|
|
|
// in which case the nsLookAndFeel should use that value;
|
|
|
|
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
|
|
|
|
// platform-specific nsLookAndFeel should use its own values instead.
|
2021-04-02 19:34:35 +03:00
|
|
|
nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, ColorScheme aScheme,
|
|
|
|
UseStandins aUseStandins,
|
2020-11-21 02:52:47 +03:00
|
|
|
nscolor& aResult) {
|
2021-02-13 06:59:22 +03:00
|
|
|
if (!sInitialized) {
|
|
|
|
Init();
|
|
|
|
}
|
2001-04-17 04:46:07 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_SYSTEM_COLOR_USE
|
2021-02-13 06:59:22 +03:00
|
|
|
if (NS_SUCCEEDED(SystemColorUseDebuggingColor(aID, aResult))) {
|
|
|
|
return NS_OK;
|
2001-04-17 04:46:07 +04:00
|
|
|
}
|
2021-02-13 06:59:22 +03:00
|
|
|
#endif
|
2001-04-17 04:46:07 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
if (aUseStandins == UseStandins::Yes) {
|
2021-09-29 13:20:56 +03:00
|
|
|
aResult = GetStandinForNativeColor(aID, aScheme);
|
2021-04-02 19:34:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-09-25 01:59:00 +03:00
|
|
|
|
2021-04-03 01:17:55 +03:00
|
|
|
auto& cache =
|
|
|
|
aScheme == ColorScheme::Light ? sLightColorCache : sDarkColorCache;
|
|
|
|
if (const auto* cached = cache.Get(aID)) {
|
2021-04-02 19:34:35 +03:00
|
|
|
if (cached->isNothing()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2021-03-19 00:04:52 +03:00
|
|
|
}
|
2021-04-02 19:34:35 +03:00
|
|
|
aResult = cached->value();
|
|
|
|
return NS_OK;
|
2001-11-06 05:41:04 +03:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:29:21 +03:00
|
|
|
if (NS_SUCCEEDED(GetColorFromPref(aID, aScheme, aResult))) {
|
2021-04-03 01:17:55 +03:00
|
|
|
cache.Insert(aID, Some(aResult));
|
2015-09-25 01:59:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-03 01:17:55 +03:00
|
|
|
if (NS_SUCCEEDED(NativeGetColor(aID, aScheme, aResult))) {
|
2021-03-08 21:12:07 +03:00
|
|
|
if (gfxPlatform::GetCMSMode() == CMSMode::All &&
|
|
|
|
!IsSpecialColor(aID, aResult)) {
|
|
|
|
qcms_transform* transform = gfxPlatform::GetCMSInverseRGBTransform();
|
|
|
|
if (transform) {
|
|
|
|
uint8_t color[4];
|
|
|
|
color[0] = NS_GET_R(aResult);
|
|
|
|
color[1] = NS_GET_G(aResult);
|
|
|
|
color[2] = NS_GET_B(aResult);
|
|
|
|
color[3] = NS_GET_A(aResult);
|
|
|
|
qcms_transform_data(transform, color, color, 1);
|
|
|
|
aResult = NS_RGBA(color[0], color[1], color[2], color[3]);
|
2017-05-05 09:22:51 +03:00
|
|
|
}
|
2021-03-08 05:47:16 +03:00
|
|
|
}
|
2021-03-08 21:12:07 +03:00
|
|
|
|
|
|
|
// NOTE: Servo holds a lock and the main thread is paused, so writing to the
|
|
|
|
// global cache here is fine.
|
2021-04-03 01:17:55 +03:00
|
|
|
cache.Insert(aID, Some(aResult));
|
2001-11-06 05:41:04 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-12 02:34:55 +04:00
|
|
|
|
2021-04-03 01:17:55 +03:00
|
|
|
cache.Insert(aID, Nothing());
|
2021-04-02 19:34:35 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
2016-07-20 18:29:36 +03:00
|
|
|
|
2020-11-21 02:52:47 +03:00
|
|
|
nsresult nsXPLookAndFeel::GetIntValue(IntID aID, int32_t& aResult) {
|
2021-03-25 01:57:36 +03:00
|
|
|
if (!sInitialized) {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
if (const auto* cached = sIntCache.Get(aID)) {
|
|
|
|
if (cached->isNothing()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
aResult = cached->value();
|
2021-03-25 01:57:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(sIntPrefs[size_t(aID)], &aResult))) {
|
|
|
|
sIntCache.Insert(aID, Some(aResult));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(NativeGetInt(aID, aResult))) {
|
|
|
|
sIntCache.Insert(aID, Nothing());
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-05-23 18:54:03 +04:00
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
sIntCache.Insert(aID, Some(aResult));
|
2021-03-25 01:57:36 +03:00
|
|
|
return NS_OK;
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2020-11-21 02:52:47 +03:00
|
|
|
nsresult nsXPLookAndFeel::GetFloatValue(FloatID aID, float& aResult) {
|
2021-03-25 01:57:36 +03:00
|
|
|
if (!sInitialized) {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
if (const auto* cached = sFloatCache.Get(aID)) {
|
|
|
|
if (cached->isNothing()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
aResult = cached->value();
|
2021-03-25 01:57:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
int32_t pref = 0;
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(sFloatPrefs[size_t(aID)], &pref))) {
|
|
|
|
aResult = float(pref) / 100.0f;
|
|
|
|
sFloatCache.Insert(aID, Some(aResult));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(NativeGetFloat(aID, aResult))) {
|
|
|
|
sFloatCache.Insert(aID, Nothing());
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-05-23 18:54:03 +04:00
|
|
|
}
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2021-04-02 19:34:35 +03:00
|
|
|
sFloatCache.Insert(aID, Some(aResult));
|
2021-03-25 01:57:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsXPLookAndFeel::LookAndFeelFontToStyle(const LookAndFeelFont& aFont,
|
|
|
|
nsString& aName,
|
|
|
|
gfxFontStyle& aStyle) {
|
|
|
|
if (!aFont.haveFont()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aName = aFont.name();
|
|
|
|
aStyle = gfxFontStyle();
|
|
|
|
aStyle.size = aFont.size();
|
|
|
|
aStyle.weight = FontWeight(aFont.weight());
|
|
|
|
aStyle.style =
|
|
|
|
aFont.italic() ? FontSlantStyle::Italic() : FontSlantStyle::Normal();
|
2021-04-06 16:42:57 +03:00
|
|
|
aStyle.systemFont = true;
|
2021-03-25 01:57:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget::LookAndFeelFont nsXPLookAndFeel::StyleToLookAndFeelFont(
|
|
|
|
const nsAString& aName, const gfxFontStyle& aStyle) {
|
|
|
|
LookAndFeelFont font;
|
|
|
|
font.haveFont() = true;
|
|
|
|
font.name() = aName;
|
|
|
|
font.size() = aStyle.size;
|
|
|
|
font.weight() = aStyle.weight.ToFloat();
|
|
|
|
font.italic() = aStyle.style.IsItalic();
|
|
|
|
MOZ_ASSERT(aStyle.style.IsNormal() || aStyle.style.IsItalic(),
|
|
|
|
"Cannot handle oblique font style");
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
// Assert that all the remaining font style properties have their
|
|
|
|
// default values.
|
|
|
|
gfxFontStyle candidate = aStyle;
|
|
|
|
gfxFontStyle defaults{};
|
|
|
|
candidate.size = defaults.size;
|
|
|
|
candidate.weight = defaults.weight;
|
|
|
|
candidate.style = defaults.style;
|
|
|
|
MOZ_ASSERT(candidate.Equals(defaults),
|
|
|
|
"Some font style properties not supported");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsXPLookAndFeel::GetFontValue(FontID aID, nsString& aName,
|
|
|
|
gfxFontStyle& aStyle) {
|
|
|
|
if (const LookAndFeelFont* cached = sFontCache.Get(aID)) {
|
|
|
|
return LookAndFeelFontToStyle(*cached, aName, aStyle);
|
|
|
|
}
|
|
|
|
LookAndFeelFont font;
|
|
|
|
const bool haveFont = NativeGetFont(aID, aName, aStyle);
|
|
|
|
font.haveFont() = haveFont;
|
|
|
|
if (haveFont) {
|
|
|
|
font = StyleToLookAndFeelFont(aName, aStyle);
|
|
|
|
}
|
|
|
|
sFontCache.Insert(aID, std::move(font));
|
|
|
|
return haveFont;
|
2000-03-31 02:32:18 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
void nsXPLookAndFeel::RefreshImpl() {
|
2021-03-25 01:57:36 +03:00
|
|
|
// Wipe out our caches.
|
2021-04-03 01:17:55 +03:00
|
|
|
sLightColorCache.Clear();
|
|
|
|
sDarkColorCache.Clear();
|
2021-03-25 01:57:36 +03:00
|
|
|
sFontCache.Clear();
|
|
|
|
sFloatCache.Clear();
|
|
|
|
sIntCache.Clear();
|
2021-10-20 11:25:57 +03:00
|
|
|
RecomputeColorSchemes();
|
2019-09-19 22:05:01 +03:00
|
|
|
|
2020-12-16 07:41:46 +03:00
|
|
|
// Clear any cached FullLookAndFeel data, which is now invalid.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
widget::RemoteLookAndFeel::ClearCachedData();
|
|
|
|
}
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2019-12-20 22:05:12 +03:00
|
|
|
static bool sRecordedLookAndFeelTelemetry = false;
|
|
|
|
|
|
|
|
void nsXPLookAndFeel::RecordTelemetry() {
|
2020-10-15 07:50:48 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-20 22:05:12 +03:00
|
|
|
if (sRecordedLookAndFeelTelemetry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sRecordedLookAndFeelTelemetry = true;
|
|
|
|
|
|
|
|
int32_t i;
|
|
|
|
Telemetry::ScalarSet(
|
|
|
|
Telemetry::ScalarID::WIDGET_DARK_MODE,
|
2020-11-21 02:52:47 +03:00
|
|
|
NS_SUCCEEDED(GetIntValue(IntID::SystemUsesDarkTheme, i)) && i != 0);
|
2020-10-15 07:50:48 +03:00
|
|
|
|
|
|
|
RecordLookAndFeelSpecificTelemetry();
|
2019-12-20 22:05:12 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2020-05-23 02:03:43 +03:00
|
|
|
// static
|
2020-10-27 13:24:40 +03:00
|
|
|
void LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind aKind) {
|
2020-05-23 02:03:43 +03:00
|
|
|
if (nsCOMPtr<nsIObserverService> obs = services::GetObserverService()) {
|
2021-05-13 02:53:08 +03:00
|
|
|
const char16_t kind[] = {char16_t(aKind), 0};
|
2021-10-12 12:22:49 +03:00
|
|
|
obs->NotifyObservers(nullptr, "internal-look-and-feel-changed", kind);
|
2020-05-23 02:03:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 15:22:14 +03:00
|
|
|
static bool ShouldUseStandinsForNativeColorForNonNativeTheme(
|
|
|
|
const dom::Document& aDoc, LookAndFeel::ColorID aColor) {
|
|
|
|
using ColorID = LookAndFeel::ColorID;
|
|
|
|
if (!aDoc.ShouldAvoidNativeTheme()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-05 17:40:52 +03:00
|
|
|
// The native theme doesn't use native system colors backgrounds etc, except
|
|
|
|
// when in high-contrast mode, so spoof some of the colors with stand-ins to
|
|
|
|
// prevent lack of contrast.
|
2021-04-02 15:22:14 +03:00
|
|
|
switch (aColor) {
|
|
|
|
case ColorID::Buttonface:
|
|
|
|
case ColorID::Buttontext:
|
|
|
|
case ColorID::MozButtonhoverface:
|
|
|
|
case ColorID::MozButtonhovertext:
|
2021-10-01 22:42:16 +03:00
|
|
|
case ColorID::MozButtonactiveface:
|
|
|
|
case ColorID::MozButtonactivetext:
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::MozButtondisabledface:
|
|
|
|
|
|
|
|
case ColorID::Threedlightshadow:
|
|
|
|
case ColorID::Threeddarkshadow:
|
|
|
|
case ColorID::Threedface:
|
2021-04-02 15:22:14 +03:00
|
|
|
|
|
|
|
case ColorID::MozCombobox:
|
|
|
|
case ColorID::MozComboboxtext:
|
|
|
|
|
|
|
|
case ColorID::Field:
|
2021-10-05 17:40:52 +03:00
|
|
|
case ColorID::MozDisabledfield:
|
2021-04-02 15:22:14 +03:00
|
|
|
case ColorID::Fieldtext:
|
|
|
|
|
|
|
|
case ColorID::Graytext:
|
|
|
|
|
|
|
|
return !PreferenceSheet::PrefsFor(aDoc)
|
2021-10-05 17:40:52 +03:00
|
|
|
.NonNativeThemeShouldBeHighContrast();
|
2021-04-02 15:22:14 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-20 11:25:57 +03:00
|
|
|
ColorScheme LookAndFeel::sChromeColorScheme;
|
|
|
|
ColorScheme LookAndFeel::sContentColorScheme;
|
2021-11-24 19:50:38 +03:00
|
|
|
bool LookAndFeel::sColorSchemeInitialized;
|
2021-10-20 11:25:57 +03:00
|
|
|
|
|
|
|
auto LookAndFeel::ColorSchemeSettingForChrome() -> ChromeColorSchemeSetting {
|
2021-10-15 19:53:08 +03:00
|
|
|
switch (StaticPrefs::browser_theme_toolbar_theme()) {
|
|
|
|
case 0: // Dark
|
2021-10-20 11:25:57 +03:00
|
|
|
return ChromeColorSchemeSetting::Dark;
|
2021-10-15 19:53:08 +03:00
|
|
|
case 1: // Light
|
2021-10-20 11:25:57 +03:00
|
|
|
return ChromeColorSchemeSetting::Light;
|
2021-10-15 19:53:08 +03:00
|
|
|
default:
|
2021-10-20 11:25:57 +03:00
|
|
|
return ChromeColorSchemeSetting::System;
|
2021-07-28 13:34:02 +03:00
|
|
|
}
|
2021-10-20 11:25:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void LookAndFeel::RecomputeColorSchemes() {
|
2021-11-24 19:50:38 +03:00
|
|
|
sColorSchemeInitialized = true;
|
|
|
|
|
2021-10-20 11:25:57 +03:00
|
|
|
sChromeColorScheme = [] {
|
|
|
|
switch (ColorSchemeSettingForChrome()) {
|
|
|
|
case ChromeColorSchemeSetting::Light:
|
|
|
|
return ColorScheme::Light;
|
|
|
|
case ChromeColorSchemeSetting::Dark:
|
|
|
|
return ColorScheme::Dark;
|
|
|
|
case ChromeColorSchemeSetting::System:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SystemColorScheme();
|
|
|
|
}();
|
|
|
|
|
|
|
|
sContentColorScheme = [] {
|
|
|
|
switch (StaticPrefs::layout_css_prefers_color_scheme_content_override()) {
|
|
|
|
case 0:
|
|
|
|
return ColorScheme::Dark;
|
|
|
|
case 1:
|
|
|
|
return ColorScheme::Light;
|
|
|
|
case 2:
|
|
|
|
return SystemColorScheme();
|
|
|
|
default:
|
|
|
|
break; // Use the browser theme.
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (StaticPrefs::browser_theme_content_theme()) {
|
|
|
|
case 0: // Dark
|
|
|
|
return ColorScheme::Dark;
|
|
|
|
case 1: // Light
|
|
|
|
return ColorScheme::Light;
|
|
|
|
default:
|
|
|
|
return ColorSchemeForChrome();
|
|
|
|
}
|
|
|
|
}();
|
2021-07-27 18:50:48 +03:00
|
|
|
}
|
|
|
|
|
2021-10-15 19:53:08 +03:00
|
|
|
ColorScheme LookAndFeel::ColorSchemeForStyle(
|
2021-07-27 18:50:48 +03:00
|
|
|
const dom::Document& aDoc, const StyleColorSchemeFlags& aFlags) {
|
2021-11-17 01:30:26 +03:00
|
|
|
if (PreferenceSheet::MayForceColors()) {
|
|
|
|
auto& prefs = PreferenceSheet::PrefsFor(aDoc);
|
|
|
|
if (!prefs.mUseDocumentColors) {
|
|
|
|
// When forcing colors, we can use our preferred color-scheme. Do this
|
|
|
|
// only if we're using system colors, as dark preference colors are not
|
|
|
|
// exposed on the UI.
|
|
|
|
//
|
|
|
|
// Also, use light if we're using a high-contrast-theme on Windows, since
|
|
|
|
// Windows overrides the light colors with HCM colors when HCM is active.
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (prefs.mUseAccessibilityTheme) {
|
|
|
|
return ColorScheme::Light;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (StaticPrefs::browser_display_use_system_colors()) {
|
|
|
|
return aDoc.PreferredColorScheme();
|
|
|
|
}
|
|
|
|
return ColorScheme::Light;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 18:50:48 +03:00
|
|
|
StyleColorSchemeFlags style(aFlags);
|
|
|
|
if (!style) {
|
|
|
|
style.bits = aDoc.GetColorSchemeBits();
|
|
|
|
}
|
|
|
|
const bool supportsDark = bool(style & StyleColorSchemeFlags::DARK);
|
|
|
|
const bool supportsLight = bool(style & StyleColorSchemeFlags::LIGHT);
|
2021-10-15 19:53:08 +03:00
|
|
|
if (supportsLight && supportsDark) {
|
|
|
|
// Both color-schemes are explicitly supported, use the preferred one.
|
|
|
|
return aDoc.PreferredColorScheme();
|
|
|
|
}
|
|
|
|
if (supportsDark || supportsLight) {
|
|
|
|
// One color-scheme is explicitly supported and one isn't, so use the one
|
|
|
|
// the content supports.
|
|
|
|
return supportsDark ? ColorScheme::Dark : ColorScheme::Light;
|
2021-07-27 18:50:48 +03:00
|
|
|
}
|
2021-10-20 11:25:57 +03:00
|
|
|
// No value specified. Chrome docs always supports both, so use the preferred
|
2021-10-15 19:53:08 +03:00
|
|
|
// color-scheme.
|
|
|
|
if (nsContentUtils::IsChromeDoc(&aDoc)) {
|
2021-10-20 11:25:57 +03:00
|
|
|
return aDoc.PreferredColorScheme();
|
2021-07-27 18:50:48 +03:00
|
|
|
}
|
2021-10-15 19:53:08 +03:00
|
|
|
// As an special-case, use the system color-scheme if allow-gtk-dark-theme is
|
|
|
|
// set.
|
|
|
|
//
|
|
|
|
// TODO(emilio): Once we ship the color-scheme property and meta tag I think
|
|
|
|
// this can go. The use case for this is sidebars and such (bug 1721359),
|
|
|
|
// which will be able to just use <meta name=color-scheme value="light dark">
|
|
|
|
// to state that they support light and dark color schemes (taking the
|
|
|
|
// PreferredColorScheme codepath above).
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
if (StaticPrefs::widget_content_allow_gtk_dark_theme()) {
|
|
|
|
return SystemColorScheme();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Default content to light.
|
|
|
|
return ColorScheme::Light;
|
2021-07-27 18:50:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LookAndFeel::ColorScheme LookAndFeel::ColorSchemeForFrame(
|
|
|
|
const nsIFrame* aFrame) {
|
|
|
|
return ColorSchemeForStyle(*aFrame->PresContext()->Document(),
|
|
|
|
aFrame->StyleUI()->mColorScheme.bits);
|
2021-04-02 15:22:14 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
// static
|
2021-04-02 19:34:35 +03:00
|
|
|
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, ColorScheme aScheme,
|
2021-04-02 15:22:14 +03:00
|
|
|
UseStandins aUseStandins) {
|
|
|
|
nscolor result;
|
|
|
|
nsresult rv = nsLookAndFeel::GetInstance()->GetColorValue(
|
2021-04-02 19:34:35 +03:00
|
|
|
aId, aScheme, aUseStandins, result);
|
2021-04-02 15:22:14 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
return Some(result);
|
|
|
|
}
|
|
|
|
|
2021-04-02 19:34:34 +03:00
|
|
|
// Returns whether there is a CSS color name for this color.
|
|
|
|
static bool ColorIsCSSAccessible(LookAndFeel::ColorID aId) {
|
|
|
|
using ColorID = LookAndFeel::ColorID;
|
|
|
|
|
|
|
|
switch (aId) {
|
2021-11-11 14:14:13 +03:00
|
|
|
case ColorID::TextSelectDisabledBackground:
|
|
|
|
case ColorID::TextSelectAttentionBackground:
|
|
|
|
case ColorID::TextSelectAttentionForeground:
|
2021-04-02 19:34:34 +03:00
|
|
|
case ColorID::TextHighlightBackground:
|
|
|
|
case ColorID::TextHighlightForeground:
|
2021-09-16 22:06:09 +03:00
|
|
|
case ColorID::ThemedScrollbar:
|
|
|
|
case ColorID::ThemedScrollbarInactive:
|
|
|
|
case ColorID::ThemedScrollbarThumb:
|
|
|
|
case ColorID::ThemedScrollbarThumbActive:
|
|
|
|
case ColorID::ThemedScrollbarThumbInactive:
|
|
|
|
case ColorID::ThemedScrollbarThumbHover:
|
2021-04-02 19:34:34 +03:00
|
|
|
case ColorID::IMERawInputBackground:
|
|
|
|
case ColorID::IMERawInputForeground:
|
|
|
|
case ColorID::IMERawInputUnderline:
|
|
|
|
case ColorID::IMESelectedRawTextBackground:
|
|
|
|
case ColorID::IMESelectedRawTextForeground:
|
|
|
|
case ColorID::IMESelectedRawTextUnderline:
|
|
|
|
case ColorID::IMEConvertedTextBackground:
|
|
|
|
case ColorID::IMEConvertedTextForeground:
|
|
|
|
case ColorID::IMEConvertedTextUnderline:
|
|
|
|
case ColorID::IMESelectedConvertedTextBackground:
|
|
|
|
case ColorID::IMESelectedConvertedTextForeground:
|
|
|
|
case ColorID::IMESelectedConvertedTextUnderline:
|
|
|
|
case ColorID::SpellCheckerUnderline:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-14 18:01:25 +03:00
|
|
|
LookAndFeel::UseStandins LookAndFeel::ShouldUseStandins(
|
|
|
|
const dom::Document& aDoc, ColorID aId) {
|
2021-07-25 00:10:44 +03:00
|
|
|
if (ShouldUseStandinsForNativeColorForNonNativeTheme(aDoc, aId)) {
|
|
|
|
return UseStandins::Yes;
|
|
|
|
}
|
2021-10-05 17:40:52 +03:00
|
|
|
if (nsContentUtils::UseStandinsForNativeColors() &&
|
|
|
|
ColorIsCSSAccessible(aId) && !nsContentUtils::IsChromeDoc(&aDoc)) {
|
2021-07-25 00:10:44 +03:00
|
|
|
return UseStandins::Yes;
|
|
|
|
}
|
|
|
|
if (aDoc.IsStaticDocument() &&
|
|
|
|
!PreferenceSheet::ContentPrefs().mUseDocumentColors) {
|
|
|
|
return UseStandins::Yes;
|
|
|
|
}
|
|
|
|
return UseStandins::No;
|
2021-06-14 18:01:25 +03:00
|
|
|
}
|
|
|
|
|
2021-04-02 15:22:14 +03:00
|
|
|
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, const nsIFrame* aFrame) {
|
2021-07-27 18:50:48 +03:00
|
|
|
const auto* doc = aFrame->PresContext()->Document();
|
|
|
|
return GetColor(aId, ColorSchemeForFrame(aFrame),
|
|
|
|
ShouldUseStandins(*doc, aId));
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult LookAndFeel::GetInt(IntID aID, int32_t* aResult) {
|
2020-11-21 02:52:47 +03:00
|
|
|
return nsLookAndFeel::GetInstance()->GetIntValue(aID, *aResult);
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult LookAndFeel::GetFloat(FloatID aID, float* aResult) {
|
2020-11-21 02:52:47 +03:00
|
|
|
return nsLookAndFeel::GetInstance()->GetFloatValue(aID, *aResult);
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 03:19:48 +04:00
|
|
|
// static
|
2019-02-08 16:22:11 +03:00
|
|
|
bool LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle) {
|
2020-11-21 02:52:47 +03:00
|
|
|
return nsLookAndFeel::GetInstance()->GetFontValue(aID, aName, aStyle);
|
2012-02-21 03:19:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
// static
|
|
|
|
char16_t LookAndFeel::GetPasswordCharacter() {
|
2011-09-09 06:27:13 +04:00
|
|
|
return nsLookAndFeel::GetInstance()->GetPasswordCharacterImpl();
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool LookAndFeel::GetEchoPassword() {
|
2019-07-22 06:55:13 +03:00
|
|
|
if (StaticPrefs::editor_password_mask_delay() >= 0) {
|
|
|
|
return StaticPrefs::editor_password_mask_delay() > 0;
|
|
|
|
}
|
2011-09-09 06:27:13 +04:00
|
|
|
return nsLookAndFeel::GetInstance()->GetEchoPasswordImpl();
|
2011-09-09 06:27:11 +04:00
|
|
|
}
|
|
|
|
|
2012-07-13 06:26:20 +04:00
|
|
|
// static
|
|
|
|
uint32_t LookAndFeel::GetPasswordMaskDelay() {
|
2019-07-22 06:55:13 +03:00
|
|
|
int32_t delay = StaticPrefs::editor_password_mask_delay();
|
|
|
|
if (delay < 0) {
|
|
|
|
return nsLookAndFeel::GetInstance()->GetPasswordMaskDelayImpl();
|
|
|
|
}
|
|
|
|
return delay;
|
2012-07-13 06:26:20 +04:00
|
|
|
}
|
|
|
|
|
2021-10-21 12:07:12 +03:00
|
|
|
bool LookAndFeel::DrawInTitlebar() {
|
2021-11-11 00:17:32 +03:00
|
|
|
switch (StaticPrefs::browser_tabs_inTitlebar()) {
|
2021-10-21 12:07:12 +03:00
|
|
|
case 0:
|
|
|
|
return false;
|
|
|
|
case 1:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nsLookAndFeel::GetInstance()->GetDefaultDrawInTitlebar();
|
|
|
|
}
|
|
|
|
|
2021-07-20 23:09:09 +03:00
|
|
|
void LookAndFeel::GetThemeInfo(nsACString& aOut) {
|
|
|
|
nsLookAndFeel::GetInstance()->GetThemeInfo(aOut);
|
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
// static
|
2021-02-10 03:47:38 +03:00
|
|
|
void LookAndFeel::Refresh() {
|
|
|
|
nsLookAndFeel::GetInstance()->RefreshImpl();
|
|
|
|
nsNativeBasicTheme::LookAndFeelChanged();
|
|
|
|
}
|
2011-09-09 06:27:11 +04:00
|
|
|
|
2017-08-03 23:16:31 +03:00
|
|
|
// static
|
|
|
|
void LookAndFeel::NativeInit() { nsLookAndFeel::GetInstance()->NativeInit(); }
|
|
|
|
|
2020-12-16 07:17:36 +03:00
|
|
|
// static
|
|
|
|
void LookAndFeel::SetData(widget::FullLookAndFeel&& aTables) {
|
|
|
|
nsLookAndFeel::GetInstance()->SetDataImpl(std::move(aTables));
|
|
|
|
}
|
|
|
|
|
2020-10-15 07:50:48 +03:00
|
|
|
} // namespace mozilla
|