DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
<!DOCTYPE HTML>
<html>
<head>
  <title>Test click events on canvas hit regions</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display">
<canvas id="input">
</canvas>
</p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
SpecialPowers.pushPrefEnv({"set": [["canvas.hitregions.enabled", true]]}).then(function() {

  var input = document.getElementById("input");
  var regionId = "";
  input.addEventListener('mousedown', function(evt){
    regionId = evt.region;
  })

  function runTests()
  {
    try {
      var ctx = input.getContext("2d");
      ctx.beginPath();
      ctx.rect(20, 20, 100, 75);
      ctx.fill();
      ctx.addHitRegion({id: "a"});

      ctx.beginPath();
      ctx.fillStyle = "red";
      ctx.rect(60, 40, 100, 75);
      ctx.fill();
      ctx.addHitRegion({id: "b"});

      var mypath = new Path2D();
      mypath.rect(80, 60, 10, 10);

      ctx.beginPath();
      ctx.fillStyle = "yellow";
      ctx.rect(80, 60, 10, 10);
      ctx.fill();
      ctx.addHitRegion({id: "c", path: mypath});

      ctx.beginPath();
      ctx.fillStyle = "green";
      ctx.rect(60, 60, 10, 10); // This region is on purpose not the hit region
      ctx.fill();
      var mypath = new Path2D();
      mypath.rect(70, 30, 10, 10);
      ctx.addHitRegion({id: "d", path: mypath});

      synthesizeMouse(input, 25,25, {type: "mousedown"});
      is(regionId, "a", "Hit region a", ". Found: " + regionId);

      synthesizeMouse(input, 5,5, {type: "mousedown", button: 1});
      is(regionId, "", "Hit region null", ". Found: " + regionId);

      synthesizeMouse(input, 65,45, {type: "mousedown"});
      is(regionId, "b", "Hit region b", ". Found: " + regionId);

      synthesizeMouse(input, 85,65, {type: "mousedown"});
      is(regionId, "c", "Hit region c", ". Found: " + regionId);

      synthesizeMouse(input, 75,35, {type: "mousedown"});
      is(regionId, "d", "Hit region d", ". Found: " + regionId);

      ctx.removeHitRegion("c");
      synthesizeMouse(input, 85,65, {type: "mousedown"});
      is(regionId, "b", "Hit region b", ". Found: " + regionId);
    } catch (e) {
      ok(false, "unexpected exception thrown: " + e);
    }

    SimpleTest.finish();
  }
 
  runTests();
});

SimpleTest.waitForExplicitFinish();


</script>
</pre>
</body>
</html>