Changeset 231739 in webkit


Ignore:
Timestamp:
May 13, 2018 2:25:44 AM (6 years ago)
Author:
krit@webkit.org
Message:

Implement SVGGeometryElement's isPointInFill and isPointInStroke
https://bugs.webkit.org/show_bug.cgi?id=185580

Reviewed by Antti Koivisto.

Implement isPointInFill and isPointInStroke methods for
SVGGeometryElement interface from SVG2.

https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement

Source/WebCore:

Tests: svg/dom/SVGGeometry-isPointInFill.xhtml

svg/dom/SVGGeometry-isPointInStroke.xhtml

  • rendering/svg/RenderSVGEllipse.cpp:

(WebCore::RenderSVGEllipse::shapeDependentStrokeContains): Flag

to switch between local and "global" coordinate space for hit testing.

  • rendering/svg/RenderSVGEllipse.h:
  • rendering/svg/RenderSVGPath.cpp:

(WebCore::RenderSVGPath::shapeDependentStrokeContains): Flag

to switch between local and "global" coordinate space for hit testing.

  • rendering/svg/RenderSVGPath.h:
  • rendering/svg/RenderSVGRect.cpp:

(WebCore::RenderSVGRect::shapeDependentStrokeContains): Flag

to switch between local and "global" coordinate space for hit testing.

  • rendering/svg/RenderSVGRect.h:
  • rendering/svg/RenderSVGShape.cpp:

(WebCore::RenderSVGShape::shapeDependentStrokeContains): Flag

to switch between local and "global" coordinate space for hit testing.

(WebCore::RenderSVGShape::isPointInFill): Take the winding rule given by

fill-rule to test if a given point is in the fill area of a path.

(WebCore::RenderSVGShape::isPointInStroke): Take stroke properties into

account to check if a point is on top of the stroke area.

  • rendering/svg/RenderSVGShape.h:
  • svg/SVGGeometryElement.cpp:

(WebCore::SVGGeometryElement::isPointInFill):
(WebCore::SVGGeometryElement::isPointInStroke):
(WebCore::SVGGeometryElement::createElementRenderer): Deleted. This is getting implemented

by inheriting classes. No need to create RenderSVGPath here.

  • svg/SVGGeometryElement.h:
  • svg/SVGGeometryElement.idl:

LayoutTests:

  • svg/dom/SVGGeometry-isPointInFill-expected.txt: Added.
  • svg/dom/SVGGeometry-isPointInFill.xhtml: Added.
  • svg/dom/SVGGeometry-isPointInStroke-expected.txt: Added.
  • svg/dom/SVGGeometry-isPointInStroke.xhtml: Added.
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r231737 r231739  
     12018-05-13  Dirk Schulze  <krit@webkit.org>
     2
     3        Implement SVGGeometryElement's isPointInFill and isPointInStroke
     4        https://bugs.webkit.org/show_bug.cgi?id=185580
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Implement isPointInFill and isPointInStroke methods for
     9        SVGGeometryElement interface from SVG2.
     10
     11        https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement
     12
     13        * svg/dom/SVGGeometry-isPointInFill-expected.txt: Added.
     14        * svg/dom/SVGGeometry-isPointInFill.xhtml: Added.
     15        * svg/dom/SVGGeometry-isPointInStroke-expected.txt: Added.
     16        * svg/dom/SVGGeometry-isPointInStroke.xhtml: Added.
     17
    1182018-05-12  Wenson Hsieh  <wenson_hsieh@apple.com>
    219
  • trunk/Source/WebCore/ChangeLog

    r231735 r231739  
     12018-05-13  Dirk Schulze  <krit@webkit.org>
     2
     3        Implement SVGGeometryElement's isPointInFill and isPointInStroke
     4        https://bugs.webkit.org/show_bug.cgi?id=185580
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Implement isPointInFill and isPointInStroke methods for
     9        SVGGeometryElement interface from SVG2.
     10
     11        https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement
     12
     13        Tests: svg/dom/SVGGeometry-isPointInFill.xhtml
     14               svg/dom/SVGGeometry-isPointInStroke.xhtml
     15
     16        * rendering/svg/RenderSVGEllipse.cpp:
     17        (WebCore::RenderSVGEllipse::shapeDependentStrokeContains): Flag
     18                to switch between local and "global" coordinate space for hit testing.
     19        * rendering/svg/RenderSVGEllipse.h:
     20        * rendering/svg/RenderSVGPath.cpp:
     21        (WebCore::RenderSVGPath::shapeDependentStrokeContains): Flag
     22                to switch between local and "global" coordinate space for hit testing.
     23        * rendering/svg/RenderSVGPath.h:
     24        * rendering/svg/RenderSVGRect.cpp:
     25        (WebCore::RenderSVGRect::shapeDependentStrokeContains): Flag
     26                to switch between local and "global" coordinate space for hit testing.
     27        * rendering/svg/RenderSVGRect.h:
     28        * rendering/svg/RenderSVGShape.cpp:
     29        (WebCore::RenderSVGShape::shapeDependentStrokeContains): Flag
     30                to switch between local and "global" coordinate space for hit testing.
     31        (WebCore::RenderSVGShape::isPointInFill): Take the winding rule given by
     32                `fill-rule` to test if a given point is in the fill area of a path.
     33        (WebCore::RenderSVGShape::isPointInStroke): Take stroke properties into
     34                account to check if a point is on top of the stroke area.
     35        * rendering/svg/RenderSVGShape.h:
     36        * svg/SVGGeometryElement.cpp:
     37        (WebCore::SVGGeometryElement::isPointInFill):
     38        (WebCore::SVGGeometryElement::isPointInStroke):
     39        (WebCore::SVGGeometryElement::createElementRenderer): Deleted. This is getting implemented
     40                by inheriting classes. No need to create RenderSVGPath here.
     41        * svg/SVGGeometryElement.h:
     42        * svg/SVGGeometryElement.idl:
     43
    1442018-05-12  Zalan Bujtas  <zalan@apple.com>
    245
  • trunk/Source/WebCore/rendering/svg/RenderSVGEllipse.cpp

    r224537 r231739  
    114114}
    115115
    116 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point)
     116bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point, PointCoordinateSpace pointCoordinateSpace)
    117117{
    118118    // The optimized contains code below does not support non-smooth strokes so we need
     
    121121        if (!hasPath())
    122122            RenderSVGShape::updateShapeFromElement();
    123         return RenderSVGShape::shapeDependentStrokeContains(point);
     123        return RenderSVGShape::shapeDependentStrokeContains(point, pointCoordinateSpace);
    124124    }
    125125
  • trunk/Source/WebCore/rendering/svg/RenderSVGEllipse.h

    r224537 r231739  
    4545    void fillShape(GraphicsContext&) const override;
    4646    void strokeShape(GraphicsContext&) const override;
    47     bool shapeDependentStrokeContains(const FloatPoint&) override;
     47    bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace) override;
    4848    bool shapeDependentFillContains(const FloatPoint&, const WindRule) const override;
    4949    void calculateRadiiAndCenter();
  • trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp

    r224537 r231739  
    102102}
    103103
    104 bool RenderSVGPath::shapeDependentStrokeContains(const FloatPoint& point)
     104bool RenderSVGPath::shapeDependentStrokeContains(const FloatPoint& point, PointCoordinateSpace pointCoordinateSpace)
    105105{
    106     if (RenderSVGShape::shapeDependentStrokeContains(point))
     106    if (RenderSVGShape::shapeDependentStrokeContains(point, pointCoordinateSpace))
    107107        return true;
    108108
  • trunk/Source/WebCore/rendering/svg/RenderSVGPath.h

    r224537 r231739  
    4444
    4545    void strokeShape(GraphicsContext&) const override;
    46     bool shapeDependentStrokeContains(const FloatPoint&) override;
     46    bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace) override;
    4747
    4848    bool shouldStrokeZeroLengthSubpath() const;
  • trunk/Source/WebCore/rendering/svg/RenderSVGRect.cpp

    r224537 r231739  
    135135}
    136136
    137 bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
     137bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point, PointCoordinateSpace pointCoordinateSpace)
    138138{
    139139    // The optimized contains code below does not support non-smooth strokes so we need
     
    142142        if (!hasPath())
    143143            RenderSVGShape::updateShapeFromElement();
    144         return RenderSVGShape::shapeDependentStrokeContains(point);
     144        return RenderSVGShape::shapeDependentStrokeContains(point, pointCoordinateSpace);
    145145    }
    146146
  • trunk/Source/WebCore/rendering/svg/RenderSVGRect.h

    r224537 r231739  
    5151    void fillShape(GraphicsContext&) const override;
    5252    void strokeShape(GraphicsContext&) const override;
    53     bool shapeDependentStrokeContains(const FloatPoint&) override;
     53    bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace) override;
    5454    bool shapeDependentFillContains(const FloatPoint&, const WindRule) const override;
    5555
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp

    r224537 r231739  
    99 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org>
    1010 * Copyright (C) 2011 University of Szeged
     11 * Copyright (C) 2018 Adobe Systems Incorporated. All rights reserved.
    1112 *
    1213 * This library is free software; you can redistribute it and/or
     
    111112}
    112113
    113 bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point)
     114bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point, PointCoordinateSpace pointCoordinateSpace)
    114115{
    115116    ASSERT(m_path);
    116117    BoundingRectStrokeStyleApplier applier(*this);
    117118
    118     if (hasNonScalingStroke()) {
     119    if (hasNonScalingStroke() && pointCoordinateSpace != LocalCoordinateSpace) {
    119120        AffineTransform nonScalingTransform = nonScalingStrokeTransform();
    120121        Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform);
     
    332333}
    333334
     335bool RenderSVGShape::isPointInFill(const FloatPoint& point)
     336{
     337    return shapeDependentFillContains(point, style().svgStyle().fillRule());
     338}
     339
     340bool RenderSVGShape::isPointInStroke(const FloatPoint& point)
     341{
     342    if (!style().svgStyle().hasStroke())
     343        return false;
     344
     345    return shapeDependentStrokeContains(point, LocalCoordinateSpace);
     346}
     347
    334348bool RenderSVGShape::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
    335349{
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.h

    r224537 r231739  
    4646    WTF_MAKE_ISO_ALLOCATED(RenderSVGShape);
    4747public:
     48    enum PointCoordinateSpace {
     49        GlobalCoordinateSpace,
     50        LocalCoordinateSpace
     51    };
    4852    RenderSVGShape(SVGGraphicsElement&, RenderStyle&&);
    4953    virtual ~RenderSVGShape();
     
    5862    virtual void strokeShape(GraphicsContext&) const;
    5963    virtual bool isRenderingDisabled() const = 0;
     64
     65    bool isPointInFill(const FloatPoint&);
     66    bool isPointInStroke(const FloatPoint&);
    6067
    6168    bool hasPath() const { return m_path.get(); }
     
    7279    virtual void updateShapeFromElement();
    7380    virtual bool isEmpty() const;
    74     virtual bool shapeDependentStrokeContains(const FloatPoint&);
     81    virtual bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace);
    7582    virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const;
    7683    float strokeWidth() const;
  • trunk/Source/WebCore/svg/SVGGeometryElement.cpp

    r230829 r231739  
    2424#include "SVGGeometryElement.h"
    2525
     26#include "DOMPoint.h"
    2627#include "RenderSVGPath.h"
    2728#include "RenderSVGResource.h"
     
    5051{
    5152    registerAnimatedPropertiesForSVGGeometryElement();
     53}
     54
     55bool SVGGeometryElement::isPointInFill(DOMPointInit&& pointInit)
     56{
     57    document().updateLayoutIgnorePendingStylesheets();
     58
     59    auto* renderer = downcast<RenderSVGShape>(this->renderer());
     60    if (!renderer)
     61        return false;
     62
     63    FloatPoint point {static_cast<float>(pointInit.x), static_cast<float>(pointInit.y)};
     64    return renderer->isPointInFill(point);
     65}
     66
     67bool SVGGeometryElement::isPointInStroke(DOMPointInit&& pointInit)
     68{
     69    document().updateLayoutIgnorePendingStylesheets();
     70
     71    auto* renderer = downcast<RenderSVGShape>(this->renderer());
     72    if (!renderer)
     73        return false;
     74
     75    FloatPoint point {static_cast<float>(pointInit.x), static_cast<float>(pointInit.y)};
     76    return renderer->isPointInStroke(point);
    5277}
    5378
     
    88113}
    89114
    90 RenderPtr<RenderElement> SVGGeometryElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
    91 {
    92     return createRenderer<RenderSVGPath>(*this, WTFMove(style));
    93115}
    94 
    95 }
  • trunk/Source/WebCore/svg/SVGGeometryElement.h

    r230829 r231739  
    3131namespace WebCore {
    3232
     33struct DOMPointInit;
    3334class SVGPoint;
    3435
     
    3940    virtual float getTotalLength() const = 0;
    4041    virtual Ref<SVGPoint> getPointAtLength(float distance) const = 0;
     42
     43    bool isPointInFill(DOMPointInit&&);
     44    bool isPointInStroke(DOMPointInit&&);
    4145
    4246protected:
     
    5054        DECLARE_ANIMATED_NUMBER(PathLength, pathLength)
    5155    END_DECLARE_ANIMATED_PROPERTIES
    52 
    53     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
    5456};
    5557
  • trunk/Source/WebCore/svg/SVGGeometryElement.idl

    r230829 r231739  
    2828    readonly attribute SVGAnimatedNumber pathLength; // FIXME: Should be [SameObject].
    2929
    30     // boolean isPointInFill(DOMPointInit point);
    31     // boolean isPointInStroke(DOMPointInit point);
     30    boolean isPointInFill(optional DOMPointInit point);
     31    boolean isPointInStroke(optional DOMPointInit point);
    3232    unrestricted float getTotalLength();
    3333    [NewObject] SVGPoint getPointAtLength(float distance);
Note: See TracChangeset for help on using the changeset viewer.