Qooxdoo: Forward iframe key events to parent application

  // To make global shortcuts work even if focus is within the iframe,
  // we have to intercept events manually.
  var sendKeyEventToParent = function(domEvent) {
    var qx = window.parent.qx;

    // Ideally we could direct everything to the Keyboard handlers own
    // input function (handler.__onKeyPress), but they marked it private
    // - thanks Qooxdoo. See also:
    // http://qooxdoo.678.n2.nabble.com/Inject-Keyboard-events-on-Qooxdoo-td7268755.html
    //
    // Instead, we'll have to use a later entry point which misses a
    // lot of browser specific normalizations, which I hope we won't
    // miss (stuff like trigger a keypress for non-printable characters
    // like UP or DOWN really might).
    //
    // An alternative would be missing even more Qooxdoo default
    // processing and triggering a Qooxdoo event for each ifrae DOM
    // event manually in the parent using qx.event.Registration.fireEvent().
    var handler = qx.event.Registration.getManager(window.parent)
      .getHandler(qx.event.handler.Keyboard);

    // See qx.event.handler.Keyboard for how these calls where constructed
    if (domEvent.type == 'keypress') {
      if (handler._charCode2KeyCode[domEvent.keyCode]) {
        handler._idealKeyHandler(
          handler._charCode2KeyCode[domEvent.keyCode], 0,
          domEvent.type, domEvent);
      } else {
        handler._idealKeyHandler(0, domEvent.keyCode, domEvent.type, domEvent);
      }
    }
    else
      // keyup, keydown
      handler._idealKeyHandler(domEvent.keyCode, 0, domEvent.type, domEvent);
  };
  this.documentNode.addEventListener('keydown', sendKeyEventToParent, true);
  this.documentNode.addEventListener('keyup', sendKeyEventToParent, true);
  this.documentNode.addEventListener('keypress', sendKeyEventToParent, true);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s