Commit ebbfecc5 authored by scheib@chromium.org's avatar scheib@chromium.org

Add new Pointer Lock spec webkitRequestPointerLock and webkitExitPointerLock methods.

https://bugs.webkit.org/show_bug.cgi?id=88891

Reviewed by Dimitri Glazkov.

Part of a series of refactoring changes to update pointer lock API to
the fullscreen locking style. https://bugs.webkit.org/show_bug.cgi?id=84402

Entering and exiting mouse lock is provided in the new webkitRequestPointerLock and
webkitExitPointerLock methods.

Source/WebCore:

Existing pointer-lock tests updated to use the new methods.

* dom/Document.cpp:
(WebCore::Document::webkitExitPointerLock):
(WebCore):
* dom/Document.h:
(Document):
* dom/Document.idl:
* dom/Element.cpp:
(WebCore):
(WebCore::Element::webkitRequestPointerLock):
* dom/Element.h:
* dom/Element.idl:

LayoutTests:

Existing tests updated to use the new methods. Also, several updated to
support manual testing.

* pointer-lock/lock-already-locked-expected.txt:
* pointer-lock/lock-already-locked.html:
* pointer-lock/mouse-event-delivery-expected.txt:
* pointer-lock/mouse-event-delivery.html:
* pointer-lock/pointer-lock-api-expected.txt:
* pointer-lock/pointer-lock-api.html:
* pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt:
* pointer-lock/pointerlockchange-pointerlockerror-events.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@120486 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2dc1ea35
2012-06-13 Vincent Scheib <scheib@chromium.org>
Add new Pointer Lock spec webkitRequestPointerLock and webkitExitPointerLock methods.
https://bugs.webkit.org/show_bug.cgi?id=88891
Reviewed by Dimitri Glazkov.
Part of a series of refactoring changes to update pointer lock API to
the fullscreen locking style. https://bugs.webkit.org/show_bug.cgi?id=84402
Entering and exiting mouse lock is provided in the new webkitRequestPointerLock and
webkitExitPointerLock methods.
Existing tests updated to use the new methods. Also, several updated to
support manual testing.
* pointer-lock/lock-already-locked-expected.txt:
* pointer-lock/lock-already-locked.html:
* pointer-lock/mouse-event-delivery-expected.txt:
* pointer-lock/mouse-event-delivery.html:
* pointer-lock/pointer-lock-api-expected.txt:
* pointer-lock/pointer-lock-api.html:
* pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt:
* pointer-lock/pointerlockchange-pointerlockerror-events.html:
2012-06-15 Abhishek Arya <inferno@chromium.org>
Unreviewed. Rebaselines for r120477.
......
......@@ -3,7 +3,18 @@ Test calling lock when already in a locked state.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS navigator.webkitPointer.isLocked is false
PASS document.webkitPointerLockElement is null
Locking targetdiv1.
PASS document.onwebkitpointerlockchange event received.
PASS document.webkitPointerLockElement is targetdiv1
Locking targetdiv1, again.
PASS document.onwebkitpointerlockchange event received.
PASS document.webkitPointerLockElement is targetdiv1
Locking targetdiv2.
PASS expectTarget1Unlock is true
PASS document.onwebkitpointerlockchange event received.
PASS document.webkitPointerLockElement is targetdiv2
PASS expectTarget2Unlock is true
PASS Lock target1 succeeded.
PASS navigator.webkitPointer.isLocked is true
PASS document.onwebkitpointerlockchange event received.
......@@ -20,4 +31,5 @@ PASS document.webkitPointerLockElement is targetdiv2
PASS successfullyParsed is true
TEST COMPLETE
doNextStep for manual testing
......@@ -5,6 +5,7 @@
</head>
<body>
<div>
<button onclick="doNextStep('manual');">doNextStep for manual testing</button>
<div id="target1"></div>
<div id="target2"></div>
</div>
......@@ -21,6 +22,7 @@
{
testPassed("document.onwebkitpointerlockchange event received.");
shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
doNextStep();
};
document.onwebkitpointerlockerror =
function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
......@@ -29,21 +31,49 @@
targetdiv1.addEventListener("webkitpointerlocklost",
function () { shouldBe("expectTarget1Unlock", "true"); });
var expectTarget2Unlock = false;
targetdiv2.addEventListener("webkitpointerlocklost",
function () { testFailed("Unexpected targetdiv2 pointerlocklost."); });
function () { shouldBe("expectTarget2Unlock", "true"); });
currentStep = 0;
function doNextStep() {
setTimeout(function () { todo[currentStep++](); }, 0);
function doNextStep(manual)
{
if (!window.layoutTestController && !manual)
return;
if (currentStep < todo.length)
setTimeout(function () { todo[currentStep++](); }, 0);
else if (currentStep++ == todo.length)
setTimeout(function () { finishJSTest(); }, 0);
}
todo = [
function () {
shouldBe("navigator.webkitPointer.isLocked", "false");
shouldBe("document.webkitPointerLockElement", "null");
debug(" Locking targetdiv1.")
targetdiv1.webkitRequestPointerLock();
expectedTargetToBeLockedString = "targetdiv1";
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
debug(" Locking targetdiv1, again.")
targetdiv1.webkitRequestPointerLock();
expectedTargetToBeLockedString = "targetdiv1";
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
debug(" Locking targetdiv2.")
expectTarget1Unlock = true;
targetdiv2.webkitRequestPointerLock();
expectedTargetToBeLockedString = "targetdiv2";
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
expectTarget1Unlock = false;
expectTarget2Unlock = true;
navigator.webkitPointer.lock(targetdiv1,
function () {
testPassed("Lock target1 succeeded.");
shouldBe("navigator.webkitPointer.isLocked", "true");
doNextStep();
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
testFailed("Lock failed.");
......@@ -52,11 +82,12 @@
expectedTargetToBeLockedString = "targetdiv1";
},
function () {
expectTarget2Unlock = false;
navigator.webkitPointer.lock(targetdiv1,
function () {
testPassed("Lock target1 succeeded again.");
shouldBe("navigator.webkitPointer.isLocked", "true");
doNextStep();
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
testFailed("Lock failed.");
......@@ -70,7 +101,7 @@
function () {
testPassed("Lock target2 succeeded.");
shouldBe("navigator.webkitPointer.isLocked", "true");
doNextStep();
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
testFailed("Lock failed.");
......@@ -78,7 +109,6 @@
});
expectedTargetToBeLockedString = "targetdiv2";
},
finishJSTest
];
doNextStep();
</script>
......
......@@ -3,17 +3,18 @@ Test mouse events are routed to lock target.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS window.eventSender is defined.
PASS Lock target1 succeeded.
With a lock in place send a click.
PASS document.onwebkitpointerlockchange event received.
PASS document.webkitPointerLockElement is targetdiv1
With a lock in place send a click.
PASS event type: mousedown, target: target1, received on: target1
PASS event type: mousedown, target: target1, received on: body
PASS Lock target2 succeeded.
With a lock in place send a click.
PASS document.onwebkitpointerlockchange event received.
PASS document.webkitPointerLockElement is targetdiv2
With a lock in place send a click.
PASS event type: mousedown, target: target2, received on: target2
PASS event type: mousedown, target: target2, received on: body
Ensure double clicks work as expected, sending 4 clicks.
Creating a click and dblclick.
Ensure double clicks work as expected, sending 4 clicks.
Creating a click and dblclick.
PASS event type: mousedown, target: target2, received on: target2
PASS event type: mouseup, target: target2, received on: target2
PASS event type: click, target: target2, received on: target2
......@@ -21,7 +22,7 @@ PASS event type: mousedown, target: target2, received on: target2
PASS event type: mouseup, target: target2, received on: target2
PASS event type: click, target: target2, received on: target2
PASS event type: dblclick, target: target2, received on: target2
Ensuring no false dblclicks if we continue.
Ensuring no false dblclicks if we continue.
PASS event type: mousedown, target: target2, received on: target2
PASS event type: mouseup, target: target2, received on: target2
PASS event type: click, target: target2, received on: target2
......@@ -31,4 +32,5 @@ PASS event type: click, target: target2, received on: target2
PASS successfullyParsed is true
TEST COMPLETE
doNextStep for manual testing
......@@ -5,17 +5,28 @@
</head>
<body id="body">
<div>
<button onclick="doNextStep('manual');">doNextStep for manual testing</button>
<div id="target1"></div>
<div id="target2"></div>
</div>
<script>
description("Test mouse events are routed to lock target.")
window.jsTestIsAsync = true;
shouldBeDefined("window.eventSender");
targetdiv1 = document.getElementById("target1");
targetdiv2 = document.getElementById("target2");
// Expect change event only for all transitions below.
expectedTargetToBeLockedString = "";
document.onwebkitpointerlockchange = function ()
{
testPassed("document.onwebkitpointerlockchange event received.");
shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
doNextStep('manual');
};
document.onwebkitpointerlockerror =
function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
function eventNotExpected(e) {
testFailed("Unexpected event " + e.type + " on " + e.currentTarget.id);
finishJSTest();
......@@ -25,82 +36,75 @@
}
currentStep = 0;
function doNextStep() {
todo[currentStep++]();
function doNextStep(manual)
{
if (!window.layoutTestController && !manual)
return;
if (currentStep < todo.length)
setTimeout(function () { todo[currentStep++](); }, 0);
else if (currentStep++ == todo.length)
setTimeout(function () { finishJSTest(); }, 0);
}
todo = [
function () {
navigator.webkitPointer.lock(targetdiv1,
function () {
testPassed("Lock target1 succeeded.");
doNextStep();
},
function () {
testFailed("Lock failed.");
finishJSTest();
});
targetdiv1.webkitRequestPointerLock();
expectedTargetToBeLockedString = "targetdiv1";
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
debug("With a lock in place send a click.")
debug(" With a lock in place send a click.")
targetdiv1.onmousedown = eventExpected;
targetdiv2.onmousedown = eventNotExpected;
document.body.onmousedown = eventExpected;
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
targetdiv1.onmousedown = undefined;
targetdiv2.onmousedown = undefined;
document.body.onmousedown = undefined;
if (window.eventSender) {
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
}
doNextStep();
},
function () {
navigator.webkitPointer.lock(targetdiv2,
function () {
testPassed("Lock target2 succeeded.");
doNextStep();
},
function () {
testFailed("Lock failed.");
finishJSTest();
});
targetdiv2.webkitRequestPointerLock();
expectedTargetToBeLockedString = "targetdiv2";
// doNextStep() called by onwebkitpointerlockchange handler.
},
function () {
debug("With a lock in place send a click.")
debug(" With a lock in place send a click.")
targetdiv1.onmousedown = eventNotExpected;
targetdiv2.onmousedown = eventExpected;
document.body.onmousedown = eventExpected;
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
targetdiv1.onmousedown = undefined;
targetdiv2.onmousedown = undefined;
document.body.onmousedown = undefined;
if (window.eventSender) {
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
}
doNextStep();
},
function () {
debug("Ensure double clicks work as expected, sending 4 clicks.")
debug(" Ensure double clicks work as expected, sending 4 clicks.")
targetdiv1.onmousedown = undefined;
document.body.onmousedown = undefined;
targetdiv2.onmousedown = eventExpected;
targetdiv2.onmouseup = eventExpected;
targetdiv2.onclick = eventExpected;
targetdiv2.ondblclick = eventExpected;
debug("Creating a click and dblclick.");
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
window.eventSender.mouseDown();
window.eventSender.mouseUp();
debug("Ensuring no false dblclicks if we continue.");
window.eventSender.mouseDown();
window.eventSender.mouseUp();
window.eventSender.mouseDown();
window.eventSender.mouseUp();
targetdiv2.onmousedown = undefined;
targetdiv2.onmouseup = undefined;
targetdiv2.onclick = undefined;
targetdiv2.ondblclick = undefined;
debug(" Creating a click and dblclick.");
if (window.eventSender) {
window.eventSender.leapForward(1000);
window.eventSender.mouseDown();
window.eventSender.mouseUp();
window.eventSender.mouseDown();
window.eventSender.mouseUp();
}
debug(" Ensuring no false dblclicks if we continue.");
if (window.eventSender) {
window.eventSender.mouseDown();
window.eventSender.mouseUp();
window.eventSender.mouseDown();
window.eventSender.mouseUp();
}
doNextStep();
},
finishJSTest
];
doNextStep();
</script>
......
......@@ -11,7 +11,9 @@ PASS navigator.webkitPointer.lock(document.body) is undefined
PASS navigator.webkitPointer.unlock() is undefined
PASS document.onwebkitpointerlockchange is defined.
PASS document.onwebkitpointerlockerror is defined.
PASS document.webkitExitPointerLock is defined.
PASS document.webkitPointerLockElement is null
PASS element.webkitRequestPointerLock is defined.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -36,7 +36,10 @@
function () {
shouldBeDefined("document.onwebkitpointerlockchange");
shouldBeDefined("document.onwebkitpointerlockerror");
shouldBeDefined("document.webkitExitPointerLock");
shouldEvaluateTo("document.webkitPointerLockElement", null);
element = document.createElement();
shouldBeDefined("element.webkitRequestPointerLock");
doNextStep();
},
];
......
......@@ -14,7 +14,6 @@ PASS onwebkitpointerlockchange received after: Lock targetDiv1 again.
PASS onwebkitpointerlockchange received after: Lock targetDiv2.
Lock targetDiv2 again.
PASS onwebkitpointerlockchange received after: Lock targetDiv2 again.
Lock null.
Lock targetIframe1.
Lock targetIframe1 (handler for iframe1).
PASS onwebkitpointerlockchange received after: Lock targetIframe1 (handler for iframe1).
......
......@@ -71,33 +71,28 @@
todo = [
function () {
expectNoEvents("Unlock.");
navigator.webkitPointer.unlock();
document.webkitExitPointerLock();
doNextStep();
},
function () {
expectOnlyChangeEvent("Lock targetDiv1.");
navigator.webkitPointer.lock(targetDiv1);
targetDiv1.webkitRequestPointerLock();
},
function () {
expectOnlyChangeEvent("Unlock again.");
navigator.webkitPointer.unlock();
document.webkitExitPointerLock();
},
function () {
expectOnlyChangeEvent("Lock targetDiv1 again.");
navigator.webkitPointer.lock(targetDiv1);
targetDiv1.webkitRequestPointerLock();
},
function () {
expectOnlyChangeEvent("Lock targetDiv2.");
navigator.webkitPointer.lock(targetDiv2);
targetDiv2.webkitRequestPointerLock();
},
function () {
expectOnlyChangeEvent("Lock targetDiv2 again.");
navigator.webkitPointer.lock(targetDiv2);
},
function () {
expectNoEvents("Lock null.");
navigator.webkitPointer.lock(null);
doNextStep();
targetDiv2.webkitRequestPointerLock();
},
function () {
targetIframe1.src = "about:blank";
......@@ -110,7 +105,7 @@
function () {
expectOnlyChangeEvent("Lock targetIframe1.");
expectOnlyChangeEvent("Lock targetIframe1 (handler for iframe1).", targetIframe1.contentDocument);
navigator.webkitPointer.lock(targetIframe1.contentDocument.body);
targetIframe1.contentDocument.body.webkitRequestPointerLock();
},
function () {
// Absorb an extra doNextStep() from previous event handlers.
......@@ -119,7 +114,7 @@
expectNoEvents("Lock targetIframe2.");
expectOnlyChangeEvent("Lock targetIframe2 (handler for iframe1).", targetIframe1.contentDocument);
expectOnlyChangeEvent("Lock targetIframe2 (handler for iframe2).", targetIframe2.contentDocument);
navigator.webkitPointer.lock(targetIframe2.contentDocument.body);
targetIframe2.contentDocument.body.webkitRequestPointerLock();
},
function () {
// Absorb an extra doNextStep() from previous event handlers.
......@@ -128,19 +123,19 @@
expectNoEvents("Unlock targetIframe2.");
expectNoEvents("Unlock targetIframe2 (handler for iframe1).", targetIframe1.contentDocument);
expectOnlyChangeEvent("Unlock targetIframe2 (handler for iframe2).", targetIframe2.contentDocument);
navigator.webkitPointer.unlock();
document.webkitExitPointerLock();
},
function () {
shouldBeDefined("testRunner.setPointerLockWillFailSynchronously");
testRunner.setPointerLockWillFailSynchronously();
expectOnlyErrorEvent("Lock with synchronous failure.");
navigator.webkitPointer.lock(targetDiv1);
targetDiv1.webkitRequestPointerLock();
},
function () {
shouldBeDefined("testRunner.setPointerLockWillFailAsynchronously");
testRunner.setPointerLockWillFailAsynchronously();
expectOnlyErrorEvent("Lock with asynchronous failure.");
navigator.webkitPointer.lock(targetDiv1);
targetDiv1.webkitRequestPointerLock();
},
];
doNextStep();
......
2012-06-13 Vincent Scheib <scheib@chromium.org>
Add new Pointer Lock spec webkitRequestPointerLock and webkitExitPointerLock methods.
https://bugs.webkit.org/show_bug.cgi?id=88891
Reviewed by Dimitri Glazkov.
Part of a series of refactoring changes to update pointer lock API to
the fullscreen locking style. https://bugs.webkit.org/show_bug.cgi?id=84402
Entering and exiting mouse lock is provided in the new webkitRequestPointerLock and
webkitExitPointerLock methods.
Existing pointer-lock tests updated to use the new methods.
* dom/Document.cpp:
(WebCore::Document::webkitExitPointerLock):
(WebCore):
* dom/Document.h:
(Document):
* dom/Document.idl:
* dom/Element.cpp:
(WebCore):
(WebCore::Element::webkitRequestPointerLock):
* dom/Element.h:
* dom/Element.idl:
2012-06-15 Tony Payne <tpayne@chromium.org>
[chromium] Add iccjpeg and qcms to chromium port
......@@ -5753,6 +5753,12 @@ void Document::addDocumentToFullScreenChangeEventQueue(Document* doc)
#endif
#if ENABLE(POINTER_LOCK)
void Document::webkitExitPointerLock()
{
if (page())
page()->pointerLockController()->requestPointerUnlock();
}
Element* Document::webkitPointerLockElement() const
{
return page() ? page()->pointerLockController()->element() : 0;
......
......@@ -1069,6 +1069,7 @@ public:
#endif
#if ENABLE(POINTER_LOCK)
void webkitExitPointerLock();
Element* webkitPointerLockElement() const;
#endif
......
......@@ -265,6 +265,7 @@ module core {
[V8EnabledAtRuntime] void webkitExitFullscreen();
#endif
[Conditional=POINTER_LOCK, V8EnabledAtRuntime=pointerLock] void webkitExitPointerLock();
readonly attribute [Conditional=POINTER_LOCK, V8EnabledAtRuntime=pointerLock] Element webkitPointerLockElement;
#if defined(ENABLE_CSS_REGIONS) && ENABLE_CSS_REGIONS
......
......@@ -57,6 +57,7 @@
#include "NodeRenderStyle.h"
#include "NodeRenderingContext.h"
#include "Page.h"
#include "PointerLockController.h"
#include "RenderRegion.h"
#include "RenderView.h"
#include "RenderWidget.h"
......@@ -66,6 +67,7 @@
#include "StyleResolver.h"
#include "Text.h"
#include "TextIterator.h"
#include "VoidCallback.h"
#include "WebKitMutationObserver.h"
#include "WebKitAnimationList.h"
#include "XMLNSNames.h"
......@@ -1867,6 +1869,13 @@ void Element::setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(boo
}
#endif
#if ENABLE(POINTER_LOCK)
void Element::webkitRequestPointerLock()
{
document()->frame()->page()->pointerLockController()->requestPointerLock(this, 0, 0);
}
#endif
SpellcheckAttributeState Element::spellcheckAttributeState() const
{
const AtomicString& value = getAttribute(HTMLNames::spellcheckAttr);
......
......@@ -403,6 +403,10 @@ public:
void webkitRequestFullscreen();
#endif
#if ENABLE(POINTER_LOCK)
void webkitRequestPointerLock();
#endif
virtual bool isSpellCheckingEnabled() const;
PassRefPtr<WebKitAnimationList> webkitGetAnimations() const;
......
......@@ -137,6 +137,8 @@ module core {
[V8EnabledAtRuntime] void webkitRequestFullscreen();
#endif
[Conditional=POINTER_LOCK, V8EnabledAtRuntime=pointerLock] void webkitRequestPointerLock();
// CSS Regions API
readonly attribute DOMString webkitRegionOverflow;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment