Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 2 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 3 | align="start"> |
michael@0 | 4 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 5 | <script><![CDATA[ |
michael@0 | 6 | var is = window.opener.SimpleTest.is; |
michael@0 | 7 | window.onerror = window.opener.onerror; |
michael@0 | 8 | |
michael@0 | 9 | const anchorPositions = |
michael@0 | 10 | [ "before_start", "before_end", "after_start", "after_end", |
michael@0 | 11 | "start_before", "start_after", "end_before", "end_after", "overlap", "screen"]; |
michael@0 | 12 | var currentPosition; |
michael@0 | 13 | |
michael@0 | 14 | function testResizer(resizerid, noShrink, hResize, vResize, testid) |
michael@0 | 15 | { |
michael@0 | 16 | var rect = document.getElementById(resizerid + "-container").getBoundingClientRect(); |
michael@0 | 17 | var resizer = document.getElementById(resizerid); |
michael@0 | 18 | var resizerrect = resizer.getBoundingClientRect(); |
michael@0 | 19 | |
michael@0 | 20 | var originalX = resizerrect.left; |
michael@0 | 21 | var originalY = resizerrect.top; |
michael@0 | 22 | |
michael@0 | 23 | const scale = 20; |
michael@0 | 24 | for (var mouseX = -1; mouseX <= 1; ++mouseX) { |
michael@0 | 25 | for (var mouseY = -1; mouseY <= 1; ++mouseY) { |
michael@0 | 26 | var expectedWidth = rect.width + hResize * mouseX * scale; |
michael@0 | 27 | var expectedHeight = rect.height + vResize * mouseY * scale; |
michael@0 | 28 | |
michael@0 | 29 | if (noShrink) { |
michael@0 | 30 | if (mouseX == -1) |
michael@0 | 31 | expectedWidth = rect.width; |
michael@0 | 32 | if (mouseY == -1) |
michael@0 | 33 | expectedHeight = rect.height; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | synthesizeMouse(document.documentElement, originalX + 5, originalY + 5, { type:"mousedown" }); |
michael@0 | 37 | synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale, |
michael@0 | 38 | originalY + 5 + mouseY * scale, { type:"mousemove" }); |
michael@0 | 39 | |
michael@0 | 40 | var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect(); |
michael@0 | 41 | is(Math.round(newrect.width), Math.round(expectedWidth), "resize element " + resizerid + |
michael@0 | 42 | " " + testid + " width moving " + mouseX + "," + mouseY + ",,," + hResize); |
michael@0 | 43 | is(Math.round(newrect.height), Math.round(expectedHeight), "resize element " + resizerid + |
michael@0 | 44 | " " + testid + " height moving " + mouseX + "," + mouseY); |
michael@0 | 45 | // release |
michael@0 | 46 | synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale, |
michael@0 | 47 | originalY + 5 + mouseY * scale, { type:"mouseup" }); |
michael@0 | 48 | // return to the original size |
michael@0 | 49 | synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale, |
michael@0 | 50 | originalY + 5 + mouseY * scale, { type:"dblclick" }); |
michael@0 | 51 | var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect(); |
michael@0 | 52 | is(Math.round(newrect.width), Math.round(rect.width), "resize element " + resizerid + |
michael@0 | 53 | " " + testid + " doubleclicking to restore original size"); |
michael@0 | 54 | is(Math.round(newrect.height), Math.round(rect.height), "resize element " + resizerid + |
michael@0 | 55 | " " + testid + " doubleclicking to restore original size"); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function doTest() { |
michael@0 | 61 | // first, check if a resizer with a element attribute set to an element that |
michael@0 | 62 | // does not exist does not cause a problem |
michael@0 | 63 | var resizer = document.getElementById("notfound"); |
michael@0 | 64 | synthesizeMouse(resizer, 5, 5, { type:"mousedown" }); |
michael@0 | 65 | synthesizeMouse(resizer, 10, 10, { type:"mousemove" }); |
michael@0 | 66 | synthesizeMouse(resizer, 5, 5, { type:"mouseup" }); |
michael@0 | 67 | |
michael@0 | 68 | testResizer("outside", true, 1, 1, ""); |
michael@0 | 69 | testResizer("html", true, 1, 1, ""); |
michael@0 | 70 | testResizer("inside", true, 1, 1, ""); |
michael@0 | 71 | testResizer("inside-large", false, 1, 1, ""); |
michael@0 | 72 | testResizer("inside-with-border", true, 1, 1, ""); |
michael@0 | 73 | |
michael@0 | 74 | document.getElementById("inside-popup-container"). |
michael@0 | 75 | openPopupAtScreen(Math.ceil(window.mozInnerScreenX) + 100, Math.ceil(window.mozInnerScreenY) + 100); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function popupShown(event) |
michael@0 | 79 | { |
michael@0 | 80 | testResizer("inside-popup", false, 1, 1, ""); |
michael@0 | 81 | document.getElementById("inside-popup-container").id = "outside-popup-container"; |
michael@0 | 82 | testResizer("outside-popup", false, 1, 1, ""); |
michael@0 | 83 | |
michael@0 | 84 | var resizerrect = document.getElementById("inside-popup").getBoundingClientRect(); |
michael@0 | 85 | synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mousedown" }); |
michael@0 | 86 | synthesizeMouse(document.documentElement, resizerrect.left + 2000, resizerrect.top + 2000, { type:"mousemove" }); |
michael@0 | 87 | |
michael@0 | 88 | var isMac = (navigator.platform.indexOf("Mac") >= 0); |
michael@0 | 89 | var popuprect = document.getElementById("outside-popup-container").getBoundingClientRect(); |
michael@0 | 90 | // subtract 3 due to space left for panel dropshadow |
michael@0 | 91 | is(Math.ceil(window.mozInnerScreenX) + popuprect.right, |
michael@0 | 92 | (isMac ? screen.availLeft + screen.availWidth : screen.left + screen.width) - 3, "resized to edge width"); |
michael@0 | 93 | is(Math.ceil(window.mozInnerScreenY) + popuprect.bottom, |
michael@0 | 94 | (isMac ? screen.availTop + screen.availHeight : screen.top + screen.height) - 3, "resized to edge height"); |
michael@0 | 95 | |
michael@0 | 96 | resizerrect = document.getElementById("inside-popup").getBoundingClientRect(); |
michael@0 | 97 | synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mouseup" }); |
michael@0 | 98 | |
michael@0 | 99 | event.target.hidePopup(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function popupHidden() |
michael@0 | 103 | { |
michael@0 | 104 | if (anchorPositions.length == 0) { |
michael@0 | 105 | window.close(); |
michael@0 | 106 | window.opener.SimpleTest.finish(); |
michael@0 | 107 | return; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | currentPosition = anchorPositions.shift(); |
michael@0 | 111 | var anchor = document.getElementById("anchor"); |
michael@0 | 112 | var popup = document.getElementById("anchored-panel-container"); |
michael@0 | 113 | |
michael@0 | 114 | if (currentPosition == "screen") |
michael@0 | 115 | popup.openPopupAtScreen(window.screenX + 100, window.screenY + 100); |
michael@0 | 116 | else |
michael@0 | 117 | popup.openPopup(anchor, currentPosition); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function anchoredPopupShown(event) |
michael@0 | 121 | { |
michael@0 | 122 | var leftAllowed = (currentPosition.indexOf("end_") == -1 && currentPosition.indexOf("_start") == -1); |
michael@0 | 123 | var rightAllowed = (currentPosition.indexOf("start_") == -1 && currentPosition.indexOf("_end") == -1); |
michael@0 | 124 | var topAllowed = (currentPosition.indexOf("after_") == -1 && currentPosition.indexOf("_before") == -1); |
michael@0 | 125 | var bottomAllowed = (currentPosition.indexOf("before_") == -1 && currentPosition.indexOf("_after") == -1); |
michael@0 | 126 | |
michael@0 | 127 | if (currentPosition == "overlap") { |
michael@0 | 128 | leftAllowed = topAllowed = false; |
michael@0 | 129 | rightAllowed = bottomAllowed = true; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | var resizerTypes = [ "topleft", "top", "topright", "left", "right", |
michael@0 | 133 | "bottomleft", "bottom", "bottomright", "bottomend" ]; |
michael@0 | 134 | for (var r = 0; r < resizerTypes.length; r++) { |
michael@0 | 135 | var resizerType = resizerTypes[r]; |
michael@0 | 136 | var horiz = 0, vert = 0; |
michael@0 | 137 | if (leftAllowed && resizerType.indexOf("left") >= 0) horiz = -1; |
michael@0 | 138 | else if (rightAllowed && (resizerType.indexOf("right") >= 0 || resizerType == "bottomend")) horiz = 1; |
michael@0 | 139 | |
michael@0 | 140 | if (topAllowed && resizerType.indexOf("top") >= 0) vert = -1; |
michael@0 | 141 | else if (bottomAllowed && resizerType.indexOf("bottom") >= 0) vert = 1; |
michael@0 | 142 | |
michael@0 | 143 | document.getElementById("anchored-panel").dir = resizerType; |
michael@0 | 144 | testResizer("anchored-panel", false, horiz, vert, currentPosition + " " + resizerType); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | event.target.hidePopup(); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | window.opener.SimpleTest.waitForFocus(doTest, window); |
michael@0 | 151 | ]]></script> |
michael@0 | 152 | |
michael@0 | 153 | <resizer id="outside" dir="bottomend" element="outside-container"/> |
michael@0 | 154 | <resizer id="notfound" dir="bottomend" element="nothing"/> |
michael@0 | 155 | <hbox id="outside-container"> |
michael@0 | 156 | <hbox minwidth="46" minheight="39"/> |
michael@0 | 157 | </hbox> |
michael@0 | 158 | <html:div id="html-container" xmlns:html="http://www.w3.org/1999/xhtml"> |
michael@0 | 159 | <html:button>One</html:button><html:br/> |
michael@0 | 160 | <resizer id="html" dir="bottomend" element="_parent"/> |
michael@0 | 161 | </html:div> |
michael@0 | 162 | <hbox id="anchor" align="start" style="margin-left: 100px;"> |
michael@0 | 163 | <hbox id="inside-container" align="start"> |
michael@0 | 164 | <hbox minwidth="45" minheight="41"/> |
michael@0 | 165 | <resizer id="inside" dir="bottomend" element="_parent"/> |
michael@0 | 166 | </hbox> |
michael@0 | 167 | <hbox id="inside-large-container" width="70" height="70" align="start"> |
michael@0 | 168 | <resizer id="inside-large" dir="bottomend" element="_parent"/> |
michael@0 | 169 | </hbox> |
michael@0 | 170 | <hbox id="inside-with-border-container" style="border: 5px solid red; padding: 2px; margin: 2px;" align="start"> |
michael@0 | 171 | <hbox minwidth="35" minheight="30"/> |
michael@0 | 172 | <resizer id="inside-with-border" dir="bottomend" element="_parent"/> |
michael@0 | 173 | </hbox> |
michael@0 | 174 | </hbox> |
michael@0 | 175 | |
michael@0 | 176 | <panel id="inside-popup-container" align="start" onpopupshown="popupShown(event)" onpopuphidden="popupHidden()"> |
michael@0 | 177 | <resizer id="inside-popup" dir="bottomend"/> |
michael@0 | 178 | <hbox width="50" height="50" flex="1"/> |
michael@0 | 179 | </panel> |
michael@0 | 180 | <resizer id="outside-popup" dir="bottomend" element="outside-popup-container"/> |
michael@0 | 181 | |
michael@0 | 182 | <panel id="anchored-panel-container" align="start" onpopupshown="anchoredPopupShown(event)" |
michael@0 | 183 | onpopuphidden="popupHidden()"> |
michael@0 | 184 | <hbox width="50" height="50" flex="1"/> |
michael@0 | 185 | <resizer id="anchored-panel" width="20" height="20"/> |
michael@0 | 186 | </panel> |
michael@0 | 187 | |
michael@0 | 188 | </window> |