Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: Source/core/page/FocusController.cpp

Issue 1152623012: WIP: delegatesFocus (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/EventHandler.cpp ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 ASSERT(!currentNode || !isNonFocusableShadowHost(*currentNode)); 519 ASSERT(!currentNode || !isNonFocusableShadowHost(*currentNode));
520 Node* found = findFocusableNodeRecursivelyBackward(scope, currentNode); 520 Node* found = findFocusableNodeRecursivelyBackward(scope, currentNode);
521 521
522 // If there's no focusable node to advance to, move up the focus scopes unti l we find one. 522 // If there's no focusable node to advance to, move up the focus scopes unti l we find one.
523 FocusNavigationScope currentScope = scope; 523 FocusNavigationScope currentScope = scope;
524 while (!found) { 524 while (!found) {
525 Node* owner = currentScope.owner(); 525 Node* owner = currentScope.owner();
526 if (!owner) 526 if (!owner)
527 break; 527 break;
528 currentScope = FocusNavigationScope::focusNavigationScopeOf(*owner); 528 currentScope = FocusNavigationScope::focusNavigationScopeOf(*owner);
529 if (isKeyboardFocusableShadowHost(*owner) && toElement(owner)->tabStop() ) { 529 if (isKeyboardFocusableShadowHost(*owner) && !toElement(owner)->shadowRo ot()->delegatesFocus()) {
530 found = owner; 530 found = owner;
531 break; 531 break;
532 } 532 }
533 found = findFocusableNodeRecursivelyBackward(currentScope, owner); 533 found = findFocusableNodeRecursivelyBackward(currentScope, owner);
534 } 534 }
535 return findFocusableNodeDecendingDownIntoFrameDocument(WebFocusTypeBackward, found); 535 return findFocusableNodeDecendingDownIntoFrameDocument(WebFocusTypeBackward, found);
536 } 536 }
537 537
538 Node* FocusController::findFocusableNodeRecursively(WebFocusType type, const Foc usNavigationScope& scope, Node* start) 538 Node* FocusController::findFocusableNodeRecursively(WebFocusType type, const Foc usNavigationScope& scope, Node* start)
539 { 539 {
540 return (type == WebFocusTypeForward) ? 540 return (type == WebFocusTypeForward) ?
541 findFocusableNodeRecursivelyForward(scope, start) : 541 findFocusableNodeRecursivelyForward(scope, start) :
542 findFocusableNodeRecursivelyBackward(scope, start); 542 findFocusableNodeRecursivelyBackward(scope, start);
543 } 543 }
544 544
545 Node* FocusController::findFocusableNodeRecursivelyForward(const FocusNavigation Scope& scope, Node* start) 545 Node* FocusController::findFocusableNodeRecursivelyForward(const FocusNavigation Scope& scope, Node* start)
546 { 546 {
547 // Starting node is exclusive. 547 // Starting node is exclusive.
548 Node* found = findFocusableNode(WebFocusTypeForward, scope, start); 548 Node* found = findFocusableNode(WebFocusTypeForward, scope, start);
549 if (!found) 549 if (!found)
550 return nullptr; 550 return nullptr;
551 if (found->isElementNode() && !toElement(found)->tabStop()) { 551 // TODO(kochi): simplify this logic further.
552 if (found->isElementNode() && toElement(found)->shadowRoot() && toElement(fo und)->shadowRoot()->delegatesFocus()) {
552 if (isShadowHostWithoutCustomFocusLogic(*found)) { 553 if (isShadowHostWithoutCustomFocusLogic(*found)) {
553 FocusNavigationScope innerScope = FocusNavigationScope::ownedByShado wHost(*found); 554 FocusNavigationScope innerScope = FocusNavigationScope::ownedByShado wHost(*found);
554 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyForward(i nnerScope, nullptr); 555 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyForward(i nnerScope, nullptr);
555 return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusab leNodeRecursivelyForward(scope, found); 556 return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusab leNodeRecursivelyForward(scope, found);
556 } 557 }
557 // Skip to the next node. 558 // Skip to the next node.
558 if (!isNonFocusableFocusScopeOwner(*found)) 559 if (!isNonFocusableFocusScopeOwner(*found))
559 found = findFocusableNodeRecursivelyForward(scope, found); 560 found = findFocusableNodeRecursivelyForward(scope, found);
560 } 561 }
561 if (!found || !isNonFocusableFocusScopeOwner(*found)) 562 if (!found || !isNonFocusableFocusScopeOwner(*found))
(...skipping 15 matching lines...) Expand all
577 return nullptr; 578 return nullptr;
578 579
579 // Now |found| is on a focusable shadow host. 580 // Now |found| is on a focusable shadow host.
580 // Find inside shadow backwards. If any focusable element is found, return i t, otherwise return 581 // Find inside shadow backwards. If any focusable element is found, return i t, otherwise return
581 // the host itself. 582 // the host itself.
582 if (isKeyboardFocusableShadowHost(*found)) { 583 if (isKeyboardFocusableShadowHost(*found)) {
583 FocusNavigationScope innerScope = FocusNavigationScope::ownedByShadowHos t(*found); 584 FocusNavigationScope innerScope = FocusNavigationScope::ownedByShadowHos t(*found);
584 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyBackward(inne rScope, nullptr); 585 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyBackward(inne rScope, nullptr);
585 if (foundInInnerFocusScope) 586 if (foundInInnerFocusScope)
586 return foundInInnerFocusScope; 587 return foundInInnerFocusScope;
587 if (found->isElementNode() && !toElement(found)->tabStop()) 588 // TODO(kochi): Simplify this logic further.
589 if (found->isElementNode() && toElement(found)->shadowRoot() && toElemen t(found)->shadowRoot()->delegatesFocus())
588 found = findFocusableNodeRecursivelyBackward(scope, found); 590 found = findFocusableNodeRecursivelyBackward(scope, found);
589 return found; 591 return found;
590 } 592 }
591 593
592 // Now |found| is on a non focusable scope owner (either shadow host or <sha dow>). 594 // Now |found| is on a non focusable scope owner (either shadow host or <sha dow>).
593 // Find focusable node in decendant scope. If not found, find next focusable node within the 595 // Find focusable node in decendant scope. If not found, find next focusable node within the
594 // current scope. 596 // current scope.
595 if (isNonFocusableFocusScopeOwner(*found)) { 597 if (isNonFocusableFocusScopeOwner(*found)) {
596 FocusNavigationScope innerScope = FocusNavigationScope::ownedByNonFocusa bleFocusScopeOwner(*found); 598 FocusNavigationScope innerScope = FocusNavigationScope::ownedByNonFocusa bleFocusScopeOwner(*found);
597 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyBackward(inne rScope, nullptr); 599 Node* foundInInnerFocusScope = findFocusableNodeRecursivelyBackward(inne rScope, nullptr);
598 return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNo deRecursivelyBackward(scope, found); 600 return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNo deRecursivelyBackward(scope, found);
599 } 601 }
600 602
601 return found->isElementNode() && toElement(found)->tabStop() ? found : findF ocusableNodeRecursivelyBackward(scope, found); 603 return found->isElementNode() && !(toElement(found)->shadowRoot() && toEleme nt(found)->shadowRoot()->delegatesFocus()) ? found : findFocusableNodeRecursivel yBackward(scope, found);
602 } 604 }
603 605
604 static Node* findNodeWithExactTabIndex(Node* start, int tabIndex, WebFocusType t ype) 606 static Node* findNodeWithExactTabIndex(Node* start, int tabIndex, WebFocusType t ype)
605 { 607 {
606 // Search is inclusive of start 608 // Search is inclusive of start
607 for (Node* node = start; node; node = type == WebFocusTypeForward ? NodeTrav ersal::next(*node) : NodeTraversal::previous(*node)) { 609 for (Node* node = start; node; node = type == WebFocusTypeForward ? NodeTrav ersal::next(*node) : NodeTraversal::previous(*node)) {
608 if (shouldVisit(*node) && adjustedTabIndex(*node) == tabIndex) 610 if (shouldVisit(*node) && adjustedTabIndex(*node) == tabIndex)
609 return node; 611 return node;
610 } 612 }
611 return nullptr; 613 return nullptr;
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 return consumed; 1012 return consumed;
1011 } 1013 }
1012 1014
1013 DEFINE_TRACE(FocusController) 1015 DEFINE_TRACE(FocusController)
1014 { 1016 {
1015 visitor->trace(m_page); 1017 visitor->trace(m_page);
1016 visitor->trace(m_focusedFrame); 1018 visitor->trace(m_focusedFrame);
1017 } 1019 }
1018 1020
1019 } // namespace blink 1021 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/EventHandler.cpp ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698