Title: [119045] trunk
Revision
119045
Author
commit-qu...@webkit.org
Date
2012-05-30 20:56:21 -0700 (Wed, 30 May 2012)

Log Message

[chromium] Implement pointer and hover CSS media features
https://bugs.webkit.org/show_bug.cgi?id=87403

Patch by Rick Byers <rby...@chromium.org> on 2012-05-30
Reviewed by Adam Barth.

Source/WebCore:

Add initial support for the pointer and hover media features as defined
here:
http://dev.w3.org/csswg/css4-mediaqueries/#pointer
http://dev.w3.org/csswg/css4-mediaqueries/#hover

For now this only supports the case where we know a touch screen is
available (currently known only for the chromium port on certain
platforms).  All other cases continue to behave exactly as if the media
feature isn't supported.

Tests: fast/media/mq-pointer.html

* css/CSSValueKeywords.in:
* css/MediaFeatureNames.h:
(MediaFeatureNames):
* css/MediaQueryEvaluator.cpp:
(WebCore::getLeastCapablePrimaryPointerDeviceType):
(WebCore):
(WebCore::hoverMediaFeatureEval):
(WebCore::pointerMediaFeatureEval):

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::InternalSettings):
(WebCore::InternalSettings::restoreTo):
(WebCore::InternalSettings::setDeviceSupportsTouch):
(WebCore):
* testing/InternalSettings.h:
(InternalSettings):
* testing/InternalSettings.idl:

LayoutTests:

Adds tests for pointer and hover media features, for the initial cases
with and without a touch screen.

* fast/media/mq-pointer-expected.txt: Added.
* fast/media/mq-pointer.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (119044 => 119045)


--- trunk/LayoutTests/ChangeLog	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/LayoutTests/ChangeLog	2012-05-31 03:56:21 UTC (rev 119045)
@@ -1,3 +1,16 @@
+2012-05-30  Rick Byers  <rby...@chromium.org>
+
+        [chromium] Implement pointer and hover CSS media features
+        https://bugs.webkit.org/show_bug.cgi?id=87403
+
+        Reviewed by Adam Barth.
+
+        Adds tests for pointer and hover media features, for the initial cases
+        with and without a touch screen.
+
+        * fast/media/mq-pointer-expected.txt: Added.
+        * fast/media/mq-pointer.html: Added.
+
 2012-05-30  Jessie Berlin  <jber...@apple.com>
 
         [Win] Need implementation of layoutTestController.setBackingScaleFactor

Added: trunk/LayoutTests/fast/media/mq-pointer-expected.txt (0 => 119045)


--- trunk/LayoutTests/fast/media/mq-pointer-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-pointer-expected.txt	2012-05-31 03:56:21 UTC (rev 119045)
@@ -0,0 +1,27 @@
+Test the (pointer) and (hover) media features. See Bug 87403 for details.
+
+------------- default configuration -------------
+Query "(pointer)": false
+Query "(Pointer)": false
+Query "(pointer:none)": false
+Query "(pointer:coarse)": false
+Query "(pointer:coARse)": false
+Query "(pointer:bogusvalue)": false
+Query "(pointer:fine)": false
+Query "(hover)": false
+Query "(hover:0)": false
+Query "(hover:1)": false
+Query "(hover:bogusvalue)": false
+------------- with touch screen -------------
+Query "(pointer)": true
+Query "(Pointer)": true
+Query "(pointer:none)": false
+Query "(pointer:coarse)": true
+Query "(pointer:coARse)": true
+Query "(pointer:bogusvalue)": false
+Query "(pointer:fine)": false
+Query "(hover)": false
+Query "(hover:0)": true
+Query "(hover:1)": false
+Query "(hover:bogusvalue)": false
+

Added: trunk/LayoutTests/fast/media/mq-pointer.html (0 => 119045)


--- trunk/LayoutTests/fast/media/mq-pointer.html	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-pointer.html	2012-05-31 03:56:21 UTC (rev 119045)
@@ -0,0 +1,58 @@
+<html>
+<head>
+<title>Test CSS4 media query "pointer" and "hover" features.</title>
+<style type="text/css">
+
+</style>
+<script type="text/_javascript_" charset="utf-8">
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    function log(m) {
+        document.getElementById('results').innerHTML += m + '<br>';
+    }
+
+    function testQueries()
+    {
+        var queries = [
+            "(pointer)",
+            "(Pointer)",
+            "(pointer:none)",
+            "(pointer:coarse)",
+            "(pointer:coARse)",
+            "(pointer:bogusvalue)",
+            "(pointer:fine)",
+            "(hover)",
+            "(hover:0)",
+            "(hover:1)",
+            "(hover:bogusvalue)" ];
+        for (var index=0; index < queries.length; index++) {
+            log("Query &quot;" + queries[index] + "&quot: " +
+                window.matchMedia(queries[index]).matches);
+        }
+    }
+
+    function runTests()
+    {
+        log("------------- default configuration -------------");
+        testQueries();
+
+        if (window.internals) {
+            internals.settings.setDeviceSupportsTouch(true);
+
+            log("------------- with touch screen -------------");
+            testQueries();
+        }
+    }
+
+</script>
+</head>
+<body _onload_="runTests()">
+    <p>Test the <a href="" and
+    <a href="" media features.
+    See <a href="" 87403</a> for details.</p>
+
+    <div id="results">
+    </div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (119044 => 119045)


--- trunk/Source/WebCore/ChangeLog	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/ChangeLog	2012-05-31 03:56:21 UTC (rev 119045)
@@ -1,3 +1,40 @@
+2012-05-30  Rick Byers  <rby...@chromium.org>
+
+        [chromium] Implement pointer and hover CSS media features
+        https://bugs.webkit.org/show_bug.cgi?id=87403
+
+        Reviewed by Adam Barth.
+
+        Add initial support for the pointer and hover media features as defined
+        here:
+        http://dev.w3.org/csswg/css4-mediaqueries/#pointer
+        http://dev.w3.org/csswg/css4-mediaqueries/#hover
+
+        For now this only supports the case where we know a touch screen is
+        available (currently known only for the chromium port on certain
+        platforms).  All other cases continue to behave exactly as if the media
+        feature isn't supported.
+
+        Tests: fast/media/mq-pointer.html
+
+        * css/CSSValueKeywords.in:
+        * css/MediaFeatureNames.h:
+        (MediaFeatureNames):
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::getLeastCapablePrimaryPointerDeviceType):
+        (WebCore):
+        (WebCore::hoverMediaFeatureEval):
+        (WebCore::pointerMediaFeatureEval):
+
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::InternalSettings):
+        (WebCore::InternalSettings::restoreTo):
+        (WebCore::InternalSettings::setDeviceSupportsTouch):
+        (WebCore):
+        * testing/InternalSettings.h:
+        (InternalSettings):
+        * testing/InternalSettings.idl:
+
 2012-05-30  Julien Chaffraix  <jchaffr...@webkit.org>
 
         Add an helper function to get the style for a cell's flow computation

Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (119044 => 119045)


--- trunk/Source/WebCore/css/CSSValueKeywords.in	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in	2012-05-31 03:56:21 UTC (rev 119045)
@@ -905,6 +905,11 @@
 // -webkit-line-align
 edges
 
+// (pointer:) media feature
+// none
+coarse
+fine
+
 #if defined(ENABLE_CSS_FILTERS) && ENABLE_CSS_FILTERS
 // -webkit-filter
 #if defined(ENABLE_CSS_SHADERS) && ENABLE_CSS_SHADERS

Modified: trunk/Source/WebCore/css/MediaFeatureNames.h (119044 => 119045)


--- trunk/Source/WebCore/css/MediaFeatureNames.h	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/css/MediaFeatureNames.h	2012-05-31 03:56:21 UTC (rev 119045)
@@ -30,6 +30,7 @@
     macro(grid, "grid") \
     macro(monochrome, "monochrome") \
     macro(height, "height") \
+    macro(hover, "hover") \
     macro(width, "width") \
     macro(orientation, "orientation") \
     macro(aspect_ratio, "aspect-ratio") \
@@ -55,6 +56,7 @@
     macro(min_height, "min-height") \
     macro(min_monochrome, "min-monochrome") \
     macro(min_width, "min-width") \
+    macro(pointer, "pointer") \
     macro(transform_2d, "-webkit-transform-2d") \
     macro(transform_3d, "-webkit-transform-3d") \
     macro(transition, "-webkit-transition") \

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (119044 => 119045)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-05-31 03:56:21 UTC (rev 119045)
@@ -45,6 +45,7 @@
 #include "PlatformScreen.h"
 #include "RenderView.h"
 #include "RenderStyle.h"
+#include "Settings.h"
 #include "StyleResolver.h"
 #include <wtf/HashMap.h>
 
@@ -536,6 +537,66 @@
     return Page::stringToViewMode(static_cast<CSSPrimitiveValue*>(value)->getStringValue()) == frame->page()->viewMode();
 }
 
+enum PointerDeviceType { TouchPointer, MousePointer, NoPointer, UnknownPointer };
+
+static PointerDeviceType leastCapablePrimaryPointerDeviceType(Frame* frame)
+{
+    if (frame->settings()->deviceSupportsTouch())
+        return TouchPointer;
+
+    // FIXME: We should also try to determine if we know we have a mouse.
+    // When we do this, we'll also need to differentiate between known not to
+    // have mouse or touch screen (NoPointer) and unknown (UnknownPointer).
+    // We could also take into account other preferences like accessibility
+    // settings to decide which of the available pointers should be considered
+    // "primary".
+
+    return UnknownPointer;
+}
+
+static bool hoverMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, MediaFeaturePrefix)
+{
+    PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame);
+
+    // If we're on a port that hasn't explicitly opted into providing pointer device information
+    // (or otherwise can't be confident in the pointer hardware available), then behave exactly
+    // as if this feature feature isn't supported.
+    if (pointer == UnknownPointer)
+        return false;
+
+    float number = 1;
+    if (value) {
+        if (!numberValue(value, number))
+            return false;
+    }
+
+    return (pointer == NoPointer && !number)
+        || (pointer == TouchPointer && !number)
+        || (pointer == MousePointer && number == 1);
+}
+
+static bool pointerMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, MediaFeaturePrefix)
+{
+    PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame);
+
+    // If we're on a port that hasn't explicitly opted into providing pointer device information
+    // (or otherwise can't be confident in the pointer hardware available), then behave exactly
+    // as if this feature feature isn't supported.
+    if (pointer == UnknownPointer)
+        return false;
+
+    if (!value)
+        return pointer != NoPointer;
+
+    if (!value->isPrimitiveValue())
+        return false;
+
+    String str = static_cast<CSSPrimitiveValue*>(value)->getStringValue();
+    return (pointer == NoPointer && str == "none")
+        || (pointer == TouchPointer && str == "coarse")
+        || (pointer == MousePointer && str == "fine");
+}
+
 static void createFunctionMap()
 {
     // Create the table.

Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (119044 => 119045)


--- trunk/Source/WebCore/testing/InternalSettings.cpp	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp	2012-05-31 03:56:21 UTC (rev 119045)
@@ -105,6 +105,7 @@
     , m_originalJavaScriptProfilingEnabled(page() && page()->inspectorController() && page()->inspectorController()->profilerEnabled())
 #endif
     , m_originalWindowFocusRestricted(settings()->windowFocusRestricted())
+    , m_originalDeviceSupportsTouch(settings()->deviceSupportsTouch())
 {
 }
 
@@ -124,6 +125,7 @@
         page()->inspectorController()->setProfilerEnabled(m_originalJavaScriptProfilingEnabled);
 #endif
     settings->setWindowFocusRestricted(m_originalWindowFocusRestricted);
+    settings->setDeviceSupportsTouch(m_originalDeviceSupportsTouch);
 }
 
 Settings* InternalSettings::settings() const
@@ -260,6 +262,12 @@
 #endif
 }
 
+void InternalSettings::setDeviceSupportsTouch(bool enabled, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setDeviceSupportsTouch(enabled);
+}
+
 typedef void (Settings::*SetFontFamilyFunction)(const AtomicString&, UScriptCode);
 static void setFontFamily(Settings* settings, const String& family, const String& script, SetFontFamilyFunction setter)
 {

Modified: trunk/Source/WebCore/testing/InternalSettings.h (119044 => 119045)


--- trunk/Source/WebCore/testing/InternalSettings.h	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/testing/InternalSettings.h	2012-05-31 03:56:21 UTC (rev 119045)
@@ -63,6 +63,7 @@
     void setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode&);
     void setPerTileDrawingEnabled(bool enabled, ExceptionCode&);
     void setTouchEventEmulationEnabled(bool enabled, ExceptionCode&);
+    void setDeviceSupportsTouch(bool enabled, ExceptionCode&);
     void setShadowDOMEnabled(bool enabled, ExceptionCode&);
     void setStandardFontFamily(const String& family, const String& script, ExceptionCode&);
     void setSerifFontFamily(const String& family, const String& script, ExceptionCode&);
@@ -104,6 +105,7 @@
     bool m_originalJavaScriptProfilingEnabled;
 #endif
     bool m_originalWindowFocusRestricted;
+    bool m_originalDeviceSupportsTouch;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/InternalSettings.idl (119044 => 119045)


--- trunk/Source/WebCore/testing/InternalSettings.idl	2012-05-31 03:55:01 UTC (rev 119044)
+++ trunk/Source/WebCore/testing/InternalSettings.idl	2012-05-31 03:56:21 UTC (rev 119045)
@@ -41,6 +41,7 @@
         boolean unifiedTextCheckingEnabled() raises (DOMException);
         void setPageScaleFactor(in float scaleFactor, in long x, in long y) raises(DOMException);
         void setTouchEventEmulationEnabled(in boolean enabled) raises(DOMException);
+        void setDeviceSupportsTouch(in boolean enabled) raises(DOMException);
         void setShadowDOMEnabled(in boolean enabled) raises(DOMException);
         void setStandardFontFamily(in DOMString family, in DOMString script) raises(DOMException);
         void setSerifFontFamily(in DOMString family, in DOMString script) raises(DOMException);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to