tor-browser

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

scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction.html (3661B)


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