Title: [241748] trunk/Source/WebCore
Revision
241748
Author
dba...@webkit.org
Date
2019-02-18 16:15:34 -0800 (Mon, 18 Feb 2019)

Log Message

Clean up and modernize RenderThemeIOS::paintCheckboxDecorations()
https://bugs.webkit.org/show_bug.cgi?id=194785

Reviewed by Simon Fraser.

Change from early return to else-clause to make the states clearer and make it more straightforward
to share more common code. Use constexpr, allocate temporary vectors with inline capacity, and
switch to uniform initializer syntax.

* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintCheckboxDecorations):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (241747 => 241748)


--- trunk/Source/WebCore/ChangeLog	2019-02-19 00:10:35 UTC (rev 241747)
+++ trunk/Source/WebCore/ChangeLog	2019-02-19 00:15:34 UTC (rev 241748)
@@ -1,5 +1,19 @@
 2019-02-18  Daniel Bates  <daba...@apple.com>
 
+        Clean up and modernize RenderThemeIOS::paintCheckboxDecorations()
+        https://bugs.webkit.org/show_bug.cgi?id=194785
+
+        Reviewed by Simon Fraser.
+
+        Change from early return to else-clause to make the states clearer and make it more straightforward
+        to share more common code. Use constexpr, allocate temporary vectors with inline capacity, and
+        switch to uniform initializer syntax.
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::paintCheckboxDecorations):
+
+2019-02-18  Daniel Bates  <daba...@apple.com>
+
         [iOS] Focus ring for checkboxes, radio buttons, buttons and search fields should hug tighter to the contour
         https://bugs.webkit.org/show_bug.cgi?id=193599
         <rdar://problem/47399602>

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (241747 => 241748)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2019-02-19 00:10:35 UTC (rev 241747)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2019-02-19 00:15:34 UTC (rev 241748)
@@ -377,68 +377,57 @@
 
 bool RenderThemeIOS::paintCheckboxDecorations(const RenderObject& box, const PaintInfo& paintInfo, const IntRect& rect)
 {
-    GraphicsContextStateSaver stateSaver(paintInfo.context());
-    FloatRect clip = addRoundedBorderClip(box, paintInfo.context(), rect);
+    bool checked = isChecked(box);
+    bool indeterminate = isIndeterminate(box);
+    CGContextRef cgContext = paintInfo.context().platformContext();
 
+    GraphicsContextStateSaver stateSaver { paintInfo.context() };
+    auto clip = addRoundedBorderClip(box, paintInfo.context(), rect);
     float width = clip.width();
     float height = clip.height();
 
-    bool checked = isChecked(box);
-    bool indeterminate = isIndeterminate(box);
+    if (checked || indeterminate) {
+        drawAxialGradient(cgContext, gradientWithName(ConcaveGradient), clip.location(), FloatPoint { clip.x(), clip.maxY() }, LinearInterpolation);
 
-    CGContextRef cgContext = paintInfo.context().platformContext();
-    if (!checked && !indeterminate) {
-        FloatPoint bottomCenter(clip.x() + clip.width() / 2.0f, clip.maxY());
-        drawAxialGradient(cgContext, gradientWithName(ShadeGradient), clip.location(), FloatPoint(clip.x(), clip.maxY()), LinearInterpolation);
-        drawRadialGradient(cgContext, gradientWithName(ShineGradient), bottomCenter, 0, bottomCenter, sqrtf((width * width) / 4.0f + height * height), ExponentialInterpolation);
-        return false;
-    }
+        constexpr float thicknessRatio = 2 / 14.0;
+        float lineWidth = std::min(width, height) * 2.0f * thicknessRatio;
 
-    drawAxialGradient(cgContext, gradientWithName(ConcaveGradient), clip.location(), FloatPoint(clip.x(), clip.maxY()), LinearInterpolation);
+        Vector<CGPoint, 3> line;
+        Vector<CGPoint, 3> shadow;
+        if (checked) {
+            constexpr CGSize size { 14.0f, 14.0f };
+            constexpr CGPoint pathRatios[] = {
+                { 2.5f / size.width, 7.5f / size.height },
+                { 5.5f / size.width, 10.5f / size.height },
+                { 11.5f / size.width, 2.5f / size.height }
+            };
 
-    static const float thicknessRatio = 2 / 14.0;
-    static const CGSize size = { 14.0f, 14.0f };
-    float lineWidth = std::min(width, height) * 2.0f * thicknessRatio;
+            line.uncheckedAppend(CGPointMake(clip.x() + width * pathRatios[0].x, clip.y() + height * pathRatios[0].y));
+            line.uncheckedAppend(CGPointMake(clip.x() + width * pathRatios[1].x, clip.y() + height * pathRatios[1].y));
+            line.uncheckedAppend(CGPointMake(clip.x() + width * pathRatios[2].x, clip.y() + height * pathRatios[2].y));
 
-    Vector<CGPoint> line;
-    Vector<CGPoint> shadow;
+            shadow.uncheckedAppend(shortened(line[0], line[1], lineWidth / 4.0f));
+            shadow.uncheckedAppend(line[1]);
+            shadow.uncheckedAppend(shortened(line[2], line[1], lineWidth / 4.0f));
+        } else {
+            line.uncheckedAppend(CGPointMake(clip.x() + 3.5, clip.center().y()));
+            line.uncheckedAppend(CGPointMake(clip.maxX() - 3.5, clip.center().y()));
 
-    if (checked) {
-        static const CGPoint pathRatios[3] = {
-            { 2.5f / size.width, 7.5f / size.height },
-            { 5.5f / size.width, 10.5f / size.height },
-            { 11.5f / size.width, 2.5f / size.height }
-        };
+            shadow.uncheckedAppend(shortened(line[0], line[1], lineWidth / 4.0f));
+            shadow.uncheckedAppend(shortened(line[1], line[0], lineWidth / 4.0f));
+        }
 
-        line = {
-            CGPointMake(clip.x() + width * pathRatios[0].x, clip.y() + height * pathRatios[0].y),
-            CGPointMake(clip.x() + width * pathRatios[1].x, clip.y() + height * pathRatios[1].y),
-            CGPointMake(clip.x() + width * pathRatios[2].x, clip.y() + height * pathRatios[2].y)
-        };
+        lineWidth = std::max<float>(lineWidth, 1);
+        drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(shadow) }, kCGLineCapSquare, lineWidth, Color { 0.0f, 0.0f, 0.0f, 0.7f });
 
-        shadow = {
-            shortened(line[0], line[1], lineWidth / 4.0f),
-            line[1],
-            shortened(line[2], line[1], lineWidth / 4.0f)
-        };
-    } else if (indeterminate) {
-        line = {
-            CGPointMake(clip.x() + 3.5, clip.center().y()),
-            CGPointMake(clip.maxX() - 3.5, clip.center().y())
-        };
+        lineWidth = std::max<float>(std::min(clip.width(), clip.height()) * thicknessRatio, 1);
+        drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(line) }, kCGLineCapButt, lineWidth, Color { 1.0f, 1.0f, 1.0f, 240 / 255.0f });
+    } else {
+        FloatPoint bottomCenter { clip.x() + clip.width() / 2.0f, clip.maxY() };
 
-        shadow = {
-            shortened(line[0], line[1], lineWidth / 4.0f),
-            shortened(line[1], line[0], lineWidth / 4.0f)
-        };
+        drawAxialGradient(cgContext, gradientWithName(ShadeGradient), clip.location(), FloatPoint { clip.x(), clip.maxY() }, LinearInterpolation);
+        drawRadialGradient(cgContext, gradientWithName(ShineGradient), bottomCenter, 0, bottomCenter, sqrtf((width * width) / 4.0f + height * height), ExponentialInterpolation);
     }
-
-    lineWidth = std::max<float>(lineWidth, 1);
-    drawJoinedLines(cgContext, shadow, kCGLineCapSquare, lineWidth, Color(0.0f, 0.0f, 0.0f, 0.7f));
-
-    lineWidth = std::max<float>(std::min(clip.width(), clip.height()) * thicknessRatio, 1);
-    drawJoinedLines(cgContext, line, kCGLineCapButt, lineWidth, Color(1.0f, 1.0f, 1.0f, 240 / 255.0f));
-
     return false;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to