I’ve been working on another task in the MouseLock implementation: When ESC key is pressed, mouse lock should exit.

I’ve been going through mxr, dxr and comments in other mozilla bugs, and came up with the following code that we might need to check for the ESC key press:

nsEvent* aEvent;
  const nsKeyEvent* keyEvent = static_cast<const nsKeyEvent*>(aEvent);
  int key = keyEvent->keyCode ? keyEvent->keyCode : keyEvent->charCode;
  
  if (key == NS_VK_ESCAPE) {  
	  fprintf(stderr, "Escape key is pressed!");
	  mIsLocked = PR_FALSE;
  }

However, it doesn’t work for now.

It builds if I insert it in the lock method for now, but I am not sure how to make it work. How will the lock/unlock method know to listen for this event? I am not sure how to implement that in c++ yet…will continue working on that.

Also, to those who need help setting up Visual Studio as their FF debugger on Windows: and https://developer.mozilla.org/en/Debugging_Mozilla_on_Windows_FAQ

—————————

Update:

Just found this piece of code:

// if we can use the keyboard (eg Ctrl+L or Ctrl+E) to open the toolbars, we
// should provide a way to collapse them too.
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) {
   FullScreen._shouldAnimate = false;
   FullScreen.mouseoverToggle(false, true);
}

http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#4027

Maybe we should also have a variable like _shouldMouseLock. On pressing ESC we can set it to false, and it could trigger the unlock() method. We could use the same variable to trigger unlock when the browser/window/tab loses focus.

2 responses


Do you want to comment?

Comments RSS and TrackBack Identifier URI ?


I wrote the code in nsPresShell.cpp which you quoted. I think you’ll want to do something like that.

Take a look at:
http://mxr.mozilla.org/mozilla-central/source/layout/base/nsPresShell.cpp#6372

You probably want to do something similar to that, e.g. have a flag on the nsIDocument/nsPIDOMWindow which has locked the mouse (I don’t know your API, so I don’t know which of these it should be), and check that when the ESC key is pressed.

There’s actually a tree of nsIDocuments (one for each in the page) but nsPresShell::HandleEventInternal() is only called on the *focused* iframe’s nsPresShell (which is basically the nsIDocument’s container). So if a subdocument of the mouse-locked subdocument is focused and ESC is pressed, you’ll still want to break out of mouse-lock (I assume?) so you’ll need to handle that case too.

I’m cpearce on IRC, ping me on IRC or email me if you have questions.

November 21, 2011 4:27 pm

Comment now!