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; |
|
dgozman
2014/06/25 13:31:35
window.devicePixelRatio already includes zoom fact
vkuzkokov
2014/06/25 17:56:58
Done.
| |
| 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 = metadata.device.width |
|
dgozman
2014/06/25 13:31:34
not: semicolon
| |
| 171 this._screenOffsetTop = offsetTop; | 166 var deviceHeightDIP = metadata.device.height |
|
dgozman
2014/06/25 13:31:35
ditto
| |
| 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 | |
| 171 this._imageZoom = Math.min(dimensionsCSS.width / this._imageElement.natu ralWidth, dimensionsCSS.height / (this._imageElement.naturalWidth * deviceSizeRa tio)); | |
| 172 this._viewportElement.classList.remove("hidden"); | |
| 173 var bordersSize = WebInspector.ScreencastView._bordersSize; | |
| 174 if (this._imageZoom < 1.01 / window.devicePixelRatio) | |
| 175 this._imageZoom = 1 / window.devicePixelRatio; | |
| 176 this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / d eviceWidthDIP; | |
| 177 this._viewportElement.style.width = deviceWidthDIP * this._screenZoom + bordersSize + "px"; | |
| 178 this._viewportElement.style.height = deviceHeightDIP * this._screenZoom + bordersSize + "px"; | |
| 179 | |
| 175 this.highlightDOMNode(this._highlightNode, this._highlightConfig); | 180 this.highlightDOMNode(this._highlightNode, this._highlightConfig); |
| 176 }, | 181 }, |
| 177 | 182 |
| 178 _isGlassPaneActive: function() | 183 _isGlassPaneActive: function() |
| 179 { | 184 { |
| 180 return !this._glassPaneElement.classList.contains("hidden"); | 185 return !this._glassPaneElement.classList.contains("hidden"); |
| 181 }, | 186 }, |
| 182 | 187 |
| 183 /** | 188 /** |
| 184 * @param {!WebInspector.Event} event | 189 * @param {!WebInspector.Event} event |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 this._glassPaneElement.classList.remove("hidden"); | 232 this._glassPaneElement.classList.remove("hidden"); |
| 228 } else if (this._profilerActive) { | 233 } else if (this._profilerActive) { |
| 229 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); | 234 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); |
| 230 this._glassPaneElement.classList.remove("hidden"); | 235 this._glassPaneElement.classList.remove("hidden"); |
| 231 } else { | 236 } else { |
| 232 this._glassPaneElement.classList.add("hidden"); | 237 this._glassPaneElement.classList.add("hidden"); |
| 233 } | 238 } |
| 234 }, | 239 }, |
| 235 | 240 |
| 236 /** | 241 /** |
| 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 | 242 * @param {?Event} event |
| 253 */ | 243 */ |
| 254 _handleMouseEvent: function(event) | 244 _handleMouseEvent: function(event) |
| 255 { | 245 { |
| 256 if (this._isGlassPaneActive()) { | 246 if (this._isGlassPaneActive()) { |
| 257 event.consume(); | 247 event.consume(); |
| 258 return; | 248 return; |
| 259 } | 249 } |
| 260 | 250 |
| 261 if (!this._viewport) | 251 if (!this._viewport) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 default: | 477 default: |
| 488 } | 478 } |
| 489 }, | 479 }, |
| 490 | 480 |
| 491 /** | 481 /** |
| 492 * @param {?Event} event | 482 * @param {?Event} event |
| 493 * @return {!{x: number, y: number}} | 483 * @return {!{x: number, y: number}} |
| 494 */ | 484 */ |
| 495 _zoomIntoScreenSpace: function(event) | 485 _zoomIntoScreenSpace: function(event) |
| 496 { | 486 { |
| 497 var zoom = this._canvasElement.offsetWidth / this._viewport.width / this ._pageScaleFactor; | 487 var zoom = this._canvasElement.offsetWidth / this._viewport.width; |
| 498 var position = {}; | 488 var position = {}; |
| 499 position.x = Math.round(event.offsetX / zoom); | 489 position.x = Math.round(event.offsetX / zoom); |
| 500 position.y = Math.round(event.offsetY / zoom); | 490 position.y = Math.round(event.offsetY / zoom); |
| 501 return position; | 491 return position; |
| 502 }, | 492 }, |
| 503 | 493 |
| 504 /** | 494 /** |
| 505 * @param {?Event} event | 495 * @param {?Event} event |
| 506 * @return {!{x: number, y: number}} | 496 * @return {!{x: number, y: number}} |
| 507 */ | 497 */ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 551 |
| 562 this._node = node; | 552 this._node = node; |
| 563 node.boxModel(callback.bind(this)); | 553 node.boxModel(callback.bind(this)); |
| 564 | 554 |
| 565 /** | 555 /** |
| 566 * @param {?DOMAgent.BoxModel} model | 556 * @param {?DOMAgent.BoxModel} model |
| 567 * @this {WebInspector.ScreencastView} | 557 * @this {WebInspector.ScreencastView} |
| 568 */ | 558 */ |
| 569 function callback(model) | 559 function callback(model) |
| 570 { | 560 { |
| 571 if (!model) { | 561 if (!model || !this._viewport) { |
| 572 this._repaint(); | 562 this._repaint(); |
| 573 return; | 563 return; |
| 574 } | 564 } |
| 575 this._model = this._scaleModel(model); | 565 this._model = this._scaleModel(model); |
| 576 this._config = config; | 566 this._config = config; |
| 577 this._repaint(); | 567 this._repaint(); |
| 578 } | 568 } |
| 579 }, | 569 }, |
| 580 | 570 |
| 581 /** | 571 /** |
| 582 * @param {!DOMAgent.BoxModel} model | 572 * @param {!DOMAgent.BoxModel} model |
| 583 * @return {!DOMAgent.BoxModel} | 573 * @return {!DOMAgent.BoxModel} |
| 584 */ | 574 */ |
| 585 _scaleModel: function(model) | 575 _scaleModel: function(model) |
| 586 { | 576 { |
| 587 var scale = this._canvasElement.offsetWidth / this._viewport.width; | 577 var scale = this._canvasElement.offsetWidth * this._pageScaleFactor / th is._viewport.width; |
| 588 | 578 |
| 589 /** | 579 /** |
| 590 * @param {!DOMAgent.Quad} quad | 580 * @param {!DOMAgent.Quad} quad |
| 591 * @this {WebInspector.ScreencastView} | 581 * @this {WebInspector.ScreencastView} |
| 592 */ | 582 */ |
| 593 function scaleQuad(quad) | 583 function scaleQuad(quad) |
| 594 { | 584 { |
| 595 for (var i = 0; i < quad.length; i += 2) { | 585 for (var i = 0; i < quad.length; i += 2) { |
| 596 quad[i] = (quad[i] - this._viewport.x) * scale; | 586 quad[i] = (quad[i] - this._viewport.x) * scale; |
| 597 quad[i + 1] = (quad[i + 1] - this._viewport.y) * scale + this._s creenOffsetTop * this._screenZoom; | 587 quad[i + 1] = (quad[i + 1] - this._viewport.y) * scale + this._s creenOffsetTop * this._screenZoom; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 } | 636 } |
| 647 if (hasContent) | 637 if (hasContent) |
| 648 this._drawOutlinedQuad(model.content, config.contentColor); | 638 this._drawOutlinedQuad(model.content, config.contentColor); |
| 649 this._context.restore(); | 639 this._context.restore(); |
| 650 | 640 |
| 651 this._drawElementTitle(); | 641 this._drawElementTitle(); |
| 652 | 642 |
| 653 this._context.globalCompositeOperation = "destination-over"; | 643 this._context.globalCompositeOperation = "destination-over"; |
| 654 } | 644 } |
| 655 | 645 |
| 656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom); | 646 this._context.scale(1 / window.devicePixelRatio, 1 / window.devicePixelR atio); |
|
dgozman
2014/06/25 13:31:35
This may be wrong with zoom != 1. Please double ch
vkuzkokov
2014/06/25 17:56:58
Done.
| |
| 647 this._context.drawImage(this._imageElement, 0, | |
| 648 this._screenOffsetTop * this._screenZoom * windo w.devicePixelRatio, | |
| 649 this._imageElement.naturalWidth * this._imageZoo m * window.devicePixelRatio, | |
|
dgozman
2014/06/25 13:31:35
Again, devicePixelRatio includes zoom.
| |
| 650 this._imageElement.naturalHeight * this._imageZo om * window.devicePixelRatio); | |
| 651 this._context.restore(); | |
| 657 | 652 |
| 658 this._context.restore(); | |
| 659 }, | 653 }, |
| 660 | 654 |
| 661 | 655 |
| 662 /** | 656 /** |
| 663 * @param {!DOMAgent.Quad} quad1 | 657 * @param {!DOMAgent.Quad} quad1 |
| 664 * @param {!DOMAgent.Quad} quad2 | 658 * @param {!DOMAgent.Quad} quad2 |
| 665 * @return {boolean} | 659 * @return {boolean} |
| 666 */ | 660 */ |
| 667 _quadsAreEqual: function(quad1, quad2) | 661 _quadsAreEqual: function(quad1, quad2) |
| 668 { | 662 { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 this._titleElement.style.left = (boxX + 3) + "px"; | 804 this._titleElement.style.left = (boxX + 3) + "px"; |
| 811 }, | 805 }, |
| 812 | 806 |
| 813 /** | 807 /** |
| 814 * @return {!{width: number, height: number}} | 808 * @return {!{width: number, height: number}} |
| 815 */ | 809 */ |
| 816 _viewportDimensions: function() | 810 _viewportDimensions: function() |
| 817 { | 811 { |
| 818 const gutterSize = 30; | 812 const gutterSize = 30; |
| 819 const bordersSize = WebInspector.ScreencastView._bordersSize; | 813 const bordersSize = WebInspector.ScreencastView._bordersSize; |
| 820 return { width: this.element.offsetWidth - bordersSize - gutterSize, | 814 var width = Math.floor(this.element.offsetWidth - bordersSize - gutterSi ze); |
| 821 height: this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight}; | 815 var height = Math.floor(this.element.offsetHeight - bordersSize - gutter Size - WebInspector.ScreencastView._navBarHeight); |
| 816 return { width: width, height: height }; | |
| 822 }, | 817 }, |
| 823 | 818 |
| 824 /** | 819 /** |
| 825 * @param {boolean} enabled | 820 * @param {boolean} enabled |
| 826 * @param {boolean} inspectUAShadowDOM | 821 * @param {boolean} inspectUAShadowDOM |
| 827 * @param {!DOMAgent.HighlightConfig} config | 822 * @param {!DOMAgent.HighlightConfig} config |
| 828 * @param {function(?Protocol.Error)=} callback | 823 * @param {function(?Protocol.Error)=} callback |
| 829 */ | 824 */ |
| 830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) | 825 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) |
| 831 { | 826 { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 return; | 1009 return; |
| 1015 this._maxDisplayedProgress = progress; | 1010 this._maxDisplayedProgress = progress; |
| 1016 this._displayProgress(progress); | 1011 this._displayProgress(progress); |
| 1017 }, | 1012 }, |
| 1018 | 1013 |
| 1019 _displayProgress: function(progress) | 1014 _displayProgress: function(progress) |
| 1020 { | 1015 { |
| 1021 this._element.style.width = (100 * progress) + "%"; | 1016 this._element.style.width = (100 * progress) + "%"; |
| 1022 } | 1017 } |
| 1023 }; | 1018 }; |
| OLD | NEW |