OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <style> |
| 3 .scroller { |
| 4 height: 100px; |
| 5 width: 100px; |
| 6 overflow: scroll; |
| 7 } |
| 8 |
| 9 .content { |
| 10 height: 500px; |
| 11 width: 500px; |
| 12 } |
| 13 </style> |
| 14 |
| 15 <script src='../../../resources/testharness.js'></script> |
| 16 <script src='../../../resources/testharnessreport.js'></script> |
| 17 |
| 18 <div id='scroller1' class='scroller'> |
| 19 <div class='content'></div> |
| 20 </div> |
| 21 <script> |
| 22 test(function() { |
| 23 const scroller = document.querySelector('#scroller1'); |
| 24 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 25 // the value scrolled. We have a square scroller/contents, so can just compute |
| 26 // one edge and use it for inline and block. |
| 27 const scrollerSize = scroller.scrollHeight - scroller.clientHeight; |
| 28 |
| 29 const blockScrollTimeline = new ScrollTimeline( |
| 30 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'block' })
; |
| 31 const inlineScrollTimeline = new ScrollTimeline( |
| 32 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline' }
); |
| 33 |
| 34 // Unscrolled, both timelines should read a currentTime of 0. |
| 35 assert_equals(blockScrollTimeline.currentTime, 0); |
| 36 assert_equals(inlineScrollTimeline.currentTime, 0); |
| 37 |
| 38 // Now do some scrolling and make sure that the ScrollTimelines update. |
| 39 scroller.scrollTop = 50; |
| 40 scroller.scrollLeft = 75; |
| 41 |
| 42 // As noted above, we have mapped timeRange such that currentTime should just |
| 43 // be the scroll offset. |
| 44 assert_equals(blockScrollTimeline.currentTime, 50); |
| 45 assert_equals(inlineScrollTimeline.currentTime, 75); |
| 46 }, 'currentTime calculates the correct time based on scrolled amount'); |
| 47 </script> |
| 48 |
| 49 |
| 50 <div id='scroller2' class='scroller'> |
| 51 <div class='content' style='height: 1000px; width: 1000px;'></div> |
| 52 </div> |
| 53 <script> |
| 54 test(function() { |
| 55 // It is unfortunately difficult to calculate what scroll offset results in an |
| 56 // exact currentTime. Scrolling is calculated in integers which allows for the |
| 57 // possibility of rounding, and scrollbar widths differ between platforms |
| 58 // which means it is not possible to ensure a divisible scroller size. |
| 59 // |
| 60 // Instead we make the scroller content big enough that a 1-pixel rounding |
| 61 // difference results in a negligible difference in the output value. |
| 62 |
| 63 const scroller = document.querySelector('#scroller2'); |
| 64 const scrollTimeline = new ScrollTimeline( |
| 65 { scrollSource: scroller, timeRange: 100, orientation: 'block' }); |
| 66 |
| 67 // Mapping timeRange to 100 gives a form of 'percentage scrolled', so |
| 68 // calculate where the 50% scroll mark would be. |
| 69 const halfwayY = (scroller.scrollHeight - scroller.clientHeight) / 2; |
| 70 scroller.scrollTop = halfwayY; |
| 71 |
| 72 assert_approx_equals(scrollTimeline.currentTime, 50, 0.5); |
| 73 }, 'currentTime adjusts correctly for the timeRange'); |
| 74 </script> |
| 75 |
| 76 <div id='scroller3' class='scroller' style='direction: rtl;'> |
| 77 <div class='content'></div> |
| 78 </div> |
| 79 <script> |
| 80 test(function() { |
| 81 const scroller = document.querySelector('#scroller3'); |
| 82 |
| 83 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 84 // the value scrolled. We have a square scroller/contents, so can just compute |
| 85 // one edge and use it for inline and block. |
| 86 const scrollerSize = scroller.scrollHeight - scroller.clientHeight; |
| 87 |
| 88 const blockScrollTimeline = new ScrollTimeline( |
| 89 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'block' })
; |
| 90 const inlineScrollTimeline = new ScrollTimeline( |
| 91 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline' }
); |
| 92 |
| 93 // Unscrolled, both timelines should read a current time of 0 even though the |
| 94 // X-axis will have started at the right hand side for rtl. |
| 95 assert_equals(blockScrollTimeline.currentTime, 0); |
| 96 assert_equals(inlineScrollTimeline.currentTime, 0); |
| 97 |
| 98 // The offset in the inline direction should be inverted. The block direction |
| 99 // should be unaffected. |
| 100 scroller.scrollTop = 50; |
| 101 scroller.scrollLeft = 75; |
| 102 |
| 103 assert_equals(blockScrollTimeline.currentTime, 50); |
| 104 assert_equals(inlineScrollTimeline.currentTime, scrollerSize - 75); |
| 105 }, 'currentTime handles direction: rtl correctly'); |
| 106 </script> |
| 107 |
| 108 <div id='scroller4' class='scroller' style='writing-mode: vertical-rl;'> |
| 109 <div class='content'></div> |
| 110 </div> |
| 111 <script> |
| 112 test(function() { |
| 113 const scroller = document.querySelector('#scroller4'); |
| 114 |
| 115 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 116 // the value scrolled. We have a square scroller/contents, so can just compute |
| 117 // one edge and use it for inline and block. |
| 118 const scrollerSize = scroller.scrollHeight - scroller.clientHeight; |
| 119 |
| 120 const blockScrollTimeline = new ScrollTimeline( |
| 121 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'block' })
; |
| 122 const inlineScrollTimeline = new ScrollTimeline( |
| 123 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline' }
); |
| 124 |
| 125 // Unscrolled, both timelines should read a current time of 0 even though the |
| 126 // X-axis will have started at the right hand side for vertical-rl. |
| 127 assert_equals(blockScrollTimeline.currentTime, 0); |
| 128 assert_equals(inlineScrollTimeline.currentTime, 0); |
| 129 |
| 130 // For vertical-rl, the X-axis starts on the right-hand-side and is the block |
| 131 // axis. The Y-axis is normal but is the inline axis. |
| 132 scroller.scrollTop = 50; |
| 133 scroller.scrollLeft = 75; |
| 134 |
| 135 assert_equals(blockScrollTimeline.currentTime, scrollerSize - 75); |
| 136 assert_equals(inlineScrollTimeline.currentTime, 50); |
| 137 }, 'currentTime handles writing-mode: vertical-rl correctly'); |
| 138 </script> |
| 139 |
| 140 <div id='scroller5' class='scroller' style='writing-mode: vertical-lr;'> |
| 141 <div class='content'></div> |
| 142 </div> |
| 143 <script> |
| 144 test(function() { |
| 145 const scroller = document.querySelector('#scroller5'); |
| 146 |
| 147 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 148 // the value scrolled. We have a square scroller/contents, so can just compute |
| 149 // one edge and use it for inline and block. |
| 150 const scrollerSize = scroller.scrollHeight - scroller.clientHeight; |
| 151 |
| 152 const blockScrollTimeline = new ScrollTimeline( |
| 153 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'block' })
; |
| 154 const inlineScrollTimeline = new ScrollTimeline( |
| 155 { scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline' }
); |
| 156 |
| 157 // Unscrolled, both timelines should read a current time of 0. |
| 158 assert_equals(blockScrollTimeline.currentTime, 0); |
| 159 assert_equals(inlineScrollTimeline.currentTime, 0); |
| 160 |
| 161 // For vertical-lr, both axes start at their 'normal' positions but the X-axis |
| 162 // is the block direction and the Y-axis is the inline direction. |
| 163 scroller.scrollTop = 50; |
| 164 scroller.scrollLeft = 75; |
| 165 |
| 166 assert_equals(blockScrollTimeline.currentTime, 75); |
| 167 assert_equals(inlineScrollTimeline.currentTime, 50); |
| 168 }, 'currentTime handles writing-mode: vertical-lr correctly'); |
| 169 </script> |
OLD | NEW |