Skip to content

Commit

Permalink
Bug 1866738 - Make initial about:blank docs always transparent, even …
Browse files Browse the repository at this point in the history
…in content docshells. r=jwatt

This implements the proposed fix to
w3c/csswg-drafts#9624, and adds a tentative
test for it.

Differential Revision: https://phabricator.services.mozilla.com/D194751
  • Loading branch information
emilio committed Nov 29, 2023
1 parent b261dd7 commit d407a74
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
28 changes: 21 additions & 7 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5359,16 +5359,35 @@ void PresShell::AddCanvasBackgroundColorItem(nsDisplayListBuilder* aBuilder,
}

bool PresShell::IsTransparentContainerElement() const {
if (mDocument->IsInitialDocument()) {
switch (StaticPrefs::layout_css_initial_document_transparency()) {
case 3:
return true;
case 2:
if (!mDocument->IsTopLevelContentDocument()) {
return true;
}
[[fallthrough]];
case 1:
if (mDocument->IsLikelyContentInaccessibleTopLevelAboutBlank()) {
return true;
}
[[fallthrough]];
default:
break;
}
}

nsPresContext* pc = GetPresContext();
if (!pc->IsRootContentDocumentCrossProcess()) {
if (pc->IsChrome()) {
if (mDocument->IsInChromeDocShell()) {
return true;
}
// Frames are transparent except if their used embedder color-scheme is
// mismatched, in which case we use an opaque background to avoid
// black-on-black or white-on-white text, see
// https://github.com/w3c/csswg-drafts/issues/4772
if (BrowsingContext* bc = pc->Document()->GetBrowsingContext()) {
if (BrowsingContext* bc = mDocument->GetBrowsingContext()) {
switch (bc->GetEmbedderColorSchemes().mUsed) {
case dom::PrefersColorSchemeOverride::Light:
return pc->DefaultBackgroundColorScheme() == ColorScheme::Light;
Expand All @@ -5382,11 +5401,6 @@ bool PresShell::IsTransparentContainerElement() const {
return true;
}

if (mDocument->IsInitialDocument() &&
mDocument->IsLikelyContentInaccessibleTopLevelAboutBlank()) {
return true;
}

nsIDocShell* docShell = pc->GetDocShell();
if (!docShell) {
return false;
Expand Down
16 changes: 16 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8221,6 +8221,22 @@
value: true
mirror: always

# Controls the transparency of the initial about:blank document. Generally you
# don't ever want a white flash in dark mode, but due to backwards compat we
# have some extra control over this, for now at least.
#
# See https://github.com/w3c/csswg-drafts/issues/9624 for iframes.
#
# Values:
# 1: content-inaccessible top-level only.
# 2: frames and content-inaccessible top-level only.
# 3: always
# Others: don't treat this document specially.
- name: layout.css.initial-document-transparency
type: RelaxedAtomicInt32
value: 3
mirror: always

# The minimum contrast ratio between the accent color foreground and background
# colors.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html>
<title>CSS Test Reference</title>
<style>:root { color-scheme: dark }</style>
<p>Should not see a white frame below</p>
<iframe width="600" height="400" src="support/dark-frame-blank.html"></iframe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<title>CSS Color Adjustment Test: about:blank doesn't cause a white backdrop in dark mode even though technically its color-scheme is mismatched</title>
<link rel="help" href="https://drafts.csswg.org/css-color-adjust/#color-scheme-effect">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/9624">
<link rel="match" href="color-scheme-iframe-background-ref.html">
<style>
:root { color-scheme: dark }
</style>
<p>Should not see a white frame below</p>
<iframe width="600" height="400"></iframe>
<script>
document.querySelector("iframe").contentWindow.stop();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!doctype html>
<style>
:root { color-scheme: dark }
</style>

0 comments on commit d407a74

Please sign in to comment.