| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 /** | 30 /** |
| 31 * @implements {WebInspector.DOMNodeHighlighter} | 31 * @implements {SDK.DOMNodeHighlighter} |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.ScreencastView = class extends WebInspector.VBox { | 34 Screencast.ScreencastView = class extends UI.VBox { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.Target} target | 36 * @param {!SDK.Target} target |
| 37 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel | 37 * @param {!SDK.ResourceTreeModel} resourceTreeModel |
| 38 */ | 38 */ |
| 39 constructor(target, resourceTreeModel) { | 39 constructor(target, resourceTreeModel) { |
| 40 super(); | 40 super(); |
| 41 this._target = target; | 41 this._target = target; |
| 42 this._domModel = WebInspector.DOMModel.fromTarget(target); | 42 this._domModel = SDK.DOMModel.fromTarget(target); |
| 43 this._resourceTreeModel = resourceTreeModel; | 43 this._resourceTreeModel = resourceTreeModel; |
| 44 | 44 |
| 45 this.setMinimumSize(150, 150); | 45 this.setMinimumSize(150, 150); |
| 46 this.registerRequiredCSS('screencast/screencastView.css'); | 46 this.registerRequiredCSS('screencast/screencastView.css'); |
| 47 } | 47 } |
| 48 | 48 |
| 49 initialize() { | 49 initialize() { |
| 50 this.element.classList.add('screencast'); | 50 this.element.classList.add('screencast'); |
| 51 | 51 |
| 52 this._createNavigationBar(); | 52 this._createNavigationBar(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 80 this._titleElement.createChild('span', 'screencast-px').textContent = 'px'; | 80 this._titleElement.createChild('span', 'screencast-px').textContent = 'px'; |
| 81 this._titleElement.style.top = '0'; | 81 this._titleElement.style.top = '0'; |
| 82 this._titleElement.style.left = '0'; | 82 this._titleElement.style.left = '0'; |
| 83 | 83 |
| 84 this._imageElement = new Image(); | 84 this._imageElement = new Image(); |
| 85 this._isCasting = false; | 85 this._isCasting = false; |
| 86 this._context = this._canvasElement.getContext('2d'); | 86 this._context = this._canvasElement.getContext('2d'); |
| 87 this._checkerboardPattern = this._createCheckerboardPattern(this._context); | 87 this._checkerboardPattern = this._createCheckerboardPattern(this._context); |
| 88 | 88 |
| 89 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); | 89 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); |
| 90 this._shortcuts[WebInspector.KeyboardShortcut.makeKey('l', WebInspector.Keyb
oardShortcut.Modifiers.Ctrl)] = | 90 this._shortcuts[UI.KeyboardShortcut.makeKey('l', UI.KeyboardShortcut.Modifie
rs.Ctrl)] = |
| 91 this._focusNavigationBar.bind(this); | 91 this._focusNavigationBar.bind(this); |
| 92 | 92 |
| 93 this._resourceTreeModel.addEventListener( | 93 this._resourceTreeModel.addEventListener( |
| 94 WebInspector.ResourceTreeModel.Events.ScreencastFrame, this._screencastF
rame, this); | 94 SDK.ResourceTreeModel.Events.ScreencastFrame, this._screencastFrame, thi
s); |
| 95 this._resourceTreeModel.addEventListener( | 95 this._resourceTreeModel.addEventListener( |
| 96 WebInspector.ResourceTreeModel.Events.ScreencastVisibilityChanged, this.
_screencastVisibilityChanged, this); | 96 SDK.ResourceTreeModel.Events.ScreencastVisibilityChanged, this._screenca
stVisibilityChanged, this); |
| 97 | 97 |
| 98 WebInspector.targetManager.addEventListener( | 98 SDK.targetManager.addEventListener( |
| 99 WebInspector.TargetManager.Events.SuspendStateChanged, this._onSuspendSt
ateChange, this); | 99 SDK.TargetManager.Events.SuspendStateChanged, this._onSuspendStateChange
, this); |
| 100 this._updateGlasspane(); | 100 this._updateGlasspane(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @override | 104 * @override |
| 105 */ | 105 */ |
| 106 wasShown() { | 106 wasShown() { |
| 107 this._startCasting(); | 107 this._startCasting(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @override | 111 * @override |
| 112 */ | 112 */ |
| 113 willHide() { | 113 willHide() { |
| 114 this._stopCasting(); | 114 this._stopCasting(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 _startCasting() { | 117 _startCasting() { |
| 118 if (WebInspector.targetManager.allTargetsSuspended()) | 118 if (SDK.targetManager.allTargetsSuspended()) |
| 119 return; | 119 return; |
| 120 if (this._isCasting) | 120 if (this._isCasting) |
| 121 return; | 121 return; |
| 122 this._isCasting = true; | 122 this._isCasting = true; |
| 123 | 123 |
| 124 const maxImageDimension = 2048; | 124 const maxImageDimension = 2048; |
| 125 var dimensions = this._viewportDimensions(); | 125 var dimensions = this._viewportDimensions(); |
| 126 if (dimensions.width < 0 || dimensions.height < 0) { | 126 if (dimensions.width < 0 || dimensions.height < 0) { |
| 127 this._isCasting = false; | 127 this._isCasting = false; |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 dimensions.width *= window.devicePixelRatio; | 130 dimensions.width *= window.devicePixelRatio; |
| 131 dimensions.height *= window.devicePixelRatio; | 131 dimensions.height *= window.devicePixelRatio; |
| 132 this._target.pageAgent().startScreencast( | 132 this._target.pageAgent().startScreencast( |
| 133 'jpeg', 80, Math.min(maxImageDimension, dimensions.width), Math.min(maxI
mageDimension, dimensions.height)); | 133 'jpeg', 80, Math.min(maxImageDimension, dimensions.width), Math.min(maxI
mageDimension, dimensions.height)); |
| 134 this._target.emulationAgent().setTouchEmulationEnabled(true); | 134 this._target.emulationAgent().setTouchEmulationEnabled(true); |
| 135 this._domModel.setHighlighter(this); | 135 this._domModel.setHighlighter(this); |
| 136 } | 136 } |
| 137 | 137 |
| 138 _stopCasting() { | 138 _stopCasting() { |
| 139 if (!this._isCasting) | 139 if (!this._isCasting) |
| 140 return; | 140 return; |
| 141 this._isCasting = false; | 141 this._isCasting = false; |
| 142 this._target.pageAgent().stopScreencast(); | 142 this._target.pageAgent().stopScreencast(); |
| 143 this._target.emulationAgent().setTouchEmulationEnabled(false); | 143 this._target.emulationAgent().setTouchEmulationEnabled(false); |
| 144 this._domModel.setHighlighter(null); | 144 this._domModel.setHighlighter(null); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {!WebInspector.Event} event | 148 * @param {!Common.Event} event |
| 149 */ | 149 */ |
| 150 _screencastFrame(event) { | 150 _screencastFrame(event) { |
| 151 var metadata = /** type {Protocol.Page.ScreencastFrameMetadata} */ (event.da
ta.metadata); | 151 var metadata = /** type {Protocol.Page.ScreencastFrameMetadata} */ (event.da
ta.metadata); |
| 152 var base64Data = /** type {string} */ (event.data.data); | 152 var base64Data = /** type {string} */ (event.data.data); |
| 153 this._imageElement.src = 'data:image/jpg;base64,' + base64Data; | 153 this._imageElement.src = 'data:image/jpg;base64,' + base64Data; |
| 154 this._pageScaleFactor = metadata.pageScaleFactor; | 154 this._pageScaleFactor = metadata.pageScaleFactor; |
| 155 this._screenOffsetTop = metadata.offsetTop; | 155 this._screenOffsetTop = metadata.offsetTop; |
| 156 this._scrollOffsetX = metadata.scrollOffsetX; | 156 this._scrollOffsetX = metadata.scrollOffsetX; |
| 157 this._scrollOffsetY = metadata.scrollOffsetY; | 157 this._scrollOffsetY = metadata.scrollOffsetY; |
| 158 | 158 |
| 159 var deviceSizeRatio = metadata.deviceHeight / metadata.deviceWidth; | 159 var deviceSizeRatio = metadata.deviceHeight / metadata.deviceWidth; |
| 160 var dimensionsCSS = this._viewportDimensions(); | 160 var dimensionsCSS = this._viewportDimensions(); |
| 161 | 161 |
| 162 this._imageZoom = Math.min( | 162 this._imageZoom = Math.min( |
| 163 dimensionsCSS.width / this._imageElement.naturalWidth, | 163 dimensionsCSS.width / this._imageElement.naturalWidth, |
| 164 dimensionsCSS.height / (this._imageElement.naturalWidth * deviceSizeRati
o)); | 164 dimensionsCSS.height / (this._imageElement.naturalWidth * deviceSizeRati
o)); |
| 165 this._viewportElement.classList.remove('hidden'); | 165 this._viewportElement.classList.remove('hidden'); |
| 166 var bordersSize = WebInspector.ScreencastView._bordersSize; | 166 var bordersSize = Screencast.ScreencastView._bordersSize; |
| 167 if (this._imageZoom < 1.01 / window.devicePixelRatio) | 167 if (this._imageZoom < 1.01 / window.devicePixelRatio) |
| 168 this._imageZoom = 1 / window.devicePixelRatio; | 168 this._imageZoom = 1 / window.devicePixelRatio; |
| 169 this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / metad
ata.deviceWidth; | 169 this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / metad
ata.deviceWidth; |
| 170 this._viewportElement.style.width = metadata.deviceWidth * this._screenZoom
+ bordersSize + 'px'; | 170 this._viewportElement.style.width = metadata.deviceWidth * this._screenZoom
+ bordersSize + 'px'; |
| 171 this._viewportElement.style.height = metadata.deviceHeight * this._screenZoo
m + bordersSize + 'px'; | 171 this._viewportElement.style.height = metadata.deviceHeight * this._screenZoo
m + bordersSize + 'px'; |
| 172 | 172 |
| 173 this.highlightDOMNode(this._highlightNode, this._highlightConfig); | 173 this.highlightDOMNode(this._highlightNode, this._highlightConfig); |
| 174 } | 174 } |
| 175 | 175 |
| 176 _isGlassPaneActive() { | 176 _isGlassPaneActive() { |
| 177 return !this._glassPaneElement.classList.contains('hidden'); | 177 return !this._glassPaneElement.classList.contains('hidden'); |
| 178 } | 178 } |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * @param {!WebInspector.Event} event | 181 * @param {!Common.Event} event |
| 182 */ | 182 */ |
| 183 _screencastVisibilityChanged(event) { | 183 _screencastVisibilityChanged(event) { |
| 184 this._targetInactive = !event.data.visible; | 184 this._targetInactive = !event.data.visible; |
| 185 this._updateGlasspane(); | 185 this._updateGlasspane(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * @param {!WebInspector.Event} event | 189 * @param {!Common.Event} event |
| 190 */ | 190 */ |
| 191 _onSuspendStateChange(event) { | 191 _onSuspendStateChange(event) { |
| 192 if (WebInspector.targetManager.allTargetsSuspended()) | 192 if (SDK.targetManager.allTargetsSuspended()) |
| 193 this._stopCasting(); | 193 this._stopCasting(); |
| 194 else | 194 else |
| 195 this._startCasting(); | 195 this._startCasting(); |
| 196 this._updateGlasspane(); | 196 this._updateGlasspane(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 _updateGlasspane() { | 199 _updateGlasspane() { |
| 200 if (this._targetInactive) { | 200 if (this._targetInactive) { |
| 201 this._glassPaneElement.textContent = WebInspector.UIString('The tab is ina
ctive'); | 201 this._glassPaneElement.textContent = Common.UIString('The tab is inactive'
); |
| 202 this._glassPaneElement.classList.remove('hidden'); | 202 this._glassPaneElement.classList.remove('hidden'); |
| 203 } else if (WebInspector.targetManager.allTargetsSuspended()) { | 203 } else if (SDK.targetManager.allTargetsSuspended()) { |
| 204 this._glassPaneElement.textContent = WebInspector.UIString('Profiling in p
rogress'); | 204 this._glassPaneElement.textContent = Common.UIString('Profiling in progres
s'); |
| 205 this._glassPaneElement.classList.remove('hidden'); | 205 this._glassPaneElement.classList.remove('hidden'); |
| 206 } else { | 206 } else { |
| 207 this._glassPaneElement.classList.add('hidden'); | 207 this._glassPaneElement.classList.add('hidden'); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * @param {!Event} event | 212 * @param {!Event} event |
| 213 */ | 213 */ |
| 214 _handleMouseEvent(event) { | 214 _handleMouseEvent(event) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 227 this._canvasElement.focus(); | 227 this._canvasElement.focus(); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 | 230 |
| 231 var position = this._convertIntoScreenSpace(event); | 231 var position = this._convertIntoScreenSpace(event); |
| 232 this._domModel.nodeForLocation( | 232 this._domModel.nodeForLocation( |
| 233 position.x / this._pageScaleFactor + this._scrollOffsetX, | 233 position.x / this._pageScaleFactor + this._scrollOffsetX, |
| 234 position.y / this._pageScaleFactor + this._scrollOffsetY, callback.bind(
this)); | 234 position.y / this._pageScaleFactor + this._scrollOffsetY, callback.bind(
this)); |
| 235 | 235 |
| 236 /** | 236 /** |
| 237 * @param {?WebInspector.DOMNode} node | 237 * @param {?SDK.DOMNode} node |
| 238 * @this {WebInspector.ScreencastView} | 238 * @this {Screencast.ScreencastView} |
| 239 */ | 239 */ |
| 240 function callback(node) { | 240 function callback(node) { |
| 241 if (!node) | 241 if (!node) |
| 242 return; | 242 return; |
| 243 if (event.type === 'mousemove') { | 243 if (event.type === 'mousemove') { |
| 244 this.highlightDOMNode(node, this._inspectModeConfig); | 244 this.highlightDOMNode(node, this._inspectModeConfig); |
| 245 this._domModel.nodeHighlightRequested(node.id); | 245 this._domModel.nodeHighlightRequested(node.id); |
| 246 } else if (event.type === 'click') { | 246 } else if (event.type === 'click') { |
| 247 WebInspector.Revealer.reveal(node); | 247 Common.Revealer.reveal(node); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * @param {!Event} event | 253 * @param {!Event} event |
| 254 */ | 254 */ |
| 255 _handleKeyEvent(event) { | 255 _handleKeyEvent(event) { |
| 256 if (this._isGlassPaneActive()) { | 256 if (this._isGlassPaneActive()) { |
| 257 event.consume(); | 257 event.consume(); |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 | 260 |
| 261 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(/** @type {
!KeyboardEvent} */ (event)); | 261 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(/** @type {!KeyboardE
vent} */ (event)); |
| 262 var handler = this._shortcuts[shortcutKey]; | 262 var handler = this._shortcuts[shortcutKey]; |
| 263 if (handler && handler(event)) { | 263 if (handler && handler(event)) { |
| 264 event.consume(); | 264 event.consume(); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 var type; | 268 var type; |
| 269 switch (event.type) { | 269 switch (event.type) { |
| 270 case 'keydown': | 270 case 'keydown': |
| 271 type = 'keyDown'; | 271 type = 'keyDown'; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 clearTimeout(this._deferredCasting); | 409 clearTimeout(this._deferredCasting); |
| 410 delete this._deferredCasting; | 410 delete this._deferredCasting; |
| 411 } | 411 } |
| 412 | 412 |
| 413 this._stopCasting(); | 413 this._stopCasting(); |
| 414 this._deferredCasting = setTimeout(this._startCasting.bind(this), 100); | 414 this._deferredCasting = setTimeout(this._startCasting.bind(this), 100); |
| 415 } | 415 } |
| 416 | 416 |
| 417 /** | 417 /** |
| 418 * @override | 418 * @override |
| 419 * @param {?WebInspector.DOMNode} node | 419 * @param {?SDK.DOMNode} node |
| 420 * @param {?Protocol.DOM.HighlightConfig} config | 420 * @param {?Protocol.DOM.HighlightConfig} config |
| 421 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId | 421 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId |
| 422 * @param {!Protocol.Runtime.RemoteObjectId=} objectId | 422 * @param {!Protocol.Runtime.RemoteObjectId=} objectId |
| 423 */ | 423 */ |
| 424 highlightDOMNode(node, config, backendNodeId, objectId) { | 424 highlightDOMNode(node, config, backendNodeId, objectId) { |
| 425 this._highlightNode = node; | 425 this._highlightNode = node; |
| 426 this._highlightConfig = config; | 426 this._highlightConfig = config; |
| 427 if (!node) { | 427 if (!node) { |
| 428 this._model = null; | 428 this._model = null; |
| 429 this._config = null; | 429 this._config = null; |
| 430 this._node = null; | 430 this._node = null; |
| 431 this._titleElement.classList.add('hidden'); | 431 this._titleElement.classList.add('hidden'); |
| 432 this._repaint(); | 432 this._repaint(); |
| 433 return; | 433 return; |
| 434 } | 434 } |
| 435 | 435 |
| 436 this._node = node; | 436 this._node = node; |
| 437 node.boxModel(callback.bind(this)); | 437 node.boxModel(callback.bind(this)); |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * @param {?Protocol.DOM.BoxModel} model | 440 * @param {?Protocol.DOM.BoxModel} model |
| 441 * @this {WebInspector.ScreencastView} | 441 * @this {Screencast.ScreencastView} |
| 442 */ | 442 */ |
| 443 function callback(model) { | 443 function callback(model) { |
| 444 if (!model || !this._pageScaleFactor) { | 444 if (!model || !this._pageScaleFactor) { |
| 445 this._repaint(); | 445 this._repaint(); |
| 446 return; | 446 return; |
| 447 } | 447 } |
| 448 this._model = this._scaleModel(model); | 448 this._model = this._scaleModel(model); |
| 449 this._config = config; | 449 this._config = config; |
| 450 this._repaint(); | 450 this._repaint(); |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 /** | 454 /** |
| 455 * @param {!Protocol.DOM.BoxModel} model | 455 * @param {!Protocol.DOM.BoxModel} model |
| 456 * @return {!Protocol.DOM.BoxModel} | 456 * @return {!Protocol.DOM.BoxModel} |
| 457 */ | 457 */ |
| 458 _scaleModel(model) { | 458 _scaleModel(model) { |
| 459 /** | 459 /** |
| 460 * @param {!Protocol.DOM.Quad} quad | 460 * @param {!Protocol.DOM.Quad} quad |
| 461 * @this {WebInspector.ScreencastView} | 461 * @this {Screencast.ScreencastView} |
| 462 */ | 462 */ |
| 463 function scaleQuad(quad) { | 463 function scaleQuad(quad) { |
| 464 for (var i = 0; i < quad.length; i += 2) { | 464 for (var i = 0; i < quad.length; i += 2) { |
| 465 quad[i] = quad[i] * this._screenZoom; | 465 quad[i] = quad[i] * this._screenZoom; |
| 466 quad[i + 1] = (quad[i + 1] + this._screenOffsetTop) * this._screenZoom; | 466 quad[i + 1] = (quad[i + 1] + this._screenOffsetTop) * this._screenZoom; |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 scaleQuad.call(this, model.content); | 470 scaleQuad.call(this, model.content); |
| 471 scaleQuad.call(this, model.padding); | 471 scaleQuad.call(this, model.padding); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 this._context.restore(); | 525 this._context.restore(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 /** | 528 /** |
| 529 * @param {!Protocol.DOM.RGBA} color | 529 * @param {!Protocol.DOM.RGBA} color |
| 530 * @return {string} | 530 * @return {string} |
| 531 */ | 531 */ |
| 532 _cssColor(color) { | 532 _cssColor(color) { |
| 533 if (!color) | 533 if (!color) |
| 534 return 'transparent'; | 534 return 'transparent'; |
| 535 return WebInspector.Color.fromRGBA([color.r, color.g, color.b, color.a]).asS
tring(WebInspector.Color.Format.RGBA) || | 535 return Common.Color.fromRGBA([color.r, color.g, color.b, color.a]).asString(
Common.Color.Format.RGBA) || |
| 536 ''; | 536 ''; |
| 537 } | 537 } |
| 538 | 538 |
| 539 /** | 539 /** |
| 540 * @param {!Protocol.DOM.Quad} quad | 540 * @param {!Protocol.DOM.Quad} quad |
| 541 * @return {!CanvasRenderingContext2D} | 541 * @return {!CanvasRenderingContext2D} |
| 542 */ | 542 */ |
| 543 _quadToPath(quad) { | 543 _quadToPath(quad) { |
| 544 this._context.beginPath(); | 544 this._context.beginPath(); |
| 545 this._context.moveTo(quad[0], quad[1]); | 545 this._context.moveTo(quad[0], quad[1]); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 655 |
| 656 this._titleElement.style.top = (boxY + 3) + 'px'; | 656 this._titleElement.style.top = (boxY + 3) + 'px'; |
| 657 this._titleElement.style.left = (boxX + 3) + 'px'; | 657 this._titleElement.style.left = (boxX + 3) + 'px'; |
| 658 } | 658 } |
| 659 | 659 |
| 660 /** | 660 /** |
| 661 * @return {!{width: number, height: number}} | 661 * @return {!{width: number, height: number}} |
| 662 */ | 662 */ |
| 663 _viewportDimensions() { | 663 _viewportDimensions() { |
| 664 const gutterSize = 30; | 664 const gutterSize = 30; |
| 665 const bordersSize = WebInspector.ScreencastView._bordersSize; | 665 const bordersSize = Screencast.ScreencastView._bordersSize; |
| 666 var width = this.element.offsetWidth - bordersSize - gutterSize; | 666 var width = this.element.offsetWidth - bordersSize - gutterSize; |
| 667 var height = this.element.offsetHeight - bordersSize - gutterSize - WebInspe
ctor.ScreencastView._navBarHeight; | 667 var height = this.element.offsetHeight - bordersSize - gutterSize - Screenca
st.ScreencastView._navBarHeight; |
| 668 return {width: width, height: height}; | 668 return {width: width, height: height}; |
| 669 } | 669 } |
| 670 | 670 |
| 671 /** | 671 /** |
| 672 * @override | 672 * @override |
| 673 * @param {!Protocol.DOM.InspectMode} mode | 673 * @param {!Protocol.DOM.InspectMode} mode |
| 674 * @param {!Protocol.DOM.HighlightConfig} config | 674 * @param {!Protocol.DOM.HighlightConfig} config |
| 675 * @param {function(?Protocol.Error)=} callback | 675 * @param {function(?Protocol.Error)=} callback |
| 676 */ | 676 */ |
| 677 setInspectMode(mode, config, callback) { | 677 setInspectMode(mode, config, callback) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 this._navigationForward.addEventListener('click', this._navigateToHistoryEnt
ry.bind(this, 1), false); | 718 this._navigationForward.addEventListener('click', this._navigateToHistoryEnt
ry.bind(this, 1), false); |
| 719 | 719 |
| 720 this._navigationReload = this._navigationBar.createChild('button', 'reload')
; | 720 this._navigationReload = this._navigationBar.createChild('button', 'reload')
; |
| 721 this._navigationReload.addEventListener('click', this._navigateReload.bind(t
his), false); | 721 this._navigationReload.addEventListener('click', this._navigateReload.bind(t
his), false); |
| 722 | 722 |
| 723 this._navigationUrl = this._navigationBar.createChild('input'); | 723 this._navigationUrl = this._navigationBar.createChild('input'); |
| 724 this._navigationUrl.type = 'text'; | 724 this._navigationUrl.type = 'text'; |
| 725 this._navigationUrl.addEventListener('keyup', this._navigationUrlKeyUp.bind(
this), true); | 725 this._navigationUrl.addEventListener('keyup', this._navigationUrlKeyUp.bind(
this), true); |
| 726 | 726 |
| 727 this._navigationProgressBar = | 727 this._navigationProgressBar = |
| 728 new WebInspector.ScreencastView.ProgressTracker(this._navigationBar.crea
teChild('div', 'progress')); | 728 new Screencast.ScreencastView.ProgressTracker(this._navigationBar.create
Child('div', 'progress')); |
| 729 | 729 |
| 730 this._requestNavigationHistory(); | 730 this._requestNavigationHistory(); |
| 731 WebInspector.targetManager.addEventListener( | 731 SDK.targetManager.addEventListener( |
| 732 WebInspector.TargetManager.Events.InspectedURLChanged, this._requestNavi
gationHistory, this); | 732 SDK.TargetManager.Events.InspectedURLChanged, this._requestNavigationHis
tory, this); |
| 733 } | 733 } |
| 734 | 734 |
| 735 _navigateToHistoryEntry(offset) { | 735 _navigateToHistoryEntry(offset) { |
| 736 var newIndex = this._historyIndex + offset; | 736 var newIndex = this._historyIndex + offset; |
| 737 if (newIndex < 0 || newIndex >= this._historyEntries.length) | 737 if (newIndex < 0 || newIndex >= this._historyEntries.length) |
| 738 return; | 738 return; |
| 739 this._target.pageAgent().navigateToHistoryEntry(this._historyEntries[newInde
x].id); | 739 this._target.pageAgent().navigateToHistoryEntry(this._historyEntries[newInde
x].id); |
| 740 this._requestNavigationHistory(); | 740 this._requestNavigationHistory(); |
| 741 } | 741 } |
| 742 | 742 |
| 743 _navigateReload() { | 743 _navigateReload() { |
| 744 this._resourceTreeModel.reloadPage(); | 744 this._resourceTreeModel.reloadPage(); |
| 745 } | 745 } |
| 746 | 746 |
| 747 _navigationUrlKeyUp(event) { | 747 _navigationUrlKeyUp(event) { |
| 748 if (event.key !== 'Enter') | 748 if (event.key !== 'Enter') |
| 749 return; | 749 return; |
| 750 var url = this._navigationUrl.value; | 750 var url = this._navigationUrl.value; |
| 751 if (!url) | 751 if (!url) |
| 752 return; | 752 return; |
| 753 if (!url.match(WebInspector.ScreencastView._SchemeRegex)) | 753 if (!url.match(Screencast.ScreencastView._SchemeRegex)) |
| 754 url = 'http://' + url; | 754 url = 'http://' + url; |
| 755 this._target.pageAgent().navigate(url); | 755 this._target.pageAgent().navigate(url); |
| 756 this._canvasElement.focus(); | 756 this._canvasElement.focus(); |
| 757 } | 757 } |
| 758 | 758 |
| 759 _requestNavigationHistory() { | 759 _requestNavigationHistory() { |
| 760 this._target.pageAgent().getNavigationHistory(this._onNavigationHistory.bind
(this)); | 760 this._target.pageAgent().getNavigationHistory(this._onNavigationHistory.bind
(this)); |
| 761 } | 761 } |
| 762 | 762 |
| 763 _onNavigationHistory(error, currentIndex, entries) { | 763 _onNavigationHistory(error, currentIndex, entries) { |
| 764 if (error) | 764 if (error) |
| 765 return; | 765 return; |
| 766 | 766 |
| 767 this._historyIndex = currentIndex; | 767 this._historyIndex = currentIndex; |
| 768 this._historyEntries = entries; | 768 this._historyEntries = entries; |
| 769 | 769 |
| 770 this._navigationBack.disabled = currentIndex === 0; | 770 this._navigationBack.disabled = currentIndex === 0; |
| 771 this._navigationForward.disabled = currentIndex === (entries.length - 1); | 771 this._navigationForward.disabled = currentIndex === (entries.length - 1); |
| 772 | 772 |
| 773 var url = entries[currentIndex].url; | 773 var url = entries[currentIndex].url; |
| 774 var match = url.match(WebInspector.ScreencastView._HttpRegex); | 774 var match = url.match(Screencast.ScreencastView._HttpRegex); |
| 775 if (match) | 775 if (match) |
| 776 url = match[1]; | 776 url = match[1]; |
| 777 InspectorFrontendHost.inspectedURLChanged(url); | 777 InspectorFrontendHost.inspectedURLChanged(url); |
| 778 this._navigationUrl.value = url; | 778 this._navigationUrl.value = url; |
| 779 } | 779 } |
| 780 | 780 |
| 781 _focusNavigationBar() { | 781 _focusNavigationBar() { |
| 782 this._navigationUrl.focus(); | 782 this._navigationUrl.focus(); |
| 783 this._navigationUrl.select(); | 783 this._navigationUrl.select(); |
| 784 return true; | 784 return true; |
| 785 } | 785 } |
| 786 }; | 786 }; |
| 787 | 787 |
| 788 WebInspector.ScreencastView._bordersSize = 44; | 788 Screencast.ScreencastView._bordersSize = 44; |
| 789 | 789 |
| 790 WebInspector.ScreencastView._navBarHeight = 29; | 790 Screencast.ScreencastView._navBarHeight = 29; |
| 791 | 791 |
| 792 WebInspector.ScreencastView._HttpRegex = /^http:\/\/(.+)/; | 792 Screencast.ScreencastView._HttpRegex = /^http:\/\/(.+)/; |
| 793 | 793 |
| 794 WebInspector.ScreencastView._SchemeRegex = /^(https?|about|chrome):/; | 794 Screencast.ScreencastView._SchemeRegex = /^(https?|about|chrome):/; |
| 795 | 795 |
| 796 /** | 796 /** |
| 797 * @unrestricted | 797 * @unrestricted |
| 798 */ | 798 */ |
| 799 WebInspector.ScreencastView.ProgressTracker = class { | 799 Screencast.ScreencastView.ProgressTracker = class { |
| 800 /** | 800 /** |
| 801 * @param {!Element} element | 801 * @param {!Element} element |
| 802 */ | 802 */ |
| 803 constructor(element) { | 803 constructor(element) { |
| 804 this._element = element; | 804 this._element = element; |
| 805 | 805 |
| 806 WebInspector.targetManager.addModelListener( | 806 SDK.targetManager.addModelListener( |
| 807 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Ma
inFrameNavigated, | 807 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.MainFrameNavigated, |
| 808 this._onMainFrameNavigated, this); | 808 this._onMainFrameNavigated, this); |
| 809 WebInspector.targetManager.addModelListener( | 809 SDK.targetManager.addModelListener( |
| 810 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Lo
ad, this._onLoad, this); | 810 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.Load, this._onLoad,
this); |
| 811 WebInspector.targetManager.addModelListener( | 811 SDK.targetManager.addModelListener( |
| 812 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestS
tarted, this._onRequestStarted, this); | 812 SDK.NetworkManager, SDK.NetworkManager.Events.RequestStarted, this._onRe
questStarted, this); |
| 813 WebInspector.targetManager.addModelListener( | 813 SDK.targetManager.addModelListener( |
| 814 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestF
inished, this._onRequestFinished, this); | 814 SDK.NetworkManager, SDK.NetworkManager.Events.RequestFinished, this._onR
equestFinished, this); |
| 815 } | 815 } |
| 816 | 816 |
| 817 _onMainFrameNavigated() { | 817 _onMainFrameNavigated() { |
| 818 this._requestIds = {}; | 818 this._requestIds = {}; |
| 819 this._startedRequests = 0; | 819 this._startedRequests = 0; |
| 820 this._finishedRequests = 0; | 820 this._finishedRequests = 0; |
| 821 this._maxDisplayedProgress = 0; | 821 this._maxDisplayedProgress = 0; |
| 822 this._updateProgress(0.1); // Display first 10% on navigation start. | 822 this._updateProgress(0.1); // Display first 10% on navigation start. |
| 823 } | 823 } |
| 824 | 824 |
| 825 _onLoad() { | 825 _onLoad() { |
| 826 delete this._requestIds; | 826 delete this._requestIds; |
| 827 this._updateProgress(1); // Display 100% progress on load, hide it in 0.5s. | 827 this._updateProgress(1); // Display 100% progress on load, hide it in 0.5s. |
| 828 setTimeout(function() { | 828 setTimeout(function() { |
| 829 if (!this._navigationProgressVisible()) | 829 if (!this._navigationProgressVisible()) |
| 830 this._displayProgress(0); | 830 this._displayProgress(0); |
| 831 }.bind(this), 500); | 831 }.bind(this), 500); |
| 832 } | 832 } |
| 833 | 833 |
| 834 _navigationProgressVisible() { | 834 _navigationProgressVisible() { |
| 835 return !!this._requestIds; | 835 return !!this._requestIds; |
| 836 } | 836 } |
| 837 | 837 |
| 838 _onRequestStarted(event) { | 838 _onRequestStarted(event) { |
| 839 if (!this._navigationProgressVisible()) | 839 if (!this._navigationProgressVisible()) |
| 840 return; | 840 return; |
| 841 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); | 841 var request = /** @type {!SDK.NetworkRequest} */ (event.data); |
| 842 // Ignore long-living WebSockets for the sake of progress indicator, as we w
on't be waiting them anyway. | 842 // Ignore long-living WebSockets for the sake of progress indicator, as we w
on't be waiting them anyway. |
| 843 if (request.type === WebInspector.resourceTypes.WebSocket) | 843 if (request.type === Common.resourceTypes.WebSocket) |
| 844 return; | 844 return; |
| 845 this._requestIds[request.requestId] = request; | 845 this._requestIds[request.requestId] = request; |
| 846 ++this._startedRequests; | 846 ++this._startedRequests; |
| 847 } | 847 } |
| 848 | 848 |
| 849 _onRequestFinished(event) { | 849 _onRequestFinished(event) { |
| 850 if (!this._navigationProgressVisible()) | 850 if (!this._navigationProgressVisible()) |
| 851 return; | 851 return; |
| 852 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); | 852 var request = /** @type {!SDK.NetworkRequest} */ (event.data); |
| 853 if (!(request.requestId in this._requestIds)) | 853 if (!(request.requestId in this._requestIds)) |
| 854 return; | 854 return; |
| 855 ++this._finishedRequests; | 855 ++this._finishedRequests; |
| 856 setTimeout(function() { | 856 setTimeout(function() { |
| 857 this._updateProgress( | 857 this._updateProgress( |
| 858 this._finishedRequests / this._startedRequests * 0.9); // Finished re
quests drive the progress up to 90%. | 858 this._finishedRequests / this._startedRequests * 0.9); // Finished re
quests drive the progress up to 90%. |
| 859 }.bind(this), 500); // Delay to give the new requests time to start. This m
akes the progress smoother. | 859 }.bind(this), 500); // Delay to give the new requests time to start. This m
akes the progress smoother. |
| 860 } | 860 } |
| 861 | 861 |
| 862 _updateProgress(progress) { | 862 _updateProgress(progress) { |
| 863 if (!this._navigationProgressVisible()) | 863 if (!this._navigationProgressVisible()) |
| 864 return; | 864 return; |
| 865 if (this._maxDisplayedProgress >= progress) | 865 if (this._maxDisplayedProgress >= progress) |
| 866 return; | 866 return; |
| 867 this._maxDisplayedProgress = progress; | 867 this._maxDisplayedProgress = progress; |
| 868 this._displayProgress(progress); | 868 this._displayProgress(progress); |
| 869 } | 869 } |
| 870 | 870 |
| 871 _displayProgress(progress) { | 871 _displayProgress(progress) { |
| 872 this._element.style.width = (100 * progress) + '%'; | 872 this._element.style.width = (100 * progress) + '%'; |
| 873 } | 873 } |
| 874 }; | 874 }; |
| OLD | NEW |