Bug 842997 - Make SelectionHelperUI startup entry points json message agnostic. r=fyan
authorJim Mathies <jmathies@mozilla.com>
Tue, 19 Mar 2013 12:43:17 -0500
changeset 125461 52007e7e160267266948ed0b17048c00333a9259
parent 125460 f999416ea0478e2e9552c5125b57827f2b4d4a84
child 125462 d54c51456af56a2215bd52ba6057cbac51bdc611
push id24459
push useremorley@mozilla.com
push dateWed, 20 Mar 2013 11:46:36 +0000
treeherdermozilla-central@1d6fe70c79c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfyan
bugs842997
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 842997 - Make SelectionHelperUI startup entry points json message agnostic. r=fyan
browser/metro/base/content/BrowserTouchHandler.js
browser/metro/base/content/ContextCommands.js
browser/metro/base/content/helperui/SelectionHelperUI.js
browser/metro/base/content/input.js
--- a/browser/metro/base/content/BrowserTouchHandler.js
+++ b/browser/metro/base/content/BrowserTouchHandler.js
@@ -17,28 +17,31 @@ const BrowserTouchHandler = {
     // Messages sent from content.js
     messageManager.addMessageListener("Content:ContextMenu", this);
   },
 
   // Content forwarding the contextmenu command
   onContentContextMenu: function onContentContextMenu(aMessage) {
     // Note, target here is the target of the message manager message,
     // usually the browser.
-    let contextInfo = { name: aMessage.name,
-                        json: aMessage.json,
-                        target: aMessage.target };
     // Touch input selection handling
-    if (!InputSourceHelper.isPrecise && !SelectionHelperUI.isActive &&
-        SelectionHelperUI.canHandle(aMessage)) {
-      SelectionHelperUI.openEditSession(aMessage);
+    if (!InputSourceHelper.isPrecise &&
+        !SelectionHelperUI.isActive &&
+        SelectionHelperUI.canHandleContextMenuMsg(aMessage)) {
+      SelectionHelperUI.openEditSession(aMessage.target,
+                                        aMessage.json.xPos,
+                                        aMessage.json.yPos);
       return;
     }
 
     // Check to see if we have context menu item(s) that apply to what
     // was clicked on.
+    let contextInfo = { name: aMessage.name,
+                        json: aMessage.json,
+                        target: aMessage.target };
     if (ContextMenuUI.showContextMenu(contextInfo)) {
       let event = document.createEvent("Events");
       event.initEvent("CancelTouchSequence", true, false);
       document.dispatchEvent(event);
     } else {
       // Send the MozEdgeUIGesture to input.js to
       // toggle the context ui.
       let event = document.createEvent("Events");
--- a/browser/metro/base/content/ContextCommands.js
+++ b/browser/metro/base/content/ContextCommands.js
@@ -95,34 +95,30 @@ var ContextCommands = {
   pasteAndGo: function cc_pasteAndGo() {
     let target = ContextMenuUI.popupState.target;
     target.editor.selectAll();
     target.editor.paste(Ci.nsIClipboard.kGlobalClipboard);
     BrowserUI.goToURI();
   },
 
   select: function cc_select() {
-    let contextInfo = { name: "",
-                        json: ContextMenuUI.popupState,
-                        target: ContextMenuUI.popupState.target };
-    SelectionHelperUI.openEditSession(contextInfo);
+    SelectionHelperUI.openEditSession(ContextMenuUI.popupState.target,
+                                      ContextMenuUI.popupState.xPos,
+                                      ContextMenuUI.popupState.yPos);
   },
 
   selectAll: function cc_selectAll() {
     let target = ContextMenuUI.popupState.target;
     if (target.localName == "browser") {
       // content
-      let x = ContextMenuUI.popupState.x;
-      let y = ContextMenuUI.popupState.y;
+      let x = ContextMenuUI.popupState.xPos;
+      let y = ContextMenuUI.popupState.yPos;
       let json = {x: x, y: y, command: "select-all" };
       target.messageManager.sendAsyncMessage("Browser:ContextCommand", json);
-      let contextInfo = { name: "",
-                          json: ContextMenuUI.popupState,
-                          target: ContextMenuUI.popupState.target };
-      SelectionHelperUI.attachEditSession(contextInfo);
+      SelectionHelperUI.attachEditSession(target, x, y);
     } else {
       // chrome
       target.editor.selectAll();
       target.focus();
     }
   },
 
   // called on display of the search text menu item
--- a/browser/metro/base/content/helperui/SelectionHelperUI.js
+++ b/browser/metro/base/content/helperui/SelectionHelperUI.js
@@ -186,17 +186,17 @@ Marker.prototype = {
 };
 
 /*
  * SelectionHelperUI
  */
 
 var SelectionHelperUI = {
   _debugEvents: false,
-  _popupState: null,
+  _msgTarget: null,
   _startMark: null,
   _endMark: null,
   _target: null,
   _movement: { active: false, x:0, y: 0 },
   _activeSelectionRect: null,
   _selectionHandlerActive: false,
 
   get startMark() {
@@ -218,101 +218,81 @@ var SelectionHelperUI = {
   },
 
   /*
    * openEditSession
    * 
    * Attempts to select underlying text at a point and begins editing
    * the section.
    */
-  openEditSession: function openEditSession(aMessage) {
-     /*
-     * aMessage - from _onContentContextMenu in ContextMenuHandler
-     *  name: aMessage.name,
-     *  target: aMessage.target
-     *  json:
-     *   types: [],
-     *   label: "",
-     *   linkURL: "",
-     *   linkTitle: "",
-     *   linkProtocol: null,
-     *   mediaURL: "",
-     *   xPos: aEvent.x,
-     *   yPos: aEvent.y
-     */
-
-    this._popupState = aMessage.json;
-    this._popupState._target = aMessage.target;
-
-    this._init();
+  openEditSession: function openEditSession(aContent, aClientX, aClientY) {
+    if (!aContent || this.isActive)
+      return;
+    this._init(aContent);
 
     // Set the track bounds for each marker NIY
-    this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
-    this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
+    this.startMark.setTrackBounds(aClientX, aClientY);
+    this.endMark.setTrackBounds(aClientX, aClientY);
 
     // Send this over to SelectionHandler in content, they'll message us
     // back with information on the current selection. SelectionStart
     // takes client coordinates.
     this._selectionHandlerActive = false;
     this._sendAsyncMessage("Browser:SelectionStart", {
-      xPos: this._popupState.xPos,
-      yPos: this._popupState.yPos
+      xPos: aClientX,
+      yPos: aClientY
     });
 
     this._setupDebugOptions();
   },
 
   /*
    * attachEditSession
    * 
    * Attaches to existing selection and begins editing.
    */
-  attachEditSession: function attachEditSession(aMessage) {
-    if (aMessage.target == undefined)
+  attachEditSession: function attachEditSession(aContent, aClientX, aClientY) {
+    if (!aContent || this.isActive)
       return;
-    this._popupState = aMessage.json;
-    this._popupState._target = aMessage.target;
-
-    this._init();
+    this._init(aContent);
 
     // Set the track bounds for each marker NIY
-    this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
-    this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
+    this.startMark.setTrackBounds(aClientX, aClientY);
+    this.endMark.setTrackBounds(aClientX, aClientY);
 
     // Send this over to SelectionHandler in content, they'll message us
     // back with information on the current selection. SelectionAttach
     // takes client coordinates.
     this._selectionHandlerActive = false;
-    this._popupState._target.messageManager.sendAsyncMessage(
-      "Browser:SelectionAttach",
-      { xPos: this._popupState.xPos,
-        yPos: this._popupState.yPos });
+    this._sendAsyncMessage("Browser:SelectionAttach", {
+      xPos: aClientX,
+      yPos: aClientY
+    });
 
     this._setupDebugOptions();
   },
 
   /*
-   * canHandle
+   * canHandleContextMenuMsg
    *
    * Determines if we can handle a ContextMenuHandler message.
    */
-  canHandle: function canHandle(aMessage) {
+  canHandleContextMenuMsg: function canHandleContextMenuMsg(aMessage) {
     if (aMessage.json.types.indexOf("content-text") != -1)
       return true;
     return false;
   },
 
   /*
    * isActive (prop)
    *
    * Determines if an edit session is currently active.
    */
   get isActive() {
-    return (this._popupState != null &&
-            this._popupState._target != null &&
+    return (this._msgTarget &&
             this._selectionHandlerActive);
   },
 
   /*
    * closeEditSession
    *
    * Closes an active edit session and shuts down. Does not clear existing
    * selection regions if they exist.
@@ -332,17 +312,20 @@ var SelectionHelperUI = {
     this._sendAsyncMessage("Browser:SelectionClear");
     this.closeEditSession();
   },
 
   /*
    * Internal
    */
 
-  _init: function _init() {
+  _init: function _init(aMsgTarget) {
+    // store the target message manager
+    this._msgTarget = aMsgTarget;
+
     // SelectionHandler messages
     messageManager.addMessageListener("Content:SelectionRange", this);
     messageManager.addMessageListener("Content:SelectionCopied", this);
     messageManager.addMessageListener("Content:SelectionFail", this);
     messageManager.addMessageListener("Content:SelectionDebugRect", this);
 
     // selection related events
     window.addEventListener("click", this, false);
@@ -394,17 +377,17 @@ var SelectionHelperUI = {
     if (this.startMark != null)
       this.startMark.shutdown();
     if (this.endMark != null)
       this.endMark.shutdown();
 
     delete this._startMark;
     delete this._endMark;
 
-    this._popupState = null;
+    this._msgTarget = null;
     this._activeSelectionRect = null;
     this._selectionHandlerActive = false;
 
     this.overlay.displayDebugLayer = false;
     this.overlay.enabled = false;
   },
 
   /*
@@ -439,22 +422,22 @@ var SelectionHelperUI = {
     }
   },
 
   /*
    * _sendAsyncMessage - helper for sending a message to
    * SelectionHandler.
    */
   _sendAsyncMessage: function _sendAsyncMessage(aMsg, aJson) {
-    if (!this._popupState || !this._popupState._target) {
+    if (!this._msgTarget) {
       if (this._debugEvents)
         Util.dumpLn("SelectionHelperUI sendAsyncMessage could not send", aMsg);
       return;
     }
-    this._popupState._target.messageManager.sendAsyncMessage(aMsg, aJson);
+    this._msgTarget.messageManager.sendAsyncMessage(aMsg, aJson);
   },
 
   _checkForActiveDrag: function _checkForActiveDrag() {
     return (this.startMark.dragging || this.endMark.dragging);
   },
 
   _hitTestSelection: function _hitTestSelection(aEvent) {
     // Ignore if the double tap isn't on our active selection rect.
@@ -641,30 +624,16 @@ var SelectionHelperUI = {
     }
   },
 
   /*
    * Callbacks from markers
    */
 
   _getMarkerBaseMessage: function _getMarkerBaseMessage() {
-  /*
-    This appears to be adjusted for scroll and scale. It should only
-    adjust for scale, content handles scroll offsets.
-    let startPos =
-      this._popupState._target.transformBrowserToClient(this.startMark.xPos,
-                                                        this.startMark.yPos);
-    let endPos =
-      this._popupState._target.transformBrowserToClient(this.endMark.xPos,
-                                                        this.endMark.yPos);
-    return {
-      start: { xPos: startPos.x, yPos: startPos.y },
-      end: { xPos: endPos.x, yPos: endPos.y },
-    };
-    */
     return {
       start: { xPos: this.startMark.xPos, yPos: this.startMark.yPos },
       end: { xPos: this.endMark.xPos, yPos: this.endMark.yPos },
     };
   },
 
   markerDragStart: function markerDragStart(aMarker) {
     let json = this._getMarkerBaseMessage();
--- a/browser/metro/base/content/input.js
+++ b/browser/metro/base/content/input.js
@@ -142,20 +142,18 @@ var TouchModule = {
             this._onTouchEnd(aEvent);
             break;
           case "dblclick":
             // XXX This will get picked up somewhere below us for "double tap to zoom"
             // once we get omtc and the apzc. Currently though dblclick is delivered to
             // content and triggers selection of text, so fire up the SelectionHelperUI
             // once selection is present.
             setTimeout(function () {
-              let contextInfo = { name: "",
-                                  json: { xPos: aEvent.clientX, yPos: aEvent.clientY },
-                                  target: Browser.selectedTab.browser };
-              SelectionHelperUI.attachEditSession(contextInfo);
+              SelectionHelperUI.attachEditSession(Browser.selectedTab.browser,
+                                                  aEvent.clientX, aEvent.clientY);
             }, 50);
             break;
         }
       }
     }
   },
 
   sample: function sample(aTimeStamp) {