mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1408122 - Apply prefers-color-scheme: dark to top-level about:blank. r=emilio,bzbarsky
I think during the All Hands in Berlin you might have suggested to do this in nsPresContext::DefaultBackgroundColor, but this seems a bit more targeted and not a header. I haven't try tested this yet, so this more of a feedback? Differential Revision: https://phabricator.services.mozilla.com/D63801 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
e2b30dea5c
commit
0b1dab0c5a
@ -16086,6 +16086,37 @@ void Document::RemoveToplevelLoadingDocument(Document* aDoc) {
|
||||
}
|
||||
}
|
||||
|
||||
StylePrefersColorScheme Document::PrefersColorScheme() const {
|
||||
if (nsContentUtils::ShouldResistFingerprinting(this)) {
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
|
||||
if (nsPresContext* pc = GetPresContext()) {
|
||||
if (auto devtoolsOverride = pc->GetOverridePrefersColorScheme()) {
|
||||
return *devtoolsOverride;
|
||||
}
|
||||
|
||||
if (pc->IsPrintingOrPrintPreview()) {
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
}
|
||||
|
||||
// If LookAndFeel::eIntID_SystemUsesDarkTheme fails then return 2
|
||||
// (no-preference)
|
||||
switch (LookAndFeel::GetInt(LookAndFeel::eIntID_SystemUsesDarkTheme, 2)) {
|
||||
case 0:
|
||||
return StylePrefersColorScheme::Light;
|
||||
case 1:
|
||||
return StylePrefersColorScheme::Dark;
|
||||
case 2:
|
||||
return StylePrefersColorScheme::NoPreference;
|
||||
default:
|
||||
// This only occurs if the user has set the ui.systemUsesDarkTheme pref to
|
||||
// an invalid value.
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool Document::UseOverlayScrollbars(const Document* aDocument) {
|
||||
BrowsingContext* bc = aDocument ? aDocument->GetBrowsingContext() : nullptr;
|
||||
|
@ -152,6 +152,7 @@ class ServoStyleSet;
|
||||
enum class StyleOrigin : uint8_t;
|
||||
class SMILAnimationController;
|
||||
enum class StyleCursorKind : uint8_t;
|
||||
enum class StylePrefersColorScheme : uint8_t;
|
||||
template <typename>
|
||||
class OwningNonNull;
|
||||
struct URLExtraData;
|
||||
@ -3872,6 +3873,9 @@ class Document : public nsINode,
|
||||
|
||||
nsIPermissionDelegateHandler* PermDelegateHandler();
|
||||
|
||||
// CSS prefers-color-scheme media feature for this document.
|
||||
StylePrefersColorScheme PrefersColorScheme() const;
|
||||
|
||||
// Returns true if we use overlay scrollbars on the system wide or on the
|
||||
// given document.
|
||||
static bool UseOverlayScrollbars(const Document* aDocument);
|
||||
|
@ -178,6 +178,7 @@
|
||||
#include "nsIDragSession.h"
|
||||
#include "nsIFrameInlines.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsSubDocumentFrame.h"
|
||||
#include "nsQueryObject.h"
|
||||
#include "mozilla/GlobalStyleSheetCache.h"
|
||||
@ -5060,7 +5061,26 @@ nscolor PresShell::GetDefaultBackgroundColorToDraw() {
|
||||
if (!mPresContext || !mPresContext->GetBackgroundColorDraw()) {
|
||||
return NS_RGB(255, 255, 255);
|
||||
}
|
||||
return mPresContext->DefaultBackgroundColor();
|
||||
|
||||
nscolor backgroundColor = mPresContext->DefaultBackgroundColor();
|
||||
if (backgroundColor != NS_RGB(255, 255, 255)) {
|
||||
// Return non-default color.
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
// Use a dark background for top-level about:blank that is inaccessible to
|
||||
// content JS.
|
||||
Document* doc = GetDocument();
|
||||
BrowsingContext* bc = doc->GetBrowsingContext();
|
||||
if (bc && bc->IsTop() && !bc->HasOpener() &&
|
||||
doc->GetDocumentURI() &&
|
||||
NS_IsAboutBlank(doc->GetDocumentURI()) &&
|
||||
doc->PrefersColorScheme() == StylePrefersColorScheme::Dark) {
|
||||
// Use --in-content-page-background for prefers-color-scheme: dark.
|
||||
return NS_RGB(0x2A, 0x2A, 0x2E);
|
||||
}
|
||||
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
void PresShell::UpdateCanvasBackground() {
|
||||
|
@ -242,32 +242,7 @@ bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) {
|
||||
|
||||
StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme(
|
||||
const Document* aDocument) {
|
||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
if (nsPresContext* pc = aDocument->GetPresContext()) {
|
||||
if (auto devtoolsOverride = pc->GetOverridePrefersColorScheme()) {
|
||||
return *devtoolsOverride;
|
||||
}
|
||||
|
||||
if (pc->IsPrintingOrPrintPreview()) {
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
}
|
||||
// If LookAndFeel::eIntID_SystemUsesDarkTheme fails then return 2
|
||||
// (no-preference)
|
||||
switch (LookAndFeel::GetInt(LookAndFeel::eIntID_SystemUsesDarkTheme, 2)) {
|
||||
case 0:
|
||||
return StylePrefersColorScheme::Light;
|
||||
case 1:
|
||||
return StylePrefersColorScheme::Dark;
|
||||
case 2:
|
||||
return StylePrefersColorScheme::NoPreference;
|
||||
default:
|
||||
// This only occurs if the user has set the ui.systemUsesDarkTheme pref to
|
||||
// an invalid value.
|
||||
return StylePrefersColorScheme::Light;
|
||||
}
|
||||
return aDocument->PrefersColorScheme();
|
||||
}
|
||||
|
||||
static PointerCapabilities GetPointerCapabilities(const Document* aDocument,
|
||||
|
@ -107,6 +107,7 @@
|
||||
@supports -moz-bool-pref("browser.in-content.dark-mode") {
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
/* Keep this in sync with layout/base/PresShell.cpp! */
|
||||
--in-content-page-background: #2A2A2E;
|
||||
--in-content-page-color: rgb(249, 249, 250);
|
||||
--in-content-text-color: var(--in-content-page-color);
|
||||
|
Loading…
Reference in New Issue
Block a user