Commit 0f7ce8b6 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Fix painting with root transform and a root element background image

Background images are painted by ViewPainter via a call to
PaintFillLayer, passing a |paint_rect|. PaintFillLayer assumes that
any offset from (0, 0) of |paint_rect| is the paint offset in the local
transform space. This was not the case the root element has a transform.
In those cases, remove the offset.

Bug: 988446

Change-Id: I74439771ade6c9c7a54131a84b40ea9a0df5e25c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018451Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735029}
parent bfa1f92c
......@@ -442,13 +442,13 @@ LayoutRect FixedAttachmentPositioningArea(const LayoutBoxModelObject& obj,
} // Anonymous namespace
BackgroundImageGeometry::BackgroundImageGeometry(const LayoutView& view)
BackgroundImageGeometry::BackgroundImageGeometry(
const LayoutView& view,
bool root_elemnet_has_transform)
: box_(view),
positioning_box_(view.RootBox()),
has_non_local_geometry_(false),
painting_view_(true),
painting_table_cell_(false),
cell_using_container_background_(false) {
root_element_has_transform_(root_elemnet_has_transform) {
// The background of the box generated by the root element covers the
// entire canvas and will be painted by the view object, but the we should
// still use the root element box for positioning.
......@@ -457,12 +457,7 @@ BackgroundImageGeometry::BackgroundImageGeometry(const LayoutView& view)
BackgroundImageGeometry::BackgroundImageGeometry(
const LayoutBoxModelObject& obj)
: box_(obj),
positioning_box_(obj),
has_non_local_geometry_(false),
painting_view_(false),
painting_table_cell_(false),
cell_using_container_background_(false) {
: box_(obj), positioning_box_(obj) {
// Specialized constructor should be used for LayoutView.
DCHECK(!obj.IsLayoutView());
}
......@@ -474,8 +469,6 @@ BackgroundImageGeometry::BackgroundImageGeometry(
positioning_box_(background_object && !background_object->IsTableCell()
? ToLayoutBoxModelObject(*background_object)
: cell),
has_non_local_geometry_(false),
painting_view_(false),
painting_table_cell_(true) {
cell_using_container_background_ =
background_object && !background_object->IsTableCell();
......@@ -729,6 +722,17 @@ void BackgroundImageGeometry::ComputePositioningArea(
snapped_box_offset =
LayoutPoint(snapped_box_outset.Left() - snapped_dest_adjust.Left(),
snapped_box_outset.Top() - snapped_dest_adjust.Top());
// |paint_rect|'s location is usually assumed by BackgroundImageGeometry
// to encode paint offset in the local transform space. The one case in
// which this is not true is painting the background of the LayoutView
// canvas when the HTML element has a transform. In that case, the
// paint offset is zero, and the offset gets applied later by a
// PaintOffsetTranslation.
if (painting_view_ && root_element_has_transform_) {
unsnapped_box_offset -= paint_rect.Location();
snapped_box_offset -= paint_rect.Location();
}
}
}
......
......@@ -31,7 +31,7 @@ class BackgroundImageGeometry {
public:
// Constructor for LayoutView where the coordinate space is different.
BackgroundImageGeometry(const LayoutView&);
BackgroundImageGeometry(const LayoutView&, bool root_elemnet_has_transform);
// Constructor for table cells where background_object may be the row or
// column the background image is attached to.
......@@ -181,10 +181,11 @@ class BackgroundImageGeometry {
FloatPoint phase_;
LayoutSize tile_size_;
LayoutSize repeat_spacing_;
bool has_non_local_geometry_;
bool painting_view_;
bool painting_table_cell_;
bool cell_using_container_background_;
bool has_non_local_geometry_ = false;
bool painting_view_ = false;
bool painting_table_cell_ = false;
bool cell_using_container_background_ = false;
bool root_element_has_transform_ = false;
};
} // namespace blink
......
......@@ -272,10 +272,12 @@ void ViewPainter::PaintRootElementGroup(
// the pixel_snapped_background_rect and context to documentElement visual
// space.
bool background_renderable = true;
bool root_element_has_transform = false;
IntRect paint_rect = pixel_snapped_background_rect;
if (!root_object || !root_object->IsBox()) {
background_renderable = false;
} else {
root_element_has_transform = root_object->StyleRef().HasTransform();
TransformationMatrix transform;
root_object->GetTransformFromContainer(root_object->View(),
PhysicalOffset(), transform);
......@@ -362,23 +364,18 @@ void ViewPainter::PaintRootElementGroup(
context.FillRect(paint_rect, Color(), SkBlendMode::kClear);
}
BackgroundImageGeometry geometry(layout_view_);
BackgroundImageGeometry geometry(layout_view_, root_element_has_transform);
BoxModelObjectPainter box_model_painter(layout_view_);
for (const auto* fill_layer : base::Reversed(reversed_paint_list)) {
DCHECK(fill_layer->Clip() == EFillBox::kBorder);
if (BackgroundImageGeometry::ShouldUseFixedAttachment(*fill_layer)) {
box_model_painter.PaintFillLayer(
paint_info, Color(), *fill_layer,
PhysicalRect(pixel_snapped_background_rect), kBackgroundBleedNone,
geometry);
} else {
PhysicalRect painting_rect(paint_rect);
PhysicalRect painting_rect(paint_rect);
if (!BackgroundImageGeometry::ShouldUseFixedAttachment(*fill_layer))
painting_rect.Move(root_object->FirstFragment().PaintOffset());
box_model_painter.PaintFillLayer(paint_info, Color(), *fill_layer,
painting_rect, kBackgroundBleedNone,
geometry);
}
box_model_painter.PaintFillLayer(paint_info, Color(), *fill_layer,
painting_rect, kBackgroundBleedNone,
geometry);
}
if (should_draw_background_in_separate_buffer && !painted_separate_backdrop)
......
......@@ -380,7 +380,6 @@ crbug.com/1042453 [ Mac ] external/wpt/css/filter-effects/idlharness.any.worker.
crbug.com/1042783 external/wpt/css/css-backgrounds/background-size/background-size-near-zero-png.html [ Failure ]
crbug.com/1042783 external/wpt/css/css-backgrounds/background-size/background-size-near-zero-svg.html [ Failure ]
crbug.com/898293 external/wpt/css/css-transforms/transform-translate-background-001.html [ Failure ]
# ====== Paint team owned tests to here ======
......
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