Skip to content
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
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

Closed

Description

@paulrouget

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.

Activity

  1. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    Looks like issue is not with bouble phase as it's what we use, but with event.preventDefault()

  2. changed the title [-]keyboard.js blocks the "Cmd-Arrow" native keybindings[/-] [+]Cmd-Arrow native keybindings and navigation shortcuts conflict[/+] on Apr 17, 2015
  3. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    So my understanding what's going on is:

    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 ?

  4. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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.

  5. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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.

  6. paulrouget commented on Apr 17, 2015

    @paulrouget
    ContributorAuthor

    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.

  7. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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.

  8. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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

  9. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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.

  10. felipc commented on Apr 17, 2015

    @felipc

    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.

    • 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
  11. Gozala commented on Apr 17, 2015

    @Gozala
    Contributor

    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.

  12. Gozala commented on Jan 12, 2016

    @Gozala
    Contributor

    Our target runtime is on Servo so no point in keeping gecko issues open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions