Bug 857825 - handle moz deck offset change events in selection code. r=mbrubeck
authorJim Mathies <jmathies@mozilla.com>
Fri, 05 Apr 2013 05:33:42 -0500
changeset 127785 6a67ec142bb14b33aed989c1484c5d15c6846521
parent 127784 d33c412d2be05ac950a35262a24c4cbd8444245b
child 127786 7dd4f12137c3f9d4321a794e933be184ff1655cf
push id24512
push userryanvm@gmail.com
push dateFri, 05 Apr 2013 20:13:49 +0000
treeherdermozilla-central@139b6ba547fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs857825
milestone23.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 857825 - handle moz deck offset change events in selection code. r=mbrubeck
browser/metro/base/content/helperui/SelectionHelperUI.js
--- a/browser/metro/base/content/helperui/SelectionHelperUI.js
+++ b/browser/metro/base/content/helperui/SelectionHelperUI.js
@@ -343,22 +343,22 @@ var SelectionHelperUI = {
    * Once the user starts a drag, the caret marker is hidden, and
    * the start and end markers take over.
    *
    * @param aBrowser - Browser object
    * @param aX, aY - Browser relative client coordinates of the tap
    * that initiated the session.
    */
   attachToCaret: function attachToCaret(aBrowser, aX, aY) {
-    if (!aBrowser)
-      return;
     if (!this.isActive)
       this._init(aBrowser);
     this._setupDebugOptions();
 
+    this._lastPoint = { xPos: aX, yPos: aY };
+
     this._selectionHandlerActive = false;
     this._sendAsyncMessage("Browser:CaretAttach", {
       xPos: aX,
       yPos: aY
     });
   },
 
   /*
@@ -423,16 +423,18 @@ var SelectionHelperUI = {
     window.addEventListener("click", this, false);
     window.addEventListener("dblclick", this, false);
     window.addEventListener("touchstart", this, true);
     window.addEventListener("touchend", this, true);
     window.addEventListener("touchmove", this, true);
     window.addEventListener("MozContextUIShow", this, true);
     window.addEventListener("MozContextUIDismiss", this, true);
     window.addEventListener("MozPrecisePointer", this, true);
+    window.addEventListener("MozDeckOffsetChanging", this, true);
+    window.addEventListener("MozDeckOffsetChanged", this, true);
 
     Elements.browsers.addEventListener("URLChanged", this, true);
     Elements.browsers.addEventListener("SizeChanged", this, true);
     Elements.browsers.addEventListener("ZoomChanged", this, true);
 
     this.overlay.enabled = true;
   },
 
@@ -446,16 +448,18 @@ var SelectionHelperUI = {
     window.removeEventListener("click", this, false);
     window.removeEventListener("dblclick", this, false);
     window.removeEventListener("touchstart", this, true);
     window.removeEventListener("touchend", this, true);
     window.removeEventListener("touchmove", this, true);
     window.removeEventListener("MozContextUIShow", this, true);
     window.removeEventListener("MozContextUIDismiss", this, true);
     window.removeEventListener("MozPrecisePointer", this, true);
+    window.removeEventListener("MozDeckOffsetChanging", this, true);
+    window.removeEventListener("MozDeckOffsetChanged", this, true);
 
     Elements.browsers.removeEventListener("URLChanged", this, true);
     Elements.browsers.removeEventListener("SizeChanged", this, true);
     Elements.browsers.removeEventListener("ZoomChanged", this, true);
 
     this._shutdownAllMarkers();
 
     this._selectionMarkIds = [];
@@ -662,16 +666,28 @@ var SelectionHelperUI = {
    * Helper for initing the array of monocle ids.
    */
   _setupMonocleIdArray: function _setupMonocleIdArray() {
     this._selectionMarkIds = ["selectionhandle-mark1",
                               "selectionhandle-mark2",
                               "selectionhandle-mark3"];
   },
 
+  _hideMonocles: function _hideMonocles() {
+    if (this._startMark) {
+      this.startMark.hide();
+    }
+    if (this._endMark) {
+      this.endMark.hide();
+    }
+    if (this._caretMark) {
+      this.caretMark.hide();
+    }
+  },
+
   /*
    * Event handlers for document events
    */
 
   /*
    * _onTap
    *
    * Handles taps that move the current caret around in text edits,
@@ -783,16 +799,36 @@ var SelectionHelperUI = {
   _onContextUIVisibilityEvent: function _onContextUIVisibilityEvent(aType) {
     // Manage display of monocles when the context ui is displayed.
     if (!this.isActive)
       return;
     this.overlay.hidden = (aType == "MozContextUIShow");
   },
 
   /*
+   * _onDeckOffsetChanging - fired by ContentAreaObserver before the browser
+   * deck is shifted for form input access in response to a soft keyboard
+   * display.
+   */
+  _onDeckOffsetChanging: function _onDeckOffsetChanging(aEvent) {
+    // Hide the monocles temporarily
+    this._hideMonocles();
+  },
+
+  /*
+   * _onDeckOffsetChanged - fired by ContentAreaObserver after the browser
+   * deck is shifted for form input access in response to a soft keyboard
+   * display.
+   */
+  _onDeckOffsetChanged: function _onDeckOffsetChanged(aEvent) {
+    // Update the monocle position and display
+    this.attachToCaret(null, this._lastPoint.xPos, this._lastPoint.yPos);
+  },
+
+  /*
    * Event handlers for message manager
    */
 
   _onDebugRectRequest: function _onDebugRectRequest(aMsg) {
     this.overlay.addDebugRect(aMsg.left, aMsg.top, aMsg.right, aMsg.bottom,
                               aMsg.color, aMsg.fill, aMsg.id);
   },
 
@@ -818,16 +854,17 @@ var SelectionHelperUI = {
       // position information we can use.
       if (json.selectionRangeFound) {
         this.caretMark.position(this._msgTarget.xbtoc(json.caret.xPos, true),
                                 this._msgTarget.ybtoc(json.caret.yPos, true));
         this.caretMark.show();
       } else {
         // Don't display anything, just shutdown.
         this.closeEditSession();
+        return;
       }
     }
 
     this._targetIsEditable = json.targetIsEditable;
     this._activeSelectionRect =
       this._msgTarget.rectBrowserToClient(json.selection, true);
     this._targetElementRect =
       this._msgTarget.rectBrowserToClient(json.element, true);
@@ -898,16 +935,24 @@ var SelectionHelperUI = {
       case "MozPrecisePointer":
         this.closeEditSessionAndClear();
         break;
 
       case "MozContextUIShow":
       case "MozContextUIDismiss":
         this._onContextUIVisibilityEvent(aEvent.type);
         break;
+
+      case "MozDeckOffsetChanging":
+        this._onDeckOffsetChanging(aEvent);
+        break;
+
+      case "MozDeckOffsetChanged":
+        this._onDeckOffsetChanged(aEvent);
+        break;
     }
   },
 
   receiveMessage: function sh_receiveMessage(aMessage) {
     if (this._debugEvents) Util.dumpLn("SelectionHelperUI:", aMessage.name);
     let json = aMessage.json;
     switch (aMessage.name) {
       case "Content:SelectionFail":