| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright (C) 2012 Google Inc. All rights reserved. | 2 Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | 3 |
| 4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
| 6 are met: | 6 are met: |
| 7 | 7 |
| 8 1. Redistributions of source code must retain the above copyright | 8 1. Redistributions of source code must retain the above copyright |
| 9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
| 10 2. Redistributions in binary form must reproduce the above copyright | 10 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 top: 0; | 54 top: 0; |
| 55 right: 0; | 55 right: 0; |
| 56 bottom: 0; | 56 bottom: 0; |
| 57 left: 0; | 57 left: 0; |
| 58 } | 58 } |
| 59 | 59 |
| 60 .dimmed { | 60 .dimmed { |
| 61 background-color: rgba(0, 0, 0, 0.31); | 61 background-color: rgba(0, 0, 0, 0.31); |
| 62 } | 62 } |
| 63 | 63 |
| 64 #canvas { | 64 #canvas, #labels-canvas { |
| 65 pointer-events: none; | 65 pointer-events: none; |
| 66 } | 66 } |
| 67 | 67 |
| 68 .controls-line { | 68 .controls-line { |
| 69 display: flex; | 69 display: flex; |
| 70 justify-content: center; | 70 justify-content: center; |
| 71 margin: 10px 0; | 71 margin: 10px 0; |
| 72 } | 72 } |
| 73 | 73 |
| 74 .message-box { | 74 .message-box { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 var textWidth = context.measureText(text).width; | 317 var textWidth = context.measureText(text).width; |
| 318 context.fillStyle = gridBackgroundColor; | 318 context.fillStyle = gridBackgroundColor; |
| 319 context.fillRect(frameWidth - textWidth - 12, drawGridBoolean ? 15 : 0, fram
eWidth, 25); | 319 context.fillRect(frameWidth - textWidth - 12, drawGridBoolean ? 15 : 0, fram
eWidth, 25); |
| 320 context.fillStyle = darkGridColor; | 320 context.fillStyle = darkGridColor; |
| 321 context.fillText(text, frameWidth - textWidth - 6, drawGridBoolean ? 33 : 18
); | 321 context.fillText(text, frameWidth - textWidth - 6, drawGridBoolean ? 33 : 18
); |
| 322 context.restore(); | 322 context.restore(); |
| 323 if (drawGridBoolean) | 323 if (drawGridBoolean) |
| 324 _drawGrid(); | 324 _drawGrid(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 function resetCanvas(canvasElement) |
| 328 { |
| 329 canvasElement.width = deviceScaleFactor * viewportSize.width; |
| 330 canvasElement.height = deviceScaleFactor * viewportSize.height; |
| 331 canvasElement.style.width = viewportSize.width + "px"; |
| 332 canvasElement.style.height = viewportSize.height + "px"; |
| 333 var context = canvasElement.getContext("2d"); |
| 334 context.scale(deviceScaleFactor, deviceScaleFactor); |
| 335 } |
| 336 |
| 327 function reset(resetData) | 337 function reset(resetData) |
| 328 { | 338 { |
| 329 window.viewportSize = resetData.viewportSize; | 339 window.viewportSize = resetData.viewportSize; |
| 330 window.deviceScaleFactor = resetData.deviceScaleFactor; | 340 window.deviceScaleFactor = resetData.deviceScaleFactor; |
| 331 window.pageZoomFactor = resetData.pageZoomFactor; | 341 window.pageZoomFactor = resetData.pageZoomFactor; |
| 332 window.scrollX = Math.round(resetData.scrollX); | 342 window.scrollX = Math.round(resetData.scrollX); |
| 333 window.scrollY = Math.round(resetData.scrollY); | 343 window.scrollY = Math.round(resetData.scrollY); |
| 334 | 344 |
| 335 window.canvas = document.getElementById("canvas"); | 345 window.canvas = document.getElementById("canvas"); |
| 336 window.context = canvas.getContext("2d"); | 346 window.context = canvas.getContext("2d"); |
| 347 resetCanvas(canvas); |
| 337 | 348 |
| 338 canvas.width = deviceScaleFactor * viewportSize.width; | 349 window.labelsCanvas = document.getElementById("labels-canvas"); |
| 339 canvas.height = deviceScaleFactor * viewportSize.height; | 350 resetCanvas(labelsCanvas); |
| 340 canvas.style.width = viewportSize.width + "px"; | 351 |
| 341 canvas.style.height = viewportSize.height + "px"; | |
| 342 context.scale(deviceScaleFactor, deviceScaleFactor); | |
| 343 window.canvasWidth = viewportSize.width; | 352 window.canvasWidth = viewportSize.width; |
| 344 window.canvasHeight = viewportSize.height; | 353 window.canvasHeight = viewportSize.height; |
| 345 | 354 |
| 346 window._controlsVisible = false; | 355 window._controlsVisible = false; |
| 347 document.querySelector(".controls-line").style.visibility = "hidden"; | 356 document.querySelector(".controls-line").style.visibility = "hidden"; |
| 348 document.getElementById("element-title").style.visibility = "hidden"; | 357 document.getElementById("element-title").style.visibility = "hidden"; |
| 349 var editor = document.getElementById("editor"); | 358 var editor = document.getElementById("editor"); |
| 350 editor.style.visibility = "hidden"; | 359 editor.style.visibility = "hidden"; |
| 351 editor.textContent = ""; | 360 editor.textContent = ""; |
| 352 document.body.classList.remove("dimmed"); | 361 document.body.classList.remove("dimmed"); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (highlight.showRulers) | 575 if (highlight.showRulers) |
| 567 _drawGrid(rulerAtRight, rulerAtBottom); | 576 _drawGrid(rulerAtRight, rulerAtBottom); |
| 568 | 577 |
| 569 if (highlight.paths.length) { | 578 if (highlight.paths.length) { |
| 570 if (highlight.showExtensionLines) | 579 if (highlight.showExtensionLines) |
| 571 _drawRulers(bounds, rulerAtRight, rulerAtBottom); | 580 _drawRulers(bounds, rulerAtRight, rulerAtBottom); |
| 572 | 581 |
| 573 if (highlight.elementInfo) | 582 if (highlight.elementInfo) |
| 574 _drawElementTitle(highlight.elementInfo, bounds); | 583 _drawElementTitle(highlight.elementInfo, bounds); |
| 575 } | 584 } |
| 576 | |
| 577 if (highlight.layoutEditorInfo) | |
| 578 showLayoutEditor(highlight.layoutEditorInfo); | |
| 579 | |
| 580 context.restore(); | 585 context.restore(); |
| 581 } | 586 } |
| 582 | 587 |
| 583 function setPlatform(platform) | 588 function setPlatform(platform) |
| 584 { | 589 { |
| 585 window.platform = platform; | 590 window.platform = platform; |
| 586 document.body.classList.add("platform-" + platform); | 591 document.body.classList.add("platform-" + platform); |
| 587 } | 592 } |
| 588 | 593 |
| 589 function dispatch(message) | 594 function dispatch(message) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 InspectorOverlayHost.resume(); | 633 InspectorOverlayHost.resume(); |
| 629 else if (event.keyIdentifier == "F10" || eventHasCtrlOrMeta(event) && event.
keyCode == 222 /* single quote */) | 634 else if (event.keyIdentifier == "F10" || eventHasCtrlOrMeta(event) && event.
keyCode == 222 /* single quote */) |
| 630 InspectorOverlayHost.stepOver(); | 635 InspectorOverlayHost.stepOver(); |
| 631 } | 636 } |
| 632 | 637 |
| 633 function showLayoutEditor(info) | 638 function showLayoutEditor(info) |
| 634 { | 639 { |
| 635 var editorElement = document.getElementById("editor"); | 640 var editorElement = document.getElementById("editor"); |
| 636 editorElement.style.visibility = "visible"; | 641 editorElement.style.visibility = "visible"; |
| 637 var anchors = info.anchors; | 642 var anchors = info.anchors; |
| 638 for (var i = 0; i < anchors.length; ++i) | 643 for (var i = 0; i < anchors.length; ++i) { |
| 639 editorElement.appendChild(createAnchor(anchors[i])); | 644 var anchorInfo = anchors[i]; |
| 645 editorElement.appendChild(createAnchor(anchorInfo)); |
| 646 if (anchorInfo.propertyName === window.draggedPropertyName) |
| 647 showLabel(anchorInfo); |
| 648 } |
| 640 } | 649 } |
| 641 | 650 |
| 642 function createAnchor(anchorInfo) | 651 function createAnchor(anchorInfo) |
| 643 { | 652 { |
| 644 var handleWidth = 5; | 653 var handleWidth = 5; |
| 645 context.save(); | 654 context.save(); |
| 646 context.shadowColor = "black"; | 655 context.shadowColor = "rgba(0, 0, 0, 0.34)"; |
| 647 context.shadowBlur = 2; | 656 context.shadowBlur = 2; |
| 648 context.strokeStyle = "rgb(0, 0, 128)"; | 657 context.fillStyle = anchorColorForProperty(anchorInfo.propertyName); |
| 649 context.fillStyle = "rgb(0, 0, 128)"; | |
| 650 context.beginPath(); | 658 context.beginPath(); |
| 651 context.arc(anchorInfo.x, anchorInfo.y, handleWidth, 0, 2 * Math.PI); | 659 context.arc(anchorInfo.x, anchorInfo.y, handleWidth, 0, 2 * Math.PI); |
| 652 context.fill(); | 660 context.fill(); |
| 653 context.stroke(); | |
| 654 context.restore(); | 661 context.restore(); |
| 655 | 662 |
| 656 var anchorElement = document.createElement("div"); | 663 var anchorElement = document.createElement("div"); |
| 657 anchorElement.className = "editor-anchor"; | 664 anchorElement.className = "editor-anchor"; |
| 658 anchorElement.style.left = anchorInfo.x - handleWidth + "px"; | 665 anchorElement.style.left = anchorInfo.x - handleWidth + "px"; |
| 659 anchorElement.style.top = anchorInfo.y - handleWidth + "px"; | 666 anchorElement.style.top = anchorInfo.y - handleWidth + "px"; |
| 660 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null, anc
horInfo)); | 667 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null, anc
horInfo)); |
| 668 anchorElement.addEventListener("mouseenter", onAnchorMouseEnter.bind(null, a
nchorInfo)); |
| 669 anchorElement.addEventListener("mouseleave", onAnchorMouseLeave.bind(null, a
nchorInfo)); |
| 661 return anchorElement; | 670 return anchorElement; |
| 662 } | 671 } |
| 663 | 672 |
| 664 function calculateDelta(deltaVector, moveDelta) | 673 function calculateDelta(deltaVector, moveDelta) |
| 665 { | 674 { |
| 666 return (deltaVector.x * moveDelta.x + deltaVector.y * moveDelta.y) / Math.sq
rt(deltaVector.x * deltaVector.x + deltaVector.y * deltaVector.y); | 675 return (deltaVector.x * moveDelta.x + deltaVector.y * moveDelta.y) / Math.sq
rt(deltaVector.x * deltaVector.x + deltaVector.y * deltaVector.y); |
| 667 } | 676 } |
| 668 | 677 |
| 669 function onAnchorMouseDown(anchorInfo, event) | 678 function onAnchorMouseDown(anchorInfo, event) |
| 670 { | 679 { |
| 671 // Only drag upon left button. Right will likely cause a context menu. So wi
ll ctrl-click on mac. | 680 // Only drag upon left button. Right will likely cause a context menu. So wi
ll ctrl-click on mac. |
| 672 if (event.button || (window.platform == "mac" && event.ctrlKey)) | 681 if (event.button || (window.platform == "mac" && event.ctrlKey)) |
| 673 return; | 682 return; |
| 674 | 683 |
| 675 event.preventDefault(); | 684 event.preventDefault(); |
| 676 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event.
screenY), anchorInfo.deltaVector); | 685 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event.
screenY), anchorInfo.deltaVector); |
| 677 document.addEventListener("mousemove", boundDragMove); | 686 document.addEventListener("mousemove", boundDragMove); |
| 678 document.addEventListener("mouseup", onDragEnd); | 687 document.addEventListener("mouseup", onDragEnd); |
| 679 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName); | 688 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName); |
| 689 window.draggedPropertyName = anchorInfo.propertyName; |
| 690 resetCanvas(labelsCanvas); |
| 691 showLabel(anchorInfo); |
| 680 } | 692 } |
| 681 | 693 |
| 682 function onDragMove(mouseDownPoint, deltaVector, event) | 694 function onDragMove(mouseDownPoint, deltaVector, event) |
| 683 { | 695 { |
| 684 if (event.buttons !== 1) { | 696 if (event.buttons !== 1) { |
| 685 onDragEnd(event); | 697 onDragEnd(event); |
| 686 return; | 698 return; |
| 687 } | 699 } |
| 688 event.preventDefault(); | 700 event.preventDefault(); |
| 689 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev
ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y))); | 701 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev
ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y))); |
| 690 } | 702 } |
| 691 | 703 |
| 704 function showLabel(anchorInfo) |
| 705 { |
| 706 var context = labelsCanvas.getContext("2d"); |
| 707 var secondaryColor = "rgba(255, 255, 255, 0.7)"; |
| 708 var labelColor = labelColorForProperty(anchorInfo.propertyName); |
| 709 _drawLabel(context, anchorInfo.x, anchorInfo.y, labelColor, [ |
| 710 {string: anchorInfo.propertyName + ": ", color: secondaryColor}, |
| 711 {string: anchorInfo.propertyValue.value, color: "white"}, |
| 712 {string: "\u2009" + anchorInfo.propertyValue.unit, color: secondaryColor
} |
| 713 ], anchorInfo.deltaVector.x < 0); |
| 714 } |
| 715 |
| 692 function onDragEnd(event) | 716 function onDragEnd(event) |
| 693 { | 717 { |
| 694 document.removeEventListener("mousemove", boundDragMove); | 718 document.removeEventListener("mousemove", boundDragMove); |
| 695 delete window.boundDragMove; | 719 delete window.boundDragMove; |
| 720 delete window.draggedPropertyName; |
| 696 document.removeEventListener("mouseup", onDragEnd); | 721 document.removeEventListener("mouseup", onDragEnd); |
| 697 event.preventDefault(); | 722 event.preventDefault(); |
| 698 InspectorOverlayHost.endPropertyChange(); | 723 InspectorOverlayHost.endPropertyChange(); |
| 724 resetCanvas(labelsCanvas); |
| 725 } |
| 726 |
| 727 function onAnchorMouseEnter(anchorInfo) |
| 728 { |
| 729 if (window.draggedPropertyName) |
| 730 return; |
| 731 |
| 732 resetCanvas(labelsCanvas); |
| 733 showLabel(anchorInfo); |
| 734 } |
| 735 |
| 736 function onAnchorMouseLeave() |
| 737 { |
| 738 if (window.draggedPropertyName) |
| 739 return; |
| 740 |
| 741 resetCanvas(labelsCanvas); |
| 699 } | 742 } |
| 700 | 743 |
| 701 function Point(x, y) | 744 function Point(x, y) |
| 702 { | 745 { |
| 703 this.x = x; | 746 this.x = x; |
| 704 this.y = y; | 747 this.y = y; |
| 705 } | 748 } |
| 706 | 749 |
| 750 function _drawLabel(context, anchorX, anchorY, labelColor, textDescription, toLe
ft) |
| 751 { |
| 752 var paddingX = 6; |
| 753 var paddingY = 4; |
| 754 var borderRadius = 2; |
| 755 var arrowWidth = 6; |
| 756 var offsetX = 6; |
| 757 var fontSize = 10; |
| 758 |
| 759 var wholeString = ""; |
| 760 for (var part of textDescription) |
| 761 wholeString += part.string; |
| 762 |
| 763 context.save(); |
| 764 context.font = fontSize + "px Arial, Roboto"; |
| 765 |
| 766 var textWidth = context.measureText(wholeString).width; |
| 767 var fullWidth = textWidth + offsetX + arrowWidth + paddingX; |
| 768 var height = fontSize + paddingY; |
| 769 var fitRight = anchorX + fullWidth < viewportSize.width; |
| 770 var fitLeft = anchorX - fullWidth > 0; |
| 771 var mirror = !fitLeft || (!toLeft && fitRight); |
| 772 |
| 773 var arrowX = -offsetX; |
| 774 var arrowY = 0; |
| 775 var right = arrowX - arrowWidth; |
| 776 var top = arrowY - height / 2; |
| 777 var bottom = arrowY + height / 2; |
| 778 var left = -fullWidth; |
| 779 |
| 780 context.save(); |
| 781 context.translate(anchorX, anchorY); |
| 782 if (mirror) |
| 783 context.scale(-1, 1); |
| 784 |
| 785 context.fillStyle = labelColor; |
| 786 context.shadowColor = "rgba(0, 0, 0, 0.34)"; |
| 787 context.shadowOffsetY = 1; |
| 788 context.shadowBlur = 1; |
| 789 context.beginPath(); |
| 790 context.moveTo(arrowX, arrowY); |
| 791 context.lineTo(right, bottom); |
| 792 context.lineTo(left + borderRadius, bottom); |
| 793 context.quadraticCurveTo(left, bottom, left, bottom - borderRadius); |
| 794 context.lineTo(left, top + borderRadius); |
| 795 context.quadraticCurveTo(left, top, left + borderRadius, top); |
| 796 context.lineTo(right, top); |
| 797 context.lineTo(arrowX, arrowY); |
| 798 context.closePath(); |
| 799 context.fill(); |
| 800 context.restore(); |
| 801 |
| 802 var textX = 0; |
| 803 if (mirror) |
| 804 textX = anchorX - right + paddingX / 2; |
| 805 else |
| 806 textX = anchorX + left + paddingX / 2; |
| 807 |
| 808 var textY = anchorY + top + fontSize; |
| 809 for (var part of textDescription) { |
| 810 context.fillStyle = part.color; |
| 811 context.fillText(part.string, textX, textY); |
| 812 textX += context.measureText(part.string).width; |
| 813 } |
| 814 context.restore(); |
| 815 } |
| 816 |
| 817 function labelColorForProperty(propertyName) |
| 818 { |
| 819 return "rgb(91, 181, 0)"; |
| 820 } |
| 821 |
| 822 function anchorColorForProperty(propertyName) |
| 823 { |
| 824 return "rgb(107, 213, 0)"; |
| 825 } |
| 826 |
| 707 window.addEventListener("DOMContentLoaded", onLoaded); | 827 window.addEventListener("DOMContentLoaded", onLoaded); |
| 708 document.addEventListener("keydown", onDocumentKeyDown); | 828 document.addEventListener("keydown", onDocumentKeyDown); |
| 709 | 829 |
| 710 </script> | 830 </script> |
| 711 </head> | 831 </head> |
| 712 <body class="fill"> | 832 <body class="fill"> |
| 713 <div class="controls-line"> | 833 <div class="controls-line"> |
| 714 <div class="message-box"><div id="paused-in-debugger"></div></div> | 834 <div class="message-box"><div id="paused-in-debugger"></div></div> |
| 715 <div class="button" id="resume-button" title="Resume script execution (F8)."
><div class="glyph"></div></div> | 835 <div class="button" id="resume-button" title="Resume script execution (F8)."
><div class="glyph"></div></div> |
| 716 <div class="button" id="step-over-button" title="Step over next function cal
l (F10)."><div class="glyph"></div></div> | 836 <div class="button" id="step-over-button" title="Step over next function cal
l (F10)."><div class="glyph"></div></div> |
| 717 </div> | 837 </div> |
| 718 </body> | 838 </body> |
| 719 <canvas id="canvas" class="fill"></canvas> | 839 <canvas id="canvas" class="fill"></canvas> |
| 840 <canvas id="labels-canvas" class="fill"></canvas> |
| 720 <div id="element-title"> | 841 <div id="element-title"> |
| 721 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s
pan> | 842 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s
pan> |
| 722 <span id="node-width"></span><span class="px">px</span><span class="px"> ×
; </span><span id="node-height"></span><span class="px">px</span> | 843 <span id="node-width"></span><span class="px">px</span><span class="px"> ×
; </span><span id="node-height"></span><span class="px">px</span> |
| 723 </div> | 844 </div> |
| 724 <div id="editor" class="fill"></div> | 845 <div id="editor" class="fill"></div> |
| 725 <div id="log"></div> | 846 <div id="log"></div> |
| 726 </html> | 847 </html> |
| OLD | NEW |