style: Apply a grayscale filter to pages when monochrome.

This hooks the "monochrome" media query and co to the
nsIPrintSettings.printInColor setting.

This print setting we're using is not exposed in the print preview UI,
but you can test it setting the print.print_in_color preference to
"false", and then print preview will correctly show up greyscale'd.

Once this lands, the UI folks just have to use it as they see fit :)

I would've liked to add a proper rendering test, but the print reftests
check only whether the PDF text matches.

I could add a test to printpreview_helper.xhtml, but I'm refactoring
that file in bug 1648064 so I'd rather wait a bit and add it in a
separate bug. The test for the media feature should make sure that we
test that code path at least.

Differential Revision: https://phabricator.services.mozilla.com/D83552
This commit is contained in:
Emilio Cobos Álvarez 2020-07-15 03:45:33 +00:00
parent 1c8d4be6b2
commit 9d3876bda0

View file

@ -247,13 +247,12 @@ fn eval_color_index(
/// https://drafts.csswg.org/mediaqueries-4/#monochrome
fn eval_monochrome(
_: &Device,
device: &Device,
query_value: Option<u32>,
range_or_operator: Option<RangeOrOperator>,
) -> bool {
// For color devices we should return 0.
// FIXME: On a monochrome device, return the actual color depth, not 0!
let depth = 0;
let depth = unsafe { bindings::Gecko_MediaFeatures_GetMonochromeBitsPerPixel(device.document()) };
RangeOrOperator::evaluate(range_or_operator, query_value, depth)
}