Title: [131768] trunk/Source/WebCore
Revision
131768
Author
commit-qu...@webkit.org
Date
2012-10-18 10:16:29 -0700 (Thu, 18 Oct 2012)

Log Message

[CSS Exclusions] Add ExclusionShape::shapeBoundingBox() method
https://bugs.webkit.org/show_bug.cgi?id=99216

Patch by Hans Muller <hmul...@adobe.com> on 2012-10-18
Reviewed by Dirk Schulze.

Added a FloatRect::extend() method which simplifies writing loops that
accumulate the bounding box for a sequence of FloatPoints. The new method
is used by ExclusionPolygon to initialize the shape's logical and physical
bounding boxes. This a clean-up, not a change in functionality. It's already
covered by the existing fast/exclusions LayoutTests.

* platform/graphics/FloatRect.cpp:
(WebCore::FloatRect::extend): Extend the FloatRect's bounds to include a FloatPoint.
(WebCore):
* platform/graphics/FloatRect.h:
(FloatRect): Added extend() method.
* rendering/ExclusionPolygon.cpp:
(WebCore::ExclusionPolygon::ExclusionPolygon): Use FloatRect::extend() to compute the polygon's internal bounding box.
* rendering/ExclusionShape.cpp:
(WebCore::ExclusionShape::createExclusionShape): Use FloatRect::extend() to compute the polygon's physical bounding box.
* rendering/ExclusionShape.h:
(WebCore::ExclusionShape::shapeBoundingBox): Return the shape's bounding box in physical coordinates.
(ExclusionShape):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (131767 => 131768)


--- trunk/Source/WebCore/ChangeLog	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/ChangeLog	2012-10-18 17:16:29 UTC (rev 131768)
@@ -1,5 +1,31 @@
 2012-10-18  Hans Muller  <hmul...@adobe.com>
 
+        [CSS Exclusions] Add ExclusionShape::shapeBoundingBox() method
+        https://bugs.webkit.org/show_bug.cgi?id=99216
+
+        Reviewed by Dirk Schulze.
+
+        Added a FloatRect::extend() method which simplifies writing loops that
+        accumulate the bounding box for a sequence of FloatPoints. The new method
+        is used by ExclusionPolygon to initialize the shape's logical and physical
+        bounding boxes. This a clean-up, not a change in functionality. It's already
+        covered by the existing fast/exclusions LayoutTests.
+
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::FloatRect::extend): Extend the FloatRect's bounds to include a FloatPoint.
+        (WebCore):
+        * platform/graphics/FloatRect.h:
+        (FloatRect): Added extend() method.
+        * rendering/ExclusionPolygon.cpp:
+        (WebCore::ExclusionPolygon::ExclusionPolygon): Use FloatRect::extend() to compute the polygon's internal bounding box.
+        * rendering/ExclusionShape.cpp:
+        (WebCore::ExclusionShape::createExclusionShape): Use FloatRect::extend() to compute the polygon's physical bounding box.
+        * rendering/ExclusionShape.h:
+        (WebCore::ExclusionShape::shapeBoundingBox): Return the shape's bounding box in physical coordinates.
+        (ExclusionShape):
+
+2012-10-18  Hans Muller  <hmul...@adobe.com>
+
         [CSS Exclusions] Handle special case "empty" shapes
         https://bugs.webkit.org/show_bug.cgi?id=99342
 

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (131767 => 131768)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-10-18 17:16:29 UTC (rev 131768)
@@ -134,6 +134,16 @@
     uniteEvenIfEmpty(other);
 }
 
+void FloatRect::extend(const FloatPoint& p)
+{
+    float minX = min(x(), p.x());
+    float minY = min(y(), p.y());
+    float maxX = max(this->maxX(), p.x());
+    float maxY = max(this->maxY(), p.y());
+
+    setLocationAndSizeFromEdges(minX, minY, maxX, maxY);
+}
+
 void FloatRect::scale(float sx, float sy)
 {
     m_location.setX(x() * sx);

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.h (131767 => 131768)


--- trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-10-18 17:16:29 UTC (rev 131768)
@@ -164,6 +164,7 @@
     void unite(const FloatRect&);
     void uniteEvenIfEmpty(const FloatRect&);
     void uniteIfNonZero(const FloatRect&);
+    void extend(const FloatPoint&);
 
     // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
     // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.

Modified: trunk/Source/WebCore/rendering/ExclusionPolygon.cpp (131767 => 131768)


--- trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2012-10-18 17:16:29 UTC (rev 131768)
@@ -62,20 +62,12 @@
     m_empty = nVertices < 3;
     Vector<ExclusionPolygonEdge*> sortedEdgesMinY(nVertices);
 
-    const FloatPoint& vertex0 = vertexAt(0);
-    float minX = vertex0.x();
-    float minY = vertex0.y();
-    float maxX = minX;
-    float maxY = minY;
+    if (nVertices)
+        m_boundingBox.setLocation(vertexAt(0));
 
     for (unsigned i = 0; i < nVertices; i++) {
         const FloatPoint& vertex = vertexAt(i);
-
-        minX = std::min(vertex.x(), minX);
-        maxX = std::max(vertex.x(), maxX);
-        minY = std::min(vertex.y(), minY);
-        maxY = std::max(vertex.y(), maxY);
-
+        m_boundingBox.extend(vertex);
         m_edges[i].polygon = this;
         m_edges[i].index1 = i;
         m_edges[i].index2 = (i + 1) % nVertices;
@@ -83,11 +75,6 @@
         sortedEdgesMinY[i] = &m_edges[i];
     }
 
-    m_boundingBox.setX(minX);
-    m_boundingBox.setY(minY);
-    m_boundingBox.setWidth(maxX - minX);
-    m_boundingBox.setHeight(maxY - minY);
-
     std::sort(sortedEdgesMinY.begin(), sortedEdgesMinY.end(), WebCore::compareEdgeMinY);
 
     for (unsigned i = 0; i < m_edges.size(); i++) {

Modified: trunk/Source/WebCore/rendering/ExclusionShape.cpp (131767 => 131768)


--- trunk/Source/WebCore/rendering/ExclusionShape.cpp	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/rendering/ExclusionShape.cpp	2012-10-18 17:16:29 UTC (rev 131768)
@@ -82,18 +82,21 @@
 
     case BasicShape::BASIC_SHAPE_RECTANGLE: {
         const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRectangle*>(basicShape);
-        float x = floatValueForLength(rectangle->x(), boxWidth);
-        float y = floatValueForLength(rectangle->y(), boxHeight);
-        float width = floatValueForLength(rectangle->width(), boxWidth);
-        float height = floatValueForLength(rectangle->height(), boxHeight);
+        FloatRect bounds(
+            floatValueForLength(rectangle->x(), boxWidth),
+            floatValueForLength(rectangle->y(), boxHeight),
+            floatValueForLength(rectangle->width(), boxWidth),
+            floatValueForLength(rectangle->height(), boxHeight));
         Length radiusXLength = rectangle->cornerRadiusX();
         Length radiusYLength = rectangle->cornerRadiusY();
-        float radiusX = radiusXLength.isUndefined() ? 0 : floatValueForLength(radiusXLength, boxWidth);
-        float radiusY = radiusYLength.isUndefined() ? 0 : floatValueForLength(radiusYLength, boxHeight);
+        FloatSize cornerRadii(
+            radiusXLength.isUndefined() ? 0 : floatValueForLength(radiusXLength, boxWidth),
+            radiusYLength.isUndefined() ? 0 : floatValueForLength(radiusYLength, boxHeight));
 
         exclusionShape = horizontalWritingMode
-            ? createExclusionRectangle(FloatRect(x, y, width, height), FloatSize(radiusX, radiusY))
-            : createExclusionRectangle(FloatRect(y, x, height, width), FloatSize(radiusY, radiusX));
+            ? createExclusionRectangle(bounds, cornerRadii)
+            : createExclusionRectangle(bounds.transposedRect(), cornerRadii.transposedSize());
+        exclusionShape->m_boundingBox = bounds;
         break;
     }
 
@@ -106,6 +109,7 @@
         exclusionShape = horizontalWritingMode
             ? createExclusionCircle(FloatPoint(centerX, centerY), radius)
             : createExclusionCircle(FloatPoint(centerY, centerX), radius);
+        exclusionShape->m_boundingBox = FloatRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
         break;
     }
 
@@ -119,6 +123,7 @@
         exclusionShape = horizontalWritingMode
             ? createExclusionEllipse(FloatPoint(centerX, centerY), FloatSize(radiusX, radiusY))
             : createExclusionEllipse(FloatPoint(centerY, centerX), FloatSize(radiusY, radiusX));
+        exclusionShape->m_boundingBox = FloatRect(centerX - radiusX, centerY - radiusY, radiusX * 2, radiusY * 2);
         break;
     }
 
@@ -127,14 +132,20 @@
         const Vector<Length>& values = polygon->values();
         size_t valuesSize = values.size();
         ASSERT(!(valuesSize % 2));
+        FloatRect boundingBox;
         Vector<FloatPoint>* vertices = new Vector<FloatPoint>(valuesSize / 2);
         for (unsigned i = 0; i < valuesSize; i += 2) {
             FloatPoint vertex(
                 floatValueForLength(values.at(i), boxWidth),
                 floatValueForLength(values.at(i + 1), boxHeight));
             (*vertices)[i / 2] = horizontalWritingMode ? vertex : vertex.transposedPoint();
+            if (!i)
+                boundingBox.setLocation(vertex);
+            else
+                boundingBox.extend(vertex);
         }
         exclusionShape = createExclusionPolygon(adoptPtr(vertices), polygon->windRule());
+        exclusionShape->m_boundingBox = boundingBox;
         break;
     }
 

Modified: trunk/Source/WebCore/rendering/ExclusionShape.h (131767 => 131768)


--- trunk/Source/WebCore/rendering/ExclusionShape.h	2012-10-18 17:10:14 UTC (rev 131767)
+++ trunk/Source/WebCore/rendering/ExclusionShape.h	2012-10-18 17:16:29 UTC (rev 131768)
@@ -64,6 +64,7 @@
     virtual ~ExclusionShape() { }
 
     virtual FloatRect shapeLogicalBoundingBox() const = 0;
+    virtual FloatRect shapeBoundingBox() const { return m_boundingBox; }
     virtual void getIncludedIntervals(float logicalTop, float logicalBottom, SegmentList&) const = 0;
     virtual void getExcludedIntervals(float logicalTop, float logicalBottom, SegmentList&) const = 0;
     virtual bool isEmpty() const = 0;
@@ -77,6 +78,7 @@
     WritingMode m_writingMode;
     float m_logicalBoxWidth;
     float m_logicalBoxHeight;
+    FloatRect m_boundingBox;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to