scrollIntoView-horizontal-tb-writing-mode.html (3383B)
1 <!DOCTYPE html> 2 <title>CSSOM View - scrollIntoView considers horizontal-tb writing mode</title> 3 <meta charset="utf-8"> 4 <meta name="viewport" content="width=device-width,initial-scale=1"> 5 <link rel="author" title="Cathie Chen" href="mailto:cathiechen@igalia.com"> 6 <link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 10 <style> 11 .box { 12 float: left; 13 width: 200px; 14 height: 200px; 15 } 16 #scroller { 17 overflow: scroll; 18 width: 300px; 19 height: 300px; 20 } 21 #container{ 22 width: 600px; 23 height: 600px; 24 } 25 #target { 26 background-color: #ff0; 27 } 28 </style> 29 <body> 30 <div id="scroller"> 31 <div id="container"> 32 <!-- ROW-1 --> 33 <div class="row"> 34 <div class="box"></div> 35 <div class="box"></div> 36 <div class="box"></div> 37 </div> 38 39 <!-- ROW-2 --> 40 <div class="row"> 41 <div class="box"></div> 42 <div class="box" id="target"></div> 43 <div class="box"></div> 44 </div> 45 46 <!-- ROW-3 --> 47 <div class="row"> 48 <div class="box"></div> 49 <div class="box"></div> 50 <div class="box"></div> 51 </div> 52 </div> 53 </div> 54 55 <script> 56 // In horizontal-tb mode, X corresponds to the inline axis and is oriented 57 // rightward. Y corresponds to the block axis and is oriented downward. 58 // So the beginning edges are the top and left edges and the ending 59 // edges are the bottom and right edges. 60 61 // This assumes that the horizontal scrollbar is on the bottom side and 62 // the vertical scrollbar is on the right side. 63 64 var target = document.getElementById("target"); 65 var scroller = document.getElementById("scroller"); 66 var scrollbar_width = scroller.offsetWidth - scroller.clientWidth; 67 68 var scroller_width = scroller.offsetWidth; 69 var scroller_height = scroller.offsetHeight; 70 var box_width = target.offsetWidth; 71 var box_height = target.offsetHeight; 72 73 var expectedX = { 74 inlineStart: box_width, 75 inlineCenter: (3*box_width - scroller_width)/2 + scrollbar_width/2, 76 inlineEnd: 2*box_width - scroller_width + scrollbar_width, 77 }; 78 79 var expectedY = { 80 blockStart: box_height, 81 blockCenter: (3*box_height - scroller_height)/2 + scrollbar_width/2, 82 blockEnd: 2*box_height - scroller_height + scrollbar_width, 83 }; 84 85 [ 86 [{block: "start", inline: "start"}, expectedX.inlineStart, expectedY.blockStart], 87 [{block: "start", inline: "center"}, expectedX.inlineCenter, expectedY.blockStart], 88 [{block: "start", inline: "end"}, expectedX.inlineEnd, expectedY.blockStart], 89 [{block: "center", inline: "start"}, expectedX.inlineStart, expectedY.blockCenter], 90 [{block: "center", inline: "center"}, expectedX.inlineCenter, expectedY.blockCenter], 91 [{block: "center", inline: "end"}, expectedX.inlineEnd, expectedY.blockCenter], 92 [{block: "end", inline: "start"}, expectedX.inlineStart, expectedY.blockEnd], 93 [{block: "end", inline: "center"}, expectedX.inlineCenter, expectedY.blockEnd], 94 [{block: "end", inline: "end"}, expectedX.inlineEnd, expectedY.blockEnd], 95 ].forEach(([input, expectedX, expectedY]) => { 96 test(() => { 97 scroller.scrollTo(0, 0); 98 target.scrollIntoView(input); 99 assert_approx_equals(scroller.scrollLeft, expectedX, 0.5, "scrollX"); 100 assert_approx_equals(scroller.scrollTop, expectedY, 0.5, "scrollY"); 101 }, `scrollIntoView(${JSON.stringify(input)})`); 102 }) 103 104 </script> 105 106 </body> 107 </html>