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

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

Issue 65303008: Have ElementTraversal::firstWithin() take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 1 month 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
« no previous file with comments | « Source/core/page/FocusController.h ('k') | Source/core/svg/SVGElement.cpp » ('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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 if (candidate.alignment == closest.alignment) { 760 if (candidate.alignment == closest.alignment) {
761 if (candidate.distance < closest.distance) 761 if (candidate.distance < closest.distance)
762 closest = candidate; 762 closest = candidate;
763 return; 763 return;
764 } 764 }
765 765
766 if (candidate.alignment > closest.alignment) 766 if (candidate.alignment > closest.alignment)
767 closest = candidate; 767 closest = candidate;
768 } 768 }
769 769
770 void FocusController::findFocusCandidateInContainer(Node* container, const Layou tRect& startingRect, FocusDirection direction, FocusCandidate& closest) 770 void FocusController::findFocusCandidateInContainer(Node& container, const Layou tRect& startingRect, FocusDirection direction, FocusCandidate& closest)
771 { 771 {
772 ASSERT(container);
773 Element* focusedElement = (focusedFrame() && focusedFrame()->document()) ? f ocusedFrame()->document()->focusedElement() : 0; 772 Element* focusedElement = (focusedFrame() && focusedFrame()->document()) ? f ocusedFrame()->document()->focusedElement() : 0;
774 773
775 Element* element = ElementTraversal::firstWithin(container); 774 Element* element = ElementTraversal::firstWithin(container);
776 FocusCandidate current; 775 FocusCandidate current;
777 current.rect = startingRect; 776 current.rect = startingRect;
778 current.focusableNode = focusedElement; 777 current.focusableNode = focusedElement;
779 current.visibleNode = focusedElement; 778 current.visibleNode = focusedElement;
780 779
781 for (; element; element = (element->isFrameOwnerElement() || canScrollInDire ction(element, direction)) 780 for (; element; element = (element->isFrameOwnerElement() || canScrollInDire ction(element, direction))
782 ? ElementTraversal::nextSkippingChildren(*element, container) 781 ? ElementTraversal::nextSkippingChildren(*element, &container)
783 : ElementTraversal::next(*element, container)) { 782 : ElementTraversal::next(*element, &container)) {
784 if (element == focusedElement) 783 if (element == focusedElement)
785 continue; 784 continue;
786 785
787 if (!element->isKeyboardFocusable() && !element->isFrameOwnerElement() & & !canScrollInDirection(element, direction)) 786 if (!element->isKeyboardFocusable() && !element->isFrameOwnerElement() & & !canScrollInDirection(element, direction))
788 continue; 787 continue;
789 788
790 FocusCandidate candidate = FocusCandidate(element, direction); 789 FocusCandidate candidate = FocusCandidate(element, direction);
791 if (candidate.isNull()) 790 if (candidate.isNull())
792 continue; 791 continue;
793 792
794 candidate.enclosingScrollableBox = container; 793 candidate.enclosingScrollableBox = &container;
795 updateFocusCandidateIfNeeded(direction, current, candidate, closest); 794 updateFocusCandidateIfNeeded(direction, current, candidate, closest);
796 } 795 }
797 } 796 }
798 797
799 bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons t LayoutRect& startingRect, FocusDirection direction) 798 bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons t LayoutRect& startingRect, FocusDirection direction)
800 { 799 {
801 if (!container) 800 if (!container)
802 return false; 801 return false;
803 802
804 LayoutRect newStartingRect = startingRect; 803 LayoutRect newStartingRect = startingRect;
805 804
806 if (startingRect.isEmpty()) 805 if (startingRect.isEmpty())
807 newStartingRect = virtualRectForDirection(direction, nodeRectInAbsoluteC oordinates(container)); 806 newStartingRect = virtualRectForDirection(direction, nodeRectInAbsoluteC oordinates(container));
808 807
809 // Find the closest node within current container in the direction of the na vigation. 808 // Find the closest node within current container in the direction of the na vigation.
810 FocusCandidate focusCandidate; 809 FocusCandidate focusCandidate;
811 findFocusCandidateInContainer(container, newStartingRect, direction, focusCa ndidate); 810 findFocusCandidateInContainer(*container, newStartingRect, direction, focusC andidate);
812 811
813 if (focusCandidate.isNull()) { 812 if (focusCandidate.isNull()) {
814 // Nothing to focus, scroll if possible. 813 // Nothing to focus, scroll if possible.
815 // NOTE: If no scrolling is performed (i.e. scrollInDirection returns fa lse), the 814 // NOTE: If no scrolling is performed (i.e. scrollInDirection returns fa lse), the
816 // spatial navigation algorithm will skip this container. 815 // spatial navigation algorithm will skip this container.
817 return scrollInDirection(container, direction); 816 return scrollInDirection(container, direction);
818 } 817 }
819 818
820 if (HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate)) { 819 if (HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate)) {
821 // If we have an iframe without the src attribute, it will not have a co ntentFrame(). 820 // If we have an iframe without the src attribute, it will not have a co ntentFrame().
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 899 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
901 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container); 900 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container);
902 if (container && container->isDocumentNode()) 901 if (container && container->isDocumentNode())
903 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 902 toDocument(container)->updateLayoutIgnorePendingStylesheets();
904 } while (!consumed && container); 903 } while (!consumed && container);
905 904
906 return consumed; 905 return consumed;
907 } 906 }
908 907
909 } // namespace WebCore 908 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/FocusController.h ('k') | Source/core/svg/SVGElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698