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

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: review comment Created 4 years, 7 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) {
414 console.error(error);
414 return; 415 return;
416 }
415 417
416 // Create a canvas to splice the images together. 418 // Create a canvas to splice the images together.
417 var canvas = createElement("canvas"); 419 var canvas = createElement("canvas");
418 var ctx = canvas.getContext("2d"); 420 var ctx = canvas.getContext("2d");
419 canvas.width = outlineRect.width; 421 canvas.width = outlineRect.width;
420 canvas.height = outlineRect.height; 422 canvas.height = outlineRect.height;
421 423
422 var promise = Promise.resolve(); 424 var promise = Promise.resolve();
423 if (this._model.outlineImage()) 425 if (this._model.outlineImage())
424 promise = promise.then(paintImage.bind(null, this._model.outline Image(), outlineRect)); 426 promise = promise.then(paintImage.bind(null, this._model.outline Image(), outlineRect));
427 promise = promise.then(drawBorder);
425 if (this._model.screenImage()) 428 if (this._model.screenImage())
426 promise = promise.then(paintImage.bind(null, this._model.screenI mage(), screenRect)); 429 promise = promise.then(paintImage.bind(null, this._model.screenI mage(), screenRect));
427 promise.then(paintScreenshot.bind(this)); 430 promise.then(paintScreenshot.bind(this));
428 431
429 /** 432 /**
430 * @param {string} src 433 * @param {string} src
431 * @param {!WebInspector.Rect} rect 434 * @param {!WebInspector.Rect} rect
432 * @return {!Promise<undefined>} 435 * @return {!Promise<undefined>}
433 */ 436 */
434 function paintImage(src, rect) 437 function paintImage(src, rect)
435 { 438 {
436 var callback; 439 var callback;
437 var promise = new Promise(fulfill => callback = fulfill); 440 var promise = new Promise(fulfill => callback = fulfill);
438 var image = new Image(); 441 var image = new Image();
439 image.crossOrigin = "Anonymous"; 442 image.crossOrigin = "Anonymous";
440 image.srcset = src; 443 image.srcset = src;
441 image.onload = onImageLoad; 444 image.onload = onImageLoad;
442 image.onerror = callback; 445 image.onerror = callback;
443 return promise; 446 return promise;
444 447
445 function onImageLoad() 448 function onImageLoad()
446 { 449 {
447 ctx.drawImage(image, rect.left, rect.top, rect.width, rect.h eight); 450 ctx.drawImage(image, rect.left, rect.top, rect.width, rect.h eight);
448 callback(); 451 callback();
449 } 452 }
450 } 453 }
451 454
455 function drawBorder()
456 {
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 }
462
452 /** 463 /**
453 * @this {WebInspector.DeviceModeView} 464 * @this {WebInspector.DeviceModeView}
454 */ 465 */
455 function paintScreenshot() 466 function paintScreenshot()
456 { 467 {
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(); 468 var pageImage = new Image();
462 pageImage.src = "data:image/png;base64," + content; 469 pageImage.src = "data:image/png;base64," + content;
463 ctx.drawImage(pageImage, 470 ctx.drawImage(pageImage,
464 visiblePageRect.left, 471 visiblePageRect.left,
465 visiblePageRect.top, 472 visiblePageRect.top,
466 Math.min(pageImage.naturalWidth, screenRect.width) , 473 Math.min(pageImage.naturalWidth, screenRect.width) ,
467 Math.min(pageImage.naturalHeight, screenRect.heigh t)); 474 Math.min(pageImage.naturalHeight, screenRect.heigh t));
468 var mainFrame = mainTarget.resourceTreeModel.mainFrame; 475 var mainFrame = mainTarget.resourceTreeModel.mainFrame;
469 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : ""; 476 var fileName = mainFrame ? mainFrame.url.trimURL().removeURLFrag ment() : "";
470 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice) 477 if (this._model.type() === WebInspector.DeviceModeModel.Type.Dev ice)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 /** 582 /**
576 * @param {number} size 583 * @param {number} size
577 */ 584 */
578 _onMarkerClick: function(size) 585 _onMarkerClick: function(size)
579 { 586 {
580 this._applyCallback.call(null, size); 587 this._applyCallback.call(null, size);
581 }, 588 },
582 589
583 __proto__: WebInspector.VBox.prototype 590 __proto__: WebInspector.VBox.prototype
584 } 591 }
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