tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scrollIntoView-vertical-rl-writing-mode.html (3767B)


      1 <!DOCTYPE html>
      2 <title>CSSOM View - scrollIntoView considers vertical-rl writing mode</title>
      3 <meta charset="utf-8">
      4 <meta name="viewport" content="width=device-width,initial-scale=1">
      5 <link rel="author" title="Suneel Kota" href="mailto:suneel.kota@samsung.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  writing-mode: vertical-rl;
     18  overflow: scroll;
     19  width: 300px;
     20  height: 300px;
     21 }
     22 #container{
     23  width: 600px;
     24  height: 600px;
     25 }
     26 #target {
     27  background-color: #ff0;
     28 }
     29 </style>
     30 <body>
     31 <div id="scroller">
     32  <div id="container">
     33    <!-- ROW-1 -->
     34    <div class="row">
     35      <div class="box"></div>
     36      <div class="box"></div>
     37      <div class="box"></div>
     38    </div>
     39 
     40    <!-- ROW-2 -->
     41    <div class="row">
     42      <div class="box"></div>
     43      <div class="box" id="target"></div>
     44      <div class="box"></div>
     45    </div>
     46 
     47    <!-- ROW-3 -->
     48    <div class="row">
     49      <div class="box"></div>
     50      <div class="box"></div>
     51      <div class="box"></div>
     52    </div>
     53  </div>
     54 </div>
     55 
     56 <script>
     57 // In vertical-rl mode, X corresponds to the block axis and is oriented
     58 // leftward. Y corresponds to the inline axis and is oriented downward.
     59 // So the beginning edges are the top and right edges and the ending
     60 // edges are the bottom and left edges.
     61 
     62 // This assumes that the horizontal scrollbar is on the bottom 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 // If scroll bar is on the left side, scroller.scrollLeft won't get bigger than 0,
     75 scroller.scrollLeft = scrollbar_width;
     76 if (scroller.scrollLeft == 0) {
     77  expectedX = {
     78    blockStart: -box_width,
     79    blockCenter: -(((3*box_width - scroller_width)/2) + (scrollbar_width/2)),
     80    blockEnd: -(((2*box_width) - scroller_width) + scrollbar_width),
     81  };
     82 } else {
     83  expectedX = {
     84    blockStart: -(box_width - scrollbar_width),
     85    blockCenter: -(((3*box_width - scroller_width)/2) + (scrollbar_width/2) - scrollbar_width),
     86    blockEnd: -((2*box_width) - scroller_width),
     87  };
     88 }
     89 
     90 var expectedY = {
     91  inlineStart: box_height,
     92  inlineCenter: ((3*box_height - scroller_height)/2) + (scrollbar_width/2),
     93  inlineEnd: ((2*box_height) - scroller_height) + scrollbar_width,
     94 };
     95 
     96 [
     97  [{block: "start", inline: "start"}, expectedX.blockStart, expectedY.inlineStart],
     98  [{block: "start", inline: "center"}, expectedX.blockStart, expectedY.inlineCenter],
     99  [{block: "start", inline: "end"}, expectedX.blockStart, expectedY.inlineEnd],
    100  [{block: "center", inline: "start"}, expectedX.blockCenter, expectedY.inlineStart],
    101  [{block: "center", inline: "center"}, expectedX.blockCenter, expectedY.inlineCenter],
    102  [{block: "center", inline: "end"}, expectedX.blockCenter, expectedY.inlineEnd],
    103  [{block: "end", inline: "start"}, expectedX.blockEnd, expectedY.inlineStart],
    104  [{block: "end", inline: "center"}, expectedX.blockEnd, expectedY.inlineCenter],
    105  [{block: "end", inline: "end"}, expectedX.blockEnd, expectedY.inlineEnd],
    106 ].forEach(([input, expectedX, expectedY]) => {
    107  test(() => {
    108    scroller.scrollTo(0, 0);
    109    target.scrollIntoView(input);
    110    assert_approx_equals(scroller.scrollLeft, expectedX, 0.5, "scrollX");
    111    assert_approx_equals(scroller.scrollTop, expectedY, 0.5, "scrollY");
    112  }, `scrollIntoView(${JSON.stringify(input)})`);
    113 })
    114 
    115 </script>
    116 
    117 </body>
    118 </html>