Skip to content
Permalink
Browse files

MathML: check that determination of space-like is done from in-flow c…

…hildren (#18991)

This is a follow-up of #18990 but for space-like elements.
    It also introduces helper to navigate in-flow children and properly use
    it in the space-like and embellished-op tests.
  • Loading branch information...
fred-wang committed Sep 11, 2019
1 parent 88606a2 commit aa2d6a597714020478b4a09e06b23b66cb82fad5
@@ -11,6 +11,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/box-navigation.js"></script>
<style>
/* Default spacing of operator 'X' is 0.2777777777777778em so quite different
from the measured/specified 0em and 1em. */
@@ -40,7 +41,7 @@
<script>
function spaceBeforeElement(id) {
var element = document.getElementById(id);
var mnBefore = element.previousElementSibling;
var mnBefore = previousInFlowSibling(element);
return element.getBoundingClientRect().left - mnBefore.getBoundingClientRect().right;
}
@@ -11,6 +11,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/box-navigation.js"></script>
<style>
/* Default spacing of operator 'X' is 0.2777777777777778em so quite different
from the measured/specified 0em and 1em. */
@@ -42,7 +43,7 @@
</style>
<script>
function spaceBeforeElement(element) {
var mnBefore = element.previousElementSibling;
var mnBefore = previousInFlowSibling(element);
return element.getBoundingClientRect().left - mnBefore.getBoundingClientRect().right;
}
@@ -11,6 +11,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/box-navigation.js"></script>
<style>
/* Default spacing of operator 'X' is 0.2777777777777778em so quite different
from the measured/specified 0em and 1em. */
@@ -27,17 +28,26 @@
color: blue !important;
background: blue !important;
}
.oof1 {
position: absolute;
}
.oof2 {
position: fixed;
}
.nobox {
display: none;
}
</style>
<script>
function spaceBefore(id) {
var element = document.getElementById(id);
var mnBeforeParent = element.parentNode.previousElementSibling;
var mnBeforeParent = previousInFlowSibling(element.parentNode);
return element.getBoundingClientRect().left - mnBeforeParent.getBoundingClientRect().right;
}
function spaceAfter(id) {
var element = document.getElementById(id);
var mnAfterParent = element.parentNode.nextElementSibling;
var mnAfterParent = nextInFlowSibling(element.parentNode);
return mnAfterParent.getBoundingClientRect().left - element.getBoundingClientRect().right;
}
@@ -54,12 +64,24 @@
assert_approx_equals(spaceAfter("complex1"), emToPx, epsilon);
}, "complex space-like subtree");
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBefore("complex1-bis"), emToPx, epsilon);
assert_approx_equals(spaceAfter("complex1-bis"), emToPx, epsilon);
}, "complex space-like subtree, from in-flow children");
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBefore("complex2"), 0, epsilon);
assert_approx_equals(spaceAfter("complex2"), 2 * emToPx, epsilon);
}, "complex non-space-like subtree");
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBefore("complex2-bis"), 0, epsilon);
assert_approx_equals(spaceAfter("complex2-bis"), 2 * emToPx, epsilon);
}, "complex non-space-like subtree, from in-flow children");
done();
}
</script>
@@ -127,6 +149,121 @@
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow>
<!-- This element is space-like because it is made of nested
mrow, mstyle, mpadded, mphantom, mtext, mspace
-->
<mrow class="testedElement" id="complex1-bis">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow></mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="1em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<p>
<math>
<mn>X</mn>
@@ -189,5 +326,121 @@
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow>
<!-- This element is not space-like. It is made of nested
mrow, mstyle, mpadded, mphantom, mtext, mspace but contains
one non-space like descendant (an mn element).
-->
<mrow class="testedElement" id="complex2-bis">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow></mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn> <!-- mn is not space-like -->
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext>X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mspace width="25px"></mspace>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="1em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
</body>
</html>
@@ -0,0 +1,22 @@
function IsInFlow(element) {
var style = window.getComputedStyle(child);
return style.getPropertyValue("display") !== "none" &&
style.getPropertyValue("position") !== "absolute" &&
style.getPropertyValue("position") !== "fixed";
}

function nextInFlowSibling(element) {
var child = element;
do {
child = child.nextElementSibling;
} while (child && !IsInFlow(child));
return child;
}

function previousInFlowSibling(element) {
var child = element;
do {
child = child.previousElementSibling;
} while (child && !IsInFlow(child));
return child;
}

0 comments on commit aa2d6a5

Please sign in to comment.
You can’t perform that action at this time.