Commit 3f0aba15 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

Add RecordHitTestData in SVGImagePainter

This CL adds RecordHitTestData in SVGImagePainter to compute touch
action rects during paint. A layout test is also added.

This CL also put the RecordHitTestData in SVGModelObjectPainter
so that both SVGImagePainter and SVGShapePainter can call.

Bug: 876468
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I6aabbad8ac10fc4fb25e4ec16b7a53cbc6cfff27
Reviewed-on: https://chromium-review.googlesource.com/1196903
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587603}
parent d54494cb
......@@ -1410,3 +1410,5 @@ Bug(none) virtual/paint-touchaction-rects/fast/events/touch/compositor-touch-hit
Bug(none) fast/events/touch/compositor-touch-hit-rects-svg-foreign-object.html [ Failure ]
Bug(none) virtual/paint-touchaction-rects/fast/events/touch/compositor-touch-hit-rects-svg-foreign-object.html [ Failure ]
Bug(none) paint/float/float-under-inline-self-painting-change.html [ Failure ]
Bug(none) virtual/paint-touchaction-rects/fast/events/touch/compositor-touch-hit-rects-svg-image.html [ Failure ]
Bug(none) fast/events/touch/compositor-touch-hit-rects-svg-image.html [ Failure ]
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="resources/compositor-touch-hit-rects.css">
<style>
svg {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="tests">
<svg>
<!-- This is a 4 5x5 blocks of solid color, taken from image/pixelated-svg-image.html -->
<image width="20" height="20" class='testcase' xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFElEQVQIHWP4z8DwHwyBNJDN8B8AQNEG+t5Ik2kAAAAASUVORK5CYII="/>
</svg>
</div>
<div id="console"></div>
<script src="resources/compositor-touch-hit-rects.js"></script>
</body>
......@@ -41,6 +41,8 @@ void SVGImagePainter::Paint(const PaintInfo& paint_info) {
!DrawingRecorder::UseCachedDrawingIfPossible(
paint_context.GetPaintInfo().context, layout_svg_image_,
paint_context.GetPaintInfo().phase)) {
if (RuntimeEnabledFeatures::PaintTouchActionRectsEnabled())
SVGModelObjectPainter::RecordHitTestData(layout_svg_image_, paint_info);
DrawingRecorder recorder(paint_context.GetPaintInfo().context,
layout_svg_image_,
paint_context.GetPaintInfo().phase);
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/layout/svg/layout_svg_model_object.h"
#include "third_party/blink/renderer/core/paint/object_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/platform/graphics/paint/hit_test_data.h"
namespace blink {
......@@ -28,6 +29,26 @@ bool SVGModelObjectPainter::CullRectSkipsPainting(const PaintInfo& paint_info) {
layout_svg_model_object_.VisualRectInLocalSVGCoordinates());
}
void SVGModelObjectPainter::RecordHitTestData(
const LayoutSVGModelObject& layout_svg_model_object,
const PaintInfo& paint_info) {
DCHECK(paint_info.phase == PaintPhase::kForeground);
// Hit test display items are only needed for compositing. This flag is used
// for for printing and drag images which do not need hit testing.
if (paint_info.GetGlobalPaintFlags() & kGlobalPaintFlattenCompositingLayers)
return;
auto touch_action = layout_svg_model_object.EffectiveWhitelistedTouchAction();
if (touch_action == TouchAction::kTouchActionAuto)
return;
auto rect =
LayoutRect(layout_svg_model_object.VisualRectInLocalSVGCoordinates());
HitTestData::RecordTouchActionRect(paint_info.context,
layout_svg_model_object,
TouchActionRect(rect, touch_action));
}
void SVGModelObjectPainter::PaintOutline(const PaintInfo& paint_info) {
if (paint_info.phase != PaintPhase::kForeground)
return;
......
......@@ -16,6 +16,13 @@ class SVGModelObjectPainter {
STACK_ALLOCATED();
public:
// Paint a hit test display item and record hit test data. This should be
// called when painting the background even if there is no other painted
// content. SVG backgrounds are painted in the kForeground paint phase.
static void RecordHitTestData(
const LayoutSVGModelObject& layout_svg_model_object,
const PaintInfo&);
SVGModelObjectPainter(const LayoutSVGModelObject& layout_svg_model_object)
: layout_svg_model_object_(layout_svg_model_object) {}
......
......@@ -40,21 +40,6 @@ static SkPath::FillType FillRuleFromStyle(const PaintInfo& paint_info,
: svg_style.FillRule());
}
void SVGShapePainter::RecordHitTestData(const PaintInfo& paint_info) {
// Hit test display items are only needed for compositing. This flag is used
// for for printing and drag images which do not need hit testing.
if (paint_info.GetGlobalPaintFlags() & kGlobalPaintFlattenCompositingLayers)
return;
auto touch_action = layout_svg_shape_.EffectiveWhitelistedTouchAction();
if (touch_action == TouchAction::kTouchActionAuto)
return;
auto rect = LayoutRect(layout_svg_shape_.VisualRectInLocalSVGCoordinates());
HitTestData::RecordTouchActionRect(paint_info.context, layout_svg_shape_,
TouchActionRect(rect, touch_action));
}
void SVGShapePainter::Paint(const PaintInfo& paint_info) {
if (paint_info.phase != PaintPhase::kForeground ||
layout_svg_shape_.StyleRef().Visibility() != EVisibility::kVisible ||
......@@ -80,7 +65,7 @@ void SVGShapePainter::Paint(const PaintInfo& paint_info) {
paint_context.GetPaintInfo().context, layout_svg_shape_,
paint_context.GetPaintInfo().phase)) {
if (RuntimeEnabledFeatures::PaintTouchActionRectsEnabled())
RecordHitTestData(paint_info);
SVGModelObjectPainter::RecordHitTestData(layout_svg_shape_, paint_info);
DrawingRecorder recorder(paint_context.GetPaintInfo().context,
layout_svg_shape_,
paint_context.GetPaintInfo().phase);
......
......@@ -36,10 +36,6 @@ class SVGShapePainter {
const LayoutSVGResourceMarker&,
const MarkerPosition&,
float stroke_width);
// Paint a hit test display item and record hit test data. This should be
// called when painting the background even if there is no other painted
// content.
void RecordHitTestData(const PaintInfo&);
const LayoutSVGShape& layout_svg_shape_;
};
......
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