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

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

Issue 2010773002: [DevTools] Draw screen border below screen image when taking screenshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 screenRect.top -= outlineRect.top; 403 screenRect.top -= outlineRect.top;
404 var visiblePageRect = this._model.visiblePageRect().scale(dpr); 404 var visiblePageRect = this._model.visiblePageRect().scale(dpr);
405 visiblePageRect.left += screenRect.left; 405 visiblePageRect.left += screenRect.left;
406 visiblePageRect.top += screenRect.top; 406 visiblePageRect.top += screenRect.top;
407 outlineRect.left = 0; 407 outlineRect.left = 0;
408 outlineRect.top = 0; 408 outlineRect.top = 0;
409 409
410 WebInspector.DOMModel.unmuteHighlight(); 410 WebInspector.DOMModel.unmuteHighlight();
411 WebInspector.inspectorView.restore(); 411 WebInspector.inspectorView.restore();
412 412
413 if (error) 413 if (error)
lushnikov 2016/05/25 18:16:58 let's do console.error here - ignoring errors sile
dgozman 2016/05/25 20:23:26 Done.
414 return; 414 return;
415 415
416 // Create a canvas to splice the images together. 416 // Create a canvas to splice the images together.
417 var canvas = createElement("canvas"); 417 var canvas = createElement("canvas");
418 var ctx = canvas.getContext("2d"); 418 var ctx = canvas.getContext("2d");
419 canvas.width = outlineRect.width; 419 canvas.width = outlineRect.width;
420 canvas.height = outlineRect.height; 420 canvas.height = outlineRect.height;
421 421
422 var promise = Promise.resolve(); 422 var promise = Promise.resolve();
423 if (this._model.outlineImage()) 423 if (this._model.outlineImage())
424 promise = promise.then(paintImage.bind(null, this._model.outline Image(), outlineRect)); 424 promise = promise.then(paintImage.bind(null, this._model.outline Image(), outlineRect));
425 promise = promise.then(drawBorder);
425 if (this._model.screenImage()) 426 if (this._model.screenImage())
426 promise = promise.then(paintImage.bind(null, this._model.screenI mage(), screenRect)); 427 promise = promise.then(paintImage.bind(null, this._model.screenI mage(), screenRect));
427 promise.then(paintScreenshot.bind(this)); 428 promise.then(paintScreenshot.bind(this));
428 429
429 /** 430 /**
430 * @param {string} src 431 * @param {string} src
431 * @param {!WebInspector.Rect} rect 432 * @param {!WebInspector.Rect} rect
432 * @return {!Promise<undefined>} 433 * @return {!Promise<undefined>}
433 */ 434 */
434 function paintImage(src, rect) 435 function paintImage(src, rect)
435 { 436 {
436 var callback; 437 var callback;
437 var promise = new Promise(fulfill => callback = fulfill); 438 var promise = new Promise(fulfill => callback = fulfill);
438 var image = new Image(); 439 var image = new Image();
439 image.crossOrigin = "Anonymous"; 440 image.crossOrigin = "Anonymous";
440 image.srcset = src; 441 image.srcset = src;
441 image.onload = onImageLoad; 442 image.onload = onImageLoad;
442 image.onerror = callback; 443 image.onerror = callback;
443 return promise; 444 return promise;
444 445
445 function onImageLoad() 446 function onImageLoad()
446 { 447 {
447 ctx.drawImage(image, rect.left, rect.top, rect.width, rect.h eight); 448 ctx.drawImage(image, rect.left, rect.top, rect.width, rect.h eight);
448 callback(); 449 callback();
449 } 450 }
450 } 451 }
451 452
453 function drawBorder()
454 {
455 ctx.strokeStyle = "hsla(0, 0%, 98%, 0.5)";
456 ctx.lineWidth = 1;
457 ctx.setLineDash([10, 10]);
458 ctx.strokeRect(screenRect.left + 1, screenRect.top + 1, screenRe ct.width - 2, screenRect.height - 2);
459 }
460
452 /** 461 /**
453 * @this {WebInspector.DeviceModeView} 462 * @this {WebInspector.DeviceModeView}
454 */ 463 */
455 function paintScreenshot() 464 function paintScreenshot()
456 { 465 {
457 ctx.strokeStyle = "hsla(0, 0%, 98%, 0.5)";
458 ctx.lineWidth = 1;
459 ctx.setLineDash([10, 10]);
460 ctx.strokeRect(screenRect.left + 1, screenRect.top + 1, screenRe ct.width - 2, screenRect.height - 2);
461 var pageImage = new Image(); 466 var pageImage = new Image();
462 pageImage.src = "data:image/png;base64," + content; 467 pageImage.src = "data:image/png;base64," + content;
463 ctx.drawImage(pageImage, 468 ctx.drawImage(pageImage,
464 visiblePageRect.left, 469 visiblePageRect.left,
465 visiblePageRect.top, 470 visiblePageRect.top,
466 Math.min(pageImage.naturalWidth, screenRect.width) , 471 Math.min(pageImage.naturalWidth, screenRect.width) ,
467 Math.min(pageImage.naturalHeight, screenRect.heigh t)); 472 Math.min(pageImage.naturalHeight, screenRect.heigh t));
468 var mainFrame = mainTarget.resourceTreeModel.mainFrame; 473 var mainFrame = mainTarget.resourceTreeModel.mainFrame;
469 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : ""; 474 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : "";
470 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice) 475 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 /** 580 /**
576 * @param {number} size 581 * @param {number} size
577 */ 582 */
578 _onMarkerClick: function(size) 583 _onMarkerClick: function(size)
579 { 584 {
580 this._applyCallback.call(null, size); 585 this._applyCallback.call(null, size);
581 }, 586 },
582 587
583 __proto__: WebInspector.VBox.prototype 588 __proto__: WebInspector.VBox.prototype
584 } 589 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698