Changeset 205290 in webkit
- Timestamp:
- Sep 1, 2016 7:22:33 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r205289 r205290 1 2016-09-01 Andreas Kling <akling@apple.com> 2 3 FocusController should pass KeyboardEvent around by reference. 4 <https://webkit.org/b/161461> 5 6 Reviewed by Sam Weinig. 7 8 Clean up FocusController to pass KeyboardEvent& around internally. 9 10 Also make FocusController::setInitialFocus() synthesize a dummy KeyboardEvent 11 if one isn't provided, just like nextFocusableElement()/previousFocusableElement() does. 12 This way we can feel confident about dereferencing the formerly KeyboardEvent* everywhere. 13 14 * page/EventHandler.cpp: 15 (WebCore::EventHandler::defaultArrowEventHandler): 16 (WebCore::EventHandler::defaultTabEventHandler): 17 * page/FocusController.cpp: 18 (WebCore::isFocusableElementOrScopeOwner): 19 (WebCore::isNonFocusableScopeOwner): 20 (WebCore::isFocusableScopeOwner): 21 (WebCore::shadowAdjustedTabIndex): 22 (WebCore::FocusController::findFocusableElementDescendingDownIntoFrameDocument): 23 (WebCore::FocusController::setInitialFocus): 24 (WebCore::FocusController::advanceFocus): 25 (WebCore::FocusController::advanceFocusInDocumentOrder): 26 (WebCore::FocusController::findFocusableElementAcrossFocusScope): 27 (WebCore::FocusController::findFocusableElementWithinScope): 28 (WebCore::FocusController::nextFocusableElementWithinScope): 29 (WebCore::FocusController::previousFocusableElementWithinScope): 30 (WebCore::FocusController::findFocusableElementOrScopeOwner): 31 (WebCore::FocusController::findElementWithExactTabIndex): 32 (WebCore::nextElementWithGreaterTabIndex): 33 (WebCore::previousElementWithLowerTabIndex): 34 (WebCore::FocusController::nextFocusableElement): 35 (WebCore::FocusController::previousFocusableElement): 36 (WebCore::FocusController::nextFocusableElementOrScopeOwner): 37 (WebCore::FocusController::previousFocusableElementOrScopeOwner): 38 (WebCore::FocusController::findFocusCandidateInContainer): 39 (WebCore::FocusController::advanceFocusDirectionallyInContainer): 40 (WebCore::FocusController::advanceFocusDirectionally): 41 * page/FocusController.h: 42 1 43 2016-09-01 Romain Bellessort <romain.bellessort@crf.canon.fr> 2 44 -
trunk/Source/WebCore/page/EventHandler.cpp
r205249 r205290 3667 3667 return; 3668 3668 3669 if (page->focusController().advanceFocus(focusDirection, &event))3669 if (page->focusController().advanceFocus(focusDirection, event)) 3670 3670 event.setDefaultHandled(); 3671 3671 } … … 3691 3691 return; 3692 3692 3693 if (page->focusController().advanceFocus(focusDirection, &event))3693 if (page->focusController().advanceFocus(focusDirection, event)) 3694 3694 event.setDefaultHandled(); 3695 3695 } -
trunk/Source/WebCore/page/FocusController.cpp
r205249 r205290 290 290 } 291 291 292 static inline bool isFocusableElementOrScopeOwner(Element& element, KeyboardEvent *event)293 { 294 return element.isKeyboardFocusable( *event) || isFocusScopeOwner(element);295 } 296 297 static inline bool isNonFocusableScopeOwner(Element& element, KeyboardEvent *event)298 { 299 return !element.isKeyboardFocusable( *event) && isFocusScopeOwner(element);300 } 301 302 static inline bool isFocusableScopeOwner(Element& element, KeyboardEvent *event)303 { 304 return element.isKeyboardFocusable( *event) && isFocusScopeOwner(element);305 } 306 307 static inline int shadowAdjustedTabIndex(Element& element, KeyboardEvent *event)292 static inline bool isFocusableElementOrScopeOwner(Element& element, KeyboardEvent& event) 293 { 294 return element.isKeyboardFocusable(event) || isFocusScopeOwner(element); 295 } 296 297 static inline bool isNonFocusableScopeOwner(Element& element, KeyboardEvent& event) 298 { 299 return !element.isKeyboardFocusable(event) && isFocusScopeOwner(element); 300 } 301 302 static inline bool isFocusableScopeOwner(Element& element, KeyboardEvent& event) 303 { 304 return element.isKeyboardFocusable(event) && isFocusScopeOwner(element); 305 } 306 307 static inline int shadowAdjustedTabIndex(Element& element, KeyboardEvent& event) 308 308 { 309 309 if (isNonFocusableScopeOwner(element, event)) { … … 377 377 } 378 378 379 Element* FocusController::findFocusableElementDescendingDownIntoFrameDocument(FocusDirection direction, Element* element, KeyboardEvent *event)379 Element* FocusController::findFocusableElementDescendingDownIntoFrameDocument(FocusDirection direction, Element* element, KeyboardEvent& event) 380 380 { 381 381 // The node we found might be a HTMLFrameOwnerElement, so descend down the tree until we find either: … … 395 395 } 396 396 397 bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* event) 398 { 399 bool didAdvanceFocus = advanceFocus(direction, event, true); 397 bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* providedEvent) 398 { 399 RefPtr<KeyboardEvent> event = providedEvent; 400 if (!event) 401 event = KeyboardEvent::createForDummy(); 402 403 bool didAdvanceFocus = advanceFocus(direction, *event, true); 400 404 401 405 // If focus is being set initially, accessibility needs to be informed that system focus has moved … … 408 412 } 409 413 410 bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent *event, bool initialFocus)414 bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent& event, bool initialFocus) 411 415 { 412 416 switch (direction) { … … 426 430 } 427 431 428 bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, KeyboardEvent *event, bool initialFocus)432 bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, KeyboardEvent& event, bool initialFocus) 429 433 { 430 434 Frame& frame = focusedOrMainFrame(); … … 465 469 } 466 470 467 if (is<HTMLFrameOwnerElement>(*element) && (!is<HTMLPlugInElement>(*element) || !element->isKeyboardFocusable( *event))) {471 if (is<HTMLFrameOwnerElement>(*element) && (!is<HTMLPlugInElement>(*element) || !element->isKeyboardFocusable(event))) { 468 472 // We focus frames rather than frame owners. 469 473 // FIXME: We should not focus frames that have no scrollbars, as focusing them isn't useful to the user. … … 503 507 } 504 508 505 Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent *event)509 Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent& event) 506 510 { 507 511 ASSERT(!is<Element>(currentNode) || !isNonFocusableScopeOwner(downcast<Element>(*currentNode), event)); … … 529 533 } 530 534 531 Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent *event)535 Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent& event) 532 536 { 533 537 // Starting node is exclusive. … … 538 542 } 539 543 540 Element* FocusController::nextFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent *event)544 Element* FocusController::nextFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event) 541 545 { 542 546 Element* found = nextFocusableElementOrScopeOwner(scope, start, event); … … 551 555 } 552 556 553 Element* FocusController::previousFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent *event)557 Element* FocusController::previousFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event) 554 558 { 555 559 Element* found = previousFocusableElementOrScopeOwner(scope, start, event); … … 570 574 } 571 575 572 Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent *event)576 Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent& event) 573 577 { 574 578 return (direction == FocusDirectionForward) … … 577 581 } 578 582 579 Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent *event, FocusDirection direction)583 Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent& event, FocusDirection direction) 580 584 { 581 585 // Search is inclusive of start … … 590 594 } 591 595 592 static Element* nextElementWithGreaterTabIndex(const FocusNavigationScope& scope, int tabIndex, KeyboardEvent *event)596 static Element* nextElementWithGreaterTabIndex(const FocusNavigationScope& scope, int tabIndex, KeyboardEvent& event) 593 597 { 594 598 // Search is inclusive of start … … 609 613 } 610 614 611 static Element* previousElementWithLowerTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent *event)615 static Element* previousElementWithLowerTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent& event) 612 616 { 613 617 // Search is inclusive of start … … 631 635 // FIXME: This can return a non-focusable shadow host. 632 636 Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); 633 return nextFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent. ptr());637 return nextFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.get()); 634 638 } 635 639 … … 638 642 // FIXME: This can return a non-focusable shadow host. 639 643 Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); 640 return previousFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent. ptr());641 } 642 643 Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent *event)644 return previousFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.get()); 645 } 646 647 Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event) 644 648 { 645 649 int startTabIndex = 0; … … 678 682 } 679 683 680 Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent *event)684 Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event) 681 685 { 682 686 Node* last = nullptr; … … 938 942 } 939 943 940 void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent *event, FocusCandidate& closest)944 void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent& event, FocusCandidate& closest) 941 945 { 942 946 Node* focusedNode = (focusedFrame() && focusedFrame()->document()) ? focusedFrame()->document()->focusedElement() : 0; … … 955 959 continue; 956 960 957 if (!element->isKeyboardFocusable( *event) && !element->isFrameOwnerElement() && !canScrollInDirection(element, direction))961 if (!element->isKeyboardFocusable(event) && !element->isFrameOwnerElement() && !canScrollInDirection(element, direction)) 958 962 continue; 959 963 … … 978 982 } 979 983 980 bool FocusController::advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent *event)984 bool FocusController::advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent& event) 981 985 { 982 986 if (!container) … … 1048 1052 } 1049 1053 1050 bool FocusController::advanceFocusDirectionally(FocusDirection direction, KeyboardEvent *event)1054 bool FocusController::advanceFocusDirectionally(FocusDirection direction, KeyboardEvent& event) 1051 1055 { 1052 1056 Document* focusedDocument = focusedOrMainFrame().document(); -
trunk/Source/WebCore/page/FocusController.h
r200576 r205290 60 60 61 61 WEBCORE_EXPORT bool setInitialFocus(FocusDirection, KeyboardEvent*); 62 bool advanceFocus(FocusDirection, KeyboardEvent *, bool initialFocus = false);62 bool advanceFocus(FocusDirection, KeyboardEvent&, bool initialFocus = false); 63 63 64 64 WEBCORE_EXPORT bool setFocusedElement(Element*, PassRefPtr<Frame>, FocusDirection = FocusDirectionNone); … … 86 86 void setIsVisibleAndActiveInternal(bool); 87 87 88 bool advanceFocusDirectionally(FocusDirection, KeyboardEvent *);89 bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent *, bool initialFocus);88 bool advanceFocusDirectionally(FocusDirection, KeyboardEvent&); 89 bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent&, bool initialFocus); 90 90 91 Element* findFocusableElementAcrossFocusScope(FocusDirection, const FocusNavigationScope& startScope, Node* start, KeyboardEvent *);91 Element* findFocusableElementAcrossFocusScope(FocusDirection, const FocusNavigationScope& startScope, Node* start, KeyboardEvent&); 92 92 93 Element* findFocusableElementWithinScope(FocusDirection, const FocusNavigationScope&, Node* start, KeyboardEvent *);94 Element* nextFocusableElementWithinScope(const FocusNavigationScope&, Node* start, KeyboardEvent *);95 Element* previousFocusableElementWithinScope(const FocusNavigationScope&, Node* start, KeyboardEvent *);93 Element* findFocusableElementWithinScope(FocusDirection, const FocusNavigationScope&, Node* start, KeyboardEvent&); 94 Element* nextFocusableElementWithinScope(const FocusNavigationScope&, Node* start, KeyboardEvent&); 95 Element* previousFocusableElementWithinScope(const FocusNavigationScope&, Node* start, KeyboardEvent&); 96 96 97 Element* findFocusableElementDescendingDownIntoFrameDocument(FocusDirection, Element*, KeyboardEvent *);97 Element* findFocusableElementDescendingDownIntoFrameDocument(FocusDirection, Element*, KeyboardEvent&); 98 98 99 99 // Searches through the given tree scope, starting from start node, for the next/previous selectable element that comes after/before start node. … … 106 106 // 107 107 // See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1 108 Element* findFocusableElementOrScopeOwner(FocusDirection, const FocusNavigationScope&, Node* start, KeyboardEvent *);108 Element* findFocusableElementOrScopeOwner(FocusDirection, const FocusNavigationScope&, Node* start, KeyboardEvent&); 109 109 110 Element* findElementWithExactTabIndex(const FocusNavigationScope&, Node* start, int tabIndex, KeyboardEvent *, FocusDirection);110 Element* findElementWithExactTabIndex(const FocusNavigationScope&, Node* start, int tabIndex, KeyboardEvent&, FocusDirection); 111 111 112 Element* nextFocusableElementOrScopeOwner(const FocusNavigationScope&, Node* start, KeyboardEvent *);113 Element* previousFocusableElementOrScopeOwner(const FocusNavigationScope&, Node* start, KeyboardEvent *);112 Element* nextFocusableElementOrScopeOwner(const FocusNavigationScope&, Node* start, KeyboardEvent&); 113 Element* previousFocusableElementOrScopeOwner(const FocusNavigationScope&, Node* start, KeyboardEvent&); 114 114 115 bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent *);116 void findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent *, FocusCandidate& closest);115 bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent&); 116 void findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent&, FocusCandidate& closest); 117 117 118 118 void focusRepaintTimerFired();
Note: See TracChangeset
for help on using the changeset viewer.