|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for scrolling selection into view</title> |
|
5 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
7 </head> |
|
8 <body> |
|
9 |
|
10 <pre id="test"> |
|
11 <script class="testbody" type="text/javascript"> |
|
12 |
|
13 var ANCHOR = 0; |
|
14 var FOCUS = 1; |
|
15 var win; |
|
16 |
|
17 function testCollapsed(id, vPercent, startAt, expected) { |
|
18 var selection = win.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); |
|
19 |
|
20 var c = win.document.getElementById("c" + id); |
|
21 var target = win.document.getElementById("target" + id); |
|
22 if (target.contentDocument) { |
|
23 selection = target.contentWindow.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); |
|
24 target = target.contentDocument.getElementById("target" + id); |
|
25 } |
|
26 selection.collapse(target.parentNode, 0); |
|
27 c.scrollTop = startAt; |
|
28 selection.scrollIntoView(FOCUS, true, vPercent, 0); |
|
29 is(c.scrollTop, expected, "Scrolling " + target.id + |
|
30 " into view with vPercent " + vPercent + ", starting at " + startAt); |
|
31 } |
|
32 |
|
33 function doTest() { |
|
34 // Test scrolling an element smaller than the scrollport |
|
35 testCollapsed("1", 0, 0, 400); |
|
36 testCollapsed("1", 100, 0, 220); |
|
37 testCollapsed("1", -1, 0, 220); |
|
38 testCollapsed("1", 0, 500, 400); |
|
39 testCollapsed("1", 100, 500, 220); |
|
40 testCollapsed("1", -1, 500, 400); |
|
41 |
|
42 // overflow:hidden elements should not be scrolled by selection |
|
43 // scrolling-into-view |
|
44 testCollapsed("2", 0, 0, 0); |
|
45 testCollapsed("2", 100, 0, 0); |
|
46 testCollapsed("2", -1, 0, 0); |
|
47 testCollapsed("2", 0, 500, 500); |
|
48 testCollapsed("2", 100, 500, 500); |
|
49 testCollapsed("2", -1, 500, 500); |
|
50 |
|
51 // Test scrolling an element larger than the scrollport |
|
52 testCollapsed("3", 0, 0, 400); |
|
53 testCollapsed("3", 100, 0, 500); |
|
54 testCollapsed("3", -1, 0, 400); |
|
55 testCollapsed("3", 0, 1000, 400); |
|
56 testCollapsed("3", 100, 1000, 500); |
|
57 // If the element can't be completely visible, we make the top edge |
|
58 // visible. |
|
59 testCollapsed("3", -1, 1000, 400); |
|
60 |
|
61 // Test scrolling an element larger than the scrollport |
|
62 testCollapsed("4", 0, 0, 400); |
|
63 testCollapsed("4", 100, 0, 500); |
|
64 testCollapsed("4", -1, 0, 400); |
|
65 testCollapsed("4", 0, 1000, 400); |
|
66 testCollapsed("4", 100, 1000, 500); |
|
67 // If the element can't be completely visible, we make the top edge |
|
68 // visible. |
|
69 testCollapsed("4", -1, 1000, 400); |
|
70 |
|
71 // Test that scrolling a translated element into view takes |
|
72 // account of the transform. |
|
73 testCollapsed("5", 0, 0, 400); |
|
74 |
|
75 // Test that scrolling a scaled element into view takes |
|
76 // account of the transform. |
|
77 testCollapsed("6", 0, 0, 150); |
|
78 |
|
79 // Test that scrolling an element with a translated, scrolling container |
|
80 // into view takes account of the transform. |
|
81 testCollapsed("7", 0, 0, 400); |
|
82 |
|
83 win.close(); |
|
84 SimpleTest.finish(); |
|
85 } |
|
86 |
|
87 function openWindow() { |
|
88 win = open("scroll_selection_into_view_window.html", "_blank", "width=500,height=350"); |
|
89 } |
|
90 |
|
91 SimpleTest.waitForExplicitFinish(); |
|
92 addLoadEvent(openWindow); |
|
93 </script> |
|
94 </pre> |
|
95 </body> |
|
96 |
|
97 </html> |