Bug 1530193 - Refactor preference stylesheet prefs to not require a pres context. r=jwatt

We really only have two sets of prefs, one for chrome-like documents
(stuff in chrome docshells + chrome-origin images), and one for the rest.

Differential Revision: https://phabricator.services.mozilla.com/D20946

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-03-06 21:34:30 +00:00
Родитель 8e84ea1e71
Коммит 8c9a745531
17 изменённых файлов: 300 добавлений и 234 удалений

Просмотреть файл

@ -1444,19 +1444,13 @@ void nsIPresShell::UpdatePreferenceStyles() {
return;
}
// We need to pass in mPresContext so that if the nsLayoutStylesheetCache
// needs to recreate the pref style sheet, it has somewhere to get the
// pref styling information from. All pres contexts for
// IsChromeOriginImage() == false will have the same pref styling information,
// and similarly for IsChromeOriginImage() == true, so it doesn't really
// matter which pres context we pass in when it does need to be recreated.
// (See nsPresContext::GetDocumentColorPreferences for how whether we
// are a chrome origin image affects some pref styling information.)
PreferenceSheet::EnsureInitialized();
auto cache = nsLayoutStylesheetCache::Singleton();
RefPtr<StyleSheet> newPrefSheet =
mPresContext->IsChromeOriginImage()
? cache->ChromePreferenceSheet(mPresContext)
: cache->ContentPreferenceSheet(mPresContext);
PreferenceSheet::ShouldUseChromePrefs(*mDocument)
? cache->ChromePreferenceSheet()
: cache->ContentPreferenceSheet();
if (mPrefStyleSheet == newPrefSheet) {
return;

Просмотреть файл

@ -110,21 +110,6 @@ class ContainerLayerPresContext : public LayerUserData {
nsPresContext* mPresContext;
};
nscolor nsPresContext::MakeColorPref(const nsString& aColor) {
ServoStyleSet* styleSet = mShell ? mShell->StyleSet() : nullptr;
nscolor result;
bool ok =
ServoCSSParser::ComputeColor(styleSet, NS_RGB(0, 0, 0), aColor, &result);
if (!ok) {
// Any better choices?
result = NS_RGB(0, 0, 0);
}
return result;
}
bool nsPresContext::IsDOMPaintEventPending() {
if (!mTransactions.IsEmpty()) {
return true;
@ -172,17 +157,8 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
mPageSize(-1, -1),
mPageScale(0.0),
mPPScale(1.0f),
mDefaultColor(NS_RGBA(0, 0, 0, 0)),
mBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF)),
mLinkColor(NS_RGB(0x00, 0x00, 0xEE)),
mActiveLinkColor(NS_RGB(0xEE, 0x00, 0x00)),
mVisitedLinkColor(NS_RGB(0x55, 0x1A, 0x8B)),
mFocusBackgroundColor(mBackgroundColor),
mFocusTextColor(mDefaultColor),
mBodyTextColor(mDefaultColor),
mViewportScrollOverrideElement(nullptr),
mViewportScrollStyles(StyleOverflow::Auto, StyleOverflow::Auto),
mFocusRingWidth(1),
mExistThrottledUpdates(false),
// mImageAnimationMode is initialised below, in constructor body
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
@ -195,11 +171,8 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
mPendingInterruptFromTest(false),
mInterruptsEnabled(false),
mUseDocumentColors(true),
mUnderlineLinks(true),
mSendAfterPaintToContent(false),
mUseFocusColors(false),
mFocusRingOnAnything(false),
mFocusRingStyle(false),
mDrawImageBackground(true), // always draw the background
mDrawColorBackground(true),
// mNeverAnimate is initialised below, in constructor body
@ -370,9 +343,8 @@ void nsPresContext::GetDocumentColorPreferences() {
// they would already be, because gfxPlatform would have been created,
// but in some reference tests, that is not the case.
gfxPrefs::GetSingleton();
PreferenceSheet::EnsureInitialized();
int32_t useAccessibilityTheme = 0;
bool usePrefColors = true;
static int32_t sDocumentColorsSetting;
static bool sDocumentColorsSettingPrefCached = false;
if (!sDocumentColorsSettingPrefCached) {
@ -381,49 +353,6 @@ void nsPresContext::GetDocumentColorPreferences() {
"browser.display.document_color_use", 0);
}
if (IsChrome() || IsChromeOriginImage()) {
usePrefColors = false;
} else {
useAccessibilityTheme =
LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
usePrefColors = !useAccessibilityTheme;
}
if (usePrefColors) {
usePrefColors =
!Preferences::GetBool("browser.display.use_system_colors", false);
}
if (nsContentUtils::UseStandinsForNativeColors()) {
// Once the |nsContentUtils::UseStandinsForNativeColors()| is true,
// use fixed color values instead of preferred colors and system colors.
mDefaultColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::eColorID_windowtext, NS_RGB(0x00, 0x00, 0x00));
mBackgroundColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::eColorID_window, NS_RGB(0xff, 0xff, 0xff));
} else if (usePrefColors) {
nsAutoString colorStr;
Preferences::GetString("browser.display.foreground_color", colorStr);
if (!colorStr.IsEmpty()) {
mDefaultColor = MakeColorPref(colorStr);
}
colorStr.Truncate();
Preferences::GetString("browser.display.background_color", colorStr);
if (!colorStr.IsEmpty()) {
mBackgroundColor = MakeColorPref(colorStr);
}
} else {
mDefaultColor = LookAndFeel::GetColor(
LookAndFeel::eColorID_WindowForeground, NS_RGB(0x00, 0x00, 0x00));
mBackgroundColor = LookAndFeel::GetColor(
LookAndFeel::eColorID_WindowBackground, NS_RGB(0xFF, 0xFF, 0xFF));
}
// Wherever we got the default background color from, ensure it is
// opaque.
mBackgroundColor =
NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF), mBackgroundColor);
// Now deal with the pref:
// 0 = default: always, except in high contrast mode
// 1 = always
@ -433,8 +362,8 @@ void nsPresContext::GetDocumentColorPreferences() {
} else if (sDocumentColorsSetting == 2) {
mUseDocumentColors = IsChrome() || IsChromeOriginImage();
} else {
MOZ_ASSERT(!useAccessibilityTheme || !(IsChrome() || IsChromeOriginImage()),
"The accessibility theme should only be on for non-chrome");
bool useAccessibilityTheme =
PreferenceSheet::UseAccessibilityTheme(IsChrome());
mUseDocumentColors = !useAccessibilityTheme;
}
}
@ -455,57 +384,6 @@ void nsPresContext::GetUserPreferences() {
mSendAfterPaintToContent = Preferences::GetBool(
"dom.send_after_paint_to_content", mSendAfterPaintToContent);
// * link colors
mUnderlineLinks =
Preferences::GetBool("browser.underline_anchors", mUnderlineLinks);
nsAutoString colorStr;
Preferences::GetString("browser.anchor_color", colorStr);
if (!colorStr.IsEmpty()) {
mLinkColor = MakeColorPref(colorStr);
}
colorStr.Truncate();
Preferences::GetString("browser.active_color", colorStr);
if (!colorStr.IsEmpty()) {
mActiveLinkColor = MakeColorPref(colorStr);
}
colorStr.Truncate();
Preferences::GetString("browser.visited_color", colorStr);
if (!colorStr.IsEmpty()) {
mVisitedLinkColor = MakeColorPref(colorStr);
}
mUseFocusColors =
Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
mFocusTextColor = mDefaultColor;
mFocusBackgroundColor = mBackgroundColor;
colorStr.Truncate();
Preferences::GetString("browser.display.focus_text_color", colorStr);
if (!colorStr.IsEmpty()) {
mFocusTextColor = MakeColorPref(colorStr);
}
colorStr.Truncate();
Preferences::GetString("browser.display.focus_background_color", colorStr);
if (!colorStr.IsEmpty()) {
mFocusBackgroundColor = MakeColorPref(colorStr);
}
mFocusRingWidth =
Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
mFocusRingOnAnything = Preferences::GetBool(
"browser.display.focus_ring_on_anything", mFocusRingOnAnything);
mFocusRingStyle =
Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
mBodyTextColor = mDefaultColor;
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
Document()->ResetLangPrefs();
@ -638,6 +516,7 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) {
// The first pres context that has its pref changed runnable called will
// be the one to cause the reconstruction of the pref style sheet.
nsLayoutStylesheetCache::InvalidatePreferenceSheets();
PreferenceSheet::Refresh();
DispatchPrefChangedRunnableIfNeeded();
if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
@ -1478,6 +1357,8 @@ void nsPresContext::SysColorChangedInternal() {
// Invalidate cached '-moz-windows-accent-color-applies' media query:
RefreshSystemMetrics();
PreferenceSheet::Refresh();
// Reset default background and foreground colors for the document since
// they may be using system colors
GetDocumentColorPreferences();

Просмотреть файл

@ -13,6 +13,7 @@
#include "mozilla/MediaFeatureChange.h"
#include "mozilla/NotNull.h"
#include "mozilla/ScrollStyles.h"
#include "mozilla/PreferenceSheet.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "nsColor.h"
@ -86,12 +87,6 @@ class Element;
} // namespace dom
} // namespace mozilla
// supported values for cached bool types
//
// FIXME(emilio): We have StaticPrefs now, probably all of these should be
// migrated.
enum nsPresContext_CachedBoolPrefType { kPresContext_UnderlineLinks = 1 };
// supported values for cached integer pref types
enum nsPresContext_CachedIntPrefType {
kPresContext_ScrollbarSide = 1,
@ -359,21 +354,6 @@ class nsPresContext : public nsISupports,
*/
void StopEmulatingMedium();
/** Get a cached boolean pref, by its type */
// * - initially created for bugs 31816, 20760, 22963
bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const {
// If called with a constant parameter, the compiler should optimize
// this switch statement away.
switch (aPrefType) {
case kPresContext_UnderlineLinks:
return mUnderlineLinks;
default:
NS_ERROR("Invalid arg passed to GetCachedBoolPref");
}
return false;
}
/** Get a cached integer pref, by its type */
// * - initially created for bugs 30910, 61883, 74186, 84398
int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const {
@ -391,28 +371,12 @@ class nsPresContext : public nsISupports,
return false;
}
/**
* Get the default colors
*/
nscolor DefaultColor() const { return mDefaultColor; }
nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
nscolor DefaultLinkColor() const { return mLinkColor; }
nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
nscolor FocusTextColor() const { return mFocusTextColor; }
/**
* Body text color, for use in quirks mode only.
*/
nscolor BodyTextColor() const { return mBodyTextColor; }
void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
bool GetUseFocusColors() const { return mUseFocusColors; }
uint8_t FocusRingWidth() const { return mFocusRingWidth; }
bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
const mozilla::PreferenceSheet::Prefs& PrefSheetPrefs() const {
return mozilla::PreferenceSheet::PrefsFor(*mDocument);
}
nscolor DefaultBackgroundColor() const {
return PrefSheetPrefs().mDefaultBackgroundColor;
}
nsISupports* GetContainerWeak() const;
@ -1220,18 +1184,6 @@ class nsPresContext : public nsISupports,
float mPageScale;
float mPPScale;
nscolor mDefaultColor;
nscolor mBackgroundColor;
nscolor mLinkColor;
nscolor mActiveLinkColor;
nscolor mVisitedLinkColor;
nscolor mFocusBackgroundColor;
nscolor mFocusTextColor;
nscolor mBodyTextColor;
// This is a non-owning pointer. May be null. If non-null, it's guaranteed to
// be pointing to an element that's still alive, because we'll reset it in
// UpdateViewportScrollStylesOverride() as part of the cleanup code when
@ -1242,8 +1194,6 @@ class nsPresContext : public nsISupports,
mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement;
ScrollStyles mViewportScrollStyles;
uint8_t mFocusRingWidth;
bool mExistThrottledUpdates;
uint16_t mImageAnimationMode;
@ -1278,7 +1228,6 @@ class nsPresContext : public nsISupports,
unsigned mPendingInterruptFromTest : 1;
unsigned mInterruptsEnabled : 1;
unsigned mUseDocumentColors : 1;
unsigned mUnderlineLinks : 1;
unsigned mSendAfterPaintToContent : 1;
unsigned mUseFocusColors : 1;
unsigned mFocusRingOnAnything : 1;
@ -1347,8 +1296,6 @@ class nsPresContext : public nsISupports,
protected:
virtual ~nsPresContext();
nscolor MakeColorPref(const nsString& aColor);
void LastRelease();
#ifdef DEBUG

Просмотреть файл

@ -765,6 +765,10 @@ Document::DocumentTheme Gecko_GetDocumentLWTheme(const Document* aDocument) {
return aDocument->ThreadSafeGetDocumentLWTheme();
}
const PreferenceSheet::Prefs* Gecko_GetPrefSheetPrefs(const Document* aDoc) {
return &PreferenceSheet::PrefsFor(*aDoc);
}
bool Gecko_IsTableBorderNonzero(RawGeckoElementBorrowed aElement) {
if (!aElement->IsHTMLElement(nsGkAtoms::table)) {
return false;

Просмотреть файл

@ -17,6 +17,7 @@
#include "mozilla/css/SheetLoadData.h"
#include "mozilla/EffectCompositor.h"
#include "mozilla/ComputedTimingFunction.h"
#include "mozilla/PreferenceSheet.h"
#include "nsCSSValue.h"
#include "nsStyleStruct.h"
@ -138,6 +139,9 @@ nsAtom* Gecko_GetXMLLangValue(RawGeckoElementBorrowed element);
mozilla::dom::Document::DocumentTheme Gecko_GetDocumentLWTheme(
const mozilla::dom::Document*);
const mozilla::PreferenceSheet::Prefs* Gecko_GetPrefSheetPrefs(
const mozilla::dom::Document*);
bool Gecko_IsTableBorderNonzero(RawGeckoElementBorrowed element);
bool Gecko_IsBrowserFrame(RawGeckoElementBorrowed element);

Просмотреть файл

@ -0,0 +1,98 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "PreferenceSheet.h"
#include "ServoCSSParser.h"
#include "MainThreadUtils.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/dom/Document.h"
#include "nsContentUtils.h"
using mozilla::dom::Document;
namespace mozilla {
bool PreferenceSheet::sInitialized;
PreferenceSheet::Prefs PreferenceSheet::sContentPrefs;
PreferenceSheet::Prefs PreferenceSheet::sChromePrefs;
static void GetColor(const char* aPrefName, nscolor& aColor) {
nsAutoString value;
Preferences::GetString(aPrefName, value);
if (value.IsEmpty()) {
return;
}
nscolor result;
if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), value, &result)) {
return;
}
aColor = result;
}
bool PreferenceSheet::ShouldUseChromePrefs(const Document& aDoc) {
return aDoc.IsInChromeDocShell() ||
(aDoc.IsBeingUsedAsImage() && aDoc.IsDocumentURISchemeChrome());
}
bool PreferenceSheet::UseAccessibilityTheme(bool aIsChrome) {
return !aIsChrome &&
!!LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
}
void PreferenceSheet::Prefs::Load(bool aIsChrome) {
*this = {};
mUnderlineLinks = StaticPrefs::browser_underline_anchors();
mUseFocusColors = StaticPrefs::browser_display_use_focus_colors();
mFocusRingWidth = StaticPrefs::browser_display_focus_ring_width();
mFocusRingStyle = StaticPrefs::browser_display_focus_ring_style();
mFocusRingOnAnything = StaticPrefs::browser_display_focus_ring_on_anything();
const bool usePrefColors = !aIsChrome && !UseAccessibilityTheme(aIsChrome) &&
!StaticPrefs::browser_display_use_system_colors();
if (nsContentUtils::UseStandinsForNativeColors()) {
mDefaultColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::eColorID_windowtext, mDefaultColor);
mDefaultBackgroundColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::eColorID_window, mDefaultBackgroundColor);
} else if (usePrefColors) {
GetColor("browser.display.background_color", mDefaultBackgroundColor);
GetColor("browser.display.foreground_color", mDefaultColor);
} else {
mDefaultColor = LookAndFeel::GetColor(
LookAndFeel::eColorID_WindowForeground, mDefaultColor);
mDefaultBackgroundColor = LookAndFeel::GetColor(
LookAndFeel::eColorID_WindowBackground, mDefaultBackgroundColor);
}
GetColor("browser.anchor_color", mLinkColor);
GetColor("browser.active_color", mActiveLinkColor);
GetColor("browser.visited_color", mVisitedLinkColor);
GetColor("browser.display.focus_text_color", mFocusTextColor);
GetColor("browser.display.focus_background_color", mFocusBackgroundColor);
// Wherever we got the default background color from, ensure it is
// opaque.
mDefaultBackgroundColor =
NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF), mDefaultBackgroundColor);
}
void PreferenceSheet::Initialize() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sInitialized);
sInitialized = true;
sContentPrefs.Load(false);
sChromePrefs.Load(true);
}
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
/* Some prefable colors for style system use */
#ifndef mozilla_ColorPreferences_h
#define mozilla_ColorPreferences_h
#include "nsColor.h"
namespace mozilla {
namespace dom {
class Document;
}
struct PreferenceSheet {
struct Prefs {
nscolor mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
nscolor mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
nscolor mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
nscolor mDefaultColor = NS_RGB(0, 0, 0);
nscolor mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
nscolor mLinkBackgroundColor = mDefaultBackgroundColor;
nscolor mFocusTextColor = mDefaultColor;
nscolor mFocusBackgroundColor = mDefaultBackgroundColor;
bool mUnderlineLinks = true;
bool mUseFocusColors = false;
uint8_t mFocusRingWidth = 1;
bool mFocusRingStyle = false;
bool mFocusRingOnAnything = false;
void Load(bool aIsChrome);
};
static void EnsureInitialized() {
if (sInitialized) {
return;
}
Initialize();
}
static void Refresh() {
sInitialized = false;
EnsureInitialized();
}
static Prefs& ContentPrefs() {
MOZ_ASSERT(sInitialized);
return sContentPrefs;
}
static Prefs& ChromePrefs() {
MOZ_ASSERT(sInitialized);
return sChromePrefs;
}
static bool ShouldUseChromePrefs(const dom::Document&);
static bool UseAccessibilityTheme(bool aIsChrome);
static const Prefs& PrefsFor(const dom::Document& aDocument) {
return ShouldUseChromePrefs(aDocument) ? ChromePrefs() : ContentPrefs();
}
private:
static bool sInitialized;
static Prefs sContentPrefs;
static Prefs sChromePrefs;
static void Initialize();
};
} // namespace mozilla
#endif

Просмотреть файл

@ -179,6 +179,7 @@ whitelist-types = [
"mozilla::ComputedTiming",
"mozilla::ComputedTimingFunction",
"mozilla::ComputedTimingFunction::BeforeFlag",
"mozilla::PreferenceSheet",
"mozilla::SeenPtrs",
"mozilla::ServoElementSnapshot.*",
"mozilla::ComputedStyle",
@ -525,6 +526,7 @@ structs-types = [
"nsINode",
"Document",
"Document_DocumentTheme",
"mozilla::PreferenceSheet_Prefs",
"nsSimpleContentList",
"mozilla::MediumFeaturesChangedResult",
"RawGeckoAnimationPropertySegment",

Просмотреть файл

@ -87,6 +87,7 @@ EXPORTS.mozilla += [
'MappedDeclarations.h',
'MediaFeatureChange.h',
'PostTraversalTask.h',
'PreferenceSheet.h',
'PreloadedStyleSheet.h',
'PseudoStyleType.h',
'RustCell.h',
@ -211,6 +212,7 @@ UNIFIED_SOURCES += [
'PaintWorkletGlobalScope.cpp',
'PaintWorkletImpl.cpp',
'PostTraversalTask.cpp',
'PreferenceSheet.cpp',
'PreloadedStyleSheet.cpp',
'PseudoStyleType.cpp',
'Rule.cpp',

Просмотреть файл

@ -67,19 +67,19 @@ StyleSheet* nsLayoutStylesheetCache::GetUserChromeSheet() {
return mUserChromeSheet;
}
StyleSheet* nsLayoutStylesheetCache::ChromePreferenceSheet(
nsPresContext* aPresContext) {
StyleSheet* nsLayoutStylesheetCache::ChromePreferenceSheet() {
if (!mChromePreferenceSheet) {
BuildPreferenceSheet(&mChromePreferenceSheet, aPresContext);
BuildPreferenceSheet(&mChromePreferenceSheet,
PreferenceSheet::ChromePrefs());
}
return mChromePreferenceSheet;
}
StyleSheet* nsLayoutStylesheetCache::ContentPreferenceSheet(
nsPresContext* aPresContext) {
StyleSheet* nsLayoutStylesheetCache::ContentPreferenceSheet() {
if (!mContentPreferenceSheet) {
BuildPreferenceSheet(&mContentPreferenceSheet, aPresContext);
BuildPreferenceSheet(&mContentPreferenceSheet,
PreferenceSheet::ContentPrefs());
}
return mContentPreferenceSheet;
@ -320,7 +320,7 @@ void nsLayoutStylesheetCache::InvalidatePreferenceSheets() {
}
void nsLayoutStylesheetCache::BuildPreferenceSheet(
RefPtr<StyleSheet>* aSheet, nsPresContext* aPresContext) {
RefPtr<StyleSheet>* aSheet, const PreferenceSheet::Prefs& aPrefs) {
*aSheet = new StyleSheet(eAgentSheetFeatures, CORS_NONE,
mozilla::net::RP_Unset, dom::SRIMetadata());
@ -346,9 +346,9 @@ void nsLayoutStylesheetCache::BuildPreferenceSheet(
"@namespace svg url(http://www.w3.org/2000/svg);\n");
// Rules for link styling.
nscolor linkColor = aPresContext->DefaultLinkColor();
nscolor activeColor = aPresContext->DefaultActiveLinkColor();
nscolor visitedColor = aPresContext->DefaultVisitedLinkColor();
nscolor linkColor = aPrefs.mLinkColor;
nscolor activeColor = aPrefs.mActiveLinkColor;
nscolor visitedColor = aPrefs.mVisitedLinkColor;
sheetText.AppendPrintf(
"*|*:link { color: #%02x%02x%02x; }\n"
@ -357,17 +357,16 @@ void nsLayoutStylesheetCache::BuildPreferenceSheet(
NS_GET_R_G_B(linkColor), NS_GET_R_G_B(activeColor),
NS_GET_R_G_B(visitedColor));
bool underlineLinks =
aPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks);
bool underlineLinks = aPrefs.mUnderlineLinks;
sheetText.AppendPrintf("*|*:any-link%s { text-decoration: %s; }\n",
underlineLinks ? ":not(svg|a)" : "",
underlineLinks ? "underline" : "none");
// Rules for focus styling.
bool focusRingOnAnything = aPresContext->GetFocusRingOnAnything();
uint8_t focusRingWidth = aPresContext->FocusRingWidth();
uint8_t focusRingStyle = aPresContext->GetFocusRingStyle();
bool focusRingOnAnything = aPrefs.mFocusRingOnAnything;
uint8_t focusRingWidth = aPrefs.mFocusRingWidth;
uint8_t focusRingStyle = aPrefs.mFocusRingStyle;
if ((focusRingWidth != 1 && focusRingWidth <= 4) || focusRingOnAnything) {
if (focusRingWidth != 1) {
@ -400,9 +399,9 @@ void nsLayoutStylesheetCache::BuildPreferenceSheet(
: "");
}
if (aPresContext->GetUseFocusColors()) {
nscolor focusText = aPresContext->FocusTextColor();
nscolor focusBG = aPresContext->FocusBackgroundColor();
if (aPrefs.mUseFocusColors) {
nscolor focusText = aPrefs.mFocusTextColor;
nscolor focusBG = aPrefs.mFocusBackgroundColor;
sheetText.AppendPrintf(
"*:focus, *:focus > font { color: #%02x%02x%02x !important; "
"background-color: #%02x%02x%02x !important; }\n",

Просмотреть файл

@ -11,6 +11,7 @@
#include "nsIObserver.h"
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/PreferenceSheet.h"
#include "mozilla/NotNull.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/css/Loader.h"
@ -46,8 +47,8 @@ class nsLayoutStylesheetCache final : public nsIObserver,
mozilla::StyleSheet* GetUserContentSheet();
mozilla::StyleSheet* GetUserChromeSheet();
mozilla::StyleSheet* ChromePreferenceSheet(nsPresContext* aPresContext);
mozilla::StyleSheet* ContentPreferenceSheet(nsPresContext* aPresContext);
mozilla::StyleSheet* ChromePreferenceSheet();
mozilla::StyleSheet* ContentPreferenceSheet();
static void InvalidatePreferenceSheets();
@ -73,7 +74,7 @@ class nsLayoutStylesheetCache final : public nsIObserver,
mozilla::css::SheetParsingMode aParsingMode,
mozilla::css::FailureAction aFailureAction);
void BuildPreferenceSheet(RefPtr<mozilla::StyleSheet>* aSheet,
nsPresContext* aPresContext);
const mozilla::PreferenceSheet::Prefs&);
static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache;
static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader;

Просмотреть файл

@ -35,6 +35,7 @@
#include "mozilla/dom/ImageTracker.h"
#include "mozilla/CORSMode.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/PreferenceSheet.h"
#include "mozilla/Likely.h"
#include "nsIURI.h"
#include "mozilla/dom/Document.h"
@ -1666,8 +1667,7 @@ nsChangeHint nsStyleTableBorder::CalcDifference(
//
static nscolor DefaultColor(const Document& aDocument) {
auto* pc = aDocument.GetPresContext();
return pc ? pc->DefaultColor() : NS_RGB(0, 0, 0);
return PreferenceSheet::PrefsFor(aDocument).mDefaultColor;
}
nsStyleColor::nsStyleColor(const Document& aDocument)

Просмотреть файл

@ -553,6 +553,54 @@ VARCACHE_PREF(
bool, true
)
//---------------------------------------------------------------------------
// Preference stylesheet prefs.
//---------------------------------------------------------------------------
VARCACHE_PREF(
"browser.display.focus_ring_on_anything",
browser_display_focus_ring_on_anything,
bool, false
)
VARCACHE_PREF(
"browser.display.focus_ring_width",
browser_display_focus_ring_width,
uint32_t, 1
)
VARCACHE_PREF(
"browser.display.focus_ring_style",
browser_display_focus_ring_style,
bool, false
)
VARCACHE_PREF(
"browser.display.use_system_colors",
browser_display_use_system_colors,
bool, true
)
VARCACHE_PREF(
"browser.display.use_focus_colors",
browser_display_use_focus_colors,
bool, false
)
VARCACHE_PREF(
"browser.underline_anchors",
browser_underline_anchors,
bool, true
)
PREF("browser.display.foreground_color", String, "")
PREF("browser.display.background_color", String, "")
PREF("browser.display.focus_background_color", String, "")
PREF("browser.display.focus_text_color", String, "")
PREF("browser.anchor_color", String, "")
PREF("browser.active_color", String, "")
PREF("browser.visited_color", String, "")
//---------------------------------------------------------------------------
// Graphics prefs
//---------------------------------------------------------------------------

Просмотреть файл

@ -150,7 +150,7 @@ impl PerDocumentStyleData {
// right now not always honored, see bug 1405543...
//
// Should we just force XBL Stylists to be NoQuirks?
let quirks_mode = unsafe { (*device.pres_context().mDocument.mRawPtr).mCompatMode };
let quirks_mode = device.document().mCompatMode;
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
stylist: Stylist::new(device, quirks_mode.into()),
@ -191,8 +191,7 @@ impl PerDocumentStyleDataImpl {
/// Returns whether visited styles are enabled.
#[inline]
pub fn visited_styles_enabled(&self) -> bool {
let doc = self.stylist.device().pres_context().mDocument.mRawPtr;
unsafe { bindings::Gecko_VisitedStylesEnabled(doc) }
unsafe { bindings::Gecko_VisitedStylesEnabled(self.stylist.device().document()) }
}
/// Measure heap usage.

Просмотреть файл

@ -83,14 +83,14 @@ impl Device {
/// Trivially constructs a new `Device`.
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
assert!(!pres_context.is_null());
let doc = unsafe { &*(*pres_context).mDocument.mRawPtr };
let prefs = unsafe { &*bindings::Gecko_GetPrefSheetPrefs(doc) };
Device {
pres_context,
default_values: ComputedValues::default_values(unsafe {
&*(*pres_context).mDocument.mRawPtr
}),
default_values: ComputedValues::default_values(doc),
// FIXME(bz): Seems dubious?
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize),
body_text_color: AtomicUsize::new(prefs.mDefaultColor as usize),
used_root_font_size: AtomicBool::new(false),
used_viewport_size: AtomicBool::new(false),
environment: CssEnvironment,
@ -168,6 +168,12 @@ impl Device {
unsafe { &*self.pres_context().mDocument.mRawPtr }
}
/// Gets the preference stylesheet prefs for our document.
#[inline]
pub fn pref_sheet_prefs(&self) -> &structs::PreferenceSheet_Prefs {
unsafe { &*bindings::Gecko_GetPrefSheetPrefs(self.document()) }
}
/// Recreates the default computed values.
pub fn reset_computed_values(&mut self) {
self.default_values = ComputedValues::default_values(self.document());
@ -243,7 +249,7 @@ impl Device {
/// Returns the default background color.
pub fn default_background_color(&self) -> RGBA {
convert_nscolor_to_rgba(self.pres_context().mBackgroundColor)
convert_nscolor_to_rgba(self.pref_sheet_prefs().mDefaultBackgroundColor)
}
/// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText).

Просмотреть файл

@ -1243,7 +1243,7 @@ impl<'le> TElement for GeckoElement<'le> {
fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
self.as_node().owner_doc().0 as *const structs::Document ==
device.pres_context().mDocument.mRawPtr
device.document() as *const _
}
fn style_attribute(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {

Просмотреть файл

@ -350,13 +350,13 @@ impl Color {
Color::Special(special) => {
use self::gecko::SpecialColorKeyword as Keyword;
_context.map(|context| {
let pres_context = context.device().pres_context();
let prefs = context.device().pref_sheet_prefs();
convert_nscolor_to_computedcolor(match special {
Keyword::MozDefaultColor => pres_context.mDefaultColor,
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
Keyword::MozHyperlinktext => pres_context.mLinkColor,
Keyword::MozActivehyperlinktext => pres_context.mActiveLinkColor,
Keyword::MozVisitedhyperlinktext => pres_context.mVisitedLinkColor,
Keyword::MozDefaultColor => prefs.mDefaultColor,
Keyword::MozDefaultBackgroundColor => prefs.mDefaultBackgroundColor,
Keyword::MozHyperlinktext => prefs.mLinkColor,
Keyword::MozActivehyperlinktext => prefs.mActiveLinkColor,
Keyword::MozVisitedhyperlinktext => prefs.mVisitedLinkColor,
})
})
},