Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion source/NVDAObjects/IAccessible/ia2Web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2006-2015 NV Access Limited
#Copyright (C) 2006-2017 NV Access Limited

"""Base classes with common support for browsers exposing IAccessible2.
"""

from ctypes import c_short
from comtypes import COMError, BSTR
import oleacc
import IAccessibleHandler
import controlTypes
from logHandler import log
from NVDAObjects.behaviors import Dialog
from . import IAccessible
from .ia2TextMozilla import MozillaCompoundTextInfo
Expand Down Expand Up @@ -48,6 +51,32 @@ class Editor(Ia2Web):
class EditorChunk(Ia2Web):
beTransparentToMouse = True

class Math(Ia2Web):

def _get_mathMl(self):
from comtypes.gen.ISimpleDOM import ISimpleDOMNode
try:
node = self.IAccessibleObject.QueryInterface(ISimpleDOMNode)
# Try the data-mathml attribute.
attr = node.attributesForNames(1, (BSTR * 1)("data-mathml"), (c_short * 1)(0,))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I dont understand this line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's partly knowing the ISimpleDOMNode interface (for which there is an idl) and partly knowing ctypes/comtypes. attributesForNames can retrieve multiple attributes. It takes three arguments: an attribute count, an array of BSTRs specifying the attribute names and an array of shorts specifying the namespace id for each attribute (which for our purposes is 0). Because comtypes doesn't quite understand that we're dealing with arrays here, we need to explicitly create the arrays. BSTR * 1 creates a type for an array of BSTR with length 1 (akin to writing BSTR foo[1] in C++). Similar situation for c_short * 1; it's akin to short foo[1] in C++.

I guess I could simplify this by defining these as variables first, but it seemed like a pointless waste of variables at the time. The question is whether this is just something that requires knowledge of ctypes/comtypes. Does the following actually make it understandable to you? If so, I'm happy to change it.

attrNames = (BSTR * 1)("data-mathml")
namespaceIds = (c_short * 1)(0)
attrVal = node.attributesForNames(1, attrNames, namespaceIds)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes it slightly better, in that I know what those bits are supposed to represent. I wasn't aware of the type * 1 syntax.

if attr:
import mathPres
if not mathPres.getLanguageFromMath(attr) and self.language:
attr = mathPres.insertLanguageIntoMath(attr, self.language)
return attr
if self.IA2Attributes.get("tag") != "math":
# This isn't MathML.
raise LookupError
if self.language:
attrs = ' xml:lang="%s"' % self.language
else:
attrs = ""
return "<math%s>%s</math>" % (attrs, node.innerHTML)
except COMError:
log.debugWarning("Error retrieving math. "
"Not supported in this browser or ISimpleDOM COM proxy not registered.", exc_info=True)
raise LookupError

def findExtraOverlayClasses(obj, clsList, baseClass=Ia2Web, documentClass=None):
"""Determine the most appropriate class if this is an IA2 web object.
This should be called after finding any classes for the specific web implementation.
Expand All @@ -64,6 +93,8 @@ def findExtraOverlayClasses(obj, clsList, baseClass=Ia2Web, documentClass=None):
clsList.append(BlockQuote)
elif iaRole == oleacc.ROLE_SYSTEM_ALERT:
clsList.append(Dialog)
elif iaRole == oleacc.ROLE_SYSTEM_EQUATION:
clsList.append(Math)

isApp = iaRole in (oleacc.ROLE_SYSTEM_APPLICATION, oleacc.ROLE_SYSTEM_DIALOG)
if isApp:
Expand Down
27 changes: 2 additions & 25 deletions source/NVDAObjects/IAccessible/mozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2006-2015 NV Access Limited, Peter Vágner
#Copyright (C) 2006-2017 NV Access Limited, Peter Vágner

from collections import namedtuple
from ctypes import c_short
import IAccessibleHandler
import oleacc
import winUser
from comtypes import IServiceProvider, COMError, BSTR
from comtypes import IServiceProvider, COMError
import eventHandler
import controlTypes
from . import IAccessible, Dialog, WindowRoot
Expand Down Expand Up @@ -156,27 +155,6 @@ class TextLeaf(Mozilla):
role = controlTypes.ROLE_STATICTEXT
beTransparentToMouse = True

class Math(Mozilla):

def _get_mathMl(self):
from comtypes.gen.ISimpleDOM import ISimpleDOMNode
node = self.IAccessibleObject.QueryInterface(ISimpleDOMNode)
# Try the data-mathml attribute.
attr = node.attributesForNames(1, (BSTR * 1)("data-mathml"), (c_short * 1)(0,))
if attr:
import mathPres
if not mathPres.getLanguageFromMath(attr) and self.language:
attr = mathPres.insertLanguageIntoMath(attr, self.language)
return attr
if self.IA2Attributes.get("tag") != "math":
# This isn't MathML.
raise LookupError
if self.language:
attrs = ' xml:lang="%s"' % self.language
else:
attrs = ""
return "<math%s>%s</math>" % (attrs, node.innerHTML)

def findExtraOverlayClasses(obj, clsList):
"""Determine the most appropriate class if this is a Mozilla object.
This works similarly to L{NVDAObjects.NVDAObject.findOverlayClasses} except that it never calls any other findOverlayClasses method.
Expand Down Expand Up @@ -238,7 +216,6 @@ def findExtraOverlayClasses(obj, clsList):
IAccessibleHandler.IA2_ROLE_EMBEDDED_OBJECT: EmbeddedObject,
"embed": EmbeddedObject,
"object": EmbeddedObject,
oleacc.ROLE_SYSTEM_EQUATION: Math,
}

#: Roles that mightn't set the focused state when they are focused.
Expand Down
2 changes: 1 addition & 1 deletion user_docs/en/userGuide.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ This requires that MathPlayer 4 is installed on the computer.
MathPlayer is available as a free download from: http://www.dessci.com/en/products/mathplayer/

NVDA supports the following types of mathematical content:
- MathML in Mozilla Firefox and Microsoft Internet Explorer.
- MathML in Mozilla Firefox, Microsoft Internet Explorer and Google Chrome.
- Design Science MathType in Microsoft Word and PowerPoint. MathType needs to be installed in order for this to work. The trial version is sufficient.
- 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.
-
Expand Down