Bug 1463576 - 5. Use docshell commands for selection actions; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Fri, 01 Jun 2018 13:39:21 -0400
changeset 802942 82753a2b34abd231a6096981cce1c119cf1dde9d
parent 802941 0e035e93f52e18d2be4539269dad4fa57620b4bf
child 802943 477ceef33a03c8788e7423bd8217cb715efe98b6
push id112001
push userbmo:nchen@mozilla.com
push dateFri, 01 Jun 2018 17:40:20 +0000
reviewerssnorp
bugs1463576
milestone62.0a1
Bug 1463576 - 5. Use docshell commands for selection actions; r?snorp Use nsIDocShell.doCommand to perform selection actions, in order to simplify code in GeckoViewSelectionActionContent. MozReview-Commit-ID: IWVh7XfQ5l8
mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
--- a/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
+++ b/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
@@ -18,88 +18,62 @@ class GeckoViewSelectionActionContent ex
 
     this._seqNo = 0;
     this._isActive = false;
     this._previousMessage = {};
 
     this._actions = [{
       id: "org.mozilla.geckoview.CUT",
       predicate: e => !e.collapsed && e.selectionEditable && !this._isPasswordField(e),
-      perform: _ => this._domWindowUtils.sendContentCommandEvent("cut"),
+      perform: _ => docShell.doCommand("cmd_cut"),
     }, {
       id: "org.mozilla.geckoview.COPY",
       predicate: e => !e.collapsed && !this._isPasswordField(e),
-      perform: _ => this._domWindowUtils.sendContentCommandEvent("copy"),
+      perform: _ => docShell.doCommand("cmd_copy"),
     }, {
       id: "org.mozilla.geckoview.PASTE",
       predicate: e => e.selectionEditable &&
                       Services.clipboard.hasDataMatchingFlavors(
                           ["text/unicode"], 1, Ci.nsIClipboard.kGlobalClipboard),
-      perform: _ => this._domWindowUtils.sendContentCommandEvent("paste"),
+      perform: _ => docShell.doCommand("cmd_paste"),
     }, {
       id: "org.mozilla.geckoview.DELETE",
       predicate: e => !e.collapsed && e.selectionEditable,
-      perform: _ => this._domWindowUtils.sendContentCommandEvent("delete"),
+      perform: _ => docShell.doCommand("cmd_delete"),
     }, {
       id: "org.mozilla.geckoview.COLLAPSE_TO_START",
       predicate: e => !e.collapsed && e.selectionEditable,
-      perform: e => this._getSelection(e).collapseToStart(),
+      perform: e => docShell.doCommand("cmd_moveLeft"),
     }, {
       id: "org.mozilla.geckoview.COLLAPSE_TO_END",
       predicate: e => !e.collapsed && e.selectionEditable,
-      perform: e => this._getSelection(e).collapseToEnd(),
+      perform: e => docShell.doCommand("cmd_moveRight"),
     }, {
       id: "org.mozilla.geckoview.UNSELECT",
       predicate: e => !e.collapsed && !e.selectionEditable,
-      perform: e => this._getSelection(e).removeAllRanges(),
+      perform: e => docShell.doCommand("cmd_selectNone"),
     }, {
       id: "org.mozilla.geckoview.SELECT_ALL",
       predicate: e => e.reason !== "longpressonemptycontent",
-      perform: e => this._getSelectionController(e).selectAll(),
+      perform: e => docShell.doCommand("cmd_selectAll"),
     }];
   }
 
-  get _domWindowUtils() {
-    return content.QueryInterface(Ci.nsIInterfaceRequestor)
-                  .getInterface(Ci.nsIDOMWindowUtils);
-  }
-
   _isPasswordField(aEvent) {
     if (!aEvent.selectionEditable) {
       return false;
     }
 
     const win = aEvent.target.defaultView;
     const focus = aEvent.target.activeElement;
     return win && win.HTMLInputElement &&
            focus instanceof win.HTMLInputElement &&
            !focus.mozIsTextField(/* excludePassword */ true);
   }
 
-  _getSelectionController(aEvent) {
-    if (aEvent.selectionEditable) {
-      const focus = aEvent.target.activeElement;
-      if (focus instanceof Ci.nsIDOMNSEditableElement && focus.editor) {
-        return focus.editor.selectionController;
-      }
-    }
-
-    return aEvent.target.defaultView
-                 .QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsIDocShell)
-                 .QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsISelectionDisplay)
-                 .QueryInterface(Ci.nsISelectionController);
-  }
-
-  _getSelection(aEvent) {
-    return this._getSelectionController(aEvent)
-               .getSelection(Ci.nsISelectionController.SELECTION_NORMAL);
-  }
-
   _getFrameOffset(aEvent) {
     // Get correct offset in case of nested iframe.
     const offset = {
       left: 0,
       top: 0,
     };
 
     let currentWindow = aEvent.target.defaultView;