From 2a8e178211bc8748fc733740b98397b6781fd8b0 Mon Sep 17 00:00:00 2001 From: James Teh Date: Wed, 14 Apr 2021 04:11:18 +0000 Subject: [PATCH] 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 --- accessible/base/nsAccessibilityService.cpp | 11 +++- accessible/base/nsAccessibilityService.h | 12 +++- accessible/tests/mochitest/tree/a11y.ini | 1 + .../mochitest/tree/test_html_in_mathml.html | 61 +++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 accessible/tests/mochitest/tree/test_html_in_mathml.html diff --git a/accessible/base/nsAccessibilityService.cpp b/accessible/base/nsAccessibilityService.cpp index 163b50433bbb..8ed7af9df9d3 100644 --- a/accessible/base/nsAccessibilityService.cpp +++ b/accessible/base/nsAccessibilityService.cpp @@ -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++) { diff --git a/accessible/base/nsAccessibilityService.h b/accessible/base/nsAccessibilityService.h index 8967c450d83c..5ce20027a752 100644 --- a/accessible/base/nsAccessibilityService.h +++ b/accessible/base/nsAccessibilityService.h @@ -366,10 +366,20 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager, using MarkupMap = nsTHashMap, 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 diff --git a/accessible/tests/mochitest/tree/a11y.ini b/accessible/tests/mochitest/tree/a11y.ini index a229eeca83c7..a1a71ed74ce7 100644 --- a/accessible/tests/mochitest/tree/a11y.ini +++ b/accessible/tests/mochitest/tree/a11y.ini @@ -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] diff --git a/accessible/tests/mochitest/tree/test_html_in_mathml.html b/accessible/tests/mochitest/tree/test_html_in_mathml.html new file mode 100644 index 000000000000..214658de4a69 --- /dev/null +++ b/accessible/tests/mochitest/tree/test_html_in_mathml.html @@ -0,0 +1,61 @@ + + + + HTML in MathML Tests + + + + + + + + + + +

+ +
+  
+ + + + + + + + + + + + +