WebUI Tab Strip: Show contextmenu on dragend, not drop

A drop event is not fired if a drag interaction did not have any x/y
pointer movement. This CL moves the contextmenu call to the dragend,
as the dragevent is consistently sent at the end of every drag flow.

(cherry picked from commit ce8cb6c863842216bf5da62aa68456931db674b5)

Bug: 1117652
Change-Id: I9e3fc078fcc2843808d3db454feb39084b97794d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446353
Commit-Queue: John Lee <[email protected]>
Reviewed-by: dpapad <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#813941}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461253
Reviewed-by: John Lee <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#176}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chrome/browser/resources/tab_strip/drag_manager.js b/chrome/browser/resources/tab_strip/drag_manager.js
index 6c1604e..0cecd6d 100644
--- a/chrome/browser/resources/tab_strip/drag_manager.js
+++ b/chrome/browser/resources/tab_strip/drag_manager.js
@@ -108,6 +108,9 @@
      */
     this.hasMoved_ = false;
 
+    /** @private {!Object<{x: number, y: number}>} */
+    this.lastPoint_ = {x: 0, y: 0};
+
     /** @const {number} */
     this.srcIndex = srcIndex;
 
@@ -221,7 +224,8 @@
     return dstIndex;
   }
 
-  cancel() {
+  /** @param {!DragEvent} event */
+  cancel(event) {
     if (this.isDraggingPlaceholder()) {
       this.element_.remove();
       return;
@@ -238,6 +242,14 @@
 
     this.element_.setDragging(false);
     this.element_.setDraggedOut(false);
+
+    if (event.type === 'dragend' && isTabElement(this.element_) &&
+        !this.hasMoved_) {
+      // If the user was dragging a tab and the tab has not ever been moved,
+      // show a context menu instead.
+      this.tabStripEmbedderProxy_.showTabContextMenu(
+          this.element_.tab.id, this.lastPoint_.x, this.lastPoint_.y);
+    }
   }
 
   /** @return {boolean} */
@@ -290,13 +302,6 @@
 
     this.element_.setDragging(false);
     this.element_.setDraggedOut(false);
-
-    if (isTabElement(this.element_) && !this.hasMoved_) {
-      // If the user was dragging a tab and the tab has not ever been moved,
-      // show a context menu instead.
-      this.tabStripEmbedderProxy_.showTabContextMenu(
-          this.element_.tab.id, event.clientX, event.clientY);
-    }
   }
 
   /**
@@ -314,6 +319,7 @@
 
   /** @param {!DragEvent} event */
   start(event) {
+    this.lastPoint_ = {x: event.clientX, y: event.clientY};
     event.dataTransfer.effectAllowed = 'move';
     const draggedItemRect = event.composedPath()[0].getBoundingClientRect();
     this.element_.setDragging(true);
@@ -368,6 +374,8 @@
 
   /** @param {!DragEvent} event */
   update(event) {
+    this.lastPoint_ = {x: event.clientX, y: event.clientY};
+
     if (event.type === 'dragleave') {
       this.element_.setDraggedOut(true);
       this.hasMoved_ = true;
@@ -489,7 +497,7 @@
    */
   onDragLeave_(event) {
     if (this.dragSession_ && this.dragSession_.isDraggingPlaceholder()) {
-      this.dragSession_.cancel();
+      this.dragSession_.cancel(event);
       this.dragSession_ = null;
       return;
     }
@@ -529,7 +537,7 @@
       return;
     }
 
-    this.dragSession_.cancel();
+    this.dragSession_.cancel(event);
     this.dragSession_ = null;
   }