Bug 1139655 - pressing enter in the searchbar should ignore button selections from mouseover, r=Gijs.
authorFlorian Quèze <florian@queze.net>
Fri, 11 Sep 2015 14:18:15 +0200
changeset 295160 6a018a619384046f1a2cf00b60a7f573aa711a8f
parent 295159 e4e04ee24e4921bd7e1f2f5459fdb8a3547db632
child 295161 27893f89ee3939afce1e553a1716aaaaaa92ff7c
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1139655
milestone43.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 1139655 - pressing enter in the searchbar should ignore button selections from mouseover, r=Gijs.
browser/components/search/content/search.xml
browser/components/search/test/browser_oneOffHeader.js
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -722,17 +722,17 @@
       <!-- override |onTextEntered| in autocomplete.xml -->
       <method name="onTextEntered">
         <parameter name="aEvent"/>
         <body><![CDATA[
           var evt = aEvent || this.mEnterEvent;
 
           let engine;
           let oneOff = this.selectedButton;
-          if (oneOff) {
+          if (oneOff && !this.selectionFromMouseOver) {
             if (!oneOff.engine) {
               oneOff.doCommand();
               this.mEnterEvent = null;
               return;
             }
             engine = oneOff.engine;
           }
           if (this.mEnterEvent && this._selectionDetails &&
@@ -744,16 +744,19 @@
 
           this.mEnterEvent = null;
         ]]></body>
       </method>
 
       <field name="_selectedButton"/>
       <property name="selectedButton" onget="return this._selectedButton;">
         <setter><![CDATA[
+          // Set to true from the mouseover handler right after this setter call.
+          this.selectionFromMouseOver = false;
+
           if (this._selectedButton)
             this._selectedButton.removeAttribute("selected");
 
           let textbox = document.getBindingParent(this).textbox;
           let header =
             document.getAnonymousElementByAttribute(this.popup, "anonid",
                                                     "search-panel-one-offs-header");
           // Avoid selecting dummy buttons.
@@ -1198,20 +1201,16 @@
             addEngineList.appendChild(button);
           }
         }
 
         // Finally, build the list of one-off buttons.
         while (list.firstChild)
           list.firstChild.remove();
 
-        // Avoid setting the selection based on mouse events before
-        // the 'popupshown' event has fired.
-        this._ignoreMouseEvents = true;
-
         let Preferences =
           Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
         let pref = Preferences.get("browser.search.hiddenOneOffs");
         let hiddenList = pref ? pref.split(",") : [];
 
         let currentEngineName = Services.search.currentEngine.name;
         let engines = Services.search.getVisibleEngines()
                               .filter(e => e.name != currentEngineName &&
@@ -1293,41 +1292,34 @@
 
           if (!--dummyItems)
             button.classList.add("last-of-row");
 
           list.appendChild(button);
         }
       ]]></handler>
 
-      <handler event="popupshown"><![CDATA[
-        this._ignoreMouseEvents = false;
-      ]]></handler>
-
       <handler event="mousedown"><![CDATA[
         // Required to receive click events from the buttons on Linux.
         event.preventDefault();
       ]]></handler>
 
       <handler event="mouseover"><![CDATA[
         let target = event.originalTarget;
         if (target.localName != "button")
           return;
 
-        // We ignore mouse events between the popupshowing and popupshown
-        // events to avoid selecting the button that happens to be under the
-        // mouse when the panel opens.
-        if (this._ignoreMouseEvents)
-          return;
-
         if ((target.classList.contains("searchbar-engine-one-off-item") &&
              !target.classList.contains("dummy")) ||
             target.classList.contains("addengine-item") ||
-            target.classList.contains("search-setting-button"))
-          document.getElementById("searchbar").textbox.selectedButton = target;
+            target.classList.contains("search-setting-button")) {
+          let textbox = document.getElementById("searchbar").textbox;
+          textbox.selectedButton = target;
+          textbox.selectionFromMouseOver = true;
+        }
       ]]></handler>
 
       <handler event="mouseout"><![CDATA[
         let target = event.originalTarget;
         if (target.localName != "button")
           return;
 
         let textbox = document.getElementById("searchbar").textbox;
--- a/browser/components/search/test/browser_oneOffHeader.js
+++ b/browser/components/search/test/browser_oneOffHeader.js
@@ -133,9 +133,12 @@ add_task(function* test_text() {
      "Header has the correct index selected when search terms have been entered and the Change Search Settings button is selected.");
   is(getHeaderText(), "Search for foo with:",
      "Header has the correct text when search terms have been entered and the Change Search Settings button is selected.");
 
   promise = promiseEvent(searchPopup, "popuphidden");
   info("Closing search panel");
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   yield promise;
+
+  // Move the cursor out of the panel area to avoid messing with other tests.
+  yield synthesizeNativeMouseMove(searchbar);
 });