Changeset 245788 in webkit


Ignore:
Timestamp:
May 27, 2019 1:34:35 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

Touch support is reported even when the device doesn't have a touch screen
https://bugs.webkit.org/show_bug.cgi?id=139681

Reviewed by Michael Catanzaro.

Source/WebCore:

Add screenHasTouchDevice() and screenIsTouchPrimaryInputDevice() to PlatformScreen and use it to decide whether
to expose touch events functionality or not.

  • bindings/js/WebCoreBuiltinNames.h:
  • css/MediaQueryEvaluator.cpp:

(WebCore::hoverEvaluate): Use screenIsTouchPrimaryInputDevice() when touch events are enabled at build time.
(WebCore::anyHoverEvaluate): Use screenHasTouchDevice() when touch events are enabled at build time.
(WebCore::pointerEvaluate): Use screenIsTouchPrimaryInputDevice() when touch events are enabled at build time.
(WebCore::anyPointerEvaluate): Use screenHasTouchDevice() when touch events are enabled at build time.

  • dom/GlobalEventHandlers.idl: Make touch event attributes enabled at runtime.
  • page/RuntimeEnabledFeatures.cpp:

(WebCore::RuntimeEnabledFeatures::touchEventsEnabled const): Return whether touch events are enabled.

  • page/RuntimeEnabledFeatures.h:

(WebCore::RuntimeEnabledFeatures::setTouchEventsEnabled): Force touch events to be enabled or disabled.

  • platform/PlatformScreen.h:

(WebCore::screenHasTouchDevice): Just return true when touch events are enabled at build time for non-gtk ports.
(WebCore::screenIsTouchPrimaryInputDevice): Ditto.

  • platform/gtk/PlatformScreenGtk.cpp:

(WebCore::screenHasTouchDevice):
(WebCore::screenIsTouchPrimaryInputDevice):
(WebCore::isTouchDevice):
(WebCore::deviceAddedCallback):
(WebCore::deviceRemovedCallback):

LayoutTests:

Remove expectations for tests that are passing now.

  • platform/gtk/TestExpectations:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245784 r245788  
     12019-05-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Touch support is reported even when the device doesn't have a touch screen
     4        https://bugs.webkit.org/show_bug.cgi?id=139681
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Remove expectations for tests that are passing now.
     9
     10        * platform/gtk/TestExpectations:
     11
    1122019-05-26  John Wilander  <wilander@apple.com>
    213
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r245623 r245788  
    821821webkit.org/b/141423 fast/css/getComputedStyle/computed-style-font.html [ Failure ]
    822822
    823 #Pointer and hover media queries.
    824 webkit.org/b/141466 fast/media/mq-any-hover-matchMedia.html [ Failure ]
    825 webkit.org/b/141466 fast/media/mq-any-hover-styling.html [ Failure ]
    826 webkit.org/b/141466 fast/media/mq-any-pointer-matchMedia.html [ Failure ]
    827 webkit.org/b/141466 fast/media/mq-any-pointer-styling.html [ Failure ]
    828 webkit.org/b/141466 fast/media/mq-hover-matchMedia.html [ Failure ]
    829 webkit.org/b/141466 fast/media/mq-hover-styling.html [ Failure ]
    830 webkit.org/b/141466 fast/media/mq-pointer-matchMedia.html [ Failure ]
    831 webkit.org/b/141466 fast/media/mq-pointer-styling.html [ Failure ]
    832 webkit.org/b/141466 fast/media/mq-pointer.html [ Failure ]
    833 
    834823webkit.org/b/116259 http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html [ Failure ]
    835824
  • trunk/Source/WebCore/ChangeLog

    r245787 r245788  
     12019-05-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Touch support is reported even when the device doesn't have a touch screen
     4        https://bugs.webkit.org/show_bug.cgi?id=139681
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add screenHasTouchDevice() and screenIsTouchPrimaryInputDevice() to PlatformScreen and use it to decide whether
     9        to expose touch events functionality or not.
     10
     11        * bindings/js/WebCoreBuiltinNames.h:
     12        * css/MediaQueryEvaluator.cpp:
     13        (WebCore::hoverEvaluate): Use screenIsTouchPrimaryInputDevice() when touch events are enabled at build time.
     14        (WebCore::anyHoverEvaluate): Use screenHasTouchDevice() when touch events are enabled at build time.
     15        (WebCore::pointerEvaluate): Use screenIsTouchPrimaryInputDevice() when touch events are enabled at build time.
     16        (WebCore::anyPointerEvaluate): Use screenHasTouchDevice() when touch events are enabled at build time.
     17        * dom/GlobalEventHandlers.idl: Make touch event attributes enabled at runtime.
     18        * page/RuntimeEnabledFeatures.cpp:
     19        (WebCore::RuntimeEnabledFeatures::touchEventsEnabled const): Return whether touch events are enabled.
     20        * page/RuntimeEnabledFeatures.h:
     21        (WebCore::RuntimeEnabledFeatures::setTouchEventsEnabled): Force touch events to be enabled or disabled.
     22        * platform/PlatformScreen.h:
     23        (WebCore::screenHasTouchDevice): Just return true when touch events are enabled at build time for non-gtk ports.
     24        (WebCore::screenIsTouchPrimaryInputDevice): Ditto.
     25        * platform/gtk/PlatformScreenGtk.cpp:
     26        (WebCore::screenHasTouchDevice):
     27        (WebCore::screenIsTouchPrimaryInputDevice):
     28        (WebCore::isTouchDevice):
     29        (WebCore::deviceAddedCallback):
     30        (WebCore::deviceRemovedCallback):
     31
    1322019-05-26  Simon Fraser  <simon.fraser@apple.com>
    233
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r244856 r245788  
    277277    macro(mediaStreamTrackConstraints) \
    278278    macro(openDatabase) \
     279    macro(ontouchcancel) \
     280    macro(ontouchend) \
     281    macro(ontouchmove) \
     282    macro(ontouchstart) \
     283    macro(ontouchforcechange) \
    279284    macro(onvrdisplayactivate) \
    280285    macro(onvrdisplayblur) \
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r240892 r245788  
    694694    if (!is<CSSPrimitiveValue>(value)) {
    695695#if ENABLE(TOUCH_EVENTS)
    696         return false;
     696        return !screenIsTouchPrimaryInputDevice();
    697697#else
    698698        return true;
     
    702702    auto keyword = downcast<CSSPrimitiveValue>(*value).valueID();
    703703#if ENABLE(TOUCH_EVENTS)
    704     return keyword == CSSValueNone;
     704    if (screenIsTouchPrimaryInputDevice())
     705        return keyword == CSSValueNone;
     706#endif
     707    return keyword == CSSValueHover;
     708}
     709
     710static bool anyHoverEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
     711{
     712    if (!is<CSSPrimitiveValue>(value)) {
     713#if ENABLE(TOUCH_EVENTS)
     714        return !screenHasTouchDevice();
    705715#else
    706     return keyword == CSSValueHover;
    707 #endif
    708 }
    709 
    710 static bool anyHoverEvaluate(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame& frame, MediaFeaturePrefix prefix)
    711 {
    712     return hoverEvaluate(value, cssToLengthConversionData, frame, prefix);
    713 }
    714 
    715 static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
    716 {
    717     if (!is<CSSPrimitiveValue>(value))
    718         return true;
     716        return true;
     717#endif
     718    }
    719719
    720720    auto keyword = downcast<CSSPrimitiveValue>(*value).valueID();
    721721#if ENABLE(TOUCH_EVENTS)
    722     return keyword == CSSValueCoarse;
    723 #else
     722    if (screenHasTouchDevice())
     723        return keyword == CSSValueNone;
     724#endif
     725    return keyword == CSSValueHover;
     726}
     727
     728static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
     729{
     730    if (!is<CSSPrimitiveValue>(value))
     731        return true;
     732
     733    auto keyword = downcast<CSSPrimitiveValue>(*value).valueID();
     734#if ENABLE(TOUCH_EVENTS)
     735    if (screenIsTouchPrimaryInputDevice())
     736        return keyword == CSSValueCoarse;
     737#endif
    724738    return keyword == CSSValueFine;
    725 #endif
    726 }
    727 
    728 static bool anyPointerEvaluate(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame& frame, MediaFeaturePrefix prefix)
    729 {
    730     return pointerEvaluate(value, cssToLengthConversionData, frame, prefix);
     739}
     740
     741static bool anyPointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
     742{
     743    if (!is<CSSPrimitiveValue>(value))
     744        return true;
     745
     746    auto keyword = downcast<CSSPrimitiveValue>(*value).valueID();
     747#if ENABLE(TOUCH_EVENTS)
     748    if (screenHasTouchDevice())
     749        return keyword == CSSValueCoarse;
     750#endif
     751    return keyword == CSSValueFine;
    731752}
    732753
  • trunk/Source/WebCore/dom/GlobalEventHandlers.idl

    r244421 r245788  
    124124    [NotEnumerable] attribute EventHandler onsearch;
    125125    [NotEnumerable] attribute EventHandler onwheel;
    126     [NotEnumerable, Conditional=TOUCH_EVENTS] attribute EventHandler ontouchcancel;
    127     [NotEnumerable, Conditional=TOUCH_EVENTS] attribute EventHandler ontouchend;
    128     [NotEnumerable, Conditional=TOUCH_EVENTS] attribute EventHandler ontouchmove;
    129     [NotEnumerable, Conditional=TOUCH_EVENTS] attribute EventHandler ontouchstart;
    130     [NotEnumerable, Conditional=TOUCH_EVENTS] attribute EventHandler ontouchforcechange;
     126    [NotEnumerable, Conditional=TOUCH_EVENTS, EnabledAtRuntime=TouchEvents] attribute EventHandler ontouchcancel;
     127    [NotEnumerable, Conditional=TOUCH_EVENTS, EnabledAtRuntime=TouchEvents] attribute EventHandler ontouchend;
     128    [NotEnumerable, Conditional=TOUCH_EVENTS, EnabledAtRuntime=TouchEvents] attribute EventHandler ontouchmove;
     129    [NotEnumerable, Conditional=TOUCH_EVENTS, EnabledAtRuntime=TouchEvents] attribute EventHandler ontouchstart;
     130    [NotEnumerable, Conditional=TOUCH_EVENTS, EnabledAtRuntime=TouchEvents] attribute EventHandler ontouchforcechange;
    131131    [NotEnumerable, Conditional=MOUSE_FORCE_EVENTS] attribute EventHandler onwebkitmouseforcechanged;
    132132    [NotEnumerable, Conditional=MOUSE_FORCE_EVENTS] attribute EventHandler onwebkitmouseforcedown;
  • trunk/Source/WebCore/page/RuntimeEnabledFeatures.cpp

    r237262 r245788  
    3434
    3535#include "MediaPlayer.h"
     36#include "PlatformScreen.h"
    3637#include <JavaScriptCore/Options.h>
    3738#include <wtf/NeverDestroyed.h>
     
    6465}
    6566
     67#if ENABLE(TOUCH_EVENTS)
     68bool RuntimeEnabledFeatures::touchEventsEnabled() const
     69{
     70    return m_touchEventsEnabled.valueOr(screenHasTouchDevice());
     71}
     72#endif
     73
    6674} // namespace WebCore
  • trunk/Source/WebCore/page/RuntimeEnabledFeatures.h

    r245491 r245788  
    348348    bool mouseEventsSimulationEnabled() const { return m_mouseEventsSimulationEnabled; }
    349349    void setMouseEventsSimulationEnabled(bool isEnabled) { m_mouseEventsSimulationEnabled = isEnabled; }
     350    bool touchEventsEnabled() const;
     351    void setTouchEventsEnabled(bool isEnabled) { m_touchEventsEnabled = isEnabled; }
    350352#endif
    351353   
     
    532534#if ENABLE(TOUCH_EVENTS)
    533535    bool m_mouseEventsSimulationEnabled { false };
     536    Optional<bool> m_touchEventsEnabled;
    534537#endif
    535538
  • trunk/Source/WebCore/platform/PlatformScreen.h

    r237266 r245788  
    123123#endif
    124124
     125#if ENABLE(TOUCH_EVENTS)
     126#if PLATFORM(GTK) || PLATFORM(WPE)
     127bool screenHasTouchDevice();
     128bool screenIsTouchPrimaryInputDevice();
     129#else
     130bool screenHasTouchDevice() { return true; }
     131bool screenIsTouchPrimaryInputDevice() { return true; }
     132#endif
     133#endif
     134
    125135} // namespace WebCore
  • trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp

    r224872 r245788  
    4242#include <gtk/gtk.h>
    4343#include <wtf/HashMap.h>
     44#include <wtf/HashSet.h>
    4445#include <wtf/NeverDestroyed.h>
     46#include <wtf/glib/GUniquePtr.h>
    4547
    4648namespace WebCore {
     
    196198}
    197199
     200#if ENABLE(TOUCH_EVENTS)
     201#ifdef GTK_API_VERSION_2
     202bool screenHasTouchDevice()
     203{
     204    return false;
     205}
     206
     207bool screenIsTouchPrimaryInputDevice()
     208{
     209    return false;
     210}
     211#else // GTK_API_VERSION_2
     212#if !GTK_CHECK_VERSION(3, 20, 0)
     213static void deviceAddedCallback(GdkDeviceManager*, GdkDevice*);
     214static void deviceRemovedCallback(GdkDeviceManager*, GdkDevice*);
     215
     216static HashSet<GdkDevice*>& touchDevices()
     217{
     218    static LazyNeverDestroyed<HashSet<GdkDevice*>> touchDeviceSet;
     219    static std::once_flag onceKey;
     220    std::call_once(onceKey, [] {
     221        touchDeviceSet.construct();
     222
     223        auto* display = gdk_display_get_default();
     224        if (!display)
     225            return;
     226
     227        auto* deviceManager = gdk_display_get_device_manager(display);
     228        if (!deviceManager)
     229            return;
     230
     231        GUniquePtr<GList> devices(gdk_device_manager_list_devices(deviceManager, GDK_DEVICE_TYPE_SLAVE));
     232        for (GList* it = devices.get(); it; it = g_list_next(it)) {
     233            auto* device = GDK_DEVICE(it->data);
     234            if (gdk_device_get_source(device) == GDK_SOURCE_TOUCHSCREEN)
     235                touchDeviceSet->add(device);
     236        }
     237
     238        g_signal_connect(deviceManager, "device-added", G_CALLBACK(deviceAddedCallback), nullptr);
     239        g_signal_connect(deviceManager, "device-removed", G_CALLBACK(deviceRemovedCallback), nullptr);
     240    });
     241
     242    return touchDeviceSet;
     243}
     244
     245static inline bool isTouchDevice(GdkDevice* device)
     246{
     247    return gdk_device_get_device_type(device) == GDK_DEVICE_TYPE_SLAVE && gdk_device_get_source(device) == GDK_SOURCE_TOUCHSCREEN;
     248}
     249
     250static void deviceAddedCallback(GdkDeviceManager*, GdkDevice* device)
     251{
     252    if (!isTouchDevice(device))
     253        return;
     254
     255    ASSERT(!touchDevices().contains(device));
     256    touchDevices().add(device);
     257}
     258
     259static void deviceRemovedCallback(GdkDeviceManager*, GdkDevice* device)
     260{
     261    if (!isTouchDevice(device))
     262        return;
     263
     264    ASSERT(touchDevices().contains(device));
     265    touchDevices().remove(device);
     266}
     267#endif // !GTK_CHECK_VERSION(3, 20, 0)
     268
     269bool screenHasTouchDevice()
     270{
     271#if GTK_CHECK_VERSION(3, 20, 0)
     272    auto* display = gdk_display_get_default();
     273    if (!display)
     274        return true;
     275
     276    auto* seat = gdk_display_get_default_seat(display);
     277    return seat ? gdk_seat_get_capabilities(seat) & GDK_SEAT_CAPABILITY_TOUCH : true;
     278#else
     279    return !touchDevices().isEmpty();
     280#endif
     281}
     282
     283bool screenIsTouchPrimaryInputDevice()
     284{
     285    auto* display = gdk_display_get_default();
     286    if (!display)
     287        return true;
     288
     289#if GTK_CHECK_VERSION(3, 20, 0)
     290    auto* seat = gdk_display_get_default_seat(display);
     291    if (!seat)
     292        return true;
     293
     294    auto* device = gdk_seat_get_pointer(seat);
     295#else
     296    auto* deviceManager = gdk_display_get_device_manager(display);
     297    if (!deviceManager)
     298        return true;
     299
     300    auto* device = gdk_device_manager_get_client_pointer(deviceManager);
     301#endif
     302
     303    return device ? gdk_device_get_source(device) == GDK_SOURCE_TOUCHSCREEN : true;
     304}
     305#endif // !GTK_API_VERSION_2
     306#endif // ENABLE(TOUCH_EVENTS)
     307
    198308} // namespace WebCore
  • trunk/Source/WebCore/platform/wpe/PlatformScreenWPE.cpp

    r239670 r245788  
    8787}
    8888
     89#if ENABLE(TOUCH_EVENTS)
     90bool screenHasTouchDevice()
     91{
     92    return true;
     93}
     94
     95bool screenIsTouchPrimaryInputDevice()
     96{
     97    return true;
     98}
     99#endif
     100
    89101} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.