Skip to content

Commit 345aa29

Browse files
committed
Support math in Chrome. Incubates #7184.
2 parents 39bd650 + 7e8fe9d commit 345aa29

3 files changed

Lines changed: 37 additions & 27 deletions

File tree

‎source/NVDAObjects/IAccessible/ia2Web.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
#A part of NonVisual Desktop Access (NVDA)
33
#This file is covered by the GNU General Public License.
44
#See the file COPYING for more details.
5-
#Copyright (C) 2006-2015 NV Access Limited
5+
#Copyright (C) 2006-2017 NV Access Limited
66

77
"""Base classes with common support for browsers exposing IAccessible2.
88
"""
99

10+
from ctypes import c_short
11+
from comtypes import COMError, BSTR
1012
import oleacc
1113
import IAccessibleHandler
1214
import controlTypes
15+
from logHandler import log
1316
from NVDAObjects.behaviors import Dialog
1417
from . import IAccessible
1518
from .ia2TextMozilla import MozillaCompoundTextInfo
@@ -48,6 +51,34 @@ class Editor(Ia2Web):
4851
class EditorChunk(Ia2Web):
4952
beTransparentToMouse = True
5053

54+
class Math(Ia2Web):
55+
56+
def _get_mathMl(self):
57+
from comtypes.gen.ISimpleDOM import ISimpleDOMNode
58+
try:
59+
node = self.IAccessibleObject.QueryInterface(ISimpleDOMNode)
60+
# Try the data-mathml attribute.
61+
attrNames = (BSTR * 1)("data-mathml")
62+
namespaceIds = (c_short * 1)(0)
63+
attr = node.attributesForNames(1, attrNames, namespaceIds)
64+
if attr:
65+
import mathPres
66+
if not mathPres.getLanguageFromMath(attr) and self.language:
67+
attr = mathPres.insertLanguageIntoMath(attr, self.language)
68+
return attr
69+
if self.IA2Attributes.get("tag") != "math":
70+
# This isn't MathML.
71+
raise LookupError
72+
if self.language:
73+
attrs = ' xml:lang="%s"' % self.language
74+
else:
75+
attrs = ""
76+
return "<math%s>%s</math>" % (attrs, node.innerHTML)
77+
except COMError:
78+
log.debugWarning("Error retrieving math. "
79+
"Not supported in this browser or ISimpleDOM COM proxy not registered.", exc_info=True)
80+
raise LookupError
81+
5182
def findExtraOverlayClasses(obj, clsList, baseClass=Ia2Web, documentClass=None):
5283
"""Determine the most appropriate class if this is an IA2 web object.
5384
This should be called after finding any classes for the specific web implementation.
@@ -64,6 +95,8 @@ def findExtraOverlayClasses(obj, clsList, baseClass=Ia2Web, documentClass=None):
6495
clsList.append(BlockQuote)
6596
elif iaRole == oleacc.ROLE_SYSTEM_ALERT:
6697
clsList.append(Dialog)
98+
elif iaRole == oleacc.ROLE_SYSTEM_EQUATION:
99+
clsList.append(Math)
67100

68101
isApp = iaRole in (oleacc.ROLE_SYSTEM_APPLICATION, oleacc.ROLE_SYSTEM_DIALOG)
69102
if isApp:

‎source/NVDAObjects/IAccessible/mozilla.py‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#A part of NonVisual Desktop Access (NVDA)
44
#This file is covered by the GNU General Public License.
55
#See the file COPYING for more details.
6-
#Copyright (C) 2006-2015 NV Access Limited, Peter Vágner
6+
#Copyright (C) 2006-2017 NV Access Limited, Peter Vágner
77

88
from collections import namedtuple
9-
from ctypes import c_short
109
import IAccessibleHandler
1110
import oleacc
1211
import winUser
13-
from comtypes import IServiceProvider, COMError, BSTR
12+
from comtypes import IServiceProvider, COMError
1413
import eventHandler
1514
import controlTypes
1615
from . import IAccessible, Dialog, WindowRoot
@@ -156,27 +155,6 @@ class TextLeaf(Mozilla):
156155
role = controlTypes.ROLE_STATICTEXT
157156
beTransparentToMouse = True
158157

159-
class Math(Mozilla):
160-
161-
def _get_mathMl(self):
162-
from comtypes.gen.ISimpleDOM import ISimpleDOMNode
163-
node = self.IAccessibleObject.QueryInterface(ISimpleDOMNode)
164-
# Try the data-mathml attribute.
165-
attr = node.attributesForNames(1, (BSTR * 1)("data-mathml"), (c_short * 1)(0,))
166-
if attr:
167-
import mathPres
168-
if not mathPres.getLanguageFromMath(attr) and self.language:
169-
attr = mathPres.insertLanguageIntoMath(attr, self.language)
170-
return attr
171-
if self.IA2Attributes.get("tag") != "math":
172-
# This isn't MathML.
173-
raise LookupError
174-
if self.language:
175-
attrs = ' xml:lang="%s"' % self.language
176-
else:
177-
attrs = ""
178-
return "<math%s>%s</math>" % (attrs, node.innerHTML)
179-
180158
def findExtraOverlayClasses(obj, clsList):
181159
"""Determine the most appropriate class if this is a Mozilla object.
182160
This works similarly to L{NVDAObjects.NVDAObject.findOverlayClasses} except that it never calls any other findOverlayClasses method.
@@ -238,7 +216,6 @@ def findExtraOverlayClasses(obj, clsList):
238216
IAccessibleHandler.IA2_ROLE_EMBEDDED_OBJECT: EmbeddedObject,
239217
"embed": EmbeddedObject,
240218
"object": EmbeddedObject,
241-
oleacc.ROLE_SYSTEM_EQUATION: Math,
242219
}
243220

244221
#: Roles that mightn't set the focused state when they are focused.

‎user_docs/en/userGuide.t2t‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ This requires that MathPlayer 4 is installed on the computer.
544544
MathPlayer is available as a free download from: http://www.dessci.com/en/products/mathplayer/
545545

546546
NVDA supports the following types of mathematical content:
547-
- MathML in Mozilla Firefox and Microsoft Internet Explorer.
547+
- MathML in Mozilla Firefox, Microsoft Internet Explorer and Google Chrome.
548548
- Design Science MathType in Microsoft Word and PowerPoint. MathType needs to be installed in order for this to work. The trial version is sufficient.
549549
- MathML in Adobe Reader. Note that this is not an official standard yet, so there is currently no publicly available software that can produce this content.
550550
-

0 commit comments

Comments
 (0)