Title: [87955] trunk/Source/WebCore
Revision
87955
Author
simon.fra...@apple.com
Date
2011-06-02 14:43:40 -0700 (Thu, 02 Jun 2011)

Log Message

2011-06-02  Simon Fraser  <simon.fra...@apple.com>

        Reviewed by Andreas Kling.

        Share Path code that uses beziers to construct a rounded rect
        https://bugs.webkit.org/show_bug.cgi?id=61960

        Have two methods in Path that construct beziers for rounded
        rects to share the same code.

        Make gCircleControlPoint a little more precise, and add
        a comment describing its derivation.

        Make use of FloatRect::maxX() and maxY().

        * platform/graphics/Path.cpp:
        (WebCore::Path::addRoundedRect):
        (WebCore::Path::addBeziersForRoundedRect):
        * platform/graphics/Path.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (87954 => 87955)


--- trunk/Source/WebCore/ChangeLog	2011-06-02 21:41:42 UTC (rev 87954)
+++ trunk/Source/WebCore/ChangeLog	2011-06-02 21:43:40 UTC (rev 87955)
@@ -1,3 +1,23 @@
+2011-06-02  Simon Fraser  <simon.fra...@apple.com>
+
+        Reviewed by Andreas Kling.
+
+        Share Path code that uses beziers to construct a rounded rect
+        https://bugs.webkit.org/show_bug.cgi?id=61960
+
+        Have two methods in Path that construct beziers for rounded
+        rects to share the same code.
+        
+        Make gCircleControlPoint a little more precise, and add
+        a comment describing its derivation.
+        
+        Make use of FloatRect::maxX() and maxY().
+
+        * platform/graphics/Path.cpp:
+        (WebCore::Path::addRoundedRect):
+        (WebCore::Path::addBeziersForRoundedRect):
+        * platform/graphics/Path.h:
+
 2011-06-02  Ryosuke Niwa  <rn...@webkit.org>
 
         Reviewed by Enrica Casucci.

Modified: trunk/Source/WebCore/platform/graphics/Path.cpp (87954 => 87955)


--- trunk/Source/WebCore/platform/graphics/Path.cpp	2011-06-02 21:41:42 UTC (rev 87954)
+++ trunk/Source/WebCore/platform/graphics/Path.cpp	2011-06-02 21:43:40 UTC (rev 87955)
@@ -35,9 +35,6 @@
 #include <math.h>
 #include <wtf/MathExtras.h>
 
-// Approximation of control point positions on a bezier to simulate a quarter of a circle.
-static const float gCircleControlPoint = 0.448f;
-
 namespace WebCore {
 
 #if !PLATFORM(OPENVG) && !PLATFORM(QT)
@@ -95,6 +92,11 @@
 }
 #endif
 
+void Path::addRoundedRect(const RoundedIntRect& r)
+{
+    addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii().bottomLeft(), r.radii().bottomRight());
+}
+
 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii)
 {
     if (rect.isEmpty())
@@ -113,29 +115,7 @@
     if (radius.height() > halfSize.height())
         radius.setHeight(halfSize.height());
 
-    moveTo(FloatPoint(rect.x() + radius.width(), rect.y()));
-
-    if (radius.width() < halfSize.width())
-        addLineTo(FloatPoint(rect.x() + rect.width() - roundingRadii.width(), rect.y()));
-
-    addBezierCurveTo(FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height()));
-
-    if (radius.height() < halfSize.height())
-        addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height()));
-
-    addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x() + rect.width() - radius.width(), rect.y() + rect.height()));
-
-    if (radius.width() < halfSize.width())
-        addLineTo(FloatPoint(rect.x() + radius.width(), rect.y() + rect.height()));
-
-    addBezierCurveTo(FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height()));
-
-    if (radius.height() < halfSize.height())
-        addLineTo(FloatPoint(rect.x(), rect.y() + radius.height()));
-
-    addBezierCurveTo(FloatPoint(rect.x(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + radius.width(), rect.y()));
-
-    closeSubpath();
+    addBeziersForRoundedRect(rect, radius, radius, radius, radius);
 }
 
 void Path::addRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius)
@@ -152,20 +132,29 @@
         return;
     }
 
+    addBeziersForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
+}
+
+// Approximation of control point positions on a bezier to simulate a quarter of a circle.
+// This is 1-kappa, where kappa = 4 * (sqrt(2) - 1) / 3
+static const float gCircleControlPoint = 0.447715f;
+
+void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius)
+{
     moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y()));
 
-    addLineTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width(), rect.y()));
-    addBezierCurveTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width() * gCircleControlPoint, rect.y()),
-                     FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height() * gCircleControlPoint),
-                     FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height()));
-    addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height()));
-    addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height() * gCircleControlPoint),
-                     FloatPoint(rect.x() + rect.width() - bottomRightRadius.width() * gCircleControlPoint, rect.y() + rect.height()),
-                     FloatPoint(rect.x() + rect.width() - bottomRightRadius.width(), rect.y() + rect.height()));
-    addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.y() + rect.height()));
-    addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.y() + rect.height()),
-                     FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height() * gCircleControlPoint),
-                     FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height()));
+    addLineTo(FloatPoint(rect.maxX() - topRightRadius.width(), rect.y()));
+    addBezierCurveTo(FloatPoint(rect.maxX() - topRightRadius.width() * gCircleControlPoint, rect.y()),
+                     FloatPoint(rect.maxX(), rect.y() + topRightRadius.height() * gCircleControlPoint),
+                     FloatPoint(rect.maxX(), rect.y() + topRightRadius.height()));
+    addLineTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height()));
+    addBezierCurveTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height() * gCircleControlPoint),
+                     FloatPoint(rect.maxX() - bottomRightRadius.width() * gCircleControlPoint, rect.maxY()),
+                     FloatPoint(rect.maxX() - bottomRightRadius.width(), rect.maxY()));
+    addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.maxY()));
+    addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.maxY()),
+                     FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height() * gCircleControlPoint),
+                     FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height()));
     addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height()));
     addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint),
                      FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()),
@@ -174,9 +163,4 @@
     closeSubpath();
 }
 
-void Path::addRoundedRect(const RoundedIntRect& r)
-{
-    addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii().bottomLeft(), r.radii().bottomRight());
 }
-
-}

Modified: trunk/Source/WebCore/platform/graphics/Path.h (87954 => 87955)


--- trunk/Source/WebCore/platform/graphics/Path.h	2011-06-02 21:41:42 UTC (rev 87954)
+++ trunk/Source/WebCore/platform/graphics/Path.h	2011-06-02 21:43:40 UTC (rev 87955)
@@ -148,6 +148,8 @@
         void transform(const AffineTransform&);
 
     private:
+        void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
+
         PlatformPathPtr m_path;
     };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to