| Index: third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js b/third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js
|
| index cbe69e3c758bfc10100bda4ce8c597f1c6107c45..127399500c182557787381c0b1dd1b56984091d9 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js
|
| @@ -197,6 +197,81 @@ WebInspector._elementDragEnd = function(event)
|
| }
|
|
|
| /**
|
| + * @param {!Element} element
|
| + * @param {function(number, number, !MouseEvent): boolean} elementDragStart
|
| + * @param {function(number, number)} elementDrag
|
| + * @param {function(number, number)} elementDragEnd
|
| + * @param {string} cursor
|
| + * @param {?string=} hoverCursor
|
| + * @param {number=} startDelay
|
| + * @param {number=} friction
|
| + */
|
| +WebInspector.installInertialDragHandle = function(element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction)
|
| +{
|
| + WebInspector.installDragHandle(element, drag.bind(null, elementDragStart), drag.bind(null, elementDrag), dragEnd, cursor, hoverCursor, startDelay);
|
| + if (typeof friction !== "number")
|
| + friction = 50;
|
| + var lastX;
|
| + var lastY;
|
| + var lastTime;
|
| + var velocityX;
|
| + var velocityY;
|
| + var holding = false;
|
| +
|
| + /**
|
| + * @param {function(number, number, !MouseEvent): boolean} callback
|
| + * @param {!MouseEvent} event
|
| + * @return {boolean}
|
| + */
|
| + function drag(callback, event)
|
| + {
|
| + lastTime = window.performance.now();
|
| + lastX = event.pageX;
|
| + lastY = event.pageY;
|
| + holding = true;
|
| + return callback(lastX, lastY, event);
|
| + }
|
| +
|
| + /**
|
| + * @param {!MouseEvent} event
|
| + */
|
| + function dragEnd(event)
|
| + {
|
| + var now = window.performance.now();
|
| + var duration = now - lastTime || 1;
|
| + const maxVelocity = 4; // 4px per millisecond.
|
| + velocityX = Number.constrain((event.pageX - lastX) / duration, -maxVelocity, maxVelocity);
|
| + velocityY = Number.constrain((event.pageY - lastY) / duration, -maxVelocity, maxVelocity);
|
| + lastX = event.pageX;
|
| + lastY = event.pageY;
|
| + lastTime = now;
|
| + holding = false;
|
| + animationStep();
|
| + }
|
| +
|
| + function animationStep()
|
| + {
|
| + var v2 = velocityX * velocityX + velocityY * velocityY;
|
| + if (v2 < 0.001 || holding) {
|
| + elementDragEnd(lastX, lastY);
|
| + return;
|
| + }
|
| + element.window().requestAnimationFrame(animationStep);
|
| + var now = window.performance.now();
|
| + var duration = now - lastTime;
|
| + if (!duration)
|
| + return;
|
| + lastTime = now;
|
| + lastX += velocityX * duration;
|
| + lastY += velocityY * duration;
|
| + var k = Math.pow(1 / (1 + friction), duration / 1000);
|
| + velocityX *= k;
|
| + velocityY *= k;
|
| + elementDrag(lastX, lastY);
|
| + }
|
| +}
|
| +
|
| +/**
|
| * @constructor
|
| * @param {!Document} document
|
| * @param {boolean=} dimmed
|
|
|