Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 }, | 116 }, |
| 117 | 117 |
| 118 _startCasting: function() | 118 _startCasting: function() |
| 119 { | 119 { |
| 120 if (this._timelineActive || this._profilerActive) | 120 if (this._timelineActive || this._profilerActive) |
| 121 return; | 121 return; |
| 122 if (this._isCasting) | 122 if (this._isCasting) |
| 123 return; | 123 return; |
| 124 this._isCasting = true; | 124 this._isCasting = true; |
| 125 | 125 |
| 126 const maxImageDimension = 1024; | 126 const maxImageDimension = 2048; |
| 127 var dimensions = this._viewportDimensions(); | 127 var dimensions = this._viewportDimensions(); |
| 128 if (dimensions.width < 0 || dimensions.height < 0) { | 128 if (dimensions.width < 0 || dimensions.height < 0) { |
| 129 this._isCasting = false; | 129 this._isCasting = false; |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 dimensions.width *= WebInspector.zoomManager.zoomFactor(); | 132 dimensions.width *= WebInspector.zoomManager.zoomFactor() * window.devic ePixelRatio; |
| 133 dimensions.height *= WebInspector.zoomManager.zoomFactor(); | 133 dimensions.height *= WebInspector.zoomManager.zoomFactor() * window.devi cePixelRatio; |
| 134 this._target.pageAgent().startScreencast("jpeg", 80, Math.min(maxImageDi mension, dimensions.width), Math.min(maxImageDimension, dimensions.height)); | 134 this._target.pageAgent().startScreencast("jpeg", 80, Math.min(maxImageDi mension, dimensions.width), Math.min(maxImageDimension, dimensions.height)); |
| 135 this._target.domModel.setHighlighter(this); | 135 this._target.domModel.setHighlighter(this); |
| 136 }, | 136 }, |
| 137 | 137 |
| 138 _stopCasting: function() | 138 _stopCasting: function() |
| 139 { | 139 { |
| 140 if (!this._isCasting) | 140 if (!this._isCasting) |
| 141 return; | 141 return; |
| 142 this._isCasting = false; | 142 this._isCasting = false; |
| 143 this._target.pageAgent().stopScreencast(); | 143 this._target.pageAgent().stopScreencast(); |
| 144 this._target.domModel.setHighlighter(null); | 144 this._target.domModel.setHighlighter(null); |
| 145 }, | 145 }, |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {!WebInspector.Event} event | 148 * @param {!WebInspector.Event} event |
| 149 */ | 149 */ |
| 150 _screencastFrame: function(event) | 150 _screencastFrame: function(event) |
| 151 { | 151 { |
| 152 var metadata = /** type {PageAgent.ScreencastFrameMetadata} */(event.dat a.metadata); | 152 var metadata = /** type {PageAgent.ScreencastFrameMetadata} */(event.dat a.metadata); |
| 153 | |
| 154 if (!metadata.deviceScaleFactor) { | |
| 155 console.log(event.data.data); | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 var base64Data = /** type {string} */(event.data.data); | 153 var base64Data = /** type {string} */(event.data.data); |
| 160 this._imageElement.src = "data:image/jpg;base64," + base64Data; | 154 this._imageElement.src = "data:image/jpg;base64," + base64Data; |
| 161 this._deviceScaleFactor = metadata.deviceScaleFactor; | 155 this._deviceScaleFactor = metadata.deviceScaleFactor; |
| 162 this._pageScaleFactor = metadata.pageScaleFactor; | 156 this._pageScaleFactor = metadata.pageScaleFactor; |
| 163 this._viewport = metadata.viewport; | 157 this._viewport = metadata.viewport; |
| 164 if (!this._viewport) | 158 if (!this._viewport) |
| 165 return; | 159 return; |
| 166 var offsetTop = metadata.offsetTop || 0; | 160 var offsetTopDIP = metadata.offsetTop || 0; |
| 167 var offsetBottom = metadata.offsetBottom || 0; | 161 var offsetBottomDIP = metadata.offsetBottom || 0; |
| 162 this._screenOffsetTop = offsetTopDIP; | |
| 168 | 163 |
| 169 var screenWidthDIP = this._viewport.width * this._pageScaleFactor; | 164 var totalBarHeightDIP = offsetTopDIP + offsetBottomDIP; |
| 170 var screenHeightDIP = this._viewport.height * this._pageScaleFactor + of fsetTop + offsetBottom; | 165 var deviceWidthDIP = Math.round(this._viewport.width); |
| 171 this._screenOffsetTop = offsetTop; | 166 var deviceHeightDIP = Math.round(this._viewport.height + totalBarHeightD IP); |
|
pfeldman
2014/06/24 16:24:59
Lets pass device dimensions from the backend inste
vkuzkokov
2014/06/25 12:17:39
Done.
| |
| 172 this._resizeViewport(screenWidthDIP, screenHeightDIP); | 167 var deviceSizeRatio = deviceHeightDIP / deviceWidthDIP; |
| 173 | 168 |
| 174 this._imageZoom = this._imageElement.naturalWidth ? this._canvasElement. offsetWidth / this._imageElement.naturalWidth : 1; | 169 var dimensionsCSS = this._viewportDimensions(); |
| 170 var dimensions = { width : dimensionsCSS.width * window.devicePixelRatio , height : dimensionsCSS.height * window.devicePixelRatio }; | |
| 171 | |
| 172 // _imageZoom - screen pixels per pixel of the image | |
| 173 this._imageZoom = Math.min(dimensions.width / this._imageElement.natural Width, dimensions.height / (this._imageElement.naturalWidth * deviceSizeRatio)); | |
| 174 this._viewportElement.classList.remove("hidden"); | |
| 175 var bordersSize = WebInspector.ScreencastView._bordersSize; | |
| 176 if (this._imageZoom < 1.01) { | |
| 177 this._imageZoom = 1; | |
| 178 // _screenZoom - screen pixels per DIP | |
| 179 this._screenZoom = this._imageElement.naturalWidth / deviceWidthDIP; | |
| 180 this._viewportElement.style.width = this._imageElement.naturalWidth / window.devicePixelRatio + bordersSize + "px"; | |
| 181 this._viewportElement.style.height = (this._imageElement.naturalHeig ht + Math.round(totalBarHeightDIP * this._screenZoom)) / window.devicePixelRatio + bordersSize + "px"; | |
| 182 } else { | |
| 183 // _screenZoom - screen pixels per DIP | |
| 184 this._screenZoom = Math.min(dimensions.width / deviceWidthDIP, dimen sions.height / deviceHeightDIP); | |
| 185 this._viewportElement.style.width = deviceWidthDIP * this._screenZoo m / window.devicePixelRatio + bordersSize + "px"; | |
| 186 this._viewportElement.style.height = deviceHeightDIP * this._screenZ oom / window.devicePixelRatio + bordersSize + "px"; | |
| 187 } | |
| 188 | |
| 175 this.highlightDOMNode(this._highlightNode, this._highlightConfig); | 189 this.highlightDOMNode(this._highlightNode, this._highlightConfig); |
| 176 }, | 190 }, |
| 177 | 191 |
| 178 _isGlassPaneActive: function() | 192 _isGlassPaneActive: function() |
| 179 { | 193 { |
| 180 return !this._glassPaneElement.classList.contains("hidden"); | 194 return !this._glassPaneElement.classList.contains("hidden"); |
| 181 }, | 195 }, |
| 182 | 196 |
| 183 /** | 197 /** |
| 184 * @param {!WebInspector.Event} event | 198 * @param {!WebInspector.Event} event |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 this._glassPaneElement.classList.remove("hidden"); | 241 this._glassPaneElement.classList.remove("hidden"); |
| 228 } else if (this._profilerActive) { | 242 } else if (this._profilerActive) { |
| 229 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); | 243 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); |
| 230 this._glassPaneElement.classList.remove("hidden"); | 244 this._glassPaneElement.classList.remove("hidden"); |
| 231 } else { | 245 } else { |
| 232 this._glassPaneElement.classList.add("hidden"); | 246 this._glassPaneElement.classList.add("hidden"); |
| 233 } | 247 } |
| 234 }, | 248 }, |
| 235 | 249 |
| 236 /** | 250 /** |
| 237 * @param {number} screenWidthDIP | |
| 238 * @param {number} screenHeightDIP | |
| 239 */ | |
| 240 _resizeViewport: function(screenWidthDIP, screenHeightDIP) | |
| 241 { | |
| 242 var dimensions = this._viewportDimensions(); | |
| 243 this._screenZoom = Math.min(dimensions.width / screenWidthDIP, dimension s.height / screenHeightDIP); | |
| 244 | |
| 245 var bordersSize = WebInspector.ScreencastView._bordersSize; | |
| 246 this._viewportElement.classList.remove("hidden"); | |
| 247 this._viewportElement.style.width = screenWidthDIP * this._screenZoom + bordersSize + "px"; | |
| 248 this._viewportElement.style.height = screenHeightDIP * this._screenZoom + bordersSize + "px"; | |
| 249 }, | |
| 250 | |
| 251 /** | |
| 252 * @param {?Event} event | 251 * @param {?Event} event |
| 253 */ | 252 */ |
| 254 _handleMouseEvent: function(event) | 253 _handleMouseEvent: function(event) |
| 255 { | 254 { |
| 256 if (this._isGlassPaneActive()) { | 255 if (this._isGlassPaneActive()) { |
| 257 event.consume(); | 256 event.consume(); |
| 258 return; | 257 return; |
| 259 } | 258 } |
| 260 | 259 |
| 261 if (!this._viewport) | 260 if (!this._viewport) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 274 | 273 |
| 275 /** | 274 /** |
| 276 * @param {?WebInspector.DOMNode} node | 275 * @param {?WebInspector.DOMNode} node |
| 277 * @this {WebInspector.ScreencastView} | 276 * @this {WebInspector.ScreencastView} |
| 278 */ | 277 */ |
| 279 function callback(node) | 278 function callback(node) |
| 280 { | 279 { |
| 281 if (!node) | 280 if (!node) |
| 282 return; | 281 return; |
| 283 if (event.type === "mousemove") | 282 if (event.type === "mousemove") |
| 284 this.highlightDOMNode(node, this._inspectModeConfig); | 283 node.highlight(this._inspectModeConfig); |
|
pfeldman
2014/06/24 16:24:59
Roll back
vkuzkokov
2014/06/25 12:17:39
Done.
| |
| 285 else if (event.type === "click") | 284 else if (event.type === "click") |
| 286 node.reveal(); | 285 node.reveal(); |
| 287 } | 286 } |
| 288 }, | 287 }, |
| 289 | 288 |
| 290 /** | 289 /** |
| 291 * @param {?Event} event | 290 * @param {?Event} event |
| 292 */ | 291 */ |
| 293 _handleKeyEvent: function(event) | 292 _handleKeyEvent: function(event) |
| 294 { | 293 { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 default: | 486 default: |
| 488 } | 487 } |
| 489 }, | 488 }, |
| 490 | 489 |
| 491 /** | 490 /** |
| 492 * @param {?Event} event | 491 * @param {?Event} event |
| 493 * @return {!{x: number, y: number}} | 492 * @return {!{x: number, y: number}} |
| 494 */ | 493 */ |
| 495 _zoomIntoScreenSpace: function(event) | 494 _zoomIntoScreenSpace: function(event) |
| 496 { | 495 { |
| 497 var zoom = this._canvasElement.offsetWidth / this._viewport.width / this ._pageScaleFactor; | 496 var zoom = this._canvasElement.offsetWidth / this._viewport.width; |
| 498 var position = {}; | 497 var position = {}; |
| 499 position.x = Math.round(event.offsetX / zoom); | 498 position.x = Math.round(event.offsetX / zoom); |
| 500 position.y = Math.round(event.offsetY / zoom); | 499 position.y = Math.round(event.offsetY / zoom); |
| 501 return position; | 500 return position; |
| 502 }, | 501 }, |
| 503 | 502 |
| 504 /** | 503 /** |
| 505 * @param {?Event} event | 504 * @param {?Event} event |
| 506 * @return {!{x: number, y: number}} | 505 * @return {!{x: number, y: number}} |
| 507 */ | 506 */ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 560 |
| 562 this._node = node; | 561 this._node = node; |
| 563 node.boxModel(callback.bind(this)); | 562 node.boxModel(callback.bind(this)); |
| 564 | 563 |
| 565 /** | 564 /** |
| 566 * @param {?DOMAgent.BoxModel} model | 565 * @param {?DOMAgent.BoxModel} model |
| 567 * @this {WebInspector.ScreencastView} | 566 * @this {WebInspector.ScreencastView} |
| 568 */ | 567 */ |
| 569 function callback(model) | 568 function callback(model) |
| 570 { | 569 { |
| 571 if (!model) { | 570 if (!model || !this._viewport) { |
| 572 this._repaint(); | 571 this._repaint(); |
| 573 return; | 572 return; |
| 574 } | 573 } |
| 575 this._model = this._scaleModel(model); | 574 this._model = this._scaleModel(model); |
| 576 this._config = config; | 575 this._config = config; |
| 577 this._repaint(); | 576 this._repaint(); |
| 578 } | 577 } |
| 579 }, | 578 }, |
| 580 | 579 |
| 581 /** | 580 /** |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 612 | 611 |
| 613 this._canvasElement.width = window.devicePixelRatio * this._canvasElemen t.offsetWidth; | 612 this._canvasElement.width = window.devicePixelRatio * this._canvasElemen t.offsetWidth; |
| 614 this._canvasElement.height = window.devicePixelRatio * this._canvasEleme nt.offsetHeight; | 613 this._canvasElement.height = window.devicePixelRatio * this._canvasEleme nt.offsetHeight; |
| 615 | 614 |
| 616 this._context.save(); | 615 this._context.save(); |
| 617 this._context.scale(window.devicePixelRatio, window.devicePixelRatio); | 616 this._context.scale(window.devicePixelRatio, window.devicePixelRatio); |
| 618 | 617 |
| 619 // Paint top and bottom gutter. | 618 // Paint top and bottom gutter. |
| 620 this._context.save(); | 619 this._context.save(); |
| 621 this._context.fillStyle = this._checkerboardPattern; | 620 this._context.fillStyle = this._checkerboardPattern; |
| 622 this._context.fillRect(0, 0, this._canvasElement.offsetWidth, this._scre enOffsetTop * this._screenZoom); | 621 this._context.fillRect(0, 0, this._canvasElement.offsetWidth, (this._scr eenOffsetTop * this._screenZoom) / window.devicePixelRatio); |
| 623 this._context.fillRect(0, this._screenOffsetTop * this._screenZoom + thi s._imageElement.naturalHeight * this._imageZoom, this._canvasElement.offsetWidth , this._canvasElement.offsetHeight); | 622 this._context.fillRect(0, (this._screenOffsetTop * this._screenZoom + th is._imageElement.naturalHeight * this._imageZoom) / window.devicePixelRatio, thi s._canvasElement.offsetWidth, this._canvasElement.offsetHeight); |
| 624 this._context.restore(); | 623 this._context.restore(); |
| 625 | 624 |
| 626 if (model && config) { | 625 if (model && config) { |
| 627 this._context.save(); | 626 this._context.save(); |
| 628 const transparentColor = "rgba(0, 0, 0, 0)"; | 627 const transparentColor = "rgba(0, 0, 0, 0)"; |
| 629 var hasContent = model.content && config.contentColor !== transparen tColor; | 628 var hasContent = model.content && config.contentColor !== transparen tColor; |
| 630 var hasPadding = model.padding && config.paddingColor !== transparen tColor; | 629 var hasPadding = model.padding && config.paddingColor !== transparen tColor; |
| 631 var hasBorder = model.border && config.borderColor !== transparentCo lor; | 630 var hasBorder = model.border && config.borderColor !== transparentCo lor; |
| 632 var hasMargin = model.margin && config.marginColor !== transparentCo lor; | 631 var hasMargin = model.margin && config.marginColor !== transparentCo lor; |
| 633 | 632 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 646 } | 645 } |
| 647 if (hasContent) | 646 if (hasContent) |
| 648 this._drawOutlinedQuad(model.content, config.contentColor); | 647 this._drawOutlinedQuad(model.content, config.contentColor); |
| 649 this._context.restore(); | 648 this._context.restore(); |
| 650 | 649 |
| 651 this._drawElementTitle(); | 650 this._drawElementTitle(); |
| 652 | 651 |
| 653 this._context.globalCompositeOperation = "destination-over"; | 652 this._context.globalCompositeOperation = "destination-over"; |
| 654 } | 653 } |
| 655 | 654 |
| 655 this._context.restore(); | |
| 656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom); | 656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom); |
| 657 | 657 |
| 658 this._context.restore(); | |
| 659 }, | 658 }, |
| 660 | 659 |
| 661 | 660 |
| 662 /** | 661 /** |
| 663 * @param {!DOMAgent.Quad} quad1 | 662 * @param {!DOMAgent.Quad} quad1 |
| 664 * @param {!DOMAgent.Quad} quad2 | 663 * @param {!DOMAgent.Quad} quad2 |
| 665 * @return {boolean} | 664 * @return {boolean} |
| 666 */ | 665 */ |
| 667 _quadsAreEqual: function(quad1, quad2) | 666 _quadsAreEqual: function(quad1, quad2) |
| 668 { | 667 { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 this._titleElement.style.left = (boxX + 3) + "px"; | 809 this._titleElement.style.left = (boxX + 3) + "px"; |
| 811 }, | 810 }, |
| 812 | 811 |
| 813 /** | 812 /** |
| 814 * @return {!{width: number, height: number}} | 813 * @return {!{width: number, height: number}} |
| 815 */ | 814 */ |
| 816 _viewportDimensions: function() | 815 _viewportDimensions: function() |
| 817 { | 816 { |
| 818 const gutterSize = 30; | 817 const gutterSize = 30; |
| 819 const bordersSize = WebInspector.ScreencastView._bordersSize; | 818 const bordersSize = WebInspector.ScreencastView._bordersSize; |
| 820 return { width: this.element.offsetWidth - bordersSize - gutterSize, | 819 var width = Math.floor(this.element.offsetWidth - bordersSize - gutterSi ze); |
| 821 height: this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight}; | 820 var height = Math.floor(this.element.offsetHeight - bordersSize - gutter Size - WebInspector.ScreencastView._navBarHeight); |
| 821 return { width: width, height: height }; | |
| 822 }, | 822 }, |
| 823 | 823 |
| 824 /** | 824 /** |
| 825 * @param {boolean} enabled | 825 * @param {boolean} enabled |
| 826 * @param {boolean} inspectUAShadowDOM | 826 * @param {boolean} inspectUAShadowDOM |
| 827 * @param {!DOMAgent.HighlightConfig} config | 827 * @param {!DOMAgent.HighlightConfig} config |
| 828 * @param {function(?Protocol.Error)=} callback | 828 * @param {function(?Protocol.Error)=} callback |
| 829 */ | 829 */ |
| 830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) | 830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) |
| 831 { | 831 { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 return; | 1014 return; |
| 1015 this._maxDisplayedProgress = progress; | 1015 this._maxDisplayedProgress = progress; |
| 1016 this._displayProgress(progress); | 1016 this._displayProgress(progress); |
| 1017 }, | 1017 }, |
| 1018 | 1018 |
| 1019 _displayProgress: function(progress) | 1019 _displayProgress: function(progress) |
| 1020 { | 1020 { |
| 1021 this._element.style.width = (100 * progress) + "%"; | 1021 this._element.style.width = (100 * progress) + "%"; |
| 1022 } | 1022 } |
| 1023 }; | 1023 }; |
| OLD | NEW |