Changeset 147831 in webkit


Ignore:
Timestamp:
Apr 5, 2013 9:21:08 PM (11 years ago)
Author:
hmuller@adobe.com
Message:

[CSS Exclusions] Add support for the simple case of shape-margin polygonal shape-outside
https://bugs.webkit.org/show_bug.cgi?id=113726

Reviewed by Dirk Schulze.

Source/WebCore:

Add support for computing the shape-outside shape-margin boundary for a polygon.
This change is similar to the one added for padding polygons, see bug 112592.
The algorithm used for computing the margin boundary is is provisional. It works
correctly for convex polygons and will work correctly for non self-intersecting
polygons whose margin boundary is the same shape as the original polygon.

Tests: fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon.html

fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon.html
fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon.html

  • rendering/ExclusionPolygon.cpp:

(WebCore::appendArc): Generalized this method a little, to deal with margin and padding connecting arcs.
(WebCore::computeShapePaddingBounds): Pass the new appendArc() parameter.
(WebCore::computeShapeMarginBounds): Compute the margin boundary for a polygon, per the constraints summarized above.
(WebCore::ExclusionPolygon::getExcludedIntervals): Use the margin polygon for this computation.

LayoutTests:

Verify that shape-outside layout works correctly on floats, when shape-margin is specifed.

  • fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon-expected.txt: Added.
  • fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon.html: Added.
  • fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon-expected.html: Added.
  • fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon.html: Added.
  • fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon-expected.html: Added.
  • fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon.html: Added.
Location:
trunk
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r147830 r147831  
     12013-04-05  Hans Muller  <hmuller@adobe.com>
     2
     3        [CSS Exclusions] Add support for the simple case of shape-margin polygonal shape-outside
     4        https://bugs.webkit.org/show_bug.cgi?id=113726
     5
     6        Reviewed by Dirk Schulze.
     7
     8        Verify that shape-outside layout works correctly on floats, when shape-margin is specifed.
     9
     10        * fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon-expected.txt: Added.
     11        * fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon.html: Added.
     12        * fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon-expected.html: Added.
     13        * fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon.html: Added.
     14        * fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon-expected.html: Added.
     15        * fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon.html: Added.
     16
    1172013-04-05  Benjamin Poulain  <bpoulain@apple.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r147829 r147831  
     12013-04-05  Hans Muller  <hmuller@adobe.com>
     2
     3        [CSS Exclusions] Add support for the simple case of shape-margin polygonal shape-outside
     4        https://bugs.webkit.org/show_bug.cgi?id=113726
     5
     6        Reviewed by Dirk Schulze.
     7
     8        Add support for computing the shape-outside shape-margin boundary for a polygon.
     9        This change is similar to the one added for padding polygons, see bug 112592.
     10        The algorithm used for computing the margin boundary is is provisional. It works
     11        correctly for convex polygons and will work correctly for non self-intersecting
     12        polygons whose margin boundary is the same shape as the original polygon.
     13
     14        Tests: fast/exclusions/shape-outside-floats/shape-outside-floats-diamond-margin-polygon.html
     15               fast/exclusions/shape-outside-floats/shape-outside-floats-left-margin-polygon.html
     16               fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon.html
     17
     18        * rendering/ExclusionPolygon.cpp:
     19        (WebCore::appendArc): Generalized this method a little, to deal with margin and padding connecting arcs.
     20        (WebCore::computeShapePaddingBounds): Pass the new appendArc() parameter.
     21        (WebCore::computeShapeMarginBounds): Compute the margin boundary for a polygon, per the constraints summarized above.
     22        (WebCore::ExclusionPolygon::getExcludedIntervals): Use the margin polygon for this computation.
     23
    1242013-04-05  Andy Estes  <aestes@apple.com>
    225
  • trunk/Source/WebCore/rendering/ExclusionPolygon.cpp

    r147111 r147831  
    109109}
    110110
    111 static inline void appendArc(Vector<FloatPoint>& vertices, const FloatPoint& arcCenter, float arcRadius, const FloatPoint& startArcVertex, const FloatPoint& endArcVertex)
     111static inline void appendArc(Vector<FloatPoint>& vertices, const FloatPoint& arcCenter, float arcRadius, const FloatPoint& startArcVertex, const FloatPoint& endArcVertex, bool padding)
    112112{
    113113    float startAngle = atan2(startArcVertex.y() - arcCenter.y(), startArcVertex.x() - arcCenter.x());
    114114    float endAngle = atan2(endArcVertex.y() - arcCenter.y(), endArcVertex.x() - arcCenter.x());
     115    const float twoPI = piFloat * 2;
    115116    if (startAngle < 0)
    116         startAngle += piFloat * 2;
     117        startAngle += twoPI;
    117118    if (endAngle < 0)
    118         endAngle += piFloat * 2;
     119        endAngle += twoPI;
     120    float angle = (startAngle > endAngle) ? (startAngle - endAngle) : (startAngle + twoPI - endAngle);
    119121    const float arcSegmentCount = 5; // An odd number so that one arc vertex will be eactly arcRadius from arcCenter.
    120     float angle5 = ((startAngle > endAngle) ? (startAngle - endAngle) : (startAngle + piFloat * 2 - endAngle)) / arcSegmentCount;
     122    float angle5 =  ((padding) ? -angle : twoPI - angle) / arcSegmentCount;
    121123
    122124    vertices.append(startArcVertex);
    123125    for (unsigned i = 1; i < arcSegmentCount; ++i) {
    124         float angle = startAngle - angle5 * i;
     126        float angle = startAngle + angle5 * i;
    125127        vertices.append(arcCenter + FloatPoint(cos(angle) * arcRadius, sin(angle) * arcRadius));
    126128    }
     
    142144            paddedVertices->append(intersection);
    143145        else if (isReflexVertex(prevEdge.vertex1(), thisEdge.vertex1(), thisEdge.vertex2()))
    144             appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEdge.vertex2(), thisOffsetEdge.vertex1());
     146            appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEdge.vertex2(), thisOffsetEdge.vertex1(), true);
    145147    }
    146148
     
    148150}
    149151
    150 // FIXME: this is just a stub (bug 112917)
    151152static inline FloatPolygon *computeShapeMarginBounds(const FloatPolygon& polygon, float margin, WindRule fillRule)
    152153{
    153     UNUSED_PARAM(margin);
    154 
    155     Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>(polygon.numberOfVertices());
    156     for (unsigned i = 0; i < polygon.numberOfVertices(); ++i)
    157         (*marginVertices)[i] = polygon.vertexAt(i);
     154    Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>();
     155    FloatPoint intersection;
     156
     157    for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) {
     158        const FloatPolygonEdge& thisEdge = polygon.edgeAt(i);
     159        const FloatPolygonEdge& prevEdge = thisEdge.previousEdge();
     160        OffsetPolygonEdge thisOffsetEdge(thisEdge, outwardEdgeNormal(thisEdge) * margin);
     161        OffsetPolygonEdge prevOffsetEdge(prevEdge, outwardEdgeNormal(prevEdge) * margin);
     162
     163        if (prevOffsetEdge.intersection(thisOffsetEdge, intersection))
     164            marginVertices->append(intersection);
     165        else
     166            appendArc(*marginVertices, thisEdge.vertex1(), margin, prevOffsetEdge.vertex2(), thisOffsetEdge.vertex1(), false);
     167    }
     168
    158169    return new FloatPolygon(adoptPtr(marginVertices), fillRule);
    159170}
     
    329340void ExclusionPolygon::getExcludedIntervals(float logicalTop, float logicalHeight, SegmentList& result) const
    330341{
    331     if (isEmpty())
     342    const FloatPolygon& polygon = shapeMarginBounds();
     343    if (polygon.isEmpty())
    332344        return;
    333345
     
    336348
    337349    Vector<ExclusionInterval> y1XIntervals, y2XIntervals;
    338     computeXIntersections(m_polygon, y1, true, y1XIntervals);
    339     computeXIntersections(m_polygon, y2, false, y2XIntervals);
     350    computeXIntersections(polygon, y1, true, y1XIntervals);
     351    computeXIntersections(polygon, y2, false, y2XIntervals);
    340352
    341353    Vector<ExclusionInterval> mergedIntervals;
     
    343355
    344356    Vector<ExclusionInterval> edgeIntervals;
    345     computeOverlappingEdgeXProjections(m_polygon, y1, y2, edgeIntervals);
     357    computeOverlappingEdgeXProjections(polygon, y1, y2, edgeIntervals);
    346358
    347359    Vector<ExclusionInterval> excludedIntervals;
Note: See TracChangeset for help on using the changeset viewer.