Changeset 205290 in webkit


Ignore:
Timestamp:
Sep 1, 2016 7:22:33 AM (8 years ago)
Author:
akling@apple.com
Message:

FocusController should pass KeyboardEvent around by reference.
<https://webkit.org/b/161461>

Reviewed by Sam Weinig.

Clean up FocusController to pass KeyboardEvent& around internally.

Also make FocusController::setInitialFocus() synthesize a dummy KeyboardEvent
if one isn't provided, just like nextFocusableElement()/previousFocusableElement() does.
This way we can feel confident about dereferencing the formerly KeyboardEvent* everywhere.

  • page/EventHandler.cpp:

(WebCore::EventHandler::defaultArrowEventHandler):
(WebCore::EventHandler::defaultTabEventHandler):

  • page/FocusController.cpp:

(WebCore::isFocusableElementOrScopeOwner):
(WebCore::isNonFocusableScopeOwner):
(WebCore::isFocusableScopeOwner):
(WebCore::shadowAdjustedTabIndex):
(WebCore::FocusController::findFocusableElementDescendingDownIntoFrameDocument):
(WebCore::FocusController::setInitialFocus):
(WebCore::FocusController::advanceFocus):
(WebCore::FocusController::advanceFocusInDocumentOrder):
(WebCore::FocusController::findFocusableElementAcrossFocusScope):
(WebCore::FocusController::findFocusableElementWithinScope):
(WebCore::FocusController::nextFocusableElementWithinScope):
(WebCore::FocusController::previousFocusableElementWithinScope):
(WebCore::FocusController::findFocusableElementOrScopeOwner):
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::previousElementWithLowerTabIndex):
(WebCore::FocusController::nextFocusableElement):
(WebCore::FocusController::previousFocusableElement):
(WebCore::FocusController::nextFocusableElementOrScopeOwner):
(WebCore::FocusController::previousFocusableElementOrScopeOwner):
(WebCore::FocusController::findFocusCandidateInContainer):
(WebCore::FocusController::advanceFocusDirectionallyInContainer):
(WebCore::FocusController::advanceFocusDirectionally):

  • page/FocusController.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205289 r205290  
     12016-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
    1432016-09-01  Romain Bellessort  <romain.bellessort@crf.canon.fr>
    244
  • trunk/Source/WebCore/page/EventHandler.cpp

    r205249 r205290  
    36673667        return;
    36683668
    3669     if (page->focusController().advanceFocus(focusDirection, &event))
     3669    if (page->focusController().advanceFocus(focusDirection, event))
    36703670        event.setDefaultHandled();
    36713671}
     
    36913691        return;
    36923692
    3693     if (page->focusController().advanceFocus(focusDirection, &event))
     3693    if (page->focusController().advanceFocus(focusDirection, event))
    36943694        event.setDefaultHandled();
    36953695}
  • trunk/Source/WebCore/page/FocusController.cpp

    r205249 r205290  
    290290}
    291291
    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)
     292static inline bool isFocusableElementOrScopeOwner(Element& element, KeyboardEvent& event)
     293{
     294    return element.isKeyboardFocusable(event) || isFocusScopeOwner(element);
     295}
     296
     297static inline bool isNonFocusableScopeOwner(Element& element, KeyboardEvent& event)
     298{
     299    return !element.isKeyboardFocusable(event) && isFocusScopeOwner(element);
     300}
     301
     302static inline bool isFocusableScopeOwner(Element& element, KeyboardEvent& event)
     303{
     304    return element.isKeyboardFocusable(event) && isFocusScopeOwner(element);
     305}
     306
     307static inline int shadowAdjustedTabIndex(Element& element, KeyboardEvent& event)
    308308{
    309309    if (isNonFocusableScopeOwner(element, event)) {
     
    377377}
    378378
    379 Element* FocusController::findFocusableElementDescendingDownIntoFrameDocument(FocusDirection direction, Element* element, KeyboardEvent* event)
     379Element* FocusController::findFocusableElementDescendingDownIntoFrameDocument(FocusDirection direction, Element* element, KeyboardEvent& event)
    380380{
    381381    // The node we found might be a HTMLFrameOwnerElement, so descend down the tree until we find either:
     
    395395}
    396396
    397 bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* event)
    398 {
    399     bool didAdvanceFocus = advanceFocus(direction, event, true);
     397bool 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);
    400404   
    401405    // If focus is being set initially, accessibility needs to be informed that system focus has moved
     
    408412}
    409413
    410 bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
     414bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent& event, bool initialFocus)
    411415{
    412416    switch (direction) {
     
    426430}
    427431
    428 bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
     432bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, KeyboardEvent& event, bool initialFocus)
    429433{
    430434    Frame& frame = focusedOrMainFrame();
     
    465469    }
    466470
    467     if (is<HTMLFrameOwnerElement>(*element) && (!is<HTMLPlugInElement>(*element) || !element->isKeyboardFocusable(*event))) {
     471    if (is<HTMLFrameOwnerElement>(*element) && (!is<HTMLPlugInElement>(*element) || !element->isKeyboardFocusable(event))) {
    468472        // We focus frames rather than frame owners.
    469473        // FIXME: We should not focus frames that have no scrollbars, as focusing them isn't useful to the user.
     
    503507}
    504508
    505 Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent* event)
     509Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, const FocusNavigationScope& scope, Node* currentNode, KeyboardEvent& event)
    506510{
    507511    ASSERT(!is<Element>(currentNode) || !isNonFocusableScopeOwner(downcast<Element>(*currentNode), event));
     
    529533}
    530534
    531 Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
     535Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent& event)
    532536{
    533537    // Starting node is exclusive.
     
    538542}
    539543
    540 Element* FocusController::nextFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
     544Element* FocusController::nextFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event)
    541545{
    542546    Element* found = nextFocusableElementOrScopeOwner(scope, start, event);
     
    551555}
    552556
    553 Element* FocusController::previousFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
     557Element* FocusController::previousFocusableElementWithinScope(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event)
    554558{
    555559    Element* found = previousFocusableElementOrScopeOwner(scope, start, event);
     
    570574}
    571575
    572 Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent* event)
     576Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent& event)
    573577{
    574578    return (direction == FocusDirectionForward)
     
    577581}
    578582
    579 Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
     583Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent& event, FocusDirection direction)
    580584{
    581585    // Search is inclusive of start
     
    590594}
    591595
    592 static Element* nextElementWithGreaterTabIndex(const FocusNavigationScope& scope, int tabIndex, KeyboardEvent* event)
     596static Element* nextElementWithGreaterTabIndex(const FocusNavigationScope& scope, int tabIndex, KeyboardEvent& event)
    593597{
    594598    // Search is inclusive of start
     
    609613}
    610614
    611 static Element* previousElementWithLowerTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent* event)
     615static Element* previousElementWithLowerTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent& event)
    612616{
    613617    // Search is inclusive of start
     
    631635    // FIXME: This can return a non-focusable shadow host.
    632636    Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy();
    633     return nextFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr());
     637    return nextFocusableElementOrScopeOwner(FocusNavigationScope::scopeOf(start), &start, keyEvent.get());
    634638}
    635639
     
    638642    // FIXME: This can return a non-focusable shadow host.
    639643    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
     647Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event)
    644648{
    645649    int startTabIndex = 0;
     
    678682}
    679683
    680 Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
     684Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent& event)
    681685{
    682686    Node* last = nullptr;
     
    938942}
    939943
    940 void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent* event, FocusCandidate& closest)
     944void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent& event, FocusCandidate& closest)
    941945{
    942946    Node* focusedNode = (focusedFrame() && focusedFrame()->document()) ? focusedFrame()->document()->focusedElement() : 0;
     
    955959            continue;
    956960
    957         if (!element->isKeyboardFocusable(*event) && !element->isFrameOwnerElement() && !canScrollInDirection(element, direction))
     961        if (!element->isKeyboardFocusable(event) && !element->isFrameOwnerElement() && !canScrollInDirection(element, direction))
    958962            continue;
    959963
     
    978982}
    979983
    980 bool FocusController::advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent* event)
     984bool FocusController::advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection direction, KeyboardEvent& event)
    981985{
    982986    if (!container)
     
    10481052}
    10491053
    1050 bool FocusController::advanceFocusDirectionally(FocusDirection direction, KeyboardEvent* event)
     1054bool FocusController::advanceFocusDirectionally(FocusDirection direction, KeyboardEvent& event)
    10511055{
    10521056    Document* focusedDocument = focusedOrMainFrame().document();
  • trunk/Source/WebCore/page/FocusController.h

    r200576 r205290  
    6060
    6161    WEBCORE_EXPORT bool setInitialFocus(FocusDirection, KeyboardEvent*);
    62     bool advanceFocus(FocusDirection, KeyboardEvent*, bool initialFocus = false);
     62    bool advanceFocus(FocusDirection, KeyboardEvent&, bool initialFocus = false);
    6363
    6464    WEBCORE_EXPORT bool setFocusedElement(Element*, PassRefPtr<Frame>, FocusDirection = FocusDirectionNone);
     
    8686    void setIsVisibleAndActiveInternal(bool);
    8787
    88     bool advanceFocusDirectionally(FocusDirection, KeyboardEvent*);
    89     bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent*, bool initialFocus);
     88    bool advanceFocusDirectionally(FocusDirection, KeyboardEvent&);
     89    bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent&, bool initialFocus);
    9090
    91     Element* findFocusableElementAcrossFocusScope(FocusDirection, const FocusNavigationScope& startScope, Node* start, KeyboardEvent*);
     91    Element* findFocusableElementAcrossFocusScope(FocusDirection, const FocusNavigationScope& startScope, Node* start, KeyboardEvent&);
    9292
    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&);
    9696
    97     Element* findFocusableElementDescendingDownIntoFrameDocument(FocusDirection, Element*, KeyboardEvent*);
     97    Element* findFocusableElementDescendingDownIntoFrameDocument(FocusDirection, Element*, KeyboardEvent&);
    9898
    9999    // Searches through the given tree scope, starting from start node, for the next/previous selectable element that comes after/before start node.
     
    106106    //
    107107    // 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&);
    109109
    110     Element* findElementWithExactTabIndex(const FocusNavigationScope&, Node* start, int tabIndex, KeyboardEvent*, FocusDirection);
     110    Element* findElementWithExactTabIndex(const FocusNavigationScope&, Node* start, int tabIndex, KeyboardEvent&, FocusDirection);
    111111   
    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&);
    114114
    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);
    117117
    118118    void focusRepaintTimerFired();
Note: See TracChangeset for help on using the changeset viewer.