Improve focus detection on initial page loading. This should make structural navigation much more reliable on inital page load.
This commit is contained in:
@@ -330,6 +330,11 @@ class Utilities(script_utilities.Utilities):
|
||||
|
||||
if len(documents) == 1:
|
||||
document = documents[0]
|
||||
if focusDoc and focusDoc != document and documentHasUri(focusDoc):
|
||||
tokens = ["WEB: Single showing document differs; using focus-based document:",
|
||||
focusDoc]
|
||||
debug.printTokens(debug.LEVEL_INFO, tokens, True)
|
||||
return focusDoc
|
||||
if documentHasUri(document):
|
||||
return document
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ gi.require_version("Atspi", "2.0")
|
||||
from gi.repository import Atspi
|
||||
|
||||
from . import cmdnames
|
||||
from . import cthulhu
|
||||
from . import dbus_service
|
||||
from . import debug
|
||||
from . import guilabels
|
||||
@@ -1175,23 +1176,38 @@ class StructuralNavigation:
|
||||
objPath = AXObject.get_path(obj)
|
||||
objRole = AXObject.get_role(obj)
|
||||
if objRole == Atspi.Role.INVALID:
|
||||
return obj, characterOffset
|
||||
return None, characterOffset
|
||||
|
||||
self._script.utilities.setCaretPosition(obj, characterOffset)
|
||||
AXObject.clear_cache(obj)
|
||||
if not AXUtilities.is_defunct(obj):
|
||||
if not AXUtilities.is_defunct(obj) and not self._script.utilities.isZombie(obj):
|
||||
return obj, characterOffset
|
||||
|
||||
tokens = ["STRUCTURAL NAVIGATION:", obj, "became defunct after setting caret position"]
|
||||
debug.printTokens(debug.LEVEL_INFO, tokens, True)
|
||||
|
||||
replicant = self._script.utilities.get_objectFromPath(objPath)
|
||||
if replicant and AXObject.get_role(replicant) == objRole:
|
||||
if replicant and AXObject.get_role(replicant) == objRole \
|
||||
and not self._script.utilities.isZombie(replicant):
|
||||
tokens = ["STRUCTURAL NAVIGATION: Updating obj to replicant", replicant]
|
||||
debug.printTokens(debug.LEVEL_INFO, tokens, True)
|
||||
obj = replicant
|
||||
return obj, characterOffset
|
||||
|
||||
return obj, characterOffset
|
||||
document = getattr(self._script.utilities, "documentFrame", None)
|
||||
searchForCaretContext = getattr(self._script.utilities, "searchForCaretContext", None)
|
||||
if document and searchForCaretContext:
|
||||
documentFrame = document()
|
||||
if documentFrame and not self._script.utilities.isZombie(documentFrame):
|
||||
fallbackObj, fallbackOffset = searchForCaretContext(documentFrame)
|
||||
if fallbackObj and not self._script.utilities.isZombie(fallbackObj):
|
||||
tokens = ["STRUCTURAL NAVIGATION: Recovering focus to", fallbackObj]
|
||||
debug.printTokens(debug.LEVEL_INFO, tokens, True)
|
||||
cthulhu.setLocusOfFocus(None, fallbackObj, notifyScript=False)
|
||||
self._script.utilities.setCaretContext(
|
||||
fallbackObj, fallbackOffset, documentFrame)
|
||||
|
||||
return None, characterOffset
|
||||
|
||||
def _presentLine(self, obj, offset):
|
||||
"""Presents the first line of the object to the user.
|
||||
|
||||
Reference in New Issue
Block a user