/// <summary>Gets the nearest focusable element right of this.</summary> /// <returns>The nearest focusable element to the right. Null if there is none.</returns> public HtmlElement GetFocusableRight() { // Has the element defined something specific? HtmlElement target = GetFocusableOverride("right"); if (target != null) { // Yep, it did! return(target); } // Distance of the nearest element (set when nearest is first set): float nearestDistance = 0f; // The current nearest element: HtmlElement nearest = null; // Grab my computed style: ComputedStyle computed = Style.Computed; // Get hold of the iterator (so we can safely skip child elements): NodeIterator allElements = document.allNodes; // Grab my x position: float myX = computed.GetMidpointX(); // Grab the midpoint of this element on Y: float myY = computed.GetMidpointY(); // For each element in the dom that is focusable and to the right of this.. foreach (Node node in allElements) { HtmlElement element = node as HtmlElement; if (element == null) { continue; } if (element != this && element.IsRightOf(myX) && element.focusable) { // We have an element to our right. // Check if it is closer than the current result. // If it is, it's the current result. // Is it nearer? float distance = element.DistanceFromFast(myX, myY); // Is it the first we've found, or is it nearer? if (nearest == null || distance < nearestDistance) { nearest = element; nearestDistance = distance; } // Make sure we don't now iterate its kids: allElements.SkipChildren = true; } } return(nearest); }