Simplify Color's interface by removing isDark()
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2020 01:32:01 +0000 (01:32 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2020 01:32:01 +0000 (01:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213707

Reviewed by Darin Adler.

- Move Color::isDark to RenderThemeIOS.mm, its one client and rename it
  to useConvexGradient() to indicate what it is actually determining.

* platform/graphics/Color.cpp:
(WebCore::Color::isDark const): Deleted.
* platform/graphics/Color.h:
* rendering/RenderThemeIOS.mm:
(WebCore::useConvexGradient):
(WebCore::RenderThemeIOS::paintPushButtonDecorations):
(WebCore::RenderThemeIOS::paintFileUploadIconDecorations):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263713 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/rendering/RenderThemeIOS.mm

index 2c40c94..8420a47 100644 (file)
@@ -1,3 +1,21 @@
+2020-06-29  Sam Weinig  <weinig@apple.com>
+
+        Simplify Color's interface by removing isDark()
+        https://bugs.webkit.org/show_bug.cgi?id=213707
+
+        Reviewed by Darin Adler.
+
+        - Move Color::isDark to RenderThemeIOS.mm, its one client and rename it
+          to useConvexGradient() to indicate what it is actually determining.
+
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::isDark const): Deleted.
+        * platform/graphics/Color.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::useConvexGradient):
+        (WebCore::RenderThemeIOS::paintPushButtonDecorations):
+        (WebCore::RenderThemeIOS::paintFileUploadIconDecorations):
+
 2020-06-29  Peng Liu  <peng.liu6@apple.com>
 
         Video spills over PiP screen a little when using Picture in Picture
index f5c35c5..63dd040 100644 (file)
@@ -131,14 +131,6 @@ Color Color::darkened() const
     return makeSimpleColor(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
 }
 
-bool Color::isDark() const
-{
-    // FIXME: This should probably be using luminance.
-    auto [r, g, b, a] = toSRGBALossy();
-    float largestNonAlphaChannel = std::max({ r, g, b });
-    return a > 0.5 && largestNonAlphaChannel < 0.5;
-}
-
 float Color::lightness() const
 {
     // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for HSL.
index a35a0dd..f3dbf97 100644 (file)
@@ -141,7 +141,6 @@ public:
     WEBCORE_EXPORT float luminance() const;
 
     // FIXME: Replace remaining uses with luminance.
-    WEBCORE_EXPORT bool isDark() const;
     WEBCORE_EXPORT float lightness() const;
 
     // This is an implementation of Porter-Duff's "source-over" equation
index e6735f7..f276599 100644 (file)
@@ -1052,13 +1052,21 @@ bool RenderThemeIOS::paintButtonDecorations(const RenderObject& box, const Paint
     return paintPushButtonDecorations(box, paintInfo, rect);
 }
 
+static bool shouldUseConvexGradient(const Color& backgroundColor)
+{
+    // FIXME: This should probably be using luminance.
+    auto [r, g, b, a] = backgroundColor.toSRGBALossy();
+    float largestNonAlphaChannel = std::max({ r, g, b });
+    return a > 0.5 && largestNonAlphaChannel < 0.5;
+}
+
 bool RenderThemeIOS::paintPushButtonDecorations(const RenderObject& box, const PaintInfo& paintInfo, const IntRect& rect)
 {
     GraphicsContextStateSaver stateSaver(paintInfo.context());
     FloatRect clip = addRoundedBorderClip(box, paintInfo.context(), rect);
 
     CGContextRef cgContext = paintInfo.context().platformContext();
-    if (box.style().visitedDependentColor(CSSPropertyBackgroundColor).isDark())
+    if (shouldUseConvexGradient(box.style().visitedDependentColor(CSSPropertyBackgroundColor)))
         drawAxialGradient(cgContext, gradientWithName(ConvexGradient), clip.location(), FloatPoint(clip.x(), clip.maxY()), LinearInterpolation);
     else {
         drawAxialGradient(cgContext, gradientWithName(ShadeGradient), clip.location(), FloatPoint(clip.x(), clip.maxY()), LinearInterpolation);
@@ -1107,7 +1115,7 @@ bool RenderThemeIOS::paintFileUploadIconDecorations(const RenderObject&, const R
             GraphicsContextStateSaver stateSaver2(paintInfo.context());
             CGContextRef cgContext = paintInfo.context().platformContext();
             paintInfo.context().clip(thumbnailRect);
-            if (backgroundImageColor.isDark())
+            if (shouldUseConvexGradient(backgroundImageColor))
                 drawAxialGradient(cgContext, gradientWithName(ConvexGradient), thumbnailRect.location(), FloatPoint(thumbnailRect.x(), thumbnailRect.maxY()), LinearInterpolation);
             else {
                 drawAxialGradient(cgContext, gradientWithName(ShadeGradient), thumbnailRect.location(), FloatPoint(thumbnailRect.x(), thumbnailRect.maxY()), LinearInterpolation);