Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: Source/devtools/front_end/ScreencastView.js

Issue 347143002: DevTools: Screencast view scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed comment Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 offsetTop = metadata.offsetTop || 0;
167 var offsetBottom = metadata.offsetBottom || 0; 161 var offsetBottom = metadata.offsetBottom || 0;
168 162
169 var screenWidthDIP = this._viewport.width * this._pageScaleFactor; 163 // Physical device size.
170 var screenHeightDIP = this._viewport.height * this._pageScaleFactor + of fsetTop + offsetBottom; 164 var screenWidthDIP = Math.round(this._viewport.width * this._pageScaleFa ctor);
pfeldman 2014/06/23 12:43:12 Can we send screen size DIP from the backend inste
vkuzkokov 2014/06/23 16:54:53 Backend patch: https://codereview.chromium.org/351
165 var screenHeightDIP = Math.round(this._viewport.height * this._pageScale Factor + offsetTop + offsetBottom);
166
167 this._screenZoom = this._imageElement.naturalWidth / screenWidthDIP;
171 this._screenOffsetTop = offsetTop; 168 this._screenOffsetTop = offsetTop;
172 this._resizeViewport(screenWidthDIP, screenHeightDIP);
173 169
174 this._imageZoom = this._imageElement.naturalWidth ? this._canvasElement. offsetWidth / this._imageElement.naturalWidth : 1; 170 var dimensions = this._viewportDimensions();
171 this._imageZoom = Math.min(dimensions.width / screenWidthDIP, dimensions .height / screenHeightDIP) * window.devicePixelRatio / this._screenZoom;
pfeldman 2014/06/23 12:43:12 This value has nothing to do with the imageZoom, r
vkuzkokov 2014/06/23 16:54:53 Multiplication by _imageZoom translates pixels of
172 this._viewportElement.classList.remove("hidden");
173 var bordersSize = WebInspector.ScreencastView._bordersSize;
174 if (this._imageZoom < 1.01) {
175 this._imageZoom = 1;
176 this._viewportElement.style.width = this._imageElement.naturalWidth / window.devicePixelRatio + bordersSize + "px";
177 this._viewportElement.style.height = (this._imageElement.naturalHeig ht + Math.floor((offsetTop + offsetBottom) * this._screenZoom)) / window.deviceP ixelRatio + bordersSize + "px";
178 } else {
179 this._screenZoom *= this._imageZoom;
180 this._viewportElement.style.width = screenWidthDIP / window.devicePi xelRatio * this._screenZoom + bordersSize + "px";
pfeldman 2014/06/23 12:43:12 This is again confusing - why would we divide scre
vkuzkokov 2014/06/23 16:54:53 Perhaps, the ordering was unfortunate. screenWidth
181 this._viewportElement.style.height = screenHeightDIP / window.device PixelRatio * this._screenZoom + bordersSize + "px";
182 }
183
175 this.highlightDOMNode(this._highlightNode, this._highlightConfig); 184 this.highlightDOMNode(this._highlightNode, this._highlightConfig);
176 }, 185 },
177 186
178 _isGlassPaneActive: function() 187 _isGlassPaneActive: function()
179 { 188 {
180 return !this._glassPaneElement.classList.contains("hidden"); 189 return !this._glassPaneElement.classList.contains("hidden");
181 }, 190 },
182 191
183 /** 192 /**
184 * @param {!WebInspector.Event} event 193 * @param {!WebInspector.Event} event
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 this._glassPaneElement.classList.remove("hidden"); 236 this._glassPaneElement.classList.remove("hidden");
228 } else if (this._profilerActive) { 237 } else if (this._profilerActive) {
229 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active"); 238 this._glassPaneElement.textContent = WebInspector.UIString("CPU prof iler is active");
230 this._glassPaneElement.classList.remove("hidden"); 239 this._glassPaneElement.classList.remove("hidden");
231 } else { 240 } else {
232 this._glassPaneElement.classList.add("hidden"); 241 this._glassPaneElement.classList.add("hidden");
233 } 242 }
234 }, 243 },
235 244
236 /** 245 /**
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 246 * @param {?Event} event
253 */ 247 */
254 _handleMouseEvent: function(event) 248 _handleMouseEvent: function(event)
255 { 249 {
256 if (this._isGlassPaneActive()) { 250 if (this._isGlassPaneActive()) {
257 event.consume(); 251 event.consume();
258 return; 252 return;
259 } 253 }
260 254
261 if (!this._viewport) 255 if (!this._viewport)
(...skipping 12 matching lines...) Expand all
274 268
275 /** 269 /**
276 * @param {?WebInspector.DOMNode} node 270 * @param {?WebInspector.DOMNode} node
277 * @this {WebInspector.ScreencastView} 271 * @this {WebInspector.ScreencastView}
278 */ 272 */
279 function callback(node) 273 function callback(node)
280 { 274 {
281 if (!node) 275 if (!node)
282 return; 276 return;
283 if (event.type === "mousemove") 277 if (event.type === "mousemove")
284 node.highlight(this._inspectModeConfig); 278 this.highlightDOMNode(node, this._inspectModeConfig);
pfeldman 2014/06/23 12:43:12 I fixed it in a separate patch.
vkuzkokov 2014/06/23 16:54:53 Removed fix from this patch
285 else if (event.type === "click") 279 else if (event.type === "click")
286 node.reveal(); 280 node.reveal();
287 } 281 }
288 }, 282 },
289 283
290 /** 284 /**
291 * @param {?Event} event 285 * @param {?Event} event
292 */ 286 */
293 _handleKeyEvent: function(event) 287 _handleKeyEvent: function(event)
294 { 288 {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 555
562 this._node = node; 556 this._node = node;
563 node.boxModel(callback.bind(this)); 557 node.boxModel(callback.bind(this));
564 558
565 /** 559 /**
566 * @param {?DOMAgent.BoxModel} model 560 * @param {?DOMAgent.BoxModel} model
567 * @this {WebInspector.ScreencastView} 561 * @this {WebInspector.ScreencastView}
568 */ 562 */
569 function callback(model) 563 function callback(model)
570 { 564 {
571 if (!model) { 565 if (!model || !this._viewport) {
572 this._repaint(); 566 this._repaint();
573 return; 567 return;
574 } 568 }
575 this._model = this._scaleModel(model); 569 this._model = this._scaleModel(model);
576 this._config = config; 570 this._config = config;
577 this._repaint(); 571 this._repaint();
578 } 572 }
579 }, 573 },
580 574
581 /** 575 /**
(...skipping 30 matching lines...) Expand all
612 606
613 this._canvasElement.width = window.devicePixelRatio * this._canvasElemen t.offsetWidth; 607 this._canvasElement.width = window.devicePixelRatio * this._canvasElemen t.offsetWidth;
614 this._canvasElement.height = window.devicePixelRatio * this._canvasEleme nt.offsetHeight; 608 this._canvasElement.height = window.devicePixelRatio * this._canvasEleme nt.offsetHeight;
615 609
616 this._context.save(); 610 this._context.save();
617 this._context.scale(window.devicePixelRatio, window.devicePixelRatio); 611 this._context.scale(window.devicePixelRatio, window.devicePixelRatio);
618 612
619 // Paint top and bottom gutter. 613 // Paint top and bottom gutter.
620 this._context.save(); 614 this._context.save();
621 this._context.fillStyle = this._checkerboardPattern; 615 this._context.fillStyle = this._checkerboardPattern;
622 this._context.fillRect(0, 0, this._canvasElement.offsetWidth, this._scre enOffsetTop * this._screenZoom); 616 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); 617 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(); 618 this._context.restore();
625 619
626 if (model && config) { 620 if (model && config) {
627 this._context.save(); 621 this._context.save();
628 const transparentColor = "rgba(0, 0, 0, 0)"; 622 const transparentColor = "rgba(0, 0, 0, 0)";
629 var hasContent = model.content && config.contentColor !== transparen tColor; 623 var hasContent = model.content && config.contentColor !== transparen tColor;
630 var hasPadding = model.padding && config.paddingColor !== transparen tColor; 624 var hasPadding = model.padding && config.paddingColor !== transparen tColor;
631 var hasBorder = model.border && config.borderColor !== transparentCo lor; 625 var hasBorder = model.border && config.borderColor !== transparentCo lor;
632 var hasMargin = model.margin && config.marginColor !== transparentCo lor; 626 var hasMargin = model.margin && config.marginColor !== transparentCo lor;
633 627
(...skipping 12 matching lines...) Expand all
646 } 640 }
647 if (hasContent) 641 if (hasContent)
648 this._drawOutlinedQuad(model.content, config.contentColor); 642 this._drawOutlinedQuad(model.content, config.contentColor);
649 this._context.restore(); 643 this._context.restore();
650 644
651 this._drawElementTitle(); 645 this._drawElementTitle();
652 646
653 this._context.globalCompositeOperation = "destination-over"; 647 this._context.globalCompositeOperation = "destination-over";
654 } 648 }
655 649
650 this._context.scale(1 / window.devicePixelRatio, 1 / window.devicePixelR atio);
656 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom); 651 this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * t his._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageE lement.naturalHeight * this._imageZoom);
657 652
658 this._context.restore(); 653 this._context.restore();
659 }, 654 },
660 655
661 656
662 /** 657 /**
663 * @param {!DOMAgent.Quad} quad1 658 * @param {!DOMAgent.Quad} quad1
664 * @param {!DOMAgent.Quad} quad2 659 * @param {!DOMAgent.Quad} quad2
665 * @return {boolean} 660 * @return {boolean}
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 this._titleElement.style.left = (boxX + 3) + "px"; 805 this._titleElement.style.left = (boxX + 3) + "px";
811 }, 806 },
812 807
813 /** 808 /**
814 * @return {!{width: number, height: number}} 809 * @return {!{width: number, height: number}}
815 */ 810 */
816 _viewportDimensions: function() 811 _viewportDimensions: function()
817 { 812 {
818 const gutterSize = 30; 813 const gutterSize = 30;
819 const bordersSize = WebInspector.ScreencastView._bordersSize; 814 const bordersSize = WebInspector.ScreencastView._bordersSize;
820 return { width: this.element.offsetWidth - bordersSize - gutterSize, 815 var width = Math.floor(this.element.offsetWidth - bordersSize - gutterSi ze);
821 height: this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight}; 816 var height = Math.floor(this.element.offsetHeight - bordersSize - gutter Size - WebInspector.ScreencastView._navBarHeight);
817 return { width: width, height: height };
822 }, 818 },
823 819
824 /** 820 /**
825 * @param {boolean} enabled 821 * @param {boolean} enabled
826 * @param {boolean} inspectUAShadowDOM 822 * @param {boolean} inspectUAShadowDOM
827 * @param {!DOMAgent.HighlightConfig} config 823 * @param {!DOMAgent.HighlightConfig} config
828 * @param {function(?Protocol.Error)=} callback 824 * @param {function(?Protocol.Error)=} callback
829 */ 825 */
830 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k) 826 setInspectModeEnabled: function(enabled, inspectUAShadowDOM, config, callbac k)
831 { 827 {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 return; 1010 return;
1015 this._maxDisplayedProgress = progress; 1011 this._maxDisplayedProgress = progress;
1016 this._displayProgress(progress); 1012 this._displayProgress(progress);
1017 }, 1013 },
1018 1014
1019 _displayProgress: function(progress) 1015 _displayProgress: function(progress)
1020 { 1016 {
1021 this._element.style.width = (100 * progress) + "%"; 1017 this._element.style.width = (100 * progress) + "%";
1022 } 1018 }
1023 }; 1019 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698