File: CSSPseudoElement-convertPoint.tentative.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (102 lines) | stat: -rw-r--r-- 3,500 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
96
97
98
99
100
101
102
<!DOCTYPE html>
<title>CSS Pseudo Test: CSSPseudoElement GeometryUtils - coordinate conversion</title>
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#CSSPseudoElement-interface">
<link rel="help" href="https://drafts.csswg.org/cssom-view-1/#extension-to-the-geometryutils-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  #container {
    position: absolute;
    left: 100px;
    top: 50px;
    width: 300px;
    height: 200px;
  }

  #target {
    position: absolute;
    left: 50px;
    top: 30px;
    width: 100px;
    height: 80px;
  }

  #target::before {
    content: '';
    display: block;
    position: absolute;
    left: 10px;
    top: 5px;
    width: 30px;
    height: 20px;
  }

  #reference {
    position: absolute;
    left: 200px;
    top: 100px;
    width: 50px;
    height: 50px;
  }
</style>
<div id="container">
  <div id="target"></div>
  <div id="reference"></div>
</div>
<script>
  test(() => {
    let pseudo = target.pseudo("::before");
    assert_true(typeof pseudo.convertPointFromNode === 'function', 'convertPointFromNode should be a function');
    assert_true(typeof pseudo.convertQuadFromNode === 'function', 'convertQuadFromNode should be a function');
    assert_true(typeof pseudo.convertRectFromNode === 'function', 'convertRectFromNode should be a function');
  }, 'CSSPseudoElement should have coordinate conversion methods');

  test(() => {
    let pseudo = target.pseudo("::before");
    let point = pseudo.convertPointFromNode({ x: 0, y: 0 }, target);
    assert_true(point instanceof DOMPoint, 'should return a DOMPoint');
  }, 'convertPointFromNode returns DOMPoint');

  test(() => {
    let pseudo = target.pseudo("::before");
    let rect = new DOMRectReadOnly(0, 0, 10, 10);
    let quad = pseudo.convertRectFromNode(rect, target);
    assert_true(quad instanceof DOMQuad, 'should return a DOMQuad');
  }, 'convertRectFromNode returns DOMQuad');

  test(() => {
    let pseudo = target.pseudo("::before");
    let inputQuad = {
      p1: { x: 0, y: 0 },
      p2: { x: 10, y: 0 },
      p3: { x: 10, y: 10 },
      p4: { x: 0, y: 10 }
    };
    let quad = pseudo.convertQuadFromNode(inputQuad, target);
    assert_true(quad instanceof DOMQuad, 'should return a DOMQuad');
  }, 'convertQuadFromNode returns DOMQuad');

  test(() => {
    let pseudo = target.pseudo("::before");
    // Convert origin of target to pseudo-element coordinate space
    let point = pseudo.convertPointFromNode({ x: 0, y: 0 }, target);
    // The ::before is at (10, 5) relative to target
    // So target's (0,0) in ::before's space should be (-10, -5)
    assert_approx_equals(point.x, -10, 1, 'x coordinate');
    assert_approx_equals(point.y, -5, 1, 'y coordinate');
  }, 'convertPointFromNode converts coordinates correctly');

  test(() => {
    let pseudo = target.pseudo("::before");
    // Convert a point from document coordinates
    let point = pseudo.convertPointFromNode({ x: 0, y: 0 }, document);
    assert_true(point instanceof DOMPoint, 'should return a DOMPoint from document');
  }, 'convertPointFromNode works with Document as source');

  test(() => {
    let pseudo = target.pseudo("::before");
    // Convert from another element
    let point = pseudo.convertPointFromNode({ x: 0, y: 0 }, reference);
    assert_true(point instanceof DOMPoint, 'should return a DOMPoint from element');
  }, 'convertPointFromNode works with Element as source');
</script>