Changeset 2517

Show
Ignore:
Timestamp:
11/20/08 04:41:51 (7 weeks ago)
Author:
bzr
Message:

braille:

  • Rename getContextRegions() to getFocusContextRegions(), as it can now only be used on the focus (see below).
  • getFocusContextRegions() and getFocusRegions() now call update() on the regions they yield if necessary. This allows these functions to avoid calling update() if it isn't necessary for some reason.
  • getFocusContextRegions() now accepts a list of regions for the previous focus. This allows it to use the focus difference level and ancestors to greatly optimise the retrieval of context. Instead of always building new regions for all context objects (and thus having to retrieve all of the information for each object), it keeps the regions that were common to the previous focus and only builds new regions for new context. This results in a significant performance increase, especially in Mozilla applications.
  • BrailleHandler?: Rename _doNewRegions() to _doNewObject() to make it clear that this function deals with moving to a new object and not just arbitrary regions.
  • api.setFocusObject(): Set the global focus variables (focusObject, focusAncestors, etc.) before calling event_virtualBuffer_gainFocus, as this event calls braille functions to handle the focus which now require that these variables be up to date.

Closes #201.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk

    • Property bzr:revision-info
      •  

        old new  
        1 timestamp: 2008-11-20 00:32:02.549000025 +1000 
         1timestamp: 2008-11-20 14:40:18.513999939 +1000 
        22committer: James Teh <jamie@jantrid.net> 
        33properties:  
    • Property bzr:revision-id:v3-list-QlpoOTFBWSZTWbrL2vUAAB1VgAAQABCAQDrrnqAgAFCgaaGRkxBoTIJ6mmaNRwhndFAoNhZjh_YY4a01fOg1ulgNNC2UrzPdXXEnDpX8XckU4UJC6y9r1A..
      •  

        old new  
        2862862314 jamie@jantrid.net-20081119113620-dz3izx839k8dy7z0 
        2872872315 jamie@jantrid.net-20081119143202-ybvjifczhpjl9ldo 
         2882316 jamie@jantrid.net-20081120044018-ubawgup09fsqgp0i 
    • Property bzr:file-ids
      •  

        old new  
        1 source/brailleDisplayDrivers/handyTech.py       handytech.py-20080908070031-15dxcuiuxfazjt1r-3 
         1source/api.py   46@dbe06fc7-9119-0410-a01d-9dbf589ecbba:trunk:source%2Fapi.py 
         2source/braille.py       braille.py-20080908070240-tjwqjsv7drp1kt8c-1 
    • Property bzr:text-parents
      •  

        old new  
         1source/api.py   jamie@jantrid.net-20081111000130-ogbjmubm7hbp2w8b 
         2source/braille.py       mick@kulgan.net-20081117132147-0s0gw63lue1v5xar 
  • trunk/source/api.py

    r2493 r2517  
    132132                        virtualBufferObject.event_virtualBuffer_firstGainFocus() 
    133133        oldVirtualBuffer=globalVars.focusObject.virtualBuffer if globalVars.focusObject else None 
     134        # Set global focus variables before calling event_virtualBuffer_gainFocus. 
     135        globalVars.focusDifferenceLevel=focusDifferenceLevel 
     136        globalVars.focusObject=obj 
     137        globalVars.focusAncestors=ancestors 
    134138        if obj.virtualBuffer is not oldVirtualBuffer: 
    135139                if hasattr(oldVirtualBuffer,"event_virtualBuffer_loseFocus"): 
     
    137141                if hasattr(obj.virtualBuffer,"event_virtualBuffer_gainFocus"): 
    138142                        obj.virtualBuffer.event_virtualBuffer_gainFocus() 
    139         globalVars.focusDifferenceLevel=focusDifferenceLevel 
    140         globalVars.focusObject=obj 
    141         globalVars.focusAncestors=ancestors 
    142143        if log.isEnabledFor(log.DEBUG): 
    143144                log.debug("%s %s %s %s"%(obj.name or "",controlTypes.speechRoleLabels[obj.role],obj.value or "",obj.description or "")) 
  • trunk/source/braille.py

    r2505 r2517  
    540540                                raise 
    541541 
    542 def getContextRegions(obj): 
     542def getFocusContextRegions(obj, oldFocusRegions=None): 
    543543        # Late import to avoid circular import. 
    544544        from virtualBuffers import VirtualBuffer 
    545         if isinstance(obj,VirtualBuffer): 
    546                 obj=obj.rootNVDAObject 
    547         ancestors=[] 
    548         ancestor=obj.parent 
    549         while ancestor: 
    550                 ancestors.append(ancestor) 
    551                 ancestor=ancestor.parent 
    552         ancestors.reverse() 
    553         for parent in ancestors[1:]: 
     545        ancestors = api.getFocusAncestors() 
     546 
     547        ancestorsEnd = len(ancestors) 
     548        if isinstance(obj, VirtualBuffer): 
     549                obj = obj.rootNVDAObject 
     550                # We only want the ancestors of the buffer's root NVDAObject. 
     551                if obj != api.getFocusObject(): 
     552                        # Search backwards through the focus ancestors to find the index of obj. 
     553                        for index, ancestor in itertools.izip(xrange(len(ancestors) - 1, 0, -1), reversed(ancestors)): 
     554                                if obj == ancestor: 
     555                                        ancestorsEnd = index 
     556                                        break 
     557 
     558        if oldFocusRegions: 
     559                # We have the regions from the previous focus, so use the focus difference level to avoid rebuilding regions which are the same. 
     560                # The focus difference level is generally where the new ancestors begin. 
     561                # However, we must ensure that it is not beyond the last ancestor we wish to consider. 
     562                # Also, we don't ever want to fetch ancestor 0 (the desktop). 
     563                newAncestorsStart = max(min(api.getFocusDifferenceLevel(), ancestorsEnd), 1) 
     564                # Search backwards through the old regions to find the last common region. 
     565                for index, region in itertools.izip(xrange(len(oldFocusRegions) - 1, -1, -1), reversed(oldFocusRegions)): 
     566                        ancestorIndex = getattr(region, "_focusAncestorIndex", None) 
     567                        if ancestorIndex is None: 
     568                                continue 
     569                        if ancestorIndex < newAncestorsStart: 
     570                                # This is the last common region. 
     571                                # An ancestor may have been skipped and not have a region, which means that we need to grab new ancestors from this point. 
     572                                newAncestorsStart = ancestorIndex + 1 
     573                                commonRegionsEnd = index + 1 
     574                                break 
     575                else: 
     576                        # No common regions were found. 
     577                        commonRegionsEnd = 0 
     578                        newAncestorsStart = 1 
     579                # Yield the common regions. 
     580                for region in oldFocusRegions[0:commonRegionsEnd]: 
     581                        yield region 
     582        else: 
     583                # Fetch all ancestors. 
     584                newAncestorsStart = 1 
     585 
     586        for index, parent in enumerate(ancestors[newAncestorsStart:ancestorsEnd], newAncestorsStart): 
    554587                role=parent.role 
    555588                if role in (controlTypes.ROLE_UNKNOWN,controlTypes.ROLE_WINDOW,controlTypes.ROLE_SECTION,controlTypes.ROLE_TREEVIEWITEM,controlTypes.ROLE_LISTITEM,controlTypes.ROLE_PARAGRAPH,controlTypes.ROLE_PROGRESSBAR,controlTypes.ROLE_EDITABLETEXT,controlTypes.ROLE_MENUITEM): 
     
    562595                if controlTypes.STATE_INVISIBLE in states or controlTypes.STATE_UNAVAILABLE in states: 
    563596                        continue 
    564                 yield NVDAObjectRegion(parent, appendText=" ") 
     597                region = NVDAObjectRegion(parent, appendText=" ") 
     598                region._focusAncestorIndex = index 
     599                region.update() 
     600                yield region 
    565601 
    566602def getFocusRegions(obj, review=False): 
     
    576612        if isinstance(obj, VirtualBuffer): 
    577613                obj = obj.rootNVDAObject 
    578         yield (ReviewNVDAObjectRegion if review else NVDAObjectRegion)(obj, appendText=" " if region2 else "") 
     614        region = (ReviewNVDAObjectRegion if review else NVDAObjectRegion)(obj, appendText=" " if region2 else "") 
     615        region.update() 
     616        yield region 
    579617        if region2: 
     618                region2.update() 
    580619                yield region2 
    581620 
     
    709748                if self.tether != self.TETHER_FOCUS: 
    710749                        return 
    711                 self._doNewRegions(itertools.chain(getContextRegions(obj), getFocusRegions(obj))) 
    712  
    713         def _doNewRegions(self, regions): 
     750                self._doNewObject(itertools.chain(getFocusContextRegions(obj, oldFocusRegions=self.mainBuffer.regions), getFocusRegions(obj))) 
     751 
     752        def _doNewObject(self, regions): 
    714753                self.mainBuffer.clear() 
    715754                for region in regions: 
    716755                        self.mainBuffer.regions.append(region) 
    717                         region.update() 
    718756                self.mainBuffer.update() 
    719757                # Last region should receive focus. 
     
    775813                else: 
    776814                        # We're reviewing a different object. 
    777                         self._doNewRegions(getFocusRegions(reviewPos.obj, review=True)) 
     815                        self._doNewObject(getFocusRegions(reviewPos.obj, review=True)) 
    778816 
    779817def initialize():