OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nuanti Ltd. | 3 * Copyright (C) 2008 Nuanti Ltd. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 Element* current = scope.currentElement(); | 433 Element* current = scope.currentElement(); |
434 if (shouldVisit(*current) && adjustedTabIndex(*current) == tabIndex) | 434 if (shouldVisit(*current) && adjustedTabIndex(*current) == tabIndex) |
435 return current; | 435 return current; |
436 } | 436 } |
437 return nullptr; | 437 return nullptr; |
438 } | 438 } |
439 | 439 |
440 Element* nextElementWithGreaterTabIndex(ScopedFocusNavigation& scope, | 440 Element* nextElementWithGreaterTabIndex(ScopedFocusNavigation& scope, |
441 int tabIndex) { | 441 int tabIndex) { |
442 // Search is inclusive of start | 442 // Search is inclusive of start |
443 int winningTabIndex = std::numeric_limits<short>::max() + 1; | 443 int winningTabIndex = std::numeric_limits<int>::max(); |
444 Element* winner = nullptr; | 444 Element* winner = nullptr; |
445 for (; scope.currentElement(); scope.moveToNext()) { | 445 for (; scope.currentElement(); scope.moveToNext()) { |
446 Element* current = scope.currentElement(); | 446 Element* current = scope.currentElement(); |
447 int currentTabIndex = adjustedTabIndex(*current); | 447 int currentTabIndex = adjustedTabIndex(*current); |
448 if (shouldVisit(*current) && currentTabIndex > tabIndex && | 448 if (shouldVisit(*current) && currentTabIndex > tabIndex) { |
449 currentTabIndex < winningTabIndex) { | 449 if (!winner || currentTabIndex < winningTabIndex) { |
450 winner = current; | 450 winner = current; |
451 winningTabIndex = currentTabIndex; | 451 winningTabIndex = currentTabIndex; |
| 452 } |
452 } | 453 } |
453 } | 454 } |
454 return winner; | 455 return winner; |
455 } | 456 } |
456 | 457 |
457 Element* previousElementWithLowerTabIndex(ScopedFocusNavigation& scope, | 458 Element* previousElementWithLowerTabIndex(ScopedFocusNavigation& scope, |
458 int tabIndex) { | 459 int tabIndex) { |
459 // Search is inclusive of start | 460 // Search is inclusive of start |
460 int winningTabIndex = 0; | 461 int winningTabIndex = 0; |
461 Element* winner = nullptr; | 462 Element* winner = nullptr; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 if (Element* winner = | 541 if (Element* winner = |
541 findElementWithExactTabIndex(scope, tabIndex, WebFocusTypeBackward)) | 542 findElementWithExactTabIndex(scope, tabIndex, WebFocusTypeBackward)) |
542 return winner; | 543 return winner; |
543 } | 544 } |
544 | 545 |
545 // There are no elements before start with the same tabindex as start, so look | 546 // There are no elements before start with the same tabindex as start, so look |
546 // for an element that: | 547 // for an element that: |
547 // 1) has the highest non-zero tabindex (that is less than start's tabindex), | 548 // 1) has the highest non-zero tabindex (that is less than start's tabindex), |
548 // and | 549 // and |
549 // 2) comes last in the scope, if there's a tie. | 550 // 2) comes last in the scope, if there's a tie. |
550 tabIndex = | 551 tabIndex = (current && tabIndex) ? tabIndex : std::numeric_limits<int>::max(); |
551 (current && tabIndex) ? tabIndex : std::numeric_limits<short>::max(); | |
552 scope.moveToLast(); | 552 scope.moveToLast(); |
553 return previousElementWithLowerTabIndex(scope, tabIndex); | 553 return previousElementWithLowerTabIndex(scope, tabIndex); |
554 } | 554 } |
555 | 555 |
556 // Searches through the given tree scope, starting from start element, for the | 556 // Searches through the given tree scope, starting from start element, for the |
557 // next/previous selectable element that comes after/before start element. | 557 // next/previous selectable element that comes after/before start element. |
558 // The order followed is as specified in the HTML spec[1], which is elements | 558 // The order followed is as specified in the HTML spec[1], which is elements |
559 // with tab indexes first (from lowest to highest), and then elements without | 559 // with tab indexes first (from lowest to highest), and then elements without |
560 // tab indexes (in document order). The search algorithm also conforms the | 560 // tab indexes (in document order). The search algorithm also conforms the |
561 // Shadow DOM spec[2], which inserts sequence in a shadow tree into its host. | 561 // Shadow DOM spec[2], which inserts sequence in a shadow tree into its host. |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1468 |
1469 return consumed; | 1469 return consumed; |
1470 } | 1470 } |
1471 | 1471 |
1472 DEFINE_TRACE(FocusController) { | 1472 DEFINE_TRACE(FocusController) { |
1473 visitor->trace(m_page); | 1473 visitor->trace(m_page); |
1474 visitor->trace(m_focusedFrame); | 1474 visitor->trace(m_focusedFrame); |
1475 } | 1475 } |
1476 | 1476 |
1477 } // namespace blink | 1477 } // namespace blink |
OLD | NEW |