| OLD | NEW |
| 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @param {string} prefix | |
| 34 */ | 32 */ |
| 35 WebInspector.OverviewGrid = function(prefix) | 33 WebInspector.OverviewGrid = class { |
| 36 { | 34 /** |
| 37 this.element = createElement("div"); | 35 * @param {string} prefix |
| 38 this.element.id = prefix + "-overview-container"; | 36 */ |
| 37 constructor(prefix) { |
| 38 this.element = createElement('div'); |
| 39 this.element.id = prefix + '-overview-container'; |
| 39 | 40 |
| 40 this._grid = new WebInspector.TimelineGrid(); | 41 this._grid = new WebInspector.TimelineGrid(); |
| 41 this._grid.element.id = prefix + "-overview-grid"; | 42 this._grid.element.id = prefix + '-overview-grid'; |
| 42 this._grid.setScrollTop(0); | 43 this._grid.setScrollTop(0); |
| 43 | 44 |
| 44 this.element.appendChild(this._grid.element); | 45 this.element.appendChild(this._grid.element); |
| 45 | 46 |
| 46 this._window = new WebInspector.OverviewGrid.Window(this.element, this._grid
.dividersLabelBarElement); | 47 this._window = new WebInspector.OverviewGrid.Window(this.element, this._grid
.dividersLabelBarElement); |
| 48 } |
| 49 |
| 50 /** |
| 51 * @return {number} |
| 52 */ |
| 53 clientWidth() { |
| 54 return this.element.clientWidth; |
| 55 } |
| 56 |
| 57 /** |
| 58 * @param {!WebInspector.TimelineGrid.Calculator} calculator |
| 59 */ |
| 60 updateDividers(calculator) { |
| 61 this._grid.updateDividers(calculator); |
| 62 } |
| 63 |
| 64 /** |
| 65 * @param {!Array.<!Element>} dividers |
| 66 */ |
| 67 addEventDividers(dividers) { |
| 68 this._grid.addEventDividers(dividers); |
| 69 } |
| 70 |
| 71 removeEventDividers() { |
| 72 this._grid.removeEventDividers(); |
| 73 } |
| 74 |
| 75 reset() { |
| 76 this._window.reset(); |
| 77 } |
| 78 |
| 79 /** |
| 80 * @return {number} |
| 81 */ |
| 82 windowLeft() { |
| 83 return this._window.windowLeft; |
| 84 } |
| 85 |
| 86 /** |
| 87 * @return {number} |
| 88 */ |
| 89 windowRight() { |
| 90 return this._window.windowRight; |
| 91 } |
| 92 |
| 93 /** |
| 94 * @param {number} left |
| 95 * @param {number} right |
| 96 */ |
| 97 setWindow(left, right) { |
| 98 this._window._setWindow(left, right); |
| 99 } |
| 100 |
| 101 /** |
| 102 * @param {string} eventType |
| 103 * @param {function(!WebInspector.Event)} listener |
| 104 * @param {!Object=} thisObject |
| 105 * @return {!WebInspector.EventTarget.EventDescriptor} |
| 106 */ |
| 107 addEventListener(eventType, listener, thisObject) { |
| 108 return this._window.addEventListener(eventType, listener, thisObject); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @param {number} zoomFactor |
| 113 * @param {number} referencePoint |
| 114 */ |
| 115 zoom(zoomFactor, referencePoint) { |
| 116 this._window._zoom(zoomFactor, referencePoint); |
| 117 } |
| 118 |
| 119 /** |
| 120 * @param {boolean} enabled |
| 121 */ |
| 122 setResizeEnabled(enabled) { |
| 123 this._window.setEnabled(enabled); |
| 124 } |
| 47 }; | 125 }; |
| 48 | 126 |
| 49 WebInspector.OverviewGrid.prototype = { | |
| 50 /** | |
| 51 * @return {number} | |
| 52 */ | |
| 53 clientWidth: function() | |
| 54 { | |
| 55 return this.element.clientWidth; | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * @param {!WebInspector.TimelineGrid.Calculator} calculator | |
| 60 */ | |
| 61 updateDividers: function(calculator) | |
| 62 { | |
| 63 this._grid.updateDividers(calculator); | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 67 * @param {!Array.<!Element>} dividers | |
| 68 */ | |
| 69 addEventDividers: function(dividers) | |
| 70 { | |
| 71 this._grid.addEventDividers(dividers); | |
| 72 }, | |
| 73 | |
| 74 removeEventDividers: function() | |
| 75 { | |
| 76 this._grid.removeEventDividers(); | |
| 77 }, | |
| 78 | |
| 79 reset: function() | |
| 80 { | |
| 81 this._window.reset(); | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 85 * @return {number} | |
| 86 */ | |
| 87 windowLeft: function() | |
| 88 { | |
| 89 return this._window.windowLeft; | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * @return {number} | |
| 94 */ | |
| 95 windowRight: function() | |
| 96 { | |
| 97 return this._window.windowRight; | |
| 98 }, | |
| 99 | |
| 100 /** | |
| 101 * @param {number} left | |
| 102 * @param {number} right | |
| 103 */ | |
| 104 setWindow: function(left, right) | |
| 105 { | |
| 106 this._window._setWindow(left, right); | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * @param {string} eventType | |
| 111 * @param {function(!WebInspector.Event)} listener | |
| 112 * @param {!Object=} thisObject | |
| 113 * @return {!WebInspector.EventTarget.EventDescriptor} | |
| 114 */ | |
| 115 addEventListener: function(eventType, listener, thisObject) | |
| 116 { | |
| 117 return this._window.addEventListener(eventType, listener, thisObject); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * @param {number} zoomFactor | |
| 122 * @param {number} referencePoint | |
| 123 */ | |
| 124 zoom: function(zoomFactor, referencePoint) | |
| 125 { | |
| 126 this._window._zoom(zoomFactor, referencePoint); | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * @param {boolean} enabled | |
| 131 */ | |
| 132 setResizeEnabled: function(enabled) | |
| 133 { | |
| 134 this._window.setEnabled(enabled); | |
| 135 } | |
| 136 }; | |
| 137 | |
| 138 | |
| 139 WebInspector.OverviewGrid.MinSelectableSize = 14; | 127 WebInspector.OverviewGrid.MinSelectableSize = 14; |
| 140 | 128 |
| 141 WebInspector.OverviewGrid.WindowScrollSpeedFactor = .3; | 129 WebInspector.OverviewGrid.WindowScrollSpeedFactor = .3; |
| 142 | 130 |
| 143 WebInspector.OverviewGrid.ResizerOffset = 3.5; // half pixel because offset valu
es are not rounded but ceiled | 131 WebInspector.OverviewGrid.ResizerOffset = 3.5; // half pixel because offset val
ues are not rounded but ceiled |
| 144 | 132 |
| 145 /** | 133 /** |
| 146 * @constructor | 134 * @unrestricted |
| 147 * @extends {WebInspector.Object} | |
| 148 * @param {!Element} parentElement | |
| 149 * @param {!Element=} dividersLabelBarElement | |
| 150 */ | 135 */ |
| 151 WebInspector.OverviewGrid.Window = function(parentElement, dividersLabelBarEleme
nt) | 136 WebInspector.OverviewGrid.Window = class extends WebInspector.Object { |
| 152 { | 137 /** |
| 138 * @param {!Element} parentElement |
| 139 * @param {!Element=} dividersLabelBarElement |
| 140 */ |
| 141 constructor(parentElement, dividersLabelBarElement) { |
| 142 super(); |
| 153 this._parentElement = parentElement; | 143 this._parentElement = parentElement; |
| 154 | 144 |
| 155 WebInspector.installDragHandle(this._parentElement, this._startWindowSelecto
rDragging.bind(this), this._windowSelectorDragging.bind(this), this._endWindowSe
lectorDragging.bind(this), "text", null); | 145 WebInspector.installDragHandle( |
| 146 this._parentElement, this._startWindowSelectorDragging.bind(this), this.
_windowSelectorDragging.bind(this), |
| 147 this._endWindowSelectorDragging.bind(this), 'text', null); |
| 156 if (dividersLabelBarElement) | 148 if (dividersLabelBarElement) |
| 157 WebInspector.installDragHandle(dividersLabelBarElement, this._startWindo
wDragging.bind(this), this._windowDragging.bind(this), null, "-webkit-grabbing",
"-webkit-grab"); | 149 WebInspector.installDragHandle( |
| 158 | 150 dividersLabelBarElement, this._startWindowDragging.bind(this), this._w
indowDragging.bind(this), null, |
| 159 this._parentElement.addEventListener("mousewheel", this._onMouseWheel.bind(t
his), true); | 151 '-webkit-grabbing', '-webkit-grab'); |
| 160 this._parentElement.addEventListener("dblclick", this._resizeWindowMaximum.b
ind(this), true); | 152 |
| 161 WebInspector.appendStyle(this._parentElement, "ui_lazy/overviewGrid.css"); | 153 this._parentElement.addEventListener('mousewheel', this._onMouseWheel.bind(t
his), true); |
| 162 | 154 this._parentElement.addEventListener('dblclick', this._resizeWindowMaximum.b
ind(this), true); |
| 163 this._leftResizeElement = parentElement.createChild("div", "overview-grid-wi
ndow-resizer"); | 155 WebInspector.appendStyle(this._parentElement, 'ui_lazy/overviewGrid.css'); |
| 164 WebInspector.installDragHandle(this._leftResizeElement, this._resizerElement
StartDragging.bind(this), this._leftResizeElementDragging.bind(this), null, "ew-
resize"); | 156 |
| 165 this._rightResizeElement = parentElement.createChild("div", "overview-grid-w
indow-resizer"); | 157 this._leftResizeElement = parentElement.createChild('div', 'overview-grid-wi
ndow-resizer'); |
| 166 WebInspector.installDragHandle(this._rightResizeElement, this._resizerElemen
tStartDragging.bind(this), this._rightResizeElementDragging.bind(this), null, "e
w-resize"); | 158 WebInspector.installDragHandle( |
| 167 | 159 this._leftResizeElement, this._resizerElementStartDragging.bind(this), |
| 168 this._leftCurtainElement = parentElement.createChild("div", "window-curtain-
left"); | 160 this._leftResizeElementDragging.bind(this), null, 'ew-resize'); |
| 169 this._rightCurtainElement = parentElement.createChild("div", "window-curtain
-right"); | 161 this._rightResizeElement = parentElement.createChild('div', 'overview-grid-w
indow-resizer'); |
| 162 WebInspector.installDragHandle( |
| 163 this._rightResizeElement, this._resizerElementStartDragging.bind(this), |
| 164 this._rightResizeElementDragging.bind(this), null, 'ew-resize'); |
| 165 |
| 166 this._leftCurtainElement = parentElement.createChild('div', 'window-curtain-
left'); |
| 167 this._rightCurtainElement = parentElement.createChild('div', 'window-curtain
-right'); |
| 170 this.reset(); | 168 this.reset(); |
| 169 } |
| 170 |
| 171 reset() { |
| 172 this.windowLeft = 0.0; |
| 173 this.windowRight = 1.0; |
| 174 this.setEnabled(true); |
| 175 this._updateCurtains(); |
| 176 } |
| 177 |
| 178 /** |
| 179 * @param {boolean} enabled |
| 180 */ |
| 181 setEnabled(enabled) { |
| 182 this._enabled = enabled; |
| 183 } |
| 184 |
| 185 /** |
| 186 * @param {!Event} event |
| 187 */ |
| 188 _resizerElementStartDragging(event) { |
| 189 if (!this._enabled) |
| 190 return false; |
| 191 this._resizerParentOffsetLeft = event.pageX - event.offsetX - event.target.o
ffsetLeft; |
| 192 event.preventDefault(); |
| 193 return true; |
| 194 } |
| 195 |
| 196 /** |
| 197 * @param {!Event} event |
| 198 */ |
| 199 _leftResizeElementDragging(event) { |
| 200 this._resizeWindowLeft(event.pageX - this._resizerParentOffsetLeft); |
| 201 event.preventDefault(); |
| 202 } |
| 203 |
| 204 /** |
| 205 * @param {!Event} event |
| 206 */ |
| 207 _rightResizeElementDragging(event) { |
| 208 this._resizeWindowRight(event.pageX - this._resizerParentOffsetLeft); |
| 209 event.preventDefault(); |
| 210 } |
| 211 |
| 212 /** |
| 213 * @param {!Event} event |
| 214 * @return {boolean} |
| 215 */ |
| 216 _startWindowSelectorDragging(event) { |
| 217 if (!this._enabled) |
| 218 return false; |
| 219 this._offsetLeft = this._parentElement.totalOffsetLeft(); |
| 220 var position = event.x - this._offsetLeft; |
| 221 this._overviewWindowSelector = new WebInspector.OverviewGrid.WindowSelector(
this._parentElement, position); |
| 222 return true; |
| 223 } |
| 224 |
| 225 /** |
| 226 * @param {!Event} event |
| 227 */ |
| 228 _windowSelectorDragging(event) { |
| 229 this._overviewWindowSelector._updatePosition(event.x - this._offsetLeft); |
| 230 event.preventDefault(); |
| 231 } |
| 232 |
| 233 /** |
| 234 * @param {!Event} event |
| 235 */ |
| 236 _endWindowSelectorDragging(event) { |
| 237 var window = this._overviewWindowSelector._close(event.x - this._offsetLeft)
; |
| 238 delete this._overviewWindowSelector; |
| 239 var clickThreshold = 3; |
| 240 if (window.end - window.start < clickThreshold) { |
| 241 if (this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.Click,
event)) |
| 242 return; |
| 243 var middle = window.end; |
| 244 window.start = Math.max(0, middle - WebInspector.OverviewGrid.MinSelectabl
eSize / 2); |
| 245 window.end = Math.min(this._parentElement.clientWidth, middle + WebInspect
or.OverviewGrid.MinSelectableSize / 2); |
| 246 } else if (window.end - window.start < WebInspector.OverviewGrid.MinSelectab
leSize) { |
| 247 if (this._parentElement.clientWidth - window.end > WebInspector.OverviewGr
id.MinSelectableSize) |
| 248 window.end = window.start + WebInspector.OverviewGrid.MinSelectableSize; |
| 249 else |
| 250 window.start = window.end - WebInspector.OverviewGrid.MinSelectableSize; |
| 251 } |
| 252 this._setWindowPosition(window.start, window.end); |
| 253 } |
| 254 |
| 255 /** |
| 256 * @param {!Event} event |
| 257 * @return {boolean} |
| 258 */ |
| 259 _startWindowDragging(event) { |
| 260 this._dragStartPoint = event.pageX; |
| 261 this._dragStartLeft = this.windowLeft; |
| 262 this._dragStartRight = this.windowRight; |
| 263 event.stopPropagation(); |
| 264 return true; |
| 265 } |
| 266 |
| 267 /** |
| 268 * @param {!Event} event |
| 269 */ |
| 270 _windowDragging(event) { |
| 271 event.preventDefault(); |
| 272 var delta = (event.pageX - this._dragStartPoint) / this._parentElement.clien
tWidth; |
| 273 if (this._dragStartLeft + delta < 0) |
| 274 delta = -this._dragStartLeft; |
| 275 |
| 276 if (this._dragStartRight + delta > 1) |
| 277 delta = 1 - this._dragStartRight; |
| 278 |
| 279 this._setWindow(this._dragStartLeft + delta, this._dragStartRight + delta); |
| 280 } |
| 281 |
| 282 /** |
| 283 * @param {number} start |
| 284 */ |
| 285 _resizeWindowLeft(start) { |
| 286 // Glue to edge. |
| 287 if (start < 10) |
| 288 start = 0; |
| 289 else if (start > this._rightResizeElement.offsetLeft - 4) |
| 290 start = this._rightResizeElement.offsetLeft - 4; |
| 291 this._setWindowPosition(start, null); |
| 292 } |
| 293 |
| 294 /** |
| 295 * @param {number} end |
| 296 */ |
| 297 _resizeWindowRight(end) { |
| 298 // Glue to edge. |
| 299 if (end > this._parentElement.clientWidth - 10) |
| 300 end = this._parentElement.clientWidth; |
| 301 else if (end < this._leftResizeElement.offsetLeft + WebInspector.OverviewGri
d.MinSelectableSize) |
| 302 end = this._leftResizeElement.offsetLeft + WebInspector.OverviewGrid.MinSe
lectableSize; |
| 303 this._setWindowPosition(null, end); |
| 304 } |
| 305 |
| 306 _resizeWindowMaximum() { |
| 307 this._setWindowPosition(0, this._parentElement.clientWidth); |
| 308 } |
| 309 |
| 310 /** |
| 311 * @param {number} windowLeft |
| 312 * @param {number} windowRight |
| 313 */ |
| 314 _setWindow(windowLeft, windowRight) { |
| 315 this.windowLeft = windowLeft; |
| 316 this.windowRight = windowRight; |
| 317 this._updateCurtains(); |
| 318 this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.WindowChanged
); |
| 319 } |
| 320 |
| 321 _updateCurtains() { |
| 322 var left = this.windowLeft; |
| 323 var right = this.windowRight; |
| 324 var width = right - left; |
| 325 |
| 326 // We allow actual time window to be arbitrarily small but don't want the UI
window to be too small. |
| 327 var widthInPixels = width * this._parentElement.clientWidth; |
| 328 var minWidthInPixels = WebInspector.OverviewGrid.MinSelectableSize / 2; |
| 329 if (widthInPixels < minWidthInPixels) { |
| 330 var factor = minWidthInPixels / widthInPixels; |
| 331 left = ((this.windowRight + this.windowLeft) - width * factor) / 2; |
| 332 right = ((this.windowRight + this.windowLeft) + width * factor) / 2; |
| 333 } |
| 334 this._leftResizeElement.style.left = (100 * left).toFixed(2) + '%'; |
| 335 this._rightResizeElement.style.left = (100 * right).toFixed(2) + '%'; |
| 336 |
| 337 this._leftCurtainElement.style.width = (100 * left).toFixed(2) + '%'; |
| 338 this._rightCurtainElement.style.width = (100 * (1 - right)).toFixed(2) + '%'
; |
| 339 } |
| 340 |
| 341 /** |
| 342 * @param {?number} start |
| 343 * @param {?number} end |
| 344 */ |
| 345 _setWindowPosition(start, end) { |
| 346 var clientWidth = this._parentElement.clientWidth; |
| 347 var windowLeft = typeof start === 'number' ? start / clientWidth : this.wind
owLeft; |
| 348 var windowRight = typeof end === 'number' ? end / clientWidth : this.windowR
ight; |
| 349 this._setWindow(windowLeft, windowRight); |
| 350 } |
| 351 |
| 352 /** |
| 353 * @param {!Event} event |
| 354 */ |
| 355 _onMouseWheel(event) { |
| 356 if (!this._enabled) |
| 357 return; |
| 358 if (typeof event.wheelDeltaY === 'number' && event.wheelDeltaY) { |
| 359 const zoomFactor = 1.1; |
| 360 const mouseWheelZoomSpeed = 1 / 120; |
| 361 |
| 362 var reference = event.offsetX / event.target.clientWidth; |
| 363 this._zoom(Math.pow(zoomFactor, -event.wheelDeltaY * mouseWheelZoomSpeed),
reference); |
| 364 } |
| 365 if (typeof event.wheelDeltaX === 'number' && event.wheelDeltaX) { |
| 366 var offset = Math.round(event.wheelDeltaX * WebInspector.OverviewGrid.Wind
owScrollSpeedFactor); |
| 367 var windowLeft = this._leftResizeElement.offsetLeft + WebInspector.Overvie
wGrid.ResizerOffset; |
| 368 var windowRight = this._rightResizeElement.offsetLeft + WebInspector.Overv
iewGrid.ResizerOffset; |
| 369 |
| 370 if (windowLeft - offset < 0) |
| 371 offset = windowLeft; |
| 372 |
| 373 if (windowRight - offset > this._parentElement.clientWidth) |
| 374 offset = windowRight - this._parentElement.clientWidth; |
| 375 |
| 376 this._setWindowPosition(windowLeft - offset, windowRight - offset); |
| 377 |
| 378 event.preventDefault(); |
| 379 } |
| 380 } |
| 381 |
| 382 /** |
| 383 * @param {number} factor |
| 384 * @param {number} reference |
| 385 */ |
| 386 _zoom(factor, reference) { |
| 387 var left = this.windowLeft; |
| 388 var right = this.windowRight; |
| 389 var windowSize = right - left; |
| 390 var newWindowSize = factor * windowSize; |
| 391 if (newWindowSize > 1) { |
| 392 newWindowSize = 1; |
| 393 factor = newWindowSize / windowSize; |
| 394 } |
| 395 left = reference + (left - reference) * factor; |
| 396 left = Number.constrain(left, 0, 1 - newWindowSize); |
| 397 |
| 398 right = reference + (right - reference) * factor; |
| 399 right = Number.constrain(right, newWindowSize, 1); |
| 400 this._setWindow(left, right); |
| 401 } |
| 171 }; | 402 }; |
| 172 | 403 |
| 173 /** @enum {symbol} */ | 404 /** @enum {symbol} */ |
| 174 WebInspector.OverviewGrid.Events = { | 405 WebInspector.OverviewGrid.Events = { |
| 175 WindowChanged: Symbol("WindowChanged"), | 406 WindowChanged: Symbol('WindowChanged'), |
| 176 Click: Symbol("Click") | 407 Click: Symbol('Click') |
| 177 }; | 408 }; |
| 178 | 409 |
| 179 WebInspector.OverviewGrid.Window.prototype = { | |
| 180 reset: function() | |
| 181 { | |
| 182 this.windowLeft = 0.0; | |
| 183 this.windowRight = 1.0; | |
| 184 this.setEnabled(true); | |
| 185 this._updateCurtains(); | |
| 186 }, | |
| 187 | |
| 188 /** | |
| 189 * @param {boolean} enabled | |
| 190 */ | |
| 191 setEnabled: function(enabled) | |
| 192 { | |
| 193 this._enabled = enabled; | |
| 194 }, | |
| 195 | |
| 196 /** | |
| 197 * @param {!Event} event | |
| 198 */ | |
| 199 _resizerElementStartDragging: function(event) | |
| 200 { | |
| 201 if (!this._enabled) | |
| 202 return false; | |
| 203 this._resizerParentOffsetLeft = event.pageX - event.offsetX - event.targ
et.offsetLeft; | |
| 204 event.preventDefault(); | |
| 205 return true; | |
| 206 }, | |
| 207 | |
| 208 /** | |
| 209 * @param {!Event} event | |
| 210 */ | |
| 211 _leftResizeElementDragging: function(event) | |
| 212 { | |
| 213 this._resizeWindowLeft(event.pageX - this._resizerParentOffsetLeft); | |
| 214 event.preventDefault(); | |
| 215 }, | |
| 216 | |
| 217 /** | |
| 218 * @param {!Event} event | |
| 219 */ | |
| 220 _rightResizeElementDragging: function(event) | |
| 221 { | |
| 222 this._resizeWindowRight(event.pageX - this._resizerParentOffsetLeft); | |
| 223 event.preventDefault(); | |
| 224 }, | |
| 225 | |
| 226 /** | |
| 227 * @param {!Event} event | |
| 228 * @return {boolean} | |
| 229 */ | |
| 230 _startWindowSelectorDragging: function(event) | |
| 231 { | |
| 232 if (!this._enabled) | |
| 233 return false; | |
| 234 this._offsetLeft = this._parentElement.totalOffsetLeft(); | |
| 235 var position = event.x - this._offsetLeft; | |
| 236 this._overviewWindowSelector = new WebInspector.OverviewGrid.WindowSelec
tor(this._parentElement, position); | |
| 237 return true; | |
| 238 }, | |
| 239 | |
| 240 /** | |
| 241 * @param {!Event} event | |
| 242 */ | |
| 243 _windowSelectorDragging: function(event) | |
| 244 { | |
| 245 this._overviewWindowSelector._updatePosition(event.x - this._offsetLeft)
; | |
| 246 event.preventDefault(); | |
| 247 }, | |
| 248 | |
| 249 /** | |
| 250 * @param {!Event} event | |
| 251 */ | |
| 252 _endWindowSelectorDragging: function(event) | |
| 253 { | |
| 254 var window = this._overviewWindowSelector._close(event.x - this._offsetL
eft); | |
| 255 delete this._overviewWindowSelector; | |
| 256 var clickThreshold = 3; | |
| 257 if (window.end - window.start < clickThreshold) { | |
| 258 if (this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.C
lick, event)) | |
| 259 return; | |
| 260 var middle = window.end; | |
| 261 window.start = Math.max(0, middle - WebInspector.OverviewGrid.MinSel
ectableSize / 2); | |
| 262 window.end = Math.min(this._parentElement.clientWidth, middle + WebI
nspector.OverviewGrid.MinSelectableSize / 2); | |
| 263 } else if (window.end - window.start < WebInspector.OverviewGrid.MinSele
ctableSize) { | |
| 264 if (this._parentElement.clientWidth - window.end > WebInspector.Over
viewGrid.MinSelectableSize) | |
| 265 window.end = window.start + WebInspector.OverviewGrid.MinSelecta
bleSize; | |
| 266 else | |
| 267 window.start = window.end - WebInspector.OverviewGrid.MinSelecta
bleSize; | |
| 268 } | |
| 269 this._setWindowPosition(window.start, window.end); | |
| 270 }, | |
| 271 | |
| 272 /** | |
| 273 * @param {!Event} event | |
| 274 * @return {boolean} | |
| 275 */ | |
| 276 _startWindowDragging: function(event) | |
| 277 { | |
| 278 this._dragStartPoint = event.pageX; | |
| 279 this._dragStartLeft = this.windowLeft; | |
| 280 this._dragStartRight = this.windowRight; | |
| 281 event.stopPropagation(); | |
| 282 return true; | |
| 283 }, | |
| 284 | |
| 285 /** | |
| 286 * @param {!Event} event | |
| 287 */ | |
| 288 _windowDragging: function(event) | |
| 289 { | |
| 290 event.preventDefault(); | |
| 291 var delta = (event.pageX - this._dragStartPoint) / this._parentElement.c
lientWidth; | |
| 292 if (this._dragStartLeft + delta < 0) | |
| 293 delta = -this._dragStartLeft; | |
| 294 | |
| 295 if (this._dragStartRight + delta > 1) | |
| 296 delta = 1 - this._dragStartRight; | |
| 297 | |
| 298 this._setWindow(this._dragStartLeft + delta, this._dragStartRight + delt
a); | |
| 299 }, | |
| 300 | |
| 301 /** | |
| 302 * @param {number} start | |
| 303 */ | |
| 304 _resizeWindowLeft: function(start) | |
| 305 { | |
| 306 // Glue to edge. | |
| 307 if (start < 10) | |
| 308 start = 0; | |
| 309 else if (start > this._rightResizeElement.offsetLeft - 4) | |
| 310 start = this._rightResizeElement.offsetLeft - 4; | |
| 311 this._setWindowPosition(start, null); | |
| 312 }, | |
| 313 | |
| 314 /** | |
| 315 * @param {number} end | |
| 316 */ | |
| 317 _resizeWindowRight: function(end) | |
| 318 { | |
| 319 // Glue to edge. | |
| 320 if (end > this._parentElement.clientWidth - 10) | |
| 321 end = this._parentElement.clientWidth; | |
| 322 else if (end < this._leftResizeElement.offsetLeft + WebInspector.Overvie
wGrid.MinSelectableSize) | |
| 323 end = this._leftResizeElement.offsetLeft + WebInspector.OverviewGrid
.MinSelectableSize; | |
| 324 this._setWindowPosition(null, end); | |
| 325 }, | |
| 326 | |
| 327 _resizeWindowMaximum: function() | |
| 328 { | |
| 329 this._setWindowPosition(0, this._parentElement.clientWidth); | |
| 330 }, | |
| 331 | |
| 332 /** | |
| 333 * @param {number} windowLeft | |
| 334 * @param {number} windowRight | |
| 335 */ | |
| 336 _setWindow: function(windowLeft, windowRight) | |
| 337 { | |
| 338 this.windowLeft = windowLeft; | |
| 339 this.windowRight = windowRight; | |
| 340 this._updateCurtains(); | |
| 341 this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.WindowCha
nged); | |
| 342 }, | |
| 343 | |
| 344 _updateCurtains: function() | |
| 345 { | |
| 346 var left = this.windowLeft; | |
| 347 var right = this.windowRight; | |
| 348 var width = right - left; | |
| 349 | |
| 350 // We allow actual time window to be arbitrarily small but don't want th
e UI window to be too small. | |
| 351 var widthInPixels = width * this._parentElement.clientWidth; | |
| 352 var minWidthInPixels = WebInspector.OverviewGrid.MinSelectableSize / 2; | |
| 353 if (widthInPixels < minWidthInPixels) { | |
| 354 var factor = minWidthInPixels / widthInPixels; | |
| 355 left = ((this.windowRight + this.windowLeft) - width * factor) / 2; | |
| 356 right = ((this.windowRight + this.windowLeft) + width * factor) / 2; | |
| 357 } | |
| 358 this._leftResizeElement.style.left = (100 * left).toFixed(2) + "%"; | |
| 359 this._rightResizeElement.style.left = (100 * right).toFixed(2) + "%"; | |
| 360 | |
| 361 this._leftCurtainElement.style.width = (100 * left).toFixed(2) + "%"; | |
| 362 this._rightCurtainElement.style.width = (100 * (1 - right)).toFixed(2) +
"%"; | |
| 363 }, | |
| 364 | |
| 365 /** | |
| 366 * @param {?number} start | |
| 367 * @param {?number} end | |
| 368 */ | |
| 369 _setWindowPosition: function(start, end) | |
| 370 { | |
| 371 var clientWidth = this._parentElement.clientWidth; | |
| 372 var windowLeft = typeof start === "number" ? start / clientWidth : this.
windowLeft; | |
| 373 var windowRight = typeof end === "number" ? end / clientWidth : this.win
dowRight; | |
| 374 this._setWindow(windowLeft, windowRight); | |
| 375 }, | |
| 376 | |
| 377 /** | |
| 378 * @param {!Event} event | |
| 379 */ | |
| 380 _onMouseWheel: function(event) | |
| 381 { | |
| 382 if (!this._enabled) | |
| 383 return; | |
| 384 if (typeof event.wheelDeltaY === "number" && event.wheelDeltaY) { | |
| 385 const zoomFactor = 1.1; | |
| 386 const mouseWheelZoomSpeed = 1 / 120; | |
| 387 | |
| 388 var reference = event.offsetX / event.target.clientWidth; | |
| 389 this._zoom(Math.pow(zoomFactor, -event.wheelDeltaY * mouseWheelZoomS
peed), reference); | |
| 390 } | |
| 391 if (typeof event.wheelDeltaX === "number" && event.wheelDeltaX) { | |
| 392 var offset = Math.round(event.wheelDeltaX * WebInspector.OverviewGri
d.WindowScrollSpeedFactor); | |
| 393 var windowLeft = this._leftResizeElement.offsetLeft + WebInspector.O
verviewGrid.ResizerOffset; | |
| 394 var windowRight = this._rightResizeElement.offsetLeft + WebInspector
.OverviewGrid.ResizerOffset; | |
| 395 | |
| 396 if (windowLeft - offset < 0) | |
| 397 offset = windowLeft; | |
| 398 | |
| 399 if (windowRight - offset > this._parentElement.clientWidth) | |
| 400 offset = windowRight - this._parentElement.clientWidth; | |
| 401 | |
| 402 this._setWindowPosition(windowLeft - offset, windowRight - offset); | |
| 403 | |
| 404 event.preventDefault(); | |
| 405 } | |
| 406 }, | |
| 407 | |
| 408 /** | |
| 409 * @param {number} factor | |
| 410 * @param {number} reference | |
| 411 */ | |
| 412 _zoom: function(factor, reference) | |
| 413 { | |
| 414 var left = this.windowLeft; | |
| 415 var right = this.windowRight; | |
| 416 var windowSize = right - left; | |
| 417 var newWindowSize = factor * windowSize; | |
| 418 if (newWindowSize > 1) { | |
| 419 newWindowSize = 1; | |
| 420 factor = newWindowSize / windowSize; | |
| 421 } | |
| 422 left = reference + (left - reference) * factor; | |
| 423 left = Number.constrain(left, 0, 1 - newWindowSize); | |
| 424 | |
| 425 right = reference + (right - reference) * factor; | |
| 426 right = Number.constrain(right, newWindowSize, 1); | |
| 427 this._setWindow(left, right); | |
| 428 }, | |
| 429 | |
| 430 __proto__: WebInspector.Object.prototype | |
| 431 }; | |
| 432 | |
| 433 /** | 410 /** |
| 434 * @constructor | 411 * @unrestricted |
| 435 */ | 412 */ |
| 436 WebInspector.OverviewGrid.WindowSelector = function(parent, position) | 413 WebInspector.OverviewGrid.WindowSelector = class { |
| 437 { | 414 constructor(parent, position) { |
| 438 this._startPosition = position; | 415 this._startPosition = position; |
| 439 this._width = parent.offsetWidth; | 416 this._width = parent.offsetWidth; |
| 440 this._windowSelector = createElement("div"); | 417 this._windowSelector = createElement('div'); |
| 441 this._windowSelector.className = "overview-grid-window-selector"; | 418 this._windowSelector.className = 'overview-grid-window-selector'; |
| 442 this._windowSelector.style.left = this._startPosition + "px"; | 419 this._windowSelector.style.left = this._startPosition + 'px'; |
| 443 this._windowSelector.style.right = this._width - this._startPosition + "px"; | 420 this._windowSelector.style.right = this._width - this._startPosition + 'px'; |
| 444 parent.appendChild(this._windowSelector); | 421 parent.appendChild(this._windowSelector); |
| 422 } |
| 423 |
| 424 _close(position) { |
| 425 position = Math.max(0, Math.min(position, this._width)); |
| 426 this._windowSelector.remove(); |
| 427 return this._startPosition < position ? {start: this._startPosition, end: po
sition} : |
| 428 {start: position, end: this._startPo
sition}; |
| 429 } |
| 430 |
| 431 _updatePosition(position) { |
| 432 position = Math.max(0, Math.min(position, this._width)); |
| 433 if (position < this._startPosition) { |
| 434 this._windowSelector.style.left = position + 'px'; |
| 435 this._windowSelector.style.right = this._width - this._startPosition + 'px
'; |
| 436 } else { |
| 437 this._windowSelector.style.left = this._startPosition + 'px'; |
| 438 this._windowSelector.style.right = this._width - position + 'px'; |
| 439 } |
| 440 } |
| 445 }; | 441 }; |
| 446 | |
| 447 WebInspector.OverviewGrid.WindowSelector.prototype = { | |
| 448 _close: function(position) | |
| 449 { | |
| 450 position = Math.max(0, Math.min(position, this._width)); | |
| 451 this._windowSelector.remove(); | |
| 452 return this._startPosition < position ? {start: this._startPosition, end
: position} : {start: position, end: this._startPosition}; | |
| 453 }, | |
| 454 | |
| 455 _updatePosition: function(position) | |
| 456 { | |
| 457 position = Math.max(0, Math.min(position, this._width)); | |
| 458 if (position < this._startPosition) { | |
| 459 this._windowSelector.style.left = position + "px"; | |
| 460 this._windowSelector.style.right = this._width - this._startPosition
+ "px"; | |
| 461 } else { | |
| 462 this._windowSelector.style.left = this._startPosition + "px"; | |
| 463 this._windowSelector.style.right = this._width - position + "px"; | |
| 464 } | |
| 465 } | |
| 466 }; | |
| OLD | NEW |