Skip to content
  • jonlee@apple.com's avatar
    REGRESSION (WK2): (Shift-)option-tabbing skips over elements when... · 54555a11
    jonlee@apple.com authored
    REGRESSION (WK2): (Shift-)option-tabbing skips over elements when transitioning from chrome to webview
    https://bugs.webkit.org/show_bug.cgi?id=68412
    <rdar://problem/9988252>
    
    Reviewed by Darin Adler.
    
    Source/WebKit2:
    
    In WK1 setInitialFocus() is called on FocusController with the key event that
    caused the web view to become first responder. In WK2 no event is sent. So if
    the key stroke that caused the change in first responder status contains the
    option modifier key, FocusController did not know that it had to switch behavior.
    
    Because there are multiple ways that the WKView can becomeFirstResponder, I changed
    the signature to setInitialFocus to express whether the key event parameter is an
    actual key event.
    
    * UIProcess/API/C/win/WKView.cpp:
    (WKViewSetInitialFocus):
    * UIProcess/API/mac/WKView.mm:
    (-[WKView becomeFirstResponder]): Take the NSApp currentEvent and pass it along if
    the event is a keyboard event, otherwise pass an empty event.
    * UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::setInitialFocus): Change in function signature to confirm that
    the event that caused the initial focus was a keyboard event, and provide the keyboard
    event itself.
    * UIProcess/WebPageProxy.h:
    * UIProcess/win/WebView.cpp:
    (WebKit::WebView::setInitialFocus):
    * UIProcess/win/WebView.h:
    * WebProcess/WebPage/WebPage.cpp:
    (WebKit::WebPage::setInitialFocus): If we know that the cause of this was a keyboard
    event, we pass that event to the FocusController. Otherwise we fall back to the original
    behavior, which is to pass no event at all.
    * WebProcess/WebPage/WebPage.h:
    * WebProcess/WebPage/WebPage.messages.in:
    
    Tools:
    
    In order to create a test for the bug, I had to update DRT and WKTR to create some
    widget that allows first responder status to move away from the main web view.
    
    Three methods were added to layoutTestController: addChromeInputField,
    removeChromeInputField, and focusWebView. addChromeInputField adds a text field
    that is a sibling to the web view, and sets up the key event loop between the two.
    removeChromeInputField removes that field. focusWebView moves first responder
    status to the web view.
    
    The test makes the call via layoutTestController and passes a callback that it
    assumes will be executed once the task is completed. In DRT the callback is called
    synchronously. In WKTR this is handled with message passing between the two
    processes.
    
    * DumpRenderTree/LayoutTestController.cpp:
    (addChromeInputFieldCallback):
    (removeChromeInputFieldCallback):
    (focusWebViewCallback):
    (LayoutTestController::staticFunctions):
    * DumpRenderTree/LayoutTestController.h:
    * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
    (LayoutTestController::addChromeInputField):
    (LayoutTestController::removeChromeInputField):
    (LayoutTestController::focusWebView):
    * DumpRenderTree/mac/DumpRenderTree.mm:
    (resetWebViewToConsistentStateBeforeTesting): When resetting for the next test,
    make sure to remove the chrome input field.
    * DumpRenderTree/mac/LayoutTestControllerMac.mm:
    (LayoutTestController::addChromeInputField):
    (LayoutTestController::removeChromeInputField):
    (LayoutTestController::focusWebView):
    * DumpRenderTree/win/LayoutTestControllerWin.cpp:
    (LayoutTestController::addChromeInputField):
    (LayoutTestController::removeChromeInputField):
    (LayoutTestController::focusWebView):
    * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
    * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
    (WTR::InjectedBundle::didReceiveMessage):
    (WTR::InjectedBundle::postAddChromeInputField):
    (WTR::InjectedBundle::postRemoveChromeInputField):
    (WTR::InjectedBundle::postFocusWebView):
    * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
    * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
    (WTR::callbackMap): Create a hash map that keeps track of the callbacks provided
    through JS.
    (WTR::cacheLayoutTestControllerCallback):
    (WTR::callLayoutTestControllerCallback):
    (WTR::LayoutTestController::addChromeInputField):
    (WTR::LayoutTestController::removeChromeInputField):
    (WTR::LayoutTestController::focusWebView):
    (WTR::LayoutTestController::callAddChromeInputFieldCallback):
    (WTR::LayoutTestController::callRemoveChromeInputFieldCallback):
    (WTR::LayoutTestController::callFocusWebViewCallback):
    * WebKitTestRunner/InjectedBundle/LayoutTestController.h:
    * WebKitTestRunner/PlatformWebView.h:
    * WebKitTestRunner/TestController.cpp:
    (WTR::TestController::resetStateToConsistentValues):
    * WebKitTestRunner/TestInvocation.cpp:
    (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
    * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
    (WTR::PlatformWebView::addChromeInputField):
    (WTR::PlatformWebView::removeChromeInputField):
    (WTR::PlatformWebView::makeWebViewFirstResponder):
    * WebKitTestRunner/mac/PlatformWebViewMac.mm:
    (WTR::PlatformWebView::addChromeInputField):
    (WTR::PlatformWebView::removeChromeInputField):
    (WTR::PlatformWebView::makeWebViewFirstResponder):
    * WebKitTestRunner/win/PlatformWebViewWin.cpp:
    (WTR::PlatformWebView::addChromeInputField):
    (WTR::PlatformWebView::removeChromeInputField):
    (WTR::PlatformWebView::makeWebViewFirstResponder):
    
    * DumpRenderTree/mac/LayoutTestControllerMac.mm: These functions have nothing to do
    with the patch-- just cleaning up style.
    (LayoutTestController::addDisallowedURL):
    (originsArrayToJS):
    (LayoutTestController::queueLoad):
    (LayoutTestController::setMockDeviceOrientation):
    (LayoutTestController::setIconDatabaseEnabled):
    (LayoutTestController::setEditingBehavior):
    
    LayoutTests:
    
    The option-key navigation is only relevant to the Mac platform.
    
    * platform/mac/fast/forms/focus-option-control-on-page-expected.txt: Added.
    * platform/mac/fast/forms/focus-option-control-on-page.html: Added.
    * platform/mac/fast/forms/script-tests/focus-option-control-on-page.js: Added.
    (startTest):
    (runKeyPresses):
    (notifyDone):
    (log):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96645 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    54555a11