Bug 1356641 - Ctrl+click location item loads wrong URL. r?mak draft
authorDrew Willcoxon <adw@mozilla.com>
Fri, 21 Apr 2017 14:16:31 -0700
changeset 566608 c877928ab8166ce32352335f7cca44eac638027c
parent 565512 4c09d2ddc229323ac7287649a6455d762d24f235
child 625380 327b4aafdc71e666c7c4c6ff6626e76ae16063ee
push id55286
push userdwillcoxon@mozilla.com
push dateFri, 21 Apr 2017 21:55:00 +0000
reviewersmak
bugs1356641
milestone55.0a1
Bug 1356641 - Ctrl+click location item loads wrong URL. r?mak With ideas and code from Oriol <oriol-bugzilla@hotmail.com>. MozReview-Commit-ID: CjuCAkYaort
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -2488,16 +2488,55 @@ extends="chrome://global/content/binding
               url: params,
             }
           }
 
           return action;
         ]]></body>
       </method>
     </implementation>
+
+    <handlers>
+      <!--
+        This overrides listitem's mousedown handler because we want to set the
+        selected item even when the shift or accel keys are pressed.
+      -->
+      <handler event="mousedown"><![CDATA[
+        // Call this.control only once since it's not a simple getter.
+        let control = this.control;
+        if (!control || control.disabled) {
+          return;
+        }
+        if (!this.selected) {
+          control.selectItem(this);
+        }
+        control.currentItem = this;
+      ]]></handler>
+
+      <handler event="mouseover"><![CDATA[
+        // The point of implementing this handler is to allow drags to change
+        // the selected item.  If the user mouses down on an item, it becomes
+        // selected.  If they then drag the mouse to another item, select it.
+        // Handle all three primary mouse buttons: right, left, and wheel, since
+        // all three change the selection on mousedown.
+        let mouseDown = event.buttons & 0b111;
+        if (!mouseDown) {
+          return;
+        }
+        // Call this.control only once since it's not a simple getter.
+        let control = this.control;
+        if (!control || control.disabled) {
+          return;
+        }
+        if (!this.selected) {
+          control.selectItem(this);
+        }
+        control.currentItem = this;
+      ]]></handler>
+    </handlers>
   </binding>
 
   <binding id="autocomplete-tree" extends="chrome://global/content/bindings/tree.xml#tree">
     <content>
       <children includes="treecols"/>
       <xul:treerows class="autocomplete-treerows tree-rows" xbl:inherits="hidescrollbar" flex="1">
         <children/>
       </xul:treerows>