Commit ca7da416 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Don't apply forced colors when printing

We don't want to print high contrast colors when in forced colors
mode. To avoid this, add a check in Document::InForcedColorsMode()
to see if we are printing. If so, InForcedColorsMode() returns false,
and the printed content is no longer affected by forced colors mode.

Bug: 970285
Change-Id: Ia0338834a6fa945a4446e51377014f951d83e997
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1987985
Commit-Queue: Alison Maher <almaher@microsoft.com>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729849}
parent 9e6a4c02
...@@ -8666,6 +8666,10 @@ void Document::UpdateForcedColors() { ...@@ -8666,6 +8666,10 @@ void Document::UpdateForcedColors() {
in_forced_colors_mode_ = forced_colors != ForcedColors::kNone; in_forced_colors_mode_ = forced_colors != ForcedColors::kNone;
} }
bool Document::InForcedColorsMode() const {
return in_forced_colors_mode_ && !Printing();
}
bool Document::IsCrossSiteSubframe() const { bool Document::IsCrossSiteSubframe() const {
// It'd be nice to avoid the url::Origin temporaries, but that would require // It'd be nice to avoid the url::Origin temporaries, but that would require
// exposing the net internal helper. // exposing the net internal helper.
......
...@@ -1591,7 +1591,7 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -1591,7 +1591,7 @@ class CORE_EXPORT Document : public ContainerNode,
void BindContentSecurityPolicy(); void BindContentSecurityPolicy();
void UpdateForcedColors(); void UpdateForcedColors();
bool InForcedColorsMode() const { return in_forced_colors_mode_; } bool InForcedColorsMode() const;
// Returns true if the subframe document is cross-site to the main frame. If // Returns true if the subframe document is cross-site to the main frame. If
// we can't tell whether the document was ever cross-site or not (e.g. it is // we can't tell whether the document was ever cross-site or not (e.g. it is
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test forced colors mode while printing.</title>
<style>
body {
background-image: url("resources/test-image.jpg");
color: red;
forced-color-adjust: none;
}
</style>
<script>
if (window.testRunner)
testRunner.setPrinting();
</script>
<body>
This text should remain red when printing in forced colors mode.
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test forced colors mode while printing.</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-mode">
<link rel=match href="forced-colors-mode-printing-01-expected.html">
<style>
body {
background-image: url("resources/test-image.jpg");
color: red;
forced-color-adjust: auto;
}
</style>
<script>
if (window.testRunner)
testRunner.setPrinting();
</script>
<body>
This text should remain red when printing in forced colors mode.
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test styles defined in forced-colors media query while printing in forced colors mode.</title>
<style>
div::before {
content: "FAIL";
font-size: 100px;
}
</style>
<script>
if (window.testRunner)
testRunner.setPrinting();
</script>
<p>You should not see a FAIL below when printing</p>
<div></div>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test styles defined in forced-colors media query while printing in forced colors mode.</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-mode">
<link rel=match href="forced-colors-mode-printing-02-expected.html">
<style>
@media print and (forced-colors: active) {
div::before {
content: "FAIL";
font-size: 100px;
}
}
</style>
<script>
if (window.testRunner)
testRunner.setPrinting();
</script>
<p>You should not see a FAIL below when printing</p>
<div></div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment