|
Lines 300-306
Element* FocusController::findFocusableE
Source/WebCore/page/FocusController.cpp_sec1
|
| 300 |
HTMLFrameOwnerElement& owner = downcast<HTMLFrameOwnerElement>(*element); |
300 |
HTMLFrameOwnerElement& owner = downcast<HTMLFrameOwnerElement>(*element); |
| 301 |
if (!owner.contentFrame()) |
301 |
if (!owner.contentFrame()) |
| 302 |
break; |
302 |
break; |
| 303 |
Element* foundElement = findFocusableElement(direction, FocusNavigationScope::scopeOwnedByIFrame(owner), 0, event); |
303 |
// FIXME: This can return a non-focusable shadow root. |
|
|
304 |
Element* foundElement = findFocusableElementOrScopeOwner(direction, FocusNavigationScope::scopeOwnedByIFrame(owner), 0, event); |
| 304 |
if (!foundElement) |
305 |
if (!foundElement) |
| 305 |
break; |
306 |
break; |
| 306 |
ASSERT(element != foundElement); |
307 |
ASSERT(element != foundElement); |
|
Lines 366-373
bool FocusController::advanceFocusInDocu
Source/WebCore/page/FocusController.cpp_sec2
|
| 366 |
} |
367 |
} |
| 367 |
|
368 |
|
| 368 |
// Chrome doesn't want focus, so we should wrap focus. |
369 |
// Chrome doesn't want focus, so we should wrap focus. |
| 369 |
element = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOf(*m_page.mainFrame().document()), 0, event); |
370 |
element = findFocusableElementAcrossFocusScope(direction, FocusNavigationScope::scopeOf(*m_page.mainFrame().document()), nullptr, event); |
| 370 |
element = findFocusableElementDescendingDownIntoFrameDocument(direction, element.get(), event); |
|
|
| 371 |
|
371 |
|
| 372 |
if (!element) |
372 |
if (!element) |
| 373 |
return false; |
373 |
return false; |
|
Lines 421-477
bool FocusController::advanceFocusInDocu
Source/WebCore/page/FocusController.cpp_sec3
|
| 421 |
Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent* event) |
421 |
Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent* event) |
| 422 |
{ |
422 |
{ |
| 423 |
ASSERT(!is<Element>(currentNode) || !isNonFocusableShadowHost(*downcast<Element>(currentNode), *event)); |
423 |
ASSERT(!is<Element>(currentNode) || !isNonFocusableShadowHost(*downcast<Element>(currentNode), *event)); |
| 424 |
Element* found; |
424 |
|
| 425 |
if (currentNode && direction == FocusDirectionForward && isFocusableShadowHost(*currentNode, *event)) { |
425 |
if (currentNode && direction == FocusDirectionForward && isFocusableShadowHost(*currentNode, *event)) { |
| 426 |
Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(downcast<Element>(*currentNode)), 0, event); |
426 |
if (Element* candidateInInnerScope = findFocusableElementWithinScope(direction, FocusNavigationScope::scopeOwnedByShadowHost(downcast<Element>(*currentNode)), 0, event)) |
| 427 |
found = foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, currentNode, event); |
427 |
return candidateInInnerScope; |
| 428 |
} else |
428 |
} |
| 429 |
found = findFocusableElementRecursively(direction, scope, currentNode, event); |
429 |
|
|
|
430 |
if (Element* candidateInCurrentScope = findFocusableElementWithinScope(direction, scope, currentNode, event)) |
| 431 |
return candidateInCurrentScope; |
| 430 |
|
432 |
|
| 431 |
// If there's no focusable node to advance to, move up the focus scopes until we find one. |
433 |
// If there's no focusable node to advance to, move up the focus scopes until we find one. |
| 432 |
Element* owner = scope.owner(); |
434 |
Element* owner = scope.owner(); |
| 433 |
while (!found && owner) { |
435 |
while (owner) { |
| 434 |
FocusNavigationScope currentScope = FocusNavigationScope::scopeOf(*owner); |
436 |
FocusNavigationScope outerScope = FocusNavigationScope::scopeOf(*owner); |
| 435 |
if (direction == FocusDirectionBackward && isFocusableShadowHost(*owner, *event)) { |
437 |
if (direction == FocusDirectionBackward && isFocusableShadowHost(*owner, *event)) |
| 436 |
found = owner; |
438 |
return findFocusableElementDescendingDownIntoFrameDocument(direction, owner, event); |
| 437 |
break; |
439 |
if (Element* candidateInOuterScope = findFocusableElementWithinScope(direction, outerScope, owner, event)) |
| 438 |
} |
440 |
return candidateInOuterScope; |
| 439 |
found = findFocusableElementRecursively(direction, currentScope, owner, event); |
441 |
owner = outerScope.owner(); |
| 440 |
owner = currentScope.owner(); |
|
|
| 441 |
} |
442 |
} |
| 442 |
found = findFocusableElementDescendingDownIntoFrameDocument(direction, found, event); |
443 |
return nullptr; |
| 443 |
return found; |
|
|
| 444 |
} |
444 |
} |
| 445 |
|
445 |
|
| 446 |
Element* FocusController::findFocusableElementRecursively(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
446 |
Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
| 447 |
{ |
447 |
{ |
| 448 |
// Starting node is exclusive. |
448 |
// Starting node is exclusive. |
| 449 |
Element* found = findFocusableElement(direction, scope, start, event); |
449 |
Element* candidate = direction == FocusDirectionForward |
|
|
450 |
? nextFocusableElementWithinScope(scope, start, event) |
| 451 |
: previousFocusableElementWithinScope(scope, start, event); |
| 452 |
return findFocusableElementDescendingDownIntoFrameDocument(direction, candidate, event); |
| 453 |
} |
| 454 |
|
| 455 |
Element* FocusController::nextFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
| 456 |
{ |
| 457 |
Element* found = nextFocusableElementOrScopeOwner(scope, start, event); |
| 450 |
if (!found) |
458 |
if (!found) |
| 451 |
return nullptr; |
459 |
return nullptr; |
| 452 |
if (direction == FocusDirectionForward) { |
460 |
if (isNonFocusableShadowHost(*found, *event)) { |
| 453 |
if (!isNonFocusableShadowHost(*found, *event)) |
461 |
if (Element* foundInInnerFocusScope = nextFocusableElementWithinScope(FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event)) |
| 454 |
return found; |
462 |
return foundInInnerFocusScope; |
| 455 |
Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); |
463 |
return nextFocusableElementWithinScope(scope, found, event); |
| 456 |
return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, found, event); |
|
|
| 457 |
} |
464 |
} |
| 458 |
ASSERT(direction == FocusDirectionBackward); |
465 |
return found; |
|
|
466 |
} |
| 467 |
|
| 468 |
Element* FocusController::previousFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
| 469 |
{ |
| 470 |
Element* found = previousFocusableElementOrScopeOwner(scope, start, event); |
| 471 |
if (!found) |
| 472 |
return nullptr; |
| 459 |
if (isFocusableShadowHost(*found, *event)) { |
473 |
if (isFocusableShadowHost(*found, *event)) { |
| 460 |
Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); |
474 |
// Search an inner focusable element in the shadow tree from the end. |
| 461 |
return foundInInnerFocusScope ? foundInInnerFocusScope : found; |
475 |
if (Element* foundInInnerFocusScope = previousFocusableElementWithinScope(FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event)) |
|
|
476 |
return foundInInnerFocusScope; |
| 477 |
return found; |
| 462 |
} |
478 |
} |
| 463 |
if (isNonFocusableShadowHost(*found, *event)) { |
479 |
if (isNonFocusableShadowHost(*found, *event)) { |
| 464 |
Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); |
480 |
if (Element* foundInInnerFocusScope = previousFocusableElementWithinScope(FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event)) |
| 465 |
return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableElementRecursively(direction, scope, found, event); |
481 |
return foundInInnerFocusScope; |
|
|
482 |
return previousFocusableElementWithinScope(scope, found, event); |
| 466 |
} |
483 |
} |
| 467 |
return found; |
484 |
return found; |
| 468 |
} |
485 |
} |
| 469 |
|
486 |
|
| 470 |
Element* FocusController::findFocusableElement(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent* event) |
487 |
Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent* event) |
| 471 |
{ |
488 |
{ |
| 472 |
return (direction == FocusDirectionForward) |
489 |
return (direction == FocusDirectionForward) |
| 473 |
? nextFocusableElement(scope, node, event) |
490 |
? nextFocusableElementOrScopeOwner(scope, node, event) |
| 474 |
: previousFocusableElement(scope, node, event); |
491 |
: previousFocusableElementOrScopeOwner(scope, node, event); |
| 475 |
} |
492 |
} |
| 476 |
|
493 |
|
| 477 |
Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction) |
494 |
Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction) |
|
Lines 528-544
static Element* previousElementWithLower
Source/WebCore/page/FocusController.cpp_sec4
|
| 528 |
|
545 |
|
| 529 |
Element* FocusController::nextFocusableElement(Node& start) |
546 |
Element* FocusController::nextFocusableElement(Node& start) |
| 530 |
{ |
547 |
{ |
|
|
548 |
// FIXME: This can return a non-focusable shadow host. |
| 531 |
Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); |
549 |
Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); |
| 532 |
return nextFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); |
550 |
return nextFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); |
| 533 |
} |
551 |
} |
| 534 |
|
552 |
|
| 535 |
Element* FocusController::previousFocusableElement(Node& start) |
553 |
Element* FocusController::previousFocusableElement(Node& start) |
| 536 |
{ |
554 |
{ |
|
|
555 |
// FIXME: This can return a non-focusable shadow host. |
| 537 |
Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); |
556 |
Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); |
| 538 |
return previousFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); |
557 |
return previousFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); |
| 539 |
} |
558 |
} |
| 540 |
|
559 |
|
| 541 |
Element* FocusController::nextFocusableElement(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
560 |
Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
| 542 |
{ |
561 |
{ |
| 543 |
int startTabIndex = 0; |
562 |
int startTabIndex = 0; |
| 544 |
if (start && is<Element>(*start)) |
563 |
if (start && is<Element>(*start)) |
|
Lines 575-581
Element* FocusController::nextFocusableE
Source/WebCore/page/FocusController.cpp_sec5
|
| 575 |
return findElementWithExactTabIndex(scope, &scope.rootNode(), 0, event, FocusDirectionForward); |
594 |
return findElementWithExactTabIndex(scope, &scope.rootNode(), 0, event, FocusDirectionForward); |
| 576 |
} |
595 |
} |
| 577 |
|
596 |
|
| 578 |
Element* FocusController::previousFocusableElement(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
597 |
Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event) |
| 579 |
{ |
598 |
{ |
| 580 |
Node* last = nullptr; |
599 |
Node* last = nullptr; |
| 581 |
for (Node* node = &scope.rootNode(); node; node = scope.lastChildInScope(node)) |
600 |
for (Node* node = &scope.rootNode(); node; node = scope.lastChildInScope(node)) |