RenderThemeIOS should use RenderTheme's color cache instead of its own.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:28:28 +0000 (19:28 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:28:28 +0000 (19:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194822
rdar://problem/48208296

Reviewed by Tim Horton.

Source/WebCore:

Tested by fast/css/apple-system-colors.html.

* css/CSSValueKeywords.in:
* css/parser/CSSPropertyParser.cpp:
(WebCore::isAppleLegacyCssValueKeyword):
* platform/graphics/Color.h:
* platform/graphics/cg/ColorCG.cpp:
(WebCore::makeRGBAFromCGColor):
(WebCore::Color::Color):
* rendering/RenderThemeIOS.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::systemColor const):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::systemColor const):

Source/WebCore/PAL:

* pal/ios/UIKitSoftLink.h:
* pal/ios/UIKitSoftLink.mm:
* pal/spi/ios/UIKitSPI.h:

LayoutTests:

* platform/ios/fast/css/apple-system-colors-expected.txt: Rebased for -apple-system-purple.
* platform/win/fast/css/apple-system-colors-expected.txt: Rebased for invalid color now
that -apple-system colors are macOS and iOS only.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/ios/fast/css/apple-system-colors-expected.txt
LayoutTests/platform/win/fast/css/apple-system-colors-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/ios/UIKitSoftLink.h
Source/WebCore/PAL/pal/ios/UIKitSoftLink.mm
Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/platform/graphics/cg/ColorCG.cpp
Source/WebCore/rendering/RenderThemeIOS.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.mm

index e7aab60..38abb52 100644 (file)
@@ -1,3 +1,15 @@
+2019-02-20  Timothy Hatcher  <timothy@apple.com>
+
+        RenderThemeIOS should use RenderTheme's color cache instead of its own.
+        https://bugs.webkit.org/show_bug.cgi?id=194822
+        rdar://problem/48208296
+
+        Reviewed by Tim Horton.
+
+        * platform/ios/fast/css/apple-system-colors-expected.txt: Rebased for -apple-system-purple.
+        * platform/win/fast/css/apple-system-colors-expected.txt: Rebased for invalid color now
+        that -apple-system colors are macOS and iOS only.
+
 2019-02-20  Loïc Yhuel  <loic.yhuel@softathome.com>
 
         Fix crash when opening Web Inspector after a WebSocket was blocked by content extensions
index eeb728b..83a9332 100644 (file)
@@ -4,7 +4,7 @@
 -apple-system-green : rgb(76, 217, 100)
 -apple-system-orange : rgb(255, 149, 0)
 -apple-system-pink : rgb(255, 45, 85)
--apple-system-purple : rgba(0, 0, 0, 0)
+-apple-system-purple : rgb(88, 86, 214)
 -apple-system-red : rgb(255, 59, 48)
 -apple-system-yellow : rgb(255, 204, 0)
 -apple-wireless-playback-target-active : rgb(0, 122, 255)
index 3390728..420cef4 100644 (file)
@@ -8,4 +8,4 @@
 -apple-system-red : rgba(0, 0, 0, 0)
 -apple-system-yellow : rgba(0, 0, 0, 0)
 -apple-wireless-playback-target-active : rgba(0, 0, 0, 0)
-current-color with inherited -apple-system-blue : rgba(0, 0, 0, 0)
+current-color with inherited -apple-system-blue : rgb(0, 0, 0)
index fdc54ed..6888107 100644 (file)
@@ -1,3 +1,26 @@
+2019-02-20  Timothy Hatcher  <timothy@apple.com>
+
+        RenderThemeIOS should use RenderTheme's color cache instead of its own.
+        https://bugs.webkit.org/show_bug.cgi?id=194822
+        rdar://problem/48208296
+
+        Reviewed by Tim Horton.
+
+        Tested by fast/css/apple-system-colors.html.
+
+        * css/CSSValueKeywords.in:
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::isAppleLegacyCssValueKeyword):
+        * platform/graphics/Color.h:
+        * platform/graphics/cg/ColorCG.cpp:
+        (WebCore::makeRGBAFromCGColor):
+        (WebCore::Color::Color):
+        * rendering/RenderThemeIOS.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::systemColor const):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::systemColor const):
+
 2019-02-20  Loïc Yhuel  <loic.yhuel@softathome.com>
 
         Fix crash when opening Web Inspector after a WebSocket was blocked by content extensions
index 7e5c531..caf3236 100644 (file)
@@ -1,3 +1,15 @@
+2019-02-20  Timothy Hatcher  <timothy@apple.com>
+
+        RenderThemeIOS should use RenderTheme's color cache instead of its own.
+        https://bugs.webkit.org/show_bug.cgi?id=194822
+        rdar://problem/48208296
+
+        Reviewed by Tim Horton.
+
+        * pal/ios/UIKitSoftLink.h:
+        * pal/ios/UIKitSoftLink.mm:
+        * pal/spi/ios/UIKitSPI.h:
+
 2019-02-16  Darin Adler  <darin@apple.com>
 
         Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc.
index f933959..90529f3 100644 (file)
@@ -56,6 +56,7 @@ SOFT_LINK_CLASS_FOR_HEADER(PAL, UILabel)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UIPasteboard)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UIScreen)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UITapGestureRecognizer)
+SOFT_LINK_CLASS_FOR_HEADER(PAL, UITraitCollection)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UIView)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UIViewController)
 SOFT_LINK_CLASS_FOR_HEADER(PAL, UIWindow)
index 33715cc..c2ed364 100644 (file)
@@ -56,6 +56,7 @@ SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UILabel)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UIPasteboard)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UIScreen)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UITapGestureRecognizer)
+SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UITraitCollection)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UIView)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UIViewController)
 SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, UIWindow)
index e1d46ac..dad3514 100644 (file)
@@ -109,6 +109,7 @@ typedef enum {
 + (UIColor *)systemGreenColor;
 + (UIColor *)systemOrangeColor;
 + (UIColor *)systemPinkColor;
++ (UIColor *)systemPurpleColor;
 + (UIColor *)systemRedColor;
 + (UIColor *)systemYellowColor;
 
index d8d3d2d..7e0e170 100644 (file)
@@ -222,22 +222,11 @@ threedshadow
 window
 windowframe
 windowtext
-#if defined(WTF_PLATFORM_MAC) && WTF_PLATFORM_MAC
+#if (defined(WTF_PLATFORM_MAC) && WTF_PLATFORM_MAC) || (defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
 -apple-system-header-text
 -apple-system-text-background
 -apple-system-control-background
--apple-system-alternate-selected-text
--apple-system-control-accent
--apple-system-even-alternating-content-background
--apple-system-odd-alternating-content-background
--apple-system-selected-content-background
--apple-system-unemphasized-selected-content-background
--apple-system-selected-text
--apple-system-unemphasized-selected-text
--apple-system-selected-text-background
--apple-system-unemphasized-selected-text-background
 -apple-system-placeholder-text
--apple-system-find-highlight-background
 -apple-system-label
 -apple-system-secondary-label
 -apple-system-tertiary-label
@@ -245,7 +234,14 @@ windowtext
 -apple-system-grid
 -apple-system-separator
 -apple-system-container-border
-#endif
+-apple-system-background
+-apple-system-secondary-background
+-apple-system-tertiary-background
+-apple-system-grouped-background
+-apple-system-secondary-grouped-background
+-apple-system-tertiary-grouped-background
+-apple-system-selected-content-background
+-apple-system-unemphasized-selected-content-background
 -apple-wireless-playback-target-active
 -apple-system-blue
 -apple-system-brown
@@ -256,6 +252,22 @@ windowtext
 -apple-system-purple
 -apple-system-red
 -apple-system-yellow
+#endif
+#if defined(WTF_PLATFORM_MAC) && WTF_PLATFORM_MAC
+-apple-system-alternate-selected-text
+-apple-system-control-accent
+-apple-system-even-alternating-content-background
+-apple-system-odd-alternating-content-background
+-apple-system-selected-text
+-apple-system-unemphasized-selected-text
+-apple-system-selected-text-background
+-apple-system-unemphasized-selected-text-background
+-apple-system-find-highlight-background
+#endif
+#if defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
+-apple-system-indigo
+-apple-system-teal
+#endif
 -webkit-focus-ring-color
 currentcolor
 //
index b6f117c..34a2d63 100644 (file)
@@ -156,12 +156,18 @@ static bool isAppleLegacyCssValueKeyword(const char* valueKeyword, unsigned leng
     static const char applePrefix[] = "-apple-";
     static const char appleSystemPrefix[] = "-apple-system";
     static const char applePayPrefix[] = "-apple-pay";
+
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     static const char* appleWirelessPlaybackTargetActive = getValueName(CSSValueAppleWirelessPlaybackTargetActive);
-    
+#endif
+
     return hasPrefix(valueKeyword, length, applePrefix)
     && !hasPrefix(valueKeyword, length, appleSystemPrefix)
     && !hasPrefix(valueKeyword, length, applePayPrefix)
-    && !WTF::equal(reinterpret_cast<const LChar*>(valueKeyword), reinterpret_cast<const LChar*>(appleWirelessPlaybackTargetActive), length);
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    && !WTF::equal(reinterpret_cast<const LChar*>(valueKeyword), reinterpret_cast<const LChar*>(appleWirelessPlaybackTargetActive), length)
+#endif
+    ;
 }
 
 template <typename CharacterType>
index 5d039bb..d6915c0 100644 (file)
@@ -262,6 +262,7 @@ public:
 
 #if USE(CG)
     WEBCORE_EXPORT Color(CGColorRef);
+    WEBCORE_EXPORT Color(CGColorRef, SemanticTag);
 #endif
 
 #if PLATFORM(WIN)
index f6e655a..109c640 100644 (file)
@@ -51,13 +51,8 @@ RetainPtr<CGColorRef> TinyLRUCachePolicy<WebCore::Color, RetainPtr<CGColorRef>>:
 
 namespace WebCore {
 
-Color::Color(CGColorRef color)
+static RGBA32 makeRGBAFromCGColor(CGColorRef color)
 {
-    if (!color) {
-        m_colorData.rgbaAndFlags = invalidRGBAColor;
-        return;
-    }
-
     size_t numComponents = CGColorGetNumberOfComponents(color);
     const CGFloat* components = CGColorGetComponents(color);
 
@@ -81,7 +76,29 @@ Color::Color(CGColorRef color)
         ASSERT_NOT_REACHED();
     }
 
-    setRGB(makeRGBA(r * 255, g * 255, b * 255, a * 255));
+    static const double scaleFactor = nextafter(256.0, 0.0);
+    return makeRGBA(r * scaleFactor, g * scaleFactor, b * scaleFactor, a * scaleFactor);
+}
+
+Color::Color(CGColorRef color)
+{
+    if (!color) {
+        m_colorData.rgbaAndFlags = invalidRGBAColor;
+        return;
+    }
+
+    setRGB(makeRGBAFromCGColor(color));
+}
+
+Color::Color(CGColorRef color, SemanticTag)
+{
+    if (!color) {
+        m_colorData.rgbaAndFlags = invalidRGBAColor;
+        return;
+    }
+
+    setRGB(makeRGBAFromCGColor(color));
+    setIsSemantic();
 }
 
 static CGColorRef leakCGColor(const Color& color)
index ed8927f..7385910 100644 (file)
@@ -159,8 +159,6 @@ private:
     String m_legacyMediaControlsStyleSheet;
     String m_mediaControlsStyleSheet;
 
-    mutable HashMap<int, Color> m_systemColorCache;
-
 #if USE(SYSTEM_PREVIEW)
     RetainPtr<CIContext> m_ciContext;
 #if HAVE(IOSURFACE)
index a28a4ad..113743f 100644 (file)
 #import <pal/spi/cocoa/CoreTextSPI.h>
 #import <pal/spi/ios/UIKitSPI.h>
 #import <wtf/NeverDestroyed.h>
+#import <wtf/ObjCRuntimeExtras.h>
 #import <wtf/RefPtr.h>
 #import <wtf/StdLibExtras.h>
 
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/RenderThemeIOSAdditions.mm>)
+#include <WebKitAdditions/RenderThemeIOSAdditions.mm>
+#endif
+
 @interface WebCoreRenderThemeBundle : NSObject
 @end
 
@@ -1413,56 +1418,60 @@ String RenderThemeIOS::mediaControlsBase64StringForIconNameAndType(const String&
 
 Color RenderThemeIOS::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::Options> options) const
 {
+    const bool useSystemAppearance = options.contains(StyleColor::Options::UseSystemAppearance);
     const bool forVisitedLink = options.contains(StyleColor::Options::ForVisitedLink);
 
+    auto& cache = colorCache(options);
+
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/RenderThemeIOSSystemColorAdditions.mm>)
+#include <WebKitAdditions/RenderThemeIOSSystemColorAdditions.mm>
+#endif
+
     // The system color cache below can't handle visited links. The only color value
     // that cares about visited links is CSSValueWebkitLink, so handle it here by
     // calling through to RenderTheme's base implementation.
     if (forVisitedLink && cssValueID == CSSValueWebkitLink)
         return RenderTheme::systemColor(cssValueID, options);
 
+    ASSERT_UNUSED(useSystemAppearance, !useSystemAppearance);
     ASSERT(!forVisitedLink);
 
-    auto addResult = m_systemColorCache.add(cssValueID, Color());
-    if (!addResult.isNewEntry)
-        return addResult.iterator->value;
-
-    Color color;
-    switch (cssValueID) {
-    case CSSValueAppleWirelessPlaybackTargetActive:
-        color = [PAL::getUIColorClass() systemBlueColor].CGColor;
-        break;
-    case CSSValueAppleSystemBlue:
-        color = [PAL::getUIColorClass() systemBlueColor].CGColor;
-        break;
-    case CSSValueAppleSystemGray:
-        color = [PAL::getUIColorClass() systemGrayColor].CGColor;
-        break;
-    case CSSValueAppleSystemGreen:
-        color = [PAL::getUIColorClass() systemGreenColor].CGColor;
-        break;
-    case CSSValueAppleSystemOrange:
-        color = [PAL::getUIColorClass() systemOrangeColor].CGColor;
-        break;
-    case CSSValueAppleSystemPink:
-        color = [PAL::getUIColorClass() systemPinkColor].CGColor;
-        break;
-    case CSSValueAppleSystemRed:
-        color = [PAL::getUIColorClass() systemRedColor].CGColor;
-        break;
-    case CSSValueAppleSystemYellow:
-        color = [PAL::getUIColorClass() systemYellowColor].CGColor;
-        break;
-    default:
-        break;
-    }
+    return cache.systemStyleColors.ensure(cssValueID, [this, cssValueID, options] () -> Color {
+        auto cssColorToSelector = [cssValueID] () -> SEL {
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/RenderThemeIOSColorToSelectorAdditions.mm>)
+#include <WebKitAdditions/RenderThemeIOSColorToSelectorAdditions.mm>
+#endif
 
-    if (!color.isValid())
-        color = RenderTheme::systemColor(cssValueID, options);
+            switch (cssValueID) {
+            case CSSValueAppleWirelessPlaybackTargetActive:
+            case CSSValueAppleSystemBlue:
+                return @selector(systemBlueColor);
+            case CSSValueAppleSystemGray:
+                return @selector(systemGrayColor);
+            case CSSValueAppleSystemGreen:
+                return @selector(systemGreenColor);
+            case CSSValueAppleSystemOrange:
+                return @selector(systemOrangeColor);
+            case CSSValueAppleSystemPink:
+                return @selector(systemPinkColor);
+            case CSSValueAppleSystemPurple:
+                return @selector(systemPurpleColor);
+            case CSSValueAppleSystemRed:
+                return @selector(systemRedColor);
+            case CSSValueAppleSystemYellow:
+                return @selector(systemYellowColor);
+            default:
+                return nullptr;
+            }
+        };
 
-    addResult.iterator->value = color;
+        if (auto selector = cssColorToSelector()) {
+            if (auto color = wtfObjCMsgSend<UIColor *>(PAL::getUIColorClass(), selector))
+                return Color(color.CGColor, Color::Semantic);
+        }
 
-    return addResult.iterator->value;
+        return RenderTheme::systemColor(cssValueID, options);
+    }).iterator->value;
 }
 
 #if ENABLE(ATTACHMENT_ELEMENT)
index ec33906..5dc10a0 100644 (file)
@@ -776,7 +776,6 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
                 return @selector(gridColor);
 #endif
             case CSSValueAppleWirelessPlaybackTargetActive:
-                return @selector(systemBlueColor);
             case CSSValueAppleSystemBlue:
                 return @selector(systemBlueColor);
             case CSSValueAppleSystemBrown: