/// <summary> /// Iterate to the first matching child of an element /// *after* the specified child. /// </summary> /// <param name="element"> /// The element whose children should be iterated. /// </param> /// <param name="afterThisChild"> /// The direct child of <paramref name="element"/> /// after which to iterate, or null if the absolute first /// matching child is desired. /// </param> /// <returns> /// The first matching <see cref="AutomationElement"/> /// after <paramref name="afterThisChild"/>. /// </returns> private AutomationElement GetFirstChild(AutomationElement element, AutomationElement afterThisChild) { if (element == null) { throw new ArgumentNullException("element"); } AddMarkedElement(element); AutomationElement child; if (afterThisChild == null) { child = GetFirstDirectChild(element); } else { child = GetNextDirectSibling(afterThisChild); } while (child != null && markedElements.Contains(child)) { child = GetNextDirectSibling(child); } if (child == null || markedElements.Contains(child)) { return(null); } AutomationElement firstChild = null; if (!markedElements.Contains(child) && condition.AppliesTo(child)) { firstChild = child; } else { firstChild = GetFirstChild(child); } while (firstChild == null && child != null) { child = GetNextDirectSibling(child); if (child == null) { return(null); } firstChild = GetFirstChild(child); } return(firstChild); }
private List <AutomationElement> Find(TreeScope scope, Condition condition, bool findFirst) { // Parent and Ancestors scopes are not supported on // Windows (this is specified in MSDN, too). if ((scope & TreeScope.Parent) == TreeScope.Parent || (scope & TreeScope.Ancestors) == TreeScope.Ancestors) { throw new ArgumentException("scope"); } List <AutomationElement> found = new List <AutomationElement> (); if ((!findFirst || found.Count == 0) && (scope & TreeScope.Element) == TreeScope.Element && condition.AppliesTo(this) && (CacheRequest.Current == CacheRequest.DefaultRequest || CacheRequest.Current.TreeFilter.AppliesTo(this))) { // TODO: Need to check request's TreeScope, too? found.Add(GetUpdatedCache(CacheRequest.Current)); } if ((!findFirst || found.Count == 0) && ((scope & TreeScope.Children) == TreeScope.Children || (scope & TreeScope.Descendants) == TreeScope.Descendants)) { TreeScope childScope = TreeScope.Element; if ((scope & TreeScope.Descendants) == TreeScope.Descendants) { childScope = TreeScope.Subtree; } AutomationElement current = TreeWalker.RawViewWalker.GetFirstChild(this); while (current != null) { //Log.Debug ("Inspecting child: " + current.Current.Name); found.AddRange(current.Find(childScope, condition, findFirst)); if (findFirst && found.Count > 0) { break; } current = TreeWalker.RawViewWalker.GetNextSibling(current); } } return(found); }
public AutomationElement Normalize(AutomationElement element) { if (element == null) { throw new ArgumentNullException("element"); } if (Condition.AppliesTo(element)) { return(element); } if (element == AutomationElement.RootElement) { // LAMESPEC: This is according to MSDN: // http://msdn.microsoft.com/en-us/library/system.windows.automation.treewalker.normalize.aspx // return element; // This is matching Microsoft's actual implementation: return(null); } return(Normalize(RawViewWalker.GetParent(element))); }
private List<AutomationElement> Find (TreeScope scope, Condition condition, bool findFirst) { // Parent and Ancestors scopes are not supported on // Windows (this is specified in MSDN, too). if ((scope & TreeScope.Parent) == TreeScope.Parent || (scope & TreeScope.Ancestors) == TreeScope.Ancestors) throw new ArgumentException ("scope"); List<AutomationElement> found = new List<AutomationElement> (); if ((!findFirst || found.Count == 0) && (scope & TreeScope.Element) == TreeScope.Element && condition.AppliesTo (this) && (CacheRequest.Current == CacheRequest.DefaultRequest || CacheRequest.Current.TreeFilter.AppliesTo (this))) { // TODO: Need to check request's TreeScope, too? found.Add (GetUpdatedCache (CacheRequest.Current)); } if ((!findFirst || found.Count == 0) && ((scope & TreeScope.Children) == TreeScope.Children || (scope & TreeScope.Descendants) == TreeScope.Descendants)) { TreeScope childScope = TreeScope.Element; if ((scope & TreeScope.Descendants) == TreeScope.Descendants) childScope = TreeScope.Subtree; AutomationElement current = TreeWalker.RawViewWalker.GetFirstChild (this); while (current != null) { //Log.Debug ("Inspecting child: " + current.Current.Name); found.AddRange (current.Find (childScope, condition, findFirst)); if (findFirst && found.Count > 0) break; current = TreeWalker.RawViewWalker.GetNextSibling (current); } } return found; }
internal override bool AppliesTo(AutomationElement element) { return(!condition.AppliesTo(element)); }