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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/perf_ui/OverviewGrid.js

Issue 2623743002: DevTools: extract modules (non-extensions) (Closed)
Patch Set: rebaseline Created 3 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 UI.OverviewGrid = class { 34 PerfUI.OverviewGrid = class {
35 /** 35 /**
36 * @param {string} prefix 36 * @param {string} prefix
37 */ 37 */
38 constructor(prefix) { 38 constructor(prefix) {
39 this.element = createElement('div'); 39 this.element = createElement('div');
40 this.element.id = prefix + '-overview-container'; 40 this.element.id = prefix + '-overview-container';
41 41
42 this._grid = new UI.TimelineGrid(); 42 this._grid = new PerfUI.TimelineGrid();
43 this._grid.element.id = prefix + '-overview-grid'; 43 this._grid.element.id = prefix + '-overview-grid';
44 this._grid.setScrollTop(0); 44 this._grid.setScrollTop(0);
45 45
46 this.element.appendChild(this._grid.element); 46 this.element.appendChild(this._grid.element);
47 47
48 this._window = new UI.OverviewGrid.Window(this.element, this._grid.dividersL abelBarElement); 48 this._window = new PerfUI.OverviewGrid.Window(this.element, this._grid.divid ersLabelBarElement);
49 } 49 }
50 50
51 /** 51 /**
52 * @return {number} 52 * @return {number}
53 */ 53 */
54 clientWidth() { 54 clientWidth() {
55 return this.element.clientWidth; 55 return this.element.clientWidth;
56 } 56 }
57 57
58 /** 58 /**
59 * @param {!UI.TimelineGrid.Calculator} calculator 59 * @param {!PerfUI.TimelineGrid.Calculator} calculator
60 */ 60 */
61 updateDividers(calculator) { 61 updateDividers(calculator) {
62 this._grid.updateDividers(calculator); 62 this._grid.updateDividers(calculator);
63 } 63 }
64 64
65 /** 65 /**
66 * @param {!Array.<!Element>} dividers 66 * @param {!Array.<!Element>} dividers
67 */ 67 */
68 addEventDividers(dividers) { 68 addEventDividers(dividers) {
69 this._grid.addEventDividers(dividers); 69 this._grid.addEventDividers(dividers);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 /** 127 /**
128 * @param {boolean} enabled 128 * @param {boolean} enabled
129 */ 129 */
130 setResizeEnabled(enabled) { 130 setResizeEnabled(enabled) {
131 this._window.setEnabled(enabled); 131 this._window.setEnabled(enabled);
132 } 132 }
133 }; 133 };
134 134
135 UI.OverviewGrid.MinSelectableSize = 14; 135 PerfUI.OverviewGrid.MinSelectableSize = 14;
136 136
137 UI.OverviewGrid.WindowScrollSpeedFactor = .3; 137 PerfUI.OverviewGrid.WindowScrollSpeedFactor = .3;
138 138
139 UI.OverviewGrid.ResizerOffset = 3.5; // half pixel because offset values are no t rounded but ceiled 139 PerfUI.OverviewGrid.ResizerOffset = 3.5; // half pixel because offset values ar e not rounded but ceiled
140 140
141 /** 141 /**
142 * @unrestricted 142 * @unrestricted
143 */ 143 */
144 UI.OverviewGrid.Window = class extends Common.Object { 144 PerfUI.OverviewGrid.Window = class extends Common.Object {
145 /** 145 /**
146 * @param {!Element} parentElement 146 * @param {!Element} parentElement
147 * @param {!Element=} dividersLabelBarElement 147 * @param {!Element=} dividersLabelBarElement
148 */ 148 */
149 constructor(parentElement, dividersLabelBarElement) { 149 constructor(parentElement, dividersLabelBarElement) {
150 super(); 150 super();
151 this._parentElement = parentElement; 151 this._parentElement = parentElement;
152 152
153 UI.installDragHandle( 153 UI.installDragHandle(
154 this._parentElement, this._startWindowSelectorDragging.bind(this), this. _windowSelectorDragging.bind(this), 154 this._parentElement, this._startWindowSelectorDragging.bind(this), this. _windowSelectorDragging.bind(this),
155 this._endWindowSelectorDragging.bind(this), 'text', null); 155 this._endWindowSelectorDragging.bind(this), 'text', null);
156 if (dividersLabelBarElement) { 156 if (dividersLabelBarElement) {
157 UI.installDragHandle( 157 UI.installDragHandle(
158 dividersLabelBarElement, this._startWindowDragging.bind(this), this._w indowDragging.bind(this), null, 158 dividersLabelBarElement, this._startWindowDragging.bind(this), this._w indowDragging.bind(this), null,
159 '-webkit-grabbing', '-webkit-grab'); 159 '-webkit-grabbing', '-webkit-grab');
160 } 160 }
161 161
162 this._parentElement.addEventListener('mousewheel', this._onMouseWheel.bind(t his), true); 162 this._parentElement.addEventListener('mousewheel', this._onMouseWheel.bind(t his), true);
163 this._parentElement.addEventListener('dblclick', this._resizeWindowMaximum.b ind(this), true); 163 this._parentElement.addEventListener('dblclick', this._resizeWindowMaximum.b ind(this), true);
164 UI.appendStyle(this._parentElement, 'ui_lazy/overviewGrid.css'); 164 UI.appendStyle(this._parentElement, 'perf_ui/overviewGrid.css');
165 165
166 this._leftResizeElement = parentElement.createChild('div', 'overview-grid-wi ndow-resizer'); 166 this._leftResizeElement = parentElement.createChild('div', 'overview-grid-wi ndow-resizer');
167 UI.installDragHandle( 167 UI.installDragHandle(
168 this._leftResizeElement, this._resizerElementStartDragging.bind(this), 168 this._leftResizeElement, this._resizerElementStartDragging.bind(this),
169 this._leftResizeElementDragging.bind(this), null, 'ew-resize'); 169 this._leftResizeElementDragging.bind(this), null, 'ew-resize');
170 this._rightResizeElement = parentElement.createChild('div', 'overview-grid-w indow-resizer'); 170 this._rightResizeElement = parentElement.createChild('div', 'overview-grid-w indow-resizer');
171 UI.installDragHandle( 171 UI.installDragHandle(
172 this._rightResizeElement, this._resizerElementStartDragging.bind(this), 172 this._rightResizeElement, this._resizerElementStartDragging.bind(this),
173 this._rightResizeElementDragging.bind(this), null, 'ew-resize'); 173 this._rightResizeElementDragging.bind(this), null, 'ew-resize');
174 174
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 227
228 /** 228 /**
229 * @param {!Event} event 229 * @param {!Event} event
230 * @return {boolean} 230 * @return {boolean}
231 */ 231 */
232 _startWindowSelectorDragging(event) { 232 _startWindowSelectorDragging(event) {
233 if (!this._enabled) 233 if (!this._enabled)
234 return false; 234 return false;
235 this._offsetLeft = this._parentElement.totalOffsetLeft(); 235 this._offsetLeft = this._parentElement.totalOffsetLeft();
236 var position = event.x - this._offsetLeft; 236 var position = event.x - this._offsetLeft;
237 this._overviewWindowSelector = new UI.OverviewGrid.WindowSelector(this._pare ntElement, position); 237 this._overviewWindowSelector = new PerfUI.OverviewGrid.WindowSelector(this._ parentElement, position);
238 return true; 238 return true;
239 } 239 }
240 240
241 /** 241 /**
242 * @param {!Event} event 242 * @param {!Event} event
243 */ 243 */
244 _windowSelectorDragging(event) { 244 _windowSelectorDragging(event) {
245 this._overviewWindowSelector._updatePosition(event.x - this._offsetLeft); 245 this._overviewWindowSelector._updatePosition(event.x - this._offsetLeft);
246 event.preventDefault(); 246 event.preventDefault();
247 } 247 }
248 248
249 /** 249 /**
250 * @param {!Event} event 250 * @param {!Event} event
251 */ 251 */
252 _endWindowSelectorDragging(event) { 252 _endWindowSelectorDragging(event) {
253 var window = this._overviewWindowSelector._close(event.x - this._offsetLeft) ; 253 var window = this._overviewWindowSelector._close(event.x - this._offsetLeft) ;
254 delete this._overviewWindowSelector; 254 delete this._overviewWindowSelector;
255 var clickThreshold = 3; 255 var clickThreshold = 3;
256 if (window.end - window.start < clickThreshold) { 256 if (window.end - window.start < clickThreshold) {
257 if (this._clickHandler && this._clickHandler.call(null, event)) 257 if (this._clickHandler && this._clickHandler.call(null, event))
258 return; 258 return;
259 var middle = window.end; 259 var middle = window.end;
260 window.start = Math.max(0, middle - UI.OverviewGrid.MinSelectableSize / 2) ; 260 window.start = Math.max(0, middle - PerfUI.OverviewGrid.MinSelectableSize / 2);
261 window.end = Math.min(this._parentElement.clientWidth, middle + UI.Overvie wGrid.MinSelectableSize / 2); 261 window.end = Math.min(this._parentElement.clientWidth, middle + PerfUI.Ove rviewGrid.MinSelectableSize / 2);
262 } else if (window.end - window.start < UI.OverviewGrid.MinSelectableSize) { 262 } else if (window.end - window.start < PerfUI.OverviewGrid.MinSelectableSize ) {
263 if (this._parentElement.clientWidth - window.end > UI.OverviewGrid.MinSele ctableSize) 263 if (this._parentElement.clientWidth - window.end > PerfUI.OverviewGrid.Min SelectableSize)
264 window.end = window.start + UI.OverviewGrid.MinSelectableSize; 264 window.end = window.start + PerfUI.OverviewGrid.MinSelectableSize;
265 else 265 else
266 window.start = window.end - UI.OverviewGrid.MinSelectableSize; 266 window.start = window.end - PerfUI.OverviewGrid.MinSelectableSize;
267 } 267 }
268 this._setWindowPosition(window.start, window.end); 268 this._setWindowPosition(window.start, window.end);
269 } 269 }
270 270
271 /** 271 /**
272 * @param {!Event} event 272 * @param {!Event} event
273 * @return {boolean} 273 * @return {boolean}
274 */ 274 */
275 _startWindowDragging(event) { 275 _startWindowDragging(event) {
276 this._dragStartPoint = event.pageX; 276 this._dragStartPoint = event.pageX;
(...skipping 30 matching lines...) Expand all
307 this._setWindowPosition(start, null); 307 this._setWindowPosition(start, null);
308 } 308 }
309 309
310 /** 310 /**
311 * @param {number} end 311 * @param {number} end
312 */ 312 */
313 _resizeWindowRight(end) { 313 _resizeWindowRight(end) {
314 // Glue to edge. 314 // Glue to edge.
315 if (end > this._parentElement.clientWidth - 10) 315 if (end > this._parentElement.clientWidth - 10)
316 end = this._parentElement.clientWidth; 316 end = this._parentElement.clientWidth;
317 else if (end < this._leftResizeElement.offsetLeft + UI.OverviewGrid.MinSelec tableSize) 317 else if (end < this._leftResizeElement.offsetLeft + PerfUI.OverviewGrid.MinS electableSize)
318 end = this._leftResizeElement.offsetLeft + UI.OverviewGrid.MinSelectableSi ze; 318 end = this._leftResizeElement.offsetLeft + PerfUI.OverviewGrid.MinSelectab leSize;
319 this._setWindowPosition(null, end); 319 this._setWindowPosition(null, end);
320 } 320 }
321 321
322 _resizeWindowMaximum() { 322 _resizeWindowMaximum() {
323 this._setWindowPosition(0, this._parentElement.clientWidth); 323 this._setWindowPosition(0, this._parentElement.clientWidth);
324 } 324 }
325 325
326 /** 326 /**
327 * @param {number} windowLeft 327 * @param {number} windowLeft
328 * @param {number} windowRight 328 * @param {number} windowRight
329 */ 329 */
330 _setWindow(windowLeft, windowRight) { 330 _setWindow(windowLeft, windowRight) {
331 this.windowLeft = windowLeft; 331 this.windowLeft = windowLeft;
332 this.windowRight = windowRight; 332 this.windowRight = windowRight;
333 this._updateCurtains(); 333 this._updateCurtains();
334 this.dispatchEventToListeners(UI.OverviewGrid.Events.WindowChanged); 334 this.dispatchEventToListeners(PerfUI.OverviewGrid.Events.WindowChanged);
335 } 335 }
336 336
337 _updateCurtains() { 337 _updateCurtains() {
338 var left = this.windowLeft; 338 var left = this.windowLeft;
339 var right = this.windowRight; 339 var right = this.windowRight;
340 var width = right - left; 340 var width = right - left;
341 341
342 // We allow actual time window to be arbitrarily small but don't want the UI window to be too small. 342 // We allow actual time window to be arbitrarily small but don't want the UI window to be too small.
343 var widthInPixels = width * this._parentElement.clientWidth; 343 var widthInPixels = width * this._parentElement.clientWidth;
344 var minWidthInPixels = UI.OverviewGrid.MinSelectableSize / 2; 344 var minWidthInPixels = PerfUI.OverviewGrid.MinSelectableSize / 2;
345 if (widthInPixels < minWidthInPixels) { 345 if (widthInPixels < minWidthInPixels) {
346 var factor = minWidthInPixels / widthInPixels; 346 var factor = minWidthInPixels / widthInPixels;
347 left = ((this.windowRight + this.windowLeft) - width * factor) / 2; 347 left = ((this.windowRight + this.windowLeft) - width * factor) / 2;
348 right = ((this.windowRight + this.windowLeft) + width * factor) / 2; 348 right = ((this.windowRight + this.windowLeft) + width * factor) / 2;
349 } 349 }
350 this._leftResizeElement.style.left = (100 * left).toFixed(2) + '%'; 350 this._leftResizeElement.style.left = (100 * left).toFixed(2) + '%';
351 this._rightResizeElement.style.left = (100 * right).toFixed(2) + '%'; 351 this._rightResizeElement.style.left = (100 * right).toFixed(2) + '%';
352 352
353 this._leftCurtainElement.style.width = (100 * left).toFixed(2) + '%'; 353 this._leftCurtainElement.style.width = (100 * left).toFixed(2) + '%';
354 this._rightCurtainElement.style.width = (100 * (1 - right)).toFixed(2) + '%' ; 354 this._rightCurtainElement.style.width = (100 * (1 - right)).toFixed(2) + '%' ;
(...skipping 17 matching lines...) Expand all
372 if (!this._enabled) 372 if (!this._enabled)
373 return; 373 return;
374 if (typeof event.wheelDeltaY === 'number' && event.wheelDeltaY) { 374 if (typeof event.wheelDeltaY === 'number' && event.wheelDeltaY) {
375 const zoomFactor = 1.1; 375 const zoomFactor = 1.1;
376 const mouseWheelZoomSpeed = 1 / 120; 376 const mouseWheelZoomSpeed = 1 / 120;
377 377
378 var reference = event.offsetX / event.target.clientWidth; 378 var reference = event.offsetX / event.target.clientWidth;
379 this._zoom(Math.pow(zoomFactor, -event.wheelDeltaY * mouseWheelZoomSpeed), reference); 379 this._zoom(Math.pow(zoomFactor, -event.wheelDeltaY * mouseWheelZoomSpeed), reference);
380 } 380 }
381 if (typeof event.wheelDeltaX === 'number' && event.wheelDeltaX) { 381 if (typeof event.wheelDeltaX === 'number' && event.wheelDeltaX) {
382 var offset = Math.round(event.wheelDeltaX * UI.OverviewGrid.WindowScrollSp eedFactor); 382 var offset = Math.round(event.wheelDeltaX * PerfUI.OverviewGrid.WindowScro llSpeedFactor);
383 var windowLeft = this._leftResizeElement.offsetLeft + UI.OverviewGrid.Resi zerOffset; 383 var windowLeft = this._leftResizeElement.offsetLeft + PerfUI.OverviewGrid. ResizerOffset;
384 var windowRight = this._rightResizeElement.offsetLeft + UI.OverviewGrid.Re sizerOffset; 384 var windowRight = this._rightResizeElement.offsetLeft + PerfUI.OverviewGri d.ResizerOffset;
385 385
386 if (windowLeft - offset < 0) 386 if (windowLeft - offset < 0)
387 offset = windowLeft; 387 offset = windowLeft;
388 388
389 if (windowRight - offset > this._parentElement.clientWidth) 389 if (windowRight - offset > this._parentElement.clientWidth)
390 offset = windowRight - this._parentElement.clientWidth; 390 offset = windowRight - this._parentElement.clientWidth;
391 391
392 this._setWindowPosition(windowLeft - offset, windowRight - offset); 392 this._setWindowPosition(windowLeft - offset, windowRight - offset);
393 393
394 event.preventDefault(); 394 event.preventDefault();
(...skipping 16 matching lines...) Expand all
411 left = reference + (left - reference) * factor; 411 left = reference + (left - reference) * factor;
412 left = Number.constrain(left, 0, 1 - newWindowSize); 412 left = Number.constrain(left, 0, 1 - newWindowSize);
413 413
414 right = reference + (right - reference) * factor; 414 right = reference + (right - reference) * factor;
415 right = Number.constrain(right, newWindowSize, 1); 415 right = Number.constrain(right, newWindowSize, 1);
416 this._setWindow(left, right); 416 this._setWindow(left, right);
417 } 417 }
418 }; 418 };
419 419
420 /** @enum {symbol} */ 420 /** @enum {symbol} */
421 UI.OverviewGrid.Events = { 421 PerfUI.OverviewGrid.Events = {
422 WindowChanged: Symbol('WindowChanged') 422 WindowChanged: Symbol('WindowChanged')
423 }; 423 };
424 424
425 /** 425 /**
426 * @unrestricted 426 * @unrestricted
427 */ 427 */
428 UI.OverviewGrid.WindowSelector = class { 428 PerfUI.OverviewGrid.WindowSelector = class {
429 constructor(parent, position) { 429 constructor(parent, position) {
430 this._startPosition = position; 430 this._startPosition = position;
431 this._width = parent.offsetWidth; 431 this._width = parent.offsetWidth;
432 this._windowSelector = createElement('div'); 432 this._windowSelector = createElement('div');
433 this._windowSelector.className = 'overview-grid-window-selector'; 433 this._windowSelector.className = 'overview-grid-window-selector';
434 this._windowSelector.style.left = this._startPosition + 'px'; 434 this._windowSelector.style.left = this._startPosition + 'px';
435 this._windowSelector.style.right = this._width - this._startPosition + 'px'; 435 this._windowSelector.style.right = this._width - this._startPosition + 'px';
436 parent.appendChild(this._windowSelector); 436 parent.appendChild(this._windowSelector);
437 } 437 }
438 438
439 _close(position) { 439 _close(position) {
440 position = Math.max(0, Math.min(position, this._width)); 440 position = Math.max(0, Math.min(position, this._width));
441 this._windowSelector.remove(); 441 this._windowSelector.remove();
442 return this._startPosition < position ? {start: this._startPosition, end: po sition} : 442 return this._startPosition < position ? {start: this._startPosition, end: po sition} :
443 {start: position, end: this._startPo sition}; 443 {start: position, end: this._startPo sition};
444 } 444 }
445 445
446 _updatePosition(position) { 446 _updatePosition(position) {
447 position = Math.max(0, Math.min(position, this._width)); 447 position = Math.max(0, Math.min(position, this._width));
448 if (position < this._startPosition) { 448 if (position < this._startPosition) {
449 this._windowSelector.style.left = position + 'px'; 449 this._windowSelector.style.left = position + 'px';
450 this._windowSelector.style.right = this._width - this._startPosition + 'px '; 450 this._windowSelector.style.right = this._width - this._startPosition + 'px ';
451 } else { 451 } else {
452 this._windowSelector.style.left = this._startPosition + 'px'; 452 this._windowSelector.style.left = this._startPosition + 'px';
453 this._windowSelector.style.right = this._width - position + 'px'; 453 this._windowSelector.style.right = this._width - position + 'px';
454 } 454 }
455 } 455 }
456 }; 456 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698