Changeset 179055 in webkit


Ignore:
Timestamp:
Jan 23, 2015 8:15:56 PM (9 years ago)
Author:
benjamin@webkit.org
Message:

Add pointer/hover media queries
https://bugs.webkit.org/show_bug.cgi?id=134822

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-01-23
Reviewed by Antti Koivisto.

Source/WebCore:

Media Queries Level 4 introduces two types of Interaction Media Features:
"pointer" and "hover". Those media features are useful for adapting the design
to the type of input:

http://dev.w3.org/csswg/mediaqueries-4/#mf-interaction

This implementation is trivial: just #ifdef the return value depending on
the support for touch events.
In the future we should move that to a client interface but let's start easy
for now.

Tests: fast/media/mq-any-hover-cssom.html

fast/media/mq-any-hover-invalid.html
fast/media/mq-any-hover-matchMedia.html
fast/media/mq-any-hover-styling.html
fast/media/mq-any-pointer-cssom.html
fast/media/mq-any-pointer-invalid.html
fast/media/mq-any-pointer-matchMedia.html
fast/media/mq-any-pointer-styling.html
fast/media/mq-hover-cssom.html
fast/media/mq-hover-invalid.html
fast/media/mq-hover-matchMedia.html
fast/media/mq-hover-styling.html
fast/media/mq-pointer-cssom.html
fast/media/mq-pointer-invalid.html
fast/media/mq-pointer-matchMedia.html
fast/media/mq-pointer-styling.html

  • css/CSSValueKeywords.in:
  • css/MediaFeatureNames.h:
  • css/MediaQueryEvaluator.cpp:

(WebCore::hoverMediaFeatureEval):
(WebCore::any_hoverMediaFeatureEval):
(WebCore::pointerMediaFeatureEval):
(WebCore::any_pointerMediaFeatureEval):
(WebCore::leastCapablePrimaryPointerDeviceType): Deleted.

  • css/MediaQueryExp.cpp:

(WebCore::featureWithCSSValueID):
(WebCore::featureWithZeroOrOne):
(WebCore::featureWithoutValue):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dispatchFakeMouseMoveEventSoon):
(WebCore::EventHandler::fakeMouseMoveEventTimerFired):

  • page/Settings.in:

LayoutTests:

  • fast/media/mq-any-hover-cssom-expected.txt: Added.
  • fast/media/mq-any-hover-cssom.html: Added.
  • fast/media/mq-any-hover-invalid-expected.txt: Added.
  • fast/media/mq-any-hover-invalid.html: Added.
  • fast/media/mq-any-hover-matchMedia-expected.txt: Added.
  • fast/media/mq-any-hover-matchMedia.html: Added.
  • fast/media/mq-any-hover-styling-expected.txt: Added.
  • fast/media/mq-any-hover-styling.html: Added.
  • fast/media/mq-any-pointer-cssom-expected.txt: Added.
  • fast/media/mq-any-pointer-cssom.html: Added.
  • fast/media/mq-any-pointer-invalid-expected.txt: Added.
  • fast/media/mq-any-pointer-invalid.html: Added.
  • fast/media/mq-any-pointer-matchMedia-expected.txt: Added.
  • fast/media/mq-any-pointer-matchMedia.html: Added.
  • fast/media/mq-any-pointer-styling-expected.txt: Added.
  • fast/media/mq-any-pointer-styling.html: Added.
  • fast/media/mq-hover-cssom-expected.txt: Added.
  • fast/media/mq-hover-cssom.html: Added.
  • fast/media/mq-hover-invalid-expected.txt: Added.
  • fast/media/mq-hover-invalid.html: Added.
  • fast/media/mq-hover-matchMedia-expected.txt: Added.
  • fast/media/mq-hover-matchMedia.html: Added.
  • fast/media/mq-hover-styling-expected.txt: Added.
  • fast/media/mq-hover-styling.html: Added.
  • fast/media/mq-pointer-cssom-expected.txt: Added.
  • fast/media/mq-pointer-cssom.html: Added.
  • fast/media/mq-pointer-expected.txt:
  • fast/media/mq-pointer-invalid-expected.txt: Added.
  • fast/media/mq-pointer-invalid.html: Added.
  • fast/media/mq-pointer-matchMedia-expected.txt: Added.
  • fast/media/mq-pointer-matchMedia.html: Added.
  • fast/media/mq-pointer-styling-expected.txt: Added.
  • fast/media/mq-pointer-styling.html: Added.
  • fast/media/mq-pointer.html:
  • platform/ios-simulator/fast/media/mq-any-hover-matchMedia-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-any-hover-styling-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-any-pointer-matchMedia-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-any-pointer-styling-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-hover-matchMedia-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-hover-styling-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-pointer-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-pointer-matchMedia-expected.txt: Added.
  • platform/ios-simulator/fast/media/mq-pointer-styling-expected.txt: Added.
Location:
trunk
Files:
42 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r179054 r179055  
     12015-01-23  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Add pointer/hover media queries
     4        https://bugs.webkit.org/show_bug.cgi?id=134822
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/media/mq-any-hover-cssom-expected.txt: Added.
     9        * fast/media/mq-any-hover-cssom.html: Added.
     10        * fast/media/mq-any-hover-invalid-expected.txt: Added.
     11        * fast/media/mq-any-hover-invalid.html: Added.
     12        * fast/media/mq-any-hover-matchMedia-expected.txt: Added.
     13        * fast/media/mq-any-hover-matchMedia.html: Added.
     14        * fast/media/mq-any-hover-styling-expected.txt: Added.
     15        * fast/media/mq-any-hover-styling.html: Added.
     16        * fast/media/mq-any-pointer-cssom-expected.txt: Added.
     17        * fast/media/mq-any-pointer-cssom.html: Added.
     18        * fast/media/mq-any-pointer-invalid-expected.txt: Added.
     19        * fast/media/mq-any-pointer-invalid.html: Added.
     20        * fast/media/mq-any-pointer-matchMedia-expected.txt: Added.
     21        * fast/media/mq-any-pointer-matchMedia.html: Added.
     22        * fast/media/mq-any-pointer-styling-expected.txt: Added.
     23        * fast/media/mq-any-pointer-styling.html: Added.
     24        * fast/media/mq-hover-cssom-expected.txt: Added.
     25        * fast/media/mq-hover-cssom.html: Added.
     26        * fast/media/mq-hover-invalid-expected.txt: Added.
     27        * fast/media/mq-hover-invalid.html: Added.
     28        * fast/media/mq-hover-matchMedia-expected.txt: Added.
     29        * fast/media/mq-hover-matchMedia.html: Added.
     30        * fast/media/mq-hover-styling-expected.txt: Added.
     31        * fast/media/mq-hover-styling.html: Added.
     32        * fast/media/mq-pointer-cssom-expected.txt: Added.
     33        * fast/media/mq-pointer-cssom.html: Added.
     34        * fast/media/mq-pointer-expected.txt:
     35        * fast/media/mq-pointer-invalid-expected.txt: Added.
     36        * fast/media/mq-pointer-invalid.html: Added.
     37        * fast/media/mq-pointer-matchMedia-expected.txt: Added.
     38        * fast/media/mq-pointer-matchMedia.html: Added.
     39        * fast/media/mq-pointer-styling-expected.txt: Added.
     40        * fast/media/mq-pointer-styling.html: Added.
     41        * fast/media/mq-pointer.html:
     42        * platform/ios-simulator/fast/media/mq-any-hover-matchMedia-expected.txt: Added.
     43        * platform/ios-simulator/fast/media/mq-any-hover-styling-expected.txt: Added.
     44        * platform/ios-simulator/fast/media/mq-any-pointer-matchMedia-expected.txt: Added.
     45        * platform/ios-simulator/fast/media/mq-any-pointer-styling-expected.txt: Added.
     46        * platform/ios-simulator/fast/media/mq-hover-matchMedia-expected.txt: Added.
     47        * platform/ios-simulator/fast/media/mq-hover-styling-expected.txt: Added.
     48        * platform/ios-simulator/fast/media/mq-pointer-expected.txt: Added.
     49        * platform/ios-simulator/fast/media/mq-pointer-matchMedia-expected.txt: Added.
     50        * platform/ios-simulator/fast/media/mq-pointer-styling-expected.txt: Added.
     51
    1522015-01-23  Commit Queue  <commit-queue@webkit.org>
    253
  • trunk/LayoutTests/fast/media/mq-pointer-expected.txt

    r119045 r179055  
    11Test the (pointer) and (hover) media features. See Bug 87403 for details.
    22
    3 ------------- default configuration -------------
    4 Query "(pointer)": false
    5 Query "(Pointer)": false
     3Query "(pointer)": true
     4Query "(Pointer)": true
    65Query "(pointer:none)": false
    76Query "(pointer:coarse)": false
    87Query "(pointer:coARse)": false
    98Query "(pointer:bogusvalue)": false
    10 Query "(pointer:fine)": false
    11 Query "(hover)": false
     9Query "(pointer:fine)": true
     10Query "(hover)": true
    1211Query "(hover:0)": false
    1312Query "(hover:1)": false
    1413Query "(hover:bogusvalue)": false
    15 ------------- with touch screen -------------
    16 Query "(pointer)": true
    17 Query "(Pointer)": true
    18 Query "(pointer:none)": false
    19 Query "(pointer:coarse)": true
    20 Query "(pointer:coARse)": true
    21 Query "(pointer:bogusvalue)": false
    22 Query "(pointer:fine)": false
    23 Query "(hover)": false
    24 Query "(hover:0)": true
    25 Query "(hover:1)": false
    26 Query "(hover:bogusvalue)": false
    2714
  • trunk/LayoutTests/fast/media/mq-pointer.html

    r122687 r179055  
    3535    function runTests()
    3636    {
    37         log("------------- default configuration -------------");
    3837        testQueries();
    39 
    40         if (window.internals) {
    41             internals.settings.setDeviceSupportsTouch(true);
    42 
    43             log("------------- with touch screen -------------");
    44             testQueries();
    45         }
    4638    }
    4739
  • trunk/Source/WebCore/ChangeLog

    r179054 r179055  
     12015-01-23  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Add pointer/hover media queries
     4        https://bugs.webkit.org/show_bug.cgi?id=134822
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Media Queries Level 4 introduces two types of Interaction Media Features:
     9        "pointer" and "hover". Those media features are useful for adapting the design
     10        to the type of input:
     11            http://dev.w3.org/csswg/mediaqueries-4/#mf-interaction
     12
     13        This implementation is trivial: just #ifdef the return value depending on
     14        the support for touch events.
     15        In the future we should move that to a client interface but let's start easy
     16        for now.
     17
     18        Tests: fast/media/mq-any-hover-cssom.html
     19               fast/media/mq-any-hover-invalid.html
     20               fast/media/mq-any-hover-matchMedia.html
     21               fast/media/mq-any-hover-styling.html
     22               fast/media/mq-any-pointer-cssom.html
     23               fast/media/mq-any-pointer-invalid.html
     24               fast/media/mq-any-pointer-matchMedia.html
     25               fast/media/mq-any-pointer-styling.html
     26               fast/media/mq-hover-cssom.html
     27               fast/media/mq-hover-invalid.html
     28               fast/media/mq-hover-matchMedia.html
     29               fast/media/mq-hover-styling.html
     30               fast/media/mq-pointer-cssom.html
     31               fast/media/mq-pointer-invalid.html
     32               fast/media/mq-pointer-matchMedia.html
     33               fast/media/mq-pointer-styling.html
     34
     35        * css/CSSValueKeywords.in:
     36        * css/MediaFeatureNames.h:
     37        * css/MediaQueryEvaluator.cpp:
     38        (WebCore::hoverMediaFeatureEval):
     39        (WebCore::any_hoverMediaFeatureEval):
     40        (WebCore::pointerMediaFeatureEval):
     41        (WebCore::any_pointerMediaFeatureEval):
     42        (WebCore::leastCapablePrimaryPointerDeviceType): Deleted.
     43        * css/MediaQueryExp.cpp:
     44        (WebCore::featureWithCSSValueID):
     45        (WebCore::featureWithZeroOrOne):
     46        (WebCore::featureWithoutValue):
     47        * page/EventHandler.cpp:
     48        (WebCore::EventHandler::dispatchFakeMouseMoveEventSoon):
     49        (WebCore::EventHandler::fakeMouseMoveEventTimerFired):
     50        * page/Settings.in:
     51
    1522015-01-23  Commit Queue  <commit-queue@webkit.org>
    253
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r178213 r179055  
    10311031fine
    10321032
     1033// (hover:) media feature.
     1034// none
     1035hover
     1036on-demand
     1037
    10331038// blend modes
    10341039// normal
  • trunk/Source/WebCore/css/MediaFeatureNames.h

    r174901 r179055  
    3333
    3434#define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
     35    macro(any_hover, "any-hover") \
     36    macro(any_pointer, "any-pointer") \
    3537    macro(color, "color") \
    3638    macro(color_index, "color-index") \
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r174901 r179055  
    648648}
    649649
    650 enum PointerDeviceType { TouchPointer, MousePointer, NoPointer, UnknownPointer };
    651 
    652 static PointerDeviceType leastCapablePrimaryPointerDeviceType(Frame* frame)
    653 {
    654     if (frame->settings().deviceSupportsTouch())
    655         return TouchPointer;
    656 
    657     // FIXME: We should also try to determine if we know we have a mouse.
    658     // When we do this, we'll also need to differentiate between known not to
    659     // have mouse or touch screen (NoPointer) and unknown (UnknownPointer).
    660     // We could also take into account other preferences like accessibility
    661     // settings to decide which of the available pointers should be considered
    662     // "primary".
    663 
    664     return UnknownPointer;
    665 }
    666 
    667 static bool hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix)
    668 {
    669     PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame);
    670 
    671     // If we're on a port that hasn't explicitly opted into providing pointer device information
    672     // (or otherwise can't be confident in the pointer hardware available), then behave exactly
    673     // as if this feature feature isn't supported.
    674     if (pointer == UnknownPointer)
    675         return false;
    676 
    677     float number = 1;
    678     if (value) {
    679         if (!numberValue(value, number))
    680             return false;
    681     }
    682 
    683     return (pointer == NoPointer && !number)
    684         || (pointer == TouchPointer && !number)
    685         || (pointer == MousePointer && number == 1);
    686 }
    687 
    688 static bool pointerMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix)
    689 {
    690     PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame);
    691 
    692     // If we're on a port that hasn't explicitly opted into providing pointer device information
    693     // (or otherwise can't be confident in the pointer hardware available), then behave exactly
    694     // as if this feature feature isn't supported.
    695     if (pointer == UnknownPointer)
    696         return false;
    697 
    698     if (!value)
    699         return pointer != NoPointer;
    700 
    701     if (!is<CSSPrimitiveValue>(*value))
    702         return false;
    703 
    704     const CSSValueID id = downcast<CSSPrimitiveValue>(*value).getValueID();
    705     return (pointer == NoPointer && id == CSSValueNone)
    706         || (pointer == TouchPointer && id == CSSValueCoarse)
    707         || (pointer == MousePointer && id == CSSValueFine);
     650static bool hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
     651{
     652    if (!is<CSSPrimitiveValue>(value)) {
     653#if ENABLE(TOUCH_EVENTS)
     654        return false;
     655#else
     656        return true;
     657#endif
     658    }
     659
     660    int hoverCSSKeywordID = downcast<CSSPrimitiveValue>(*value).getValueID();
     661#if ENABLE(TOUCH_EVENTS)
     662    return hoverCSSKeywordID == CSSValueNone;
     663#else
     664    return hoverCSSKeywordID == CSSValueHover;
     665#endif
     666}
     667
     668static bool any_hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame* frame, MediaFeaturePrefix prefix)
     669{
     670    return hoverMediaFeatureEval(value, cssToLengthConversionData, frame, prefix);
     671}
     672
     673static bool pointerMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
     674{
     675    if (!is<CSSPrimitiveValue>(value))
     676        return true;
     677
     678    int pointerCSSKeywordID = downcast<CSSPrimitiveValue>(*value).getValueID();
     679#if ENABLE(TOUCH_EVENTS)
     680    return pointerCSSKeywordID == CSSValueCoarse;
     681#else
     682    return pointerCSSKeywordID == CSSValueFine;
     683#endif
     684}
     685
     686static bool any_pointerMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame* frame, MediaFeaturePrefix prefix)
     687{
     688    return pointerMediaFeatureEval(value, cssToLengthConversionData, frame, prefix);
    708689}
    709690
  • trunk/Source/WebCore/css/MediaQueryExp.cpp

    r174901 r179055  
    4848        || mediaFeature == MediaFeatureNames::view_modeMediaFeature
    4949#endif // ENABLE(VIEW_MODE_CSS_MEDIA)
     50        || mediaFeature == MediaFeatureNames::any_hoverMediaFeature
     51        || mediaFeature == MediaFeatureNames::any_pointerMediaFeature
     52        || mediaFeature == MediaFeatureNames::hoverMediaFeature
    5053        || mediaFeature == MediaFeatureNames::inverted_colorsMediaFeature
    5154        || mediaFeature == MediaFeatureNames::pointerMediaFeature;
     
    115118        return false;
    116119
    117     return mediaFeature == MediaFeatureNames::gridMediaFeature
    118         || mediaFeature == MediaFeatureNames::hoverMediaFeature;
     120    return mediaFeature == MediaFeatureNames::gridMediaFeature;
    119121}
    120122
     
    132134{
    133135    // Media features that are prefixed by min/max cannot be used without a value.
    134     return mediaFeature == MediaFeatureNames::monochromeMediaFeature
     136    return mediaFeature == MediaFeatureNames::any_hoverMediaFeature
     137        || mediaFeature == MediaFeatureNames::any_pointerMediaFeature
     138        || mediaFeature == MediaFeatureNames::monochromeMediaFeature
    135139        || mediaFeature == MediaFeatureNames::colorMediaFeature
    136140        || mediaFeature == MediaFeatureNames::color_indexMediaFeature
  • trunk/Source/WebCore/page/EventHandler.cpp

    r178715 r179055  
    28992899        return;
    29002900
    2901     if (!m_frame.settings().deviceSupportsMouse())
    2902         return;
    2903 
    29042901    if (Page* page = m_frame.page()) {
    29052902        if (!page->chrome().client().shouldDispatchFakeMouseMoveEvents())
     
    29472944{
    29482945    ASSERT(!m_mousePressed);
    2949 
    2950     if (!m_frame.settings().deviceSupportsMouse())
    2951         return;
    29522946
    29532947    FrameView* view = m_frame.view();
  • trunk/Source/WebCore/page/Settings.in

    r178949 r179055  
    148148wantsBalancedSetDefersLoadingBehavior initial=false
    149149requestAnimationFrameEnabled initial=true
    150 deviceSupportsTouch initial=false
    151 deviceSupportsMouse initial=true
    152150
    153151fixedPositionCreatesStackingContext initial=defaultFixedPositionCreatesStackingContext
Note: See TracChangeset for help on using the changeset viewer.