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

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

Issue 2612913002: DevTools: Add feature to capture full-height screenshots (Closed)
Patch Set: More readable Created 3 years, 11 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
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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 Emulation.DeviceModeView = class extends UI.VBox { 7 Emulation.DeviceModeView = class extends UI.VBox {
8 constructor() { 8 constructor() {
9 super(true); 9 super(true);
10 this.setMinimumSize(150, 150); 10 this.setMinimumSize(150, 150);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 fileName += Common.UIString('(%s)', this._model.device().title); 463 fileName += Common.UIString('(%s)', this._model.device().title);
464 // Trigger download. 464 // Trigger download.
465 var link = createElement('a'); 465 var link = createElement('a');
466 link.download = fileName + '.png'; 466 link.download = fileName + '.png';
467 link.href = canvas.toDataURL('image/png'); 467 link.href = canvas.toDataURL('image/png');
468 link.click(); 468 link.click();
469 }; 469 };
470 } 470 }
471 } 471 }
472 } 472 }
473
474 captureFullHeightScreenshot() {
475 var mainTarget = SDK.targetManager.mainTarget();
476 if (!mainTarget)
477 return;
478 SDK.DOMModel.muteHighlight();
479 this._model.captureFullHeightScreenshot(screenshotCaptured.bind(this));
480
481 /**
482 * @param {?Protocol.Error} error
483 * @param {string} content
484 * @this {Emulation.DeviceModeView}
485 */
486 function screenshotCaptured(error, content) {
487 SDK.DOMModel.unmuteHighlight();
488 if (error) {
489 console.error(error);
490 return;
491 }
492 var canvas = createElement('canvas');
493 var pageImage = new Image();
494 pageImage.src = 'data:image/png;base64,' + content;
495 pageImage.onload = () => {
496 var ctx = canvas.getContext('2d');
497 ctx.imageSmoothingEnabled = false;
498 canvas.width = pageImage.width;
499 canvas.height = pageImage.height;
500 ctx.drawImage(pageImage, 0, 0);
501 var url = mainTarget && mainTarget.inspectedURL();
502 var fileName = url ? url.trimURL().removeURLFragment() : '';
503 if (this._model.type() === Emulation.DeviceModeModel.Type.Device)
504 fileName += Common.UIString('(%s)', this._model.device().title);
505 var link = createElement('a');
506 link.download = fileName + '.png';
507 canvas.toBlob(function(blob) {
508 link.href = URL.createObjectURL(blob);
509 link.click();
510 });
511 }
512 }
513 }
473 }; 514 };
474 515
475 /** 516 /**
476 * @unrestricted 517 * @unrestricted
477 */ 518 */
478 Emulation.DeviceModeView.Ruler = class extends UI.VBox { 519 Emulation.DeviceModeView.Ruler = class extends UI.VBox {
479 /** 520 /**
480 * @param {boolean} horizontal 521 * @param {boolean} horizontal
481 * @param {function(number)} applyCallback 522 * @param {function(number)} applyCallback
482 */ 523 */
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 return Promise.resolve(); 606 return Promise.resolve();
566 } 607 }
567 608
568 /** 609 /**
569 * @param {number} size 610 * @param {number} size
570 */ 611 */
571 _onMarkerClick(size) { 612 _onMarkerClick(size) {
572 this._applyCallback.call(null, size); 613 this._applyCallback.call(null, size);
573 } 614 }
574 }; 615 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698