示例#1
0
        /// <summary>Gets the nearest focusable element below this.</summary>
        /// <returns>The nearest focusable element below. Null if there is none.</returns>
        public HtmlElement GetFocusableBelow()
        {
            // Has the element defined something specific?
            HtmlElement target = GetFocusableOverride("down");

            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 below this..
            foreach (Node node in allElements)
            {
                HtmlElement element = node as HtmlElement;

                if (element == null)
                {
                    continue;
                }

                if (element != this && element.IsBelow(myY) && element.focusable)
                {
                    // We have an element below.

                    // 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);
        }