Skip to content

Commit

Permalink
Allow for paint offset roots that don't have PaintLayers.
Browse files Browse the repository at this point in the history
LayoutSVGRoot is not always a stacking context at present,
so it does not always have a PaintLayer.

TBR=chrishtr@chromium.org

(cherry picked from commit 68c4cdb)

Bug: 773198
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ia146f3a90512b98de961bd1f243b9e8439c6d382
Reviewed-on: https://chromium-review.googlesource.com/717564
Reviewed-by: Tien-Ren Chen <trchen@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#508817}
Reviewed-on: https://chromium-review.googlesource.com/719586
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/branch-heads/3239@{#8}
Cr-Branched-From: adb61db-refs/heads/master@{#508578}
  • Loading branch information
chrishtr committed Oct 15, 2017
1 parent 7329c3a commit 264b84e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
26 changes: 15 additions & 11 deletions third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void PaintPropertyTreeBuilder::UpdateProperties(
context.fixed_position.fixed_position_children_fixed_to_root = true;
return;
} else {
context.current.paint_offset_root = frame_view.GetLayoutView()->Layer();
context.current.paint_offset_root = frame_view.GetLayoutView();
}

#if DCHECK_IS_ON()
Expand Down Expand Up @@ -1269,7 +1269,7 @@ void PaintPropertyTreeBuilder::UpdatePaintOffset(
// above the scroll of the LayoutView. Child content is relative to that
// transform, and hence the fixed-position element.
if (context.fixed_position.fixed_position_children_fixed_to_root)
context.current.paint_offset_root = object.Layer();
context.current.paint_offset_root = &object;
break;
default:
NOTREACHED();
Expand All @@ -1296,13 +1296,19 @@ void PaintPropertyTreeBuilder::UpdatePaintOffset(
static inline LayoutPoint VisualOffsetFromPaintOffsetRoot(
const PaintPropertyTreeBuilderFragmentContext& context,
const PaintLayer* child) {
PaintLayer* paint_offset_root = context.current.paint_offset_root;
LayoutPoint result = child->VisualOffsetFromAncestor(paint_offset_root);
const LayoutBoxModelObject* paint_offset_root =
context.current.paint_offset_root;
PaintLayer* painting_layer = paint_offset_root->PaintingLayer();
LayoutPoint result = child->VisualOffsetFromAncestor(painting_layer);
if (!paint_offset_root->Layer()) {
result.Move(-paint_offset_root->OffsetFromAncestorContainer(
&painting_layer->GetLayoutObject()));
}

// Don't include scroll offset of paint_offset_root. Any scroll is
// already included in a separate transform node.
if (paint_offset_root->GetLayoutObject().HasOverflowClip())
result += paint_offset_root->GetLayoutBox()->ScrolledContentOffset();
if (paint_offset_root->HasOverflowClip())
result += ToLayoutBox(paint_offset_root)->ScrolledContentOffset();
return result;
}

Expand Down Expand Up @@ -1351,8 +1357,7 @@ void PaintPropertyTreeBuilder::UpdateForObjectLocationAndSize(
paint_offset.MoveBy(
VisualOffsetFromPaintOffsetRoot(context, enclosing_pagination_layer));
// The paint offset root can have a subpixel paint offset adjustment.
paint_offset.MoveBy(
context.current.paint_offset_root->GetLayoutObject().PaintOffset());
paint_offset.MoveBy(context.current.paint_offset_root->PaintOffset());

if (paint_offset_translation) {
paint_offset_translation =
Expand All @@ -1364,7 +1369,7 @@ void PaintPropertyTreeBuilder::UpdateForObjectLocationAndSize(
}

if (paint_offset_translation)
context.current.paint_offset_root = ToLayoutBoxModelObject(object).Layer();
context.current.paint_offset_root = &ToLayoutBoxModelObject(object);

if (!object.IsBox())
return;
Expand Down Expand Up @@ -1525,8 +1530,7 @@ void PaintPropertyTreeBuilder::UpdateFragments(
// component.
pagination_visual_offset.MoveBy(
full_context.fragments[0]
.current.paint_offset_root->GetLayoutObject()
.PaintOffset());
.current.paint_offset_root->PaintOffset());

fragment_clip.MoveBy(pagination_visual_offset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PaintPropertyTreeBuilderFragmentContext {
// fragmentation offsets. See FragmentContext for the fragmented version.
LayoutPoint paint_offset;
// The PaintLayer corresponding to the origin of |paint_offset|.
PaintLayer* paint_offset_root = nullptr;
const LayoutBoxModelObject* paint_offset_root = nullptr;
// Whether newly created children should flatten their inherited transform
// (equivalently, draw into the plane of their parent). Should generally
// be updated whenever |transform| is; flattening only needs to happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,62 @@ TEST_P(PaintPropertyTreeBuilderTest, TransformNodesAcrossSVGHTMLBoundary) {
div_with_transform_properties->Transform()->Parent());
}

TEST_P(PaintPropertyTreeBuilderTest, PaintOffsetTranslationSVGHTMLBoundary) {
SetBodyInnerHTML(
"<svg id='svg'"
" <foreignObject>"
" <body>"
" <div id='divWithTransform'"
" style='transform: translate3d(3px, 4px, 5px);'></div>"
" </body>"
" </foreignObject>"
"</svg>");

LayoutObject& svg = *GetLayoutObjectByElementId("svg");
const ObjectPaintProperties* svg_properties =
svg.FirstFragment()->PaintProperties();
EXPECT_EQ(
FloatSize(8, 8),
svg_properties->PaintOffsetTranslation()->Matrix().To2DTranslation());

LayoutObject& div_with_transform =
*GetLayoutObjectByElementId("divWithTransform");
const ObjectPaintProperties* div_with_transform_properties =
div_with_transform.FirstFragment()->PaintProperties();
EXPECT_EQ(TransformationMatrix().Translate3d(3, 4, 5),
div_with_transform_properties->Transform()->Matrix());
EXPECT_EQ(FloatSize(8, 158),
div_with_transform_properties->PaintOffsetTranslation()
->Matrix()
.To2DTranslation());
EXPECT_EQ(div_with_transform_properties->PaintOffsetTranslation(),
div_with_transform_properties->Transform()->Parent());
}

TEST_P(PaintPropertyTreeBuilderTest,
PaintOffsetTranslationSVGHTMLBoundaryMulticol) {
SetBodyInnerHTML(
"<svg id='svg'>"
" <foreignObject>"
" <body>"
" <div id='divWithColumns' style='columns: 2'>"
" <div style='width: 5px; height: 5px; background: blue'>"
" </div>"
" </body>"
" </foreignObject>"
"</svg>");

LayoutObject& svg = *GetLayoutObjectByElementId("svg");
const ObjectPaintProperties* svg_properties =
svg.FirstFragment()->PaintProperties();
EXPECT_EQ(
FloatSize(8, 8),
svg_properties->PaintOffsetTranslation()->Matrix().To2DTranslation());
LayoutObject& div_with_columns =
*GetLayoutObjectByElementId("divWithColumns")->SlowFirstChild();
EXPECT_EQ(LayoutPoint(0, 0), div_with_columns.FirstFragment()->PaintOffset());
}

TEST_P(PaintPropertyTreeBuilderTest,
FixedTransformAncestorAcrossSVGHTMLBoundary) {
SetBodyInnerHTML(
Expand Down

0 comments on commit 264b84e

Please sign in to comment.