Move the focus to the next element in the tab order. To determine the specified tab order, refer to HtmlPage#getTabbableElements() @return the element that has focus after calling this method
()
| 1617 | * @return the element that has focus after calling this method |
| 1618 | */ |
| 1619 | public HtmlElement tabToNextElement() { |
| 1620 | final List<HtmlElement> elements = getTabbableElements(); |
| 1621 | if (elements.isEmpty()) { |
| 1622 | setFocusedElement(null); |
| 1623 | return null; |
| 1624 | } |
| 1625 | |
| 1626 | final HtmlElement elementToGiveFocus; |
| 1627 | final DomElement elementWithFocus = getFocusedElement(); |
| 1628 | if (elementWithFocus == null) { |
| 1629 | elementToGiveFocus = elements.get(0); |
| 1630 | } |
| 1631 | else { |
| 1632 | final int index = elements.indexOf(elementWithFocus); |
| 1633 | if (index == -1) { |
| 1634 | // The element with focus isn't on this page |
| 1635 | elementToGiveFocus = elements.get(0); |
| 1636 | } |
| 1637 | else if (index == elements.size() - 1) { |
| 1638 | // if at last jump to start |
| 1639 | elementToGiveFocus = elements.get(0); |
| 1640 | } |
| 1641 | else { |
| 1642 | elementToGiveFocus = elements.get(index + 1); |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | setFocusedElement(elementToGiveFocus); |
| 1647 | return elementToGiveFocus; |
| 1648 | } |
| 1649 | |
| 1650 | /** |
| 1651 | * Move the focus to the previous element in the tab order. To determine the specified tab |