Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/core/rendering/ExclusionPolygon.cpp

Issue 14220005: Add support for the simple case of shape-margin polygonal shape-outside (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon-expected.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return FloatSize(0, (edgeDelta.width() > 0 ? 1 : -1)); 101 return FloatSize(0, (edgeDelta.width() > 0 ? 1 : -1));
102 float edgeLength = edgeDelta.diagonalLength(); 102 float edgeLength = edgeDelta.diagonalLength();
103 return FloatSize(-edgeDelta.height() / edgeLength, edgeDelta.width() / edgeL ength); 103 return FloatSize(-edgeDelta.height() / edgeLength, edgeDelta.width() / edgeL ength);
104 } 104 }
105 105
106 static inline FloatSize outwardEdgeNormal(const FloatPolygonEdge& edge) 106 static inline FloatSize outwardEdgeNormal(const FloatPolygonEdge& edge)
107 { 107 {
108 return -inwardEdgeNormal(edge); 108 return -inwardEdgeNormal(edge);
109 } 109 }
110 110
111 static inline void appendArc(Vector<FloatPoint>& vertices, const FloatPoint& arc Center, float arcRadius, const FloatPoint& startArcVertex, const FloatPoint& end ArcVertex) 111 static inline void appendArc(Vector<FloatPoint>& vertices, const FloatPoint& arc Center, float arcRadius, const FloatPoint& startArcVertex, const FloatPoint& end ArcVertex, bool padding)
112 { 112 {
113 float startAngle = atan2(startArcVertex.y() - arcCenter.y(), startArcVertex. x() - arcCenter.x()); 113 float startAngle = atan2(startArcVertex.y() - arcCenter.y(), startArcVertex. x() - arcCenter.x());
114 float endAngle = atan2(endArcVertex.y() - arcCenter.y(), endArcVertex.x() - arcCenter.x()); 114 float endAngle = atan2(endArcVertex.y() - arcCenter.y(), endArcVertex.x() - arcCenter.x());
115 const float twoPI = piFloat * 2;
115 if (startAngle < 0) 116 if (startAngle < 0)
116 startAngle += piFloat * 2; 117 startAngle += twoPI;
117 if (endAngle < 0) 118 if (endAngle < 0)
118 endAngle += piFloat * 2; 119 endAngle += twoPI;
120 float angle = (startAngle > endAngle) ? (startAngle - endAngle) : (startAngl e + twoPI - endAngle);
119 const float arcSegmentCount = 5; // An odd number so that one arc vertex wil l be eactly arcRadius from arcCenter. 121 const float arcSegmentCount = 5; // An odd number so that one arc vertex wil l be eactly arcRadius from arcCenter.
120 float angle5 = ((startAngle > endAngle) ? (startAngle - endAngle) : (startAn gle + piFloat * 2 - endAngle)) / arcSegmentCount; 122 float angle5 = ((padding) ? -angle : twoPI - angle) / arcSegmentCount;
121 123
122 vertices.append(startArcVertex); 124 vertices.append(startArcVertex);
123 for (unsigned i = 1; i < arcSegmentCount; ++i) { 125 for (unsigned i = 1; i < arcSegmentCount; ++i) {
124 float angle = startAngle - angle5 * i; 126 float angle = startAngle + angle5 * i;
125 vertices.append(arcCenter + FloatPoint(cos(angle) * arcRadius, sin(angle ) * arcRadius)); 127 vertices.append(arcCenter + FloatPoint(cos(angle) * arcRadius, sin(angle ) * arcRadius));
126 } 128 }
127 vertices.append(endArcVertex); 129 vertices.append(endArcVertex);
128 } 130 }
129 131
130 static inline FloatPolygon *computeShapePaddingBounds(const FloatPolygon& polygo n, float padding, WindRule fillRule) 132 static inline FloatPolygon *computeShapePaddingBounds(const FloatPolygon& polygo n, float padding, WindRule fillRule)
131 { 133 {
132 Vector<FloatPoint>* paddedVertices = new Vector<FloatPoint>(); 134 Vector<FloatPoint>* paddedVertices = new Vector<FloatPoint>();
133 FloatPoint intersection; 135 FloatPoint intersection;
134 136
135 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) { 137 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) {
136 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i); 138 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i);
137 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge(); 139 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge();
138 OffsetPolygonEdge thisOffsetEdge(thisEdge, inwardEdgeNormal(thisEdge) * padding); 140 OffsetPolygonEdge thisOffsetEdge(thisEdge, inwardEdgeNormal(thisEdge) * padding);
139 OffsetPolygonEdge prevOffsetEdge(prevEdge, inwardEdgeNormal(prevEdge) * padding); 141 OffsetPolygonEdge prevOffsetEdge(prevEdge, inwardEdgeNormal(prevEdge) * padding);
140 142
141 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection)) 143 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection))
142 paddedVertices->append(intersection); 144 paddedVertices->append(intersection);
143 else if (isReflexVertex(prevEdge.vertex1(), thisEdge.vertex1(), thisEdge .vertex2())) 145 else if (isReflexVertex(prevEdge.vertex1(), thisEdge.vertex1(), thisEdge .vertex2()))
144 appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEd ge.vertex2(), thisOffsetEdge.vertex1()); 146 appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEd ge.vertex2(), thisOffsetEdge.vertex1(), true);
145 } 147 }
146 148
147 return new FloatPolygon(adoptPtr(paddedVertices), fillRule); 149 return new FloatPolygon(adoptPtr(paddedVertices), fillRule);
eseidel 2013/04/22 16:01:27 Also PassOwnPtr.
148 } 150 }
149 151
150 // FIXME: this is just a stub (bug 112917)
151 static inline FloatPolygon *computeShapeMarginBounds(const FloatPolygon& polygon , float margin, WindRule fillRule) 152 static inline FloatPolygon *computeShapeMarginBounds(const FloatPolygon& polygon , float margin, WindRule fillRule)
eseidel 2013/04/22 16:01:27 * goes next to the type in WK style.
152 { 153 {
153 UNUSED_PARAM(margin); 154 Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>();
eseidel 2013/04/22 16:01:27 Please use an OwnPtr so this doens't get accidenta
155 FloatPoint intersection;
154 156
155 Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>(polygon.numberOf Vertices()); 157 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) {
156 for (unsigned i = 0; i < polygon.numberOfVertices(); ++i) 158 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i);
157 (*marginVertices)[i] = polygon.vertexAt(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, prevOffsetEdg e.vertex2(), thisOffsetEdge.vertex1(), false);
167 }
168
158 return new FloatPolygon(adoptPtr(marginVertices), fillRule); 169 return new FloatPolygon(adoptPtr(marginVertices), fillRule);
eseidel 2013/04/22 16:01:27 This needs to return a PassOwnPtr for the same rea
159 } 170 }
160 171
161 const FloatPolygon& ExclusionPolygon::shapePaddingBounds() const 172 const FloatPolygon& ExclusionPolygon::shapePaddingBounds() const
162 { 173 {
163 ASSERT(shapePadding() >= 0); 174 ASSERT(shapePadding() >= 0);
164 if (!shapePadding()) 175 if (!shapePadding())
165 return m_polygon; 176 return m_polygon;
166 177
167 if (!m_paddingBounds) 178 if (!m_paddingBounds)
168 m_paddingBounds = adoptPtr(computeShapePaddingBounds(m_polygon, shapePad ding(), m_polygon.fillRule())); 179 m_paddingBounds = adoptPtr(computeShapePaddingBounds(m_polygon, shapePad ding(), m_polygon.fillRule()));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 332
322 if (x2 > x1) 333 if (x2 > x1)
323 result.append(ExclusionInterval(x1, x2)); 334 result.append(ExclusionInterval(x1, x2));
324 } 335 }
325 336
326 sortExclusionIntervals(result); 337 sortExclusionIntervals(result);
327 } 338 }
328 339
329 void ExclusionPolygon::getExcludedIntervals(float logicalTop, float logicalHeigh t, SegmentList& result) const 340 void ExclusionPolygon::getExcludedIntervals(float logicalTop, float logicalHeigh t, SegmentList& result) const
330 { 341 {
331 if (isEmpty()) 342 const FloatPolygon& polygon = shapeMarginBounds();
343 if (polygon.isEmpty())
332 return; 344 return;
333 345
334 float y1 = logicalTop; 346 float y1 = logicalTop;
335 float y2 = y1 + logicalHeight; 347 float y2 = y1 + logicalHeight;
336 348
337 Vector<ExclusionInterval> y1XIntervals, y2XIntervals; 349 Vector<ExclusionInterval> y1XIntervals, y2XIntervals;
338 computeXIntersections(m_polygon, y1, true, y1XIntervals); 350 computeXIntersections(polygon, y1, true, y1XIntervals);
339 computeXIntersections(m_polygon, y2, false, y2XIntervals); 351 computeXIntersections(polygon, y2, false, y2XIntervals);
340 352
341 Vector<ExclusionInterval> mergedIntervals; 353 Vector<ExclusionInterval> mergedIntervals;
342 mergeExclusionIntervals(y1XIntervals, y2XIntervals, mergedIntervals); 354 mergeExclusionIntervals(y1XIntervals, y2XIntervals, mergedIntervals);
343 355
344 Vector<ExclusionInterval> edgeIntervals; 356 Vector<ExclusionInterval> edgeIntervals;
345 computeOverlappingEdgeXProjections(m_polygon, y1, y2, edgeIntervals); 357 computeOverlappingEdgeXProjections(polygon, y1, y2, edgeIntervals);
346 358
347 Vector<ExclusionInterval> excludedIntervals; 359 Vector<ExclusionInterval> excludedIntervals;
348 mergeExclusionIntervals(mergedIntervals, edgeIntervals, excludedIntervals); 360 mergeExclusionIntervals(mergedIntervals, edgeIntervals, excludedIntervals);
349 361
350 for (unsigned i = 0; i < excludedIntervals.size(); ++i) { 362 for (unsigned i = 0; i < excludedIntervals.size(); ++i) {
351 ExclusionInterval interval = excludedIntervals[i]; 363 ExclusionInterval interval = excludedIntervals[i];
352 result.append(LineSegment(interval.x1, interval.x2)); 364 result.append(LineSegment(interval.x1, interval.x2));
353 } 365 }
354 } 366 }
355 367
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 489 }
478 } 490 }
479 } 491 }
480 492
481 if (firstFitFound) 493 if (firstFitFound)
482 result = firstFitRect.y(); 494 result = firstFitRect.y();
483 return firstFitFound; 495 return firstFitFound;
484 } 496 }
485 497
486 } // namespace WebCore 498 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/exclusions/shape-outside-floats/shape-outside-floats-right-margin-polygon-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698