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

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: 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 var visiblePageRect = this._model.visiblePageRect();
480 var pageWidth = Math.floor(visiblePageRect.width);
dgozman 2017/01/11 01:19:25 visiblePageRect is cropped by available space. Thi
ahmetemirercin 2017/01/11 19:25:18 After updating 'setVisibleSize' to handle width&he
481
482 var executionContext = UI.context.flavor(SDK.ExecutionContext);
dgozman 2017/01/11 01:19:25 Should instead use mainTarget.runtimeModel.default
ahmetemirercin 2017/01/11 19:25:17 Done.
483 executionContext.evaluate(
484 'document.scrollingElement.scrollHeight', '', false, true, true, false, false, evaluated.bind(this));
485
486 function evaluated(result) {
dgozman 2017/01/11 01:19:25 Annotate with JSDoc please.
ahmetemirercin 2017/01/11 19:25:17 Done.
487 var scrollHeight = result.value;
488 mainTarget.pageAgent().getLayoutMetrics((err, layoutViewport, visualViewpo rt) => {
dgozman 2017/01/11 01:19:24 Actually, we can expose content size through getLa
dgozman 2017/01/11 01:19:25 Let's put this method (which calls into agent) int
ahmetemirercin 2017/01/11 19:25:18 Checked that exception about responsive mode and f
489 var promises = [];
490 var scaledScrollHeight = Math.floor(scrollHeight * visualViewport.scale * this._model.scale());
491 promises.push(mainTarget.emulationAgent().forceViewport(0, 0, visualView port.scale));
492 promises.push(mainTarget.emulationAgent().setDeviceMetricsOverride(
493 0, 0, 0, this._model._device.mobile(), false, this._model.scale()));
dgozman 2017/01/11 01:19:25 We should use current device scale factor applied
ahmetemirercin 2017/01/11 19:25:18 Done.
494 promises.push(mainTarget.emulationAgent().setVisibleSize(pageWidth, scal edScrollHeight));
495 Promise.all(promises).then(() => {
496 mainTarget.pageAgent().captureScreenshot(screenshotCaptured.bind(this) );
497 })
498 })
499 }
500
501 /**
502 * @param {?Protocol.Error} error
503 * @param {string} content
504 * @this {Emulation.DeviceModeView}
505 */
506 function screenshotCaptured(error, content) {
507 mainTarget.emulationAgent().resetViewport();
508 mainTarget.emulationAgent().setVisibleSize(Math.floor(visiblePageRect.widt h), Math.floor(visiblePageRect.height));
dgozman 2017/01/11 01:19:25 We should instead pass (0, 0) and add support on b
ahmetemirercin 2017/01/11 19:25:18 I think we can reset visible size from DeviceModeM
509 SDK.DOMModel.unmuteHighlight();
510 UI.inspectorView.restore();
dgozman 2017/01/11 01:19:25 Don't need this.
ahmetemirercin 2017/01/11 19:25:18 Done.
511 if (error) {
512 console.error(error);
513 return;
514 }
515
516 var canvas = createElement('canvas');
517 var pageImage = new Image();
518 pageImage.src = 'data:image/png;base64,' + content;
519 pageImage.onload = () => {
520 var ctx = canvas.getContext('2d');
521 ctx.imageSmoothingEnabled = false;
522 canvas.width = pageImage.width;
523 canvas.height = pageImage.height;
524 ctx.drawImage(pageImage, 0, 0, pageImage.width, pageImage.height);
525 var url = mainTarget && mainTarget.inspectedURL();
526 var fileName = url ? url.trimURL().removeURLFragment() : '';
527 if (this._model.type() === Emulation.DeviceModeModel.Type.Device)
528 fileName += Common.UIString('(%s)', this._model.device().title);
529 var link = createElement('a');
530 link.download = fileName + '.png';
531 canvas.toBlob(function(blob) {
532 link.href = URL.createObjectURL(blob);
dgozman 2017/01/11 01:19:25 Instead of drawing to canvas, can we just do the f
ahmetemirercin 2017/01/11 19:25:18 I tried this and because of data url size limits (
dgozman 2017/01/12 21:49:35 Oh, I see. That's unfortunate... Thanks for explan
533 link.click();
534 });
535 }
536 }
537 }
473 }; 538 };
474 539
475 /** 540 /**
476 * @unrestricted 541 * @unrestricted
477 */ 542 */
478 Emulation.DeviceModeView.Ruler = class extends UI.VBox { 543 Emulation.DeviceModeView.Ruler = class extends UI.VBox {
479 /** 544 /**
480 * @param {boolean} horizontal 545 * @param {boolean} horizontal
481 * @param {function(number)} applyCallback 546 * @param {function(number)} applyCallback
482 */ 547 */
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 return Promise.resolve(); 630 return Promise.resolve();
566 } 631 }
567 632
568 /** 633 /**
569 * @param {number} size 634 * @param {number} size
570 */ 635 */
571 _onMarkerClick(size) { 636 _onMarkerClick(size) {
572 this._applyCallback.call(null, size); 637 this._applyCallback.call(null, size);
573 } 638 }
574 }; 639 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698