scroll-element-to-rect-centered.html 1.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<html>
  <head>
    <body>
      <div id="console"></div>
      <div style="position: relative; width: 2400px; height: 2400px; background-color: white;">
        <div style="position:fixed; left: 50px; top: 30px; width: 200px; height: 250px; background-color: green;"></div>
        <div style="position:absolute; left: 600px; top: 800px;"> <input id="textbox" type="text"></div>
      </div>
    </body>
    <script src="../js/resources/js-test-pre.js"></script>
    <script>
      if (window.internals) {
        var box = document.getElementById('textbox');
        window.internals.scrollElementToRect(box, 50, 30, 200, 250);
      }
      var rect = box.getBoundingClientRect();
      var computedLeft = 50 + Math.floor((200 - rect.width) / 2);
      var computedTop = 30 + Math.floor((250 - rect.height) / 2);
      debug("Scrolled element to rect");
      shouldBe("rect.left", "computedLeft");
      shouldBe("rect.top", "computedTop");
      if (window.layoutTestController) {
        layoutTestController.dumpAsText();
      }
      successfullyParsed = true;
    </script>
    <script src="../js/resources/js-test-post.js"></script>
    </script>
  </head>
</html>