Commit 1b5ef063 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

[CI] Cleanup some SVG hit-testing code

...mostly by de-indenting it by reversing the visibility-check. Also
reuse ComputedStyle locals and switch to using a ComputedStyle&.
In LayoutSVGShape::NodeAtFloatPointInternal, the large-ish condition is
split into three slightly smaller.

Change-Id: I275081391a3b399f9887215f4fe3075884de103c
Reviewed-on: https://chromium-review.googlesource.com/995674Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#548154}
parent 52d613e7
......@@ -155,27 +155,27 @@ bool LayoutSVGImage::NodeAtFloatPoint(HitTestResult& result,
if (hit_test_action != kHitTestForeground)
return false;
const ComputedStyle& style = StyleRef();
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_IMAGE_HITTESTING,
result.GetHitTestRequest(),
Style()->PointerEvents());
bool is_visible = (Style()->Visibility() == EVisibility::kVisible);
if (is_visible || !hit_rules.require_visible) {
FloatPoint local_point;
if (!SVGLayoutSupport::TransformToUserSpaceAndCheckClipping(
*this, LocalToSVGParentTransform(), point_in_parent, local_point))
return false;
if (hit_rules.can_hit_fill || hit_rules.can_hit_bounding_box) {
if (object_bounding_box_.Contains(local_point)) {
const LayoutPoint& local_layout_point = LayoutPoint(local_point);
UpdateHitTestResult(result, local_layout_point);
if (result.AddNodeToListBasedTestResult(
GetElement(), local_layout_point) == kStopHitTesting)
return true;
}
style.PointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
FloatPoint local_point;
if (!SVGLayoutSupport::TransformToUserSpaceAndCheckClipping(
*this, LocalToSVGParentTransform(), point_in_parent, local_point))
return false;
if (hit_rules.can_hit_fill || hit_rules.can_hit_bounding_box) {
if (object_bounding_box_.Contains(local_point)) {
const LayoutPoint& local_layout_point = LayoutPoint(local_point);
UpdateHitTestResult(result, local_layout_point);
if (result.AddNodeToListBasedTestResult(
GetElement(), local_layout_point) == kStopHitTesting)
return true;
}
}
return false;
}
......
......@@ -366,22 +366,24 @@ bool LayoutSVGShape::NodeAtFloatPoint(HitTestResult& result,
bool LayoutSVGShape::NodeAtFloatPointInternal(const HitTestRequest& request,
const FloatPoint& local_point,
PointerEventsHitRules hit_rules) {
bool is_visible = (Style()->Visibility() == EVisibility::kVisible);
if (is_visible || !hit_rules.require_visible) {
const SVGComputedStyle& svg_style = Style()->SvgStyle();
WindRule fill_rule = svg_style.FillRule();
if (request.SvgClipContent())
fill_rule = svg_style.ClipRule();
if ((hit_rules.can_hit_bounding_box &&
ObjectBoundingBox().Contains(local_point)) ||
(hit_rules.can_hit_stroke &&
(svg_style.HasStroke() || !hit_rules.require_stroke) &&
StrokeContains(local_point, hit_rules.require_stroke)) ||
(hit_rules.can_hit_fill &&
(svg_style.HasFill() || !hit_rules.require_fill) &&
FillContains(local_point, hit_rules.require_fill, fill_rule)))
return true;
}
const ComputedStyle& style = StyleRef();
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
if (hit_rules.can_hit_bounding_box &&
ObjectBoundingBox().Contains(local_point))
return true;
const SVGComputedStyle& svg_style = style.SvgStyle();
if (hit_rules.can_hit_stroke &&
(svg_style.HasStroke() || !hit_rules.require_stroke) &&
StrokeContains(local_point, hit_rules.require_stroke))
return true;
WindRule fill_rule = svg_style.FillRule();
if (request.SvgClipContent())
fill_rule = svg_style.ClipRule();
if (hit_rules.can_hit_fill &&
(svg_style.HasFill() || !hit_rules.require_fill) &&
FillContains(local_point, hit_rules.require_fill, fill_rule))
return true;
return false;
}
......
......@@ -305,38 +305,39 @@ bool LayoutSVGText::NodeAtFloatPoint(HitTestResult& result,
if (hit_test_action != kHitTestForeground)
return false;
const ComputedStyle& style = StyleRef();
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_TEXT_HITTESTING,
result.GetHitTestRequest(),
Style()->PointerEvents());
bool is_visible = (Style()->Visibility() == EVisibility::kVisible);
if (is_visible || !hit_rules.require_visible) {
if ((hit_rules.can_hit_bounding_box && !ObjectBoundingBox().IsEmpty()) ||
(hit_rules.can_hit_stroke &&
(Style()->SvgStyle().HasStroke() || !hit_rules.require_stroke)) ||
(hit_rules.can_hit_fill &&
(Style()->SvgStyle().HasFill() || !hit_rules.require_fill))) {
FloatPoint local_point;
if (!SVGLayoutSupport::TransformToUserSpaceAndCheckClipping(
*this, LocalToSVGParentTransform(), point_in_parent, local_point))
return false;
HitTestLocation hit_test_location(local_point);
if (LayoutBlock::NodeAtPoint(result, hit_test_location, LayoutPoint(),
hit_test_action))
return true;
style.PointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
// Consider the bounding box if requested.
if (hit_rules.can_hit_bounding_box &&
ObjectBoundingBox().Contains(local_point)) {
const LayoutPoint& local_layout_point = LayoutPoint(local_point);
UpdateHitTestResult(result, local_layout_point);
if (result.AddNodeToListBasedTestResult(
GetElement(), local_layout_point) == kStopHitTesting)
return true;
}
if ((hit_rules.can_hit_bounding_box && !ObjectBoundingBox().IsEmpty()) ||
(hit_rules.can_hit_stroke &&
(style.SvgStyle().HasStroke() || !hit_rules.require_stroke)) ||
(hit_rules.can_hit_fill &&
(style.SvgStyle().HasFill() || !hit_rules.require_fill))) {
FloatPoint local_point;
if (!SVGLayoutSupport::TransformToUserSpaceAndCheckClipping(
*this, LocalToSVGParentTransform(), point_in_parent, local_point))
return false;
HitTestLocation hit_test_location(local_point);
if (LayoutBlock::NodeAtPoint(result, hit_test_location, LayoutPoint(),
hit_test_action))
return true;
// Consider the bounding box if requested.
if (hit_rules.can_hit_bounding_box &&
ObjectBoundingBox().Contains(local_point)) {
const LayoutPoint& local_layout_point = LayoutPoint(local_point);
UpdateHitTestResult(result, local_layout_point);
if (result.AddNodeToListBasedTestResult(
GetElement(), local_layout_point) == kStopHitTesting)
return true;
}
}
return false;
}
......
......@@ -283,45 +283,41 @@ bool SVGInlineTextBox::NodeAtPoint(HitTestResult& result,
// FIXME: integrate with InlineTextBox::nodeAtPoint better.
DCHECK(!IsLineBreak());
auto line_layout_item = LineLayoutSVGInlineText(GetLineLayoutItem());
const ComputedStyle& style = line_layout_item.StyleRef();
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_TEXT_HITTESTING,
result.GetHitTestRequest(),
GetLineLayoutItem().Style()->PointerEvents());
bool is_visible =
GetLineLayoutItem().Style()->Visibility() == EVisibility::kVisible;
if (is_visible || !hit_rules.require_visible) {
if (hit_rules.can_hit_bounding_box ||
(hit_rules.can_hit_stroke &&
(GetLineLayoutItem().Style()->SvgStyle().HasStroke() ||
!hit_rules.require_stroke)) ||
(hit_rules.can_hit_fill &&
(GetLineLayoutItem().Style()->SvgStyle().HasFill() ||
!hit_rules.require_fill))) {
LayoutRect rect(Location(), Size());
rect.MoveBy(accumulated_offset);
if (location_in_container.Intersects(rect)) {
LineLayoutSVGInlineText line_layout_item =
LineLayoutSVGInlineText(GetLineLayoutItem());
const SimpleFontData* font_data =
line_layout_item.ScaledFont().PrimaryFont();
DCHECK(font_data);
if (!font_data)
return false;
DCHECK(line_layout_item.ScalingFactor());
float baseline = font_data->GetFontMetrics().FloatAscent() /
line_layout_item.ScalingFactor();
FloatPoint float_location = FloatPoint(location_in_container.Point());
for (const SVGTextFragment& fragment : text_fragments_) {
FloatQuad fragment_quad = fragment.BoundingQuad(baseline);
if (fragment_quad.ContainsPoint(float_location)) {
line_layout_item.UpdateHitTestResult(
result, location_in_container.Point() -
ToLayoutSize(accumulated_offset));
if (result.AddNodeToListBasedTestResult(line_layout_item.GetNode(),
location_in_container,
rect) == kStopHitTesting)
return true;
}
style.PointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
if (hit_rules.can_hit_bounding_box ||
(hit_rules.can_hit_stroke &&
(style.SvgStyle().HasStroke() || !hit_rules.require_stroke)) ||
(hit_rules.can_hit_fill &&
(style.SvgStyle().HasFill() || !hit_rules.require_fill))) {
LayoutRect rect(Location(), Size());
rect.MoveBy(accumulated_offset);
if (location_in_container.Intersects(rect)) {
const SimpleFontData* font_data =
line_layout_item.ScaledFont().PrimaryFont();
DCHECK(font_data);
if (!font_data)
return false;
DCHECK(line_layout_item.ScalingFactor());
float baseline = font_data->GetFontMetrics().FloatAscent() /
line_layout_item.ScalingFactor();
FloatPoint float_location = FloatPoint(location_in_container.Point());
for (const SVGTextFragment& fragment : text_fragments_) {
FloatQuad fragment_quad = fragment.BoundingQuad(baseline);
if (fragment_quad.ContainsPoint(float_location)) {
line_layout_item.UpdateHitTestResult(
result,
location_in_container.Point() - ToLayoutSize(accumulated_offset));
if (result.AddNodeToListBasedTestResult(line_layout_item.GetNode(),
location_in_container,
rect) == kStopHitTesting)
return true;
}
}
}
......
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