Add <meta name="supported-color-schemes"> to control what color schemes the page supports
https://bugs.webkit.org/show_bug.cgi?id=190526
rdar://problem/45230140

Reviewed by Dean Jackson.

Source/WebCore:

Test: css-dark-mode/supported-color-schemes.html

* dom/Document.cpp:
(WebCore::isColorSchemeSeparator): Added.
(WebCore::processColorSchemes): Added.
(WebCore::Document::processSupportedColorSchemes): Added.
(WebCore::Document::useDarkAppearance const): Take system appearance and document's
suppoerted color shcemes into account.
* dom/Document.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragment): Update use of LocalDefaultSystemAppearance.
* html/HTMLMetaElement.cpp:
(WebCore::HTMLMetaElement::process): Added supported-color-schemes behind runtime feature check.
* inspector/InspectorOverlay.cpp:
(WebCore::InspectorOverlay::paint): Update use of LocalDefaultSystemAppearance.
* platform/mac/DragImageMac.mm:
(WebCore::createDragImageForLink): Update use of LocalDefaultSystemAppearance.
* platform/mac/LocalDefaultSystemAppearance.h:
* platform/mac/LocalDefaultSystemAppearance.mm:
(WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance):
Drop the need for useSystemAppearance. This is accounted for in Document::useDarkAppearance.
* platform/mac/ThemeMac.mm:
(WebCore::ThemeMac::paint): Update use of LocalDefaultSystemAppearance.
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::paintContents): Update use of LocalDefaultSystemAppearance.
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::paintContents): Update use of LocalDefaultSystemAppearance.
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::paint): Use document instead of page.
* rendering/RenderThemeCocoa.mm:
(WebCore::RenderThemeCocoa::drawLineForDocumentMarker): Update use of LocalDefaultSystemAppearance.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::documentViewFor const): Update use of LocalDefaultSystemAppearance.
(WebCore::RenderThemeMac::platformActiveSelectionBackgroundColor const): Ditto.
(WebCore::RenderThemeMac::platformInactiveSelectionBackgroundColor const): Ditto.
(WebCore::RenderThemeMac::transformSelectionBackgroundColor const): Ditto.
(WebCore::RenderThemeMac::supportsSelectionForegroundColors const): Ditto.
(WebCore::RenderThemeMac::platformActiveSelectionForegroundColor const): Ditto.
(WebCore::RenderThemeMac::platformInactiveSelectionForegroundColor const): Ditto.
(WebCore::RenderThemeMac::platformActiveListBoxSelectionBackgroundColor const): Ditto.
(WebCore::RenderThemeMac::platformInactiveListBoxSelectionBackgroundColor const): Ditto.
(WebCore::RenderThemeMac::platformActiveListBoxSelectionForegroundColor const): Ditto.
(WebCore::RenderThemeMac::platformInactiveListBoxSelectionForegroundColor const): Ditto.
(WebCore::RenderThemeMac::platformActiveTextSearchHighlightColor const): Ditto.
(WebCore::RenderThemeMac::colorCache const): Ditto.
(WebCore::RenderThemeMac::systemColor const): Ditto.
(WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary): Ditto.
(WebCore::RenderThemeMac::paintSliderThumb): Ditto.
(WebCore::RenderThemeMac::usingDarkAppearance const): No need to limit to macOS here.
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::draw): Update use of LocalDefaultSystemAppearance.

Source/WebKit:

* UIProcess/mac/WKPrintingView.mm:
(-[WKPrintingView drawRect:]): Update use of LocalDefaultSystemAppearance.
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::renderedImage): Ditto.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::paintControlForLayerInContext): Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::drawRect): Ditto.

Source/WebKitLegacy/mac:

* WebCoreSupport/WebEditorClient.mm:
(_WebCreateFragment): Update use of LocalDefaultSystemAppearance.

LayoutTests:

* css-dark-mode/supported-color-schemes-expected.txt: Added.
* css-dark-mode/supported-color-schemes.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@237204 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index bbd97cb..9f6b5ab 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2018-10-16  Timothy Hatcher  <timothy@apple.com>
+
+        Add <meta name="supported-color-schemes"> to control what color schemes the page supports
+        https://bugs.webkit.org/show_bug.cgi?id=190526
+        rdar://problem/45230140
+
+        Reviewed by Dean Jackson.
+
+        * css-dark-mode/supported-color-schemes-expected.txt: Added.
+        * css-dark-mode/supported-color-schemes.html: Added.
+
 2018-10-16  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Canvas: capture previously saved states and add them to the recording payload
diff --git a/LayoutTests/css-dark-mode/supported-color-schemes-expected.txt b/LayoutTests/css-dark-mode/supported-color-schemes-expected.txt
new file mode 100644
index 0000000..0a51dca
--- /dev/null
+++ b/LayoutTests/css-dark-mode/supported-color-schemes-expected.txt
@@ -0,0 +1,23 @@
+
+PASS Element colors are correct in light color scheme with only light supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to light and dark 
+PASS Element colors are correct in light color scheme with light and dark supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with light and dark supported color scheme 
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to dark 
+PASS Element colors are correct in light color scheme with only dark supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with only dark supported color scheme 
+PASS Supported color schemes changed to light and a bogus value 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Supported color schemes changed to empty value 
+PASS Element colors are correct in dark color scheme with implicit light supported color scheme 
+PASS Supported color schemes changed to light and dark 
+PASS Element colors are correct in dark color scheme with light and dark supported color scheme 
+PASS Supported color schemes changed to a bogus value and dark 
+PASS Element colors are correct in dark color scheme with dark supported color scheme 
+
diff --git a/LayoutTests/css-dark-mode/supported-color-schemes.html b/LayoutTests/css-dark-mode/supported-color-schemes.html
new file mode 100644
index 0000000..0127a31
--- /dev/null
+++ b/LayoutTests/css-dark-mode/supported-color-schemes.html
@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+
+<!-- webkit-test-runner [ experimental:DarkModeCSSEnabled=true ] -->
+
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+
+<style>
+#test1 {
+    color: text;
+}
+</style>
+
+<meta id="meta" name="supported-color-schemes" content="light">
+
+<div id="test1"></div>
+
+<script>
+function test_prop(id, prop, expected) {
+    assert_equals(window.getComputedStyle(document.getElementById(id)).getPropertyValue(prop).trim(), expected);
+}
+
+function test_color_is_white(id) {
+    test_prop("test1", "color", "rgb(255, 255, 255)");
+}
+
+function test_color_is_black(id) {
+    test_prop("test1", "color", "rgb(0, 0, 0)");
+}
+
+test(function() {
+    // The semantic text color should be black.
+    test_color_is_black("test1");
+}, "Element colors are correct in light color scheme with only light supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(true);
+}, "Dark color scheme enabled");
+
+test(function() {
+    // The semantic text color should be black, and not change.
+    test_color_is_black("test1");
+}, "Element colors are correct in dark color scheme with only light supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(false);
+}, "Light color scheme enabled");
+
+test(function() {
+    document.getElementById("meta").content = "light dark";
+}, "Supported color schemes changed to light and dark");
+
+test(function() {
+    // The semantic text color should be black.
+    test_color_is_black("test1");
+}, "Element colors are correct in light color scheme with light and dark supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(true);
+}, "Dark color scheme enabled");
+
+test(function() {
+    // The semantic text color should be white.
+    test_color_is_white("test1");
+}, "Element colors are correct in dark color scheme with light and dark supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(false);
+}, "Light color scheme enabled");
+
+test(function() {
+    document.getElementById("meta").content = "dark";
+}, "Supported color schemes changed to dark");
+
+test(function() {
+    // The semantic text color should be white.
+    test_color_is_white("test1");
+}, "Element colors are correct in light color scheme with only dark supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(true);
+}, "Dark color scheme enabled");
+
+test(function() {
+    // The semantic text color should be white still.
+    test_color_is_white("test1");
+}, "Element colors are correct in dark color scheme with only dark supported color scheme");
+
+test(function() {
+    document.getElementById("meta").content = "light ,foo ";
+}, "Supported color schemes changed to light and a bogus value");
+
+test(function() {
+    // The semantic text color should be black again.
+    test_color_is_black("test1");
+}, "Element colors are correct in dark color scheme with only light supported color scheme");
+
+test(function() {
+    document.getElementById("meta").content = "";
+}, "Supported color schemes changed to empty value");
+
+test(function() {
+    // The semantic text color should be black still.
+    test_color_is_black("test1");
+}, "Element colors are correct in dark color scheme with implicit light supported color scheme");
+
+test(function() {
+    document.getElementById("meta").content = "   light, dark ";
+}, "Supported color schemes changed to light and dark");
+
+test(function() {
+    // The semantic text color should be white now.
+    test_color_is_white("test1");
+}, "Element colors are correct in dark color scheme with light and dark supported color scheme");
+
+test(function() {
+    document.getElementById("meta").content = ", foo dark";
+}, "Supported color schemes changed to a bogus value and dark");
+
+test(function() {
+    // The semantic text color should be white still.
+    test_color_is_white("test1");
+}, "Element colors are correct in dark color scheme with dark supported color scheme");
+</script>
diff --git a/LayoutTests/platform/mac-highsierra/css-dark-mode/supported-color-schemes-expected.txt b/LayoutTests/platform/mac-highsierra/css-dark-mode/supported-color-schemes-expected.txt
new file mode 100644
index 0000000..96f9086
--- /dev/null
+++ b/LayoutTests/platform/mac-highsierra/css-dark-mode/supported-color-schemes-expected.txt
@@ -0,0 +1,23 @@
+
+PASS Element colors are correct in light color scheme with only light supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to light and dark 
+PASS Element colors are correct in light color scheme with light and dark supported color scheme 
+PASS Dark color scheme enabled 
+FAIL Element colors are correct in dark color scheme with light and dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to dark 
+FAIL Element colors are correct in light color scheme with only dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Dark color scheme enabled 
+FAIL Element colors are correct in dark color scheme with only dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Supported color schemes changed to light and a bogus value 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Supported color schemes changed to empty value 
+PASS Element colors are correct in dark color scheme with implicit light supported color scheme 
+PASS Supported color schemes changed to light and dark 
+FAIL Element colors are correct in dark color scheme with light and dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Supported color schemes changed to a bogus value and dark 
+FAIL Element colors are correct in dark color scheme with dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+
diff --git a/LayoutTests/platform/mac-sierra/css-dark-mode/supported-color-schemes-expected.txt b/LayoutTests/platform/mac-sierra/css-dark-mode/supported-color-schemes-expected.txt
new file mode 100644
index 0000000..96f9086
--- /dev/null
+++ b/LayoutTests/platform/mac-sierra/css-dark-mode/supported-color-schemes-expected.txt
@@ -0,0 +1,23 @@
+
+PASS Element colors are correct in light color scheme with only light supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to light and dark 
+PASS Element colors are correct in light color scheme with light and dark supported color scheme 
+PASS Dark color scheme enabled 
+FAIL Element colors are correct in dark color scheme with light and dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Light color scheme enabled 
+PASS Supported color schemes changed to dark 
+FAIL Element colors are correct in light color scheme with only dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Dark color scheme enabled 
+FAIL Element colors are correct in dark color scheme with only dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Supported color schemes changed to light and a bogus value 
+PASS Element colors are correct in dark color scheme with only light supported color scheme 
+PASS Supported color schemes changed to empty value 
+PASS Element colors are correct in dark color scheme with implicit light supported color scheme 
+PASS Supported color schemes changed to light and dark 
+FAIL Element colors are correct in dark color scheme with light and dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+PASS Supported color schemes changed to a bogus value and dark 
+FAIL Element colors are correct in dark color scheme with dark supported color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index e3d1359..43dfff0 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,63 @@
+2018-10-16  Timothy Hatcher  <timothy@apple.com>
+
+        Add <meta name="supported-color-schemes"> to control what color schemes the page supports
+        https://bugs.webkit.org/show_bug.cgi?id=190526
+        rdar://problem/45230140
+
+        Reviewed by Dean Jackson.
+
+        Test: css-dark-mode/supported-color-schemes.html
+
+        * dom/Document.cpp:
+        (WebCore::isColorSchemeSeparator): Added.
+        (WebCore::processColorSchemes): Added.
+        (WebCore::Document::processSupportedColorSchemes): Added.
+        (WebCore::Document::useDarkAppearance const): Take system appearance and document's
+        suppoerted color shcemes into account.
+        * dom/Document.h:
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::createFragment): Update use of LocalDefaultSystemAppearance.
+        * html/HTMLMetaElement.cpp:
+        (WebCore::HTMLMetaElement::process): Added supported-color-schemes behind runtime feature check.
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::InspectorOverlay::paint): Update use of LocalDefaultSystemAppearance.
+        * platform/mac/DragImageMac.mm:
+        (WebCore::createDragImageForLink): Update use of LocalDefaultSystemAppearance.
+        * platform/mac/LocalDefaultSystemAppearance.h:
+        * platform/mac/LocalDefaultSystemAppearance.mm:
+        (WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance):
+        Drop the need for useSystemAppearance. This is accounted for in Document::useDarkAppearance.
+        * platform/mac/ThemeMac.mm:
+        (WebCore::ThemeMac::paint): Update use of LocalDefaultSystemAppearance.
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::paintContents): Update use of LocalDefaultSystemAppearance.
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::paintContents): Update use of LocalDefaultSystemAppearance.
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::paint): Use document instead of page.
+        * rendering/RenderThemeCocoa.mm:
+        (WebCore::RenderThemeCocoa::drawLineForDocumentMarker): Update use of LocalDefaultSystemAppearance.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::documentViewFor const): Update use of LocalDefaultSystemAppearance.
+        (WebCore::RenderThemeMac::platformActiveSelectionBackgroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformInactiveSelectionBackgroundColor const): Ditto.
+        (WebCore::RenderThemeMac::transformSelectionBackgroundColor const): Ditto.
+        (WebCore::RenderThemeMac::supportsSelectionForegroundColors const): Ditto.
+        (WebCore::RenderThemeMac::platformActiveSelectionForegroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformInactiveSelectionForegroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformActiveListBoxSelectionBackgroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformInactiveListBoxSelectionBackgroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformActiveListBoxSelectionForegroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformInactiveListBoxSelectionForegroundColor const): Ditto.
+        (WebCore::RenderThemeMac::platformActiveTextSearchHighlightColor const): Ditto.
+        (WebCore::RenderThemeMac::colorCache const): Ditto.
+        (WebCore::RenderThemeMac::systemColor const): Ditto.
+        (WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary): Ditto.
+        (WebCore::RenderThemeMac::paintSliderThumb): Ditto.
+        (WebCore::RenderThemeMac::usingDarkAppearance const): No need to limit to macOS here.
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::draw): Update use of LocalDefaultSystemAppearance.
+
 2018-10-16  Rob Buis  <rbuis@igalia.com>
 
         Remove superfluous VIDEO build guard
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 4ec008e..582c3942 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -3556,6 +3556,54 @@
     }
 }
 
+#if ENABLE(DARK_MODE_CSS)
+static bool isColorSchemeSeparator(UChar character)
+{
+    return isASCIISpace(character) || character == ',';
+}
+
+static void processColorSchemes(StringView colorSchemes, const WTF::Function<void(StringView key)>& callback)
+{
+    unsigned length = colorSchemes.length();
+    for (unsigned i = 0; i < length; ) {
+        // Skip to first non-separator.
+        while (i < length && isColorSchemeSeparator(colorSchemes[i]))
+            ++i;
+        unsigned keyBegin = i;
+
+        // Skip to first separator.
+        while (i < length && !isColorSchemeSeparator(colorSchemes[i]))
+            ++i;
+        unsigned keyEnd = i;
+
+        if (keyBegin == keyEnd)
+            continue;
+
+        callback(colorSchemes.substring(keyBegin, keyEnd - keyBegin));
+    }
+}
+
+void Document::processSupportedColorSchemes(const String& colorSchemes)
+{
+    OptionSet<ColorSchemes> supportedColorSchemes;
+
+    processColorSchemes(colorSchemes, [&supportedColorSchemes](StringView key) {
+        if (equalLettersIgnoringASCIICase(key, "light"))
+            supportedColorSchemes.add(ColorSchemes::Light);
+        else if (equalLettersIgnoringASCIICase(key, "dark"))
+            supportedColorSchemes.add(ColorSchemes::Dark);
+    });
+
+    if (supportedColorSchemes.isEmpty())
+        supportedColorSchemes.add(ColorSchemes::Light);
+
+    m_supportedColorSchemes = supportedColorSchemes;
+
+    if (auto* page = this->page())
+        page->updateStyleAfterChangeInEnvironment();
+}
+#endif
+
 #if PLATFORM(IOS)
 
 void Document::processFormatDetection(const String& features)
@@ -7211,10 +7259,26 @@
 
 bool Document::useDarkAppearance() const
 {
-    bool useDarkAppearance = false;
+#if ENABLE(DARK_MODE_CSS)
+    if (m_supportedColorSchemes.contains(ColorSchemes::Dark) && !m_supportedColorSchemes.contains(ColorSchemes::Light))
+        return true;
+#endif
+
+    bool pageUsesDarkAppearance = false;
     if (Page* documentPage = page())
-        useDarkAppearance = documentPage->useDarkAppearance();
-    return useDarkAppearance;
+        pageUsesDarkAppearance = documentPage->useDarkAppearance();
+
+    if (useSystemAppearance())
+        return pageUsesDarkAppearance;
+
+#if ENABLE(DARK_MODE_CSS)
+    if (m_supportedColorSchemes.contains(ColorSchemes::Dark))
+        return pageUsesDarkAppearance;
+
+    ASSERT(m_supportedColorSchemes.contains(ColorSchemes::Light));
+#endif
+
+    return false;
 }
 
 OptionSet<StyleColor::Options> Document::styleColorOptions() const
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index cc0ade8..5e44874 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -572,8 +572,8 @@
 
     float deviceScaleFactor() const;
 
-    bool useSystemAppearance() const;
-    bool useDarkAppearance() const;
+    WEBCORE_EXPORT bool useSystemAppearance() const;
+    WEBCORE_EXPORT bool useDarkAppearance() const;
 
     OptionSet<StyleColor::Options> styleColorOptions() const;
 
@@ -895,6 +895,15 @@
     void updateViewportArguments();
     void processReferrerPolicy(const String& policy, ReferrerPolicySource);
 
+#if ENABLE(DARK_MODE_CSS)
+    enum class ColorSchemes : uint8_t {
+        Light = 1 << 0,
+        Dark = 1 << 1
+    };
+
+    void processSupportedColorSchemes(const String& colorSchemes);
+#endif
+
     // Returns the owning element in the parent document.
     // Returns 0 if this is the top level document.
     HTMLFrameOwnerElement* ownerElement() const;
@@ -1751,6 +1760,10 @@
     std::unique_ptr<SVGDocumentExtensions> m_svgExtensions;
     HashSet<SVGUseElement*> m_svgUseElements;
 
+#if ENABLE(DARK_MODE_CSS)
+    OptionSet<ColorSchemes> m_supportedColorSchemes { ColorSchemes::Light };
+#endif
+
 #if ENABLE(DASHBOARD_SUPPORT)
     Vector<AnnotatedRegionValue> m_annotatedRegions;
     bool m_hasAnnotatedRegions { false };
diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
index c5a88f3..1c80793 100644
--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
@@ -132,8 +132,7 @@
     Document& document = *frame.document();
 
 #if PLATFORM(MAC)
-    auto* page = frame.page();
-    LocalDefaultSystemAppearance localAppearance(page->useSystemAppearance(), page->useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(document.useDarkAppearance());
 #endif
 
     NSArray *subresources = nil;
diff --git a/Source/WebCore/html/HTMLMetaElement.cpp b/Source/WebCore/html/HTMLMetaElement.cpp
index 0acebca..79bc87d 100644
--- a/Source/WebCore/html/HTMLMetaElement.cpp
+++ b/Source/WebCore/html/HTMLMetaElement.cpp
@@ -91,6 +91,10 @@
         document().processViewport(contentValue, ViewportArguments::ViewportMeta);
     else if (RuntimeEnabledFeatures::sharedFeatures().disabledAdaptationsMetaTagEnabled() && equalLettersIgnoringASCIICase(name(), "disabled-adaptations"))
         document().processDisabledAdaptations(contentValue);
+#if ENABLE(DARK_MODE_CSS)
+    else if (RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled() && equalLettersIgnoringASCIICase(name(), "supported-color-schemes"))
+        document().processSupportedColorSchemes(contentValue);
+#endif
 #if PLATFORM(IOS)
     else if (equalLettersIgnoringASCIICase(name(), "format-detection"))
         document().processFormatDetection(contentValue);
diff --git a/Source/WebCore/inspector/InspectorOverlay.cpp b/Source/WebCore/inspector/InspectorOverlay.cpp
index 1725e93..d5def90 100644
--- a/Source/WebCore/inspector/InspectorOverlay.cpp
+++ b/Source/WebCore/inspector/InspectorOverlay.cpp
@@ -181,7 +181,7 @@
         return;
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(m_page.useSystemAppearance(), m_page.useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(m_page.mainFrame().document()->useDarkAppearance());
 #endif
 
     GraphicsContextStateSaver stateSaver(context);
diff --git a/Source/WebCore/platform/mac/DragImageMac.mm b/Source/WebCore/platform/mac/DragImageMac.mm
index 201cb33..11cda24 100644
--- a/Source/WebCore/platform/mac/DragImageMac.mm
+++ b/Source/WebCore/platform/mac/DragImageMac.mm
@@ -300,9 +300,7 @@
 {
     LinkImageLayout layout(url, title);
 
-    Page* page = element.document().page();
-
-    LocalDefaultSystemAppearance localAppearance(true, page ? page->useDarkAppearance() : false);
+    LocalDefaultSystemAppearance localAppearance(element.document().useDarkAppearance());
 
     auto imageSize = layout.boundingRect.size();
 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
diff --git a/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h b/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h
index ef65be0..1cb1b2b 100644
--- a/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h
+++ b/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h
@@ -40,7 +40,7 @@
     WTF_MAKE_NONCOPYABLE(LocalDefaultSystemAppearance);
 
 public:
-    WEBCORE_EXPORT LocalDefaultSystemAppearance(bool useSystemAppearance, bool useDarkAppearance);
+    WEBCORE_EXPORT LocalDefaultSystemAppearance(bool useDarkAppearance);
     WEBCORE_EXPORT ~LocalDefaultSystemAppearance();
 
     bool usingDarkAppearance() const
diff --git a/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm b/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm
index 1d5f7e1..6b6821e 100644
--- a/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm
+++ b/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm
@@ -31,15 +31,14 @@
 
 namespace WebCore {
 
-LocalDefaultSystemAppearance::LocalDefaultSystemAppearance(bool useSystemAppearance, bool useDarkAppearance)
+LocalDefaultSystemAppearance::LocalDefaultSystemAppearance(bool useDarkAppearance)
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     m_savedSystemAppearance = [NSAppearance currentAppearance];
-    m_usingDarkAppearance = useSystemAppearance && useDarkAppearance;
+    m_usingDarkAppearance = useDarkAppearance;
 
     [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:m_usingDarkAppearance ? NSAppearanceNameDarkAqua : NSAppearanceNameAqua]];
 #else
-    UNUSED_PARAM(useSystemAppearance);
     UNUSED_PARAM(useDarkAppearance);
 #endif
 }
diff --git a/Source/WebCore/platform/mac/ThemeMac.mm b/Source/WebCore/platform/mac/ThemeMac.mm
index 3473426..955d693 100644
--- a/Source/WebCore/platform/mac/ThemeMac.mm
+++ b/Source/WebCore/platform/mac/ThemeMac.mm
@@ -907,7 +907,9 @@
 
 void ThemeMac::paint(ControlPart part, ControlStates& states, GraphicsContext& context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor, bool useSystemAppearance, bool useDarkAppearance)
 {
-    LocalDefaultSystemAppearance localAppearance(useSystemAppearance, useDarkAppearance);
+    UNUSED_PARAM(useSystemAppearance);
+
+    LocalDefaultSystemAppearance localAppearance(useDarkAppearance);
 
     switch (part) {
         case CheckboxPart:
diff --git a/Source/WebCore/rendering/RenderLayerBacking.cpp b/Source/WebCore/rendering/RenderLayerBacking.cpp
index e12c869..148020b 100644
--- a/Source/WebCore/rendering/RenderLayerBacking.cpp
+++ b/Source/WebCore/rendering/RenderLayerBacking.cpp
@@ -2541,7 +2541,7 @@
 #endif
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(renderer().page().useSystemAppearance(), renderer().page().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(renderer().document().useDarkAppearance());
 #endif
 
     // The dirtyRect is in the coords of the painting root.
diff --git a/Source/WebCore/rendering/RenderLayerCompositor.cpp b/Source/WebCore/rendering/RenderLayerCompositor.cpp
index b0cba54..1655337 100644
--- a/Source/WebCore/rendering/RenderLayerCompositor.cpp
+++ b/Source/WebCore/rendering/RenderLayerCompositor.cpp
@@ -2782,7 +2782,7 @@
 void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& clip, GraphicsLayerPaintBehavior)
 {
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(page().useSystemAppearance(), page().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(m_renderView.document().useDarkAppearance());
 #endif
 
     IntRect pixelSnappedRectForIntegralPositionedItems = snappedIntRect(LayoutRect(clip));
diff --git a/Source/WebCore/rendering/RenderTheme.cpp b/Source/WebCore/rendering/RenderTheme.cpp
index 34f3a1e..a487a3c 100644
--- a/Source/WebCore/rendering/RenderTheme.cpp
+++ b/Source/WebCore/rendering/RenderTheme.cpp
@@ -317,7 +317,7 @@
     case ButtonPart:
     case InnerSpinButtonPart:
         updateControlStatesForRenderer(box, controlStates);
-        Theme::singleton().paint(part, controlStates, paintInfo.context(), devicePixelSnappedRect, box.style().effectiveZoom(), &box.view().frameView(), deviceScaleFactor, pageScaleFactor, box.page().useSystemAppearance(), box.page().useDarkAppearance());
+        Theme::singleton().paint(part, controlStates, paintInfo.context(), devicePixelSnappedRect, box.style().effectiveZoom(), &box.view().frameView(), deviceScaleFactor, pageScaleFactor, box.document().useSystemAppearance(), box.document().useDarkAppearance());
         return false;
     default:
         break;
diff --git a/Source/WebCore/rendering/RenderThemeCocoa.mm b/Source/WebCore/rendering/RenderThemeCocoa.mm
index 1f88aed..835a695 100644
--- a/Source/WebCore/rendering/RenderThemeCocoa.mm
+++ b/Source/WebCore/rendering/RenderThemeCocoa.mm
@@ -56,7 +56,7 @@
     if (context.paintingDisabled())
         return;
 
-    auto circleColor = colorForMarkerLineStyle(style, renderer.page().useSystemAppearance() && renderer.page().useDarkAppearance());
+    auto circleColor = colorForMarkerLineStyle(style, renderer.document().useDarkAppearance());
 
     // Center the underline and ensure we only draw entire dots.
     FloatPoint offsetPoint = origin;
diff --git a/Source/WebCore/rendering/RenderThemeMac.mm b/Source/WebCore/rendering/RenderThemeMac.mm
index 91cd6de..6b8dbcd 100644
--- a/Source/WebCore/rendering/RenderThemeMac.mm
+++ b/Source/WebCore/rendering/RenderThemeMac.mm
@@ -297,7 +297,7 @@
 
 NSView *RenderThemeMac::documentViewFor(const RenderObject& o) const
 {
-    LocalDefaultSystemAppearance localAppearance(o.page().useSystemAppearance(), o.page().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(o));
     ControlStates states(extractControlStatesForRenderer(o));
     return ThemeMac::ensuredView(&o.view().frameView(), states);
 }
@@ -392,14 +392,14 @@
 
 Color RenderThemeMac::platformActiveSelectionBackgroundColor(OptionSet<StyleColor::Options> options) const
 {
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor selectedTextBackgroundColor]);
 }
 
 Color RenderThemeMac::platformInactiveSelectionBackgroundColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor unemphasizedSelectedTextBackgroundColor]);
 #else
     UNUSED_PARAM(options);
@@ -409,7 +409,7 @@
 
 Color RenderThemeMac::transformSelectionBackgroundColor(const Color& color, OptionSet<StyleColor::Options> options) const
 {
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     if (localAppearance.usingDarkAppearance()) {
         // Use an alpha value that is similar to results from blendWithWhite() on light colors.
         static const float darkAppearanceAlpha = 0.8;
@@ -421,13 +421,13 @@
 
 bool RenderThemeMac::supportsSelectionForegroundColors(OptionSet<StyleColor::Options> options) const
 {
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return localAppearance.usingDarkAppearance();
 }
 
 Color RenderThemeMac::platformActiveSelectionForegroundColor(OptionSet<StyleColor::Options> options) const
 {
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     if (localAppearance.usingDarkAppearance())
         return colorFromNSColor([NSColor selectedTextColor]);
     return { };
@@ -436,7 +436,7 @@
 Color RenderThemeMac::platformInactiveSelectionForegroundColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     if (localAppearance.usingDarkAppearance())
         return colorFromNSColor([NSColor unemphasizedSelectedTextColor]);
     return { };
@@ -449,7 +449,7 @@
 Color RenderThemeMac::platformActiveListBoxSelectionBackgroundColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor selectedContentBackgroundColor]);
 #else
     UNUSED_PARAM(options);
@@ -460,7 +460,7 @@
 Color RenderThemeMac::platformInactiveListBoxSelectionBackgroundColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor unemphasizedSelectedContentBackgroundColor]);
 #else
     UNUSED_PARAM(options);
@@ -470,14 +470,14 @@
 
 Color RenderThemeMac::platformActiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options> options) const
 {
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor alternateSelectedControlTextColor]);
 }
 
 Color RenderThemeMac::platformInactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor unemphasizedSelectedTextColor]);
 #else
     UNUSED_PARAM(options);
@@ -495,7 +495,7 @@
 Color RenderThemeMac::platformActiveTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
-    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     return colorFromNSColor([NSColor findHighlightColor]);
 #else
     UNUSED_PARAM(options);
@@ -612,9 +612,7 @@
 
 auto RenderThemeMac::colorCache(OptionSet<StyleColor::Options> options) const -> ColorCache&
 {
-    const bool useSystemAppearance = options.contains(StyleColor::Options::UseSystemAppearance);
-    const bool useDarkAppearance = options.contains(StyleColor::Options::UseDarkAppearance);
-    LocalDefaultSystemAppearance localAppearance(useSystemAppearance, useDarkAppearance);
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseDarkAppearance));
     if (localAppearance.usingDarkAppearance())
         return m_darkColorCache;
     return RenderTheme::colorCache(options);
@@ -626,7 +624,7 @@
     const bool useDarkAppearance = options.contains(StyleColor::Options::UseDarkAppearance);
     const bool forVisitedLink = options.contains(StyleColor::Options::ForVisitedLink);
 
-    LocalDefaultSystemAppearance localAppearance(useSystemAppearance, useDarkAppearance);
+    LocalDefaultSystemAppearance localAppearance(useDarkAppearance);
 
     auto& cache = colorCache(options);
 
@@ -1802,7 +1800,7 @@
 
 void RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary(NSCell* cell, const RenderObject& renderer, const PaintInfo& paintInfo, const FloatRect& rect)
 {
-    LocalDefaultSystemAppearance localAppearance(renderer.page().useSystemAppearance(), renderer.page().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(renderer));
     bool shouldDrawFocusRing = isFocused(renderer) && renderer.style().outlineStyleIsAuto() == OutlineIsAuto::On;
     bool shouldUseImageBuffer = renderer.style().effectiveZoom() != 1 || renderer.page().pageScaleFactor() != 1;
     bool shouldDrawCell = true;
@@ -1884,7 +1882,7 @@
         ? sliderThumbVertical()
         : sliderThumbHorizontal();
 
-    LocalDefaultSystemAppearance localAppearance(o.page().useSystemAppearance(), o.page().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(o));
 
     LocalCurrentGraphicsContext localContext(paintInfo.context());
 
@@ -2997,12 +2995,7 @@
 
 bool RenderThemeMac::usingDarkAppearance(const RenderObject& o) const
 {
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-    return o.page().useSystemAppearance() && o.page().useDarkAppearance();
-#else
-    UNUSED_PARAM(o);
-    return false;
-#endif
+    return o.document().useDarkAppearance();
 }
 
 CGColorRef RenderThemeMac::colorForMarkerLineStyle(DocumentMarkerLineStyle style, bool useDarkMode)
diff --git a/Source/WebCore/svg/graphics/SVGImage.cpp b/Source/WebCore/svg/graphics/SVGImage.cpp
index 088c10b..91ef851 100644
--- a/Source/WebCore/svg/graphics/SVGImage.cpp
+++ b/Source/WebCore/svg/graphics/SVGImage.cpp
@@ -324,7 +324,8 @@
     }
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(m_page->useSystemAppearance(), m_page->useDarkAppearance());
+    auto* document = m_page->mainFrame().document();
+    LocalDefaultSystemAppearance localAppearance(document ? document->useDarkAppearance() : false);
 #endif
 
     view->paint(context, intersection(context.clipBounds(), enclosingIntRect(srcRect)));
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 05a037c..9972177 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,20 @@
+2018-10-16  Timothy Hatcher  <timothy@apple.com>
+
+        Add <meta name="supported-color-schemes"> to control what color schemes the page supports
+        https://bugs.webkit.org/show_bug.cgi?id=190526
+        rdar://problem/45230140
+
+        Reviewed by Dean Jackson.
+
+        * UIProcess/mac/WKPrintingView.mm:
+        (-[WKPrintingView drawRect:]): Update use of LocalDefaultSystemAppearance.
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
+        (WebKit::InjectedBundleRangeHandle::renderedImage): Ditto.
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::paintControlForLayerInContext): Ditto.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::drawRect): Ditto.
+
 2018-10-16  Justin Michaud  <justin_michaud@apple.com>
 
         Implement feature flag and bindings for CSS Painting API
diff --git a/Source/WebKit/UIProcess/mac/WKPrintingView.mm b/Source/WebKit/UIProcess/mac/WKPrintingView.mm
index d206ffe..aa53743 100644
--- a/Source/WebKit/UIProcess/mac/WKPrintingView.mm
+++ b/Source/WebKit/UIProcess/mac/WKPrintingView.mm
@@ -556,11 +556,8 @@
 
     ASSERT(_printOperation == [NSPrintOperation currentOperation]);
 
-    auto* page = _webFrame->page();
-    if (!page)
-        return;
-
-    WebCore::LocalDefaultSystemAppearance localAppearance(page->useSystemAppearance(), page->useDarkAppearance());
+    // Always use the light appearance when printing.
+    WebCore::LocalDefaultSystemAppearance localAppearance(false);
 
     if ([self _isPrintingPreview]) {
         [self _drawPreview:nsRect];
diff --git a/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp b/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
index 6a80186..3f4f567 100644
--- a/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
+++ b/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
@@ -124,7 +124,7 @@
         return nullptr;
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(frame->page()->useSystemAppearance(), frame->page()->useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(ownerDocument.useDarkAppearance());
 #endif
 
     Ref<Frame> protector(*frame);
diff --git a/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm b/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
index 49b2225..d20760e 100644
--- a/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
+++ b/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
@@ -1219,7 +1219,7 @@
 {
 #if PLATFORM(MAC)
     auto* page = webFrame()->coreFrame()->page();
-    LocalDefaultSystemAppearance localAppearance(page->useSystemAppearance(), page->useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(page->useDarkAppearance());
 #endif
 
     GraphicsContext graphicsContext(context);
diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp
index e1f6727..321acbb 100644
--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp
+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp
@@ -1541,7 +1541,8 @@
 void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect)
 {
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(m_page->useSystemAppearance(), m_page->useDarkAppearance());
+    auto* document = m_mainFrame->coreFrame()->document();
+    LocalDefaultSystemAppearance localAppearance(document ? document->useDarkAppearance() : false);
 #endif
 
     GraphicsContextStateSaver stateSaver(graphicsContext);
diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog
index b05e12d..b1b1adb 100644
--- a/Source/WebKitLegacy/mac/ChangeLog
+++ b/Source/WebKitLegacy/mac/ChangeLog
@@ -1,3 +1,14 @@
+2018-10-16  Timothy Hatcher  <timothy@apple.com>
+
+        Add <meta name="supported-color-schemes"> to control what color schemes the page supports
+        https://bugs.webkit.org/show_bug.cgi?id=190526
+        rdar://problem/45230140
+
+        Reviewed by Dean Jackson.
+
+        * WebCoreSupport/WebEditorClient.mm:
+        (_WebCreateFragment): Update use of LocalDefaultSystemAppearance.
+
 2018-10-16  Justin Michaud  <justin_michaud@apple.com>
 
         Implement feature flag and bindings for CSS Painting API
diff --git a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
index 3180429..0c073a6 100644
--- a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
+++ b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
@@ -478,8 +478,7 @@
 void _WebCreateFragment(Document& document, NSAttributedString *string, FragmentAndResources& result)
 {
 #if PLATFORM(MAC)
-    auto* page = document.page();
-    LocalDefaultSystemAppearance localAppearance(page->useSystemAppearance(), page->useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(document.useDarkAppearance());
 #endif
 
     static NSDictionary *documentAttributes = [attributesForAttributedStringConversion() retain];