Video previews on shutterstock.com don't play when tapped on iPadOS
https://bugs.webkit.org/show_bug.cgi?id=209903
<rdar://problem/58844166>

Reviewed by Wenson Hsieh.

When tapping on a video preview after searching for a video on shutterstock.com, for instance on https://www.shutterstock.com/video/search/people,
we correctly enter the hover state thanks to our content observation heuristics, but the <video> preview inserted fails to play and show due to a
style rule setting a "display: none" style if the media-query "pointer: coarse" evaluates to true.

In order to improve this website's behavior on iPadOS, we add a new quirk that prevents the "pointer: coarse" media query from evaluating to true.
This new quirk, shouldPreventPointerMediaQueryFromEvaluatingToCoarse(), evaluates to true only for this this website.

* css/MediaQueryEvaluator.cpp:
(WebCore::pointerEvaluate):
* page/Quirks.cpp:
(WebCore::Quirks::shouldPreventPointerMediaQueryFromEvaluatingToCoarse const):
* page/Quirks.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259387 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 71a9094..584b6a4 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2020-04-02  Antoine Quint  <graouts@apple.com>
+
+        Video previews on shutterstock.com don't play when tapped on iPadOS
+        https://bugs.webkit.org/show_bug.cgi?id=209903
+        <rdar://problem/58844166>
+
+        Reviewed by Wenson Hsieh.
+
+        When tapping on a video preview after searching for a video on shutterstock.com, for instance on https://www.shutterstock.com/video/search/people,
+        we correctly enter the hover state thanks to our content observation heuristics, but the <video> preview inserted fails to play and show due to a
+        style rule setting a "display: none" style if the media-query "pointer: coarse" evaluates to true.
+
+        In order to improve this website's behavior on iPadOS, we add a new quirk that prevents the "pointer: coarse" media query from evaluating to true.
+        This new quirk, shouldPreventPointerMediaQueryFromEvaluatingToCoarse(), evaluates to true only for this this website.
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::pointerEvaluate):
+        * page/Quirks.cpp:
+        (WebCore::Quirks::shouldPreventPointerMediaQueryFromEvaluatingToCoarse const):
+        * page/Quirks.h:
+
 2020-04-02  youenn fablet  <youenn@apple.com>
 
         Remove synchronous termination of service workers
diff --git a/Source/WebCore/css/MediaQueryEvaluator.cpp b/Source/WebCore/css/MediaQueryEvaluator.cpp
index 2ac1630..7a3aade 100644
--- a/Source/WebCore/css/MediaQueryEvaluator.cpp
+++ b/Source/WebCore/css/MediaQueryEvaluator.cpp
@@ -43,6 +43,7 @@
 #include "NodeRenderStyle.h"
 #include "Page.h"
 #include "PlatformScreen.h"
+#include "Quirks.h"
 #include "RenderStyle.h"
 #include "RenderView.h"
 #include "Settings.h"
@@ -747,15 +748,19 @@
     return keyword == CSSValueHover;
 }
 
-static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
+static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
 {
     if (!is<CSSPrimitiveValue>(value))
         return true;
 
     auto keyword = downcast<CSSPrimitiveValue>(*value).valueID();
 #if ENABLE(TOUCH_EVENTS)
-    if (screenIsTouchPrimaryInputDevice())
-        return keyword == CSSValueCoarse;
+    if (screenIsTouchPrimaryInputDevice()) {
+        if (!frame.document() || !frame.document()->quirks().shouldPreventPointerMediaQueryFromEvaluatingToCoarse())
+            return keyword == CSSValueCoarse;
+    }
+#else
+    UNUSED_PARAM(frame);
 #endif
     return keyword == CSSValueFine;
 }
diff --git a/Source/WebCore/page/Quirks.cpp b/Source/WebCore/page/Quirks.cpp
index d978019..5f06b83 100644
--- a/Source/WebCore/page/Quirks.cpp
+++ b/Source/WebCore/page/Quirks.cpp
@@ -426,6 +426,15 @@
 
     return false;
 }
+
+bool Quirks::shouldPreventPointerMediaQueryFromEvaluatingToCoarse() const
+{
+    if (!needsQuirks())
+        return false;
+
+    auto host = m_document->topDocument().url().host();
+    return equalLettersIgnoringASCIICase(host, "shutterstock.com") || host.endsWithIgnoringASCIICase(".shutterstock.com");
+}
 #endif
 
 bool Quirks::shouldAvoidResizingWhenInputViewBoundsChange() const
diff --git a/Source/WebCore/page/Quirks.h b/Source/WebCore/page/Quirks.h
index bb737a0..d6f8574 100644
--- a/Source/WebCore/page/Quirks.h
+++ b/Source/WebCore/page/Quirks.h
@@ -56,6 +56,7 @@
     bool shouldDispatchedSimulatedMouseEventsAssumeDefaultPrevented(EventTarget*) const;
     Optional<Event::IsCancelable> simulatedMouseEventTypeForTarget(EventTarget*) const;
     bool shouldMakeTouchEventNonCancelableForTarget(EventTarget*) const;
+    bool shouldPreventPointerMediaQueryFromEvaluatingToCoarse() const;
 #endif
     bool shouldDisablePointerEventsQuirk() const;
     bool needsInputModeNoneImplicitly(const HTMLElement&) const;