Bug 1039540 - In-content preferences: Disable the sorting of rows of sub-dialogs when right clicking. r=MattN, a=sledru
authorDeepak Koli <deepakkoli93@gmail.com>
Thu, 26 Mar 2015 18:02:49 -0700
changeset 258245 a9d533ac9ff4
parent 258244 94de32e773b8
child 258246 d3e9b16fc53f
push id4627
push userryanvm@gmail.com
push date2015-04-03 19:22 +0000
treeherdermozilla-beta@5f5a4c5a7e02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, sledru
bugs1039540
milestone38.0
Bug 1039540 - In-content preferences: Disable the sorting of rows of sub-dialogs when right clicking. r=MattN, a=sledru Review comments applied by MattN
browser/components/preferences/permissions.js
browser/components/preferences/permissions.xul
toolkit/components/passwordmgr/content/passwordManager.js
toolkit/components/passwordmgr/content/passwordManager.xul
toolkit/components/passwordmgr/content/passwordManagerCommon.js
toolkit/components/passwordmgr/content/passwordManagerExceptions.js
toolkit/components/passwordmgr/content/passwordManagerExceptions.xul
--- a/browser/components/preferences/permissions.js
+++ b/browser/components/preferences/permissions.js
@@ -1,9 +1,8 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
 const nsICookiePermission = Components.interfaces.nsICookiePermission;
 
 const NOTIFICATION_FLUSH_PERMISSIONS = "flush-pending-permissions";
@@ -177,16 +176,30 @@ var gPermissionManager = {
     urlField.value = aParams.prefilledHost;
     urlField.hidden = !urlFieldVisible;
 
     this.onHostInput(urlField);
 
     var urlLabel = document.getElementById("urlLabel");
     urlLabel.hidden = !urlFieldVisible;
 
+    let treecols = document.getElementsByTagName("treecols")[0];
+    treecols.addEventListener("click", event => {
+      if (event.target.nodeName != "treecol" || event.button != 0) {
+        return;
+      }
+
+      let sortField = event.target.getAttribute("data-field-name");
+      if (!sortField) {
+        return;
+      }
+
+      gPermissionManager.onPermissionSort(sortField);
+    });
+
     var os = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
     os.notifyObservers(null, NOTIFICATION_FLUSH_PERMISSIONS, this._type);
     os.addObserver(this, "perm-changed", false);
 
     this._loadPermissions();
     
     urlField.focus();
--- a/browser/components/preferences/permissions.xul
+++ b/browser/components/preferences/permissions.xul
@@ -48,20 +48,20 @@
     </hbox>
     <separator class="thin"/>
     <tree id="permissionsTree" flex="1" style="height: 18em;"
           hidecolumnpicker="true"
           onkeypress="gPermissionManager.onPermissionKeyPress(event)"
           onselect="gPermissionManager.onPermissionSelected();">
       <treecols>
         <treecol id="siteCol" label="&treehead.sitename.label;" flex="3"
-                onclick="gPermissionManager.onPermissionSort('rawHost');" persist="width"/>
+                 data-field-name="rawHost" persist="width"/>
         <splitter class="tree-splitter"/>
         <treecol id="statusCol" label="&treehead.status.label;" flex="1"
-                onclick="gPermissionManager.onPermissionSort('capability');" persist="width"/>
+                 data-field-name="capability" persist="width"/>
       </treecols>
       <treechildren/>
     </tree>
   </vbox>
   <hbox align="end">
     <hbox class="actionButtons" flex="1">
       <button id="removePermission" disabled="true"
               accesskey="&removepermission.accesskey;"
--- a/toolkit/components/passwordmgr/content/passwordManager.js
+++ b/toolkit/components/passwordmgr/content/passwordManager.js
@@ -1,10 +1,8 @@
-// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*** =================== SAVED SIGNONS CODE =================== ***/
 
 var kSignonBundle;
 var showingPasswords = false;
@@ -14,16 +12,20 @@ var dateAndTimeFormatter = new Intl.Date
                              { day: "numeric", month: "short", year: "numeric",
                                hour: "numeric", minute: "numeric" });
 
 function SignonsStartup() {
   kSignonBundle = document.getElementById("signonBundle");
   document.getElementById("togglePasswords").label = kSignonBundle.getString("showPasswords");
   document.getElementById("togglePasswords").accessKey = kSignonBundle.getString("showPasswordsAccessKey");
   document.getElementById("signonsIntro").textContent = kSignonBundle.getString("loginsSpielAll");
+
+  let treecols = document.getElementsByTagName("treecols")[0];
+  treecols.addEventListener("click", HandleTreeColumnClick.bind(null, SignonColumnSort));
+
   LoadSignons();
 
   // filter the table if requested by caller
   if (window.arguments &&
       window.arguments[0] &&
       window.arguments[0].filterString)
     setFilter(window.arguments[0].filterString);
 
--- a/toolkit/components/passwordmgr/content/passwordManager.xul
+++ b/toolkit/components/passwordmgr/content/passwordManager.xul
@@ -58,41 +58,41 @@
     <tree id="signonsTree" flex="1"
           width="750"
           style="height: 20em;"
           onkeypress="HandleSignonKeyPress(event)"
           onselect="SignonSelected();"
           context="signonsTreeContextMenu">
       <treecols>
         <treecol id="siteCol" label="&treehead.site.label;" flex="40"
-                 onclick="SignonColumnSort('hostname');" persist="width"
+                 data-field-name="hostname" persist="width"
                  ignoreincolumnpicker="true"
                  sortDirection="ascending"/>
         <splitter class="tree-splitter"/>
         <treecol id="userCol" label="&treehead.username.label;" flex="25"
                  ignoreincolumnpicker="true"
-                 onclick="SignonColumnSort('username');" persist="width"/>
+                 data-field-name="username" persist="width"/>
         <splitter class="tree-splitter"/>
         <treecol id="passwordCol" label="&treehead.password.label;" flex="15"
                  ignoreincolumnpicker="true"
-                 onclick="SignonColumnSort('password');" persist="width"
+                 data-field-name="password" persist="width"
                  hidden="true"/>
         <splitter class="tree-splitter"/>
         <treecol id="timeCreatedCol" label="&treehead.timeCreated.label;" flex="10"
-                 onclick="SignonColumnSort('timeCreated');" persist="width hidden"
+                 data-field-name="timeCreated" persist="width hidden"
                  hidden="true"/>
         <splitter class="tree-splitter"/>
         <treecol id="timeLastUsedCol" label="&treehead.timeLastUsed.label;" flex="20"
-                 onclick="SignonColumnSort('timeLastUsed');" persist="width hidden"/>
+                 data-field-name="timeLastUsed" persist="width hidden"/>
         <splitter class="tree-splitter"/>
         <treecol id="timePasswordChangedCol" label="&treehead.timePasswordChanged.label;" flex="10"
-                 onclick="SignonColumnSort('timePasswordChanged');" persist="width hidden"/>
+                 data-field-name="timePasswordChanged" persist="width hidden"/>
         <splitter class="tree-splitter"/>
         <treecol id="timesUsedCol" label="&treehead.timesUsed.label;" flex="1"
-                 onclick="SignonColumnSort('timesUsed');" persist="width hidden"
+                 data-field-name="timesUsed" persist="width hidden"
                  hidden="true"/>
         <splitter class="tree-splitter"/>
       </treecols>
       <treechildren/>
     </tree>
     <separator class="thin"/>
     <hbox id="SignonViewerButtons">
       <button id="removeSignon" disabled="true" icon="remove"
--- a/toolkit/components/passwordmgr/content/passwordManagerCommon.js
+++ b/toolkit/components/passwordmgr/content/passwordManagerCommon.js
@@ -1,10 +1,8 @@
-// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*** =================== INITIALISATION CODE =================== ***/
 
 var kObserverService;
 
@@ -155,16 +153,29 @@ function GetTreeSelections(tree) {
           selections[selections.length] = k;
         }
       }
     }
   }
   return selections;
 }
 
+function HandleTreeColumnClick(sortFunction, event) {
+  if (event.target.nodeName != "treecol" || event.button != 0) {
+    return;
+  }
+
+  let sortField = event.target.getAttribute("data-field-name");
+  if (!sortField) {
+    return;
+  }
+
+  sortFunction(sortField);
+}
+
 function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) {
 
   // remember which item was selected so we can restore it after the sort
   var selections = GetTreeSelections(tree);
   var selectedNumber = selections.length ? table[selections[0]].number : -1;
 
   // determine if sort is to be ascending or descending
   var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
--- a/toolkit/components/passwordmgr/content/passwordManagerExceptions.js
+++ b/toolkit/components/passwordmgr/content/passwordManagerExceptions.js
@@ -1,18 +1,19 @@
-// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*** =================== REJECTED SIGNONS CODE =================== ***/
 
 function RejectsStartup() {
   LoadRejects();
+
+  let treecols = document.getElementsByTagName("treecols")[0];
+  treecols.addEventListener("click", HandleTreeColumnClick.bind(null, RejectColumnSort));
 }
 
 var rejectsTreeView = {
   rowCount : 0,
   setTree : function(tree){},
   getImageSrc : function(row,column) {},
   getProgressMode : function(row,column) {},
   getCellValue : function(row,column) {},
--- a/toolkit/components/passwordmgr/content/passwordManagerExceptions.xul
+++ b/toolkit/components/passwordmgr/content/passwordManagerExceptions.xul
@@ -25,17 +25,17 @@
     <vbox id="rejectedsites" flex="1">
         <description control="rejectsTree">&loginsSpielExceptions.label;</description>
         <separator class="thin"/>
         <tree id="rejectsTree" flex="1" style="height: 10em;" hidecolumnpicker="true"
               onkeypress="HandleRejectKeyPress(event)"
               onselect="RejectSelected();">
           <treecols>
             <treecol id="rejectCol" label="&treehead.site.label;" flex="5"
-                     onclick="RejectColumnSort('host');" sortDirection="ascending"/>
+                     data-field-name="host" sortDirection="ascending"/>
           </treecols>
           <treechildren/>
         </tree>
         <separator class="thin"/>
         <hbox>
           <button id="removeReject" disabled="true" icon="remove"
                   accesskey="&remove.accesskey;"
                   label="&remove.label;" oncommand="DeleteReject();"/>