Bug 1039540 - In-content preferences: Disable the sorting of rows of sub-dialogs when right clicking; r=MattN
authorDeepak Koli <deepakkoli93@gmail.com>
Thu, 26 Mar 2015 18:02:49 -0700
changeset 264799 817390369f571b684fb6e66a495b42f9a687720a
parent 264798 521c3eb713749c37aeb0ec58646751f6893594c7
child 264800 180361c8634a8a34936ddd849eda5aee603d3132
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1039540
milestone39.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 1039540 - In-content preferences: Disable the sorting of rows of sub-dialogs when right clicking; r=MattN 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/. */
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
 const nsICookiePermission = Components.interfaces.nsICookiePermission;
@@ -227,16 +226,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);
+    });
+
     Services.obs.notifyObservers(null, NOTIFICATION_FLUSH_PERMISSIONS, this._type);
     Services.obs.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>
   <vbox>
     <hbox class="actionButtons" align="left" 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();"/>