Bug 1703600 part 5: Create mMathMLMarkupMap and use it for MathML elements. r=eeejay

Now, MathML elements (as well as XUL and SVG elements) will never use the HTML markup map.

Differential Revision: https://phabricator.services.mozilla.com/D111365
This commit is contained in:
James Teh 2021-04-14 04:11:18 +00:00
Родитель 244a85a2e3
Коммит 2a8e178211
4 изменённых файлов: 82 добавлений и 3 удалений

Просмотреть файл

@ -225,6 +225,9 @@ static int32_t sPlatformDisabledState = 0;
static const MarkupMapInfo sHTMLMarkupMapList[] = {
#include "HTMLMarkupMap.h"
};
static const MarkupMapInfo sMathMLMarkupMapList[] = {
#include "MathMLMarkupMap.h"
};
@ -265,7 +268,8 @@ uint32_t nsAccessibilityService::gConsumers = 0;
nsAccessibilityService::nsAccessibilityService()
: DocManager(),
FocusManager(),
mHTMLMarkupMap(ArrayLength(sHTMLMarkupMapList))
mHTMLMarkupMap(ArrayLength(sHTMLMarkupMapList)),
mMathMLMarkupMap(ArrayLength(sMathMLMarkupMapList))
#ifdef MOZ_XUL
,
mXULMarkupMap(ArrayLength(sXULMarkupMapList))
@ -1121,7 +1125,7 @@ LocalAccessible* nsAccessibilityService::CreateAccessible(
} else if (content->IsMathMLElement()) {
const MarkupMapInfo* markupMap =
mHTMLMarkupMap.Get(content->NodeInfo()->NameAtom());
mMathMLMarkupMap.Get(content->NodeInfo()->NameAtom());
if (markupMap && markupMap->new_func) {
newAcc = markupMap->new_func(content->AsElement(), aContext);
}
@ -1197,6 +1201,9 @@ bool nsAccessibilityService::Init() {
mHTMLMarkupMap.InsertOrUpdate(sHTMLMarkupMapList[i].tag,
&sHTMLMarkupMapList[i]);
}
for (const auto& info : sMathMLMarkupMapList) {
mMathMLMarkupMap.InsertOrUpdate(info.tag, &info);
}
#ifdef MOZ_XUL
for (uint32_t i = 0; i < ArrayLength(sXULMarkupMapList); i++) {

Просмотреть файл

@ -366,10 +366,20 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager,
using MarkupMap = nsTHashMap<nsPtrHashKey<const nsAtom>,
const mozilla::a11y::MarkupMapInfo*>;
MarkupMap mHTMLMarkupMap;
MarkupMap mMathMLMarkupMap;
const mozilla::a11y::MarkupMapInfo* GetMarkupMapInfoForNode(
const nsIContent* aContent) const {
return mHTMLMarkupMap.Get(aContent->NodeInfo()->NameAtom());
if (aContent->IsHTMLElement()) {
return mHTMLMarkupMap.Get(aContent->NodeInfo()->NameAtom());
}
if (aContent->IsMathMLElement()) {
return mMathMLMarkupMap.Get(aContent->NodeInfo()->NameAtom());
}
// This function can be called by MarkupAttribute, etc. which might in turn
// be called on a XUL, SVG, etc. element. For example, this can happen
// with nsAccUtils::SetLiveContainerAttributes.
return nullptr;
}
#ifdef MOZ_XUL

Просмотреть файл

@ -34,6 +34,7 @@ skip-if = true # Bug 561508
[test_formctrl.xhtml]
[test_gencontent.html]
[test_groupbox.xhtml]
[test_html_in_mathml.html]
[test_iframe.html]
[test_image.xhtml]
[test_img.html]

Просмотреть файл

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML in MathML Tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript">
function doTest() {
// <label> is generally not valid in MathML and shouldn't create an HTMl
// label.
testAccessibleTree("invalidLabel", {
MATHML_MATH: [ {
TEXT: [ {
TEXT_LEAF: []
} ],
} ],
});
// HTML is valid inside <mtext>, so <label> should create an HTMl label.
testAccessibleTree("validLabel", {
MATHML_MATH: [ {
MATHML_TEXT: [ {
LABEL: [ {
TEXT_LEAF: []
} ],
} ],
} ],
});
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<math id="invalidLabel">
<label>Text</label>
</math>
<math id="validLabel">
<mtext>
<label>Text</label>
</mtext>
</math>
</body>
</html>