REGRESSION(r196265): WKWebView fires mouseover, mouseenter, and mouseleave events...
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2018 22:05:49 +0000 (22:05 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2018 22:05:49 +0000 (22:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187545
<rdar://problem/42401575>

Reviewed by Ryosuke Niwa.

Source/WebCore:

When the window is not active, we should only update the scrollbar for mouse events. GTK
apps have different expectation on this behavior.

Test: fast/events/inactive-window-no-mouse-event.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleMouseMoveEvent):
(WebCore::EventHandler::shouldSendMouseEventsToInactiveWindows const):
* page/EventHandler.h:

LayoutTests:

* TestExpectations:
* fast/events/inactive-window-no-mouse-event-expected.txt: Added.
* fast/events/inactive-window-no-mouse-event.html: Added.
* platform/mac-wk2/TestExpectations:

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

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/events/inactive-window-no-mouse-event-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/inactive-window-no-mouse-event.html [new file with mode: 0644]
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h

index c8b0772..f31fa63 100644 (file)
@@ -1,3 +1,16 @@
+2018-09-20  Sihui Liu  <sihui_liu@apple.com>
+
+        REGRESSION(r196265): WKWebView fires mouseover, mouseenter, and mouseleave events even when it's in a background window
+        https://bugs.webkit.org/show_bug.cgi?id=187545
+        <rdar://problem/42401575>
+
+        Reviewed by Ryosuke Niwa.
+
+        * TestExpectations:
+        * fast/events/inactive-window-no-mouse-event-expected.txt: Added.
+        * fast/events/inactive-window-no-mouse-event.html: Added.
+        * platform/mac-wk2/TestExpectations:
+
 2018-09-20  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         [Win] TestRunner::queueLoad() fails to generate correct url for some urls.
index 845020d..c916400 100644 (file)
@@ -404,6 +404,9 @@ fast/canvas/webgl/context-update-on-display-configuration.html [ Skip ]
 
 fast/misc/valid-primary-screen-displayID.html [ Skip ]
 
+# This test currently only works for mac-wk2
+fast/events/inactive-window-no-mouse-event.html [ Skip ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific tests.
 #//////////////////////////////////////////////////////////////////////////////////////////
diff --git a/LayoutTests/fast/events/inactive-window-no-mouse-event-expected.txt b/LayoutTests/fast/events/inactive-window-no-mouse-event-expected.txt
new file mode 100644 (file)
index 0000000..732fffa
--- /dev/null
@@ -0,0 +1,13 @@
+This test verifies no mouseenter, mouseleave or mousemove event sent to web page when window is inactive.
+To manually test, open another app to make window visible but inactive, then move mouse to red box area. On success, you should not see color change.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS mousemoveDetected is false
+PASS mouseenterCount is 0
+PASS mouseleaveCount is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/inactive-window-no-mouse-event.html b/LayoutTests/fast/events/inactive-window-no-mouse-event.html
new file mode 100644 (file)
index 0000000..2d9e625
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="around" style="width:600px; height:600px; top:0px; left:0px; background-color:blue; position:absolute"></div>
+<div id="target" style="width:200px; height:200px; top:200px; left:200px; background-color:red; position:absolute"></div>
+
+<script src="../../resources/js-test.js"></script>
+<script>
+jsTestIsAsync = true;
+
+var mouseenterCount = 0;
+var mouseleaveCount = 0;
+var mousemoveDetected = false;
+
+var target = document.getElementById("target");
+var around = document.getElementById("around");
+target.addEventListener('mouseenter',() => {
+    document.getElementById("target").style.backgroundColor = "yellow";
+
+    debug("Mouse enters target.");
+       mouseenterCount++;
+});
+target.addEventListener('mouseleave',() => {
+    document.getElementById("target").style.backgroundColor = "red";
+
+    debug("Mouse leaves target.");
+    mouseleaveCount++;
+});
+around.addEventListener('mousemove',() => {
+
+    shouldBeFalse("mousemoveDetected");
+    shouldBe("mouseenterCount", "0");
+    shouldBe("mouseleaveCount", "0");
+
+    mousemoveDetected = true;
+
+    finishJSTest();
+});
+
+description("This test verifies no mouseenter, mouseleave or mousemove event sent to web page when window is inactive.<br>\
+    To manually test, open another app to make window visible but inactive, then move mouse to red box area. On success, you should not see color change.");
+
+if (window.internals)
+    window.internals.setPageIsFocusedAndActive(false);
+
+if (window.eventSender) {
+    left = target.offsetLeft;
+    top = target.offsetTop;
+
+    eventSender.mouseMoveTo(around.offsetLeft, around.offsetTop);
+    eventSender.mouseMoveTo(target.offsetLeft, target.offsetTop);
+    eventSender.mouseMoveTo(around.offsetLeft, around.offsetTop);
+}
+
+setTimeout(() => {
+    if (window.internals)
+        window.internals.setPageIsFocusedAndActive(true);
+
+    if (window.eventSender) 
+        eventSender.mouseMoveTo(around.offsetLeft + 1, around.offsetTop + 1);
+}, 200);
+
+</script>
+</body>
+</html>
index fbf1571..c808fc9 100644 (file)
@@ -62,6 +62,8 @@ webkit.org/b/187773 http/tests/webAPIStatistics [ Pass ]
 webkit.org/b/184569 storage/indexeddb/modern/transactions-stop-on-navigation.html [ Pass Failure ]
 
 
+fast/events/inactive-window-no-mouse-event.html [ Pass ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
 #//////////////////////////////////////////////////////////////////////////////////////////
index cf3d57d..b8c0724 100644 (file)
@@ -1,3 +1,21 @@
+2018-09-20  Sihui Liu  <sihui_liu@apple.com>
+
+        REGRESSION(r196265): WKWebView fires mouseover, mouseenter, and mouseleave events even when it's in a background window
+        https://bugs.webkit.org/show_bug.cgi?id=187545
+        <rdar://problem/42401575>
+
+        Reviewed by Ryosuke Niwa.
+
+        When the window is not active, we should only update the scrollbar for mouse events. GTK
+        apps have different expectation on this behavior.
+
+        Test: fast/events/inactive-window-no-mouse-event.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleMouseMoveEvent):
+        (WebCore::EventHandler::shouldSendMouseEventsToInactiveWindows const):
+        * page/EventHandler.h:
+
 2018-09-20  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed, rolling out r235976.
index d4961bd..b86cfca 100644 (file)
@@ -1965,7 +1965,9 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& platformMouseE
             scrollbar->mouseMoved(platformMouseEvent); // Handle hover effects on platforms that support visual feedback on scrollbar hovering.
 #endif
         if (onlyUpdateScrollbars) {
-            updateMouseEventTargetNode(mouseEvent.targetNode(), platformMouseEvent, true);
+            if (shouldSendMouseEventsToInactiveWindows())
+                updateMouseEventTargetNode(mouseEvent.targetNode(), platformMouseEvent, true);
+
             return true;
         }
     }
@@ -2008,6 +2010,14 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& platformMouseE
     return swallowEvent;
 }
 
+bool EventHandler::shouldSendMouseEventsToInactiveWindows() const
+{
+#if PLATFORM(GTK)
+    return true;
+#endif
+    return false;
+}
+
 void EventHandler::invalidateClick()
 {
     m_clickCount = 0;
index 75ad268..c88a649 100644 (file)
@@ -493,6 +493,8 @@ private:
     void clearOrScheduleClearingLatchedStateIfNeeded(const PlatformWheelEvent&);
     void clearLatchedState();
 
+    bool shouldSendMouseEventsToInactiveWindows() const;
+
     Frame& m_frame;
 
     bool m_mousePressed { false };