layout/xul/test/window_resizer_element.xul

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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

mercurial