Integrate dark mode support for iOS.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jun 2019 19:19:16 +0000 (19:19 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jun 2019 19:19:16 +0000 (19:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198687
rdar://problem/51545643

Reviewed by Tim Horton.

Source/JavaScriptCore:

* Configurations/FeatureDefines.xcconfig:

Source/WebCore:

Tests: css-dark-mode

* Configurations/FeatureDefines.xcconfig:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::showLetterpressedGlyphsWithAdvances):
* platform/ios/LocalCurrentTraitCollection.h: Added.
* platform/ios/LocalCurrentTraitCollection.mm: Added.
* platform/ios/PasteboardIOS.mm:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::systemColor const):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::systemColor const):

Source/WebCore/PAL:

* Configurations/FeatureDefines.xcconfig:
* pal/spi/ios/UIKitSPI.h:

Source/WebKit:

* Configurations/FeatureDefines.xcconfig:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _effectiveAppearanceIsDark]):
(-[WKWebView _effectiveAppearanceIsInactive]):
(-[WKWebView _dynamicUserInterfaceTraitDidChange]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::effectiveAppearanceIsDark const):
(WebKit::PageClientImpl::effectiveAppearanceIsInactive const):
* UIProcess/ios/WKPasswordView.mm:
(-[WKPasswordView showInScrollView:]):
(configureScrollView): Deleted.

Source/WebKitLegacy/mac:

* Configurations/FeatureDefines.xcconfig:

Source/WTF:

* wtf/Platform.h:

Tools:

* TestWebKitAPI/Configurations/FeatureDefines.xcconfig:

LayoutTests:

* platform/ios/TestExpectations:

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

30 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/ios/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/Configurations/FeatureDefines.xcconfig
Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm
Source/WebCore/platform/ios/LocalCurrentTraitCollection.h [new file with mode: 0644]
Source/WebCore/platform/ios/LocalCurrentTraitCollection.mm [new file with mode: 0644]
Source/WebCore/platform/ios/PasteboardIOS.mm
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebKit/ChangeLog
Source/WebKit/Configurations/FeatureDefines.xcconfig
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/ios/WKPasswordView.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Configurations/FeatureDefines.xcconfig
Tools/ChangeLog
Tools/TestWebKitAPI/Configurations/FeatureDefines.xcconfig

index 238810e..fc32a87 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * platform/ios/TestExpectations:
+
 2019-06-10  Youenn Fablet  <youenn@apple.com>
 
         Call was negotiated with H264 Base Profile 42e01f but encoded in High Profile
index 25d58bc..e849fbc 100644 (file)
@@ -1144,6 +1144,9 @@ fast/css/variables/env/ios [ Pass ]
 # Dark mode not supported on iOS
 css-dark-mode [ Skip ]
 
+# Test Dark Mode CSS support for light mode on older systems.
+css-dark-mode/older-systems [ Pass ]
+
 ###
 # Known failures
 ##
@@ -3278,4 +3281,4 @@ fast/scrolling/ipad/overflow-scrolling-touch-enabled-stacking-modern-compatibili
 webkit.org/b/197778 [ Debug ] webgl/2.0.0/conformance2/attribs/gl-vertexattribipointer.html [ Slow ]
 
 # Was unskipped, but now has missing results in iOS . Skipping on iOS only.
-media/controls-after-reload.html [ Skip ]
\ No newline at end of file
+media/controls-after-reload.html [ Skip ]
index b708a4b..3cbfe26 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * Configurations/FeatureDefines.xcconfig:
+
 2019-06-10  Adrian Perez de Castro  <aperez@igalia.com>
 
         [JSC] Linker fails when unified sources are not in use
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));
index a3d4c99..7324451 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * wtf/Platform.h:
+
 2019-06-08  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] If we have a bound interface identifier, set it on new PKPaymentRequests
index 332eb3e..83d3673 100644 (file)
 #endif
 #endif
 
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(GTK)
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) || PLATFORM(GTK)
 #define HAVE_OS_DARK_MODE_SUPPORT 1
 #endif
 
index 72cd7ec..76e7949 100644 (file)
@@ -1,3 +1,26 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        Tests: css-dark-mode
+
+        * Configurations/FeatureDefines.xcconfig:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::showLetterpressedGlyphsWithAdvances):
+        * platform/ios/LocalCurrentTraitCollection.h: Added.
+        * platform/ios/LocalCurrentTraitCollection.mm: Added.
+        * platform/ios/PasteboardIOS.mm:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::systemColor const):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::systemColor const):
+
 2019-06-10  Ali Juma  <ajuma@chromium.org>
 
         REGRESSION (r245396): Page load time performance regression
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));
index fc3b4b4..cd1d516 100644 (file)
@@ -1,3 +1,14 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * Configurations/FeatureDefines.xcconfig:
+        * pal/spi/ios/UIKitSPI.h:
+
 2019-06-08  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] If we have a bound interface identifier, set it on new PKPaymentRequests
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));
index 12f351a..9b5e5a3 100644 (file)
@@ -116,6 +116,7 @@ typedef enum {
 + (UIColor *)systemPurpleColor;
 + (UIColor *)systemRedColor;
 + (UIColor *)systemYellowColor;
++ (UIColor *)systemTealColor;
 
 + (UIColor *)_disambiguated_due_to_CIImage_colorWithCGColor:(CGColorRef)cgColor;
 
@@ -161,4 +162,10 @@ NS_ASSUME_NONNULL_END
 @end
 #endif
 
+#if HAVE(OS_DARK_MODE_SUPPORT)
+@interface UIColor (UIColorInternal)
++ (UIColor *)tableCellDefaultSelectionTintColor;
+@end
+#endif
+
 #endif // PLATFORM(IOS_FAMILY)
index bd29e5b..6048303 100644 (file)
@@ -383,6 +383,7 @@ platform/ios/LegacyTileGrid.mm
 platform/ios/LegacyTileGridTile.mm
 platform/ios/LegacyTileLayer.mm
 platform/ios/LegacyTileLayerPool.mm
+platform/ios/LocalCurrentTraitCollection.mm
 platform/ios/LowPowerModeNotifierIOS.mm
 platform/ios/PasteboardIOS.mm
 platform/ios/PlatformEventFactoryIOS.mm @no-unify
index 7b69a86..0e46120 100644 (file)
                1C21E57D183ED1FF001C289D /* IOSurfacePool.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C21E57B183ED1FF001C289D /* IOSurfacePool.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C24EEA51C729CE40080F8FC /* FontFaceSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C24EEA31C729CE40080F8FC /* FontFaceSet.h */; };
                1C24EEA91C72A7B40080F8FC /* JSFontFaceSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C24EEA71C72A7B40080F8FC /* JSFontFaceSet.h */; };
+               1C43DE6B22AB4B8A001527D9 /* LocalCurrentTraitCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */; };
                1C6626111C6E7CA600AB527C /* FontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C66260F1C6E7CA600AB527C /* FontFace.h */; };
                1C73A7132185757E004CCEA5 /* TextUnderlineOffset.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C73A71521857587004CCEA5 /* TextDecorationThickness.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CB6B4F8217B83930093B9CD /* TextDecorationThickness.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C33277121CF0BE1000DC9F2 /* WHLSLNamedType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNamedType.h; sourceTree = "<group>"; };
                1C33277221CF0D2E000DC9F2 /* WHLSLUnnamedType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLUnnamedType.h; sourceTree = "<group>"; };
                1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCacheCoreText.cpp; sourceTree = "<group>"; };
+               1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentTraitCollection.h; sourceTree = "<group>"; };
+               1C43DE6A22AB4B8A001527D9 /* LocalCurrentTraitCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentTraitCollection.mm; sourceTree = "<group>"; };
                1C59B0182238687900853805 /* WHLSLScopedSetAdder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLScopedSetAdder.h; sourceTree = "<group>"; };
                1C66260E1C6E7CA600AB527C /* FontFace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFace.cpp; sourceTree = "<group>"; };
                1C66260F1C6E7CA600AB527C /* FontFace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontFace.h; sourceTree = "<group>"; };
                                E4B65A5D132FADB60070E7BE /* LegacyTileLayer.mm */,
                                E4E39AFA1330EFA8003AB274 /* LegacyTileLayerPool.h */,
                                E4E39AFC1330EFC5003AB274 /* LegacyTileLayerPool.mm */,
+                               1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */,
+                               1C43DE6A22AB4B8A001527D9 /* LocalCurrentTraitCollection.mm */,
                                46EFAF0D1E5FB9C200E7F34B /* LowPowerModeNotifierIOS.mm */,
                                E45390190EAFCACA003695C8 /* PasteboardIOS.mm */,
                                26601EBD14B3B9AD0012C0FE /* PlatformEventFactoryIOS.h */,
                                51E6821016387302003BBF3C /* LoaderStrategy.h in Headers */,
                                8A12E35D11FA33280025836A /* LoadTiming.h in Headers */,
                                06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
+                               1C43DE6B22AB4B8A001527D9 /* LocalCurrentTraitCollection.h in Headers */,
                                445775E520472F73008DCE5D /* LocalDefaultSystemAppearance.h in Headers */,
                                F5973DE015CFB2030027F804 /* LocaleMac.h in Headers */,
                                7633A72613D8B33A008501B6 /* LocaleToScriptMapping.h in Headers */,
index 3b2f141..c6e1a29 100644 (file)
@@ -129,8 +129,8 @@ static void showLetterpressedGlyphsWithAdvances(const FloatPoint& point, const F
         styleConfiguration.useSimplifiedEffect = YES;
     }
 
-#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/FontCascadeCocoaAdditions.mm>)
-#include <WebKitAdditions/FontCascadeCocoaAdditions.mm>
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    styleConfiguration.appearanceName = coreContext.useDarkAppearance() ? @"UIAppearanceDark" : @"UIAppearanceLight";
 #endif
 
     CGContextSetFont(context, adoptCF(CTFontCopyGraphicsFont(ctFont, nullptr)).get());
diff --git a/Source/WebCore/platform/ios/LocalCurrentTraitCollection.h b/Source/WebCore/platform/ios/LocalCurrentTraitCollection.h
new file mode 100644 (file)
index 0000000..626b014
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Noncopyable.h>
+#include <wtf/RetainPtr.h>
+
+#if PLATFORM(IOS_FAMILY)
+
+OBJC_CLASS UITraitCollection;
+
+namespace WebCore {
+
+// This class automatically saves and restores the current UITraitCollection for
+// functions which call out into UIKit and rely on the current UITraitCollection being set
+class LocalCurrentTraitCollection {
+    WTF_MAKE_NONCOPYABLE(LocalCurrentTraitCollection);
+
+public:
+    WEBCORE_EXPORT LocalCurrentTraitCollection(bool useDarkAppearance, bool useBaseLevelAppearance);
+    WEBCORE_EXPORT LocalCurrentTraitCollection(UITraitCollection *);
+    WEBCORE_EXPORT ~LocalCurrentTraitCollection();
+
+    bool usingDarkAppearance() const
+    {
+#if HAVE(OS_DARK_MODE_SUPPORT)
+        return m_usingDarkAppearance;
+#else
+        return false;
+#endif
+    }
+
+    bool usingBaseLevelAppearance() const
+    {
+#if HAVE(OS_DARK_MODE_SUPPORT)
+        return m_usingBaseLevelAppearance;
+#else
+        return true;
+#endif
+    }
+
+private:
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    RetainPtr<UITraitCollection> m_savedTraitCollection;
+    bool m_usingDarkAppearance { false };
+    bool m_usingBaseLevelAppearance { true };
+#endif
+};
+
+}
+
+#endif // PLATFORM(IOS_FAMILY)
+
diff --git a/Source/WebCore/platform/ios/LocalCurrentTraitCollection.mm b/Source/WebCore/platform/ios/LocalCurrentTraitCollection.mm
new file mode 100644 (file)
index 0000000..193567a
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocalCurrentTraitCollection.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#include <pal/ios/UIKitSoftLink.h>
+
+namespace WebCore {
+
+LocalCurrentTraitCollection::LocalCurrentTraitCollection(bool useDarkAppearance, bool useBaseLevelAppearance)
+{
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    m_savedTraitCollection = [PAL::getUITraitCollectionClass() _currentTraitCollection];
+    m_usingDarkAppearance = useDarkAppearance;
+    m_usingBaseLevelAppearance = useBaseLevelAppearance;
+
+    auto userInterfaceStyleTrait = [PAL::getUITraitCollectionClass() traitCollectionWithUserInterfaceStyle:m_usingDarkAppearance ? UIUserInterfaceStyleDark : UIUserInterfaceStyleLight];
+    auto backgroundLevelTrait = [PAL::getUITraitCollectionClass() traitCollectionWithUserInterfaceLevel:m_usingBaseLevelAppearance ? UIUserInterfaceLevelBase : UIUserInterfaceLevelElevated];
+    auto newTraitCollection = [PAL::getUITraitCollectionClass() traitCollectionWithTraitsFromCollections:@[ m_savedTraitCollection.get(), userInterfaceStyleTrait, backgroundLevelTrait ]];
+
+    [PAL::getUITraitCollectionClass() _setCurrentTraitCollection:newTraitCollection];
+#else
+    UNUSED_PARAM(useDarkAppearance);
+    UNUSED_PARAM(useBaseLevelAppearance);
+#endif
+}
+
+LocalCurrentTraitCollection::LocalCurrentTraitCollection(UITraitCollection *traitCollection)
+{
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    m_savedTraitCollection = [PAL::getUITraitCollectionClass() _currentTraitCollection];
+    m_usingDarkAppearance = traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
+    m_usingBaseLevelAppearance = traitCollection.userInterfaceLevel == UIUserInterfaceLevelBase;
+
+    [PAL::getUITraitCollectionClass() _setCurrentTraitCollection:traitCollection];
+#else
+    UNUSED_PARAM(traitCollection);
+#endif
+}
+
+LocalCurrentTraitCollection::~LocalCurrentTraitCollection()
+{
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    [PAL::getUITraitCollectionClass() _setCurrentTraitCollection:m_savedTraitCollection.get()];
+#endif
+}
+
+}
+
+#endif // PLATFORM(IOS_FAMILY)
index 8e005ca..c7f609b 100644 (file)
@@ -41,7 +41,7 @@
 #import <wtf/URL.h>
 #import <wtf/text/StringHash.h>
 
-@interface NSAttributedString (NSAttributedStringKitAdditions)
+@interface NSAttributedString (NSAttributedStringInternal)
 - (id)initWithRTF:(NSData *)data documentAttributes:(NSDictionary **)dict;
 - (id)initWithRTFD:(NSData *)data documentAttributes:(NSDictionary **)dict;
 - (NSData *)RTFFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict;
index 0e639f8..9da48fe 100644 (file)
@@ -52,6 +52,7 @@
 #import "HTMLSelectElement.h"
 #import "IOSurface.h"
 #import "Icon.h"
+#import "LocalCurrentTraitCollection.h"
 #import "LocalizedDateCache.h"
 #import "NodeRenderStyle.h"
 #import "Page.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
 
@@ -1446,16 +1443,54 @@ Color RenderThemeIOS::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
 
     auto& cache = colorCache(options);
     return cache.systemStyleColors.ensure(cssValueID, [this, cssValueID, options] () -> Color {
-#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/RenderThemeIOSSystemColorAdditions.mm>)
-#include <WebKitAdditions/RenderThemeIOSSystemColorAdditions.mm>
-#endif
+        const bool useDarkAppearance = options.contains(StyleColor::Options::UseDarkAppearance);
+        const bool useInactiveAppearance = options.contains(StyleColor::Options::UseInactiveAppearance);
+        LocalCurrentTraitCollection localTraitCollection(useDarkAppearance, useInactiveAppearance);
 
         auto cssColorToSelector = [cssValueID] () -> SEL {
-#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/RenderThemeIOSColorToSelectorAdditions.mm>)
-#include <WebKitAdditions/RenderThemeIOSColorToSelectorAdditions.mm>
-#endif
-
             switch (cssValueID) {
+#if HAVE(OS_DARK_MODE_SUPPORT)
+            case CSSValueText:
+            case CSSValueAppleSystemLabel:
+            case CSSValueAppleSystemHeaderText:
+                return @selector(labelColor);
+            case CSSValueAppleSystemSecondaryLabel:
+                return @selector(secondaryLabelColor);
+            case CSSValueAppleSystemTertiaryLabel:
+                return @selector(tertiaryLabelColor);
+            case CSSValueAppleSystemQuaternaryLabel:
+                return @selector(quaternaryLabelColor);
+            case CSSValueAppleSystemPlaceholderText:
+                return @selector(placeholderTextColor);
+            case CSSValueWebkitControlBackground:
+            case CSSValueAppleSystemControlBackground:
+            case CSSValueAppleSystemTextBackground:
+            case CSSValueAppleSystemBackground:
+                return @selector(systemBackgroundColor);
+            case CSSValueAppleSystemSecondaryBackground:
+                return @selector(secondarySystemBackgroundColor);
+            case CSSValueAppleSystemTertiaryBackground:
+                return @selector(tertiarySystemBackgroundColor);
+            case CSSValueAppleSystemGroupedBackground:
+                return @selector(systemGroupedBackgroundColor);
+            case CSSValueAppleSystemSecondaryGroupedBackground:
+                return @selector(secondarySystemGroupedBackgroundColor);
+            case CSSValueAppleSystemTertiaryGroupedBackground:
+                return @selector(tertiarySystemGroupedBackgroundColor);
+            case CSSValueAppleSystemGrid:
+            case CSSValueAppleSystemSeparator:
+            case CSSValueAppleSystemContainerBorder:
+                return @selector(separatorColor);
+            case CSSValueAppleSystemSelectedContentBackground:
+            case CSSValueAppleSystemUnemphasizedSelectedContentBackground:
+                return @selector(tableCellDefaultSelectionTintColor);
+            case CSSValueAppleSystemBrown:
+                return @selector(systemBrownColor);
+            case CSSValueAppleSystemIndigo:
+                return @selector(systemIndigoColor);
+#endif
+            case CSSValueAppleSystemTeal:
+                return @selector(systemTealColor);
             case CSSValueAppleWirelessPlaybackTargetActive:
             case CSSValueAppleSystemBlue:
                 return @selector(systemBlueColor);
index 7667de0..3e379cf 100644 (file)
@@ -713,6 +713,12 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
                 return @selector(windowFrameTextColor);
             case CSSValueAppleSystemHeaderText:
                 return @selector(headerTextColor);
+            case CSSValueAppleSystemBackground:
+            case CSSValueAppleSystemSecondaryBackground:
+            case CSSValueAppleSystemTertiaryBackground:
+            case CSSValueAppleSystemGroupedBackground:
+            case CSSValueAppleSystemSecondaryGroupedBackground:
+            case CSSValueAppleSystemTertiaryGroupedBackground:
             case CSSValueAppleSystemTextBackground:
                 return @selector(textBackgroundColor);
             case CSSValueAppleSystemControlBackground:
index cd34b60..8c184f3 100644 (file)
@@ -1,3 +1,25 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * Configurations/FeatureDefines.xcconfig:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _effectiveAppearanceIsDark]):
+        (-[WKWebView _effectiveAppearanceIsInactive]):
+        (-[WKWebView _dynamicUserInterfaceTraitDidChange]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::effectiveAppearanceIsDark const):
+        (WebKit::PageClientImpl::effectiveAppearanceIsInactive const):
+        * UIProcess/ios/WKPasswordView.mm:
+        (-[WKPasswordView showInScrollView:]):
+        (configureScrollView): Deleted.
+
 2019-06-10  Sihui Liu  <sihui_liu@apple.com>
 
         [WKHTTPCookieStore getAllCookies:] may return duplicate cookies
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));
index b2bf98f..20558c9 100644 (file)
@@ -473,11 +473,21 @@ static bool shouldAllowSettingAnyXHRHeaderFromFileURLs()
     return _focusPreservationCount || _activeFocusedStateRetainCount;
 }
 
-#endif
+- (BOOL)_effectiveAppearanceIsDark
+{
+    return self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
+}
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/WKWebViewInternalAdditions.mm>
+- (BOOL)_effectiveAppearanceIsInactive
+{
+#if HAVE(OS_DARK_MODE_SUPPORT) && !PLATFORM(WATCHOS)
+    return self.traitCollection.userInterfaceLevel != UIUserInterfaceLevelElevated;
+#else
+    return NO;
 #endif
+}
+
+#endif // PLATFORM(IOS_FAMILY)
 
 static bool shouldRequireUserGestureToLoadVideo()
 {
@@ -7257,11 +7267,15 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     [_contentView _simulateTextEntered:text];
 }
 
-#endif // PLATFORM(IOS_FAMILY)
+- (void)_dynamicUserInterfaceTraitDidChange
+{
+    if (!_page)
+        return;
+    _page->effectiveAppearanceDidChange();
+    [self _updateScrollViewBackground];
+}
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/WKWebViewAdditions.mm>
-#endif
+#endif // PLATFORM(IOS_FAMILY)
 
 - (BOOL)_beginBackSwipeForTesting
 {
index 56fe5c2..a8d153e 100644 (file)
@@ -169,11 +169,10 @@ struct PrintInfo;
 @property (nonatomic, readonly) UIEdgeInsets _computedObscuredInset;
 @property (nonatomic, readonly) UIEdgeInsets _computedUnobscuredSafeAreaInset;
 @property (nonatomic, readonly, getter=_isRetainingActiveFocusedState) BOOL _retainingActiveFocusedState;
-#endif
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/WKWebViewInternalAdditions.h>
-#endif
+- (BOOL)_effectiveAppearanceIsDark;
+- (BOOL)_effectiveAppearanceIsInactive;
+#endif // PLATFORM(IOS_FAMILY)
 
 #if ENABLE(ATTACHMENT_ELEMENT)
 - (void)_didRemoveAttachment:(API::Attachment&)attachment;
index 413c93b..3287185 100644 (file)
@@ -141,9 +141,8 @@ private:
         
     void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) override;
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/PageClientImplIOSAdditions.h>
-#endif
+    bool effectiveAppearanceIsDark() const override;
+    bool effectiveAppearanceIsInactive() const override;
 
     void couldNotRestorePageState() override;
     void restorePageState(Optional<WebCore::FloatPoint>, const WebCore::FloatPoint&, const WebCore::FloatBoxExtent&, double) override;
index 267bd43..9dc5a5a 100644 (file)
@@ -476,9 +476,15 @@ void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dicti
 #endif // ENABLE(REVEAL)
 }
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/PageClientImplIOSAdditions.mm>
-#endif
+bool PageClientImpl::effectiveAppearanceIsDark() const
+{
+    return [m_webView _effectiveAppearanceIsDark];
+}
+
+bool PageClientImpl::effectiveAppearanceIsInactive() const
+{
+    return [m_webView _effectiveAppearanceIsInactive];
+}
 
 void PageClientImpl::setRemoteLayerTreeRootNode(RemoteLayerTreeNode* rootNode)
 {
index 0111ec5..b1a49a1 100644 (file)
 #import <wtf/RetainPtr.h>
 #import <wtf/text/WTFString.h>
 
-#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKPasswordViewAdditions.mm>)
-#include <WebKitAdditions/WKPasswordViewAdditions.mm>
-#else
-static void configureScrollView(UIScrollView *scrollView)
-{
-    [scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
-}
-#endif
-
-
 const CGFloat passwordEntryFieldPadding = 10;
 
 @interface WKPasswordView () <UIDocumentPasswordViewDelegate>
@@ -111,7 +101,11 @@ const CGFloat passwordEntryFieldPadding = 10;
     [_scrollView setZoomScale:1];
     [_scrollView setContentSize:self.frame.size];
 
-    configureScrollView(_scrollView.get());
+#if HAVE(OS_DARK_MODE_SUPPORT)
+    [_scrollView setBackgroundColor:UIColor.systemGroupedBackgroundColor];
+#else
+    [_scrollView setBackgroundColor:UIColor.groupTableViewBackgroundColor];
+#endif
 
     [scrollView addSubview:self];
 }
index c4334a9..a5f7c2c 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * Configurations/FeatureDefines.xcconfig:
+
 2019-06-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         REGRESSION (r244182) [WK1]: Page updates should always scheduleCompositingLayerFlush() immediately
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));
index b60322f..84dfa77 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-10  Timothy Hatcher  <timothy@apple.com>
+
+        Integrate dark mode support for iOS.
+        https://bugs.webkit.org/show_bug.cgi?id=198687
+        rdar://problem/51545643
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Configurations/FeatureDefines.xcconfig:
+
 2019-06-10  Jonathan Bedard  <jbedard@apple.com>
 
         webkitpy: xcrun simctl spawn *** launchctl print system output is not utf-8
index 62ffb4a..da49952 100644 (file)
@@ -115,6 +115,9 @@ ENABLE_CURSOR_VISIBILITY = ENABLE_CURSOR_VISIBILITY;
 ENABLE_CUSTOM_SCHEME_HANDLER = ;
 
 ENABLE_DARK_MODE_CSS = $(ENABLE_DARK_MODE_CSS_$(WK_PLATFORM_NAME));
+ENABLE_DARK_MODE_CSS_iphoneos = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iphonesimulator = ENABLE_DARK_MODE_CSS;
+ENABLE_DARK_MODE_CSS_iosmac = ENABLE_DARK_MODE_CSS;
 ENABLE_DARK_MODE_CSS_macosx = ENABLE_DARK_MODE_CSS;
 
 ENABLE_DASHBOARD_SUPPORT = $(ENABLE_DASHBOARD_SUPPORT_$(WK_PLATFORM_NAME));