[Building on the "Mouse Capture for Canvas" thread:
http://lists.w3.org/Archives/Public/public-webapps/2011JanMar/thread.html#msg437
]
I'm working on an implementation of mouse lock in Chrome, and would
appreciate collaboration on refinement of the spec proposal. Hopefully
webapps is willing to pick up this spec work? I'm up for helping write the
draft.
Some updates from Sirisian's Comment 12 on the w3 bug (
http://www.w3.org/Bugs/Public/show_bug.cgi?id=9557#c12):
- We shouldn't need events for success/failure to obtain lock, those can be
callbacks similar to geolocation API: (
http://dev.w3.org/geo/api/spec-source.html#geolocation_interface).
My short summary is then:
- 2 new methods on an element to enter and exit mouse lock. Two callbacks on
the entering call provide notification of success or failure.
- Mousemove event gains .deltaX .deltaY members, always valid, not just
during mouse lock.
- Elements have an event to detect when mouseLock is lost.
Example
x = document.getElementById("x");
x.addEventListener("mousemove", mouseMove);
x.addEventListener("mouseLockLost", mouseLockLost);
x.lockMouse(
function() { console.log("Locked."); },
function() { console.log("Lock rejected."); } );
function mouseMove(e) { console.log(e.deltaX + ", " + e.deltaY); }
function mouseLockLost(e) { console.log("Lost lock."); }