Bug 1591505 - Fixed drag and drop (reorder) of chat accounts. r=mkmelin
authorKhushil Mistry <khushil324@gmail.com>
Fri, 08 Nov 2019 12:45:00 +0100
changeset 81049 160cac84b99c0c3b8725a8f114145f2b6a56df63
parent 81048 9b8b03b90835cb841d5aa08ef93dcda34de9a1fe
child 81050 09dfc108f9c23890e921334d425d5245491ccc3a
child 81092 c2490a04ab6c2f5d94da4421e9ad5b9bdfdb00ea
child 81108 f66f154ecd6b16d0950823552de5b63f10a2b7a1
child 81143 9a8a3ff81582bd19a01a6a3add171b0f34769105
push id9744
push userishikawa@yk.rim.or.jp
push dateSat, 09 Nov 2019 02:01:06 +0000
treeherdertry-comm-central@56c83244ac0e [default view] [failures only]
reviewersmkmelin
bugs1591505
Bug 1591505 - Fixed drag and drop (reorder) of chat accounts. r=mkmelin
mail/components/im/content/imAccounts.js
--- a/mail/components/im/content/imAccounts.js
+++ b/mail/components/im/content/imAccounts.js
@@ -137,17 +137,19 @@ var gAccountManager = {
       // Focus the "New Account" button if there are no accounts left.
       document.getElementById("newaccount").focus();
       // Return early, otherwise we'll run into an 'undefined property' strict
       //  warning when trying to focus the buttons. Fixes bug 408.
       return;
     }
 
     // The selected item is still selected
-    accountList.selectedItem.setFocus();
+    if (accountList.selectedItem) {
+      accountList.selectedItem.setFocus();
+    }
     accountList.ensureSelectedElementIsVisible();
 
     // We need to refresh the disabled menu items
     this.disableCommandItems();
   },
   observe(aObject, aTopic, aData) {
     if (aTopic == "prpl-quit") {
       // libpurple is being uninitialized. We don't need the account
@@ -701,35 +703,41 @@ var gAMDragAndDrop = {
     this.SCROLL_SPEED = Services.prefs.getIntPref(
       "toolkit.scrollbox.scrollIncrement",
       20
     );
     return this.SCROLL_SPEED;
   },
 
   onDragStart(aEvent, aTransferData, aAction) {
-    let accountElement = aEvent.explicitOriginalTarget;
-    // This stops the dragging session.
-    if (!(accountElement instanceof Ci.nsIDOMXULSelectControlItemElement)) {
-      throw new Error("Element is not draggable!");
+    let accountElement = aEvent.target.closest(
+      'richlistitem[is="chat-account-richlistitem"]'
+    );
+    if (!accountElement) {
+      return;
     }
     if (gAccountManager.accountList.itemCount == 1) {
       throw new Error("Can't drag while there is only one account!");
     }
 
     // Transferdata is never used, but we need to transfer something.
     aTransferData.data = new TransferData();
     aTransferData.data.addDataForFlavour(
       this.ACCOUNT_MIME_TYPE,
       accountElement
     );
   },
 
   onDragOver(aEvent, aFlavour, aSession) {
-    let accountElement = aEvent.explicitOriginalTarget;
+    let accountElement = aEvent.target.closest(
+      'richlistitem[is="chat-account-richlistitem"]'
+    );
+    if (!accountElement) {
+      return;
+    }
     // We are dragging over the account manager, consider it is the same as
     // the last element.
     if (accountElement == gAccountManager.accountList) {
       accountElement = gAccountManager.accountList.lastElementChild;
     }
 
     // Auto scroll the account list if we are dragging at the top/bottom
     this.checkForMagicScroll(aEvent.clientY);
@@ -769,17 +777,16 @@ var gAMDragAndDrop = {
 
     this._accountElement = accountElement;
   },
 
   cleanBorders(aIsEnd) {
     if (!this._accountElement) {
       return;
     }
-
     this._accountElement.removeAttribute("dragover");
     // reset the border of the previous element
     let previousItem = this._accountElement.previousElementSibling;
     if (previousItem) {
       if (
         aIsEnd &&
         !previousItem.style.borderBottom &&
         previousItem.previousElementSibling
@@ -790,17 +797,19 @@ var gAMDragAndDrop = {
     }
 
     if (aIsEnd) {
       delete this._accountElement;
     }
   },
 
   canDrop(aEvent, aSession) {
-    let accountElement = aEvent.explicitOriginalTarget;
+    let accountElement = aEvent.target.closest(
+      'richlistitem[is="chat-account-richlistitem"]'
+    );
     if (accountElement == gAccountManager.accountList) {
       accountElement = gAccountManager.accountList.lastElementChild;
     }
     return accountElement != gAccountManager.accountList.selectedItem;
   },
 
   checkForMagicScroll(aClientY) {
     let accountList = gAccountManager.accountList;
@@ -812,17 +821,22 @@ var gAMDragAndDrop = {
       // We are not on a scroll zone
       return;
     }
 
     accountList.scrollTop += direction * this.SCROLL_SPEED;
   },
 
   onDrop(aEvent, aTransferData, aSession) {
-    let accountElement = aEvent.explicitOriginalTarget;
+    let accountElement = aEvent.target.closest(
+      'richlistitem[is="chat-account-richlistitem"]'
+    );
+    if (!accountElement) {
+      return;
+    }
     if (accountElement == gAccountManager.accountList) {
       accountElement = gAccountManager.accountList.lastElementChild;
     }
 
     if (!aSession.canDrop) {
       return;
     }