You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
Cmd-Arrow native keybindings and navigation shortcuts conflict #317
In the child process, Cmd-Arrow can be used to move the cursor in an input element. In the main process it's used to navigate (goBack/goForward). The event listeners in the child process should be able to cancel the parent process event.
changed the title [-]keyboard.js blocks the "Cmd-Arrow" native keybindings[/-][+]Cmd-Arrow native keybindings and navigation shortcuts conflict[/+]on Apr 17, 2015
When I type cmd left in the textarea of the tab, keyboard events are fired in the parent process and we navigate page back & preventDefault(). If I get rid of preventDefault() everything seems work fine. I find this really add, I was assuming the event will propagate from content process (if not prevented) to a parent process. But it seems reverse meaning parent process get's event first and if it prevents default it does not even reaches a content process. What I can not explain is how is that removing .preventDefault() in parent fixes the issue, or to be more clear how is it that we do not navigate page back ?
Correction for my last comment, in fact event we do navigate page back / forward it's just in my test I could not go back / forward there for I observed correct behavior in the child process and nothing happend in chrome process.
What does seem to happen is that keyboard event Meta Left / Meta Right keyboard events are dispatche in the parent process first and then if default isn't prevented associated command is executed in the content process.
I can not tell if that is by a design or if it is a bug, if that is by a design that seems odd as it is reverse of how how events would have propagated if iframe was within the same process.
I also looked up history to find out when .preventDefault() was introduced and it was in #236 although as far as I can tell we only needed .stopPropagation(). So I think we could remove .preventDefault which would resolve issue if you can not go back / forward. Although we still need a real fix for this though.
how events would have propagated if iframe was within the same process.
I think you're assuming events propagate through iframes the same way they propagate through the DOM (propagating and bubbling). I don't think this is the case for content docshells. It's only the case of chrome docshells.
So in non e10s desktop firefox you could listen for content events on docShell.chromeEventHandler not sure how is that done in e10 though.
Either way the problem is there are two handlers for the same event one in child and other in parent, and parent needs to handle it only if child does not do it. If event is fired on parent first there seems no way of knowing if child is going to handling that event as well or not.
Posting quote from the coverastion with Felipe about how it's done on desktop:
gozala: I'm trying to figure out how does Meta ArrowLeft keybinding works in E10S, was wondering if you could provide me some input gozala: I'm trynig to do something on b2g desktop and seems like parent process event handler is invoked first and only after event goes to child process and runs command on input field gozala: I'm wondering how on desktop FF we do not invoke goBack if you're in the input field in the child process gozala: and we do invoke it otherwise felipe: basically if anything calls preventDefault, we do not invoke the handlers felipe: and the html input code calls preventDefault for backspace gozala: so does event gets dispatched in child process first ? felipe: are you more interested in knowing who calls preventDefault, or how calling it will prevent the keybinding from running? felipe: ok gozala: it seems that event is dispatched in the parent process first in b2g desktop felipe: it gets dispatched in the parent, but it's captured early on and propagation stopped. We then dispatch it in child, wait for an answer, and redispatch it in the parent
I suspect that b2g shell does that event propagation to a child that felipe descripted after event boubbles from our index.html that is why preventing it never delegates to a child process. And not preventing it does navigation back. Looks like b2g shell should use capture phase for that event handler in order for this to work as expected.
We have code in the platform that handles this in the way I described (so, it's not in the frontend), but it's probably not used by b2g because it's XUL/XBL code. Probably you could try to replicate the same thing in the b2g shell.
Here's how it works:
nsXBLWindowKeyHandler is the class that implements the key event handlers. It has two listeners, one in the capturing phase and one in the bubbling phase.
Now the normal handling happens through the bubbling listener of nsXBLWindowKeyHandler, which runs the appropriate command.
If there's no command listened for this key combination, this waiting on the reply won't happen, and both events will bubble in "parallel" in the parent and the child
I feel like most reasonable way to go about this would be to check an event.target of the keyboard / mouse event and if it is a remote iframe cancell it and dispatch on child (as described by @felipc), check status set by a child and then re-dispatch on chrome. That way I would expect that index.html will get to see only re-dispatched events & onyl if the child has not cancelled them. I would also expect index.html to be able to handle event before the child, if capture phase was used so it could prevent it from ever reaching a child. I'd expect this should be achievable from b2g shell by using both capture and bouble phase event handlers.
That way event propagation will follow familiar event propagation model even though it's going to cross process boundries.
P.S.: Makes me wonder how does chrome apps browser elements do this.
Activity
Gozala commentedon Apr 17, 2015
Looks like issue is not with bouble phase as it's what we use, but with
event.preventDefault()[-]keyboard.js blocks the "Cmd-Arrow" native keybindings[/-][+]Cmd-Arrow native keybindings and navigation shortcuts conflict[/+]Gozala commentedon Apr 17, 2015
So my understanding what's going on is:
When I type
cmd leftin the textarea of the tab, keyboard events are fired in the parent process and we navigate page back &preventDefault(). If I get rid ofpreventDefault()everything seems work fine. I find this really add, I was assuming the event will propagate from content process (if not prevented) to a parent process. But it seems reverse meaning parent process get's event first and if it prevents default it does not even reaches a content process. What I can not explain is how is that removing.preventDefault()in parent fixes the issue, or to be more clear how is it that we do not navigate page back ?Gozala commentedon Apr 17, 2015
Correction for my last comment, in fact event we do navigate page back / forward it's just in my test I could not go back / forward there for I observed correct behavior in the child process and nothing happend in chrome process.
What does seem to happen is that keyboard event
Meta Left/Meta Rightkeyboard events are dispatche in the parent process first and then if default isn't prevented associated command is executed in the content process.I can not tell if that is by a design or if it is a bug, if that is by a design that seems odd as it is reverse of how how events would have propagated if iframe was within the same process.
Gozala commentedon Apr 17, 2015
I also looked up history to find out when
.preventDefault()was introduced and it was in #236 although as far as I can tell we only needed.stopPropagation(). So I think we could remove.preventDefaultwhich would resolve issue if you can not go back / forward. Although we still need a real fix for this though.paulrouget commentedon Apr 17, 2015
I think you're assuming events propagate through iframes the same way they propagate through the DOM (propagating and bubbling). I don't think this is the case for content docshells. It's only the case of chrome docshells.
Gozala commentedon Apr 17, 2015
So in non e10s desktop firefox you could listen for content events on docShell.chromeEventHandler not sure how is that done in e10 though.
Either way the problem is there are two handlers for the same event one in child and other in parent, and parent needs to handle it only if child does not do it. If event is fired on parent first there seems no way of knowing if child is going to handling that event as well or not.
Gozala commentedon Apr 17, 2015
Posting quote from the coverastion with Felipe about how it's done on desktop:
Gozala commentedon Apr 17, 2015
I suspect that b2g shell does that event propagation to a child that felipe descripted after event boubbles from our
index.htmlthat is why preventing it never delegates to a child process. And not preventing it does navigation back. Looks like b2g shell should use capture phase for that event handler in order for this to work as expected.felipc commentedon Apr 17, 2015
We have code in the platform that handles this in the way I described (so, it's not in the frontend), but it's probably not used by b2g because it's XUL/XBL code. Probably you could try to replicate the same thing in the b2g shell.
Here's how it works:
nsXBLWindowKeyHandler is the class that implements the key event handlers. It has two listeners, one in the capturing phase and one in the bubbling phase.
In the capturing phase (https://dxr.mozilla.org/mozilla-central/source/dom/xbl/nsXBLWindowKeyHandler.cpp#321), when the event happens, it checks to see if the key combination is used as a shortcut key* (i.e., if there's a for it, https://dxr.mozilla.org/mozilla-central/source/browser/base/content/browser-sets.inc).
If that's the case, it sets a flag on the event (mWantReplyFromContentProcess) and stops its propagation. After the event is forwarded to the child (which is done automatically for all key/mouse events), if that flag was flag, TabParent will receive a message with the status of the event from the child (https://dxr.mozilla.org/mozilla-central/source/dom/ipc/TabChild.cpp#2512), and redispatch it in the parent (with the correct preventedDefault flag).
Now the normal handling happens through the bubbling listener of nsXBLWindowKeyHandler, which runs the appropriate command.
Gozala commentedon Apr 17, 2015
I feel like most reasonable way to go about this would be to check an
event.targetof the keyboard / mouse event and if it is a remote iframe cancell it and dispatch on child (as described by @felipc), check status set by a child and then re-dispatch on chrome. That way I would expect thatindex.htmlwill get to see only re-dispatched events & onyl if the child has not cancelled them. I would also expectindex.htmlto be able to handle event before the child, if capture phase was used so it could prevent it from ever reaching a child. I'd expect this should be achievable from b2g shell by using both capture and bouble phase event handlers.That way event propagation will follow familiar event propagation model even though it's going to cross process boundries.
P.S.: Makes me wonder how does chrome apps browser elements do this.
Gozala commentedon Jan 12, 2016
Our target runtime is on Servo so no point in keeping gecko issues open.