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) |
| 169 this._imageZoom = 1 / window.devicePixelRatio; |
| 170 this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / m
etadata.deviceWidth; |
| 171 this._viewportElement.style.width = metadata.deviceWidth * this._screenZ
oom + bordersSize + "px"; |
| 172 this._viewportElement.style.height = metadata.deviceHeight * this._scree
nZoom + 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; | |
498 var position = {}; | 481 var position = {}; |
499 position.x = Math.round(event.offsetX / zoom); | 482 position.x = Math.round(event.offsetX / this._screenZoom); |
500 position.y = Math.round(event.offsetY / zoom); | 483 position.y = Math.round(event.offsetY / this._screenZoom); |
501 return position; | 484 return position; |
502 }, | 485 }, |
503 | 486 |
504 /** | 487 /** |
505 * @param {?Event} event | 488 * @param {?Event} event |
506 * @return {!{x: number, y: number}} | 489 * @return {!{x: number, y: number}} |
507 */ | 490 */ |
508 _convertIntoScreenSpace: function(event) | 491 _convertIntoScreenSpace: function(event) |
509 { | 492 { |
510 var position = this._zoomIntoScreenSpace(event); | 493 var position = this._zoomIntoScreenSpace(event); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 544 |
562 this._node = node; | 545 this._node = node; |
563 node.boxModel(callback.bind(this)); | 546 node.boxModel(callback.bind(this)); |
564 | 547 |
565 /** | 548 /** |
566 * @param {?DOMAgent.BoxModel} model | 549 * @param {?DOMAgent.BoxModel} model |
567 * @this {WebInspector.ScreencastView} | 550 * @this {WebInspector.ScreencastView} |
568 */ | 551 */ |
569 function callback(model) | 552 function callback(model) |
570 { | 553 { |
571 if (!model) { | 554 if (!model || !this._pageScaleFactor) { |
572 this._repaint(); | 555 this._repaint(); |
573 return; | 556 return; |
574 } | 557 } |
575 this._model = this._scaleModel(model); | 558 this._model = this._scaleModel(model); |
576 this._config = config; | 559 this._config = config; |
577 this._repaint(); | 560 this._repaint(); |
578 } | 561 } |
579 }, | 562 }, |
580 | 563 |
581 /** | 564 /** |
582 * @param {!DOMAgent.BoxModel} model | 565 * @param {!DOMAgent.BoxModel} model |
583 * @return {!DOMAgent.BoxModel} | 566 * @return {!DOMAgent.BoxModel} |
584 */ | 567 */ |
585 _scaleModel: function(model) | 568 _scaleModel: function(model) |
586 { | 569 { |
587 var scale = this._canvasElement.offsetWidth / this._viewport.width; | |
588 | |
589 /** | 570 /** |
590 * @param {!DOMAgent.Quad} quad | 571 * @param {!DOMAgent.Quad} quad |
591 * @this {WebInspector.ScreencastView} | 572 * @this {WebInspector.ScreencastView} |
592 */ | 573 */ |
593 function scaleQuad(quad) | 574 function scaleQuad(quad) |
594 { | 575 { |
595 for (var i = 0; i < quad.length; i += 2) { | 576 for (var i = 0; i < quad.length; i += 2) { |
596 quad[i] = (quad[i] - this._viewport.x) * scale; | 577 quad[i] = (quad[i] - this._scrollOffsetX) * this._pageScaleFacto
r * this._screenZoom; |
597 quad[i + 1] = (quad[i + 1] - this._viewport.y) * scale + this._s
creenOffsetTop * this._screenZoom; | 578 quad[i + 1] = ((quad[i + 1] - this._scrollOffsetY) * this._pageS
caleFactor + this._screenOffsetTop) * this._screenZoom; |
598 } | 579 } |
599 } | 580 } |
600 | 581 |
601 scaleQuad.call(this, model.content); | 582 scaleQuad.call(this, model.content); |
602 scaleQuad.call(this, model.padding); | 583 scaleQuad.call(this, model.padding); |
603 scaleQuad.call(this, model.border); | 584 scaleQuad.call(this, model.border); |
604 scaleQuad.call(this, model.margin); | 585 scaleQuad.call(this, model.margin); |
605 return model; | 586 return model; |
606 }, | 587 }, |
607 | 588 |
608 _repaint: function() | 589 _repaint: function() |
609 { | 590 { |
610 var model = this._model; | 591 var model = this._model; |
611 var config = this._config; | 592 var config = this._config; |
612 | 593 |
613 this._canvasElement.width = window.devicePixelRatio * this._canvasElemen
t.offsetWidth; | 594 var canvasWidth = this._canvasElement.getBoundingClientRect().width; |
614 this._canvasElement.height = window.devicePixelRatio * this._canvasEleme
nt.offsetHeight; | 595 var canvasHeight = this._canvasElement.getBoundingClientRect().height; |
| 596 this._canvasElement.width = window.devicePixelRatio * canvasWidth; |
| 597 this._canvasElement.height = window.devicePixelRatio * canvasHeight; |
615 | 598 |
616 this._context.save(); | 599 this._context.save(); |
617 this._context.scale(window.devicePixelRatio, window.devicePixelRatio); | 600 this._context.scale(window.devicePixelRatio, window.devicePixelRatio); |
618 | 601 |
619 // Paint top and bottom gutter. | 602 // Paint top and bottom gutter. |
620 this._context.save(); | 603 this._context.save(); |
621 this._context.fillStyle = this._checkerboardPattern; | 604 this._context.fillStyle = this._checkerboardPattern; |
622 this._context.fillRect(0, 0, this._canvasElement.offsetWidth, this._scre
enOffsetTop * this._screenZoom); | 605 this._context.fillRect(0, 0, canvasWidth, this._screenOffsetTop * this._
screenZoom); |
623 this._context.fillRect(0, this._screenOffsetTop * this._screenZoom + thi
s._imageElement.naturalHeight * this._imageZoom, this._canvasElement.offsetWidth
, this._canvasElement.offsetHeight); | 606 this._context.fillRect(0, this._screenOffsetTop * this._screenZoom + thi
s._imageElement.naturalHeight * this._imageZoom, canvasWidth, canvasHeight); |
624 this._context.restore(); | 607 this._context.restore(); |
625 | 608 |
626 if (model && config) { | 609 if (model && config) { |
627 this._context.save(); | 610 this._context.save(); |
628 const transparentColor = "rgba(0, 0, 0, 0)"; | 611 const transparentColor = "rgba(0, 0, 0, 0)"; |
629 var hasContent = model.content && config.contentColor !== transparen
tColor; | 612 var hasContent = model.content && config.contentColor !== transparen
tColor; |
630 var hasPadding = model.padding && config.paddingColor !== transparen
tColor; | 613 var hasPadding = model.padding && config.paddingColor !== transparen
tColor; |
631 var hasBorder = model.border && config.borderColor !== transparentCo
lor; | 614 var hasBorder = model.border && config.borderColor !== transparentCo
lor; |
632 var hasMargin = model.margin && config.marginColor !== transparentCo
lor; | 615 var hasMargin = model.margin && config.marginColor !== transparentCo
lor; |
633 | 616 |
(...skipping 13 matching lines...) Expand all Loading... |
647 if (hasContent) | 630 if (hasContent) |
648 this._drawOutlinedQuad(model.content, config.contentColor); | 631 this._drawOutlinedQuad(model.content, config.contentColor); |
649 this._context.restore(); | 632 this._context.restore(); |
650 | 633 |
651 this._drawElementTitle(); | 634 this._drawElementTitle(); |
652 | 635 |
653 this._context.globalCompositeOperation = "destination-over"; | 636 this._context.globalCompositeOperation = "destination-over"; |
654 } | 637 } |
655 | 638 |
656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t
his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE
lement.naturalHeight * this._imageZoom); | 639 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.restore(); |
657 | 641 |
658 this._context.restore(); | |
659 }, | 642 }, |
660 | 643 |
661 | 644 |
662 /** | 645 /** |
663 * @param {!DOMAgent.Quad} quad1 | 646 * @param {!DOMAgent.Quad} quad1 |
664 * @param {!DOMAgent.Quad} quad2 | 647 * @param {!DOMAgent.Quad} quad2 |
665 * @return {boolean} | 648 * @return {boolean} |
666 */ | 649 */ |
667 _quadsAreEqual: function(quad1, quad2) | 650 _quadsAreEqual: function(quad1, quad2) |
668 { | 651 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 this._context.fillStyle = "red"; | 711 this._context.fillStyle = "red"; |
729 this._quadToPath(clipQuad).fill(); | 712 this._quadToPath(clipQuad).fill(); |
730 this._context.restore(); | 713 this._context.restore(); |
731 }, | 714 }, |
732 | 715 |
733 _drawElementTitle: function() | 716 _drawElementTitle: function() |
734 { | 717 { |
735 if (!this._node) | 718 if (!this._node) |
736 return; | 719 return; |
737 | 720 |
738 var canvasWidth = this._canvasElement.offsetWidth; | 721 var canvasWidth = this._canvasElement.getBoundingClientRect().width; |
739 var canvasHeight = this._canvasElement.offsetHeight; | 722 var canvasHeight = this._canvasElement.getBoundingClientRect().height; |
740 | 723 |
741 var lowerCaseName = this._node.localName() || this._node.nodeName().toLo
werCase(); | 724 var lowerCaseName = this._node.localName() || this._node.nodeName().toLo
werCase(); |
742 this._tagNameElement.textContent = lowerCaseName; | 725 this._tagNameElement.textContent = lowerCaseName; |
743 this._nodeIdElement.textContent = this._node.getAttribute("id") ? "#" +
this._node.getAttribute("id") : ""; | 726 this._nodeIdElement.textContent = this._node.getAttribute("id") ? "#" +
this._node.getAttribute("id") : ""; |
744 this._nodeIdElement.textContent = this._node.getAttribute("id") ? "#" +
this._node.getAttribute("id") : ""; | 727 this._nodeIdElement.textContent = this._node.getAttribute("id") ? "#" +
this._node.getAttribute("id") : ""; |
745 var className = this._node.getAttribute("class"); | 728 var className = this._node.getAttribute("class"); |
746 if (className && className.length > 50) | 729 if (className && className.length > 50) |
747 className = className.substring(0, 50) + "\u2026"; | 730 className = className.substring(0, 50) + "\u2026"; |
748 this._classNameElement.textContent = className || ""; | 731 this._classNameElement.textContent = className || ""; |
749 this._nodeWidthElement.textContent = this._model.width; | 732 this._nodeWidthElement.textContent = this._model.width; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 this._titleElement.style.left = (boxX + 3) + "px"; | 793 this._titleElement.style.left = (boxX + 3) + "px"; |
811 }, | 794 }, |
812 | 795 |
813 /** | 796 /** |
814 * @return {!{width: number, height: number}} | 797 * @return {!{width: number, height: number}} |
815 */ | 798 */ |
816 _viewportDimensions: function() | 799 _viewportDimensions: function() |
817 { | 800 { |
818 const gutterSize = 30; | 801 const gutterSize = 30; |
819 const bordersSize = WebInspector.ScreencastView._bordersSize; | 802 const bordersSize = WebInspector.ScreencastView._bordersSize; |
820 return { width: this.element.offsetWidth - bordersSize - gutterSize, | 803 var width = this.element.offsetWidth - bordersSize - gutterSize; |
821 height: this.element.offsetHeight - bordersSize - gutterSize -
WebInspector.ScreencastView._navBarHeight}; | 804 var height = this.element.offsetHeight - bordersSize - gutterSize - WebI
nspector.ScreencastView._navBarHeight; |
| 805 return { width: width, height: height }; |
822 }, | 806 }, |
823 | 807 |
824 /** | 808 /** |
825 * @param {boolean} enabled | 809 * @param {boolean} enabled |
826 * @param {boolean} inspectUAShadowDOM | 810 * @param {boolean} inspectUAShadowDOM |
827 * @param {!DOMAgent.HighlightConfig} config | 811 * @param {!DOMAgent.HighlightConfig} config |
828 * @param {function(?Protocol.Error)=} callback | 812 * @param {function(?Protocol.Error)=} callback |
829 */ | 813 */ |
830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac
k) | 814 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac
k) |
831 { | 815 { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 return; | 998 return; |
1015 this._maxDisplayedProgress = progress; | 999 this._maxDisplayedProgress = progress; |
1016 this._displayProgress(progress); | 1000 this._displayProgress(progress); |
1017 }, | 1001 }, |
1018 | 1002 |
1019 _displayProgress: function(progress) | 1003 _displayProgress: function(progress) |
1020 { | 1004 { |
1021 this._element.style.width = (100 * progress) + "%"; | 1005 this._element.style.width = (100 * progress) + "%"; |
1022 } | 1006 } |
1023 }; | 1007 }; |
OLD | NEW |