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

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

Issue 1840533002: Devtools: Add screenshot button to device mode toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined again Created 4 years, 8 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 /** 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 }, 344 },
345 345
346 /** 346 /**
347 * @override 347 * @override
348 */ 348 */
349 willHide: function() 349 willHide: function()
350 { 350 {
351 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null); 351 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null);
352 }, 352 },
353 353
354 captureScreenshot: function()
355 {
356 var mainTarget = WebInspector.targetManager.mainTarget();
357 if (!mainTarget)
358 return;
359 mainTarget.pageAgent().captureScreenshot(screenshotCaptured.bind(this));
360
361 /**
362 * @param {?Protocol.Error} error
363 * @param {string} content
364 * @this {WebInspector.DeviceModeView}
365 */
366 function screenshotCaptured(error, content)
367 {
368 if (error)
369 return;
370
371 // Create a canvas to splice the images together.
372 var canvas = createElement("canvas");
373 var ctx = canvas.getContext("2d");
374 var screenRect = this._model.screenRect();
375 canvas.width = screenRect.width;
376 canvas.height = screenRect.height;
377 // Add any available screen images.
378 if (this._model.screenImage()) {
379 var screenImage = new Image();
380 screenImage.srcset = this._model.screenImage();
381 ctx.drawImage(screenImage, 0, 0, screenRect.width, screenRect.he ight);
382 }
383 var pageImage = new Image();
384 pageImage.src = "data:image/png;base64," + content;
385 var visiblePageRect = this._model.visiblePageRect();
386 ctx.drawImage(pageImage, visiblePageRect.left, visiblePageRect.top, visiblePageRect.width, visiblePageRect.height);
387 var mainFrame = mainTarget.resourceTreeModel.mainFrame;
388 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFragment () : "";
389 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device)
390 fileName += WebInspector.UIString("(%s)", this._model.device().t itle);
391 // Trigger download.
392 var link = createElement("a");
393 link.download = fileName + ".png";
394 link.href = canvas.toDataURL("image/png");
395 link.click();
396 }
397 },
398
354 __proto__: WebInspector.VBox.prototype 399 __proto__: WebInspector.VBox.prototype
355 } 400 }
356 401
357 /** 402 /**
358 * @constructor 403 * @constructor
359 * @extends {WebInspector.VBox} 404 * @extends {WebInspector.VBox}
360 * @param {boolean} horizontal 405 * @param {boolean} horizontal
361 * @param {function(number)} applyCallback 406 * @param {function(number)} applyCallback
362 */ 407 */
363 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) 408 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 /** 499 /**
455 * @param {number} size 500 * @param {number} size
456 */ 501 */
457 _onMarkerClick: function(size) 502 _onMarkerClick: function(size)
458 { 503 {
459 this._applyCallback.call(null, size); 504 this._applyCallback.call(null, size);
460 }, 505 },
461 506
462 __proto__: WebInspector.VBox.prototype 507 __proto__: WebInspector.VBox.prototype
463 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698