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

Side by Side Diff: Source/core/inspector/InspectorOverlayPage.html

Issue 1212373003: Devtools [LayouEditor]: Show label with size info (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: show while dragging Created 5 years, 5 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 <!-- 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
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
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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 if (!window._controlsVisible) 634 if (!window._controlsVisible)
626 return; 635 return;
627 if (event.keyIdentifier == "F8" || eventHasCtrlOrMeta(event) && event.keyCod e == 220 /* backslash */) 636 if (event.keyIdentifier == "F8" || eventHasCtrlOrMeta(event) && event.keyCod e == 220 /* backslash */)
628 InspectorOverlayHost.resume(); 637 InspectorOverlayHost.resume();
629 else if (event.keyIdentifier == "F10" || eventHasCtrlOrMeta(event) && event. keyCode == 222 /* single quote */) 638 else if (event.keyIdentifier == "F10" || eventHasCtrlOrMeta(event) && event. keyCode == 222 /* single quote */)
630 InspectorOverlayHost.stepOver(); 639 InspectorOverlayHost.stepOver();
631 } 640 }
632 641
633 function showLayoutEditor(info) 642 function showLayoutEditor(info)
634 { 643 {
644 resetCanvas(labelsCanvas);
dgozman 2015/06/29 15:18:35 Let's remove this and instead call showLayoutEdito
sergeyv 2015/06/29 16:30:33 Done.
635 var editorElement = document.getElementById("editor"); 645 var editorElement = document.getElementById("editor");
636 editorElement.style.visibility = "visible"; 646 editorElement.style.visibility = "visible";
637 var anchors = info.anchors; 647 var anchors = info.anchors;
638 for (var i = 0; i < anchors.length; ++i) 648 for (var i = 0; i < anchors.length; ++i) {
639 editorElement.appendChild(createAnchor(anchors[i])); 649 var anchorInfo = anchors[i];
650 editorElement.appendChild(createAnchor(anchorInfo));
651 if (anchorInfo.propertyName === window.draggedPropertyName)
652 showLabel(anchorInfo);
653 }
640 } 654 }
641 655
642 function createAnchor(anchorInfo) 656 function createAnchor(anchorInfo)
643 { 657 {
644 var handleWidth = 5; 658 var handleWidth = 5;
645 context.save(); 659 context.save();
646 context.shadowColor = "black"; 660 context.shadowColor = "rgba(0, 0, 0, 0.34)";
647 context.shadowBlur = 2; 661 context.shadowBlur = 2;
648 context.strokeStyle = "rgb(0, 0, 128)"; 662 context.fillStyle = anchorColorForProperty(anchorInfo.propertyName);
649 context.fillStyle = "rgb(0, 0, 128)";
650 context.beginPath(); 663 context.beginPath();
651 context.arc(anchorInfo.x, anchorInfo.y, handleWidth, 0, 2 * Math.PI); 664 context.arc(anchorInfo.x, anchorInfo.y, handleWidth, 0, 2 * Math.PI);
652 context.fill(); 665 context.fill();
653 context.stroke();
654 context.restore(); 666 context.restore();
655 667
656 var anchorElement = document.createElement("div"); 668 var anchorElement = document.createElement("div");
657 anchorElement.className = "editor-anchor"; 669 anchorElement.className = "editor-anchor";
658 anchorElement.style.left = anchorInfo.x - handleWidth + "px"; 670 anchorElement.style.left = anchorInfo.x - handleWidth + "px";
659 anchorElement.style.top = anchorInfo.y - handleWidth + "px"; 671 anchorElement.style.top = anchorInfo.y - handleWidth + "px";
660 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null, anc horInfo)); 672 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null, anc horInfo));
673 anchorElement.addEventListener("mouseenter", onAnchorMouseEnter.bind(null, a nchorInfo));
674 anchorElement.addEventListener("mouseleave", onAnchorMouseLeave.bind(null, a nchorInfo));
661 return anchorElement; 675 return anchorElement;
662 } 676 }
663 677
664 function calculateDelta(deltaVector, moveDelta) 678 function calculateDelta(deltaVector, moveDelta)
665 { 679 {
666 return (deltaVector.x * moveDelta.x + deltaVector.y * moveDelta.y) / Math.sq rt(deltaVector.x * deltaVector.x + deltaVector.y * deltaVector.y); 680 return (deltaVector.x * moveDelta.x + deltaVector.y * moveDelta.y) / Math.sq rt(deltaVector.x * deltaVector.x + deltaVector.y * deltaVector.y);
667 } 681 }
668 682
669 function onAnchorMouseDown(anchorInfo, event) 683 function onAnchorMouseDown(anchorInfo, event)
670 { 684 {
671 // Only drag upon left button. Right will likely cause a context menu. So wi ll ctrl-click on mac. 685 // 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)) 686 if (event.button || (window.platform == "mac" && event.ctrlKey))
673 return; 687 return;
674 688
675 event.preventDefault(); 689 event.preventDefault();
676 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event. screenY), anchorInfo.deltaVector); 690 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event. screenY), anchorInfo.deltaVector);
677 document.addEventListener("mousemove", boundDragMove); 691 document.addEventListener("mousemove", boundDragMove);
678 document.addEventListener("mouseup", onDragEnd); 692 document.addEventListener("mouseup", onDragEnd);
679 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName); 693 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName);
694 window.draggedPropertyName = anchorInfo.propertyName;
695 resetCanvas(labelsCanvas);
696 showLabel(anchorInfo);
680 } 697 }
681 698
682 function onDragMove(mouseDownPoint, deltaVector, event) 699 function onDragMove(mouseDownPoint, deltaVector, event)
683 { 700 {
684 if (event.buttons !== 1) { 701 if (event.buttons !== 1) {
685 onDragEnd(event); 702 onDragEnd(event);
686 return; 703 return;
687 } 704 }
688 event.preventDefault(); 705 event.preventDefault();
689 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y))); 706 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y)));
690 } 707 }
691 708
709 function showLabel(anchorInfo)
710 {
711 var context = labelsCanvas.getContext("2d");
712 var secondaryColor = "rgba(255, 255, 255, 0.7)";
713 var labelColor = labelColorForProperty(anchorInfo.propertyName);
714 _drawLabel(context, anchorInfo.x, anchorInfo.y, labelColor, [
715 {string: anchorInfo.propertyName + ": ", color: secondaryColor},
716 {string: anchorInfo.value.value, color: "white"},
dgozman 2015/06/29 15:18:35 Let's rename anchorInfo.value to anchorInfo.proper
sergeyv 2015/06/29 16:30:33 Done.
717 {string: "\u2009" + anchorInfo.value.dimension, color: secondaryColor}
718 ], anchorInfo.deltaVector.x < 0);
719 }
720
692 function onDragEnd(event) 721 function onDragEnd(event)
693 { 722 {
694 document.removeEventListener("mousemove", boundDragMove); 723 document.removeEventListener("mousemove", boundDragMove);
695 delete window.boundDragMove; 724 delete window.boundDragMove;
725 delete window.draggedPropertyName;
696 document.removeEventListener("mouseup", onDragEnd); 726 document.removeEventListener("mouseup", onDragEnd);
697 event.preventDefault(); 727 event.preventDefault();
698 InspectorOverlayHost.endPropertyChange(); 728 InspectorOverlayHost.endPropertyChange();
729 resetCanvas(labelsCanvas);
730 }
731
732 function onAnchorMouseEnter(anchorInfo)
733 {
734 if (window.draggedPropertyName)
735 return;
736
737 resetCanvas(labelsCanvas);
738 showLabel(anchorInfo);
739 }
740
741 function onAnchorMouseLeave()
742 {
743 if (window.draggedPropertyName)
744 return;
745
746 resetCanvas(labelsCanvas);
699 } 747 }
700 748
701 function Point(x, y) 749 function Point(x, y)
702 { 750 {
703 this.x = x; 751 this.x = x;
704 this.y = y; 752 this.y = y;
705 } 753 }
706 754
755 function _drawLabel(context, referX, referY, labelColor, textDescription, toLeft )
756 {
757 var paddingX = 6;
758 var paddingY = 4;
759 var borderRadius = 2;
760 var arrowWidth = 6;
761 var offsetX = 6;
762 var fontSize = 10;
763
764 var wholeString = "";
765 for (var part of textDescription)
766 wholeString += part.string;
767
768 context.save();
769 context.font = fontSize + "px Arial, Roboto";
770
771 var textWidth = context.measureText(wholeString).width;
772 var fullWidth = textWidth + offsetX + arrowWidth + paddingX;
773 var height = fontSize + paddingY;
774 var fitRight = referX + fullWidth < viewportSize.width;
775 var fitLeft = referX - fullWidth > 0;
776 var mirror = !fitLeft || (!toLeft && fitRight);
777
778 var arrowX = -offsetX;
779 var arrowY = 0;
780 var halfHeight = height / 2;
dgozman 2015/06/29 15:18:35 unused
sergeyv 2015/06/29 16:30:33 Done.
781 var right = arrowX - arrowWidth;
782 var top = arrowY - height / 2;
783 var bottom = arrowY + height / 2;
784 var left = -fullWidth;
785
786 context.save();
787 context.translate(referX, referY);
dgozman 2015/06/29 15:18:35 anchorX, anchorY
sergeyv 2015/06/29 16:30:33 Done.
788 if (mirror)
789 context.scale(-1, 1);
790
791 context.fillStyle = labelColor;
792 context.shadowColor = "rgba(0, 0, 0, 0.34)";
793 context.shadowOffsetY = 1;
794 context.shadowBlur = 1;
795 context.beginPath();
796 context.moveTo(arrowX, arrowY);
797 context.lineTo(right, bottom);
798 context.lineTo(left + borderRadius, bottom);
799 context.quadraticCurveTo(left, bottom, left, bottom - borderRadius);
800 context.lineTo(left, top + borderRadius);
801 context.quadraticCurveTo(left, top, left + borderRadius, top);
802 context.lineTo(right, top);
803 context.lineTo(arrowX, arrowY);
804 context.closePath();
805 context.fill();
806 context.restore();
807
808 var textX = 0;
809 if (mirror)
810 textX = referX - right + paddingX / 2;
811 else
812 textX = referX + left + paddingX / 2;
813
814 var textY = referY + top + fontSize;
815 for (var part of textDescription) {
816 context.fillStyle = part.color;
817 context.fillText(part.string, textX, textY);
818 textX += context.measureText(part.string).width;
819 }
820 context.restore();
821 }
822
823 function labelColorForProperty(propertyName)
824 {
825 return "rgb(91, 181, 0)";
826 }
827
828 function anchorColorForProperty(propertyName)
829 {
830 return "rgb(107, 213, 0)";
831 }
832
707 window.addEventListener("DOMContentLoaded", onLoaded); 833 window.addEventListener("DOMContentLoaded", onLoaded);
708 document.addEventListener("keydown", onDocumentKeyDown); 834 document.addEventListener("keydown", onDocumentKeyDown);
709 835
710 </script> 836 </script>
711 </head> 837 </head>
712 <body class="fill"> 838 <body class="fill">
713 <div class="controls-line"> 839 <div class="controls-line">
714 <div class="message-box"><div id="paused-in-debugger"></div></div> 840 <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> 841 <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> 842 <div class="button" id="step-over-button" title="Step over next function cal l (F10)."><div class="glyph"></div></div>
717 </div> 843 </div>
718 </body> 844 </body>
719 <canvas id="canvas" class="fill"></canvas> 845 <canvas id="canvas" class="fill"></canvas>
846 <canvas id="labels-canvas" class="fill"></canvas>
720 <div id="element-title"> 847 <div id="element-title">
721 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s pan> 848 <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"> &#xD7 ; </span><span id="node-height"></span><span class="px">px</span> 849 <span id="node-width"></span><span class="px">px</span><span class="px"> &#xD7 ; </span><span id="node-height"></span><span class="px">px</span>
723 </div> 850 </div>
724 <div id="editor" class="fill"></div> 851 <div id="editor" class="fill"></div>
725 <div id="log"></div> 852 <div id="log"></div>
726 </html> 853 </html>
OLDNEW
« no previous file with comments | « no previous file | Source/core/inspector/LayoutEditor.h » ('j') | Source/core/inspector/LayoutEditor.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698