Make it easier for non-Apple ports to enable dark mode CSS support.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 01:51:03 +0000 (01:51 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 01:51:03 +0000 (01:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193882

Reviewed by Megan Gardner.

Source/WebCore:

* page/FrameView.cpp:
(WebCore::FrameView::updateBackgroundRecursively): Limit use of system
background color to the Mac platform.
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::purgeCaches): Purge m_darkColorCache.
(WebCore::RenderTheme::platformColorsDidChange): Reset m_darkColorCache.
(WebCore::RenderTheme::colorCache const): Added m_darkColorCache.
* rendering/RenderTheme.h:
(WebCore::RenderTheme::colorCache const): Deleted.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::purgeCaches): Removed m_darkColorCache.
(WebCore::RenderThemeMac::platformColorsDidChange): Deleted.
(WebCore::RenderThemeMac::colorCache const): Deleted.

Source/WebKit:

Make modern WebKit code for dark mode usable by other ports, to match
the WebCore parts that have been cross-platform all along.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/PageClient.h:
(WebKit::PageClient::effectiveAppearanceIsDark const):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::useDarkAppearance const):
(WebKit::WebPageProxy::effectiveAppearanceDidChange):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_shouldAttachDrawingAreaOnPageTransition):
(WebKit::WebPage::setUseDarkAppearance):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]): Fix some defines.
(-[WebView _effectiveAppearanceIsDark]): Ditto.

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebView.mm

index b9260e6..f43ca04 100644 (file)
@@ -1,3 +1,25 @@
+2019-01-28  Timothy Hatcher  <timothy@apple.com>
+
+        Make it easier for non-Apple ports to enable dark mode CSS support.
+        https://bugs.webkit.org/show_bug.cgi?id=193882
+
+        Reviewed by Megan Gardner.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::updateBackgroundRecursively): Limit use of system
+        background color to the Mac platform.
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::purgeCaches): Purge m_darkColorCache.
+        (WebCore::RenderTheme::platformColorsDidChange): Reset m_darkColorCache.
+        (WebCore::RenderTheme::colorCache const): Added m_darkColorCache.
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::colorCache const): Deleted.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::purgeCaches): Removed m_darkColorCache.
+        (WebCore::RenderThemeMac::platformColorsDidChange): Deleted.
+        (WebCore::RenderThemeMac::colorCache const): Deleted.
+
 2019-01-28  Simon Fraser  <simon.fraser@apple.com>
 
         svg/text/select-text-inside-non-static-position.html crashes under ScrollingStateTree::unparentChildrenAndDestroyNode()
index 4a8ef53..b6bbaf3 100644 (file)
@@ -3013,7 +3013,7 @@ void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
 
 void FrameView::updateBackgroundRecursively(bool transparent)
 {
-#if ENABLE(DARK_MODE_CSS)
+#if ENABLE(DARK_MODE_CSS) && PLATFORM(MAC)
     Color backgroundColor = transparent ? Color::transparent : RenderTheme::singleton().systemColor(CSSValueAppleSystemControlBackground, styleColorOptions());
 #else
     Color backgroundColor = transparent ? Color::transparent : Color::white;
index c4fa356..2a45f10 100644 (file)
@@ -1216,15 +1216,24 @@ void RenderTheme::adjustSearchFieldResultsButtonStyle(StyleResolver&, RenderStyl
 void RenderTheme::purgeCaches()
 {
     m_colorCache = ColorCache();
+    m_darkColorCache = ColorCache();
 }
 
 void RenderTheme::platformColorsDidChange()
 {
     m_colorCache = ColorCache();
+    m_darkColorCache = ColorCache();
 
     Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
 }
 
+auto RenderTheme::colorCache(OptionSet<StyleColor::Options> options) const -> ColorCache&
+{
+    if (options.contains(StyleColor::Options::UseDarkAppearance))
+        return m_darkColorCache;
+    return m_colorCache;
+}
+
 FontCascadeDescription& RenderTheme::cachedSystemFontDescription(CSSValueID systemFontID) const
 {
     static NeverDestroyed<FontCascadeDescription> caption;
index a6292a4..471a9a3 100644 (file)
@@ -438,10 +438,11 @@ protected:
         Color inactiveTextSearchHighlightColor;
     };
 
-    virtual ColorCache& colorCache(OptionSet<StyleColor::Options>) const { return m_colorCache; }
+    virtual ColorCache& colorCache(OptionSet<StyleColor::Options>) const;
 
 private:
     mutable ColorCache m_colorCache;
+    mutable ColorCache m_darkColorCache;
 };
 
 } // namespace WebCore
index b74344c..a1361af 100644 (file)
@@ -68,8 +68,6 @@ public:
 
     ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) final { return SmallScrollbar; }
 
-    void platformColorsDidChange() final;
-
     int minimumMenuListSize(const RenderStyle&) const final;
 
     void adjustSliderThumbSize(RenderStyle&, const Element*) const final;
@@ -177,8 +175,6 @@ private:
 
     Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const final;
 
-    ColorCache& colorCache(OptionSet<StyleColor::Options>) const final;
-
     void purgeCaches() final;
 
     // Get the control size based off the font. Used by some of the controls (like buttons).
@@ -256,8 +252,6 @@ private:
     bool m_isSliderThumbHorizontalPressed { false };
     bool m_isSliderThumbVerticalPressed { false };
 
-    mutable ColorCache m_darkColorCache;
-
     RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
 
     String m_legacyMediaControlsScript;
index afee9d0..ec33906 100644 (file)
@@ -335,7 +335,6 @@ void RenderThemeMac::purgeCaches()
     m_mediaControlsScript.clearImplIfNotShared();
     m_legacyMediaControlsStyleSheet.clearImplIfNotShared();
     m_mediaControlsStyleSheet.clearImplIfNotShared();
-    m_darkColorCache = ColorCache();
 
     RenderTheme::purgeCaches();
 }
@@ -605,21 +604,6 @@ static RGBA32 menuBackgroundColor()
     return makeRGBA(pixel[0], pixel[1], pixel[2], pixel[3]);
 }
 
-void RenderThemeMac::platformColorsDidChange()
-{
-    m_darkColorCache = ColorCache();
-
-    RenderTheme::platformColorsDidChange();
-}
-
-auto RenderThemeMac::colorCache(OptionSet<StyleColor::Options> options) const -> ColorCache&
-{
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
-    if (localAppearance.usingDarkAppearance())
-        return m_darkColorCache;
-    return RenderTheme::colorCache(options);
-}
-
 Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::Options> options) const
 {
     const bool useSystemAppearance = options.contains(StyleColor::Options::UseSystemAppearance);
index 99d6056..e35e6af 100644 (file)
@@ -1,3 +1,30 @@
+2019-01-28  Timothy Hatcher  <timothy@apple.com>
+
+        Make it easier for non-Apple ports to enable dark mode CSS support.
+        https://bugs.webkit.org/show_bug.cgi?id=193882
+
+        Reviewed by Megan Gardner.
+
+        Make modern WebKit code for dark mode usable by other ports, to match
+        the WebCore parts that have been cross-platform all along.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::effectiveAppearanceIsDark const):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        (WebKit::WebPageProxy::useDarkAppearance const):
+        (WebKit::WebPageProxy::effectiveAppearanceDidChange):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_shouldAttachDrawingAreaOnPageTransition):
+        (WebKit::WebPage::setUseDarkAppearance):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2019-01-28  Andy Estes  <aestes@apple.com>
 
         [Cocoa] Add SPI to _WKUserContentExtensionStore to retrieve its underlying WKContentRuleListStore
index 6d07c03..af75d99 100644 (file)
@@ -74,11 +74,11 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << mimeTypesWithCustomContentProviders;
     encoder << controlledByAutomation;
     encoder << isProcessSwap;
+    encoder << useDarkAppearance;
 
 #if PLATFORM(MAC)
     encoder << colorSpace;
     encoder << useSystemAppearance;
-    encoder << useDarkAppearance;
 #endif
 #if PLATFORM(IOS_FAMILY)
     encoder << screenSize;
@@ -229,14 +229,14 @@ Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decod
         return WTF::nullopt;
     if (!decoder.decode(parameters.isProcessSwap))
         return WTF::nullopt;
+    if (!decoder.decode(parameters.useDarkAppearance))
+        return WTF::nullopt;
 
 #if PLATFORM(MAC)
     if (!decoder.decode(parameters.colorSpace))
         return WTF::nullopt;
     if (!decoder.decode(parameters.useSystemAppearance))
         return WTF::nullopt;
-    if (!decoder.decode(parameters.useDarkAppearance))
-        return WTF::nullopt;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
index b382cee..fb327e4 100644 (file)
@@ -131,10 +131,11 @@ struct WebPageCreationParameters {
     bool controlledByAutomation;
     bool isProcessSwap { false };
 
+    bool useDarkAppearance { false };
+
 #if PLATFORM(MAC)
     ColorSpaceData colorSpace;
     bool useSystemAppearance;
-    bool useDarkAppearance;
 #endif
 #if PLATFORM(IOS_FAMILY)
     WebCore::FloatSize screenSize;
index 43413af..4872c94 100644 (file)
@@ -311,6 +311,8 @@ public:
     virtual void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) = 0;
 #endif
 
+    virtual bool effectiveAppearanceIsDark() const { return false; }
+
     virtual void enterAcceleratedCompositingMode(const LayerTreeContext&) = 0;
     virtual void exitAcceleratedCompositingMode() = 0;
     virtual void updateAcceleratedCompositingMode(const LayerTreeContext&) = 0;
@@ -337,8 +339,6 @@ public:
     virtual NSWindow *platformWindow() = 0;
     virtual void setShouldSuppressFirstResponderChanges(bool) = 0;
 
-    virtual bool effectiveAppearanceIsDark() const = 0;
-
 #if WK_API_ENABLED
     virtual NSView *inspectorAttachmentView() = 0;
     virtual _WKRemoteObjectRegistry *remoteObjectRegistry() = 0;
index 756f686..47d320f 100644 (file)
@@ -6785,10 +6785,10 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
     parameters.backgroundExtendsBeyondPage = m_backgroundExtendsBeyondPage;
     parameters.layerHostingMode = m_layerHostingMode;
     parameters.controlledByAutomation = m_controlledByAutomation;
+    parameters.useDarkAppearance = useDarkAppearance();
 #if PLATFORM(MAC)
     parameters.colorSpace = pageClient().colorSpace();
     parameters.useSystemAppearance = m_useSystemAppearance;
-    parameters.useDarkAppearance = useDarkAppearance();
 #endif
 #if PLATFORM(IOS_FAMILY)
     parameters.screenSize = screenSize();
@@ -7406,11 +7406,6 @@ void WebPageProxy::handleAlternativeTextUIResult(const String& result)
         m_process->send(Messages::WebPage::HandleAlternativeTextUIResult(result), m_pageID);
 }
 
-bool WebPageProxy::useDarkAppearance() const
-{
-    return pageClient().effectiveAppearanceIsDark();
-}
-
 #if USE(DICTATION_ALTERNATIVES)
 void WebPageProxy::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
 {
@@ -7917,14 +7912,6 @@ void WebPageProxy::setUseSystemAppearance(bool useSystemAppearance)
     m_process->send(Messages::WebPage::SetUseSystemAppearance(useSystemAppearance), m_pageID);
 }
     
-void WebPageProxy::effectiveAppearanceDidChange()
-{
-    if (!isValid())
-        return;
-
-    m_process->send(Messages::WebPage::SetUseDarkAppearance(useDarkAppearance()), m_pageID);
-}
-
 void WebPageProxy::setHeaderBannerHeightForTesting(int height)
 {
     m_process->send(Messages::WebPage::SetHeaderBannerHeightForTesting(height), m_pageID);
@@ -8274,6 +8261,19 @@ void WebPageProxy::requestStorageAccess(String&& subFrameHost, String&& topFrame
 }
 #endif
 
+bool WebPageProxy::useDarkAppearance() const
+{
+    return pageClient().effectiveAppearanceIsDark();
+}
+
+void WebPageProxy::effectiveAppearanceDidChange()
+{
+    if (!isValid())
+        return;
+
+    m_process->send(Messages::WebPage::SetUseDarkAppearance(useDarkAppearance()), m_pageID);
+}
+
 #if PLATFORM(COCOA)
 void WebPageProxy::touchBarMenuDataChanged(const TouchBarMenuData& touchBarMenuData)
 {
index 19b12f4..a5ec160 100644 (file)
@@ -897,9 +897,10 @@ public:
 #if PLATFORM(MAC)
     void setUseSystemAppearance(bool);
     bool useSystemAppearance() const { return m_useSystemAppearance; }
+#endif
+
     void effectiveAppearanceDidChange();
     bool useDarkAppearance() const;
-#endif
 
 #if PLATFORM(COCOA)
     // Called by the web process through a message.
index d0b9753..dbec358 100644 (file)
@@ -523,10 +523,13 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     setPageLength(parameters.pageLength);
     setGapBetweenPages(parameters.gapBetweenPages);
     setPaginationLineGridEnabled(parameters.paginationLineGridEnabled);
+
+    setUseDarkAppearance(parameters.useDarkAppearance);
+
 #if PLATFORM(MAC)
     setUseSystemAppearance(parameters.useSystemAppearance);
-    setUseDarkAppearance(parameters.useDarkAppearance);
 #endif
+
     // If the page is created off-screen, its visibilityState should be prerender.
     m_page->setActivityState(m_activityState);
     if (!isVisible())
@@ -4501,12 +4504,13 @@ void WebPage::setUseSystemAppearance(bool useSystemAppearance)
 {
     corePage()->setUseSystemAppearance(useSystemAppearance);
 }
-    
+
+#endif
+
 void WebPage::setUseDarkAppearance(bool useDarkAppearance)
 {
     corePage()->setUseDarkAppearance(useDarkAppearance);
 }
-#endif
 
 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
 {
index e764f99..3a4fdc0 100644 (file)
@@ -537,9 +537,10 @@ public:
     void setBottomOverhangImage(WebImage*);
     
     void setUseSystemAppearance(bool);
-    void setUseDarkAppearance(bool);
 #endif
 
+    void setUseDarkAppearance(bool);
+
     bool windowIsFocused() const;
     bool windowAndWebPageAreFocused() const;
 
index 4dbe0a3..0270b8b 100644 (file)
@@ -474,12 +474,13 @@ messages -> WebPage LegacyReceiver {
     HandleAcceptedCandidate(struct WebCore::TextCheckingResult acceptedCandidate)
 
     SetUseSystemAppearance(bool useSystemAppearance);
-    SetUseDarkAppearance(bool useDarkAppearance);
 
     SetHeaderBannerHeightForTesting(int height);
     SetFooterBannerHeightForTesting(int height);
 #endif
 
+    SetUseDarkAppearance(bool useDarkAppearance);
+
 #if PLATFORM(COCOA)
     RequestActiveNowPlayingSessionInfo(WebKit::CallbackID callbackID)
 #endif
index 003561e..2dbc8a4 100644 (file)
@@ -1,3 +1,14 @@
+2019-01-28  Timothy Hatcher  <timothy@apple.com>
+
+        Make it easier for non-Apple ports to enable dark mode CSS support.
+        https://bugs.webkit.org/show_bug.cgi?id=193882
+
+        Reviewed by Megan Gardner.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]): Fix some defines.
+        (-[WebView _effectiveAppearanceIsDark]): Ditto.
+
 2019-01-27  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Introduce a static accessibility tree
index eaef8ff..0f4b84c 100644 (file)
@@ -1583,6 +1583,9 @@ static void WebKitInitializeGamepadProviderIfNecessary()
         ResourceHandle::forceContentSniffing();
 
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
+#endif
+
+#if HAVE(OS_DARK_MODE_SUPPORT) && PLATFORM(MAC)
     _private->page->setUseDarkAppearance(self._effectiveAppearanceIsDark);
 #endif
 
@@ -5293,15 +5296,13 @@ static Vector<String> toStringVector(NSArray* patterns)
     return insets;
 }
 
+#if HAVE(OS_DARK_MODE_SUPPORT) && PLATFORM(MAC)
 - (bool)_effectiveAppearanceIsDark
 {
-#if HAVE(OS_DARK_MODE_SUPPORT)
     NSAppearanceName appearance = [[self effectiveAppearance] bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
     return [appearance isEqualToString:NSAppearanceNameDarkAqua];
-#else
-    return false;
-#endif
 }
+#endif
 
 - (void)_setUseSystemAppearance:(BOOL)useSystemAppearance
 {
@@ -5317,6 +5318,7 @@ static Vector<String> toStringVector(NSArray* patterns)
     return _private->page->useSystemAppearance();
 }
 
+#if HAVE(OS_DARK_MODE_SUPPORT) && PLATFORM(MAC)
 - (void)viewDidChangeEffectiveAppearance
 {
     // This can be called during [super initWithCoder:] and [super initWithFrame:].
@@ -5326,6 +5328,7 @@ static Vector<String> toStringVector(NSArray* patterns)
 
     _private->page->setUseDarkAppearance(self._effectiveAppearanceIsDark);
 }
+#endif
 
 - (void)_setSourceApplicationAuditData:(NSData *)sourceApplicationAuditData
 {