Exit pointer lock when page goes into page cache.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 06:19:57 +0000 (06:19 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Dec 2016 06:19:57 +0000 (06:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165425
rdar://problem/29430834

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

Source/WebCore:

Test: pointer-lock/lock-lost-on-navigation.html

Cancel pointer lock when page goes into page cache and add methods to Internals
so it can be tested.

* dom/Document.cpp:
(WebCore::Document::setPageCacheState):
* page/PointerLockController.h:
* testing/Internals.cpp:
(WebCore::Internals::pageHasPendingPointerLock):
(WebCore::Internals::pageHasPointerLock):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* platform/mac/TestExpectations:
* pointer-lock/lock-lost-on-navigation-expected.txt: Added.
* pointer-lock/lock-lost-on-navigation.html: Added.
* pointer-lock/resources/lock-lost-on-navigation2.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/mac/TestExpectations
LayoutTests/pointer-lock/lock-lost-on-navigation-expected.txt [new file with mode: 0644]
LayoutTests/pointer-lock/lock-lost-on-navigation.html [new file with mode: 0644]
LayoutTests/pointer-lock/resources/lock-lost-on-navigation2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/page/PointerLockController.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 80bcfcb..1c4c441 100644 (file)
@@ -1,3 +1,16 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        Exit pointer lock when page goes into page cache.
+        https://bugs.webkit.org/show_bug.cgi?id=165425
+        rdar://problem/29430834
+
+        Reviewed by Jer Noble.
+
+        * platform/mac/TestExpectations:
+        * pointer-lock/lock-lost-on-navigation-expected.txt: Added.
+        * pointer-lock/lock-lost-on-navigation.html: Added.
+        * pointer-lock/resources/lock-lost-on-navigation2.html: Added.
+
 2016-12-07  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Unskip calc() tests
index 2a4d57c..8ef5574 100644 (file)
@@ -288,6 +288,7 @@ pointer-lock/mouse-event-delivery.html
 pointer-lock/pointerlockchange-event-on-lock-lost.html
 pointer-lock/pointerlockchange-pointerlockerror-events.html
 pointer-lock/pointerlockelement-null-when-pending.html
+pointer-lock/lock-lost-on-navigation.html [ Pass ]
 http/tests/pointer-lock/
 
 webkit.org/b/82763 fast/forms/textarea-placeholder-set-attribute.html
diff --git a/LayoutTests/pointer-lock/lock-lost-on-navigation-expected.txt b/LayoutTests/pointer-lock/lock-lost-on-navigation-expected.txt
new file mode 100644 (file)
index 0000000..e098435
--- /dev/null
@@ -0,0 +1,12 @@
+Test that pointer lock is lost after navigation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.testRunner is defined.
+PASS internals.pageHasPendingPointerLock() is false
+PASS internals.pageHasPointerLock() is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/pointer-lock/lock-lost-on-navigation.html b/LayoutTests/pointer-lock/lock-lost-on-navigation.html
new file mode 100644 (file)
index 0000000..531a6c3
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<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 when lock is lost.")
+    window.jsTestIsAsync = true;
+    shouldBeDefined("window.testRunner");
+
+    targetDiv1 = document.getElementById("target1");
+
+    todo = [
+        function () {
+            expectOnlyChangeEvent("Lock targetDiv1.");
+            targetDiv1.requestPointerLock();
+            // doNextStep called by event handler.
+        },
+        function () {
+            shouldBe("document.pointerLockElement", "targetDiv1");
+            setTimeout(() => {
+                window.location.href = "resources/lock-lost-on-navigation2.html";    
+            }, 0);
+        },
+    ];
+    doNextStepWithUserGesture();
+</script>
+<script src="../http/tests/resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/pointer-lock/resources/lock-lost-on-navigation2.html b/LayoutTests/pointer-lock/resources/lock-lost-on-navigation2.html
new file mode 100644 (file)
index 0000000..36f1f0d
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<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 pointer lock is lost after navigation.")
+    window.jsTestIsAsync = true;
+    shouldBeDefined("window.testRunner");
+
+    shouldBe("internals.pageHasPendingPointerLock()", "false");
+    shouldBe("internals.pageHasPointerLock()", "false");
+    finishJSTest();
+</script>
+<script src="../../http/tests/resources/js-test-post.js"></script>
+</body>
+</html>
+
index c99bff6..50bc66d 100644 (file)
@@ -1,3 +1,25 @@
+2016-12-07  Jeremy Jones  <jeremyj@apple.com>
+
+        Exit pointer lock when page goes into page cache.
+        https://bugs.webkit.org/show_bug.cgi?id=165425
+        rdar://problem/29430834
+
+        Reviewed by Jer Noble.
+
+        Test: pointer-lock/lock-lost-on-navigation.html
+
+        Cancel pointer lock when page goes into page cache and add methods to Internals
+        so it can be tested.
+
+        * dom/Document.cpp:
+        (WebCore::Document::setPageCacheState):
+        * page/PointerLockController.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::pageHasPendingPointerLock):
+        (WebCore::Internals::pageHasPointerLock):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2016-12-07  Antoine Quint  <graouts@apple.com>
 
         [Modern Media Controls] Tracks panel does not display in the right location in fullscreen and cannot be dismissed
index b19f53e..8e99b91 100644 (file)
@@ -4544,6 +4544,10 @@ void Document::setPageCacheState(PageCacheState state)
                 v->resetScrollbars();
         }
 
+#if ENABLE(POINTER_LOCK)
+        exitPointerLock();
+#endif
+
         styleScope().clearResolver();
         clearSelectorQueryCache();
         m_styleRecalcTimer.stop();
index 87d6cf1..cb6b0f9 100644 (file)
@@ -48,8 +48,8 @@ public:
     void requestPointerUnlockAndForceCursorVisible();
     void elementRemoved(Element&);
     void documentDetached(Document&);
-    bool lockPending() const;
-    Element* element() const;
+    WEBCORE_EXPORT bool lockPending() const;
+    WEBCORE_EXPORT Element* element() const;
 
     WEBCORE_EXPORT void didAcquirePointerLock();
     WEBCORE_EXPORT void didNotAcquirePointerLock();
index 1dbfee4..28c1223 100644 (file)
 #include "MediaPlaybackTargetContext.h"
 #endif
 
+#if ENABLE(POINTER_LOCK)
+#include "PointerLockController.h"
+#endif
+
 using JSC::CallData;
 using JSC::CallType;
 using JSC::CodeBlock;
@@ -3405,4 +3409,34 @@ void Internals::reportBacktrace()
     WTFReportBacktrace();
 }
 
+#if ENABLE(POINTER_LOCK)
+bool Internals::pageHasPendingPointerLock() const
+{
+    Document* document = contextDocument();
+    if (!document)
+        return false;
+
+    Page* page = document->page();
+    if (!page)
+        return false;
+
+    return page->pointerLockController().lockPending();
+}
+
+bool Internals::pageHasPointerLock() const
+{
+    Document* document = contextDocument();
+    if (!document)
+        return false;
+
+    Page* page = document->page();
+    if (!page)
+        return false;
+
+    auto& controller = page->pointerLockController();
+    return controller.element() && !controller.lockPending();
+}
+#endif
+
+
 } // namespace WebCore
index ac3ed00..5275508 100644 (file)
@@ -508,6 +508,11 @@ public:
     
     void reportBacktrace();
 
+#if ENABLE(POINTER_LOCK)
+    bool pageHasPendingPointerLock() const;
+    bool pageHasPointerLock() const;
+#endif
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
index 2282ac4..e83d2af 100644 (file)
@@ -483,4 +483,7 @@ enum EventThrottlingBehavior {
     boolean userPrefersReducedMotion();
     
     void reportBacktrace();
+
+    [Conditional=POINTER_LOCK] boolean pageHasPendingPointerLock();
+    [Conditional=POINTER_LOCK] boolean pageHasPointerLock();
 };