Bug 914447 - Fix: taps that don't intersect the inputField of the nav bar don't invoke selection control. r=mbrubeck
authorJim Mathies <jmathies@mozilla.com>
Fri, 06 Dec 2013 05:38:35 -0600
changeset 174900 e9d3b9da94bd0f360b4df275885b0dce5141c811
parent 174899 51c1585b15bea7dfb31dcf24bedd01f18a70b431
child 174901 7b156069de688cd3d054db9c89e4b22a4ef4bc75
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs914447
milestone28.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 914447 - Fix: taps that don't intersect the inputField of the nav bar don't invoke selection control. r=mbrubeck
browser/metro/base/content/browser.xul
browser/metro/base/content/helperui/ChromeSelectionHandler.js
browser/metro/base/content/helperui/SelectionHelperUI.js
--- a/browser/metro/base/content/browser.xul
+++ b/browser/metro/base/content/browser.xul
@@ -242,17 +242,17 @@ Desktop browser's sync prefs.
             </box>
 
             <textbox id="urlbar-edit" type="url" flex="1"
                      autocompletesearch="history"
                      autocompletepopup="urlbar-autocomplete"
                      completeselectedindex="true"
                      placeholder="&urlbar.emptytext;"
                      tabscrolling="true"
-                     onclick="SelectionHelperUI.urlbarClick();"/>
+                     onclick="SelectionHelperUI.urlbarTextboxClick(this);"/>
 
             <toolbarbutton id="go-button" class="urlbar-button"
                            command="cmd_go"/>
             <toolbarbutton id="reload-button" class="urlbar-button"
                            oncommand="CommandUpdater.doCommand(
                                         event.shiftKey ? 'cmd_forceReload'
                                                        : 'cmd_reload');"/>
             <toolbarbutton id="stop-button" class="urlbar-button"
--- a/browser/metro/base/content/helperui/ChromeSelectionHandler.js
+++ b/browser/metro/base/content/helperui/ChromeSelectionHandler.js
@@ -29,20 +29,19 @@ var ChromeSelectionHandler = {
 
   /*
    * General selection start method for both caret and selection mode.
    */
   _onSelectionAttach: function _onSelectionAttach(aJson) {
     this._domWinUtils = Util.getWindowUtils(window);
     this._contentWindow = window;
     this._targetElement = this._domWinUtils.elementFromPoint(aJson.xPos, aJson.yPos, true, false);
-
     this._targetIsEditable = this._targetElement instanceof Components.interfaces.nsIDOMXULTextBoxElement;
     if (!this._targetIsEditable) {
-      this._onFail("not an editable?");
+      this._onFail("not an editable?", this._targetElement);
       return;
     }
 
     let selection = this._getSelection();
     if (!selection) {
       this._onFail("no selection.");
       return;
     }
--- a/browser/metro/base/content/helperui/SelectionHelperUI.js
+++ b/browser/metro/base/content/helperui/SelectionHelperUI.js
@@ -339,19 +339,19 @@ var SelectionHelperUI = {
 
   /*
    * Observers
    */
 
   observe: function (aSubject, aTopic, aData) {
     switch (aTopic) {
       case "attach_edit_session_to_content":
-        let event = aSubject;
-        this.attachEditSession(Browser.selectedTab.browser,
-                               event.clientX, event.clientY);
+        // We receive this from text input bindings when this module
+        // isn't accessible.
+        this.chromeTextboxClick(aSubject);
         break;
 
       case "apzc-transform-begin":
         if (this.isActive && this.layerMode == kContentLayer) {
           this._hideMonocles();
         }
         break;
 
@@ -510,16 +510,50 @@ var SelectionHelperUI = {
     // which we will call _shutdown().
     let clearSelection = aClearSelection || false;
     this._sendAsyncMessage("Browser:SelectionClose", {
       clearSelection: clearSelection
     });
   },
 
   /*
+   * Event handler on the navbar text input. Called from navbar bindings
+   * when focus is applied to the edit.
+   */
+  urlbarTextboxClick: function(aEdit) {
+    // workaround for bug 925457: taping browser chrome resets last tap
+    // co-ordinates to 'undefined' so that we know not to shift the browser
+    // when the keyboard is up in SelectionHandler's _calcNewContentPosition().
+    Browser.selectedTab.browser.messageManager.sendAsyncMessage("Browser:ResetLastPos", {
+      xPos: null,
+      yPos: null
+    });
+
+    if (InputSourceHelper.isPrecise || !aEdit.textLength) {
+      return;
+    }
+
+    // Enable selection when there's text in the control
+    let innerRect = aEdit.inputField.getBoundingClientRect();
+    this.attachEditSession(ChromeSelectionHandler,
+                           innerRect.left,
+                           innerRect.top);
+  },
+
+  /*
+   * Click handler for chrome pages loaded into the browser (about:config).
+   * Called from the text input bindings via the attach_edit_session_to_content
+   * observer.
+   */
+  chromeTextboxClick: function (aEvent) {
+    this.attachEditSession(Browser.selectedTab.browser,
+                           aEvent.clientX, aEvent.clientY);
+  },
+
+  /*
    * Handy debug routines that work independent of selection. They
    * make use of the selection overlay for drawing points.
    */
 
   debugDisplayDebugPoint: function (aLeft, aTop, aSize, aCssColorStr, aFill) {
     this.overlay.enabled = true;
     this.overlay.displayDebugLayer = true;
     this.overlay.addDebugRect(aLeft, aTop, aLeft + aSize, aTop + aSize,
@@ -830,30 +864,20 @@ var SelectionHelperUI = {
     }
     return true;
   },
 
   /*
    * Event handlers for document events
    */
 
-   urlbarClick: function() {
-    // Workaround for bug 925457: taping browser chrome resets last tap
-    // co-ordinates to 'undefined' so that we know not to shift the browser
-    // when the keyboard is up (in SelectionHandler._calcNewContentPosition())
-    Browser.selectedTab.browser.messageManager.sendAsyncMessage("Browser:ResetLastPos", {
-      xPos: null,
-      yPos: null
-    });
-   },
-
   /*
    * Handles taps that move the current caret around in text edits,
    * clear active selection and focus when neccessary, or change
-   * modes.
+   * modes. Only active afer SelectionHandlerUI is initialized.
    */
   _onClick: function(aEvent) {
     if (this.layerMode == kChromeLayer && this._targetIsEditable) {
       this.attachToCaret(this._msgTarget, aEvent.clientX, aEvent.clientY);
     }
   },
 
   _onKeypress: function _onKeypress() {