Commit 208ee0d7 authored by Joanmarie Diggs's avatar Joanmarie Diggs

Web: Try to be a little bit smart about dumping cache

Quirks in web sites and web browsers are tricky....

* If the children-changed event is our current object, dump cache and
  also the context because all bets are off regarding whether or not
  our current location is stale.
* If the children-changed event is an ancestor of our current object,
  dump cache but preserve the context because something around us
  has changed, but our present location should still be valid. Plus
  subsequent sanity checks should trigger us to update things if
  our present location isn't valid after all.
* Otherwise, something elsewhere has changed so don't dump the cache.

Also add more debugging to get to the bottom of remaining quirks.
parent 6b42da7b
......@@ -32,6 +32,7 @@ import inspect
import traceback
import os
import pyatspi
import re
import subprocess
import sys
......@@ -338,7 +339,7 @@ def attributesToString(acc, indent=""):
except:
return "%sattributes=(exception)" % indent
return "%sattributes='%s'" % (indent, " ".join(attributes))
return "%sattributes='%s'" % (indent, re.sub("\s+", " ", ", ".join(attributes)))
def getAccessibleDetails(level, acc, indent="", includeApp=True):
"""Returns a string, suitable for printing, that describes the
......@@ -371,23 +372,34 @@ def getAccessibleDetails(level, acc, indent="", includeApp=True):
string = indent
try:
name_string = "name='%s'" % acc.name
name_string = "name='%s'".replace("\n", "\\n") % acc.name
except:
name_string = "name=(exception)"
try:
desc_string = "%sdescription='%s'".replace("\n", "\\n") % (indent, acc.description)
except:
desc_string = "%sdescription=(exception)" % indent
try:
role_string = "role='%s'" % acc.getRoleName()
except:
role_string = "role=(exception)"
try:
path_string = "%spath=%s" % (indent, pyatspi.getPath(acc))
except:
path_string = "%spath=(exception)" % indent
state_string = statesToString(acc, indent)
rel_string = relationsToString(acc, indent)
iface_string = interfacesToString(acc, indent)
attr_string = attributesToString(acc, indent)
try:
string += "%s %s \n%s \n%s \n%s \n%s" \
% (name_string, role_string, state_string, rel_string, iface_string, attr_string)
string += "%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
% (name_string, role_string, desc_string, state_string, rel_string,
iface_string, attr_string, path_string)
except:
string += "(exception fetching data)"
......
......@@ -754,7 +754,11 @@ class EventManager:
if not debug.eventDebugFilter or debug.eventDebugFilter.match(eType) \
and not eType.startswith("mouse:"):
debug.printDetails(debug.LEVEL_INFO, ' ' * 18, event.source)
indent = " " * 32
debug.printDetails(debug.LEVEL_INFO, indent, event.source)
if isinstance(event.any_data, pyatspi.Accessible):
debug.println(debug.LEVEL_INFO, '%sANY DATA:' % indent)
debug.printDetails(debug.LEVEL_INFO, indent, event.any_data, includeApp=False)
script = self._getScriptForEvent(event)
if not script:
......
......@@ -1697,9 +1697,17 @@ class Script(default.Script):
isLiveRegion = self.utilities.isLiveRegion(event.source)
document = self.utilities.getDocumentForObject(event.source)
if document and not isLiveRegion:
# Issues in Firefox are leading to our not relocating our position.
inTable = self.utilities.getTable(orca_state.locusOfFocus) is not None
self.utilities.dumpCache(document, preserveContext=inTable)
if event.source == orca_state.locusOfFocus:
msg = "WEB: Dumping cache and context: source is focus %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
self.utilities.dumpCache(document, preserveContext=False)
elif pyatspi.findAncestor(orca_state.locusOfFocus, lambda x: x == event.source):
msg = "WEB: Dumping cache: source is ancestor of focus %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
self.utilities.dumpCache(document, preserveContext=True)
else:
msg = "WEB: Not dumping cache. Focus is %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
else:
msg = "WEB: Could not get document for event source"
debug.println(debug.LEVEL_INFO, msg, True)
......@@ -1797,9 +1805,17 @@ class Script(default.Script):
document = self.utilities.getDocumentForObject(event.source)
if document:
# Issues in Firefox are leading to our not relocating our position.
inTable = self.utilities.getTable(orca_state.locusOfFocus) is not None
self.utilities.dumpCache(document, preserveContext=inTable)
if event.source == orca_state.locusOfFocus:
msg = "WEB: Dumping cache and context: source is focus %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
self.utilities.dumpCache(document, preserveContext=False)
elif pyatspi.findAncestor(orca_state.locusOfFocus, lambda x: x == event.source):
msg = "WEB: Dumping cache: source is ancestor of focus %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
self.utilities.dumpCache(document, preserveContext=True)
else:
msg = "WEB: Not dumping cache. Focus is %s" % orca_state.locusOfFocus
debug.println(debug.LEVEL_INFO, msg, True)
if self.utilities.handleEventForRemovedChild(event):
msg = "WEB: Event handled for removed child."
......
......@@ -1555,6 +1555,7 @@ class Utilities(script_utilities.Utilities):
if useCache:
if self.findObjectInContents(obj, offset, self._currentObjectContents, usingCache=True) != -1:
self._debugContentsInfo(obj, offset, self._currentObjectContents, "Object (cached)")
return self._currentObjectContents
objIsLandmark = self.isLandmark(obj)
......@@ -1595,6 +1596,7 @@ class Utilities(script_utilities.Utilities):
if useCache:
self._currentObjectContents = objects
self._debugContentsInfo(obj, offset, objects, "Object (not cached)")
return objects
def _contentIsSubsetOf(self, contentA, contentB):
......@@ -1614,18 +1616,14 @@ class Utilities(script_utilities.Utilities):
msg = "WEB: %s for %s at offset %i:" % (contentsMsg, obj, offset)
debug.println(debug.LEVEL_INFO, msg, True)
indent = " " * 8
for i, (acc, start, end, string) in enumerate(contents):
indent = " " * 8
try:
description = acc.description
extents = self.getExtents(acc, start, end)
except:
description = "(exception)"
extents = "(exception)"
states = debug.statesToString(acc, indent)
attrs = debug.attributesToString(acc, indent)
msg = " %i. %s (chars: %i-%i) '%s' extents=%s description=%s\n%s\n%s" % \
(i, acc, start, end, string, extents, description, states, attrs)
msg = " %i. chars: %i-%i: '%s' extents=%s\n" % (i, start, end, string, extents)
msg += debug.getAccessibleDetails(debug.LEVEL_INFO, acc, indent)
debug.println(debug.LEVEL_INFO, msg, True)
def treatAsEndOfLine(self, obj, offset):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment