|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 |
|
5 <window title="Popups in Scaled Content" |
|
6 onload="setTimeout(runTests, 0);" |
|
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
8 |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
11 |
|
12 <!-- This test checks that the position is correct in two cases: |
|
13 - a popup anchored at an element in a scaled document |
|
14 - a popup opened at a screen coordinate in a scaled window |
|
15 --> |
|
16 |
|
17 <iframe id="frame" width="60" height="140" |
|
18 src="data:text/html,<html><body><input size='4' id='one'><input size='4' id='two'></body></html>"/> |
|
19 |
|
20 <menupopup id="popup" onpopupshown="shown()" onpopuphidden="nextTest()"> |
|
21 <menuitem label="One"/> |
|
22 </menupopup> |
|
23 |
|
24 <script class="testbody" type="application/javascript"> |
|
25 <![CDATA[ |
|
26 |
|
27 var screenTest = false; |
|
28 var screenx = -1, screeny = -1; |
|
29 |
|
30 SimpleTest.waitForExplicitFinish(); |
|
31 |
|
32 function runTests() |
|
33 { |
|
34 setScale($("frame").contentWindow, 2); |
|
35 |
|
36 var anchor = $("frame").contentDocument.getElementById("two"); |
|
37 anchor.getBoundingClientRect(); // flush to update display after scale change |
|
38 $("popup").openPopup(anchor, "after_start"); |
|
39 } |
|
40 |
|
41 function setScale(win, scale) |
|
42 { |
|
43 var wn = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
|
44 .getInterface(Components.interfaces.nsIWebNavigation); |
|
45 var shell = wn.QueryInterface(Components.interfaces.nsIDocShell); |
|
46 var docViewer = shell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer); |
|
47 docViewer.fullZoom = scale; |
|
48 } |
|
49 |
|
50 function shown() |
|
51 { |
|
52 if (screenTest) { |
|
53 var box = $("popup").boxObject; |
|
54 is(box.screenX, screenx, "screen left position"); |
|
55 is(box.screenY, screeny, "screen top position"); |
|
56 } |
|
57 else { |
|
58 var anchor = $("frame").contentDocument.getElementById("two"); |
|
59 |
|
60 is(Math.round(anchor.getBoundingClientRect().left * 2), |
|
61 Math.round($("popup").getBoundingClientRect().left), "anchored left position"); |
|
62 is(Math.round(anchor.getBoundingClientRect().bottom * 2), |
|
63 Math.round($("popup").getBoundingClientRect().top), "anchored top position"); |
|
64 } |
|
65 |
|
66 $("popup").hidePopup(); |
|
67 } |
|
68 |
|
69 function nextTest() |
|
70 { |
|
71 if (screenTest) { |
|
72 setScale(window, 1); |
|
73 SimpleTest.finish(); |
|
74 } |
|
75 else { |
|
76 screenTest = true; |
|
77 var box = document.documentElement.boxObject; |
|
78 |
|
79 // - the iframe is at 4×, but out here css pixels are only 2× device pixels |
|
80 // - the popup manager rounds off (or truncates) the coordinates to |
|
81 // integers, so ensure we pass in even numbers to openPopupAtScreen |
|
82 screenx = (x = even(box.screenX + 120))/2; |
|
83 screeny = (y = even(box.screenY + 120))/2; |
|
84 setScale(window, 2); |
|
85 $("popup").openPopupAtScreen(x, y); |
|
86 } |
|
87 } |
|
88 |
|
89 function even(n) |
|
90 { |
|
91 return (n % 2) ? n+1 : n; |
|
92 } |
|
93 ]]> |
|
94 </script> |
|
95 |
|
96 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
97 <p id="display"> |
|
98 </p> |
|
99 <div id="content" style="display: none"> |
|
100 </div> |
|
101 <pre id="test"> |
|
102 </pre> |
|
103 </body> |
|
104 |
|
105 </window> |