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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js

Issue 1928453002: DevTools: account for client devicePixelRatio while capturing screenshots. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 */ 8 */
9 WebInspector.DeviceModeView = function() 9 WebInspector.DeviceModeView = function()
10 { 10 {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 */ 389 */
390 function screenshotCaptured(error, content) 390 function screenshotCaptured(error, content)
391 { 391 {
392 if (error) 392 if (error)
393 return; 393 return;
394 394
395 // Create a canvas to splice the images together. 395 // Create a canvas to splice the images together.
396 var canvas = createElement("canvas"); 396 var canvas = createElement("canvas");
397 var ctx = canvas.getContext("2d"); 397 var ctx = canvas.getContext("2d");
398 var screenRect = this._model.screenRect(); 398 var screenRect = this._model.screenRect();
399 canvas.width = screenRect.width; 399 var dpr = window.devicePixelRatio;
400 canvas.height = screenRect.height; 400 canvas.width = screenRect.width * dpr;
dgozman 2016/04/27 18:34:23 I think we'd better get scale from the pageImage.n
pfeldman 2016/04/27 21:11:47 I thought about it, but it produces wrong results
401 canvas.height = screenRect.height * dpr;
401 // Add any available screen images. 402 // Add any available screen images.
402 if (this._model.screenImage()) { 403 if (this._model.screenImage()) {
403 var screenImage = new Image(); 404 var screenImage = new Image();
404 screenImage.crossOrigin = "Anonymous"; 405 screenImage.crossOrigin = "Anonymous";
405 screenImage.srcset = this._model.screenImage(); 406 screenImage.srcset = this._model.screenImage();
406 ctx.drawImage(screenImage, 0, 0, screenRect.width, screenRect.he ight); 407 screenImage.onload = onImageLoad.bind(this);
408 screenImage.onerror = paintScreenshot.bind(this);
409 } else {
410 paintScreenshot.call(this);
407 } 411 }
408 var pageImage = new Image(); 412
409 pageImage.src = "data:image/png;base64," + content; 413 /**
410 var visiblePageRect = this._model.visiblePageRect(); 414 * @this {WebInspector.DeviceModeView}
411 ctx.drawImage(pageImage, visiblePageRect.left, visiblePageRect.top, visiblePageRect.width, visiblePageRect.height); 415 */
412 var mainFrame = mainTarget.resourceTreeModel.mainFrame; 416 function onImageLoad()
413 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFragment () : ""; 417 {
414 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) 418 ctx.drawImage(screenImage, 0, 0, screenRect.width * dpr, screenR ect.height * dpr);
415 fileName += WebInspector.UIString("(%s)", this._model.device().t itle); 419 paintScreenshot.call(this);
416 // Trigger download. 420 }
417 var link = createElement("a"); 421
418 link.download = fileName + ".png"; 422 /**
419 link.href = canvas.toDataURL("image/png"); 423 * @this {WebInspector.DeviceModeView}
420 link.click(); 424 */
425 function paintScreenshot()
426 {
427 var pageImage = new Image();
428 pageImage.src = "data:image/png;base64," + content;
429 var visiblePageRect = this._model.visiblePageRect();
dgozman 2016/04/27 18:34:23 .scale(dpr)
pfeldman 2016/04/27 21:11:47 Done.
430 ctx.drawImage(pageImage,
431 visiblePageRect.left * dpr,
432 visiblePageRect.top * dpr,
433 visiblePageRect.width * dpr,
434 visiblePageRect.height * dpr);
435 var mainFrame = mainTarget.resourceTreeModel.mainFrame;
436 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : "";
437 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice)
438 fileName += WebInspector.UIString("(%s)", this._model.device ().title);
439 // Trigger download.
440 var link = createElement("a");
441 link.download = fileName + ".png";
442 link.href = canvas.toDataURL("image/png");
443 link.click();
444 }
421 } 445 }
422 }, 446 },
423 447
424 __proto__: WebInspector.VBox.prototype 448 __proto__: WebInspector.VBox.prototype
425 } 449 }
426 450
427 /** 451 /**
428 * @constructor 452 * @constructor
429 * @extends {WebInspector.VBox} 453 * @extends {WebInspector.VBox}
430 * @param {boolean} horizontal 454 * @param {boolean} horizontal
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 /** 548 /**
525 * @param {number} size 549 * @param {number} size
526 */ 550 */
527 _onMarkerClick: function(size) 551 _onMarkerClick: function(size)
528 { 552 {
529 this._applyCallback.call(null, size); 553 this._applyCallback.call(null, size);
530 }, 554 },
531 555
532 __proto__: WebInspector.VBox.prototype 556 __proto__: WebInspector.VBox.prototype
533 } 557 }
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