Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js

Issue 1995123002: Revert of DevTools: Add inertia to flamechart dragging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
5 * Copyright (C) 2009 Joseph Pecoraro 5 * Copyright (C) 2009 Joseph Pecoraro
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 var elementDragEnd = WebInspector._elementEndDraggingEventListener; 190 var elementDragEnd = WebInspector._elementEndDraggingEventListener;
191 191
192 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); 192 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event));
193 193
194 event.preventDefault(); 194 event.preventDefault();
195 if (elementDragEnd) 195 if (elementDragEnd)
196 elementDragEnd(/** @type {!MouseEvent} */ (event)); 196 elementDragEnd(/** @type {!MouseEvent} */ (event));
197 } 197 }
198 198
199 /** 199 /**
200 * @param {!Element} element
201 * @param {function(number, number, !MouseEvent): boolean} elementDragStart
202 * @param {function(number, number)} elementDrag
203 * @param {function(number, number)} elementDragEnd
204 * @param {string} cursor
205 * @param {?string=} hoverCursor
206 * @param {number=} startDelay
207 * @param {number=} friction
208 */
209 WebInspector.installInertialDragHandle = function(element, elementDragStart, ele mentDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction)
210 {
211 WebInspector.installDragHandle(element, drag.bind(null, elementDragStart), d rag.bind(null, elementDrag), dragEnd, cursor, hoverCursor, startDelay);
212 if (typeof friction !== "number")
213 friction = 50;
214 var lastX;
215 var lastY;
216 var lastTime;
217 var velocityX;
218 var velocityY;
219 var holding = false;
220
221 /**
222 * @param {function(number, number, !MouseEvent): boolean} callback
223 * @param {!MouseEvent} event
224 * @return {boolean}
225 */
226 function drag(callback, event)
227 {
228 lastTime = window.performance.now();
229 lastX = event.pageX;
230 lastY = event.pageY;
231 holding = true;
232 return callback(lastX, lastY, event);
233 }
234
235 /**
236 * @param {!MouseEvent} event
237 */
238 function dragEnd(event)
239 {
240 var now = window.performance.now();
241 var maxVelocity = 4; // 4px per millisecond.
242 var duration = now - lastTime || 1;
243 velocityX = Number.constrain((event.pageX - lastX) / duration, -maxVeloc ity, maxVelocity);
244 velocityY = Number.constrain((event.pageY - lastY) / duration, -maxVeloc ity, maxVelocity);
245 lastX = event.pageX;
246 lastY = event.pageY;
247 lastTime = now;
248 holding = false;
249 elementDrag(lastX, lastY);
250 element.window().requestAnimationFrame(animationStep);
251 }
252
253 function animationStep()
254 {
255 var v2 = velocityX * velocityX + velocityY * velocityY;
256 if (v2 < 0.001 || holding) {
257 elementDragEnd(lastX, lastY);
258 return;
259 }
260 var now = window.performance.now();
261 var duration = now - lastTime || 1;
262 element.window().requestAnimationFrame(animationStep);
263 lastTime = now;
264 lastX += velocityX * duration;
265 lastY += velocityY * duration;
266 var k = Math.pow(1 / (1 + friction), duration / 1000);
267 velocityX *= k;
268 velocityY *= k;
269 elementDrag(lastX, lastY);
270 }
271 }
272
273 /**
274 * @constructor 200 * @constructor
275 * @param {!Document} document 201 * @param {!Document} document
276 * @param {boolean=} dimmed 202 * @param {boolean=} dimmed
277 */ 203 */
278 WebInspector.GlassPane = function(document, dimmed) 204 WebInspector.GlassPane = function(document, dimmed)
279 { 205 {
280 this.element = createElement("div"); 206 this.element = createElement("div");
281 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent"; 207 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent";
282 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1 000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be low. 208 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1 000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be low.
283 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right: 0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd en;"; 209 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right: 0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd en;";
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 * @param {string} title 1915 * @param {string} title
1990 * @return {!Element} 1916 * @return {!Element}
1991 */ 1917 */
1992 WebInspector.linkifyDocumentationURLAsNode = function(article, title) 1918 WebInspector.linkifyDocumentationURLAsNode = function(article, title)
1993 { 1919 {
1994 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true); 1920 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true);
1995 } 1921 }
1996 1922
1997 /** @type {!WebInspector.ThemeSupport} */ 1923 /** @type {!WebInspector.ThemeSupport} */
1998 WebInspector.themeSupport; 1924 WebInspector.themeSupport;
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698