Changeset 221099 in webkit


Ignore:
Timestamp:
Aug 23, 2017 1:35:49 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Add WKUIDelegatePrivate callbacks corresponding to WKPageUIClient's takeFocus, focus, and unfocus
https://bugs.webkit.org/show_bug.cgi?id=175896

Reviewed by Tim Horton.
Source/WebKit:


I also renamed _webViewShow to _showWebView based on feedback from https://bugs.webkit.org/show_bug.cgi?id=175797

Added an API test.

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::toWKFocusDirection):
(WebKit::UIDelegate::UIClient::takeFocus):
(WebKit::UIDelegate::UIClient::focus):
(WebKit::UIDelegate::UIClient::unfocus):
(WebKit::UIDelegate::UIClient::showPage):

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:

(-[UITestDelegate _showWebView:]):
(TEST):
(tabEvent):
(synthesizeTab):
(-[FocusDelegate _webView:takeFocus:]):
(-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(-[UITestDelegate _webViewShow:]): Deleted.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221093 r221099  
     12017-08-23  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate callbacks corresponding to WKPageUIClient's takeFocus, focus, and unfocus
     4        https://bugs.webkit.org/show_bug.cgi?id=175896
     5
     6        Reviewed by Tim Horton.
     7       
     8        I also renamed _webViewShow to _showWebView based on feedback from https://bugs.webkit.org/show_bug.cgi?id=175797
     9
     10        Added an API test.
     11
     12        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     13        * UIProcess/Cocoa/UIDelegate.h:
     14        * UIProcess/Cocoa/UIDelegate.mm:
     15        (WebKit::UIDelegate::setDelegate):
     16        (WebKit::toWKFocusDirection):
     17        (WebKit::UIDelegate::UIClient::takeFocus):
     18        (WebKit::UIDelegate::UIClient::focus):
     19        (WebKit::UIDelegate::UIClient::unfocus):
     20        (WebKit::UIDelegate::UIClient::showPage):
     21
    1222017-08-23  Youenn Fablet  <youenn@apple.com>
    223
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r221065 r221099  
    4646@protocol UIDragSession;
    4747@protocol UIDropSession;
     48#else
     49typedef NS_ENUM(NSInteger, _WKFocusDirection) {
     50    WKFocusDirectionBackward,
     51    WKFocusDirectionForward,
     52} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    4853#endif
    4954
     
    121126- (void)_webView:(WKWebView *)webView didChangeSafeAreaShouldAffectObscuredInsets:(BOOL)safeAreaShouldAffectObscuredInsets WK_API_AVAILABLE(ios(WK_IOS_TBA));
    122127#else
    123 - (void)_webViewShow:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     128- (void)_showWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     129- (void)_focusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     130- (void)_unfocusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     131- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    124132- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
    125133- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r221055 r221099  
    9898#if PLATFORM(MAC)
    9999        void showPage(WebPageProxy*) final;
     100        void takeFocus(WebKit::WebPageProxy*, WKFocusDirection) final;
     101        void focus(WebKit::WebPageProxy*) final;
     102        void unfocus(WebKit::WebPageProxy*) final;
    100103        bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) override;
    101104#endif
     
    133136        bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
    134137        bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
    135         bool webViewShow : 1;
    136138        bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
    137139        bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
     
    139141        bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
    140142#if PLATFORM(MAC)
     143        bool showWebView : 1;
     144        bool focusWebView : 1;
     145        bool unfocusWebView : 1;
     146        bool webViewTakeFocus : 1;
    141147        bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
    142148#endif
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r221055 r221099  
    101101
    102102#if PLATFORM(MAC)
    103     m_delegateMethods.webViewShow = [delegate respondsToSelector:@selector(_webViewShow:)];
     103    m_delegateMethods.showWebView = [delegate respondsToSelector:@selector(_showWebView:)];
     104    m_delegateMethods.focusWebView = [delegate respondsToSelector:@selector(_focusWebView:)];
     105    m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
     106    m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
    104107    m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
    105108#endif
     
    373376
    374377#if PLATFORM(MAC)
     378static inline _WKFocusDirection toWKFocusDirection(WKFocusDirection direction)
     379{
     380    switch (direction) {
     381    case kWKFocusDirectionBackward:
     382        return WKFocusDirectionBackward;
     383    case kWKFocusDirectionForward:
     384        return WKFocusDirectionForward;
     385    }
     386    ASSERT_NOT_REACHED();
     387    return WKFocusDirectionForward;
     388}
     389
     390void UIDelegate::UIClient::takeFocus(WebKit::WebPageProxy*, WKFocusDirection direction)
     391{
     392    if (!m_uiDelegate.m_delegateMethods.webViewTakeFocus)
     393        return;
     394   
     395    auto delegate = m_uiDelegate.m_delegate.get();
     396    if (!delegate)
     397        return;
     398   
     399    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView takeFocus:toWKFocusDirection(direction)];
     400}
     401
     402void UIDelegate::UIClient::focus(WebKit::WebPageProxy*)
     403{
     404    if (!m_uiDelegate.m_delegateMethods.focusWebView)
     405        return;
     406   
     407    auto delegate = m_uiDelegate.m_delegate.get();
     408    if (!delegate)
     409        return;
     410   
     411    [(id <WKUIDelegatePrivate>)delegate _focusWebView:m_uiDelegate.m_webView];
     412}
     413
     414void UIDelegate::UIClient::unfocus(WebKit::WebPageProxy*)
     415{
     416    if (!m_uiDelegate.m_delegateMethods.unfocusWebView)
     417        return;
     418   
     419    auto delegate = m_uiDelegate.m_delegate.get();
     420    if (!delegate)
     421        return;
     422   
     423    [(id <WKUIDelegatePrivate>)delegate _unfocusWebView:m_uiDelegate.m_webView];
     424}
     425
    375426void UIDelegate::UIClient::showPage(WebPageProxy*)
    376427{
    377     if (!m_uiDelegate.m_delegateMethods.webViewShow)
    378         return;
    379 
    380     auto delegate = m_uiDelegate.m_delegate.get();
    381     if (!delegate)
    382         return;
    383    
    384     [(id <WKUIDelegatePrivate>)delegate _webViewShow:m_uiDelegate.m_webView];
     428    if (!m_uiDelegate.m_delegateMethods.showWebView)
     429        return;
     430
     431    auto delegate = m_uiDelegate.m_delegate.get();
     432    if (!delegate)
     433        return;
     434   
     435    [(id <WKUIDelegatePrivate>)delegate _showWebView:m_uiDelegate.m_webView];
    385436}
    386437
  • trunk/Tools/ChangeLog

    r221095 r221099  
     12017-08-23  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate callbacks corresponding to WKPageUIClient's takeFocus, focus, and unfocus
     4        https://bugs.webkit.org/show_bug.cgi?id=175896
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
     9        (-[UITestDelegate _showWebView:]):
     10        (TEST):
     11        (tabEvent):
     12        (synthesizeTab):
     13        (-[FocusDelegate _webView:takeFocus:]):
     14        (-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     15        (-[UITestDelegate _webViewShow:]): Deleted.
     16
    1172017-08-23  Eric Carlson  <eric.carlson@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm

    r221055 r221099  
    3232#import "TestWKWebView.h"
    3333#import "Utilities.h"
     34#import <Carbon/Carbon.h>
    3435#import <WebKit/WKUIDelegatePrivate.h>
    3536#import <WebKit/WKWebView.h>
    3637#import <wtf/RetainPtr.h>
     38#import <wtf/mac/AppKitCompatibilityDeclarations.h>
    3739
    3840@class UITestDelegate;
     
    5557}
    5658
    57 - (void)_webViewShow:(WKWebView *)webView
     59- (void)_showWebView:(WKWebView *)webView
    5860{
    5961    webViewFromDelegateCallback = webView;
     
    7577@end
    7678
    77 TEST(WebKit2, ShowPage)
     79TEST(WebKit2, ShowWebView)
    7880{
    7981    delegate = adoptNS([[UITestDelegate alloc] init]);
     
    8890}
    8991
     92static NSEvent *tabEvent(NSWindow *window, NSEventType type, NSEventModifierFlags flags)
     93{
     94    return [NSEvent keyEventWithType:type location:NSMakePoint(5, 5) modifierFlags:flags timestamp:GetCurrentEventTime() windowNumber:[window windowNumber] context:[NSGraphicsContext currentContext] characters:@"\t" charactersIgnoringModifiers:@"\t" isARepeat:NO keyCode:0];
     95}
     96
     97static void synthesizeTab(NSWindow *window, NSView *view, bool withShiftDown)
     98{
     99    [view keyDown:tabEvent(window, NSEventTypeKeyDown, withShiftDown ? NSEventModifierFlagShift : 0)];
     100    [view keyUp:tabEvent(window, NSEventTypeKeyUp, withShiftDown ? NSEventModifierFlagShift : 0)];
     101}
     102
     103static RetainPtr<NSWindow> window;
     104static _WKFocusDirection takenDirection;
     105
     106@interface FocusDelegate : NSObject <WKUIDelegatePrivate>
     107@end
     108
     109@implementation FocusDelegate
     110
     111- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction
     112{
     113    takenDirection = direction;
     114    done = true;
     115}
     116
     117- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
     118{
     119    completionHandler();
     120    synthesizeTab(window.get(), webView, true);
     121}
     122
     123@end
     124
     125TEST(WebKit2, Focus)
     126{
     127    window = adoptNS([[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 800, 600) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]);
     128    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
     129    [[window contentView] addSubview:webView.get()];
     130    auto delegate = adoptNS([[FocusDelegate alloc] init]);
     131    [webView setUIDelegate:delegate.get()];
     132    NSString *html = @"<script>function loaded() { document.getElementById('in').focus(); alert('ready'); }</script>"
     133    "<body onload='loaded()'><input type='text' id='in'></body>";
     134    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com/"]];
     135    TestWebKitAPI::Util::run(&done);
     136    ASSERT_EQ(takenDirection, WKFocusDirectionBackward);
     137}
     138
    90139#endif // PLATFORM(MAC)
    91140
Note: See TracChangeset for help on using the changeset viewer.