One esc to exit fullscreen and pointer lock
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 01:19:03 +0000 (01:19 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 01:19:03 +0000 (01:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165416
rdar://problem/29430711

Patch by Jeremy Jones <jeremyj@apple.com> on 2016-12-07
Reviewed by Jer Noble.

Source/WebCore:

Test: pointer-lock/lock-lost-on-esc-in-fullscreen.html

When handling escape, also exit fullscreen on escape.
This also means that escape can exit fullscreen in TestRunner.

* page/EventHandler.cpp:
(WebCore::EventHandler::keyEvent):

Source/WebKit2:

Fix a crash when didLosePointerLock is not specified.

* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):

Tools:

Implement WKPageUIClientV8 for pointer lock support.
Add "escape" key support in EventSenderProxy.

* WebKitTestRunner/TestController.cpp:
(WTR::requestPointerLock):
(WTR::TestController::createOtherPage):
(WTR::TestController::createWebViewWithOptions):
* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::keyDown):

LayoutTests:

* platform/mac-wk2/TestExpectations:
* pointer-lock/lock-lost-on-esc-in-fullscreen-expected.txt: Added.
* pointer-lock/lock-lost-on-esc-in-fullscreen.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen-expected.txt [new file with mode: 0644]
LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/mac/EventSenderProxy.mm

index e7f75ab..5e69935 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        One esc to exit fullscreen and pointer lock
+        https://bugs.webkit.org/show_bug.cgi?id=165416
+        rdar://problem/29430711
+
+        Reviewed by Jer Noble.
+
+        * platform/mac-wk2/TestExpectations:
+        * pointer-lock/lock-lost-on-esc-in-fullscreen-expected.txt: Added.
+        * pointer-lock/lock-lost-on-esc-in-fullscreen.html: Added.
+
 2016-12-07  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Remove tests that depend on SVG CSS OM that has been removed
index 23c51fd..91e301a 100644 (file)
@@ -19,6 +19,8 @@ fast/media/mq-inverted-colors-live-update-in-subframes.html [ Pass ]
 fast/media/mq-monochrome-live-update.html [ Pass ]
 fast/media/mq-prefers-reduced-motion-live-update.html [ Pass ]
 
+pointer-lock/lock-lost-on-esc-in-fullscreen.html [ Pass ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
 #//////////////////////////////////////////////////////////////////////////////////////////
diff --git a/LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen-expected.txt b/LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen-expected.txt
new file mode 100644 (file)
index 0000000..3426db7
--- /dev/null
@@ -0,0 +1,19 @@
+Test that pointerlockchange event is dispatched on esc in fullscreen.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.testRunner is defined.
+PASS onwebkitfullscreenchange received after: Entered fullscreen
+     Lock targetDiv1.
+PASS onpointerlockchange received after: Lock targetDiv1.
+PASS document.pointerLockElement is targetDiv1
+Sending Escape keyDown event.
+PASS onpointerlockchange received after: Sending Escape keyDown event.
+PASS onwebkitfullscreenchange received after: Sending Escape keyDown event.
+PASS document.pointerLockElement is null
+PASS document.webkitIsFullScreen is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen.html b/LayoutTests/pointer-lock/lock-lost-on-esc-in-fullscreen.html
new file mode 100644 (file)
index 0000000..82cce50
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML><!-- webkit-test-runner [ enablePointerLock=true ] -->
+<html>
+<head>
+<script src="../http/tests/resources/js-test-pre.js"></script>
+<script src="../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
+</head>
+<body>
+<div>
+  <div id="target1"></div>
+</div>
+<script>
+    description("Test that pointerlockchange event is dispatched on esc in fullscreen.")
+    window.jsTestIsAsync = true;
+    shouldBeDefined("window.testRunner");
+
+    targetDiv1 = document.getElementById("target1");
+
+    todo = [
+        function () {
+            document.documentElement.webkitRequestFullScreen();
+            eventExpected("onwebkitfullscreenchange", "Entered fullscreen", 1, document);
+            // doNextStep called by event handler.
+        },
+        function () {
+            doNextStepWithUserGesture();
+        },
+        function () {
+            expectOnlyChangeEvent("Lock targetDiv1.");
+            targetDiv1.requestPointerLock();
+            // doNextStep called by event handler.
+        },
+        function () {
+            shouldBe("document.pointerLockElement", "targetDiv1");
+            doNextStepWithUserGesture();
+        },
+        function() {
+            document["onpointerlockchange"] = function () {
+                testPassed("onpointerlockchange" + " received after: " + "Sending Escape keyDown event.");
+            };
+            //expectOnlyChangeEvent("Lock targetDiv1.");
+            eventExpected("onwebkitfullscreenchange", "Sending Escape keyDown event.", 1, document);
+            debug("Sending Escape keyDown event.");
+            if (window.eventSender)
+                eventSender.keyDown("escape");
+        },
+        function() {
+            shouldBe("document.pointerLockElement", "null");
+            shouldBe("document.webkitIsFullScreen", "false");
+            doNextStep();
+        },
+    ];
+    doNextStepWithUserGesture();
+</script>
+<script src="../http/tests/resources/js-test-post.js"></script>
+</body>
+</html>
+
index feeb844..cbc8d57 100644 (file)
@@ -1,3 +1,19 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        One esc to exit fullscreen and pointer lock
+        https://bugs.webkit.org/show_bug.cgi?id=165416
+        rdar://problem/29430711
+
+        Reviewed by Jer Noble.
+
+        Test: pointer-lock/lock-lost-on-esc-in-fullscreen.html
+
+        When handling escape, also exit fullscreen on escape.
+        This also means that escape can exit fullscreen in TestRunner.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::keyEvent):
+
 2016-12-07  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [JSC] Drop translate phase in module loader
index cf047e1..b648385 100644 (file)
@@ -3065,13 +3065,19 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
 #if ENABLE(POINTER_LOCK)
     if (initialKeyEvent.type() == PlatformEvent::KeyDown && initialKeyEvent.windowsVirtualKeyCode() == VK_ESCAPE && m_frame.page()->pointerLockController().element()) {
         m_frame.page()->pointerLockController().requestPointerUnlockAndForceCursorVisible();
-        return true;
     }
 #endif
 
 #if ENABLE(FULLSCREEN_API)
-    if (m_frame.document()->webkitIsFullScreen() && !isKeyEventAllowedInFullScreen(initialKeyEvent))
-        return false;
+    if (m_frame.document()->webkitIsFullScreen()) {
+        if (initialKeyEvent.windowsVirtualKeyCode() == VK_ESCAPE) {
+            m_frame.document()->webkitCancelFullScreen();
+            return true;
+        }
+
+        if (!isKeyEventAllowedInFullScreen(initialKeyEvent))
+            return false;
+    }
 #endif
 
     if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) {
index 1d44b8a..2153c30 100644 (file)
@@ -1,3 +1,16 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        One esc to exit fullscreen and pointer lock
+        https://bugs.webkit.org/show_bug.cgi?id=165416
+        rdar://problem/29430711
+
+        Reviewed by Jer Noble.
+
+        Fix a crash when didLosePointerLock is not specified.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+
 2016-12-07  Keith Rollin  <krollin@apple.com>
 
         Network event record/replay
index 0d1d0ed..7ca217c 100644 (file)
@@ -2229,7 +2229,7 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
 
         void didLosePointerLock(WebPageProxy* page) override
         {
-            if (!m_client.requestPointerLock)
+            if (!m_client.didLosePointerLock)
                 return;
 
             m_client.didLosePointerLock(toAPI(page), m_client.base.clientInfo);
index c59c8ee..f297b98 100644 (file)
@@ -1,3 +1,21 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        One esc to exit fullscreen and pointer lock
+        https://bugs.webkit.org/show_bug.cgi?id=165416
+        rdar://problem/29430711
+
+        Reviewed by Jer Noble.
+
+        Implement WKPageUIClientV8 for pointer lock support.
+        Add "escape" key support in EventSenderProxy.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::requestPointerLock):
+        (WTR::TestController::createOtherPage):
+        (WTR::TestController::createWebViewWithOptions):
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::keyDown):
+
 2016-12-07  Simon Fraser  <simon.fraser@apple.com>
 
         Add system trace points for JavaScript VM entry/exit
index 71fc1ad..082e692 100644 (file)
@@ -197,6 +197,11 @@ static void checkUserMediaPermissionForOrigin(WKPageRef, WKFrameRef frame, WKSec
     TestController::singleton().handleCheckOfUserMediaPermissionForOrigin(frame, userMediaDocumentOrigin, topLevelDocumentOrigin, checkRequest);
 }
 
+static void requestPointerLock(WKPageRef page, const void*)
+{
+    WKPageDidAllowPointerLock(page);
+}
+
 WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo)
 {
     PlatformWebView* parentView = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
@@ -206,8 +211,8 @@ WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKPageConfiguration
 
     view->resizeTo(800, 600);
 
-    WKPageUIClientV6 otherPageUIClient = {
-        { 6, view },
+    WKPageUIClientV8 otherPageUIClient = {
+        { 8, view },
         0, // createNewPage_deprecatedForUseWithV0
         0, // showPage
         closeOtherPage,
@@ -270,6 +275,10 @@ WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKPageConfiguration
         0, // runJavaScriptConfirm
         0, // runJavaScriptPrompt
         checkUserMediaPermissionForOrigin,
+        0, // runBeforeUnloadConfirmPanel
+        0, // fullscreenMayReturnToInline
+        requestPointerLock,
+        0,
     };
     WKPageSetPageUIClient(newPage, &otherPageUIClient.base);
     
@@ -474,8 +483,8 @@ void TestController::createWebViewWithOptions(const TestOptions& options)
     resetPreferencesToConsistentValues(options);
 
     platformCreateWebView(configuration.get(), options);
-    WKPageUIClientV6 pageUIClient = {
-        { 6, m_mainWebView.get() },
+    WKPageUIClientV8 pageUIClient = {
+        { 8, m_mainWebView.get() },
         0, // createNewPage_deprecatedForUseWithV0
         0, // showPage
         0, // close
@@ -538,6 +547,10 @@ void TestController::createWebViewWithOptions(const TestOptions& options)
         0, // runJavaScriptConfirm
         0, // runJavaScriptPrompt
         checkUserMediaPermissionForOrigin,
+        0, // runBeforeUnloadConfirmPanel
+        0, // fullscreenMayReturnToInline
+        requestPointerLock,
+        0,
     };
     WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base);
 
index d5bcdd7..8029f94 100644 (file)
@@ -630,7 +630,7 @@ void EventSenderProxy::leapForward(int milliseconds)
 
 void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
 {
-    NSString* character = [NSString stringWithCString:toSTD(key).c_str() 
+    NSString* character = [NSString stringWithCString:toSTD(key).c_str()
                                    encoding:[NSString defaultCStringEncoding]];
 
     NSString *eventCharacter = character;
@@ -707,6 +707,10 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
         const unichar ch = 0xFFE8;
         eventCharacter = [NSString stringWithCharacters:&ch length:1];
         keyCode = 0x3D;
+    } else if ([character isEqualToString:@"escape"]) {
+        const unichar ch = 0x1B;
+        eventCharacter = [NSString stringWithCharacters:&ch length:1];
+        keyCode = 0x35;
     }
 
     // Compare the input string with the function-key names defined by the DOM spec (i.e. "F1",...,"F24").