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