layout/xul/test/window_resizer_element.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/test/window_resizer_element.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,188 @@
     1.4 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.5 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     1.6 +        align="start">
     1.7 +<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
     1.8 +<script><![CDATA[
     1.9 +var is = window.opener.SimpleTest.is;
    1.10 +window.onerror = window.opener.onerror;
    1.11 +
    1.12 +const anchorPositions =
    1.13 +  [ "before_start", "before_end", "after_start", "after_end",
    1.14 +    "start_before", "start_after", "end_before", "end_after", "overlap", "screen"];
    1.15 +var currentPosition;
    1.16 +
    1.17 +function testResizer(resizerid, noShrink, hResize, vResize, testid)
    1.18 +{
    1.19 +  var rect = document.getElementById(resizerid + "-container").getBoundingClientRect();
    1.20 +  var resizer = document.getElementById(resizerid);
    1.21 +  var resizerrect = resizer.getBoundingClientRect();
    1.22 +
    1.23 +  var originalX = resizerrect.left;
    1.24 +  var originalY = resizerrect.top;
    1.25 +
    1.26 +  const scale = 20;
    1.27 +  for (var mouseX = -1; mouseX <= 1; ++mouseX) {
    1.28 +    for (var mouseY = -1; mouseY <= 1; ++mouseY) {
    1.29 +      var expectedWidth = rect.width + hResize * mouseX * scale;
    1.30 +      var expectedHeight = rect.height + vResize * mouseY * scale;
    1.31 +
    1.32 +      if (noShrink) {
    1.33 +        if (mouseX == -1)
    1.34 +          expectedWidth = rect.width;
    1.35 +        if (mouseY == -1)
    1.36 +          expectedHeight = rect.height;
    1.37 +      }
    1.38 +
    1.39 +      synthesizeMouse(document.documentElement, originalX + 5, originalY + 5, { type:"mousedown" });
    1.40 +      synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
    1.41 +                      originalY + 5 + mouseY * scale, { type:"mousemove" });
    1.42 +
    1.43 +      var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect();
    1.44 +      is(Math.round(newrect.width), Math.round(expectedWidth), "resize element " + resizerid +
    1.45 +         " " + testid + " width moving " + mouseX + "," + mouseY + ",,," + hResize);
    1.46 +      is(Math.round(newrect.height), Math.round(expectedHeight), "resize element " + resizerid +
    1.47 +         " " + testid + " height moving " + mouseX + "," + mouseY);
    1.48 +      // release
    1.49 +      synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
    1.50 +                      originalY + 5 + mouseY * scale, { type:"mouseup" });
    1.51 +      // return to the original size
    1.52 +      synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
    1.53 +                      originalY + 5 + mouseY * scale, { type:"dblclick" });
    1.54 +      var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect();
    1.55 +      is(Math.round(newrect.width), Math.round(rect.width), "resize element " + resizerid +
    1.56 +         " " + testid + " doubleclicking to restore original size");
    1.57 +      is(Math.round(newrect.height), Math.round(rect.height), "resize element " + resizerid +
    1.58 +         " " + testid + " doubleclicking to restore original size");
    1.59 +    }
    1.60 +  }
    1.61 +}
    1.62 +
    1.63 +function doTest() {
    1.64 +  // first, check if a resizer with a element attribute set to an element that
    1.65 +  // does not exist does not cause a problem
    1.66 +  var resizer = document.getElementById("notfound");
    1.67 +  synthesizeMouse(resizer, 5, 5, { type:"mousedown" });
    1.68 +  synthesizeMouse(resizer, 10, 10, { type:"mousemove" });
    1.69 +  synthesizeMouse(resizer, 5, 5, { type:"mouseup" });
    1.70 +
    1.71 +  testResizer("outside", true, 1, 1, "");
    1.72 +  testResizer("html", true, 1, 1, "");
    1.73 +  testResizer("inside", true, 1, 1, "");
    1.74 +  testResizer("inside-large", false, 1, 1, "");
    1.75 +  testResizer("inside-with-border", true, 1, 1, "");
    1.76 +
    1.77 +  document.getElementById("inside-popup-container").
    1.78 +    openPopupAtScreen(Math.ceil(window.mozInnerScreenX) + 100, Math.ceil(window.mozInnerScreenY) + 100);
    1.79 +}
    1.80 +
    1.81 +function popupShown(event)
    1.82 +{
    1.83 +  testResizer("inside-popup", false, 1, 1, "");
    1.84 +  document.getElementById("inside-popup-container").id = "outside-popup-container";
    1.85 +  testResizer("outside-popup", false, 1, 1, "");
    1.86 +
    1.87 +  var resizerrect = document.getElementById("inside-popup").getBoundingClientRect();
    1.88 +  synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mousedown" });
    1.89 +  synthesizeMouse(document.documentElement, resizerrect.left + 2000, resizerrect.top + 2000, { type:"mousemove" });
    1.90 +
    1.91 +  var isMac = (navigator.platform.indexOf("Mac") >= 0);
    1.92 +  var popuprect = document.getElementById("outside-popup-container").getBoundingClientRect();
    1.93 +  // subtract 3 due to space left for panel dropshadow
    1.94 +  is(Math.ceil(window.mozInnerScreenX) + popuprect.right,
    1.95 +     (isMac ? screen.availLeft + screen.availWidth : screen.left + screen.width) - 3, "resized to edge width");
    1.96 +  is(Math.ceil(window.mozInnerScreenY) + popuprect.bottom,
    1.97 +     (isMac ? screen.availTop + screen.availHeight : screen.top + screen.height) - 3, "resized to edge height");
    1.98 +
    1.99 +  resizerrect = document.getElementById("inside-popup").getBoundingClientRect();
   1.100 +  synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mouseup" });
   1.101 +
   1.102 +  event.target.hidePopup();
   1.103 +}
   1.104 +
   1.105 +function popupHidden()
   1.106 +{
   1.107 +  if (anchorPositions.length == 0) {
   1.108 +    window.close();
   1.109 +    window.opener.SimpleTest.finish();
   1.110 +    return;
   1.111 +  }
   1.112 +
   1.113 +  currentPosition = anchorPositions.shift();
   1.114 +  var anchor = document.getElementById("anchor");
   1.115 +  var popup = document.getElementById("anchored-panel-container");
   1.116 +
   1.117 +  if (currentPosition == "screen")
   1.118 +    popup.openPopupAtScreen(window.screenX + 100, window.screenY + 100);
   1.119 +  else
   1.120 +    popup.openPopup(anchor, currentPosition);
   1.121 +}
   1.122 +
   1.123 +function anchoredPopupShown(event)
   1.124 +{
   1.125 +  var leftAllowed = (currentPosition.indexOf("end_") == -1 && currentPosition.indexOf("_start") == -1);
   1.126 +  var rightAllowed = (currentPosition.indexOf("start_") == -1 && currentPosition.indexOf("_end") == -1);
   1.127 +  var topAllowed = (currentPosition.indexOf("after_") == -1 && currentPosition.indexOf("_before") == -1);
   1.128 +  var bottomAllowed = (currentPosition.indexOf("before_") == -1 && currentPosition.indexOf("_after") == -1);
   1.129 +
   1.130 +  if (currentPosition == "overlap") {
   1.131 +    leftAllowed = topAllowed = false;
   1.132 +    rightAllowed = bottomAllowed = true;
   1.133 +  }
   1.134 +
   1.135 +  var resizerTypes = [ "topleft", "top", "topright", "left", "right",
   1.136 +                       "bottomleft", "bottom", "bottomright", "bottomend" ];
   1.137 +  for (var r = 0; r < resizerTypes.length; r++) {
   1.138 +    var resizerType = resizerTypes[r];
   1.139 +    var horiz = 0, vert = 0;
   1.140 +    if (leftAllowed && resizerType.indexOf("left") >= 0) horiz = -1;
   1.141 +    else if (rightAllowed && (resizerType.indexOf("right") >= 0 || resizerType == "bottomend")) horiz = 1;
   1.142 +
   1.143 +    if (topAllowed && resizerType.indexOf("top") >= 0) vert = -1;
   1.144 +    else if (bottomAllowed && resizerType.indexOf("bottom") >= 0) vert = 1;
   1.145 +
   1.146 +    document.getElementById("anchored-panel").dir = resizerType;
   1.147 +    testResizer("anchored-panel", false, horiz, vert, currentPosition + " " + resizerType);
   1.148 +  }
   1.149 +
   1.150 +  event.target.hidePopup();
   1.151 +}
   1.152 +
   1.153 +window.opener.SimpleTest.waitForFocus(doTest, window);
   1.154 +]]></script>
   1.155 +
   1.156 +<resizer id="outside" dir="bottomend" element="outside-container"/>
   1.157 +<resizer id="notfound" dir="bottomend" element="nothing"/>
   1.158 +<hbox id="outside-container">
   1.159 +  <hbox minwidth="46" minheight="39"/>
   1.160 +</hbox>
   1.161 +<html:div id="html-container" xmlns:html="http://www.w3.org/1999/xhtml">
   1.162 +  <html:button>One</html:button><html:br/>
   1.163 +  <resizer id="html" dir="bottomend" element="_parent"/>
   1.164 +</html:div>
   1.165 +<hbox id="anchor" align="start" style="margin-left: 100px;">
   1.166 +  <hbox id="inside-container" align="start">
   1.167 +    <hbox minwidth="45" minheight="41"/>
   1.168 +    <resizer id="inside" dir="bottomend" element="_parent"/>
   1.169 +  </hbox>
   1.170 +  <hbox id="inside-large-container" width="70" height="70" align="start">
   1.171 +    <resizer id="inside-large" dir="bottomend" element="_parent"/>
   1.172 +  </hbox>
   1.173 +  <hbox id="inside-with-border-container" style="border: 5px solid red; padding: 2px; margin: 2px;" align="start">
   1.174 +    <hbox minwidth="35" minheight="30"/>
   1.175 +    <resizer id="inside-with-border" dir="bottomend" element="_parent"/>
   1.176 +  </hbox>
   1.177 +</hbox>
   1.178 +
   1.179 +<panel id="inside-popup-container" align="start" onpopupshown="popupShown(event)" onpopuphidden="popupHidden()">
   1.180 +  <resizer id="inside-popup" dir="bottomend"/>
   1.181 +  <hbox width="50" height="50" flex="1"/>
   1.182 +</panel>
   1.183 +<resizer id="outside-popup" dir="bottomend" element="outside-popup-container"/>
   1.184 +
   1.185 +<panel id="anchored-panel-container" align="start" onpopupshown="anchoredPopupShown(event)"
   1.186 +       onpopuphidden="popupHidden()">
   1.187 +  <hbox width="50" height="50" flex="1"/>
   1.188 +  <resizer id="anchored-panel" width="20" height="20"/>
   1.189 +</panel>
   1.190 +
   1.191 +</window>

mercurial