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

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

Issue 1936243002: DevTools: account for client devicePixelRatio while capturing screenshots. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 */ 365 */
366 function screenshotCaptured(error, content) 366 function screenshotCaptured(error, content)
367 { 367 {
368 if (error) 368 if (error)
369 return; 369 return;
370 370
371 // Create a canvas to splice the images together. 371 // Create a canvas to splice the images together.
372 var canvas = createElement("canvas"); 372 var canvas = createElement("canvas");
373 var ctx = canvas.getContext("2d"); 373 var ctx = canvas.getContext("2d");
374 var screenRect = this._model.screenRect(); 374 var screenRect = this._model.screenRect();
375 canvas.width = screenRect.width; 375 var dpr = window.devicePixelRatio;
376 canvas.height = screenRect.height; 376 canvas.width = screenRect.width * dpr;
377 canvas.height = screenRect.height * dpr;
377 // Add any available screen images. 378 // Add any available screen images.
378 if (this._model.screenImage()) { 379 if (this._model.screenImage()) {
379 var screenImage = new Image(); 380 var screenImage = new Image();
380 screenImage.crossOrigin = "Anonymous"; 381 screenImage.crossOrigin = "Anonymous";
381 screenImage.srcset = this._model.screenImage(); 382 screenImage.srcset = this._model.screenImage();
382 ctx.drawImage(screenImage, 0, 0, screenRect.width, screenRect.he ight); 383 screenImage.onload = onImageLoad.bind(this);
384 screenImage.onerror = paintScreenshot.bind(this);
385 } else {
386 paintScreenshot.call(this);
383 } 387 }
384 var pageImage = new Image(); 388
385 pageImage.src = "data:image/png;base64," + content; 389 /**
386 var visiblePageRect = this._model.visiblePageRect(); 390 * @this {WebInspector.DeviceModeView}
387 ctx.drawImage(pageImage, visiblePageRect.left, visiblePageRect.top, visiblePageRect.width, visiblePageRect.height); 391 */
388 var mainFrame = mainTarget.resourceTreeModel.mainFrame; 392 function onImageLoad()
389 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFragment () : ""; 393 {
390 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) 394 ctx.drawImage(screenImage, 0, 0, screenRect.width * dpr, screenR ect.height * dpr);
391 fileName += WebInspector.UIString("(%s)", this._model.device().t itle); 395 paintScreenshot.call(this);
392 // Trigger download. 396 }
393 var link = createElement("a"); 397
394 link.download = fileName + ".png"; 398 /**
395 link.href = canvas.toDataURL("image/png"); 399 * @this {WebInspector.DeviceModeView}
396 link.click(); 400 */
401 function paintScreenshot()
402 {
403 var pageImage = new Image();
404 pageImage.src = "data:image/png;base64," + content;
405 var visiblePageRect = this._model.visiblePageRect().scale(dpr);
406 ctx.drawImage(pageImage,
407 visiblePageRect.left,
408 visiblePageRect.top,
409 visiblePageRect.width,
410 visiblePageRect.height);
411 var mainFrame = mainTarget.resourceTreeModel.mainFrame;
412 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : "";
413 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice)
414 fileName += WebInspector.UIString("(%s)", this._model.device ().title);
415 // Trigger download.
416 var link = createElement("a");
417 link.download = fileName + ".png";
418 link.href = canvas.toDataURL("image/png");
419 link.click();
420 }
397 } 421 }
398 }, 422 },
399 423
400 __proto__: WebInspector.VBox.prototype 424 __proto__: WebInspector.VBox.prototype
401 } 425 }
402 426
403 /** 427 /**
404 * @constructor 428 * @constructor
405 * @extends {WebInspector.VBox} 429 * @extends {WebInspector.VBox}
406 * @param {boolean} horizontal 430 * @param {boolean} horizontal
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 /** 524 /**
501 * @param {number} size 525 * @param {number} size
502 */ 526 */
503 _onMarkerClick: function(size) 527 _onMarkerClick: function(size)
504 { 528 {
505 this._applyCallback.call(null, size); 529 this._applyCallback.call(null, size);
506 }, 530 },
507 531
508 __proto__: WebInspector.VBox.prototype 532 __proto__: WebInspector.VBox.prototype
509 } 533 }
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