Printing a <meter> element

#41198413 Filed 2015-08-29 P3 / S5 Blink > Layout

The bug

The <meter> gauge is drawn entirely with CSS background gradients on divs inside its user-agent shadow tree (html.css). When printing, Blink forces backgrounds to white unless "Background graphics" is checked in the print dialog (print-color-adjust defaults to economy).

Actual the printout shows an empty box where the meter should be.

Expected the meter gauge is visible in the printout, like checkboxes, radios and progress bars are (those are painted natively, so the background stripping never affected them).

Repro steps

1. Open this page in Chrome / Chromium.

2. Press the print button below (or Ctrl+P) and look at the preview. Leave "Background graphics" unchecked (default).

3. Unfixed: the meters below render as empty boxes. Fixed: the colored gauges are visible.

Live samples

optimum (green) 85/100
suboptimum (yellow) 50/100
even-less-good (red) 10/100
half full, defaults 50%
reference (progress, always printed) 50%

Root cause

BoxPainterBase::ShouldForceWhiteBackgroundForPrintEconomy() (core/paint/box_painter_base.cc) rewrites background color and image to solid white while printing when the style's print-color-adjust is economy and "print backgrounds" is off. The meter shadow parts (::-webkit-meter-bar, ::-webkit-meter-*-value) never opted out, so the whole control paints as white-on-white.

Fix

/* third_party/blink/renderer/core/html/resources/html.css */
meter::-webkit-meter-bar,
meter::-webkit-meter-optimum-value,
meter::-webkit-meter-suboptimum-value,
meter::-webkit-meter-even-less-good-value {
    print-color-adjust: exact;
}

Covered by the new unit test PrintContextTest.MeterWithShouldPrintBackgroundDisabled (core/page/print_context_test.cc): prints a page with a <meter> while backgrounds are disabled and asserts that a non-white fill is recorded.

Authors keep full control: setting meter::-webkit-meter-bar { print-color-adjust: economy } (or appearance: none plus custom styling) still overrides the UA default.

Manual workaround (unfixed builds)

In the print dialog, open "More settings" and check Background graphics.

Links

Issue: issues.chromium.org/issues/41198413 (migrated from crbug.com/526384)