Example #1
0
        /// <summary>Moves the focus to the previous element as defined by tabindex.
        /// All elements with an explicit tabindex are defined as being before all
        /// elements which don't have an explicit tabindex.</summary>
        /// <returns>True if anything happened.</returns>
        public bool TabPrevious()
        {
            // These track the current best found element.
            int         bestSoFar = int.MaxValue;
            HtmlElement best      = null;

            // Get the current focused element:
            HtmlElement focused = htmlActiveElement;

            if (focused == null)
            {
                // Haven't got one - hunt for a node with *no* tabindex first:
                body.SearchChildFocusable(null, false, -1, ref bestSoFar, ref best);

                if (best == null)
                {
                    // Find the last node with a tabIndex:
                    body.SearchChildFocusable(null, false, int.MaxValue, ref bestSoFar, ref best);
                }
            }
            else
            {
                best = focused.GetFocusedPrevious();
            }

            if (best != null)
            {
                // Focus it now:
                best.focus();

                return(true);
            }

            return(false);
        }