1# Orca 2# 3# Copyright (C) 2015 Igalia, S.L. 4# 5# Author: Joanmarie Diggs <jdiggs@igalia.com> 6# 7# This library is free software; you can redistribute it and/or 8# modify it under the terms of the GNU Lesser General Public 9# License as published by the Free Software Foundation; either 10# version 2.1 of the License, or (at your option) any later version. 11# 12# This library is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# Lesser General Public License for more details. 16# 17# You should have received a copy of the GNU Lesser General Public 18# License along with this library; if not, write to the 19# Free Software Foundation, Inc., Franklin Street, Fifth Floor, 20# Boston MA 02110-1301 USA. 21 22__id__ = "$Id$" 23__version__ = "$Revision$" 24__date__ = "$Date$" 25__copyright__ = "Copyright (c) 2015 Igalia, S.L." 26__license__ = "LGPL" 27 28import orca.braille as braille 29import orca.braille_generator as braille_generator 30import orca.scripts.toolkits.WebKitGtk as WebKitGtk 31 32class BrailleGenerator(WebKitGtk.BrailleGenerator, braille_generator.BrailleGenerator): 33 34 def __init__(self, script): 35 super().__init__(script) 36 self._cache = {} 37 38 def _isMessageListToggleCell(self, obj): 39 cached = self._cache.get(hash(obj), {}) 40 rv = cached.get("isMessageListToggleCell") 41 if rv is None: 42 rv = self._script.utilities.isMessageListToggleCell(obj) 43 cached["isMessageListToggleCell"] = rv 44 self._cache[hash(obj)] = cached 45 46 return rv 47 48 def _generateRealActiveDescendantDisplayedText(self, obj, **args): 49 if self._isMessageListToggleCell(obj): 50 return [] 51 52 return super()._generateRealActiveDescendantDisplayedText(obj, **args) 53 54 def generateBraille(self, obj, **args): 55 self._cache = {} 56 result, focusedRegion = super().generateBraille(obj, **args) 57 self._cache = {} 58 59 if not result or focusedRegion != result[0]: 60 return [result, focusedRegion] 61 62 hasObj = lambda x: isinstance(x, (braille.Component, braille.Text)) 63 isObj = lambda x: self._script.utilities.isSameObject(obj, x.accessible) 64 matches = [r for r in result if hasObj(r) and isObj(r)] 65 if matches: 66 focusedRegion = matches[0] 67 68 return [result, focusedRegion] 69