// IsListeningFor - called by UIAccess client during removal of listeners. Returns // true if rid, eventId and clientCallback represent this listener instance. internal bool IsListeningFor(AutomationEvent eventId, AutomationElement el, Delegate clientCallback) { // Removing the event handler using the element RuntimeId prevents problems with dead elements int[] rid = null; try { rid = el.GetRuntimeId(); } catch (ElementNotAvailableException) { // This can't be the element this instance is holding because when // creating this instance we caused the RuntimeId to be cached. return(false); } if (!Misc.Compare(_refRid, rid)) { return(false); } if (_eventListener.EventId != eventId) { return(false); } if (_clientCallback != clientCallback) { return(false); } return(true); }
// WithinScope - returns true if rid is the RuntimeId of this listener or listening for all elements. internal bool WithinScope(int [] rid) { // Quick look: If want all elements then no compare is necessary if ((_eventListener.TreeScope & TreeScope.Subtree) == TreeScope.Subtree && Misc.Compare(_refRid, AutomationElement.RootElement.GetRuntimeId())) { return(true); } // Can only determine if ref element is the element using RuntimeId; // can't determine other relationships. if ((_eventListener.TreeScope & TreeScope.Element) == 0) { return(false); } // Quick look: If they want this element but use our ref RuntimeId // since the weak reference may be gone. if (Misc.Compare(rid, _refRid)) { return(true); } // rid is not the ref element return(false); }
// WithinScope - returns true if el is within the scope of this listener. internal bool WithinScope(AutomationElement el) { // Quick look: If want all elements then no compare is necessary if ((_eventListener.TreeScope & TreeScope.Subtree) == TreeScope.Subtree && Misc.Compare(_refRid, AutomationElement.RootElement.GetRuntimeId())) { return(true); } // If our weak reference is still alive, then get it AutomationElement elThis = AutomationElement; if (elThis == null) { return(false); // reference is no longer alive } // Quick look: If they want this element if ((_eventListener.TreeScope & TreeScope.Element) != 0 && Misc.Compare(el, elThis)) { return(true); } AutomationElement elParent; // Quick look (sort of): If they want to include children if (((_eventListener.TreeScope & TreeScope.Children) != 0 || (_eventListener.TreeScope & TreeScope.Descendants) != 0)) { elParent = TreeWalker.RawViewWalker.GetParent(el); if (elParent != null && Misc.Compare(elParent, elThis)) { return(true); } } // Quick look (sort of): If they want to include the parent if (((_eventListener.TreeScope & TreeScope.Parent) != 0 || (_eventListener.TreeScope & TreeScope.Ancestors) != 0)) { elParent = TreeWalker.RawViewWalker.GetParent(elThis); if (elParent != null && Misc.Compare(elParent, el)) { return(true); } } // More work if they want to include any descendents of this element if ((_eventListener.TreeScope & TreeScope.Descendants) != 0 && IsChildOf(elThis, el)) { return(true); } // More work if they want to include any anscestors of this element if ((_eventListener.TreeScope & TreeScope.Ancestors) != 0 && IsChildOf(el, elThis)) { return(true); } return(false); }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods // return true if el is a child of elPossibleParent private bool IsChildOf(AutomationElement elPossibleParent, AutomationElement el) { // Do the work [slower] using the proxies if (!Misc.Compare(el, elPossibleParent)) { AutomationElement elPossibleChild = TreeWalker.RawViewWalker.GetParent(el); while (elPossibleChild != null) { if (Misc.Compare(elPossibleChild, elPossibleParent)) { return(true); } elPossibleChild = TreeWalker.RawViewWalker.GetParent(elPossibleChild); } } return(false); }