window_resizer_element.xul 8.1 KB

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