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

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

Issue 1317913004: Devtools [LayoutEditor]: show selector info and highlight affected nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cursor2
Patch Set: Rebase Created 5 years, 3 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 const gridBackgroundColor = "rgba(255, 255, 255, 0.8)"; 247 const gridBackgroundColor = "rgba(255, 255, 255, 0.8)";
248 248
249 function drawPausedInDebuggerMessage(message) 249 function drawPausedInDebuggerMessage(message)
250 { 250 {
251 window._controlsVisible = true; 251 window._controlsVisible = true;
252 document.querySelector(".controls-line").style.visibility = "visible"; 252 document.querySelector(".controls-line").style.visibility = "visible";
253 document.getElementById("paused-in-debugger").textContent = message; 253 document.getElementById("paused-in-debugger").textContent = message;
254 document.body.classList.add("dimmed"); 254 document.body.classList.add("dimmed");
255 } 255 }
256 256
257 function _drawGrid(rulerAtRight, rulerAtBottom) 257 function _drawGrid(context, rulerAtRight, rulerAtBottom)
258 { 258 {
259 if (window._gridPainted) 259 if (window._gridPainted)
260 return; 260 return;
261 window._gridPainted = true; 261 window._gridPainted = true;
262 262
263 context.save(); 263 context.save();
264 264
265 var pageFactor = pageZoomFactor; 265 var pageFactor = pageZoomFactor;
266 function zoom(x) 266 function zoom(x)
267 { 267 {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 402
403 var frameWidth = canvasWidth; 403 var frameWidth = canvasWidth;
404 var textWidth = context.measureText(text).width; 404 var textWidth = context.measureText(text).width;
405 context.fillStyle = gridBackgroundColor; 405 context.fillStyle = gridBackgroundColor;
406 context.fillRect(frameWidth - textWidth - 12, drawGridBoolean ? 15 : 0, fram eWidth, 25); 406 context.fillRect(frameWidth - textWidth - 12, drawGridBoolean ? 15 : 0, fram eWidth, 25);
407 context.fillStyle = darkGridColor; 407 context.fillStyle = darkGridColor;
408 context.fillText(text, frameWidth - textWidth - 6, drawGridBoolean ? 33 : 18 ); 408 context.fillText(text, frameWidth - textWidth - 6, drawGridBoolean ? 33 : 18 );
409 context.restore(); 409 context.restore();
410 if (drawGridBoolean) 410 if (drawGridBoolean)
411 _drawGrid(); 411 _drawGrid(context);
412 } 412 }
413 413
414 function resetCanvas(canvasElement) 414 function resetCanvas(canvasElement)
415 { 415 {
416 canvasElement.width = deviceScaleFactor * viewportSize.width; 416 canvasElement.width = deviceScaleFactor * viewportSize.width;
417 canvasElement.height = deviceScaleFactor * viewportSize.height; 417 canvasElement.height = deviceScaleFactor * viewportSize.height;
418 canvasElement.style.width = viewportSize.width + "px"; 418 canvasElement.style.width = viewportSize.width + "px";
419 canvasElement.style.height = viewportSize.height + "px"; 419 canvasElement.style.height = viewportSize.height + "px";
420 var context = canvasElement.getContext("2d"); 420 var context = canvasElement.getContext("2d");
421 context.scale(deviceScaleFactor, deviceScaleFactor); 421 context.scale(deviceScaleFactor, deviceScaleFactor);
422 } 422 }
423 423
424 function reset(resetData) 424 function reset(resetData)
425 { 425 {
426 window.viewportSize = resetData.viewportSize; 426 window.viewportSize = resetData.viewportSize;
427 window.deviceScaleFactor = resetData.deviceScaleFactor; 427 window.deviceScaleFactor = resetData.deviceScaleFactor;
428 window.pageZoomFactor = resetData.pageZoomFactor; 428 window.pageZoomFactor = resetData.pageZoomFactor;
429 window.scrollX = Math.round(resetData.scrollX); 429 window.scrollX = Math.round(resetData.scrollX);
430 window.scrollY = Math.round(resetData.scrollY); 430 window.scrollY = Math.round(resetData.scrollY);
431 431
432 window.canvas = document.getElementById("canvas"); 432 window.canvas = document.getElementById("canvas");
433 window.context = canvas.getContext("2d"); 433 window.context = canvas.getContext("2d");
434 resetCanvas(canvas); 434 resetCanvas(canvas);
435 435 var matchedNodesCanvas = document.getElementById("layout-editor-matched-node s-canvas");
436 resetCanvas(matchedNodesCanvas);
436 window.labelsCanvas = document.getElementById("labels-canvas"); 437 window.labelsCanvas = document.getElementById("labels-canvas");
437 resetLabelCanvas(); 438 resetLabelCanvas();
438 439
439 window.canvasWidth = viewportSize.width; 440 window.canvasWidth = viewportSize.width;
440 window.canvasHeight = viewportSize.height; 441 window.canvasHeight = viewportSize.height;
441 442
442 window._controlsVisible = false; 443 window._controlsVisible = false;
443 document.querySelector(".controls-line").style.visibility = "hidden"; 444 document.querySelector(".controls-line").style.visibility = "hidden";
444 document.getElementById("element-title").style.visibility = "hidden"; 445 document.getElementById("element-title").style.visibility = "hidden";
445 document.getElementById("tooltip-container").classList.add("hidden"); 446 document.getElementById("tooltip-container").classList.add("hidden");
446 var editor = document.getElementById("editor"); 447 var editor = document.getElementById("editor");
447 editor.style.visibility = "hidden"; 448 editor.style.visibility = "hidden";
448 editor.textContent = ""; 449 editor.textContent = "";
450 document.getElementById("selector-tooltip").style.visibility = "hidden";
449 document.body.classList.remove("dimmed"); 451 document.body.classList.remove("dimmed");
450 document.removeEventListener("mousedown", consumeEvent); 452 document.removeEventListener("mousedown", consumeEvent);
451 document.removeEventListener("mousemove", onLayoutEditorMouseMove); 453 document.removeEventListener("mousemove", onLayoutEditorMouseMove);
452 document.removeEventListener("mouseup", consumeEvent); 454 document.removeEventListener("mouseup", consumeEvent);
453 document.removeEventListener("click", onLayoutEditorClick); 455 document.removeEventListener("click", onLayoutEditorClick);
454 document.removeEventListener("keydown", onLayoutEditorKeyDown); 456 document.removeEventListener("keydown", onLayoutEditorKeyDown);
457 document.removeEventListener("mousewheel", onLayoutEditorMouseWheel);
455 458
456 delete window.hoverableAreas; 459 delete window.hoverableAreas;
457 delete window.anchorsByType; 460 delete window.anchorsByType;
458 window._gridPainted = false; 461 window._gridPainted = false;
459 } 462 }
460 463
461 function _drawElementTitle(elementInfo, bounds) 464 function _drawElementTitle(context, elementInfo, bounds)
462 { 465 {
463 document.getElementById("tag-name").textContent = elementInfo.tagName; 466 document.getElementById("tag-name").textContent = elementInfo.tagName;
464 document.getElementById("node-id").textContent = elementInfo.idValue ? "#" + elementInfo.idValue : ""; 467 document.getElementById("node-id").textContent = elementInfo.idValue ? "#" + elementInfo.idValue : "";
465 var className = elementInfo.className; 468 var className = elementInfo.className;
466 if (className && className.length > 50) 469 if (className && className.length > 50)
467 className = className.substring(0, 50) + "\u2026"; 470 className = className.substring(0, 50) + "\u2026";
468 document.getElementById("class-name").textContent = className || ""; 471 document.getElementById("class-name").textContent = className || "";
469 document.getElementById("node-width").textContent = elementInfo.nodeWidth; 472 document.getElementById("node-width").textContent = elementInfo.nodeWidth;
470 document.getElementById("node-height").textContent = elementInfo.nodeHeight; 473 document.getElementById("node-height").textContent = elementInfo.nodeHeight;
471 var elementTitle = document.getElementById("element-title"); 474 var elementTitle = document.getElementById("element-title");
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 // Hide arrow if element is completely off the sides of the page. 584 // Hide arrow if element is completely off the sides of the page.
582 var arrowHidden = arrowX < pageMargin + tooltipBorderRadius || arrowX + arro wRadius * 2 > canvasWidth - pageMargin - tooltipBorderRadius; 585 var arrowHidden = arrowX < pageMargin + tooltipBorderRadius || arrowX + arro wRadius * 2 > canvasWidth - pageMargin - tooltipBorderRadius;
583 tooltipArrow.classList.toggle("hidden", arrowHidden); 586 tooltipArrow.classList.toggle("hidden", arrowHidden);
584 if (!arrowHidden) { 587 if (!arrowHidden) {
585 tooltipArrow.classList.toggle("tooltip-arrow-top", onTop); 588 tooltipArrow.classList.toggle("tooltip-arrow-top", onTop);
586 tooltipArrow.style.top = (onTop ? boxY + titleHeight : boxY - arrowRadiu s) + "px"; 589 tooltipArrow.style.top = (onTop ? boxY + titleHeight : boxY - arrowRadiu s) + "px";
587 tooltipArrow.style.left = arrowX + "px"; 590 tooltipArrow.style.left = arrowX + "px";
588 } 591 }
589 } 592 }
590 593
591 function _drawRulers(bounds, rulerAtRight, rulerAtBottom) 594 function _drawRulers(context, bounds, rulerAtRight, rulerAtBottom)
592 { 595 {
593 context.save(); 596 context.save();
594 var width = canvasWidth; 597 var width = canvasWidth;
595 var height = canvasHeight; 598 var height = canvasHeight;
596 context.strokeStyle = "rgba(128, 128, 128, 0.3)"; 599 context.strokeStyle = "rgba(128, 128, 128, 0.3)";
597 context.lineWidth = 1; 600 context.lineWidth = 1;
598 context.translate(0.5, 0.5); 601 context.translate(0.5, 0.5);
599 602
600 if (rulerAtRight) { 603 if (rulerAtRight) {
601 for (var y in bounds.rightmostXForY) { 604 for (var y in bounds.rightmostXForY) {
(...skipping 23 matching lines...) Expand all
625 context.beginPath(); 628 context.beginPath();
626 context.moveTo(x, 0); 629 context.moveTo(x, 0);
627 context.lineTo(x, bounds.topmostYForX[x]); 630 context.lineTo(x, bounds.topmostYForX[x]);
628 context.stroke(); 631 context.stroke();
629 } 632 }
630 } 633 }
631 634
632 context.restore(); 635 context.restore();
633 } 636 }
634 637
635 function drawPath(commands, fillColor, outlineColor, bounds, name) 638 function drawPath(context, commands, fillColor, outlineColor, bounds, name)
636 { 639 {
637 var commandsIndex = 0; 640 var commandsIndex = 0;
638 641
639 function extractPoints(count) 642 function extractPoints(count)
640 { 643 {
641 var points = []; 644 var points = [];
642 645
643 for (var i = 0; i < count; ++i) { 646 for (var i = 0; i < count; ++i) {
644 var x = Math.round(commands[commandsIndex++]); 647 var x = Math.round(commands[commandsIndex++]);
645 bounds.maxX = Math.max(bounds.maxX, x); 648 bounds.maxX = Math.max(bounds.maxX, x);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 context.restore(); 697 context.restore();
695 698
696 if (name) { 699 if (name) {
697 if (!window.hoverableAreas) 700 if (!window.hoverableAreas)
698 window.hoverableAreas = new Map(); 701 window.hoverableAreas = new Map();
699 702
700 window.hoverableAreas.set(name, path); 703 window.hoverableAreas.set(name, path);
701 } 704 }
702 } 705 }
703 706
704 function drawHighlight(highlight) 707 function drawHighlight(highlight, context)
705 { 708 {
709 context = context || window.context;
706 context.save(); 710 context.save();
707 711
708 var bounds = { 712 var bounds = {
709 minX: Number.MAX_VALUE, 713 minX: Number.MAX_VALUE,
710 minY: Number.MAX_VALUE, 714 minY: Number.MAX_VALUE,
711 maxX: Number.MIN_VALUE, 715 maxX: Number.MIN_VALUE,
712 maxY: Number.MIN_VALUE, 716 maxY: Number.MIN_VALUE,
713 leftmostXForY: {}, 717 leftmostXForY: {},
714 rightmostXForY: {}, 718 rightmostXForY: {},
715 topmostYForX: {}, 719 topmostYForX: {},
716 bottommostYForX: {} 720 bottommostYForX: {}
717 }; 721 };
718 722
719 for (var paths = highlight.paths.slice(); paths.length;) { 723 for (var paths = highlight.paths.slice(); paths.length;) {
720 var path = paths.pop(); 724 var path = paths.pop();
721 drawPath(path.path, path.fillColor, path.outlineColor, bounds, path.name ); 725 drawPath(context, path.path, path.fillColor, path.outlineColor, bounds, path.name);
722 if (paths.length) { 726 if (paths.length) {
723 context.save(); 727 context.save();
724 context.globalCompositeOperation = "destination-out"; 728 context.globalCompositeOperation = "destination-out";
725 drawPath(paths[paths.length - 1].path, "red", null, bounds); 729 drawPath(context, paths[paths.length - 1].path, "red", null, bounds) ;
726 context.restore(); 730 context.restore();
727 } 731 }
728 } 732 }
729 733
730 var rulerAtRight = highlight.paths.length && highlight.showRulers && bounds. minX < 20 && bounds.maxX + 20 < canvasWidth; 734 var rulerAtRight = highlight.paths.length && highlight.showRulers && bounds. minX < 20 && bounds.maxX + 20 < canvasWidth;
731 var rulerAtBottom = highlight.paths.length && highlight.showRulers && bounds .minY < 20 && bounds.maxY + 20 < canvasHeight; 735 var rulerAtBottom = highlight.paths.length && highlight.showRulers && bounds .minY < 20 && bounds.maxY + 20 < canvasHeight;
732 736
733 if (highlight.showRulers) 737 if (highlight.showRulers)
734 _drawGrid(rulerAtRight, rulerAtBottom); 738 _drawGrid(context, rulerAtRight, rulerAtBottom);
735 739
736 if (highlight.paths.length) { 740 if (highlight.paths.length) {
737 if (highlight.showExtensionLines) 741 if (highlight.showExtensionLines)
738 _drawRulers(bounds, rulerAtRight, rulerAtBottom); 742 _drawRulers(context, bounds, rulerAtRight, rulerAtBottom);
739 743
740 if (highlight.elementInfo && highlight.displayAsMaterial) 744 if (highlight.elementInfo && highlight.displayAsMaterial)
741 _drawMaterialElementTitle(highlight.elementInfo, bounds); 745 _drawMaterialElementTitle(highlight.elementInfo, bounds);
742 else if (highlight.elementInfo) 746 else if (highlight.elementInfo)
743 _drawElementTitle(highlight.elementInfo, bounds); 747 _drawElementTitle(context, highlight.elementInfo, bounds);
744 } 748 }
745 context.restore(); 749 context.restore();
746 } 750 }
747 751
748 function setPlatform(platform) 752 function setPlatform(platform)
749 { 753 {
750 window.platform = platform; 754 window.platform = platform;
751 document.body.classList.add("platform-" + platform); 755 document.body.classList.add("platform-" + platform);
752 } 756 }
753 757
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 } 817 }
814 818
815 if (selectedAnchorInfo) 819 if (selectedAnchorInfo)
816 showLabels(selectedAnchorInfo.type, selectedAnchorInfo.propertyName); 820 showLabels(selectedAnchorInfo.type, selectedAnchorInfo.propertyName);
817 821
818 document.addEventListener("mousedown", consumeEvent); 822 document.addEventListener("mousedown", consumeEvent);
819 document.addEventListener("mousemove", onLayoutEditorMouseMove); 823 document.addEventListener("mousemove", onLayoutEditorMouseMove);
820 document.addEventListener("mouseup", consumeEvent); 824 document.addEventListener("mouseup", consumeEvent);
821 document.addEventListener("click", onLayoutEditorClick); 825 document.addEventListener("click", onLayoutEditorClick);
822 document.addEventListener("keydown", onLayoutEditorKeyDown); 826 document.addEventListener("keydown", onLayoutEditorKeyDown);
827 document.addEventListener("mousewheel", onLayoutEditorMouseWheel);
828 showSelectorTooltip();
829 }
830
831 function showSelectorTooltip()
832 {
833 var tooltipElement = document.getElementById("selector-tooltip");
834 tooltipElement.style.visibility = "visible";
835 tooltipElement.style.left = "100px";
836 tooltipElement.style.top = "100px";
837 var selectorInfo = JSON.parse(InspectorOverlayHost.currentSelectorInfo());
838 tooltipElement.textContent = selectorInfo.selector;
839 tooltipElement.style.backgroundColor = "#eee";
840
841 var matchedNodesCanvas = document.getElementById("layout-editor-matched-node s-canvas");
842 resetCanvas(matchedNodesCanvas);
843
844 if (!selectorInfo.nodes)
845 return;
846
847 for (var nodeHighlight of selectorInfo.nodes)
848 drawHighlight(nodeHighlight, matchedNodesCanvas.getContext("2d"));
823 } 849 }
824 850
825 function createAnchor(anchorInfo) 851 function createAnchor(anchorInfo)
826 { 852 {
827 var handleWidth = 5; 853 var handleWidth = 5;
828 context.save(); 854 context.save();
829 context.shadowColor = "rgba(0, 0, 0, 0.34)"; 855 context.shadowColor = "rgba(0, 0, 0, 0.34)";
830 context.shadowBlur = 2; 856 context.shadowBlur = 2;
831 context.fillStyle = anchorColorForProperty(anchorInfo); 857 context.fillStyle = anchorColorForProperty(anchorInfo);
832 context.beginPath(); 858 context.beginPath();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 if (window.draggedPropertyName) 1085 if (window.draggedPropertyName)
1060 return; 1086 return;
1061 1087
1062 // Clear selection on Esc. 1088 // Clear selection on Esc.
1063 if (event.keyIdentifier === "U+001B") { 1089 if (event.keyIdentifier === "U+001B") {
1064 event.preventDefault(); 1090 event.preventDefault();
1065 InspectorOverlayHost.clearSelection(false); 1091 InspectorOverlayHost.clearSelection(false);
1066 } 1092 }
1067 } 1093 }
1068 1094
1095 function onLayoutEditorMouseWheel(event)
1096 {
1097 event.preventDefault();
1098 if (event.wheelDelta > 0)
1099 InspectorOverlayHost.previousSelector();
1100 else
1101 InspectorOverlayHost.nextSelector();
1102
1103 showSelectorTooltip();
1104 }
1105
1069 function consumeEvent(event) 1106 function consumeEvent(event)
1070 { 1107 {
1071 event.preventDefault(); 1108 event.preventDefault();
1072 } 1109 }
1073 1110
1074 function resetLabelCanvas() 1111 function resetLabelCanvas()
1075 { 1112 {
1076 delete window.labelCanvasState; 1113 delete window.labelCanvasState;
1077 resetCanvas(labelsCanvas); 1114 resetCanvas(labelsCanvas);
1078 if (!window.draggedPropertyName && document.body.style.cursor) 1115 if (!window.draggedPropertyName && document.body.style.cursor)
(...skipping 27 matching lines...) Expand all
1106 1143
1107 </script> 1144 </script>
1108 </head> 1145 </head>
1109 <body class="fill"> 1146 <body class="fill">
1110 <div class="controls-line"> 1147 <div class="controls-line">
1111 <div class="message-box"><div id="paused-in-debugger"></div></div> 1148 <div class="message-box"><div id="paused-in-debugger"></div></div>
1112 <div class="button" id="resume-button" title="Resume script execution (F8)." ><div class="glyph"></div></div> 1149 <div class="button" id="resume-button" title="Resume script execution (F8)." ><div class="glyph"></div></div>
1113 <div class="button" id="step-over-button" title="Step over next function cal l (F10)."><div class="glyph"></div></div> 1150 <div class="button" id="step-over-button" title="Step over next function cal l (F10)."><div class="glyph"></div></div>
1114 </div> 1151 </div>
1115 </body> 1152 </body>
1153 <canvas id="layout-editor-matched-nodes-canvas" class="fill"></canvas>
1116 <canvas id="canvas" class="fill"></canvas> 1154 <canvas id="canvas" class="fill"></canvas>
1117 <canvas id="labels-canvas" class="fill"></canvas> 1155 <canvas id="labels-canvas" class="fill"></canvas>
1118 <div id="element-title"> 1156 <div id="element-title">
1119 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s pan> 1157 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s pan>
1120 <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> 1158 <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>
1121 </div> 1159 </div>
1122 <div id="tooltip-container" class="hidden"> 1160 <div id="tooltip-container" class="hidden">
1123 <div id="element-tooltip"> 1161 <div id="element-tooltip">
1124 <div id="element-description" class="monospace"><span id="material-tag-nam e"></span><span id="material-node-id"></span><span id="material-class-name"></sp an></div> 1162 <div id="element-description" class="monospace"><span id="material-tag-nam e"></span><span id="material-node-id"></span><span id="material-class-name"></sp an></div>
1125 <div id="dimensions"><span id="material-node-width"></span>&#xD7;<span id= "material-node-height"></span></div> 1163 <div id="dimensions"><span id="material-node-width"></span>&#xD7;<span id= "material-node-height"></span></div>
1126 </div> 1164 </div>
1127 <div id="element-tooltip-arrow"></div> 1165 <div id="element-tooltip-arrow"></div>
1128 <div id="editor" class="fill"></div> 1166 <div id="editor" class="fill"></div>
1167 <div id="selector-tooltip"></div>
1129 <div id="log"></div> 1168 <div id="log"></div>
1130 </html> 1169 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698