summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/presentation-markup/fractions/frac-bar-002.html
blob: 3eb5433e821382a3a7c76dce8f62219e46e56c5b (plain)
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
<!DOCTYPE html>
<html class="reftest-wait">
  <head>
    <meta charset="utf-8">
    <title>fractions bar</title>
    <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">
    <meta name="assert" content="Verify painting of the fraction bar when margin/padding/border are involved.">
    <link rel="match" href="frac-bar-002-ref.html">
    <style type="text/css">
      @font-face {
        font-family: TestFont;
        src: url("/fonts/math/fraction-rulethickness10000.woff");
      }
      math {
        /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */
        /* The gap / shift / axisheight parameters are set to 0. */
        font-family: "TestFont";
        font-size: 1px;
      }
      #container {
          position: absolute;
          left: 0;
          top: 0;
      }
      #red {
          position: absolute;
          background: red;
          margin: 1px;
          width: 148px;
          height: 148px;
      }
    </style>
    <script src="/mathml/support/fonts.js"></script>
    <script src="/common/reftest-wait.js"></script>
    <script>
      window.addEventListener("load", () => { loadAllFonts().then(adjustPositionOfFraction); });

      function adjustPositionOfFraction()
      {
          requestAnimationFrame(() => {
              var container = document.getElementById("container");
              var red = document.getElementById("red");
              var numeratorBox = document.getElementById("numerator").getBoundingClientRect();
              const shift = 50;
              const numeratorMargin = 20;

              /* Move the red square at the expected position,
                 with a 1px gap to avoid antialiasing issues. */
              red.style.left = `${shift}px`;
              red.style.top = `${shift}px`;

              /* Move the fraction bar at the expected position. */
              container.style.left = (shift - numeratorBox.left + numeratorMargin) + "px";
              container.style.top = (shift - numeratorBox.bottom - numeratorMargin) + "px";
              requestAnimationFrame(takeScreenshot);
        });
      }
    </script>
  </head>
  <body>
    <p>This test passes if you see a green <strong>square</strong> and no red.</p>
    <div>
      <div id="red"></div>
      <div id="container">
        <math>
          <!-- border, padding and margin should not affect the width of the fraction bar. -->
          <mfrac style="color: green; font-size: 15em;
                        border: 30px solid transparent;
                        padding: 60px; margin: 120px;
                        ">
            <!-- the bar width is the one of the numerator margin box i.e. 80 + 2 * (5 + 10 + 20) = 150px -->
            <mspace id="numerator" width="80px"
                    style="border: 5px solid transparent;
                           padding: 10px; margin: 20px;"></mspace>
            <mspace></mspace>
          </mfrac>
        </math>
      </div>
    </div>
    <script src="/mathml/support/feature-detection.js"></script>
    <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mfrac");</script>
  </body>
</html>