Add color-gamut media query support
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2016 22:10:50 +0000 (22:10 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2016 22:10:50 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155994
<rdar://problem/23282326>

Reviewed by Darin Adler.

Source/WebCore:

Add the new CSS media query: color-gamut
https://drafts.csswg.org/mediaqueries-4/#color-gamut

This ultimately calls into screenSupportsExtendedColor,
which has only been implemented on iOS at the moment.
All displays will match the "srgb" keyword, but only
iOS devices with an extended color screen will
match against "p3" (e.g. the iPad Pro 9.7").
Nothing will match against "rec2020".

Test: fast/media/mq-color-gamut.html

* css/CSSValueKeywords.in: Add "p3" and "rec2020".
* css/MediaFeatureNames.h: Add "color-gamut"
* css/MediaQueryEvaluator.cpp:
(WebCore::color_gamutMediaFeatureEval): Call
screenSupportsExtendedColor to see if we're srgb or p3.
* css/MediaQueryExp.cpp:
(WebCore::featureWithCSSValueID):
* platform/efl/PlatformScreenEfl.cpp: Add empty implementation.
(WebCore::screenSupportsExtendedColor):
* platform/gtk/PlatformScreenGtk.cpp: Ditto.
(WebCore::screenSupportsExtendedColor):
* platform/win/PlatformScreenWin.cpp: Ditto.
(WebCore::screenSupportsExtendedColor):

LayoutTests:

New test for color-gamut.

* fast/media/mq-color-gamut-expected.html: Added.
* fast/media/mq-color-gamut.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/media/mq-color-gamut-expected.html [new file with mode: 0644]
LayoutTests/fast/media/mq-color-gamut.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/MediaFeatureNames.h
Source/WebCore/css/MediaQueryEvaluator.cpp
Source/WebCore/css/MediaQueryExp.cpp
Source/WebCore/platform/efl/PlatformScreenEfl.cpp
Source/WebCore/platform/gtk/PlatformScreenGtk.cpp
Source/WebCore/platform/win/PlatformScreenWin.cpp

index dc71f62..8613519 100644 (file)
@@ -1,3 +1,16 @@
+2016-04-04  Dean Jackson  <dino@apple.com>
+
+        Add color-gamut media query support
+        https://bugs.webkit.org/show_bug.cgi?id=155994
+        <rdar://problem/23282326>
+
+        Reviewed by Darin Adler.
+
+        New test for color-gamut.
+
+        * fast/media/mq-color-gamut-expected.html: Added.
+        * fast/media/mq-color-gamut.html: Added.
+
 2016-04-04  Ryan Haddad  <ryanhaddad@apple.com>
 
         Skipping crashing test fast/loader/opaque-base-url.html on Debug
diff --git a/LayoutTests/fast/media/mq-color-gamut-expected.html b/LayoutTests/fast/media/mq-color-gamut-expected.html
new file mode 100644 (file)
index 0000000..014716f
--- /dev/null
@@ -0,0 +1,16 @@
+<html>
+<head>
+<title>CSS4 media query test: color-gamut.</title>
+<style type="text/css">
+#a { background-color: green; }
+#b { background-color: blue; }
+#c { background-color: green; }
+</style>
+</head>
+<body>
+  <p id="a">This paragraph should have a green background.</p>
+  <p id="b">This paragraph should have a blue background on a device with a display that supports something close to sRGB, which is nearly all displays. Otherwise the background should be green.</p>
+  <p id="c">This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.</p>
+  <p>Note that the expected results of this test assume a display that is not significantly wider than sRGB.</p>
+</body>
+</html>
diff --git a/LayoutTests/fast/media/mq-color-gamut.html b/LayoutTests/fast/media/mq-color-gamut.html
new file mode 100644 (file)
index 0000000..8597438
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+<title>CSS4 media query test: color-gamut.</title>
+<style type="text/css">
+#a { background-color: green; }
+#b { background-color: green; }
+#c { background-color: green; }
+
+@media (color-gamut: srgb) {
+#b { background-color: blue; }
+}
+
+@media (color-gamut: p3) {
+#c { background-color: blue; }
+}
+</style>
+</head>
+<body>
+  <p id="a">This paragraph should have a green background.</p>
+  <p id="b">This paragraph should have a blue background on a device with a display that supports something close to sRGB, which is nearly all displays. Otherwise the background should be green.</p>
+  <p id="c">This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.</p>
+  <p>Note that the expected results of this test assume a display that is not significantly wider than sRGB.</p>
+</body>
+</html>
index e61d22d..adb016f 100644 (file)
@@ -1,3 +1,37 @@
+2016-04-04  Dean Jackson  <dino@apple.com>
+
+        Add color-gamut media query support
+        https://bugs.webkit.org/show_bug.cgi?id=155994
+        <rdar://problem/23282326>
+
+        Reviewed by Darin Adler.
+
+        Add the new CSS media query: color-gamut
+        https://drafts.csswg.org/mediaqueries-4/#color-gamut
+
+        This ultimately calls into screenSupportsExtendedColor,
+        which has only been implemented on iOS at the moment.
+        All displays will match the "srgb" keyword, but only
+        iOS devices with an extended color screen will
+        match against "p3" (e.g. the iPad Pro 9.7").
+        Nothing will match against "rec2020".
+
+        Test: fast/media/mq-color-gamut.html
+
+        * css/CSSValueKeywords.in: Add "p3" and "rec2020".
+        * css/MediaFeatureNames.h: Add "color-gamut"
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::color_gamutMediaFeatureEval): Call
+        screenSupportsExtendedColor to see if we're srgb or p3.
+        * css/MediaQueryExp.cpp:
+        (WebCore::featureWithCSSValueID):
+        * platform/efl/PlatformScreenEfl.cpp: Add empty implementation.
+        (WebCore::screenSupportsExtendedColor):
+        * platform/gtk/PlatformScreenGtk.cpp: Ditto.
+        (WebCore::screenSupportsExtendedColor):
+        * platform/win/PlatformScreenWin.cpp: Ditto.
+        (WebCore::screenSupportsExtendedColor):
+
 2016-04-04  Brent Fulgham  <bfulgham@apple.com>
 
         Update feature status on anchor download attribute.
index df916e8..396f7f5 100644 (file)
@@ -1196,3 +1196,7 @@ allow-end
 first
 force-end
 last
+
+// color-gamut
+p3
+rec2020
index 512af90..b5ca250 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
     macro(any_pointer, "any-pointer") \
     macro(color, "color") \
     macro(color_index, "color-index") \
+    macro(color_gamut, "color-gamut") \
     macro(grid, "grid") \
     macro(monochrome, "monochrome") \
     macro(height, "height") \
index 012688a..e155f1a 100644 (file)
@@ -250,6 +250,28 @@ static bool color_indexMediaFeatureEval(CSSValue* value, const CSSToLengthConver
     return numberValue(value, number) && compareValue(0, static_cast<int>(number), op);
 }
 
+static bool color_gamutMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
+{
+    if (!value)
+        return true;
+
+    switch (downcast<CSSPrimitiveValue>(*value).getValueID()) {
+    case CSSValueSrgb:
+        return true;
+    case CSSValueP3:
+        // FIXME: For the moment we'll just assume an "extended
+        // color" display is at least as good as P3.
+        return screenSupportsExtendedColor();
+    case CSSValueRec2020:
+        // FIXME: At some point we should start detecting displays that
+        // support more colors.
+        return false;
+    default:
+        ASSERT_NOT_REACHED();
+        return true;
+    }
+}
+
 static bool monochromeMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
 {
     if (!screenIsMonochrome(frame->page()->mainFrame().view())) {
index e63dff6..e8da780 100644 (file)
@@ -45,6 +45,7 @@ static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const
 #if ENABLE(VIEW_MODE_CSS_MEDIA)
         || mediaFeature == MediaFeatureNames::view_modeMediaFeature
 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
+        || mediaFeature == MediaFeatureNames::color_gamutMediaFeature
         || mediaFeature == MediaFeatureNames::any_hoverMediaFeature
         || mediaFeature == MediaFeatureNames::any_pointerMediaFeature
         || mediaFeature == MediaFeatureNames::hoverMediaFeature
index 4d449f4..a43d82c 100644 (file)
@@ -118,4 +118,9 @@ FloatRect screenAvailableRect(Widget* widget)
     return screenRect(widget);
 }
 
+bool screenSupportsExtendedColor()
+{
+    return false;
+}
+
 }
index be2b9c9..1ee59d3 100644 (file)
@@ -130,4 +130,9 @@ FloatRect screenAvailableRect(Widget* widget)
 
 }
 
+bool screenSupportsExtendedColor()
+{
+    return false;
+}
+
 } // namespace WebCore
index 95429b8..15dff9f 100644 (file)
@@ -101,4 +101,9 @@ FloatRect screenAvailableRect(Widget* widget)
     return monitorInfo.rcWork;
 }
 
+bool screenSupportsExtendedColor()
+{
+    return false;
+}
+
 } // namespace WebCore