<html>
<head>
<title>Hit Test: Right-to-Left Table</title>
  <style>
    table.testtable {background-color: green; border: 0px; border-collapse: collapse;}
    table.testtable td { font-size: 20px; border: none; background-color: red; border-spacing:0px; width:60px; height:60px; direction:rtl;}
    body { margin: 0px 0px 0px 0px; }
  </style>
  <script>
      var cellHeight = 60;
      var cellWidth = 60;
      var logMsg = "";
      var failed = false;
      var hitArray = [[false, false, false],
                      [false, false, false],
                      [false, false, false]];

      if (window.testRunner) {
          window.testRunner.dumpAsText();
          window.testRunner.waitUntilDone();
      }

      function clearHitArray() {
          for (var i = 0; i < hitArray.length; ++i) {
              for (var j = 0; j < hitArray[i].length; ++j) {
                 hitArray[i][j] = false;
              } 
          }
      }

      function cellHit_r1c1(cell) {
          hitArray[0][0] = true;
          hitArray[0][1] = true;
          hitArray[0][2] = true;
      }

      function cellHit_r2c1(cell) {
          hitArray[1][0] = true;
      }

      function cellHit_r2c2(cell) {
          hitArray[1][1] = true;
          hitArray[2][1] = true;
      }

      function cellHit_r2c3(cell) {
          hitArray[1][2] = true;
      }

      function cellHit_r3c1(cell) {
          hitArray[2][0] = true;
      }

      function cellHit_r3c3(cell) {
          hitArray[2][2] = true;
      }

    function doTest() {
      var ypos = cellHeight / 2;
      for (var row = 0; row < 3; row++) {
        var xpos = cellWidth / 2;
        for (var col = 0; col < 3; col++) {
          logMsg += "Hit cell at row: " + row + ", column: " + col + ": ";
          var elem = document.elementFromPoint(xpos, ypos);
          if (elem) elem.onmousemove();
          if (!hitArray[row][col]) failed = true;
          logMsg += (hitArray[row][col] ? "SUCCESS" : "FAIL") + "<br />";
          clearHitArray();
          xpos += cellWidth;
        }
        ypos += cellHeight;
      }
      document.body.innerHTML =(failed ? "FAIL!!!<br/>" : "SUCCESS!!!<br/>") +logMsg;
      if (window.testRunner) {
          window.testRunner.notifyDone();
      }
    }

  </script>
</head>
  <body onload="doTest()">
    <table class="testtable">
      <tr>
        <td colspan="3" align="right" onmousemove="cellHit_r1c1(this)"></td>
      </tr>
      <tr>
        <td onmousemove="cellHit_r2c1(this)"></td>
        <td rowspan="2" onmousemove="cellHit_r2c2(this)"></td>
        <td onmousemove="cellHit_r2c3(this)"></td>
      </tr>
      <tr>
        <td onmousemove="cellHit_r3c1(this)"></td>
        <td onmousemove="cellHit_r3c3(this)"></td>
      </tr>
    </table>
  </body>
</html>
