Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 this._model.prepareForFullHeightScreenshot().then(() => { | |
| 481 mainTarget.pageAgent().captureScreenshot(screenshotCaptured.bind(this)); | |
|
dgozman
2017/01/13 23:38:48
Put this into model as well, and let it resetViewp
ahmetemirercin
2017/01/16 17:52:01
Done.
| |
| 482 }); | |
| 483 | |
| 484 /** | |
| 485 * @param {?Protocol.Error} error | |
| 486 * @param {string} content | |
| 487 * @this {Emulation.DeviceModeView} | |
| 488 */ | |
| 489 function screenshotCaptured(error, content) { | |
| 490 this._model.resetViewport(); | |
| 491 this._model.resetVisibleSize(); | |
| 492 SDK.DOMModel.unmuteHighlight(); | |
| 493 if (error) { | |
| 494 console.error(error); | |
| 495 return; | |
| 496 } | |
| 497 | |
| 498 var canvas = createElement('canvas'); | |
| 499 var pageImage = new Image(); | |
| 500 pageImage.src = 'data:image/png;base64,' + content; | |
| 501 pageImage.onload = () => { | |
| 502 var ctx = canvas.getContext('2d'); | |
| 503 ctx.imageSmoothingEnabled = false; | |
| 504 canvas.width = pageImage.width; | |
| 505 canvas.height = pageImage.height; | |
| 506 ctx.drawImage(pageImage, 0, 0, pageImage.width, pageImage.height); | |
| 507 var url = mainTarget && mainTarget.inspectedURL(); | |
| 508 var fileName = url ? url.trimURL().removeURLFragment() : ''; | |
| 509 if (this._model.type() === Emulation.DeviceModeModel.Type.Device) | |
| 510 fileName += Common.UIString('(%s)', this._model.device().title); | |
| 511 var link = createElement('a'); | |
| 512 link.download = fileName + '.png'; | |
| 513 canvas.toBlob(function(blob) { | |
| 514 link.href = URL.createObjectURL(blob); | |
| 515 link.click(); | |
| 516 }); | |
| 517 } | |
| 518 } | |
| 519 } | |
| 473 }; | 520 }; |
| 474 | 521 |
| 475 /** | 522 /** |
| 476 * @unrestricted | 523 * @unrestricted |
| 477 */ | 524 */ |
| 478 Emulation.DeviceModeView.Ruler = class extends UI.VBox { | 525 Emulation.DeviceModeView.Ruler = class extends UI.VBox { |
| 479 /** | 526 /** |
| 480 * @param {boolean} horizontal | 527 * @param {boolean} horizontal |
| 481 * @param {function(number)} applyCallback | 528 * @param {function(number)} applyCallback |
| 482 */ | 529 */ |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 return Promise.resolve(); | 612 return Promise.resolve(); |
| 566 } | 613 } |
| 567 | 614 |
| 568 /** | 615 /** |
| 569 * @param {number} size | 616 * @param {number} size |
| 570 */ | 617 */ |
| 571 _onMarkerClick(size) { | 618 _onMarkerClick(size) { |
| 572 this._applyCallback.call(null, size); | 619 this._applyCallback.call(null, size); |
| 573 } | 620 } |
| 574 }; | 621 }; |
| OLD | NEW |