File: 006.xhtml

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (95 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download
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
94
95
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="../resources/test-helper.js"></script>
<head>
  <title>Canvas drag and drop: allowed effects 'copy','move','link'</title>
  <style type="text/css">
    div {
      display: inline-block;
      vertical-align: top;
      background-color: olive;
      color: white;
      padding: 20px;
      width: 100px;
      height: 100px;
    }
    div:nth-child(2) {
      background-color: green;
    }
    div:nth-child(3) {
      background-color: teal;
    }
  </style>
</head>
<body>
  <p>
    Drag these canvas elements. Each has a different effectAllowed and color
    pattern.
  </p>
  <p>
    <canvas id="copy-drag" width="100" height="100" draggable="true"
      ondragstart="event.dataTransfer.effectAllowed = 'copy'">Copy
      Canvas</canvas>
    <canvas id="move-drag" width="100" height="100" draggable="true"
      ondragstart="event.dataTransfer.effectAllowed = 'move'">Move
      Canvas</canvas>
    <canvas id="link-drag" width="100" height="100" draggable="true"
      ondragstart="event.dataTransfer.effectAllowed = 'link'">Link
      Canvas</canvas>
  </p>
  <p>
    Drop targets for each effect:
  </p>
  <p>
  <div id="copy-drop" ondragover="onDragOver(event, 'copy')">copy</div>
  <div id="move-drop" ondragover="onDragOver(event, 'move')">move</div>
  <div id="link-drop" ondragover="onDragOver(event, 'link')">link</div>
  </p>
</body>
<script>
  // Draw patterns on the three canvases with different colors
  function drawCanvasPattern(canvasId, primaryColor, secondaryColor) {
    var canvas = document.getElementById(canvasId),
      c = canvas.getContext('2d');
    for (var x = 0; x != 50; x++) {
      c.fillStyle = (x % 2 == 0) ? primaryColor : secondaryColor;
      c.beginPath();
      c.moveTo(x, x);
      c.lineTo(100 - x, x);
      c.lineTo(100 - x, 100 - x);
      c.lineTo(x, 100 - x);
      c.closePath();
      c.fill();
    }
  }

  // Draw the three canvas patterns
  drawCanvasPattern('copy-drag', 'olive', 'white');
  drawCanvasPattern('move-drag', 'green', 'white');
  drawCanvasPattern('link-drag', 'teal', 'white');

  function onDragOver(event, effect) {
    event.preventDefault();
    event.dataTransfer.dropEffect = effect;
  }

  async function test() {
    await new Promise(loaded => window.addEventListener("load", loaded));

    for (const effect of ['copy', 'move', 'link']) {
      const dragCanvas = document.getElementById(effect + '-drag');
      const dropDiv = document.getElementById(effect + '-drop');

      dragDropTest(
        dragCanvas, dropDiv, dropEffectOnDropCallBack,
        'dropEffect should match effectAllowed on drop for ' + effect);
    }
  }
  test();
</script>
</html>