Changeset 96645 in webkit


Ignore:
Timestamp:
Oct 4, 2011 2:23:29 PM (13 years ago)
Author:
jonlee@apple.com
Message:

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):

Location:
trunk
Files:
4 added
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r96643 r96645  
     12011-10-04  Jon Lee  <jonlee@apple.com>
     2
     3        REGRESSION (WK2): (Shift-)option-tabbing skips over elements when transitioning from chrome to webview
     4        https://bugs.webkit.org/show_bug.cgi?id=68412
     5        <rdar://problem/9988252>
     6
     7        Reviewed by Darin Adler.
     8
     9        The option-key navigation is only relevant to the Mac platform.
     10
     11        * platform/mac/fast/forms/focus-option-control-on-page-expected.txt: Added.
     12        * platform/mac/fast/forms/focus-option-control-on-page.html: Added.
     13        * platform/mac/fast/forms/script-tests/focus-option-control-on-page.js: Added.
     14        (startTest):
     15        (runKeyPresses):
     16        (notifyDone):
     17        (log):
     18
    1192011-10-04  David Hyatt  <hyatt@apple.com>
    220
  • trunk/Source/WebKit2/ChangeLog

    r96619 r96645  
     12011-10-04  Jon Lee  <jonlee@apple.com>
     2
     3        REGRESSION (WK2): (Shift-)option-tabbing skips over elements when transitioning from chrome to webview
     4        https://bugs.webkit.org/show_bug.cgi?id=68412
     5        <rdar://problem/9988252>
     6
     7        Reviewed by Darin Adler.
     8
     9        In WK1 setInitialFocus() is called on FocusController with the key event that
     10        caused the web view to become first responder. In WK2 no event is sent. So if
     11        the key stroke that caused the change in first responder status contains the
     12        option modifier key, FocusController did not know that it had to switch behavior.
     13
     14        Because there are multiple ways that the WKView can becomeFirstResponder, I changed
     15        the signature to setInitialFocus to express whether the key event parameter is an
     16        actual key event.
     17
     18        * UIProcess/API/C/win/WKView.cpp:
     19        (WKViewSetInitialFocus):
     20        * UIProcess/API/mac/WKView.mm:
     21        (-[WKView becomeFirstResponder]): Take the NSApp currentEvent and pass it along if
     22        the event is a keyboard event, otherwise pass an empty event.
     23        * UIProcess/WebPageProxy.cpp:
     24        (WebKit::WebPageProxy::setInitialFocus): Change in function signature to confirm that
     25        the event that caused the initial focus was a keyboard event, and provide the keyboard
     26        event itself.
     27        * UIProcess/WebPageProxy.h:
     28        * UIProcess/win/WebView.cpp:
     29        (WebKit::WebView::setInitialFocus):
     30        * UIProcess/win/WebView.h:
     31        * WebProcess/WebPage/WebPage.cpp:
     32        (WebKit::WebPage::setInitialFocus): If we know that the cause of this was a keyboard
     33        event, we pass that event to the FocusController. Otherwise we fall back to the original
     34        behavior, which is to pass no event at all.
     35        * WebProcess/WebPage/WebPage.h:
     36        * WebProcess/WebPage/WebPage.messages.in:
     37
    1382011-10-04  Jeff Miller  <jeffm@apple.com>
    239
  • trunk/Source/WebKit2/UIProcess/API/C/win/WKView.cpp

    r95901 r96645  
    7070void WKViewSetInitialFocus(WKViewRef viewRef, bool forward)
    7171{
    72     toImpl(viewRef)->setInitialFocus(forward);
     72    bool isKeyboardEventValid = false;
     73    toImpl(viewRef)->setInitialFocus(forward, isKeyboardEventValid, WebKeyboardEvent());
    7374}
    7475
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r95901 r96645  
    312312
    313313    _data->_inBecomeFirstResponder = false;
    314 
    315     if (direction != NSDirectSelection)
    316         _data->_page->setInitialFocus(direction == NSSelectingNext);
    317 
     314   
     315    if (direction != NSDirectSelection) {
     316        NSEvent *event = [NSApp currentEvent];
     317        NSEvent *keyboardEvent = nil;
     318        if ([event type] == NSKeyDown || [event type] == NSKeyUp)
     319            keyboardEvent = event;
     320        _data->_page->setInitialFocus(direction == NSSelectingNext, keyboardEvent != nil, NativeWebKeyboardEvent(keyboardEvent, self));
     321    }
    318322    return YES;
    319323}
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r96613 r96645  
    701701}
    702702
    703 void WebPageProxy::setInitialFocus(bool forward)
    704 {
    705     if (!isValid())
    706         return;
    707     process()->send(Messages::WebPage::SetInitialFocus(forward), m_pageID);
     703void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent)
     704{
     705    if (!isValid())
     706        return;
     707    process()->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent), m_pageID);
    708708}
    709709
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r96413 r96645  
    263263    void viewWillEndLiveResize();
    264264
    265     void setInitialFocus(bool);
     265    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
    266266    void setWindowResizerSize(const WebCore::IntSize&);
    267267   
  • trunk/Source/WebKit2/UIProcess/win/WebView.cpp

    r95901 r96645  
    10691069}
    10701070
    1071 void WebView::setInitialFocus(bool forward)
    1072 {
    1073     m_page->setInitialFocus(forward);
     1071void WebView::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event)
     1072{
     1073    m_page->setInitialFocus(forward, isKeyboardEventValid, event);
    10741074}
    10751075
  • trunk/Source/WebKit2/UIProcess/win/WebView.h

    r95901 r96645  
    8080    void setIsVisible(bool);
    8181    void setOverrideCursor(HCURSOR);
    82     void setInitialFocus(bool forward);
     82    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
    8383    void setScrollOffsetOnNextResize(const WebCore::IntSize&);
    8484    void setFindIndicatorCallback(WKViewFindIndicatorCallback, void*);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r96619 r96645  
    13661366}
    13671367
    1368 void WebPage::setInitialFocus(bool forward)
     1368void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event)
    13691369{
    13701370    if (!m_page || !m_page->focusController())
     
    13731373    Frame* frame = m_page->focusController()->focusedOrMainFrame();
    13741374    frame->document()->setFocusedNode(0);
     1375
     1376    if (isKeyboardEventValid && event.type() == WebEvent::KeyDown) {
     1377        PlatformKeyboardEvent platformEvent(platform(event));
     1378        platformEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown);
     1379        m_page->focusController()->setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, KeyboardEvent::create(platformEvent, frame->document()->defaultView()).get());
     1380        return;
     1381    }
     1382
    13751383    m_page->focusController()->setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, 0);
    13761384}
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r96439 r96645  
    481481    void setActive(bool);
    482482    void setFocused(bool);
    483     void setInitialFocus(bool);
     483    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
    484484    void setWindowResizerSize(const WebCore::IntSize&);
    485485    void setIsInWindow(bool);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r96439 r96645  
    2424    SetActive(bool active)
    2525    SetFocused(bool focused)
    26     SetInitialFocus(bool forward)
     26    SetInitialFocus(bool forward, bool isKeyboardEventValid, WebKit::WebKeyboardEvent event)
    2727    SetIsInWindow(bool isInWindow)
    2828
  • trunk/Tools/ChangeLog

    r96623 r96645  
     12011-10-04  Jon Lee  <jonlee@apple.com>
     2
     3        REGRESSION (WK2): (Shift-)option-tabbing skips over elements when transitioning from chrome to webview
     4        https://bugs.webkit.org/show_bug.cgi?id=68412
     5        <rdar://problem/9988252>
     6
     7        Reviewed by Darin Adler.
     8
     9        In order to create a test for the bug, I had to update DRT and WKTR to create some
     10        widget that allows first responder status to move away from the main web view.
     11
     12        Three methods were added to layoutTestController: addChromeInputField,
     13        removeChromeInputField, and focusWebView. addChromeInputField adds a text field
     14        that is a sibling to the web view, and sets up the key event loop between the two.
     15        removeChromeInputField removes that field. focusWebView moves first responder
     16        status to the web view.
     17
     18        The test makes the call via layoutTestController and passes a callback that it
     19        assumes will be executed once the task is completed. In DRT the callback is called
     20        synchronously. In WKTR this is handled with message passing between the two
     21        processes.
     22
     23        * DumpRenderTree/LayoutTestController.cpp:
     24        (addChromeInputFieldCallback):
     25        (removeChromeInputFieldCallback):
     26        (focusWebViewCallback):
     27        (LayoutTestController::staticFunctions):
     28        * DumpRenderTree/LayoutTestController.h:
     29        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
     30        (LayoutTestController::addChromeInputField):
     31        (LayoutTestController::removeChromeInputField):
     32        (LayoutTestController::focusWebView):
     33        * DumpRenderTree/mac/DumpRenderTree.mm:
     34        (resetWebViewToConsistentStateBeforeTesting): When resetting for the next test,
     35        make sure to remove the chrome input field.
     36        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
     37        (LayoutTestController::addChromeInputField):
     38        (LayoutTestController::removeChromeInputField):
     39        (LayoutTestController::focusWebView):
     40        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
     41        (LayoutTestController::addChromeInputField):
     42        (LayoutTestController::removeChromeInputField):
     43        (LayoutTestController::focusWebView):
     44        * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
     45        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     46        (WTR::InjectedBundle::didReceiveMessage):
     47        (WTR::InjectedBundle::postAddChromeInputField):
     48        (WTR::InjectedBundle::postRemoveChromeInputField):
     49        (WTR::InjectedBundle::postFocusWebView):
     50        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     51        * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
     52        (WTR::callbackMap): Create a hash map that keeps track of the callbacks provided
     53        through JS.
     54        (WTR::cacheLayoutTestControllerCallback):
     55        (WTR::callLayoutTestControllerCallback):
     56        (WTR::LayoutTestController::addChromeInputField):
     57        (WTR::LayoutTestController::removeChromeInputField):
     58        (WTR::LayoutTestController::focusWebView):
     59        (WTR::LayoutTestController::callAddChromeInputFieldCallback):
     60        (WTR::LayoutTestController::callRemoveChromeInputFieldCallback):
     61        (WTR::LayoutTestController::callFocusWebViewCallback):
     62        * WebKitTestRunner/InjectedBundle/LayoutTestController.h:
     63        * WebKitTestRunner/PlatformWebView.h:
     64        * WebKitTestRunner/TestController.cpp:
     65        (WTR::TestController::resetStateToConsistentValues):
     66        * WebKitTestRunner/TestInvocation.cpp:
     67        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
     68        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
     69        (WTR::PlatformWebView::addChromeInputField):
     70        (WTR::PlatformWebView::removeChromeInputField):
     71        (WTR::PlatformWebView::makeWebViewFirstResponder):
     72        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
     73        (WTR::PlatformWebView::addChromeInputField):
     74        (WTR::PlatformWebView::removeChromeInputField):
     75        (WTR::PlatformWebView::makeWebViewFirstResponder):
     76        * WebKitTestRunner/win/PlatformWebViewWin.cpp:
     77        (WTR::PlatformWebView::addChromeInputField):
     78        (WTR::PlatformWebView::removeChromeInputField):
     79        (WTR::PlatformWebView::makeWebViewFirstResponder):
     80
     81        * DumpRenderTree/mac/LayoutTestControllerMac.mm: These functions have nothing to do
     82        with the patch-- just cleaning up style.
     83        (LayoutTestController::addDisallowedURL):
     84        (originsArrayToJS):
     85        (LayoutTestController::queueLoad):
     86        (LayoutTestController::setMockDeviceOrientation):
     87        (LayoutTestController::setIconDatabaseEnabled):
     88        (LayoutTestController::setEditingBehavior):
     89
    1902011-10-04  Simon Fraser  <simon.fraser@apple.com>
    291
  • trunk/Tools/DumpRenderTree/LayoutTestController.cpp

    r94105 r96645  
    21582158        controller->setShouldStayOnPageAfterHandlingBeforeUnload(JSValueToBoolean(context, arguments[0]));
    21592159
     2160    return JSValueMakeUndefined(context);
     2161}
     2162
     2163static JSValueRef addChromeInputFieldCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     2164{
     2165    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
     2166    controller->addChromeInputField();
     2167    // the first argument is a callback that is called once the input field has been added
     2168    if (argumentCount == 1)
     2169        JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
     2170    return JSValueMakeUndefined(context);
     2171}
     2172
     2173static JSValueRef removeChromeInputFieldCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     2174{
     2175    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
     2176    controller->removeChromeInputField();
     2177    // the first argument is a callback that is called once the input field has been added
     2178    if (argumentCount == 1)
     2179        JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
     2180    return JSValueMakeUndefined(context);
     2181}
     2182
     2183static JSValueRef focusWebViewCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     2184{
     2185    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
     2186    controller->focusWebView();
     2187    // the first argument is a callback that is called once the input field has been added
     2188    if (argumentCount == 1)
     2189        JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
    21602190    return JSValueMakeUndefined(context);
    21612191}
     
    24372467        { "allowRoundingHacks", allowRoundingHacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    24382468        { "setShouldStayOnPageAfterHandlingBeforeUnload", setShouldStayOnPageAfterHandlingBeforeUnloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     2469        { "addChromeInputField", addChromeInputFieldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     2470        { "removeChromeInputField", removeChromeInputFieldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     2471        { "focusWebView", focusWebViewCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    24392472        { 0, 0, 0 }
    24402473    };
  • trunk/Tools/DumpRenderTree/LayoutTestController.h

    r94343 r96645  
    315315    void setShouldStayOnPageAfterHandlingBeforeUnload(bool shouldStayOnPageAfterHandlingBeforeUnload) { m_shouldStayOnPageAfterHandlingBeforeUnload = shouldStayOnPageAfterHandlingBeforeUnload; }
    316316
     317    void addChromeInputField();
     318    void removeChromeInputField();
     319    void focusWebView();
     320   
    317321    void setPOSIXLocale(JSStringRef locale);
    318322
  • trunk/Tools/DumpRenderTree/gtk/LayoutTestControllerGtk.cpp

    r94343 r96645  
    988988{
    989989}
     990
     991void LayoutTestController::addChromeInputField()
     992{
     993}
     994
     995void LayoutTestController::removeChromeInputField()
     996{
     997}
     998
     999void LayoutTestController::focusWebView()
     1000{
     1001}
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r96434 r96645  
    11641164    resetDefaultsToConsistentValues();
    11651165
    1166     if (gLayoutTestController)
     1166    if (gLayoutTestController) {
    11671167        WebCoreTestSupport::resetInternalsObject([mainFrame globalContext]);
     1168        // in the case that a test using the chrome input field failed, be sure to clean up for the next test
     1169        gLayoutTestController->removeChromeInputField();
     1170    }
    11681171
    11691172    [[mainFrame webView] setSmartInsertDeleteEnabled:YES];
  • trunk/Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm

    r95588 r96645  
    120120
    121121    // Canonicalize the URL
    122     NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:(NSString *)urlCF.get()]];
     122    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:(NSString *)urlCF.get()]];
    123123    request = [NSURLProtocol canonicalRequestForRequest:request];
    124124
     
    169169}
    170170
    171 JSValueRef originsArrayToJS(JSContextRef context, NSArray* origins)
     171JSValueRef originsArrayToJS(JSContextRef context, NSArray *origins)
    172172{
    173173    NSUInteger count = [origins count];
     
    426426
    427427    NSURL *nsurl = [NSURL URLWithString:urlNS relativeToURL:[[[mainFrame dataSource] response] URL]];
    428     NSString* nsurlString = [nsurl absoluteString];
     428    NSString *nsurlString = [nsurl absoluteString];
    429429
    430430    JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString([nsurlString UTF8String]));
     
    509509    // DumpRenderTree configured the WebView to use WebDeviceOrientationProviderMock.
    510510    id<WebDeviceOrientationProvider> provider = [[mainFrame webView] _deviceOrientationProvider];
    511     WebDeviceOrientationProviderMock* mockProvider = static_cast<WebDeviceOrientationProviderMock*>(provider);
    512     WebDeviceOrientation* orientation = [[WebDeviceOrientation alloc] initWithCanProvideAlpha:canProvideAlpha alpha:alpha canProvideBeta:canProvideBeta beta:beta canProvideGamma:canProvideGamma gamma:gamma];
     511    WebDeviceOrientationProviderMock *mockProvider = static_cast<WebDeviceOrientationProviderMock*>(provider);
     512    WebDeviceOrientation *orientation = [[WebDeviceOrientation alloc] initWithCanProvideAlpha:canProvideAlpha alpha:alpha canProvideBeta:canProvideBeta beta:beta canProvideGamma:canProvideGamma gamma:gamma];
    513513    [mockProvider setOrientation:orientation];
    514514    [orientation release];
     
    551551{
    552552    // FIXME: Workaround <rdar://problem/6480108>
    553     static WebIconDatabase* sharedWebIconDatabase = NULL;
     553    static WebIconDatabase *sharedWebIconDatabase = NULL;
    554554    if (!sharedWebIconDatabase) {
    555555        if (!iconDatabaseEnabled)
     
    11521152void LayoutTestController::setEditingBehavior(const char* editingBehavior)
    11531153{
    1154     NSString* editingBehaviorNS = [[NSString alloc] initWithUTF8String:editingBehavior];
     1154    NSString *editingBehaviorNS = [[NSString alloc] initWithUTF8String:editingBehavior];
    11551155    if ([editingBehaviorNS isEqualToString:@"mac"])
    11561156        [[WebPreferences standardPreferences] setEditingBehavior:WebKitEditingMacBehavior];
     
    12031203#endif
    12041204}
     1205
     1206void LayoutTestController::addChromeInputField()
     1207{
     1208    NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)];
     1209    textField.tag = 1;
     1210    [[[[mainFrame webView] window] contentView] addSubview:textField];
     1211    [textField release];
     1212   
     1213    [textField setNextKeyView:[mainFrame webView]];
     1214    [[mainFrame webView] setNextKeyView:textField];
     1215}
     1216
     1217void LayoutTestController::removeChromeInputField()
     1218{
     1219    NSView* textField = [[[[mainFrame webView] window] contentView] viewWithTag:1];
     1220    if (textField) {
     1221        [textField removeFromSuperview];
     1222        focusWebView();
     1223    }
     1224}
     1225
     1226void LayoutTestController::focusWebView()
     1227{
     1228    [[[mainFrame webView] window] makeFirstResponder:[mainFrame webView]];
     1229}
  • trunk/Tools/DumpRenderTree/win/LayoutTestControllerWin.cpp

    r94343 r96645  
    15411541{
    15421542}
     1543
     1544void LayoutTestController::addChromeInputField()
     1545{
     1546}
     1547
     1548void LayoutTestController::removeChromeInputField()
     1549{
     1550}
     1551
     1552void LayoutTestController::focusWebView()
     1553{
     1554}
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl

    r96405 r96645  
    122122       
    123123        void setShouldStayOnPageAfterHandlingBeforeUnload(in boolean flag);
     124       
     125        // Focus testing.
     126        void addChromeInputField(in object callback);
     127        void removeChromeInputField(in object callback);
     128        void focusWebView(in object callback);
    124129    };
    125130
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r96405 r96645  
    159159        return;
    160160    }
     161    if (WKStringIsEqualToUTF8CString(messageName, "CallAddChromeInputFieldCallback")) {
     162        m_layoutTestController->callAddChromeInputFieldCallback();
     163        return;
     164    }
     165    if (WKStringIsEqualToUTF8CString(messageName, "CallRemoveChromeInputFieldCallback")) {
     166        m_layoutTestController->callRemoveChromeInputFieldCallback();
     167        return;
     168    }
     169    if (WKStringIsEqualToUTF8CString(messageName, "CallFocusWebViewCallback")) {
     170        m_layoutTestController->callFocusWebViewCallback();
     171        return;
     172    }
    161173
    162174    WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error"));
     
    247259}
    248260
     261void InjectedBundle::postAddChromeInputField()
     262{
     263    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("AddChromeInputField"));
     264    WKBundlePostMessage(m_bundle, messageName.get(), 0);
     265}
     266
     267void InjectedBundle::postRemoveChromeInputField()
     268{
     269    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("RemoveChromeInputField"));
     270    WKBundlePostMessage(m_bundle, messageName.get(), 0);
     271}
     272
     273void InjectedBundle::postFocusWebView()
     274{
     275    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("FocusWebView"));
     276    WKBundlePostMessage(m_bundle, messageName.get(), 0);
     277}
     278
    249279} // namespace WTR
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r96005 r96645  
    7575   
    7676    void postNewBeforeUnloadReturnValue(bool);
     77    void postAddChromeInputField();
     78    void postRemoveChromeInputField();
     79    void postFocusWebView();
    7780
    7881private:
  • trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp

    r96405 r96645  
    514514}
    515515
     516typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;
     517static CallbackMap& callbackMap()
     518{
     519    static CallbackMap& map = *new CallbackMap;
     520    return map;
     521}
     522
     523static void cacheLayoutTestControllerCallback(unsigned index, JSValueRef callback)
     524{
     525    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
     526    JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
     527    JSValueProtect(context, callback);
     528    callbackMap().add(index, callback);
     529}
     530
     531static void callLayoutTestControllerCallback(unsigned index)
     532{
     533    if (!callbackMap().contains(index))
     534        return;
     535    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
     536    JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
     537    JSObjectRef callback = JSValueToObject(context, callbackMap().take(index), 0);
     538    JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), 0, 0, 0);
     539    JSValueUnprotect(context, callback);
     540}
     541
     542void LayoutTestController::addChromeInputField(JSValueRef callback)
     543{
     544    cacheLayoutTestControllerCallback(1, callback);
     545    InjectedBundle::shared().postAddChromeInputField();
     546}
     547
     548void LayoutTestController::removeChromeInputField(JSValueRef callback)
     549{
     550    cacheLayoutTestControllerCallback(2, callback);
     551    InjectedBundle::shared().postRemoveChromeInputField();
     552}
     553
     554void LayoutTestController::focusWebView(JSValueRef callback)
     555{
     556    cacheLayoutTestControllerCallback(3, callback);
     557    InjectedBundle::shared().postFocusWebView();
     558}
     559
     560void LayoutTestController::callAddChromeInputFieldCallback()
     561{
     562    callLayoutTestControllerCallback(1);
     563}
     564
     565void LayoutTestController::callRemoveChromeInputFieldCallback()
     566{
     567    callLayoutTestControllerCallback(2);
     568}
     569
     570void LayoutTestController::callFocusWebViewCallback()
     571{
     572    callLayoutTestControllerCallback(3);
     573}
     574
    516575} // namespace WTR
  • trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h

    r96405 r96645  
    177177    bool globalFlag() const { return m_globalFlag; }
    178178    void setGlobalFlag(bool value) { m_globalFlag = value; }
     179   
     180    void addChromeInputField(JSValueRef);
     181    void removeChromeInputField(JSValueRef);
     182    void focusWebView(JSValueRef);
     183    void callAddChromeInputFieldCallback();
     184    void callRemoveChromeInputFieldCallback();
     185    void callFocusWebViewCallback();
    179186
    180187private:
  • trunk/Tools/WebKitTestRunner/PlatformWebView.h

    r96416 r96645  
    7171    WKRect windowFrame();
    7272    void setWindowFrame(WKRect);
     73   
     74    void addChromeInputField();
     75    void removeChromeInputField();
     76    void makeWebViewFirstResponder();
    7377
    7478private:
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r96439 r96645  
    427427#endif
    428428
     429    // in the case that a test using the chrome input field failed, be sure to clean up for the next test
     430    m_mainWebView->removeChromeInputField();
    429431    m_mainWebView->focus();
    430432
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r96005 r96645  
    249249        return;
    250250    }
     251   
     252    if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) {
     253        TestController::shared().mainWebView()->addChromeInputField();
     254        WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback"));
     255        WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
     256        return;
     257    }
     258
     259    if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) {
     260        TestController::shared().mainWebView()->removeChromeInputField();
     261        WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback"));
     262        WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
     263        return;
     264    }
     265   
     266    if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) {
     267        TestController::shared().mainWebView()->makeWebViewFirstResponder();
     268        WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback"));
     269        WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
     270        return;
     271    }
    251272
    252273    ASSERT_NOT_REACHED();
  • trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp

    r87760 r96645  
    9898}
    9999
     100void PlatformWebView::addChromeInputField()
     101{
     102}
     103
     104void PlatformWebView::removeChromeInputField()
     105{
     106}
     107
     108void PlatformWebView::makeWebViewFirstResponder()
     109{
     110}
     111
    100112} // namespace WTR
    101113
  • trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm

    r85083 r96645  
    8181}
    8282
     83void PlatformWebView::addChromeInputField()
     84{
     85    NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)];
     86    textField.tag = 1;
     87    [[m_window contentView] addSubview:textField];
     88    [textField release];
     89
     90    [textField setNextKeyView:m_view];
     91    [m_view setNextKeyView:textField];
     92}
     93
     94void PlatformWebView::removeChromeInputField()
     95{
     96    NSView* textField = [[m_window contentView] viewWithTag:1];
     97    if (textField) {
     98        [textField removeFromSuperview];
     99        makeWebViewFirstResponder();
     100    }
     101}
     102
     103void PlatformWebView::makeWebViewFirstResponder()
     104{
     105    [m_window makeFirstResponder:m_view];
     106}
     107
    83108} // namespace WTR
  • trunk/Tools/WebKitTestRunner/win/PlatformWebViewWin.cpp

    r81135 r96645  
    9898}
    9999
     100
     101void PlatformWebView::addChromeInputField()
     102{
     103}
     104
     105void PlatformWebView::removeChromeInputField()
     106{
     107}
     108
     109void PlatformWebView::makeWebViewFirstResponder()
     110{
     111}
     112
    100113} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.