From 4f644719aefdfb5254a418bce4df7f7fe7ae1727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 2 Aug 2020 08:45:29 +0000 Subject: [PATCH] Bug 1436758 - Make color-adjust: exact not darken foreground colors. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D85660 --- layout/base/nsLayoutUtils.cpp | 14 +++++------ layout/base/tests/chrome/chrome.ini | 2 ++ layout/base/tests/chrome/color_adjust.html | 9 ++++++++ .../base/tests/chrome/color_adjust_ref.html | 8 +++++++ .../tests/chrome/printpreview_helper.xhtml | 23 +++++++++++++++++-- 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 layout/base/tests/chrome/color_adjust.html create mode 100644 layout/base/tests/chrome/color_adjust_ref.html diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index dd46ad6a2ffc..757aeb95277d 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -6209,16 +6209,16 @@ static nscolor DarkenColor(nscolor aColor) { // background images and colors are being suppressed, because that means // light text will not be visible against the (presumed light-colored) // background. -static bool ShouldDarkenColors(nsPresContext* aPresContext) { - return !aPresContext->GetBackgroundColorDraw() && - !aPresContext->GetBackgroundImageDraw(); +static bool ShouldDarkenColors(nsIFrame* aFrame) { + nsPresContext* pc = aFrame->PresContext(); + if (pc->GetBackgroundColorDraw() || pc->GetBackgroundImageDraw()) { + return false; + } + return aFrame->StyleVisibility()->mColorAdjust != StyleColorAdjust::Exact; } nscolor nsLayoutUtils::DarkenColorIfNeeded(nsIFrame* aFrame, nscolor aColor) { - if (ShouldDarkenColors(aFrame->PresContext())) { - return DarkenColor(aColor); - } - return aColor; + return ShouldDarkenColors(aFrame) ? DarkenColor(aColor) : aColor; } gfxFloat nsLayoutUtils::GetSnappedBaselineY(nsIFrame* aFrame, diff --git a/layout/base/tests/chrome/chrome.ini b/layout/base/tests/chrome/chrome.ini index f9e24ffe0b9c..51c7233f042d 100644 --- a/layout/base/tests/chrome/chrome.ini +++ b/layout/base/tests/chrome/chrome.ini @@ -27,6 +27,8 @@ support-files = printpreview_images_sw.html printpreview_images_sw_ref.html printpreview_images_sw.js + color_adjust.html + color_adjust_ref.html test_document_adopted_styles.html test_document_adopted_styles_ref.html test_shadow_root_adopted_styles.html diff --git a/layout/base/tests/chrome/color_adjust.html b/layout/base/tests/chrome/color_adjust.html new file mode 100644 index 000000000000..4a9846e28d92 --- /dev/null +++ b/layout/base/tests/chrome/color_adjust.html @@ -0,0 +1,9 @@ + + +Some text goes here diff --git a/layout/base/tests/chrome/color_adjust_ref.html b/layout/base/tests/chrome/color_adjust_ref.html new file mode 100644 index 000000000000..f5986f93bf7e --- /dev/null +++ b/layout/base/tests/chrome/color_adjust_ref.html @@ -0,0 +1,8 @@ + + +Some text goes here diff --git a/layout/base/tests/chrome/printpreview_helper.xhtml b/layout/base/tests/chrome/printpreview_helper.xhtml index 2e658b2bc617..4ac2ac191325 100644 --- a/layout/base/tests/chrome/printpreview_helper.xhtml +++ b/layout/base/tests/chrome/printpreview_helper.xhtml @@ -440,7 +440,7 @@ async function compareFiles(src1, src2, options = {}) { await messagePromise; } - await printpreview(options); + await printpreview(options.test || options); ctx1.drawWindow(frameElts[1].contentWindow, 0, 0, 400, 400, "rgb(255,255,255)"); exitprintpreview(); @@ -449,7 +449,7 @@ async function compareFiles(src1, src2, options = {}) { iframeElement.setAttribute("src", BASE + src2); }); - await printpreview(options); + await printpreview(options.ref || options); ctx2.drawWindow(frameElts[1].contentWindow, 0, 0, 400, 400, "rgb(255,255,255)"); exitprintpreview(); @@ -518,6 +518,25 @@ async function runTest18() { }, }); + requestAnimationFrame(() => setTimeout(runTest19)); +} + +async function runTest18() { + await compareFiles("color_adjust.html", "color_adjust_ref.html", { + test: { + settings: { + printBGColors: false, + printBGImages: false, + }, + }, + ref: { + settings: { + printBGColors: true, + printBGImages: true, + }, + }, + }); + finish(); }