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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 anchorElement.style.left = anchorInfo.x - handleWidth + "px"; | 830 anchorElement.style.left = anchorInfo.x - handleWidth + "px"; |
831 anchorElement.style.top = anchorInfo.y - handleWidth + "px"; | 831 anchorElement.style.top = anchorInfo.y - handleWidth + "px"; |
832 if (anchorInfo.propertyValue.mutable) | 832 if (anchorInfo.propertyValue.mutable) |
833 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null,
anchorInfo)); | 833 anchorElement.addEventListener("mousedown", onAnchorMouseDown.bind(null,
anchorInfo)); |
834 anchorElement.addEventListener("mousemove", onAnchorMouseMove.bind(null, anc
horInfo)); | 834 anchorElement.addEventListener("mousemove", onAnchorMouseMove.bind(null, anc
horInfo)); |
835 return anchorElement; | 835 return anchorElement; |
836 } | 836 } |
837 | 837 |
838 function calculateDelta(deltaVector, moveDelta) | 838 function calculateDelta(deltaVector, moveDelta) |
839 { | 839 { |
840 return (deltaVector.x * moveDelta.x + deltaVector.y * moveDelta.y) / Math.sq
rt(deltaVector.x * deltaVector.x + deltaVector.y * deltaVector.y); | 840 return scalarProduct(deltaVector, moveDelta) / Math.sqrt(scalarProduct(delta
Vector, deltaVector)); |
841 } | 841 } |
842 | 842 |
843 function onAnchorMouseDown(anchorInfo, event) | 843 function onAnchorMouseDown(anchorInfo, event) |
844 { | 844 { |
845 // Only drag upon left button. Right will likely cause a context menu. So wi
ll ctrl-click on mac. | 845 // Only drag upon left button. Right will likely cause a context menu. So wi
ll ctrl-click on mac. |
846 if (event.button || (window.platform == "mac" && event.ctrlKey)) | 846 if (event.button || (window.platform == "mac" && event.ctrlKey)) |
847 return; | 847 return; |
848 | 848 |
849 event.preventDefault(); | 849 event.preventDefault(); |
850 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event.
screenY), anchorInfo.deltaVector); | 850 window.boundDragMove = onDragMove.bind(null, new Point(event.screenX, event.
screenY), anchorInfo.deltaVector); |
851 document.addEventListener("mousemove", boundDragMove); | 851 document.addEventListener("mousemove", boundDragMove); |
852 document.addEventListener("mouseup", onDragEnd); | 852 document.addEventListener("mouseup", onDragEnd); |
853 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName); | 853 InspectorOverlayHost.startPropertyChange(anchorInfo.propertyName); |
854 window.draggedPropertyName = anchorInfo.propertyName; | 854 window.draggedPropertyName = anchorInfo.propertyName; |
855 showLabels(anchorInfo.type, anchorInfo.propertyName); | 855 showLabels(anchorInfo.type, anchorInfo.propertyName); |
856 } | 856 } |
857 | 857 |
858 function onDragMove(mouseDownPoint, deltaVector, event) | 858 function onDragMove(mouseDownPoint, deltaVector, event) |
859 { | 859 { |
860 if (event.buttons !== 1) { | 860 if (event.buttons !== 1) { |
861 onDragEnd(event); | 861 onDragEnd(event); |
862 return; | 862 return; |
863 } | 863 } |
864 event.preventDefault(); | 864 event.preventDefault(); |
865 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev
ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y))); | 865 InspectorOverlayHost.changeProperty(calculateDelta(deltaVector, new Point(ev
ent.screenX - mouseDownPoint.x, event.screenY - mouseDownPoint.y))); |
866 } | 866 } |
867 | 867 |
| 868 function onDragEnd(event) |
| 869 { |
| 870 document.removeEventListener("mousemove", boundDragMove); |
| 871 delete window.boundDragMove; |
| 872 delete window.draggedPropertyName; |
| 873 document.removeEventListener("mouseup", onDragEnd); |
| 874 event.preventDefault(); |
| 875 InspectorOverlayHost.endPropertyChange(); |
| 876 resetLabelCanvas(); |
| 877 } |
| 878 |
868 function showLabel(anchorInfo, showLongDescription) | 879 function showLabel(anchorInfo, showLongDescription) |
869 { | 880 { |
870 var context = labelsCanvas.getContext("2d"); | 881 var context = labelsCanvas.getContext("2d"); |
871 var secondaryColor = "rgba(255, 255, 255, 0.7)"; | 882 var secondaryColor = "rgba(255, 255, 255, 0.7)"; |
872 var labelColor = labelColorForProperty(anchorInfo); | 883 var labelColor = labelColorForProperty(anchorInfo); |
873 var textDescription = [ | 884 var textDescription = [ |
874 {string: String(parseFloat(anchorInfo.propertyValue.value.toFixed(2))),
color: "white" }, | 885 {string: String(parseFloat(anchorInfo.propertyValue.value.toFixed(2))),
color: "white" }, |
875 {string: "\u2009" + anchorInfo.propertyValue.unit, color: secondaryColor
} | 886 {string: "\u2009" + anchorInfo.propertyValue.unit, color: secondaryColor
} |
876 ]; | 887 ]; |
877 | 888 |
(...skipping 14 matching lines...) Expand all Loading... |
892 window.labelCanvasState = {type: type, fullLabelName: fullLabelName}; | 903 window.labelCanvasState = {type: type, fullLabelName: fullLabelName}; |
893 var anchors = anchorsByType.get(type) || []; | 904 var anchors = anchorsByType.get(type) || []; |
894 var selectedAnchorInfo = null; | 905 var selectedAnchorInfo = null; |
895 for (var anchorInfo of anchors) { | 906 for (var anchorInfo of anchors) { |
896 if (fullLabelName !== anchorInfo.propertyName) | 907 if (fullLabelName !== anchorInfo.propertyName) |
897 showLabel(anchorInfo, false); | 908 showLabel(anchorInfo, false); |
898 else | 909 else |
899 selectedAnchorInfo = anchorInfo; | 910 selectedAnchorInfo = anchorInfo; |
900 } | 911 } |
901 | 912 |
902 if (selectedAnchorInfo) | 913 if (!selectedAnchorInfo) |
903 showLabel(selectedAnchorInfo, true); | 914 return; |
904 } | |
905 | 915 |
906 function onDragEnd(event) | 916 showLabel(selectedAnchorInfo, true); |
907 { | 917 document.body.style.cursor = chooseAnchorPointer(selectedAnchorInfo.deltaVec
tor); |
908 document.removeEventListener("mousemove", boundDragMove); | |
909 delete window.boundDragMove; | |
910 delete window.draggedPropertyName; | |
911 document.removeEventListener("mouseup", onDragEnd); | |
912 event.preventDefault(); | |
913 InspectorOverlayHost.endPropertyChange(); | |
914 resetLabelCanvas(); | |
915 } | 918 } |
916 | 919 |
917 function onAnchorMouseMove(anchorInfo) | 920 function onAnchorMouseMove(anchorInfo) |
918 { | 921 { |
919 if (window.draggedPropertyName) | 922 if (window.draggedPropertyName) |
920 return; | 923 return; |
921 event.preventDefault(); | 924 event.preventDefault(); |
922 event.stopPropagation(); | 925 event.stopPropagation(); |
923 showLabels(anchorInfo.type, anchorInfo.propertyName); | 926 showLabels(anchorInfo.type, anchorInfo.propertyName); |
924 } | 927 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 } | 1024 } |
1022 | 1025 |
1023 function onGlobalMouseMove(event) | 1026 function onGlobalMouseMove(event) |
1024 { | 1027 { |
1025 if (!window.hoverableAreas) | 1028 if (!window.hoverableAreas) |
1026 return; | 1029 return; |
1027 var types = ["padding", "margin"]; | 1030 var types = ["padding", "margin"]; |
1028 for (var type of types) { | 1031 for (var type of types) { |
1029 var path = hoverableAreas.get(type); | 1032 var path = hoverableAreas.get(type); |
1030 if (path && context.isPointInPath(path, deviceScaleFactor * event.x, dev
iceScaleFactor * event.y)) { | 1033 if (path && context.isPointInPath(path, deviceScaleFactor * event.x, dev
iceScaleFactor * event.y)) { |
| 1034 event.preventDefault(); |
1031 showLabels(type); | 1035 showLabels(type); |
1032 break; | 1036 return; |
1033 } | 1037 } |
1034 } | 1038 } |
| 1039 resetLabelCanvas(); |
1035 } | 1040 } |
1036 | 1041 |
1037 function resetLabelCanvas() | 1042 function resetLabelCanvas() |
1038 { | 1043 { |
1039 delete window.labelCanvasState; | 1044 delete window.labelCanvasState; |
1040 resetCanvas(labelsCanvas); | 1045 resetCanvas(labelsCanvas); |
| 1046 if (!window.draggedPropertyName && document.body.style.cursor) |
| 1047 document.body.style.cursor = ""; |
| 1048 } |
| 1049 |
| 1050 function scalarProduct(v1, v2) |
| 1051 { |
| 1052 return v1.x * v2.x + v1.y * v2.y; |
| 1053 } |
| 1054 |
| 1055 var pointers = [ {name: "ns-resize", vector: new Point(0, -1)}, {name: "ew-resiz
e", vector: new Point(-1, 0)}, |
| 1056 {name: "ns-resize", vector: new Point(0, 1)}, {name: "ew-resize", vector: ne
w Point(1, 0)}]; |
| 1057 |
| 1058 function chooseAnchorPointer(direction) |
| 1059 { |
| 1060 var maxValue = scalarProduct(direction, pointers[0].vector); |
| 1061 var maxIndex = 0; |
| 1062 for (var i = 1; i < pointers.length; ++i) { |
| 1063 var currentValue = scalarProduct(direction, pointers[i].vector); |
| 1064 if (currentValue > maxValue) { |
| 1065 maxValue = currentValue; |
| 1066 maxIndex = i; |
| 1067 } |
| 1068 } |
| 1069 return pointers[maxIndex].name; |
1041 } | 1070 } |
1042 | 1071 |
1043 window.addEventListener("DOMContentLoaded", onLoaded); | 1072 window.addEventListener("DOMContentLoaded", onLoaded); |
1044 document.addEventListener("keydown", onDocumentKeyDown); | 1073 document.addEventListener("keydown", onDocumentKeyDown); |
1045 | 1074 |
1046 </script> | 1075 </script> |
1047 </head> | 1076 </head> |
1048 <body class="fill"> | 1077 <body class="fill"> |
1049 <div class="controls-line"> | 1078 <div class="controls-line"> |
1050 <div class="message-box"><div id="paused-in-debugger"></div></div> | 1079 <div class="message-box"><div id="paused-in-debugger"></div></div> |
1051 <div class="button" id="resume-button" title="Resume script execution (F8)."
><div class="glyph"></div></div> | 1080 <div class="button" id="resume-button" title="Resume script execution (F8)."
><div class="glyph"></div></div> |
1052 <div class="button" id="step-over-button" title="Step over next function cal
l (F10)."><div class="glyph"></div></div> | 1081 <div class="button" id="step-over-button" title="Step over next function cal
l (F10)."><div class="glyph"></div></div> |
1053 </div> | 1082 </div> |
1054 </body> | 1083 </body> |
1055 <canvas id="canvas" class="fill"></canvas> | 1084 <canvas id="canvas" class="fill"></canvas> |
1056 <canvas id="labels-canvas" class="fill"></canvas> | 1085 <canvas id="labels-canvas" class="fill"></canvas> |
1057 <div id="element-title"> | 1086 <div id="element-title"> |
1058 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s
pan> | 1087 <span id="tag-name"></span><span id="node-id"></span><span id="class-name"></s
pan> |
1059 <span id="node-width"></span><span class="px">px</span><span class="px"> ×
; </span><span id="node-height"></span><span class="px">px</span> | 1088 <span id="node-width"></span><span class="px">px</span><span class="px"> ×
; </span><span id="node-height"></span><span class="px">px</span> |
1060 </div> | 1089 </div> |
1061 <div id="tooltip-container" class="hidden"> | 1090 <div id="tooltip-container" class="hidden"> |
1062 <div id="element-tooltip"> | 1091 <div id="element-tooltip"> |
1063 <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> | 1092 <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> |
1064 <div id="dimensions"><span id="material-node-width"></span>×<span id=
"material-node-height"></span></div> | 1093 <div id="dimensions"><span id="material-node-width"></span>×<span id=
"material-node-height"></span></div> |
1065 </div> | 1094 </div> |
1066 <div id="element-tooltip-arrow"></div> | 1095 <div id="element-tooltip-arrow"></div> |
1067 <div id="editor" class="fill"></div> | 1096 <div id="editor" class="fill"></div> |
1068 <div id="log"></div> | 1097 <div id="log"></div> |
1069 </html> | 1098 </html> |
OLD | NEW |