Commit 13c96db0 authored by scheib@chromium.org's avatar scheib@chromium.org

Add new Pointer Lock spec events webkitpointerlockchange and webkitpointerlockerror

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

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

New change and error events added. Follow up patches will remove
the previous callbacks and pointerlocklost event. Tests updated
to include the new events, and a new test added specifically for
the new events, pointerlockchange-pointerlockerror-events.html.

Source/WebCore:

Test: pointer-lock/pointerlockchange-pointerlockerror-events.html

* dom/Document.h:
(Document):
* dom/Document.idl:
* dom/EventNames.h:
(WebCore):
* page/PointerLockController.cpp:
(WebCore::PointerLockController::requestPointerLock):
(WebCore::PointerLockController::didAcquirePointerLock):
(WebCore::PointerLockController::didNotAcquirePointerLock):
(WebCore::PointerLockController::didLosePointerLock):
(WebCore::PointerLockController::enqueueEvent):
(WebCore):
* page/PointerLockController.h:
(PointerLockController):

LayoutTests:

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@119763 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2f94ec59
2012-06-06 Vincent Scheib <scheib@chromium.org>
Add new Pointer Lock spec events webkitpointerlockchange and webkitpointerlockerror
https://bugs.webkit.org/show_bug.cgi?id=88377
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
New change and error events added. Follow up patches will remove
the previous callbacks and pointerlocklost event. Tests updated
to include the new events, and a new test added specifically for
the new events, pointerlockchange-pointerlockerror-events.html.
* pointer-lock/lock-already-locked-expected.txt:
* pointer-lock/lock-already-locked.html:
* pointer-lock/pointer-lock-api-expected.txt:
* pointer-lock/pointer-lock-api.html:
* pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt: Added.
* pointer-lock/pointerlockchange-pointerlockerror-events.html: Added.
* pointer-lock/pointerlocklost-event-expected.txt:
* pointer-lock/pointerlocklost-event.html:
2012-06-07 Takashi Sakamoto <tasak@google.com>
Incorrect border rendering when border radius is above 2px.
......
......@@ -6,11 +6,15 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS navigator.webkitPointer.isLocked is false
PASS Lock target1 succeeded.
PASS navigator.webkitPointer.isLocked is true
PASS document.onwebkitpointerlockchange event received.
PASS Lock target1 succeeded again.
PASS navigator.webkitPointer.isLocked is true
PASS document.onwebkitpointerlockchange event received.
PASS expectTarget1Unlock is true
PASS Lock target2 succeeded.
PASS navigator.webkitPointer.isLocked is true
PASS document.onwebkitpointerlockchange event received.
PASS document.onwebkitpointerlockchange event received.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -15,6 +15,12 @@
targetdiv1 = document.getElementById("target1");
targetdiv2 = document.getElementById("target2");
// Expect change event only for all transitions below.
document.onwebkitpointerlockchange =
function () { testPassed("document.onwebkitpointerlockchange event received."); };
document.onwebkitpointerlockerror =
function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
var expectTarget1Unlock = false;
targetdiv1.addEventListener("webkitpointerlocklost",
function () { shouldBe("expectTarget1Unlock", "true"); });
......@@ -24,7 +30,7 @@
currentStep = 0;
function doNextStep() {
todo[currentStep++]();
setTimeout(function () { todo[currentStep++](); }, 0);
}
todo = [
function () {
......
......@@ -4,6 +4,8 @@ PASS navigator.webkitPointer.isLocked is false
PASS navigator.webkitPointer.lock() threw exception TypeError: Not enough arguments.
PASS navigator.webkitPointer.lock(document) is undefined
PASS navigator.webkitPointer.unlock() is undefined
PASS document.onwebkitpointerlockchange is defined.
PASS document.onwebkitpointerlockerror is defined.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -10,6 +10,8 @@
shouldThrow("navigator.webkitPointer.lock()", "'TypeError: Not enough arguments'");
shouldEvaluateTo("navigator.webkitPointer.lock(document)", "undefined");
shouldEvaluateTo("navigator.webkitPointer.unlock()", "undefined");
shouldBeDefined("document.onwebkitpointerlockchange");
shouldBeDefined("document.onwebkitpointerlockerror");
</script>
<script src="../fast/js/resources/js-test-post.js"></script>
</body>
......
Test expected pointerlockchange and pointerlockerror events.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Unlock.
Lock targetDiv1.
PASS onwebkitpointerlockchange received after: Lock targetDiv1.
Unlock again.
PASS onwebkitpointerlockchange received after: Unlock again.
Lock targetDiv1 again.
PASS onwebkitpointerlockchange received after: Lock targetDiv1 again.
Lock targetDiv2.
PASS onwebkitpointerlockchange received after: Lock targetDiv2.
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).
PASS onwebkitpointerlockchange received after: Lock targetIframe1.
PASS onwebkitpointerlockchange received after: Lock targetIframe1.
Lock targetIframe2.
Lock targetIframe2 (handler for iframe1).
Lock targetIframe2 (handler for iframe2).
PASS onwebkitpointerlockchange received after: Lock targetIframe2 (handler for iframe2).
PASS onwebkitpointerlockchange received after: Lock targetIframe2 (handler for iframe1).
PASS onwebkitpointerlockchange received after: Lock targetIframe2 (handler for iframe1).
Unlock targetIframe2.
Unlock targetIframe2 (handler for iframe1).
Unlock targetIframe2 (handler for iframe2).
PASS onwebkitpointerlockchange received after: Unlock targetIframe2 (handler for iframe2).
PASS layoutTestController.setPointerLockWillFailSynchronously is defined.
Lock with synchronous failure.
PASS onwebkitpointerlockerror received after: Lock with synchronous failure.
PASS layoutTestController.setPointerLockWillFailAsynchronously is defined.
Lock with asynchronous failure.
PASS onwebkitpointerlockerror received after: Lock with asynchronous failure.
PASS successfullyParsed is true
TEST COMPLETE
doNextStep for manual testing
<!DOCTYPE HTML>
<html>
<head>
<script src="../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<div>
<button onclick="doNextStep('manual');">doNextStep for manual testing</button>
<div id="target1"></div>
<div id="target2"></div>
<iframe id="iframe1"></iframe>
<iframe id="iframe2"></iframe>
</div>
<script>
description("Test expected pointerlockchange and pointerlockerror events.")
window.jsTestIsAsync = true;
targetDiv1 = document.getElementById("target1");
targetDiv2 = document.getElementById("target2");
targetIframe1 = document.getElementById("iframe1");
targetIframe2 = document.getElementById("iframe2");
function eventExpected(eventHandlerName, message, expectedCalls, targetHanderNode)
{
targetHanderNode[eventHandlerName] = function ()
{
switch (expectedCalls--) {
case 0:
testFailed(eventHandlerName + " received after: " + message);
finishJSTest();
break;
case 1:
doNextStep();
default:
testPassed(eventHandlerName + " received after: " + message);
};
};
};
function expectOnlyChangeEvent(message, expectedCalls, targetDocument) {
debug(" " + message);
expectedCalls = expectedCalls !== undefined ? expectedCalls : 1;
targetDocument = targetDocument !== undefined ? targetDocument : document;
eventExpected("onwebkitpointerlockchange", message, expectedCalls, targetDocument);
eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
};
function expectOnlyErrorEvent(message, expectedCalls, targetDocument) {
debug(" " + message);
expectedCalls = expectedCalls !== undefined ? expectedCalls : 1;
targetDocument = targetDocument !== undefined ? targetDocument : document;
eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
eventExpected("onwebkitpointerlockerror", message, expectedCalls, targetDocument);
};
function expectNoEvents(message, targetDocument) {
debug(" " + message);
targetDocument = targetDocument !== undefined ? targetDocument : document;
eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
};
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 () {
expectNoEvents("Unlock.");
navigator.webkitPointer.unlock();
doNextStep();
},
function () {
expectOnlyChangeEvent("Lock targetDiv1.");
navigator.webkitPointer.lock(targetDiv1);
},
function () {
expectOnlyChangeEvent("Unlock again.");
navigator.webkitPointer.unlock();
},
function () {
expectOnlyChangeEvent("Lock targetDiv1 again.");
navigator.webkitPointer.lock(targetDiv1);
},
function () {
// FIXME: Only 1 change event should be expected.
// But, we will see 2 until we remove the old code for
// pointerlocklost and remove the call to didLosePointerLock
// made in PointerLockController::requestPointerLock.
// (https://bugs.webkit.org/show_bug.cgi?id=84402)
expectOnlyChangeEvent("Lock targetDiv2.", 2);
navigator.webkitPointer.lock(targetDiv2);
},
function () {
expectOnlyChangeEvent("Lock targetDiv2 again.");
navigator.webkitPointer.lock(targetDiv2);
},
function () {
expectNoEvents("Lock null.");
navigator.webkitPointer.lock(null);
doNextStep();
},
function () {
targetIframe1.src = "about:blank";
targetIframe1.onload = function () { doNextStep(); }
},
function () {
targetIframe2.src = "about:blank";
targetIframe2.onload = function () { doNextStep(); }
},
function () {
// FIXME: Only 1 change event should be expected.
// But, we will see 2 until we remove the old code for
// pointerlocklost and remove the call to didLosePointerLock
// made in PointerLockController::requestPointerLock.
// (https://bugs.webkit.org/show_bug.cgi?id=84402)
expectOnlyChangeEvent("Lock targetIframe1.", 2);
expectOnlyChangeEvent("Lock targetIframe1 (handler for iframe1).", 1, targetIframe1.contentDocument);
navigator.webkitPointer.lock(targetIframe1.contentDocument.body);
},
function () {
// Absorb an extra doNextStep() from previous event handlers.
},
function () {
expectNoEvents("Lock targetIframe2.");
// FIXME: Only 1 change event should be expected.
// But, we will see 2 until we remove the old code for
// pointerlocklost and remove the call to didLosePointerLock
// made in PointerLockController::requestPointerLock.
// (https://bugs.webkit.org/show_bug.cgi?id=84402)
expectOnlyChangeEvent("Lock targetIframe2 (handler for iframe1).", 2, targetIframe1.contentDocument);
expectOnlyChangeEvent("Lock targetIframe2 (handler for iframe2).", 1, targetIframe2.contentDocument);
navigator.webkitPointer.lock(targetIframe2.contentDocument.body);
},
function () {
// Absorb an extra doNextStep() from previous event handlers.
},
function () {
expectNoEvents("Unlock targetIframe2.");
expectNoEvents("Unlock targetIframe2 (handler for iframe1).", targetIframe1.contentDocument);
expectOnlyChangeEvent("Unlock targetIframe2 (handler for iframe2).", 1, targetIframe2.contentDocument);
navigator.webkitPointer.unlock();
},
function () {
shouldBeDefined("layoutTestController.setPointerLockWillFailSynchronously");
layoutTestController.setPointerLockWillFailSynchronously();
expectOnlyErrorEvent("Lock with synchronous failure.");
navigator.webkitPointer.lock(targetDiv1);
},
function () {
shouldBeDefined("layoutTestController.setPointerLockWillFailAsynchronously");
layoutTestController.setPointerLockWillFailAsynchronously();
expectOnlyErrorEvent("Lock with asynchronous failure.");
navigator.webkitPointer.lock(targetDiv1);
},
];
doNextStep();
</script>
<script src="../fast/js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -9,12 +9,16 @@ JavaScript initiated unlock.
PASS webkitpointerlocklost handler call 0
PASS webkitpointerlocklost handler call 1
PASS All expected webkitpointerlocklost events received.
PASS onwebkitpointerlockchange received.
PASS All expected onwebkitpointerlockchange events received.
PASS navigator.webkitPointer.isLocked is false
PASS navigator.webkitPointer.isLocked is true
Host initiated unlock.
PASS webkitpointerlocklost handler call 0
PASS webkitpointerlocklost handler call 1
PASS All expected webkitpointerlocklost events received.
PASS onwebkitpointerlockchange received.
PASS All expected onwebkitpointerlockchange events received.
PASS navigator.webkitPointer.isLocked is false
PASS successfullyParsed is true
......
......@@ -8,12 +8,32 @@
<div id="target"></div>
</div>
<script>
// FIXME: Rename this test to pointerlockchange-event-on-lock-lost. (https://bugs.webkit.org/show_bug.cgi?id=84402)
description("Test that pointerlocklost event is dispatched.")
window.jsTestIsAsync = true;
shouldBeDefined("window.layoutTestController");
targetdiv = document.getElementById("target");
// FIXME: Keep pointerlockchange and pointerlockerror event usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
document.onwebkitpointerlockchange = lockchangeToUnlockedHandler;
document.onwebkitpointerlockerror =
function () { testFailed("document.onwebkitpointerlockerror dispatched"); finishJSTest(); };
lockchangeToUnlockedHandlers = 1;
lockchangeToUnlockedReceipts = 0;
function lockchangeToUnlockedHandler() {
if (navigator.webkitPointer.isLocked == false) {
testPassed("onwebkitpointerlockchange received.");
lockchangeToUnlockedReceipts++;
if (lockchangeToUnlockedReceipts == lockchangeToUnlockedHandlers) {
testPassed("All expected onwebkitpointerlockchange events received.");
}
}
}
// FIXME: Remove pointerlocklost usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
document.addEventListener("webkitpointerlocklost", locklostHandler);
targetdiv.addEventListener("webkitpointerlocklost", locklostHandler);
locklosthandlers = 2;
......@@ -30,7 +50,7 @@
currentStep = 0;
function doNextStep() {
todo[currentStep++]();
setTimeout(function () { todo[currentStep++](); }, 0);
}
todo = [
function () {
......@@ -67,6 +87,7 @@
},
function () {
debug("Host initiated unlock.")
lockchangeToUnlockedReceipts = 0;
locklostreceipts = 0;
layoutTestController.didLosePointerLock();
},
......
2012-06-06 Vincent Scheib <scheib@chromium.org>
Add new Pointer Lock spec events webkitpointerlockchange and webkitpointerlockerror
https://bugs.webkit.org/show_bug.cgi?id=88377
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
New change and error events added. Follow up patches will remove
the previous callbacks and pointerlocklost event. Tests updated
to include the new events, and a new test added specifically for
the new events, pointerlockchange-pointerlockerror-events.html.
Test: pointer-lock/pointerlockchange-pointerlockerror-events.html
* dom/Document.h:
(Document):
* dom/Document.idl:
* dom/EventNames.h:
(WebCore):
* page/PointerLockController.cpp:
(WebCore::PointerLockController::requestPointerLock):
(WebCore::PointerLockController::didAcquirePointerLock):
(WebCore::PointerLockController::didNotAcquirePointerLock):
(WebCore::PointerLockController::didLosePointerLock):
(WebCore::PointerLockController::enqueueEvent):
(WebCore):
* page/PointerLockController.h:
(PointerLockController):
2012-06-07 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r119744.
......
......@@ -330,6 +330,10 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
#endif
#if ENABLE(POINTER_LOCK)
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockchange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockerror);
#endif
#if ENABLE(PAGE_VISIBILITY_API)
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange);
#endif
......
......@@ -330,6 +330,8 @@ module core {
attribute [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] EventListener ontouchcancel;
attribute [NotEnumerable, Conditional=FULLSCREEN_API] EventListener onwebkitfullscreenchange;
attribute [NotEnumerable, Conditional=FULLSCREEN_API] EventListener onwebkitfullscreenerror;
attribute [NotEnumerable, Conditional=POINTER_LOCK] EventListener onwebkitpointerlockchange;
attribute [NotEnumerable, Conditional=POINTER_LOCK] EventListener onwebkitpointerlockerror;
#endif
#if defined(ENABLE_TOUCH_EVENTS) && ENABLE_TOUCH_EVENTS
......
......@@ -220,6 +220,8 @@ namespace WebCore {
macro(show) \
\
macro(webkitpointerlocklost) \
macro(webkitpointerlockchange) \
macro(webkitpointerlockerror) \
\
macro(webkitRegionLayoutUpdate) \
\
......
......@@ -48,7 +48,16 @@ PassOwnPtr<PointerLockController> PointerLockController::create(Page* page)
void PointerLockController::requestPointerLock(Element* target, PassRefPtr<VoidCallback> successCallback, PassRefPtr<VoidCallback> failureCallback)
{
if (!target)
return;
if (isLocked()) {
// FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
enqueueEvent(eventNames().webkitpointerlockchangeEvent, target);
if (m_element->document() != target->document())
enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element.get());
// FIXME: Remove callback usage, keep assignment of m_element = target. (https://bugs.webkit.org/show_bug.cgi?id=84402)
if (m_element == target) {
if (successCallback)
successCallback->handleEvent();
......@@ -62,8 +71,14 @@ void PointerLockController::requestPointerLock(Element* target, PassRefPtr<VoidC
m_element = target;
m_successCallback = successCallback;
m_failureCallback = failureCallback;
} else if (failureCallback)
failureCallback->handleEvent();
} else {
// FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
// FIXME: Remove callback usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
if (failureCallback)
failureCallback->handleEvent();
}
}
void PointerLockController::requestPointerUnlock()
......@@ -78,6 +93,10 @@ bool PointerLockController::isLocked()
void PointerLockController::didAcquirePointerLock()
{
// FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element.get());
// FIXME: Remove callback usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
RefPtr<Element> elementToNotify(m_element);
RefPtr<VoidCallback> callbackToIssue(m_successCallback);
m_successCallback = 0;
......@@ -89,6 +108,10 @@ void PointerLockController::didAcquirePointerLock()
void PointerLockController::didNotAcquirePointerLock()
{
// FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
enqueueEvent(eventNames().webkitpointerlockerrorEvent, m_element.get());
// FIXME: Remove callback usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
RefPtr<Element> elementToNotify(m_element);
RefPtr<VoidCallback> callbackToIssue(m_failureCallback);
m_element = 0;
......@@ -101,6 +124,10 @@ void PointerLockController::didNotAcquirePointerLock()
void PointerLockController::didLosePointerLock()
{
// FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element.get());
// FIXME: Remove callback usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
RefPtr<Element> elementToNotify(m_element);
m_element = 0;
m_successCallback = 0;
......@@ -121,6 +148,13 @@ void PointerLockController::dispatchLockedMouseEvent(const PlatformMouseEvent& e
m_element->dispatchMouseEvent(event, eventNames().clickEvent, event.clickCount());
}
void PointerLockController::enqueueEvent(const AtomicString& type, Element* element)
{
if (!element)
return;
element->document()->enqueueDocumentEvent(Event::create(type, true, false));
}
} // namespace WebCore
#endif // ENABLE(POINTER_LOCK)
......@@ -54,8 +54,11 @@ public:
private:
explicit PointerLockController(Page*);
void enqueueEvent(const AtomicString& type, Element*);
Page* m_page;
RefPtr<Element> m_element;
// FIXME: Remove callback usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
RefPtr<VoidCallback> m_successCallback;
RefPtr<VoidCallback> m_failureCallback;
};
......
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