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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 Node* FocusController::findFocusableNode(FocusDirection direction, FocusNavigati
onScope scope, Node* node) | 461 Node* FocusController::findFocusableNode(FocusDirection direction, FocusNavigati
onScope scope, Node* node) |
462 { | 462 { |
463 return (direction == FocusDirectionForward) | 463 return (direction == FocusDirectionForward) |
464 ? nextFocusableNode(scope, node) | 464 ? nextFocusableNode(scope, node) |
465 : previousFocusableNode(scope, node); | 465 : previousFocusableNode(scope, node); |
466 } | 466 } |
467 | 467 |
468 Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, Focu
sDirection direction) | 468 Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, Focu
sDirection direction) |
469 { | 469 { |
470 // Search is inclusive of start | 470 // Search is inclusive of start |
471 for (Node* node = start; node; node = direction == FocusDirectionForward ? N
odeTraversal::next(*node) : NodeTraversal::previous(node)) { | 471 for (Node* node = start; node; node = direction == FocusDirectionForward ? N
odeTraversal::next(*node) : NodeTraversal::previous(*node)) { |
472 if (shouldVisit(node) && adjustedTabIndex(node) == tabIndex) | 472 if (shouldVisit(node) && adjustedTabIndex(node) == tabIndex) |
473 return node; | 473 return node; |
474 } | 474 } |
475 return 0; | 475 return 0; |
476 } | 476 } |
477 | 477 |
478 static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex) | 478 static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex) |
479 { | 479 { |
480 // Search is inclusive of start | 480 // Search is inclusive of start |
481 int winningTabIndex = std::numeric_limits<short>::max() + 1; | 481 int winningTabIndex = std::numeric_limits<short>::max() + 1; |
482 Node* winner = 0; | 482 Node* winner = 0; |
483 for (Node* node = start; node; node = NodeTraversal::next(*node)) { | 483 for (Node* node = start; node; node = NodeTraversal::next(*node)) { |
484 if (shouldVisit(node) && node->tabIndex() > tabIndex && node->tabIndex()
< winningTabIndex) { | 484 if (shouldVisit(node) && node->tabIndex() > tabIndex && node->tabIndex()
< winningTabIndex) { |
485 winner = node; | 485 winner = node; |
486 winningTabIndex = node->tabIndex(); | 486 winningTabIndex = node->tabIndex(); |
487 } | 487 } |
488 } | 488 } |
489 | 489 |
490 return winner; | 490 return winner; |
491 } | 491 } |
492 | 492 |
493 static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex) | 493 static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex) |
494 { | 494 { |
495 // Search is inclusive of start | 495 // Search is inclusive of start |
496 int winningTabIndex = 0; | 496 int winningTabIndex = 0; |
497 Node* winner = 0; | 497 Node* winner = 0; |
498 for (Node* node = start; node; node = NodeTraversal::previous(node)) { | 498 for (Node* node = start; node; node = NodeTraversal::previous(*node)) { |
499 int currentTabIndex = adjustedTabIndex(node); | 499 int currentTabIndex = adjustedTabIndex(node); |
500 if ((shouldVisit(node) || isNonKeyboardFocusableShadowHost(node)) && cur
rentTabIndex < tabIndex && currentTabIndex > winningTabIndex) { | 500 if ((shouldVisit(node) || isNonKeyboardFocusableShadowHost(node)) && cur
rentTabIndex < tabIndex && currentTabIndex > winningTabIndex) { |
501 winner = node; | 501 winner = node; |
502 winningTabIndex = currentTabIndex; | 502 winningTabIndex = currentTabIndex; |
503 } | 503 } |
504 } | 504 } |
505 return winner; | 505 return winner; |
506 } | 506 } |
507 | 507 |
508 Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start
) | 508 Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start
) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 Node* last = 0; | 542 Node* last = 0; |
543 for (Node* node = scope.rootNode(); node; node = node->lastChild()) | 543 for (Node* node = scope.rootNode(); node; node = node->lastChild()) |
544 last = node; | 544 last = node; |
545 ASSERT(last); | 545 ASSERT(last); |
546 | 546 |
547 // First try to find the last node in the scope that comes before start and
has the same tabindex as start. | 547 // First try to find the last node in the scope that comes before start and
has the same tabindex as start. |
548 // If start is null, find the last node in the scope with a tabindex of 0. | 548 // If start is null, find the last node in the scope with a tabindex of 0. |
549 Node* startingNode; | 549 Node* startingNode; |
550 int startingTabIndex; | 550 int startingTabIndex; |
551 if (start) { | 551 if (start) { |
552 startingNode = NodeTraversal::previous(start); | 552 startingNode = NodeTraversal::previous(*start); |
553 startingTabIndex = adjustedTabIndex(start); | 553 startingTabIndex = adjustedTabIndex(start); |
554 } else { | 554 } else { |
555 startingNode = last; | 555 startingNode = last; |
556 startingTabIndex = 0; | 556 startingTabIndex = 0; |
557 } | 557 } |
558 | 558 |
559 // However, if a node is excluded from the normal tabbing cycle, the previou
s focusable node is determined by tree order | 559 // However, if a node is excluded from the normal tabbing cycle, the previou
s focusable node is determined by tree order |
560 if (startingTabIndex < 0) { | 560 if (startingTabIndex < 0) { |
561 for (Node* node = startingNode; node; node = NodeTraversal::previous(nod
e)) { | 561 for (Node* node = startingNode; node; node = NodeTraversal::previous(*no
de)) { |
562 if (shouldVisit(node) && adjustedTabIndex(node) >= 0) | 562 if (shouldVisit(node) && adjustedTabIndex(node) >= 0) |
563 return node; | 563 return node; |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex,
FocusDirectionBackward)) | 567 if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex,
FocusDirectionBackward)) |
568 return winner; | 568 return winner; |
569 | 569 |
570 // There are no nodes before start with the same tabindex as start, so look
for a node that: | 570 // There are no nodes before start with the same tabindex as start, so look
for a node that: |
571 // 1) has the highest non-zero tabindex (that is less than start's tabindex)
, and | 571 // 1) has the highest non-zero tabindex (that is less than start's tabindex)
, and |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); | 900 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); |
901 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct
ion, container); | 901 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct
ion, container); |
902 if (container && container->isDocumentNode()) | 902 if (container && container->isDocumentNode()) |
903 toDocument(container)->updateLayoutIgnorePendingStylesheets(); | 903 toDocument(container)->updateLayoutIgnorePendingStylesheets(); |
904 } while (!consumed && container); | 904 } while (!consumed && container); |
905 | 905 |
906 return consumed; | 906 return consumed; |
907 } | 907 } |
908 | 908 |
909 } // namespace WebCore | 909 } // namespace WebCore |
OLD | NEW |