Commit 2a25370e authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Align HitTestClippedOutByClipPath coordinate space with paint

In the paint code (ClipPathClipper), the reference box used is the one
computed by LocalReferenceBox(), and the coordinate space is adjusted
for that. In the hit-testing code however, the reference box is adjusted
instead, leading to incorrect results when the reference box is
subjected to an additional transform (a 'transform' on a <clipPath>.)

Instead, set up the reference box and coordinate space in the hit-
testing code in the same way as for paint, by translating to the correct
local coordinate space before performing the actual hit-test.

Bug: 876390
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I60acd616964a942893f0e256766aca728d14b494
Reviewed-on: https://chromium-review.googlesource.com/1188302Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#586028}
parent aff2c048
<!DOCTYPE html>
<title>Hit-test of clip-path objectBoundingBox &lt;clipPath> with additional transform</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
body {
margin: 0;
}
.box {
width: 100px;
height: 100px;
background-color: blue;
margin: 100px;
clip-path: url(#clip);
}
</style>
<div class="box"></div>
<svg height="0">
<clipPath id="clip" clipPathUnits="objectBoundingBox" transform="scale(0.01, 0.01)">
<polygon points="50,0 100,50 50,100 0,50"/>
</clipPath>
</svg>
<script>
function assert_element_at(element, pointlist) {
for (var point of pointlist) {
var result = document.elementFromPoint(point[0], point[1]);
assert_equals(result, element, point.join(','));
}
}
test(function() {
var div = document.querySelector('.box');
// Points inside clip-path.
assert_element_at(div, [[150, 150], [150, 125], [150, 175], [125, 150], [175, 150]]);
// Points outside clip-path.
assert_element_at(document.body, [[120, 120], [180, 120], [120, 180], [180, 180]]);
});
</script>
......@@ -2448,16 +2448,15 @@ bool PaintLayer::HitTestClippedOutByClipPath(
DCHECK(IsSelfPaintingLayer());
DCHECK(root_layer);
LayoutRect reference_box(
ClipPathClipper::LocalReferenceBox(GetLayoutObject()));
LayoutRect origin;
if (EnclosingPaginationLayer())
ConvertFromFlowThreadToVisualBoundingBoxInAncestor(root_layer,
reference_box);
ConvertFromFlowThreadToVisualBoundingBoxInAncestor(root_layer, origin);
else
ConvertToLayerCoords(root_layer, reference_box);
ConvertToLayerCoords(root_layer, origin);
FloatPoint point(hit_test_location.Point());
FloatRect float_reference_box(reference_box);
FloatPoint point(hit_test_location.Point() - origin.Location());
FloatRect reference_box(
ClipPathClipper::LocalReferenceBox(GetLayoutObject()));
ClipPathOperation* clip_path_operation =
GetLayoutObject().StyleRef().ClipPath();
......@@ -2465,7 +2464,7 @@ bool PaintLayer::HitTestClippedOutByClipPath(
if (clip_path_operation->GetType() == ClipPathOperation::SHAPE) {
ShapeClipPathOperation* clip_path =
ToShapeClipPathOperation(clip_path_operation);
return !clip_path->GetPath(float_reference_box).Contains(point);
return !clip_path->GetPath(reference_box).Contains(point);
}
DCHECK_EQ(clip_path_operation->GetType(), ClipPathOperation::REFERENCE);
SVGResource* resource =
......@@ -2484,8 +2483,8 @@ bool PaintLayer::HitTestClippedOutByClipPath(
// not zoomed.
float inverse_zoom = 1 / GetLayoutObject().StyleRef().EffectiveZoom();
point.Scale(inverse_zoom, inverse_zoom);
float_reference_box.Scale(inverse_zoom);
return !clipper->HitTestClipContent(float_reference_box, point);
reference_box.Scale(inverse_zoom);
return !clipper->HitTestClipContent(reference_box, point);
}
bool PaintLayer::IntersectsDamageRect(
......
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