From MozillaWiki
Jump to: navigation, search

Selection information and copy-paste interface in Browser API

This is a proposal to allow mozbrowser parent to mutate a selection range (editable and non-editable), and interact with clipboard indirectly. The mozbrowser parent (System app in Gaia) is responsible for drawing a "popup" when the user selects the text. Gecko remain responsible for drawing the caret, and the touch handle for the caret.

New events


This event should fire when the user selects a range of text. Note that since the UX spec specifies holding an empty input box for some time constitutes a select action, the event should also fire in that occasion with empty selection range (but the boundingClientRect should still valid (is this possible?)

Expose the following detail dict for the parent frame to show a control for copy-paste. Or, make the detail null to indicate the menu should go away.

The parent frame SHOULD call evt.preventDefault(); if it has handled the event.

 detail: {
   /* a TextRectangle object representing the dimension of the selection */
   boundingClientRect: (TextRectangle),
   /* whether or not the user have select the entire selectable range starting from the current position. */
   canSelectAll: (Boolean),
   /* whether or not the user could copy and remove the text in the range.
      Gecko should avoid content like passwords being copied. */
   canCut: (Boolean),
   /* whether or not the user could copy the text in the range.
      Gecko should avoid content like passwords being copied. */
   canCopy: (Boolean),
   /* whether or not the user could paste into the range.
      Supposedly, only editable content is pastable; Gecko might(?) be responsive to what currently holds in the clipboard too. */
   canPaste: (Boolean),
   /* the text representing the selection, for use case like implementing "Twit selection" or "Look up dictionary" buttons.
      there is no request for the feature now so we will not implementing this for now. (we might have privacy issue on this one too)
   text: (DOMString)

New methods




These methods allow mozbrowser parent/grandparent to work with selection and clipboard.


Expand the selection to the entire selectable range (like what Ctrl+A do) from the current selection.

Special glue for System app

The embeder of the System app is the outer chrome document. System app cannot use this API to control it's own inputs nor contents. To workaround that we would put a series of mozChromeEvent/mozContentEvent events in shell.js to relay the controls.

Passing the event to the grandparent frame

If the event is not handled by the parent frame, (i.e. preventDefault() is not called), the default action of the event is to dispatch the same event on the outer "grandparent" mozbrowser frame, with it's TextRectangle object information properly updated to be relative to the parent frame.

We do this to make sure text input in the current Browser app tabs (i.e. the grandson mozbrower frame of the System app) can be handled by the System app.