From ba7373413fc4faf4a8b391bedce564d5df9dd09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 15 Sep 2020 16:26:05 +0000 Subject: [PATCH] Bug 1665064 - Honor print background image settings on WebRender too. r=kats,jwatt CLOSED TREE We usually suppress background images in nsCSSRendering::PaintStyleImageLayerWithSC, but that codepath isn't hit by WebRender, so instead do it during display list building, the same way we suppress background colors. Differential Revision: https://phabricator.services.mozilla.com/D90278 --- .../tests/chrome/printpreview_helper.xhtml | 10 +++++++ layout/generic/nsCanvasFrame.cpp | 26 ++++++++++++------- layout/painting/nsDisplayList.cpp | 6 ++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/layout/base/tests/chrome/printpreview_helper.xhtml b/layout/base/tests/chrome/printpreview_helper.xhtml index ba82f2c71aea..ff213b733fb9 100644 --- a/layout/base/tests/chrome/printpreview_helper.xhtml +++ b/layout/base/tests/chrome/printpreview_helper.xhtml @@ -672,6 +672,16 @@ async function runTest25() { async function runTest26() { await compareFiles("printpreview_downloadable_font_in_iframe.html", "printpreview_downloadable_font_in_iframe_ref.html"); + requestAnimationFrame(() => setTimeout(runTest27)); +} + +async function runTest27() { + await compareFiles("data:text/html,", "data:text/html,", { + settings: { + printBGColors: false, + printBGImages: false, + } + }); finish(); } diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index 8b049da18780..8702a4eb8b29 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -515,15 +515,23 @@ void nsCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, bool needBlendContainer = false; nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder); - // In high-contrast-mode, we suppress background-image on the canvas frame - // (even when backplating), because users expect site backgrounds to conform - // to their HCM background color when a solid color is rendered, and some - // websites use solid-color images instead of an overwritable background - // color. - const bool suppressBackgroundImage = - !PresContext()->PrefSheetPrefs().mUseDocumentColors && - StaticPrefs:: - browser_display_suppress_canvas_background_image_on_forced_colors(); + const bool suppressBackgroundImage = [&] { + // Handle print settings. + if (!ComputeShouldPaintBackground().mImage) { + return true; + } + // In high-contrast-mode, we suppress background-image on the canvas frame + // (even when backplating), because users expect site backgrounds to + // conform to their HCM background color when a solid color is rendered, + // and some websites use solid-color images instead of an overwritable + // background color. + if (!PresContext()->PrefSheetPrefs().mUseDocumentColors && + StaticPrefs:: + browser_display_suppress_canvas_background_image_on_forced_colors()) { + return true; + } + return false; + }(); // Create separate items for each background layer. const nsStyleImageLayers& layers = bg->StyleBackground()->mImage; diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index d28777481283..4d99a8ddd97e 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -3509,11 +3509,9 @@ bool nsDisplayBackgroundImage::AppendBackgroundItemsToTop( } bool drawBackgroundColor = false; - // Dummy initialisation to keep Valgrind/Memcheck happy. - // See bug 1122375 comment 1. + bool drawBackgroundImage = false; nscolor color = NS_RGBA(0, 0, 0, 0); if (!nsCSSRendering::IsCanvasFrame(aFrame) && bg) { - bool drawBackgroundImage; color = nsCSSRendering::DetermineBackgroundColor( presContext, bgSC, aFrame, drawBackgroundImage, drawBackgroundColor); } @@ -3593,7 +3591,7 @@ bool nsDisplayBackgroundImage::AppendBackgroundItemsToTop( return true; } - if (!bg) { + if (!bg || !drawBackgroundImage) { aList->AppendToTop(&bgItemList); return false; }