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

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: DevTools: Add feature to capture full-height screenshots 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
480 var executionContext = mainTarget.runtimeModel.defaultExecutionContext();
481 executionContext.evaluate(
482 'document.scrollingElement.scrollHeight', '', false, true, true, false, false, evaluated.bind(this));
483
484 /**
485 * @param {?SDK.RemoteObject} result
486 * @this {Emulation.DeviceModeView}
487 */
488 function evaluated(result) {
489 var scrollHeight = result.value;
dgozman 2017/01/12 21:49:36 I still think we should expose this through getLay
ahmetemirercin 2017/01/13 01:49:23 Done.
490 mainTarget.pageAgent().getLayoutMetrics((err, layoutViewport, visualViewpo rt) => {
dgozman 2017/01/12 21:49:35 I still think this should be in DeviceModeModel. V
ahmetemirercin 2017/01/13 01:49:23 Done.
491 var promises = [];
492 var scaledScrollHeight = Math.floor(scrollHeight * visualViewport.scale * this._model.scale());
493 promises.push(mainTarget.emulationAgent().forceViewport(0, 0, visualView port.scale));
494 promises.push(mainTarget.emulationAgent().setDeviceMetricsOverride(
495 0, 0, this._model.appliedDeviceScaleFactor(), this._model.isMobile() , false, this._model.scale()));
496 promises.push(mainTarget.emulationAgent().setVisibleSize(0, scaledScroll Height));
497 Promise.all(promises).then(() => {
498 mainTarget.pageAgent().captureScreenshot(screenshotCaptured.bind(this) );
499 })
500 })
501 }
502
503 /**
504 * @param {?Protocol.Error} error
505 * @param {string} content
506 * @this {Emulation.DeviceModeView}
507 */
508 function screenshotCaptured(error, content) {
509 mainTarget.emulationAgent().resetViewport();
ahmetemirercin 2017/01/13 01:49:23 This is also done according to comment above.
510 this._model.resetVisibleSize();
511 SDK.DOMModel.unmuteHighlight();
512 if (error) {
513 console.error(error);
514 return;
515 }
516
517 var canvas = createElement('canvas');
518 var pageImage = new Image();
519 pageImage.src = 'data:image/png;base64,' + content;
520 pageImage.onload = () => {
521 var ctx = canvas.getContext('2d');
522 ctx.imageSmoothingEnabled = false;
523 canvas.width = pageImage.width;
524 canvas.height = pageImage.height;
525 ctx.drawImage(pageImage, 0, 0, pageImage.width, pageImage.height);
526 var url = mainTarget && mainTarget.inspectedURL();
527 var fileName = url ? url.trimURL().removeURLFragment() : '';
528 if (this._model.type() === Emulation.DeviceModeModel.Type.Device)
529 fileName += Common.UIString('(%s)', this._model.device().title);
530 var link = createElement('a');
531 link.download = fileName + '.png';
532 canvas.toBlob(function(blob) {
533 link.href = URL.createObjectURL(blob);
534 link.click();
535 });
536 }
537 }
538 }
473 }; 539 };
474 540
475 /** 541 /**
476 * @unrestricted 542 * @unrestricted
477 */ 543 */
478 Emulation.DeviceModeView.Ruler = class extends UI.VBox { 544 Emulation.DeviceModeView.Ruler = class extends UI.VBox {
479 /** 545 /**
480 * @param {boolean} horizontal 546 * @param {boolean} horizontal
481 * @param {function(number)} applyCallback 547 * @param {function(number)} applyCallback
482 */ 548 */
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 return Promise.resolve(); 631 return Promise.resolve();
566 } 632 }
567 633
568 /** 634 /**
569 * @param {number} size 635 * @param {number} size
570 */ 636 */
571 _onMarkerClick(size) { 637 _onMarkerClick(size) {
572 this._applyCallback.call(null, size); 638 this._applyCallback.call(null, size);
573 } 639 }
574 }; 640 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698