Add experimental support for a `supported-color-schemes` CSS property.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 21:57:40 +0000 (21:57 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 21:57:40 +0000 (21:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191319
rdar://problem/45852261

Reviewed by Dean Jackson.

Source/WebCore:

Tests: css-dark-mode/parse-supported-color-schemes.html
       css-dark-mode/supported-color-schemes-css.html

* WebCore.xcodeproj/project.pbxproj:
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::valueForPropertyinStyle):
* css/CSSProperties.json:
* css/CSSValueKeywords.in:
* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::updateSupportedColorSchemes):
(WebCore::StyleBuilderConverter::convertSupportedColorSchemes):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::colorFromPrimitiveValue const):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeSupportedColorSchemes):
(WebCore::CSSPropertyParser::parseSingleValue):
* dom/Document.cpp:
(WebCore::Document::resetLinkColor):
(WebCore::Document::resetVisitedLinkColor):
(WebCore::Document::resetActiveLinkColor):
(WebCore::Document::processSupportedColorSchemes):
(WebCore::Document::useDarkAppearance const):
(WebCore::Document::styleColorOptions const):
* dom/Document.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragment):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal):
* inspector/InspectorOverlay.cpp:
(WebCore::InspectorOverlay::paint):
* page/FrameView.cpp:
(WebCore::FrameView::useDarkAppearance const):
(WebCore::FrameView::paintScrollCorner):
* platform/mac/DragImageMac.mm:
(WebCore::createDragImageForLink):
* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::paintBoxDecorations):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paintPlatformDocumentMarker):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::paintRootBoxFillLayers):
(WebCore::RenderBox::paintBackground):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::selectionColor const):
(WebCore::RenderElement::selectionBackgroundColor const):
(WebCore::RenderElement::paintFocusRing):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::paintAreaElementFocusRing):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::paintContents):
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::paintContents):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::paintItemForeground):
(WebCore::RenderListBox::paintItemBackground):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::useDarkAppearance const):
(WebCore::RenderObject::styleColorOptions const):
* rendering/RenderObject.h:
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::paintBackgroundsBehindCell):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::paint):
* rendering/RenderTheme.h:
(WebCore::RenderTheme::usingDarkAppearance const): Deleted.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::documentViewFor const):
(WebCore::RenderThemeMac::adjustMenuListStyle const):
(WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary):
(WebCore::RenderThemeMac::paintSliderThumb):
(WebCore::RenderThemeMac::usingDarkAppearance const): Deleted.
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::supportedColorSchemes const):
(WebCore::RenderStyle::setSupportedColorSchemes):
(WebCore::RenderStyle::initialSupportedColorSchemes):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleRareInheritedData.cpp:
(WebCore::StyleRareInheritedData::StyleRareInheritedData):
(WebCore::StyleRareInheritedData::operator== const):
* rendering/style/StyleRareInheritedData.h:
* rendering/style/StyleSupportedColorSchemes.h: Added.
(WebCore::StyleSupportedColorSchemes::StyleSupportedColorSchemes):
(WebCore::StyleSupportedColorSchemes::operator== const):
(WebCore::StyleSupportedColorSchemes::operator!= const):
(WebCore::StyleSupportedColorSchemes::isAuto const):
(WebCore::StyleSupportedColorSchemes::isOnly const):
(WebCore::StyleSupportedColorSchemes::colorSchemes const):
(WebCore::StyleSupportedColorSchemes::add):
(WebCore::StyleSupportedColorSchemes::contains const):
(WebCore::StyleSupportedColorSchemes::setAllowsTransformations):
(WebCore::StyleSupportedColorSchemes::allowsTransformations const):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::draw):

Source/WebKit:

* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::renderedImage):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::drawRect):

LayoutTests:

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

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

45 files changed:
LayoutTests/ChangeLog
LayoutTests/css-dark-mode/parse-supported-color-schemes-expected.txt [new file with mode: 0644]
LayoutTests/css-dark-mode/parse-supported-color-schemes.html [new file with mode: 0644]
LayoutTests/css-dark-mode/supported-color-schemes-css-expected.txt [new file with mode: 0644]
LayoutTests/css-dark-mode/supported-color-schemes-css.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/StyleBuilderConverter.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/mac/DragImageMac.mm
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderListBox.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderTableCell.cpp
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/RenderStyleConstants.h
Source/WebCore/rendering/style/StyleRareInheritedData.cpp
Source/WebCore/rendering/style/StyleRareInheritedData.h
Source/WebCore/rendering/style/StyleSupportedColorSchemes.h [new file with mode: 0644]
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm

index 1951feb..9bce4bf 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-08  Timothy Hatcher  <timothy@apple.com>
+
+        Add experimental support for a `supported-color-schemes` CSS property.
+        https://bugs.webkit.org/show_bug.cgi?id=191319
+        rdar://problem/45852261
+
+        Reviewed by Dean Jackson.
+
+        * css-dark-mode/parse-supported-color-schemes-expected.txt: Added.
+        * css-dark-mode/parse-supported-color-schemes.html: Added.
+        * css-dark-mode/supported-color-schemes-css-expected.txt: Added.
+        * css-dark-mode/supported-color-schemes-css.html: Added.
+
 2018-11-08  Per Arne Vollan  <pvollan@apple.com>
 
         [Sierra Release WK2] Layout Test media/track/track-cue-css.html is a flaky failure
diff --git a/LayoutTests/css-dark-mode/parse-supported-color-schemes-expected.txt b/LayoutTests/css-dark-mode/parse-supported-color-schemes-expected.txt
new file mode 100644 (file)
index 0000000..2a287f5
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS Test valid values 
+PASS Test invalid values 
+
diff --git a/LayoutTests/css-dark-mode/parse-supported-color-schemes.html b/LayoutTests/css-dark-mode/parse-supported-color-schemes.html
new file mode 100644 (file)
index 0000000..1bc10a8
--- /dev/null
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+
+<!-- webkit-test-runner [ experimental:DarkModeCSSEnabled=true ] -->
+
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+
+<style>
+#testAuto {
+    supported-color-schemes: auto;
+}
+
+#testOnly {
+    supported-color-schemes: only;
+}
+
+#testLight {
+    supported-color-schemes: light;
+}
+
+#testDark {
+    supported-color-schemes: dark;
+}
+
+#testLightDark {
+    supported-color-schemes: light dark;
+}
+
+#testDarkLight {
+    supported-color-schemes: dark light;
+}
+
+#testLightDarkOnly {
+    supported-color-schemes: light dark only;
+}
+
+#testOnlyDark {
+    supported-color-schemes: only dark;
+}
+
+#testLightOnlyDark {
+    supported-color-schemes: light only dark;
+}
+
+#testLightUnknown {
+    supported-color-schemes: light foo;
+}
+
+#testUnknownDarkOnly {
+    supported-color-schemes: bar dark only;
+}
+
+#testLightUnknownOnly {
+    supported-color-schemes: light baz only;
+}
+
+#testInvalidLightAuto {
+    supported-color-schemes: light auto;
+}
+
+#testInvalidAutoDark {
+    supported-color-schemes: auto dark;
+}
+
+#testInvalidLightDarkLight {
+    supported-color-schemes: light dark light;
+}
+
+#testInvalidNumber {
+    supported-color-schemes: 42;
+}
+
+#testInvalidString {
+    supported-color-schemes: "foo";
+}
+
+#testInvalidLightString {
+    supported-color-schemes: light "foo";
+}
+</style>
+
+<div id="testAuto"></div>
+<div id="testOnly"></div>
+<div id="testLight"></div>
+<div id="testDark"></div>
+<div id="testLightDark"></div>
+<div id="testDarkLight"></div>
+<div id="testLightDarkOnly"></div>
+<div id="testOnlyDark"></div>
+<div id="testLightOnlyDark"></div>
+<div id="testLightUnknown"></div>
+<div id="testUnknownDarkOnly"></div>
+
+<div id="testInvalidLightAuto"></div>
+<div id="testInvalidAutoDark"></div>
+<div id="testInvalidLightDarkLight"></div>
+<div id="testInvalidNumber"></div>
+<div id="testInvalidString"></div>
+<div id="testInvalidLightString"></div>
+
+<script>
+function test_prop(id, property, expected) {
+    assert_equals(window.getComputedStyle(document.getElementById(id)).getPropertyValue(property), expected);
+}
+
+test(function() {
+    test_prop("testAuto", "supported-color-schemes", "auto");
+    test_prop("testOnly", "supported-color-schemes", "light only");
+    test_prop("testLight", "supported-color-schemes", "light");
+    test_prop("testDark", "supported-color-schemes", "dark");
+    test_prop("testLightDark", "supported-color-schemes", "light dark");
+    test_prop("testDarkLight", "supported-color-schemes", "light dark");
+    test_prop("testLightDarkOnly", "supported-color-schemes", "light dark only");
+    test_prop("testOnlyDark", "supported-color-schemes", "dark only");
+    test_prop("testLightOnlyDark", "supported-color-schemes", "light dark only");
+    test_prop("testLightUnknown", "supported-color-schemes", "light");
+    test_prop("testUnknownDarkOnly", "supported-color-schemes", "dark only");
+}, "Test valid values");
+
+test(function() {
+    test_prop("testInvalidLightAuto", "supported-color-schemes", "auto");
+    test_prop("testInvalidAutoDark", "supported-color-schemes", "auto");
+    test_prop("testInvalidLightDarkLight", "supported-color-schemes", "auto");
+    test_prop("testInvalidNumber", "supported-color-schemes", "auto");
+    test_prop("testInvalidString", "supported-color-schemes", "auto");
+    test_prop("testInvalidLightString", "supported-color-schemes", "auto");
+}, "Test invalid values");
+</script>
diff --git a/LayoutTests/css-dark-mode/supported-color-schemes-css-expected.txt b/LayoutTests/css-dark-mode/supported-color-schemes-css-expected.txt
new file mode 100644 (file)
index 0000000..cddd56f
--- /dev/null
@@ -0,0 +1,28 @@
+
+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 auto 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 via <meta> element 
+PASS Element colors are correct in dark color scheme with light and dark supported color scheme via <meta> element 
+PASS Supported color schemes changed to light value 
+PASS Element colors are correct in dark color scheme with explicit light, overriding <meta> element 
+PASS Remove test meta element 
+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-css.html b/LayoutTests/css-dark-mode/supported-color-schemes-css.html
new file mode 100644 (file)
index 0000000..b6ca680
--- /dev/null
@@ -0,0 +1,153 @@
+<!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>
+
+<div id="test1"></div>
+
+<script>
+function test_prop(id, prop, expected) {
+    assert_equals(window.getComputedStyle(document.getElementById(id)).getPropertyValue(prop), 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.body.style.setProperty("supported-color-schemes", "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.body.style.setProperty("supported-color-schemes", "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.body.style.setProperty("supported-color-schemes", "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.body.style.setProperty("supported-color-schemes", "auto");
+}, "Supported color schemes changed to auto 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() {
+    let meta = document.createElement("meta");
+    meta.id = "test-meta";
+    meta.name = "supported-color-schemes";
+    meta.content = "light dark";
+    document.head.appendChild(meta);
+}, "Supported color schemes changed to light and dark via <meta> element");
+
+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 via <meta> element");
+
+test(function() {
+    document.body.style.setProperty("supported-color-schemes", "light");
+}, "Supported color schemes changed to light 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 explicit light, overriding <meta> element");
+
+test(function() {
+    document.getElementById("test-meta").remove();
+}, "Remove test meta element");
+
+test(function() {
+    document.body.style.setProperty("supported-color-schemes", "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.body.style.setProperty("supported-color-schemes", "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>
index d18c482..2cb15fe 100644 (file)
@@ -1,3 +1,106 @@
+2018-11-08  Timothy Hatcher  <timothy@apple.com>
+
+        Add experimental support for a `supported-color-schemes` CSS property.
+        https://bugs.webkit.org/show_bug.cgi?id=191319
+        rdar://problem/45852261
+
+        Reviewed by Dean Jackson.
+
+        Tests: css-dark-mode/parse-supported-color-schemes.html
+               css-dark-mode/supported-color-schemes-css.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::valueForPropertyinStyle):
+        * css/CSSProperties.json:
+        * css/CSSValueKeywords.in:
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::updateSupportedColorSchemes):
+        (WebCore::StyleBuilderConverter::convertSupportedColorSchemes):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::colorFromPrimitiveValue const):
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeSupportedColorSchemes):
+        (WebCore::CSSPropertyParser::parseSingleValue):
+        * dom/Document.cpp:
+        (WebCore::Document::resetLinkColor):
+        (WebCore::Document::resetVisitedLinkColor):
+        (WebCore::Document::resetActiveLinkColor):
+        (WebCore::Document::processSupportedColorSchemes):
+        (WebCore::Document::useDarkAppearance const):
+        (WebCore::Document::styleColorOptions const):
+        * dom/Document.h:
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::createFragment):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal):
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::InspectorOverlay::paint):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::useDarkAppearance const):
+        (WebCore::FrameView::paintScrollCorner):
+        * platform/mac/DragImageMac.mm:
+        (WebCore::createDragImageForLink):
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::paintBoxDecorations):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paintPlatformDocumentMarker):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::paintRootBoxFillLayers):
+        (WebCore::RenderBox::paintBackground):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::selectionColor const):
+        (WebCore::RenderElement::selectionBackgroundColor const):
+        (WebCore::RenderElement::paintFocusRing):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paintAreaElementFocusRing):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::paintContents):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::paintContents):
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::paintItemForeground):
+        (WebCore::RenderListBox::paintItemBackground):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::useDarkAppearance const):
+        (WebCore::RenderObject::styleColorOptions const):
+        * rendering/RenderObject.h:
+        * rendering/RenderTableCell.cpp:
+        (WebCore::RenderTableCell::paintBackgroundsBehindCell):
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::paint):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::usingDarkAppearance const): Deleted.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::documentViewFor const):
+        (WebCore::RenderThemeMac::adjustMenuListStyle const):
+        (WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary):
+        (WebCore::RenderThemeMac::paintSliderThumb):
+        (WebCore::RenderThemeMac::usingDarkAppearance const): Deleted.
+        * rendering/style/RenderStyle.h:
+        (WebCore::RenderStyle::supportedColorSchemes const):
+        (WebCore::RenderStyle::setSupportedColorSchemes):
+        (WebCore::RenderStyle::initialSupportedColorSchemes):
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleRareInheritedData.cpp:
+        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
+        (WebCore::StyleRareInheritedData::operator== const):
+        * rendering/style/StyleRareInheritedData.h:
+        * rendering/style/StyleSupportedColorSchemes.h: Added.
+        (WebCore::StyleSupportedColorSchemes::StyleSupportedColorSchemes):
+        (WebCore::StyleSupportedColorSchemes::operator== const):
+        (WebCore::StyleSupportedColorSchemes::operator!= const):
+        (WebCore::StyleSupportedColorSchemes::isAuto const):
+        (WebCore::StyleSupportedColorSchemes::isOnly const):
+        (WebCore::StyleSupportedColorSchemes::colorSchemes const):
+        (WebCore::StyleSupportedColorSchemes::add):
+        (WebCore::StyleSupportedColorSchemes::contains const):
+        (WebCore::StyleSupportedColorSchemes::setAllowsTransformations):
+        (WebCore::StyleSupportedColorSchemes::allowsTransformations const):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::draw):
+
 2018-11-08  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Restrict domains at the target level instead of only at the window level
index 3f9dabc..a62dd78 100644 (file)
                1C010701192594DF008A4201 /* InlineTextBoxStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */; };
                1C0939EB1A13E12900B788E5 /* CachedSVGFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0939E91A13E12900B788E5 /* CachedSVGFont.h */; };
                1C09D0591E31C6A900725F18 /* libPAL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C09D0501E31C32900725F18 /* libPAL.a */; };
+               1C0AA16D21940DC800896829 /* StyleSupportedColorSchemes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0AA16A21940DC700896829 /* StyleSupportedColorSchemes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C12AC2B1EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C18DA59181AF6A500C4EF22 /* TextPainter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C18DA57181AF6A500C4EF22 /* TextPainter.h */; };
                1C21E57D183ED1FF001C289D /* IOSurfacePool.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C21E57B183ED1FF001C289D /* IOSurfacePool.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedSVGFont.cpp; sourceTree = "<group>"; };
                1C0939E91A13E12900B788E5 /* CachedSVGFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedSVGFont.h; sourceTree = "<group>"; };
                1C09D04B1E31C32800725F18 /* PAL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PAL.xcodeproj; path = PAL/PAL.xcodeproj; sourceTree = "<group>"; };
+               1C0AA16A21940DC700896829 /* StyleSupportedColorSchemes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSupportedColorSchemes.h; sourceTree = "<group>"; };
                1C12AC281EE778AE0079E0A0 /* FontFamilySpecificationCoreText.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FontFamilySpecificationCoreText.cpp; sourceTree = "<group>"; };
                1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontFamilySpecificationCoreText.h; sourceTree = "<group>"; };
                1C12AC2C1EE779950079E0A0 /* FontDescriptionCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FontDescriptionCocoa.cpp; sourceTree = "<group>"; };
                                F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */,
                                F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */,
                                9D63800F1AF16E160031A15C /* StyleSelfAlignmentData.h */,
+                               1C0AA16A21940DC700896829 /* StyleSupportedColorSchemes.h */,
                                BC5EB5E60E81BFEF00B25965 /* StyleSurroundData.cpp */,
                                BC5EB5E40E81BF6D00B25965 /* StyleSurroundData.h */,
                                BC5EB80D0E81F2CE00B25965 /* StyleTransformData.cpp */,
                                A8EA800C0A19516E00A8EF5F /* StyleSheet.h in Headers */,
                                E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */,
                                A8EA800A0A19516E00A8EF5F /* StyleSheetList.h in Headers */,
+                               1C0AA16D21940DC800896829 /* StyleSupportedColorSchemes.h in Headers */,
                                BC5EB5E50E81BF6D00B25965 /* StyleSurroundData.h in Headers */,
                                BC5EB8100E81F2CE00B25965 /* StyleTransformData.h in Headers */,
                                E4DEAA1817A93DC3000E0430 /* StyleTreeResolver.h in Headers */,
index 2ef6629..0afa12f 100644 (file)
@@ -448,6 +448,9 @@ static const CSSPropertyID computedProperties[] = {
     CSSPropertyStrokeMiterlimit,
     CSSPropertyStrokeOpacity,
     CSSPropertyStrokeWidth,
+#if ENABLE(DARK_MODE_CSS)
+    CSSPropertySupportedColorSchemes,
+#endif
     CSSPropertyAlignmentBaseline,
     CSSPropertyBaselineShift,
     CSSPropertyDominantBaseline,
@@ -3969,6 +3972,27 @@ RefPtr<CSSValue> ComputedStyleExtractor::valueForPropertyinStyle(const RenderSty
             return cssValuePool.createValue(style.applePayButtonType());
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+        case CSSPropertySupportedColorSchemes: {
+            if (!RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled())
+                return nullptr;
+
+            auto supportedColorSchemes = style.supportedColorSchemes();
+            if (supportedColorSchemes.isAuto())
+                return cssValuePool.createIdentifierValue(CSSValueAuto);
+
+            auto list = CSSValueList::createSpaceSeparated();
+            if (supportedColorSchemes.contains(ColorSchemes::Light))
+                list->append(cssValuePool.createIdentifierValue(CSSValueLight));
+            if (supportedColorSchemes.contains(ColorSchemes::Dark))
+                list->append(cssValuePool.createIdentifierValue(CSSValueDark));
+            if (!supportedColorSchemes.allowsTransformations())
+                list->append(cssValuePool.createIdentifierValue(CSSValueOnly));
+            ASSERT(list->length());
+            return WTFMove(list);
+        }
+#endif
+
         /* Individual properties not part of the spec */
         case CSSPropertyBackgroundRepeatX:
         case CSSPropertyBackgroundRepeatY:
index 28d8482..a154eb0 100644 (file)
             },
             "status": "non-standard"
         },
+        "supported-color-schemes": {
+            "inherited": true,
+            "values": [
+                "auto",
+                "light",
+                "dark",
+                "only"
+            ],
+            "codegen-properties": {
+                "converter": "SupportedColorSchemes",
+                "enable-if": "ENABLE_DARK_MODE_CSS"
+            },
+            "status": {
+                "status": "non-standard"
+            }
+        },
         "order": {
             "codegen-properties": {
                 "aliases": [
index 90f912a..86b5e59 100644 (file)
@@ -1384,6 +1384,11 @@ no-preference
 light
 dark
 // no-preference
+
+// supported-color-schemes
+only
+// light
+// dark
 #endif
 
 // auto-repeat
index 0e838bb..e61d1f5 100644 (file)
@@ -77,6 +77,9 @@ public:
     template<CSSPropertyID> static NinePieceImage convertBorderMask(StyleResolver&, CSSValue&);
     template<CSSPropertyID> static RefPtr<StyleImage> convertStyleImage(StyleResolver&, CSSValue&);
     static TransformOperations convertTransform(StyleResolver&, const CSSValue&);
+#if ENABLE(DARK_MODE_CSS)
+    static StyleSupportedColorSchemes convertSupportedColorSchemes(StyleResolver&, const CSSValue&);
+#endif
     static String convertString(StyleResolver&, const CSSValue&);
     static String convertStringOrAuto(StyleResolver&, const CSSValue&);
     static String convertStringOrNone(StyleResolver&, const CSSValue&);
@@ -165,6 +168,10 @@ private:
     static Length parseSnapCoordinate(StyleResolver&, const CSSValue&);
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+    static void updateSupportedColorSchemes(const CSSPrimitiveValue&, StyleSupportedColorSchemes&);
+#endif
+
     static Length convertTo100PercentMinusLength(const Length&);
     template<CSSValueID, CSSValueID> static Length convertPositionComponent(StyleResolver&, const CSSPrimitiveValue&);
 
@@ -453,6 +460,48 @@ inline TransformOperations StyleBuilderConverter::convertTransform(StyleResolver
     return operations;
 }
 
+#if ENABLE(DARK_MODE_CSS)
+inline void StyleBuilderConverter::updateSupportedColorSchemes(const CSSPrimitiveValue& primitiveValue, StyleSupportedColorSchemes& supportedColorSchemes)
+{
+    ASSERT(primitiveValue.isValueID());
+
+    switch (primitiveValue.valueID()) {
+    case CSSValueAuto:
+        supportedColorSchemes = StyleSupportedColorSchemes();
+        break;
+    case CSSValueOnly:
+        supportedColorSchemes.setAllowsTransformations(false);
+        break;
+    case CSSValueLight:
+        supportedColorSchemes.add(ColorSchemes::Light);
+        break;
+    case CSSValueDark:
+        supportedColorSchemes.add(ColorSchemes::Dark);
+        break;
+    default:
+        // Unknown identifiers are allowed and ignored.
+        break;
+    }
+}
+
+inline StyleSupportedColorSchemes StyleBuilderConverter::convertSupportedColorSchemes(StyleResolver&, const CSSValue& value)
+{
+    StyleSupportedColorSchemes supportedColorSchemes;
+
+    if (is<CSSValueList>(value)) {
+        for (auto& currentValue : downcast<CSSValueList>(value))
+            updateSupportedColorSchemes(downcast<CSSPrimitiveValue>(currentValue.get()), supportedColorSchemes);
+    } else if (is<CSSPrimitiveValue>(value))
+        updateSupportedColorSchemes(downcast<CSSPrimitiveValue>(value), supportedColorSchemes);
+
+    // If the value was just "only", that is synonymous for "only light".
+    if (supportedColorSchemes.isOnly())
+        supportedColorSchemes.add(ColorSchemes::Light);
+
+    return supportedColorSchemes;
+}
+#endif
+
 inline String StyleBuilderConverter::convertString(StyleResolver&, const CSSValue& value)
 {
     return downcast<CSSPrimitiveValue>(value).stringValue();
index 75b0b8d..24b06be 100644 (file)
@@ -1841,14 +1841,14 @@ Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, boo
     case CSSValueWebkitActivelink:
         return document().activeLinkColor();
     case CSSValueWebkitFocusRingColor:
-        return RenderTheme::focusRingColor(document().styleColorOptions());
+        return RenderTheme::focusRingColor(document().styleColorOptions(m_state.style()));
     case CSSValueCurrentcolor:
         // Color is an inherited property so depending on it effectively makes the property inherited.
         // FIXME: Setting the flag as a side effect of calling this function is a bit oblique. Can we do better?
         m_state.style()->setHasExplicitlyInheritedProperties();
         return m_state.style()->color();
     default:
-        return StyleColor::colorFromKeyword(identifier, document().styleColorOptions());
+        return StyleColor::colorFromKeyword(identifier, document().styleColorOptions(m_state.style()));
     }
 }
 
index d3a0477..15e7fe6 100644 (file)
@@ -3747,7 +3747,51 @@ static RefPtr<CSSValue> consumeTextEmphasisPosition(CSSParserTokenRange& range)
         list->append(CSSValuePool::singleton().createIdentifierValue(leftRightValueID));
     return list;
 }
-    
+
+#if ENABLE(DARK_MODE_CSS)
+
+static RefPtr<CSSValue> consumeSupportedColorSchemes(CSSParserTokenRange& range)
+{
+    if (isAuto(range.peek().id()))
+        return consumeIdent(range);
+
+    Vector<CSSValueID, 3> identifiers;
+
+    while (!range.atEnd()) {
+        if (range.peek().type() != IdentToken)
+            return nullptr;
+
+        CSSValueID id = range.peek().id();
+
+        switch (id) {
+        case CSSValueAuto:
+            // Auto is only allowed as a single value, and was handled earlier.
+            // Don't allow it in the list.
+            return nullptr;
+
+        case CSSValueOnly:
+        case CSSValueLight:
+        case CSSValueDark:
+            if (!identifiers.appendIfNotContains(id))
+                return nullptr;
+            break;
+
+        default:
+            // Unknown identifiers are allowed and ignored.
+            break;
+        }
+
+        range.consumeIncludingWhitespace();
+    }
+
+    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
+    for (auto id : identifiers)
+        list->append(CSSValuePool::singleton().createIdentifierValue(id));
+    return list;
+}
+
+#endif
+
 #if ENABLE(DASHBOARD_SUPPORT)
 
 static RefPtr<CSSValue> consumeWebkitDashboardRegion(CSSParserTokenRange& range, CSSParserMode mode)
@@ -4289,6 +4333,12 @@ RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS
         return consumeWebkitAspectRatio(m_range);
     case CSSPropertyWebkitTextEmphasisPosition:
         return consumeTextEmphasisPosition(m_range);
+#if ENABLE(DARK_MODE_CSS)
+    case CSSPropertySupportedColorSchemes:
+        if (!RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled())
+            return nullptr;
+        return consumeSupportedColorSchemes(m_range);
+#endif
 #if ENABLE(DASHBOARD_SUPPORT)
     case CSSPropertyWebkitDashboardRegion:
         return consumeWebkitDashboardRegion(m_range, m_context.mode);
index 1e6bc4b..f073142 100644 (file)
@@ -817,17 +817,17 @@ String Document::compatMode() const
 
 void Document::resetLinkColor()
 {
-    m_linkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions());
+    m_linkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions(nullptr));
 }
 
 void Document::resetVisitedLinkColor()
 {
-    m_visitedLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions() | StyleColor::Options::ForVisitedLink);
+    m_visitedLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions(nullptr) | StyleColor::Options::ForVisitedLink);
 }
 
 void Document::resetActiveLinkColor()
 {
-    m_activeLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitActivelink, styleColorOptions());
+    m_activeLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitActivelink, styleColorOptions(nullptr));
 }
 
 DOMImplementation& Document::implementation()
@@ -3590,18 +3590,34 @@ static void processColorSchemes(StringView colorSchemes, const WTF::Function<voi
 void Document::processSupportedColorSchemes(const String& colorSchemes)
 {
     OptionSet<ColorSchemes> supportedColorSchemes;
+    bool allowsTransformations = true;
+    bool autoEncountered = false;
+
+    processColorSchemes(colorSchemes, [&](StringView key) {
+        if (equalLettersIgnoringASCIICase(key, "auto")) {
+            supportedColorSchemes = { };
+            allowsTransformations = true;
+            autoEncountered = true;
+            return;
+        }
+
+        if (autoEncountered)
+            return;
 
-    processColorSchemes(colorSchemes, [&supportedColorSchemes](StringView key) {
         if (equalLettersIgnoringASCIICase(key, "light"))
             supportedColorSchemes.add(ColorSchemes::Light);
         else if (equalLettersIgnoringASCIICase(key, "dark"))
             supportedColorSchemes.add(ColorSchemes::Dark);
+        else if (equalLettersIgnoringASCIICase(key, "only"))
+            allowsTransformations = false;
     });
 
-    if (supportedColorSchemes.isEmpty())
+    // If the value was just "only", that is synonymous for "only light".
+    if (supportedColorSchemes.isEmpty() && !allowsTransformations)
         supportedColorSchemes.add(ColorSchemes::Light);
 
     m_supportedColorSchemes = supportedColorSchemes;
+    m_allowsColorSchemeTransformations = allowsTransformations;
 
     if (auto* page = this->page())
         page->updateStyleAfterChangeInEnvironment();
@@ -7281,11 +7297,23 @@ bool Document::useSystemAppearance() const
     return useSystemAppearance;
 }
 
-bool Document::useDarkAppearance() const
+bool Document::useDarkAppearance(const RenderStyle* style) const
 {
 #if ENABLE(DARK_MODE_CSS)
-    if (m_supportedColorSchemes.contains(ColorSchemes::Dark) && !m_supportedColorSchemes.contains(ColorSchemes::Light))
+    OptionSet<ColorSchemes> supportedColorSchemes;
+
+    // Use the style's supported color schemes, if supplied.
+    if (style)
+        supportedColorSchemes = style->supportedColorSchemes().colorSchemes();
+
+    // Fallback to the document's supported color schemes if style was empty (auto).
+    if (supportedColorSchemes.isEmpty())
+        supportedColorSchemes = m_supportedColorSchemes;
+
+    if (supportedColorSchemes.contains(ColorSchemes::Dark) && !supportedColorSchemes.contains(ColorSchemes::Light))
         return true;
+#else
+    UNUSED_PARAM(style);
 #endif
 
     bool pageUsesDarkAppearance = false;
@@ -7296,21 +7324,19 @@ bool Document::useDarkAppearance() const
         return pageUsesDarkAppearance;
 
 #if ENABLE(DARK_MODE_CSS)
-    if (m_supportedColorSchemes.contains(ColorSchemes::Dark))
+    if (supportedColorSchemes.contains(ColorSchemes::Dark))
         return pageUsesDarkAppearance;
-
-    ASSERT(m_supportedColorSchemes.contains(ColorSchemes::Light));
 #endif
 
     return false;
 }
 
-OptionSet<StyleColor::Options> Document::styleColorOptions() const
+OptionSet<StyleColor::Options> Document::styleColorOptions(const RenderStyle* style) const
 {
     OptionSet<StyleColor::Options> options;
     if (useSystemAppearance())
         options.add(StyleColor::Options::UseSystemAppearance);
-    if (useDarkAppearance())
+    if (useDarkAppearance(style))
         options.add(StyleColor::Options::UseDarkAppearance);
     return options;
 }
index 6a7265a..cd53dba 100644 (file)
@@ -578,9 +578,9 @@ public:
     float deviceScaleFactor() const;
 
     WEBCORE_EXPORT bool useSystemAppearance() const;
-    WEBCORE_EXPORT bool useDarkAppearance() const;
+    WEBCORE_EXPORT bool useDarkAppearance(const RenderStyle*) const;
 
-    OptionSet<StyleColor::Options> styleColorOptions() const;
+    OptionSet<StyleColor::Options> styleColorOptions(const RenderStyle*) const;
 
     WEBCORE_EXPORT Ref<Range> createRange();
 
@@ -901,11 +901,6 @@ public:
     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
 
@@ -1772,7 +1767,8 @@ private:
     HashSet<SVGUseElement*> m_svgUseElements;
 
 #if ENABLE(DARK_MODE_CSS)
-    OptionSet<ColorSchemes> m_supportedColorSchemes { ColorSchemes::Light };
+    OptionSet<ColorSchemes> m_supportedColorSchemes;
+    bool m_allowsColorSchemeTransformations { true };
 #endif
 
 #if ENABLE(DASHBOARD_SUPPORT)
index aefeb1a..d4207b9 100644 (file)
@@ -50,6 +50,7 @@
 #import "MIMETypeRegistry.h"
 #import "Page.h"
 #import "PublicURLManager.h"
+#import "RenderView.h"
 #import "RuntimeEnabledFeatures.h"
 #import "SerializedAttachmentData.h"
 #import "Settings.h"
@@ -133,7 +134,9 @@ static FragmentAndResources createFragment(Frame& frame, NSAttributedString *str
     Document& document = *frame.document();
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(document.useDarkAppearance());
+    auto* view = frame.view();
+    auto* renderView = view ? view->renderView() : nullptr;
+    LocalDefaultSystemAppearance localAppearance(renderView ? renderView->useDarkAppearance() : false);
 #endif
 
     NSArray *subresources = nil;
index d15dec4..da1c80f 100644 (file)
@@ -86,7 +86,7 @@ void CanvasRenderingContext2D::drawFocusIfNeededInternal(const Path& path, Eleme
     auto* context = drawingContext();
     if (!element.focused() || !state().hasInvertibleTransform || path.isEmpty() || !element.isDescendantOf(canvas()) || !context)
         return;
-    context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor(element.document().styleColorOptions()));
+    context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor(element.document().styleColorOptions(canvas().computedStyle())));
 }
 
 String CanvasRenderingContext2D::font() const
index d5def90..dec71e5 100644 (file)
@@ -180,12 +180,13 @@ void InspectorOverlay::paint(GraphicsContext& context)
     if (!shouldShowOverlay())
         return;
 
+    GraphicsContextStateSaver stateSaver(context);
+    FrameView* view = overlayPage()->mainFrame().view();
+
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(m_page.mainFrame().document()->useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(view->renderView()->useDarkAppearance());
 #endif
 
-    GraphicsContextStateSaver stateSaver(context);
-    FrameView* view = overlayPage()->mainFrame().view();
     view->updateLayoutAndStyleIfNeededRecursive();
     view->paint(context, IntRect(0, 0, view->width(), view->height()));
 }
index 3e6246a..20d7615 100644 (file)
@@ -2046,9 +2046,7 @@ bool FrameView::shouldSetCursor() const
 
 bool FrameView::useDarkAppearance() const
 {
-    ASSERT(frame().document());
-    auto& document = *frame().document();
-    return document.useDarkAppearance();
+    return renderView()->useDarkAppearance();
 }
 
 bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
@@ -3911,8 +3909,7 @@ void FrameView::paintScrollCorner(GraphicsContext& context, const IntRect& corne
 #if PLATFORM(MAC)
     // If dark appearance is used or the overlay style is light (because of a dark page background), set the dark apppearance.
     // Keep this in sync with ScrollAnimatorMac's effectiveAppearanceForScrollerImp:.
-    auto* document = frame().document();
-    bool useDarkAppearance = (document && document->useDarkAppearance()) || scrollbarOverlayStyle() == WebCore::ScrollbarOverlayStyleLight;
+    bool useDarkAppearance = renderView()->useDarkAppearance() || scrollbarOverlayStyle() == WebCore::ScrollbarOverlayStyleLight;
     LocalDefaultSystemAppearance localAppearance(useDarkAppearance);
 #endif
 
index 11cda24..9c30f79 100644 (file)
@@ -300,7 +300,7 @@ DragImageRef createDragImageForLink(Element& element, URL& url, const String& ti
 {
     LinkImageLayout layout(url, title);
 
-    LocalDefaultSystemAppearance localAppearance(element.document().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(element.document().useDarkAppearance(element.computedStyle()));
 
     auto imageSize = layout.boundingRect.size();
 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
index d745811..03e41e7 100644 (file)
@@ -1372,7 +1372,7 @@ void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint&
     Color color = lineStyle.visitedDependentColor(CSSPropertyBackgroundColor);
 
     CompositeOperator compositeOp = CompositeSourceOver;
-    if (renderer().document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && renderer().theme().usingDarkAppearance(renderer()))
+    if (renderer().document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && renderer().useDarkAppearance())
         compositeOp = CompositeDestinationOut;
 
     color = lineStyle.colorByApplyingColorFilter(color);
index 5039e2a..08eb039 100644 (file)
@@ -716,7 +716,7 @@ void InlineTextBox::paintPlatformDocumentMarker(GraphicsContext& context, const
     auto bounds = calculateDocumentMarkerBounds(markedText);
 
     auto lineStyleForMarkedTextType = [&]() -> DocumentMarkerLineStyle {
-        bool shouldUseDarkAppearance = renderer().document().useDarkAppearance();
+        bool shouldUseDarkAppearance = renderer().useDarkAppearance();
         switch (markedText.type) {
         case MarkedText::SpellingError:
             return { DocumentMarkerLineStyle::Mode::Spelling, shouldUseDarkAppearance };
index ca6e7c1..0f12ad8 100644 (file)
@@ -1207,7 +1207,7 @@ void RenderBox::paintRootBoxFillLayers(const PaintInfo& paintInfo)
     auto color = style.visitedDependentColor(CSSPropertyBackgroundColor);
 
     CompositeOperator compositeOp = CompositeSourceOver;
-    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && theme().usingDarkAppearance(*this))
+    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && useDarkAppearance())
         compositeOp = CompositeDestinationOut;
 
     paintFillLayers(paintInfo, style.colorByApplyingColorFilter(color), style.backgroundLayers(), view().backgroundRect(), BackgroundBleedNone, compositeOp, rootBackgroundRenderer);
@@ -1341,7 +1341,7 @@ void RenderBox::paintBackground(const PaintInfo& paintInfo, const LayoutRect& pa
     Color backgroundColor = style().visitedDependentColor(CSSPropertyBackgroundColor);
 
     CompositeOperator compositeOp = CompositeSourceOver;
-    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(backgroundColor) && theme().usingDarkAppearance(*this))
+    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(backgroundColor) && useDarkAppearance())
         compositeOp = CompositeDestinationOut;
 
     paintFillLayers(paintInfo, style().colorByApplyingColorFilter(backgroundColor), style().backgroundLayers(), paintRect, bleedAvoidance, compositeOp);
index bf97c08..908b85a 100644 (file)
@@ -1374,8 +1374,8 @@ Color RenderElement::selectionColor(CSSPropertyID colorProperty) const
     }
 
     if (frame().selection().isFocusedAndActive())
-        return theme().activeSelectionForegroundColor(document().styleColorOptions());
-    return theme().inactiveSelectionForegroundColor(document().styleColorOptions());
+        return theme().activeSelectionForegroundColor(styleColorOptions());
+    return theme().inactiveSelectionForegroundColor(styleColorOptions());
 }
 
 std::unique_ptr<RenderStyle> RenderElement::selectionPseudoStyle() const
@@ -1409,15 +1409,15 @@ Color RenderElement::selectionBackgroundColor() const
         return Color();
 
     if (frame().selection().shouldShowBlockCursor() && frame().selection().isCaret())
-        return theme().transformSelectionBackgroundColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor), document().styleColorOptions());
+        return theme().transformSelectionBackgroundColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor), styleColorOptions());
 
     std::unique_ptr<RenderStyle> pseudoStyle = selectionPseudoStyle();
     if (pseudoStyle && pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor).isValid())
-        return theme().transformSelectionBackgroundColor(pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor), document().styleColorOptions());
+        return theme().transformSelectionBackgroundColor(pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor), styleColorOptions());
 
     if (frame().selection().isFocusedAndActive())
-        return theme().activeSelectionBackgroundColor(document().styleColorOptions());
-    return theme().inactiveSelectionBackgroundColor(document().styleColorOptions());
+        return theme().activeSelectionBackgroundColor(styleColorOptions());
+    return theme().inactiveSelectionBackgroundColor(styleColorOptions());
 }
 
 bool RenderElement::getLeadingCorner(FloatPoint& point, bool& insideFixed) const
@@ -1838,9 +1838,9 @@ void RenderElement::paintFocusRing(PaintInfo& paintInfo, const RenderStyle& styl
             for (auto rect : pixelSnappedFocusRingRects)
                 path.addRect(rect);
         }
-        paintInfo.context().drawFocusRing(path, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(document().styleColorOptions()));
+        paintInfo.context().drawFocusRing(path, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(styleColorOptions()));
     } else
-        paintInfo.context().drawFocusRing(pixelSnappedFocusRingRects, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(document().styleColorOptions()));
+        paintInfo.context().drawFocusRing(pixelSnappedFocusRingRects, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(styleColorOptions()));
     if (needsRepaint)
         page().focusController().setFocusedElementNeedsRepaint();
 #else
index 8109ebf..a0d2b7b 100644 (file)
@@ -574,7 +574,7 @@ void RenderImage::paintAreaElementFocusRing(PaintInfo& paintInfo, const LayoutPo
 
 #if PLATFORM(MAC)
     bool needsRepaint;
-    paintInfo.context().drawFocusRing(path, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(document().styleColorOptions()));
+    paintInfo.context().drawFocusRing(path, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::focusRingColor(styleColorOptions()));
     if (needsRepaint)
         page().focusController().setFocusedElementNeedsRepaint();
 #else
index 88d6e01..bb7b19e 100644 (file)
@@ -2541,7 +2541,7 @@ void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, Graph
 #endif
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(renderer().document().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(renderer().useDarkAppearance());
 #endif
 
     // The dirtyRect is in the coords of the painting root.
index b655ff2..092b500 100644 (file)
@@ -2782,7 +2782,7 @@ void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRec
 void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& clip, GraphicsLayerPaintBehavior)
 {
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(m_renderView.document().useDarkAppearance());
+    LocalDefaultSystemAppearance localAppearance(m_renderView.useDarkAppearance());
 #endif
 
     IntRect pixelSnappedRectForIntegralPositionedItems = snappedIntRect(LayoutRect(clip));
index ecd5516..5200813 100644 (file)
@@ -428,10 +428,10 @@ void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
     Color textColor = itemStyle.visitedDependentColorWithColorFilter(CSSPropertyColor);
     if (isOptionElement && downcast<HTMLOptionElement>(*listItemElement).selected()) {
         if (frame().selection().isFocusedAndActive() && document().focusedElement() == &selectElement())
-            textColor = theme().activeListBoxSelectionForegroundColor(document().styleColorOptions());
+            textColor = theme().activeListBoxSelectionForegroundColor(styleColorOptions());
         // Honor the foreground color for disabled items
         else if (!listItemElement->isDisabledFormControl() && !selectElement().isDisabledFormControl())
-            textColor = theme().inactiveListBoxSelectionForegroundColor(document().styleColorOptions());
+            textColor = theme().inactiveListBoxSelectionForegroundColor(styleColorOptions());
     }
 
     paintInfo.context().setFillColor(textColor);
@@ -461,9 +461,9 @@ void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint&
     Color backColor;
     if (is<HTMLOptionElement>(*listItemElement) && downcast<HTMLOptionElement>(*listItemElement).selected()) {
         if (frame().selection().isFocusedAndActive() && document().focusedElement() == &selectElement())
-            backColor = theme().activeListBoxSelectionBackgroundColor(document().styleColorOptions());
+            backColor = theme().activeListBoxSelectionBackgroundColor(styleColorOptions());
         else
-            backColor = theme().inactiveListBoxSelectionBackgroundColor(document().styleColorOptions());
+            backColor = theme().inactiveListBoxSelectionBackgroundColor(styleColorOptions());
     } else
         backColor = itemStyle.visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
 
index 7644450..4255105 100644 (file)
@@ -1801,6 +1801,16 @@ CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
     return SetCursorBasedOnStyle;
 }
 
+bool RenderObject::useDarkAppearance() const
+{
+    return document().useDarkAppearance(&style());
+}
+
+OptionSet<StyleColor::Options> RenderObject::styleColorOptions() const
+{
+    return document().styleColorOptions(&style());
+}
+
 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
 {
     if (needsLayout())
index 13b36d6..2dce9dc 100644 (file)
@@ -176,6 +176,9 @@ public:
         return locateEnclosingFragmentedFlow();
     }
 
+    WEBCORE_EXPORT bool useDarkAppearance() const;
+    OptionSet<StyleColor::Options> styleColorOptions() const;
+
 #ifndef NDEBUG
     void setHasAXObject(bool flag) { m_hasAXObject = flag; }
     bool hasAXObject() const { return m_hasAXObject; }
index 345a7bb..7541978 100644 (file)
@@ -1289,7 +1289,7 @@ void RenderTableCell::paintBackgroundsBehindCell(PaintInfo& paintInfo, const Lay
 
     CompositeOperator compositeOp = CompositeSourceOver;
     Color color = style.visitedDependentColor(CSSPropertyBackgroundColor);
-    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && theme().usingDarkAppearance(*this))
+    if (document().settings().punchOutWhiteBackgroundsInDarkMode() && Color::isWhiteColor(color) && useDarkAppearance())
         compositeOp = CompositeDestinationOut;
 
     color = style.colorByApplyingColorFilter(color);
index bd66bb3..2573903 100644 (file)
@@ -318,7 +318,7 @@ bool RenderTheme::paint(const RenderBox& box, ControlStates& controlStates, cons
     case ButtonPart:
     case InnerSpinButtonPart:
         updateControlStatesForRenderer(box, controlStates);
-        Theme::singleton().paint(part, controlStates, paintInfo.context(), devicePixelSnappedRect, box.style().effectiveZoom(), &box.view().frameView(), deviceScaleFactor, pageScaleFactor, box.document().useSystemAppearance(), box.document().useDarkAppearance());
+        Theme::singleton().paint(part, controlStates, paintInfo.context(), devicePixelSnappedRect, box.style().effectiveZoom(), &box.view().frameView(), deviceScaleFactor, pageScaleFactor, box.document().useSystemAppearance(), box.useDarkAppearance());
         return false;
     default:
         break;
index 8fba4db..132a6e4 100644 (file)
@@ -261,8 +261,6 @@ public:
     virtual void paintSystemPreviewBadge(Image&, const PaintInfo&, const FloatRect&);
 #endif
 
-    virtual bool usingDarkAppearance(const RenderObject&) const { return false; }
-
 protected:
     virtual FontCascadeDescription& cachedSystemFontDescription(CSSValueID systemFontID) const;
     virtual void updateCachedSystemFontDescription(CSSValueID systemFontID, FontCascadeDescription&) const = 0;
index d85761a..1dd2b1f 100644 (file)
@@ -174,8 +174,6 @@ private:
     bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&) final;
 #endif
 
-    bool usingDarkAppearance(const RenderObject&) const final;
-
 private:
     String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const final;
 
index 3fbd60d..d550e5b 100644 (file)
@@ -297,7 +297,7 @@ RenderThemeMac::RenderThemeMac()
 
 NSView *RenderThemeMac::documentViewFor(const RenderObject& o) const
 {
-    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(o));
+    LocalDefaultSystemAppearance localAppearance(o.useDarkAppearance());
     ControlStates states(extractControlStatesForRenderer(o));
     return ThemeMac::ensuredView(&o.view().frameView(), states);
 }
@@ -1713,7 +1713,7 @@ void RenderThemeMac::adjustMenuListStyle(StyleResolver& styleResolver, RenderSty
     // Set the foreground color to black or gray when we have the aqua look.
     Color c = Color::darkGray;
     if (e) {
-        OptionSet<StyleColor::Options> options = e->document().styleColorOptions();
+        OptionSet<StyleColor::Options> options = e->document().styleColorOptions(&style);
         c = !e->isDisabledFormControl() ? systemColor(CSSValueButtontext, options) : systemColor(CSSValueGraytext, options);
     }
     style.setColor(c);
@@ -1800,7 +1800,7 @@ void RenderThemeMac::setPopupButtonCellState(const RenderObject& o, const IntSiz
 
 void RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary(NSCell* cell, const RenderObject& renderer, const PaintInfo& paintInfo, const FloatRect& rect)
 {
-    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(renderer));
+    LocalDefaultSystemAppearance localAppearance(renderer.useDarkAppearance());
     bool shouldDrawFocusRing = isFocused(renderer) && renderer.style().outlineStyleIsAuto() == OutlineIsAuto::On;
     bool shouldUseImageBuffer = renderer.style().effectiveZoom() != 1 || renderer.page().pageScaleFactor() != 1;
     bool shouldDrawCell = true;
@@ -1882,7 +1882,7 @@ bool RenderThemeMac::paintSliderThumb(const RenderObject& o, const PaintInfo& pa
         ? sliderThumbVertical()
         : sliderThumbHorizontal();
 
-    LocalDefaultSystemAppearance localAppearance(usingDarkAppearance(o));
+    LocalDefaultSystemAppearance localAppearance(o.useDarkAppearance());
 
     LocalCurrentGraphicsContext localContext(paintInfo.context());
 
@@ -2994,11 +2994,6 @@ bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintIn
 
 #endif // ENABLE(ATTACHMENT_ELEMENT)
 
-bool RenderThemeMac::usingDarkAppearance(const RenderObject& o) const
-{
-    return o.document().useDarkAppearance();
-}
-
 } // namespace WebCore
 
 #endif // PLATFORM(MAC)
index 981b8ee..8555d0b 100644 (file)
 #include "TextSizeAdjustment.h"
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+#include "StyleSupportedColorSchemes.h"
+#endif
+
 #define SET_VAR(group, variable, value) do { \
         if (!compareEqual(group->variable, value)) \
             group.access().variable = value; \
@@ -632,6 +636,10 @@ public:
 
     RubyPosition rubyPosition() const { return static_cast<RubyPosition>(m_rareInheritedData->rubyPosition); }
 
+#if ENABLE(DARK_MODE_CSS)
+    StyleSupportedColorSchemes supportedColorSchemes() const { return m_rareInheritedData->supportedColorSchemes; }
+#endif
+
     TextOrientation textOrientation() const { return static_cast<TextOrientation>(m_rareInheritedData->textOrientation); }
 
     ObjectFit objectFit() const { return static_cast<ObjectFit>(m_rareNonInheritedData->objectFit); }
@@ -1165,6 +1173,10 @@ public:
 
     void setRubyPosition(RubyPosition position) { SET_VAR(m_rareInheritedData, rubyPosition, static_cast<unsigned>(position)); }
 
+#if ENABLE(DARK_MODE_CSS)
+    void setSupportedColorSchemes(StyleSupportedColorSchemes supported) { SET_VAR(m_rareInheritedData, supportedColorSchemes, supported); }
+#endif
+
     void setFilter(const FilterOperations& ops) { SET_NESTED_VAR(m_rareNonInheritedData, filter, operations, ops); }
     void setAppleColorFilter(const FilterOperations& ops) { SET_NESTED_VAR(m_rareInheritedData, appleColorFilter, operations, ops); }
 
@@ -1578,6 +1590,10 @@ public:
     static QuotesData* initialQuotes() { return nullptr; }
     static const AtomicString& initialContentAltText() { return emptyAtom(); }
 
+#if ENABLE(DARK_MODE_CSS)
+    static StyleSupportedColorSchemes initialSupportedColorSchemes() { return { }; }
+#endif
+
 #if ENABLE(CSS3_TEXT)
     static TextIndentLine initialTextIndentLine() { return TextIndentLine::FirstLine; }
     static TextIndentType initialTextIndentType() { return TextIndentType::Normal; }
index 176eb21..66e5c7b 100644 (file)
@@ -1018,6 +1018,15 @@ enum class RubyPosition : uint8_t {
     InterCharacter
 };
 
+#if ENABLE(DARK_MODE_CSS)
+enum class ColorSchemes : uint8_t {
+    Light = 1 << 0,
+    Dark = 1 << 1
+};
+
+static const size_t ColorSchemesBits = 2;
+#endif
+
 static const size_t GridAutoFlowBits = 4;
 enum InternalGridAutoFlowAlgorithm {
     InternalAutoFlowAlgorithmSparse = 1 << 0,
index 5fb79b3..45f736a 100644 (file)
@@ -31,6 +31,7 @@
 #include "StyleCustomPropertyData.h"
 #include "StyleFilterData.h"
 #include "StyleImage.h"
+#include "StyleSupportedColorSchemes.h"
 #include <wtf/PointerComparison.h>
 
 namespace WebCore {
@@ -67,6 +68,10 @@ struct GreaterThanOrSameSizeAsStyleRareInheritedData : public RefCounted<Greater
     Color tapHighlightColor;
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+    StyleSupportedColorSchemes supportedColorSchemes;
+#endif
+
     void* customPropertyDataRefs[1];
 };
 
@@ -153,6 +158,9 @@ StyleRareInheritedData::StyleRareInheritedData()
 #if ENABLE(TOUCH_EVENTS)
     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
 #endif
+#if ENABLE(DARK_MODE_CSS)
+    , supportedColorSchemes(RenderStyle::initialSupportedColorSchemes())
+#endif
 {
 }
 
@@ -251,6 +259,9 @@ inline StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedDa
 #if ENABLE(TOUCH_EVENTS)
     , tapHighlightColor(o.tapHighlightColor)
 #endif
+#if ENABLE(DARK_MODE_CSS)
+    , supportedColorSchemes(o.supportedColorSchemes)
+#endif
 {
 }
 
@@ -297,6 +308,9 @@ bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
 #if ENABLE(TEXT_AUTOSIZING)
         && textSizeAdjust == o.textSizeAdjust
 #endif
+#if ENABLE(DARK_MODE_CSS)
+        && supportedColorSchemes == o.supportedColorSchemes
+#endif
         && userSelect == o.userSelect
         && speakAs == o.speakAs
         && hyphens == o.hyphens
index a3ad175..b2bddfd 100644 (file)
 #include "TextSizeAdjustment.h"
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+#include "StyleSupportedColorSchemes.h"
+#endif
+
 namespace WebCore {
 
 class CursorList;
@@ -181,6 +185,10 @@ public:
     Color tapHighlightColor;
 #endif
 
+#if ENABLE(DARK_MODE_CSS)
+    StyleSupportedColorSchemes supportedColorSchemes;
+#endif
+
 private:
     StyleRareInheritedData();
     StyleRareInheritedData(const StyleRareInheritedData&);
diff --git a/Source/WebCore/rendering/style/StyleSupportedColorSchemes.h b/Source/WebCore/rendering/style/StyleSupportedColorSchemes.h
new file mode 100644 (file)
index 0000000..96e24cb
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#pragma once
+
+#if ENABLE(DARK_MODE_CSS)
+
+#include "RenderStyleConstants.h"
+#include <wtf/OptionSet.h>
+
+namespace WebCore {
+
+class StyleSupportedColorSchemes {
+public:
+    StyleSupportedColorSchemes() { }
+
+    StyleSupportedColorSchemes(const StyleSupportedColorSchemes& other)
+        : m_colorSchemes(other.m_colorSchemes)
+        , m_allowsTransformations(other.m_allowsTransformations)
+    { }
+
+    StyleSupportedColorSchemes(OptionSet<ColorSchemes> colorSchemes, bool allowsTransformations)
+        : m_colorSchemes(colorSchemes)
+        , m_allowsTransformations(allowsTransformations)
+    { }
+
+    bool operator==(const StyleSupportedColorSchemes& other) const
+    {
+        return m_colorSchemes == other.m_colorSchemes && m_allowsTransformations == other.m_allowsTransformations;
+    }
+
+    bool operator!=(const StyleSupportedColorSchemes& other) const { return !(*this == other); }
+
+    bool isAuto() const { return m_colorSchemes.isEmpty() && m_allowsTransformations; }
+    bool isOnly() const { return m_colorSchemes.isEmpty() && !m_allowsTransformations; }
+
+    OptionSet<ColorSchemes> colorSchemes() const { return m_colorSchemes; }
+
+    void add(ColorSchemes colorScheme) { m_colorSchemes.add(colorScheme); }
+    bool contains(ColorSchemes colorScheme) const { return m_colorSchemes.contains(colorScheme); }
+
+    void setAllowsTransformations(bool allow) { m_allowsTransformations = allow; }
+    bool allowsTransformations() const { return m_allowsTransformations; }
+
+private:
+    OptionSet<ColorSchemes> m_colorSchemes;
+    bool m_allowsTransformations { true };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(DARK_MODE_CSS)
index 91ef851..06097ec 100644 (file)
@@ -47,6 +47,7 @@
 #include "PageConfiguration.h"
 #include "RenderSVGRoot.h"
 #include "RenderStyle.h"
+#include "RenderView.h"
 #include "SVGDocument.h"
 #include "SVGFEImageElement.h"
 #include "SVGForeignObjectElement.h"
@@ -324,8 +325,7 @@ ImageDrawResult SVGImage::draw(GraphicsContext& context, const FloatRect& dstRec
     }
 
 #if PLATFORM(MAC)
-    auto* document = m_page->mainFrame().document();
-    LocalDefaultSystemAppearance localAppearance(document ? document->useDarkAppearance() : false);
+    LocalDefaultSystemAppearance localAppearance(view->renderView()->useDarkAppearance());
 #endif
 
     view->paint(context, intersection(context.clipBounds(), enclosingIntRect(srcRect)));
index 53018fd..77d715f 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-08  Timothy Hatcher  <timothy@apple.com>
+
+        Add experimental support for a `supported-color-schemes` CSS property.
+        https://bugs.webkit.org/show_bug.cgi?id=191319
+        rdar://problem/45852261
+
+        Reviewed by Dean Jackson.
+
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
+        (WebKit::InjectedBundleRangeHandle::renderedImage):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::drawRect):
+
 2018-11-08  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Use DeviceIdHashSaltStorage to generate device ID hash salt
index 3f4f567..4bfdd7f 100644 (file)
@@ -41,6 +41,7 @@
 #include <WebCore/JSRange.h>
 #include <WebCore/Page.h>
 #include <WebCore/Range.h>
+#include <WebCore/RenderView.h>
 #include <WebCore/VisibleSelection.h>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
@@ -124,7 +125,8 @@ RefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions option
         return nullptr;
 
 #if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(ownerDocument.useDarkAppearance());
+    RenderView* renderView = frameView->renderView();
+    LocalDefaultSystemAppearance localAppearance(renderView ? renderView->useDarkAppearance() : false);
 #endif
 
     Ref<Frame> protector(*frame);
index 80c5383..2f54d5d 100644 (file)
@@ -1556,8 +1556,8 @@ void WebPage::scrollMainFrameIfNotAtMaxScrollPosition(const IntSize& scrollOffse
 void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect)
 {
 #if PLATFORM(MAC)
-    auto* document = m_mainFrame->coreFrame()->document();
-    LocalDefaultSystemAppearance localAppearance(document ? document->useDarkAppearance() : false);
+    RenderView* renderView = m_page->mainFrame().view()->renderView();
+    LocalDefaultSystemAppearance localAppearance(renderView ? renderView->useDarkAppearance() : false);
 #endif
 
     GraphicsContextStateSaver stateSaver(graphicsContext);
index 5546d00..3d6afcb 100644 (file)
 #import "WebUIKitDelegate.h"
 #endif
 
-#if PLATFORM(MAC)
-#import <WebCore/LocalDefaultSystemAppearance.h>
-#endif
-
 using namespace WebCore;
 
 using namespace HTMLNames;
@@ -477,10 +473,6 @@ static NSDictionary *attributesForAttributedStringConversion()
 
 void _WebCreateFragment(Document& document, NSAttributedString *string, FragmentAndResources& result)
 {
-#if PLATFORM(MAC)
-    LocalDefaultSystemAppearance localAppearance(document.useDarkAppearance());
-#endif
-
     static NSDictionary *documentAttributes = [attributesForAttributedStringConversion() retain];
     NSArray *subresources;
     DOMDocumentFragment* fragment = [string _documentFromRange:NSMakeRange(0, [string length])