Commit ef097e04 authored by Florin Malita's avatar Florin Malita Committed by Commit Bot

Fix box-shadow clipping for opaque-background <body>

In the presence of an opaque background,
BoxPainterBase::PaintNormalBoxShadow() insets the shadow clip by one
unit (in order to mitigate seaming artifacs), effectively expanding the
shadow inwards, and relies on the opaque background overdrawing this
inset.

But <body> doesn't paint its own background -- it gets transferred to
the view and painted in a different context => the shadow inset remains
visible.

To address this, pass background-skip information to
PaintNormalBoxShadow(), and disable the inset logic when the background
is not being drawn.

Bug: 899342
Change-Id: I5e04a1c17c2be324bf4c6767d2159372f546cc24
Reviewed-on: https://chromium-review.googlesource.com/c/1336495
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#609014}
parent 48f85308
<!DOCTYPE html>
<html>
<head>
<title>CSS box-shadow Test: &lt;body&gt; shadow should look the same regardless of background color</title>
<link rel="author" title="fmalita" href="mailto:fmalita@chromium.org">
<link rel="help" href="https://www.w3.org/TR/css-backgrounds-3/#the-box-shadow">
<link rel="match" href="reference/box-shadow-body-ref.html">
<style type="text/css">
body {
position: relative;
box-shadow: 0 0 0 4px red;
height: 300px;
width: 600px;
margin: 20px auto;
background-color: white;
}
</style>
</head>
<body></body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>CSS box-shadow Test Reference</title>
<link rel="author" title="fmalita" href="mailto:fmalita@chromium.org">
<style type="text/css">
html {
background-color: white;
}
body {
position: relative;
box-shadow: 0 0 0 4px red;
height: 300px;
width: 600px;
margin: 20px auto;
}
</style>
</head>
<body></body>
</html>
...@@ -139,12 +139,17 @@ void BoxPainter::PaintBoxDecorationBackgroundWithRect( ...@@ -139,12 +139,17 @@ void BoxPainter::PaintBoxDecorationBackgroundWithRect(
BackgroundIsKnownToBeOpaque(paint_info)) BackgroundIsKnownToBeOpaque(paint_info))
recorder.SetKnownToBeOpaque(); recorder.SetKnownToBeOpaque();
const auto skip_background = layout_box_.BackgroundTransfersToView() ||
(paint_info.SkipRootBackground() &&
paint_info.PaintContainer() == &layout_box_);
bool needs_end_layer = false; bool needs_end_layer = false;
if (!painting_scrolling_background) { if (!painting_scrolling_background) {
// FIXME: Should eventually give the theme control over whether the box // FIXME: Should eventually give the theme control over whether the box
// shadow should paint, since controls could have custom shadows of their // shadow should paint, since controls could have custom shadows of their
// own. // own.
BoxPainterBase::PaintNormalBoxShadow(paint_info, paint_rect, style); BoxPainterBase::PaintNormalBoxShadow(paint_info, paint_rect, style, true,
true, skip_background);
if (BleedAvoidanceIsClipping(box_decoration_data.bleed_avoidance)) { if (BleedAvoidanceIsClipping(box_decoration_data.bleed_avoidance)) {
state_saver.Save(); state_saver.Save();
...@@ -166,10 +171,7 @@ void BoxPainter::PaintBoxDecorationBackgroundWithRect( ...@@ -166,10 +171,7 @@ void BoxPainter::PaintBoxDecorationBackgroundWithRect(
bool theme_painted = bool theme_painted =
box_decoration_data.has_appearance && box_decoration_data.has_appearance &&
!theme_painter.Paint(layout_box_, paint_info, snapped_paint_rect); !theme_painter.Paint(layout_box_, paint_info, snapped_paint_rect);
bool should_paint_background = if (!theme_painted && !skip_background) {
!theme_painted && (!paint_info.SkipRootBackground() ||
paint_info.PaintContainer() != &layout_box_);
if (should_paint_background) {
PaintBackground(paint_info, paint_rect, PaintBackground(paint_info, paint_rect,
box_decoration_data.background_color, box_decoration_data.background_color,
box_decoration_data.bleed_avoidance); box_decoration_data.bleed_avoidance);
......
...@@ -54,7 +54,8 @@ void BoxPainterBase::PaintNormalBoxShadow(const PaintInfo& info, ...@@ -54,7 +54,8 @@ void BoxPainterBase::PaintNormalBoxShadow(const PaintInfo& info,
const LayoutRect& paint_rect, const LayoutRect& paint_rect,
const ComputedStyle& style, const ComputedStyle& style,
bool include_logical_left_edge, bool include_logical_left_edge,
bool include_logical_right_edge) { bool include_logical_right_edge,
bool background_is_skipped) {
if (!style.BoxShadow()) if (!style.BoxShadow())
return; return;
GraphicsContext& context = info.context; GraphicsContext& context = info.context;
...@@ -64,8 +65,9 @@ void BoxPainterBase::PaintNormalBoxShadow(const PaintInfo& info, ...@@ -64,8 +65,9 @@ void BoxPainterBase::PaintNormalBoxShadow(const PaintInfo& info,
bool has_border_radius = style.HasBorderRadius(); bool has_border_radius = style.HasBorderRadius();
bool has_opaque_background = bool has_opaque_background =
!background_is_skipped &&
style.VisitedDependentColor(GetCSSPropertyBackgroundColor()).Alpha() == style.VisitedDependentColor(GetCSSPropertyBackgroundColor()).Alpha() ==
255; 255;
GraphicsContextStateSaver state_saver(context, false); GraphicsContextStateSaver state_saver(context, false);
......
...@@ -67,7 +67,8 @@ class BoxPainterBase { ...@@ -67,7 +67,8 @@ class BoxPainterBase {
const LayoutRect&, const LayoutRect&,
const ComputedStyle&, const ComputedStyle&,
bool include_logical_left_edge = true, bool include_logical_left_edge = true,
bool include_logical_right_edge = true); bool include_logical_right_edge = true,
bool background_is_skipped = true);
static void PaintInsetBoxShadowWithBorderRect( static void PaintInsetBoxShadowWithBorderRect(
const PaintInfo&, const PaintInfo&,
......
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