Clean up LocalDefaultSystemAppearance and prefers-dark-interface media query
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 22:26:58 +0000 (22:26 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 22:26:58 +0000 (22:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186323
rdar://problem/38382252

Reviewed by Tim Horton.

Source/WebCore:

* css/MediaFeatureNames.h:
* css/MediaQueryEvaluator.cpp:
(WebCore::prefersDarkInterfaceEvaluate):
(WebCore::defaultAppearanceEvaluate): Deleted.
* css/MediaQueryExpression.cpp:
(WebCore::featureWithValidIdent):
(WebCore::isFeatureValidWithoutValue):
* platform/mac/LocalDefaultSystemAppearance.mm:
(WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance):

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _defaultAppearance]):
* UIProcess/API/mac/WKView.mm:
(-[WKView _defaultAppearance]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::useDefaultAppearance):

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _defaultAppearance]):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/MediaFeatureNames.h
Source/WebCore/css/MediaQueryEvaluator.cpp
Source/WebCore/css/MediaQueryExpression.cpp
Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/mac/WKView.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebView.mm

index c646d13..4e0c983 100644 (file)
@@ -1,3 +1,22 @@
+2018-06-05  Timothy Hatcher  <timothy@apple.com>
+
+        Clean up LocalDefaultSystemAppearance and prefers-dark-interface media query
+
+        https://bugs.webkit.org/show_bug.cgi?id=186323
+        rdar://problem/38382252
+
+        Reviewed by Tim Horton.
+
+        * css/MediaFeatureNames.h:
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::prefersDarkInterfaceEvaluate):
+        (WebCore::defaultAppearanceEvaluate): Deleted.
+        * css/MediaQueryExpression.cpp:
+        (WebCore::featureWithValidIdent):
+        (WebCore::isFeatureValidWithoutValue):
+        * platform/mac/LocalDefaultSystemAppearance.mm:
+        (WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance):
+
 2018-06-05  Darin Adler  <darin@apple.com>
 
         [Cocoa] Improve some soft linking compatibility with ARC
index adbd6f0..81a6680 100644 (file)
 #define CSS_MEDIAQUERY_DISPLAY_MODE(macro)
 #endif
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/MediaFeatureNamesAdditions.h>
-#else
-#define DEFAULT_APPEARANCE_MEDIA_QUERY "prefers-default-appearance"
-#endif
-
-
 #define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
     macro(animation, "-webkit-animation") \
     macro(anyHover, "any-hover") \
@@ -77,7 +70,7 @@
     macro(monochrome, "monochrome") \
     macro(orientation, "orientation") \
     macro(pointer, "pointer") \
-    macro(defaultAppearance, DEFAULT_APPEARANCE_MEDIA_QUERY) \
+    macro(prefersDarkInterface, "prefers-dark-interface") \
     macro(prefersReducedMotion, "prefers-reduced-motion") \
     macro(resolution, "resolution") \
     macro(transform2d, "-webkit-transform-2d") \
index 5b7cb06..8c793c2 100644 (file)
@@ -713,17 +713,17 @@ static bool anyPointerEvaluate(CSSValue* value, const CSSToLengthConversionData&
     return pointerEvaluate(value, cssToLengthConversionData, frame, prefix);
 }
     
-static bool defaultAppearanceEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
+static bool prefersDarkInterfaceEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
 {
-    bool defaultAppearance = false;
-    
+    bool prefersDarkInterface = false;
+
     if (!frame.page()->defaultAppearance())
-        defaultAppearance = true;
-    
+        prefersDarkInterface = true;
+
     if (!value)
-        return defaultAppearance;
-    
-    return downcast<CSSPrimitiveValue>(*value).valueID() == (defaultAppearance ? CSSValuePrefers : CSSValueNoPreference);
+        return prefersDarkInterface;
+
+    return downcast<CSSPrimitiveValue>(*value).valueID() == (prefersDarkInterface ? CSSValuePrefers : CSSValueNoPreference);
 }
 
 static bool prefersReducedMotionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
index 2d8e5f0..d553392 100644 (file)
@@ -54,7 +54,7 @@ static inline bool featureWithValidIdent(const AtomicString& mediaFeature, const
     || mediaFeature == MediaFeatureNames::displayMode
 #endif
     || mediaFeature == MediaFeatureNames::prefersReducedMotion
-    || (mediaFeature == MediaFeatureNames::defaultAppearance && context.useSystemAppearance);
+    || (mediaFeature == MediaFeatureNames::prefersDarkInterface && context.useSystemAppearance);
 }
 
 static inline bool featureWithValidDensity(const String& mediaFeature, const CSSPrimitiveValue& value)
@@ -162,7 +162,7 @@ static inline bool isFeatureValidWithoutValue(const AtomicString& mediaFeature,
         || mediaFeature == MediaFeatureNames::invertedColors
         || mediaFeature == MediaFeatureNames::pointer
         || mediaFeature == MediaFeatureNames::prefersReducedMotion
-        || (mediaFeature == MediaFeatureNames::defaultAppearance && context.useSystemAppearance)
+        || (mediaFeature == MediaFeatureNames::prefersDarkInterface && context.useSystemAppearance)
         || mediaFeature == MediaFeatureNames::devicePixelRatio
         || mediaFeature == MediaFeatureNames::resolution
 #if ENABLE(APPLICATION_MANIFEST)
index 5512309..bf9592d 100644 (file)
 
 namespace WebCore {
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/LocalDefaultSystemAppearanceAdditions.mm>
-#else
-LocalDefaultSystemAppearance::LocalDefaultSystemAppearance(bool useSystemAppearance, bool)
+LocalDefaultSystemAppearance::LocalDefaultSystemAppearance(bool useSystemAppearance, bool useDefaultAppearance)
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     m_savedSystemAppearance = [NSAppearance currentAppearance];
-    [NSAppearance setCurrentAppearance:useSystemAppearance ? [NSApp effectiveAppearance] : [NSAppearance appearanceNamed:NSAppearanceNameAqua]];
+    [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:(!useSystemAppearance || useDefaultAppearance ? NSAppearanceNameAqua : NSAppearanceNameDarkAqua)]];
 #else
     UNUSED_PARAM(useSystemAppearance);
+    UNUSED_PARAM(useDefaultAppearance);
 #endif
 }
-#endif
 
 LocalDefaultSystemAppearance::~LocalDefaultSystemAppearance()
 {
index 9e33562..81c97c2 100644 (file)
@@ -1,3 +1,20 @@
+2018-06-05  Timothy Hatcher  <timothy@apple.com>
+
+        Clean up LocalDefaultSystemAppearance and prefers-dark-interface media query
+
+        https://bugs.webkit.org/show_bug.cgi?id=186323
+        rdar://problem/38382252
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _defaultAppearance]):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _defaultAppearance]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::useDefaultAppearance):
+
 2018-06-05  Sihui Liu  <sihui_liu@apple.com>
 
         [iOS] TestWebKitAPI.WebKit.WKHTTPCookieStoreWithoutProcessPool fails because cookies aren't flushed to file
index 0e642a6..1cb60ec 100644 (file)
@@ -470,11 +470,10 @@ static uint32_t convertSystemLayoutDirection(NSUserInterfaceLayoutDirection dire
     return static_cast<uint32_t>(WebCore::UserInterfaceLayoutDirection::LTR);
 }
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewAndWKWebViewAdditions.mm>
-#else
-- (bool)_defaultAppearance { return true; }
-#endif
+- (bool)_defaultAppearance
+{
+    return _impl->useDefaultAppearance();
+}
 
 #endif // PLATFORM(MAC)
 
index 2ff40f4..f68e981 100644 (file)
@@ -1620,11 +1620,10 @@ static _WKOverlayScrollbarStyle toAPIScrollbarStyle(std::optional<WebCore::Scrol
     _data->_impl->setShouldSuppressFirstResponderChanges(shouldSuppress);
 }
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewAndWKWebViewAdditions.mm>
-#else
-- (bool)_defaultAppearance { return true; }
-#endif
+- (bool)_defaultAppearance
+{
+    return _data->_impl->useDefaultAppearance();
+}
 
 - (void)effectiveAppearanceDidChange
 {
index 16f5390..e3994d3 100644 (file)
@@ -539,6 +539,7 @@ public:
     void setUseSystemAppearance(bool);
     bool useSystemAppearance();
     void setDefaultAppearance(bool);
+    bool useDefaultAppearance();
 
 private:
 #if HAVE(TOUCH_BAR)
index d64f476..6f94bc6 100644 (file)
@@ -5013,6 +5013,19 @@ bool WebViewImpl::useSystemAppearance()
     return m_page->useSystemAppearance();
 }
 
+bool WebViewImpl::useDefaultAppearance()
+{
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    if (!useSystemAppearance())
+        return true;
+
+    NSAppearanceName appearance = [[m_view effectiveAppearance] bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
+    return [appearance isEqualToString:NSAppearanceNameAqua];
+#else
+    return true;
+#endif
+}
+
 void WebViewImpl::setDefaultAppearance(bool defaultAppearance)
 {
     m_page->setDefaultAppearance(defaultAppearance);
index 9ed70f2..d86f4cf 100644 (file)
@@ -1,3 +1,15 @@
+2018-06-05  Timothy Hatcher  <timothy@apple.com>
+
+        Clean up LocalDefaultSystemAppearance and prefers-dark-interface media query
+
+        https://bugs.webkit.org/show_bug.cgi?id=186323
+        rdar://problem/38382252
+
+        Reviewed by Tim Horton.
+
+        * WebView/WebView.mm:
+        (-[WebView _defaultAppearance]):
+
 2018-06-05  Brent Fulgham  <bfulgham@apple.com>
 
         Revise DEFAULT_EXPERIMENTAL_FEATURES_ENABLED to work properly on Apple builds
index 7875a7e..0e2f7c2 100644 (file)
@@ -5275,12 +5275,18 @@ static Vector<String> toStringVector(NSArray* patterns)
     return insets;
 }
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewAndWKWebViewAdditions.mm>
+- (bool)_defaultAppearance
+{
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    if (![self _useSystemAppearance])
+        return true;
+
+    NSAppearanceName appearance = [[self effectiveAppearance] bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
+    return [appearance isEqualToString:NSAppearanceNameAqua];
 #else
-- (bool)_defaultAppearance { return true; }
+    return true;
 #endif
-
+}
 
 - (void)_updateDefaultAppearance
 {