Bug 1293300 - Accidental one-off search if mouse pointer hovers over a search engine when typing in location bar and pressing enter. r=florian
authorDrew Willcoxon <adw@mozilla.com>
Thu, 11 Aug 2016 13:56:25 -0700
changeset 350550 89ba380478e36de087ba1c046b60363b956d4abc
parent 350549 d99ed7fbe3118be0204980a4119044ec30628382
child 350551 a31f07fbdc2e249f76469bc897bcad548a892417
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1293300
milestone51.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 1293300 - Accidental one-off search if mouse pointer hovers over a search engine when typing in location bar and pressing enter. r=florian MozReview-Commit-ID: 53MGnGs6CxF
browser/base/content/urlbarBindings.xml
browser/components/search/content/search.xml
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -361,18 +361,17 @@ file, You can obtain one at http://mozil
         <body><![CDATA[
           let isMouseEvent = event instanceof MouseEvent;
           if (isMouseEvent && event.button == 2) {
             // Do nothing for right clicks.
             return;
           }
 
           // Do the command of the selected one-off if it's not an engine.
-          let selectedOneOff =
-            this.popup.oneOffSearchButtons.visuallySelectedButton;
+          let selectedOneOff = this.popup.oneOffSearchButtons.selectedButton;
           if (selectedOneOff && !selectedOneOff.engine) {
             selectedOneOff.doCommand();
             return;
           }
 
           let where = openUILinkWhere;
           if (!where) {
             if (isMouseEvent) {
@@ -410,17 +409,17 @@ file, You can obtain one at http://mozil
                     gBrowser.removeTab(prevTab);
                   }
                   return;
                 }
                 break;
               case "searchengine":
                 if (selectedOneOff && selectedOneOff.engine) {
                   // Replace the engine with the selected one-off engine.
-                  action.params.engineName = engine.name;
+                  action.params.engineName = selectedOneOff.engine.name;
                 }
                 [url, postData] = this._recordSearchEngineLoad(
                   action.params.engineName,
                   action.params.searchSuggestion || action.params.searchQuery,
                   event,
                   where,
                   openUILinkParams
                 );
@@ -1633,17 +1632,17 @@ file, You can obtain one at http://mozil
               resolve();
             };
             this.addEventListener("transitionend", onTransitionEnd, true);
           });
           ]]>
         </body>
       </method>
 
-      <method name="_visuallySelectedOneOffChanged">
+      <method name="_selectedOneOffChanged">
         <body><![CDATA[
           // Update all searchengine result items to use the newly selected
           // engine.
           for (let item of this.richlistbox.childNodes) {
             if (item.collapsed) {
               break;
             }
             let url = item.getAttribute("url");
@@ -1688,18 +1687,18 @@ file, You can obtain one at http://mozil
         <getter><![CDATA[
           // When building the popup, autocomplete reuses an item at index i if
           // that item's url attribute matches the controller's value at index
           // i, but only if overrideSearchEngineName matches the engine in the
           // url attribute.  To absolutely avoid reusing items that shouldn't be
           // reused, always return a non-null name here by falling back to the
           // current engine.
           let engine =
-            (this.oneOffSearchButtons.visuallySelectedButton &&
-             this.oneOffSearchButtons.visuallySelectedButton.engine) ||
+            (this.oneOffSearchButtons.selectedButton &&
+             this.oneOffSearchButtons.selectedButton.engine) ||
              Services.search.currentEngine;
           return engine ? engine.name : null;
         ]]></getter>
       </property>
 
       <method name="createResultLabel">
         <parameter name="item"/>
         <parameter name="proposedLabel"/>
@@ -1764,18 +1763,18 @@ file, You can obtain one at http://mozil
             }
           ]]>
         </body>
       </method>
 
     </implementation>
     <handlers>
 
-      <handler event="OneOffsVisuallySelectedButtonChanged"><![CDATA[
-        this._visuallySelectedOneOffChanged();
+      <handler event="SelectedOneOffButtonChanged"><![CDATA[
+        this._selectedOneOffChanged();
       ]]></handler>
 
       <handler event="mousedown"><![CDATA[
         // Required to make the xul:label.text-link elements in the search
         // suggestions notification work correctly when clicked on Linux.
         // This is copied from the mousedown handler in
         // browser-search-autocomplete-result-popup, which apparently had a
         // similar problem.
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1553,21 +1553,20 @@
           if (aUpdateLogicallySelectedButton) {
             this._selectedButton = val;
             if (val && !val.engine) {
               // If the button doesn't have an engine, then clear the popup's
               // selection to indicate that pressing Return while the button is
               // selected will do the button's command, not search.
               this.popup.selectedIndex = -1;
             }
+            let event = document.createEvent("Events");
+            event.initEvent("SelectedOneOffButtonChanged", true, false);
+            this.dispatchEvent(event);
           }
-
-          let event = document.createEvent("Events");
-          event.initEvent("OneOffsVisuallySelectedButtonChanged", true, false);
-          this.dispatchEvent(event);
         ]]></body>
       </method>
 
       <method name="getSelectableButtons">
         <parameter name="aIncludeNonEngineButtons"/>
         <body><![CDATA[
           let buttons = [];
           let oneOff = document.getAnonymousElementByAttribute(this, "anonid",
@@ -1906,17 +1905,17 @@
 
     <handlers>
 
       <handler event="mousedown"><![CDATA[
         // Required to receive click events from the buttons on Linux.
         event.preventDefault();
       ]]></handler>
 
-      <handler event="mouseover"><![CDATA[
+      <handler event="mousemove"><![CDATA[
         let target = event.originalTarget;
         if (target.localName != "button")
           return;
 
         // Ignore mouse events when the context menu is open.
          if (this._ignoreMouseEvents)
            return;