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 *= window.devicePixelRatio; |
| 133 dimensions.height *= WebInspector.zoomManager.zoomFactor(); | 133 dimensions.height *= window.devicePixelRatio; |
| 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; | |
| 162 this._pageScaleFactor = metadata.pageScaleFactor; | 155 this._pageScaleFactor = metadata.pageScaleFactor; |
| 163 this._viewport = metadata.viewport; | 156 this._screenOffsetTop = metadata.offsetTop; |
| 164 if (!this._viewport) | 157 this._deviceWidth = metadata.deviceWidth; |
| 165 return; | 158 this._deviceHeight = metadata.deviceHeight; |
| 166 var offsetTop = metadata.offsetTop || 0; | 159 this._scrollOffsetX = metadata.scrollOffsetX; |
| 167 var offsetBottom = metadata.offsetBottom || 0; | 160 this._scrollOffsetY = metadata.scrollOffsetY; |
| 168 | 161 |
| 169 var screenWidthDIP = this._viewport.width * this._pageScaleFactor; | 162 var deviceSizeRatio = metadata.deviceHeight / metadata.deviceWidth; |
| 170 var screenHeightDIP = this._viewport.height * this._pageScaleFactor + of fsetTop + offsetBottom; | 163 var dimensionsCSS = this._viewportDimensions(); |
| 171 this._screenOffsetTop = offsetTop; | |
| 172 this._resizeViewport(screenWidthDIP, screenHeightDIP); | |
| 173 | 164 |
| 174 this._imageZoom = this._imageElement.naturalWidth ? this._canvasElement. offsetWidth / this._imageElement.naturalWidth : 1; | 165 this._imageZoom = Math.min(dimensionsCSS.width / this._imageElement.natu ralWidth, dimensionsCSS.height / (this._imageElement.naturalWidth * deviceSizeRa tio)); |
| 166 this._viewportElement.classList.remove("hidden"); | |
| 167 var bordersSize = WebInspector.ScreencastView._bordersSize; | |
| 168 //if (this._imageZoom < 1.01 / window.devicePixelRatio) | |
|
dgozman
2014/06/26 11:34:21
Dead code.
vkuzkokov
2014/06/26 14:15:54
Forgot to uncomment
| |
| 169 // this._imageZoom = 1 / window.devicePixelRatio; | |
| 170 this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / m etadata.deviceWidth; | |
|
dgozman
2014/06/26 11:34:21
Let's call this something like |imageCssToDeviceDi
| |
| 171 this._viewportElement.style.width = metadata.deviceWidth * this._screenZ oom + bordersSize + "px"; | |
| 172 this._viewportElement.style.height = metadata.deviceHeight* this._screen Zoom + bordersSize + "px"; | |
| 173 | |
| 175 this.highlightDOMNode(this._highlightNode, this._highlightConfig); | 174 this.highlightDOMNode(this._highlightNode, this._highlightConfig); |
| 176 }, | 175 }, |
| 177 | 176 |
| 178 _isGlassPaneActive: function() | 177 _isGlassPaneActive: function() |
| 179 { | 178 { |
| 180 return !this._glassPaneElement.classList.contains("hidden"); | 179 return !this._glassPaneElement.classList.contains("hidden"); |
| 181 }, | 180 }, |
| 182 | 181 |
| 183 /** | 182 /** |
| 184 * @param {!WebInspector.Event} event | 183 * @param {!WebInspector.Event} event |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 this._glassPaneElement.classList.remove("hidden"); | 226 this._glassPaneElement.classList.remove("hidden"); |
| 228 } else if (this._profilerActive) { | 227 } else if (this._profilerActive) { |
| 229 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); | 228 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); |
| 230 this._glassPaneElement.classList.remove("hidden"); | 229 this._glassPaneElement.classList.remove("hidden"); |
| 231 } else { | 230 } else { |
| 232 this._glassPaneElement.classList.add("hidden"); | 231 this._glassPaneElement.classList.add("hidden"); |
| 233 } | 232 } |
| 234 }, | 233 }, |
| 235 | 234 |
| 236 /** | 235 /** |
| 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 | 236 * @param {?Event} event |
| 253 */ | 237 */ |
| 254 _handleMouseEvent: function(event) | 238 _handleMouseEvent: function(event) |
| 255 { | 239 { |
| 256 if (this._isGlassPaneActive()) { | 240 if (this._isGlassPaneActive()) { |
| 257 event.consume(); | 241 event.consume(); |
| 258 return; | 242 return; |
| 259 } | 243 } |
| 260 | 244 |
| 261 if (!this._viewport) | 245 if (!this._pageScaleFactor) |
| 262 return; | 246 return; |
| 263 | 247 |
| 264 if (!this._inspectModeConfig || event.type === "mousewheel") { | 248 if (!this._inspectModeConfig || event.type === "mousewheel") { |
| 265 this._simulateTouchGestureForMouseEvent(event); | 249 this._simulateTouchGestureForMouseEvent(event); |
| 266 event.preventDefault(); | 250 event.preventDefault(); |
| 267 if (event.type === "mousedown") | 251 if (event.type === "mousedown") |
| 268 this._canvasElement.focus(); | 252 this._canvasElement.focus(); |
| 269 return; | 253 return; |
| 270 } | 254 } |
| 271 | 255 |
| 272 var position = this._convertIntoScreenSpace(event); | 256 var position = this._convertIntoScreenSpace(event); |
| 273 this._target.domModel.nodeForLocation(position.x / this._pageScaleFactor , position.y / this._pageScaleFactor, callback.bind(this)); | 257 this._target.domModel.nodeForLocation(position.x / this._pageScaleFactor + this._scrollOffsetX, position.y / this._pageScaleFactor + this._scrollOffsetY , callback.bind(this)); |
| 274 | 258 |
| 275 /** | 259 /** |
| 276 * @param {?WebInspector.DOMNode} node | 260 * @param {?WebInspector.DOMNode} node |
| 277 * @this {WebInspector.ScreencastView} | 261 * @this {WebInspector.ScreencastView} |
| 278 */ | 262 */ |
| 279 function callback(node) | 263 function callback(node) |
| 280 { | 264 { |
| 281 if (!node) | 265 if (!node) |
| 282 return; | 266 return; |
| 283 if (event.type === "mousemove") | 267 if (event.type === "mousemove") |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 default: | 471 default: |
| 488 } | 472 } |
| 489 }, | 473 }, |
| 490 | 474 |
| 491 /** | 475 /** |
| 492 * @param {?Event} event | 476 * @param {?Event} event |
| 493 * @return {!{x: number, y: number}} | 477 * @return {!{x: number, y: number}} |
| 494 */ | 478 */ |
| 495 _zoomIntoScreenSpace: function(event) | 479 _zoomIntoScreenSpace: function(event) |
| 496 { | 480 { |
| 497 var zoom = this._canvasElement.offsetWidth / this._viewport.width / this ._pageScaleFactor; | 481 var zoom = this._canvasElement.offsetWidth / this._deviceWidth; |
| 498 var position = {}; | 482 var position = {}; |
| 499 position.x = Math.round(event.offsetX / zoom); | 483 position.x = Math.round(event.offsetX / zoom); |
| 500 position.y = Math.round(event.offsetY / zoom); | 484 position.y = Math.round(event.offsetY / zoom); |
| 501 return position; | 485 return position; |
| 502 }, | 486 }, |
| 503 | 487 |
| 504 /** | 488 /** |
| 505 * @param {?Event} event | 489 * @param {?Event} event |
| 506 * @return {!{x: number, y: number}} | 490 * @return {!{x: number, y: number}} |
| 507 */ | 491 */ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 545 |
| 562 this._node = node; | 546 this._node = node; |
| 563 node.boxModel(callback.bind(this)); | 547 node.boxModel(callback.bind(this)); |
| 564 | 548 |
| 565 /** | 549 /** |
| 566 * @param {?DOMAgent.BoxModel} model | 550 * @param {?DOMAgent.BoxModel} model |
| 567 * @this {WebInspector.ScreencastView} | 551 * @this {WebInspector.ScreencastView} |
| 568 */ | 552 */ |
| 569 function callback(model) | 553 function callback(model) |
| 570 { | 554 { |
| 571 if (!model) { | 555 if (!model || !this._pageScaleFactor) { |
| 572 this._repaint(); | 556 this._repaint(); |
| 573 return; | 557 return; |
| 574 } | 558 } |
| 575 this._model = this._scaleModel(model); | 559 this._model = this._scaleModel(model); |
| 576 this._config = config; | 560 this._config = config; |
| 577 this._repaint(); | 561 this._repaint(); |
| 578 } | 562 } |
| 579 }, | 563 }, |
| 580 | 564 |
| 581 /** | 565 /** |
| 582 * @param {!DOMAgent.BoxModel} model | 566 * @param {!DOMAgent.BoxModel} model |
| 583 * @return {!DOMAgent.BoxModel} | 567 * @return {!DOMAgent.BoxModel} |
| 584 */ | 568 */ |
| 585 _scaleModel: function(model) | 569 _scaleModel: function(model) |
| 586 { | 570 { |
| 587 var scale = this._canvasElement.offsetWidth / this._viewport.width; | 571 var scale = this._canvasElement.offsetWidth * this._pageScaleFactor / th is._deviceWidth; |
| 588 | 572 |
| 589 /** | 573 /** |
| 590 * @param {!DOMAgent.Quad} quad | 574 * @param {!DOMAgent.Quad} quad |
| 591 * @this {WebInspector.ScreencastView} | 575 * @this {WebInspector.ScreencastView} |
| 592 */ | 576 */ |
| 593 function scaleQuad(quad) | 577 function scaleQuad(quad) |
| 594 { | 578 { |
| 595 for (var i = 0; i < quad.length; i += 2) { | 579 for (var i = 0; i < quad.length; i += 2) { |
| 596 quad[i] = (quad[i] - this._viewport.x) * scale; | 580 quad[i] = (quad[i] - this._scrollOffsetX) * scale; |
| 597 quad[i + 1] = (quad[i + 1] - this._viewport.y) * scale + this._s creenOffsetTop * this._screenZoom; | 581 quad[i + 1] = (quad[i + 1] - this._scrollOffsetY) * scale + this ._screenOffsetTop * this._screenZoom; |
| 598 } | 582 } |
| 599 } | 583 } |
| 600 | 584 |
| 601 scaleQuad.call(this, model.content); | 585 scaleQuad.call(this, model.content); |
| 602 scaleQuad.call(this, model.padding); | 586 scaleQuad.call(this, model.padding); |
| 603 scaleQuad.call(this, model.border); | 587 scaleQuad.call(this, model.border); |
| 604 scaleQuad.call(this, model.margin); | 588 scaleQuad.call(this, model.margin); |
| 605 return model; | 589 return model; |
| 606 }, | 590 }, |
| 607 | 591 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 } | 630 } |
| 647 if (hasContent) | 631 if (hasContent) |
| 648 this._drawOutlinedQuad(model.content, config.contentColor); | 632 this._drawOutlinedQuad(model.content, config.contentColor); |
| 649 this._context.restore(); | 633 this._context.restore(); |
| 650 | 634 |
| 651 this._drawElementTitle(); | 635 this._drawElementTitle(); |
| 652 | 636 |
| 653 this._context.globalCompositeOperation = "destination-over"; | 637 this._context.globalCompositeOperation = "destination-over"; |
| 654 } | 638 } |
| 655 | 639 |
| 656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom); | 640 this._context.scale(1 / window.devicePixelRatio, 1 / window.devicePixelR atio); |
| 641 this._context.drawImage(this._imageElement, 0, | |
| 642 this._screenOffsetTop * this._screenZoom * windo w.devicePixelRatio, | |
| 643 this._imageElement.naturalWidth * this._imageZoo m * window.devicePixelRatio, | |
|
dgozman
2014/06/26 11:34:21
Why scale context and then multiply everything by
vkuzkokov
2014/06/26 14:15:54
No reason
| |
| 644 this._imageElement.naturalHeight * this._imageZo om * window.devicePixelRatio); | |
| 645 this._context.restore(); | |
| 657 | 646 |
| 658 this._context.restore(); | |
| 659 }, | 647 }, |
| 660 | 648 |
| 661 | 649 |
| 662 /** | 650 /** |
| 663 * @param {!DOMAgent.Quad} quad1 | 651 * @param {!DOMAgent.Quad} quad1 |
| 664 * @param {!DOMAgent.Quad} quad2 | 652 * @param {!DOMAgent.Quad} quad2 |
| 665 * @return {boolean} | 653 * @return {boolean} |
| 666 */ | 654 */ |
| 667 _quadsAreEqual: function(quad1, quad2) | 655 _quadsAreEqual: function(quad1, quad2) |
| 668 { | 656 { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 this._titleElement.style.left = (boxX + 3) + "px"; | 798 this._titleElement.style.left = (boxX + 3) + "px"; |
| 811 }, | 799 }, |
| 812 | 800 |
| 813 /** | 801 /** |
| 814 * @return {!{width: number, height: number}} | 802 * @return {!{width: number, height: number}} |
| 815 */ | 803 */ |
| 816 _viewportDimensions: function() | 804 _viewportDimensions: function() |
| 817 { | 805 { |
| 818 const gutterSize = 30; | 806 const gutterSize = 30; |
| 819 const bordersSize = WebInspector.ScreencastView._bordersSize; | 807 const bordersSize = WebInspector.ScreencastView._bordersSize; |
| 820 return { width: this.element.offsetWidth - bordersSize - gutterSize, | 808 var width = Math.floor(this.element.offsetWidth - bordersSize - gutterSi ze); |
| 821 height: this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight}; | 809 var height = Math.floor(this.element.offsetHeight - bordersSize - gutter Size - WebInspector.ScreencastView._navBarHeight); |
|
dgozman
2014/06/26 11:34:21
Ensure that canvas has exactly integer width/heigh
| |
| 810 return { width: width, height: height }; | |
| 822 }, | 811 }, |
| 823 | 812 |
| 824 /** | 813 /** |
| 825 * @param {boolean} enabled | 814 * @param {boolean} enabled |
| 826 * @param {boolean} inspectUAShadowDOM | 815 * @param {boolean} inspectUAShadowDOM |
| 827 * @param {!DOMAgent.HighlightConfig} config | 816 * @param {!DOMAgent.HighlightConfig} config |
| 828 * @param {function(?Protocol.Error)=} callback | 817 * @param {function(?Protocol.Error)=} callback |
| 829 */ | 818 */ |
| 830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) | 819 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) |
| 831 { | 820 { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 return; | 1003 return; |
| 1015 this._maxDisplayedProgress = progress; | 1004 this._maxDisplayedProgress = progress; |
| 1016 this._displayProgress(progress); | 1005 this._displayProgress(progress); |
| 1017 }, | 1006 }, |
| 1018 | 1007 |
| 1019 _displayProgress: function(progress) | 1008 _displayProgress: function(progress) |
| 1020 { | 1009 { |
| 1021 this._element.style.width = (100 * progress) + "%"; | 1010 this._element.style.width = (100 * progress) + "%"; |
| 1022 } | 1011 } |
| 1023 }; | 1012 }; |
| OLD | NEW |