- Revision
- 221099
- Author
- [email protected]
- Date
- 2017-08-23 13:35:49 -0700 (Wed, 23 Aug 2017)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (221098 => 221099)
--- trunk/Source/WebKit/ChangeLog 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Source/WebKit/ChangeLog 2017-08-23 20:35:49 UTC (rev 221099)
@@ -1,3 +1,24 @@
+2017-08-23 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate callbacks corresponding to WKPageUIClient's takeFocus, focus, and unfocus
+ https://bugs.webkit.org/show_bug.cgi?id=175896
+
+ Reviewed by Tim Horton.
+
+ 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):
+
2017-08-23 Youenn Fablet <[email protected]>
[CacheAPI] Introduce a WebKit::CacheStorage namespace
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (221098 => 221099)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-23 20:35:49 UTC (rev 221099)
@@ -45,6 +45,11 @@
@class UITargetedDragPreview;
@protocol UIDragSession;
@protocol UIDropSession;
+#else
+typedef NS_ENUM(NSInteger, _WKFocusDirection) {
+ WKFocusDirectionBackward,
+ WKFocusDirectionForward,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
#endif
@protocol WKUIDelegatePrivate <WKUIDelegate>
@@ -120,7 +125,10 @@
#endif
- (void)_webView:(WKWebView *)webView didChangeSafeAreaShouldAffectObscuredInsets:(BOOL)safeAreaShouldAffectObscuredInsets WK_API_AVAILABLE(ios(WK_IOS_TBA));
#else
-- (void)_webViewShow:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_showWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_focusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_unfocusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (221098 => 221099)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-23 20:35:49 UTC (rev 221099)
@@ -97,6 +97,9 @@
void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void (unsigned long long)>&& completionHandler) override;
#if PLATFORM(MAC)
void showPage(WebPageProxy*) final;
+ void takeFocus(WebKit::WebPageProxy*, WKFocusDirection) final;
+ void focus(WebKit::WebPageProxy*) final;
+ void unfocus(WebKit::WebPageProxy*) final;
bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) override;
#endif
bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) override;
@@ -132,12 +135,15 @@
struct {
bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
- bool webViewShow : 1;
bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
#if PLATFORM(MAC)
+ bool showWebView : 1;
+ bool focusWebView : 1;
+ bool unfocusWebView : 1;
+ bool webViewTakeFocus : 1;
bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
#endif
bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (221098 => 221099)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-23 20:35:49 UTC (rev 221099)
@@ -100,7 +100,10 @@
m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
#if PLATFORM(MAC)
- m_delegateMethods.webViewShow = [delegate respondsToSelector:@selector(_webViewShow:)];
+ m_delegateMethods.showWebView = [delegate respondsToSelector:@selector(_showWebView:)];
+ m_delegateMethods.focusWebView = [delegate respondsToSelector:@selector(_focusWebView:)];
+ m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
+ m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
#endif
@@ -372,9 +375,57 @@
}
#if PLATFORM(MAC)
+static inline _WKFocusDirection toWKFocusDirection(WKFocusDirection direction)
+{
+ switch (direction) {
+ case kWKFocusDirectionBackward:
+ return WKFocusDirectionBackward;
+ case kWKFocusDirectionForward:
+ return WKFocusDirectionForward;
+ }
+ ASSERT_NOT_REACHED();
+ return WKFocusDirectionForward;
+}
+
+void UIDelegate::UIClient::takeFocus(WebKit::WebPageProxy*, WKFocusDirection direction)
+{
+ if (!m_uiDelegate.m_delegateMethods.webViewTakeFocus)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView takeFocus:toWKFocusDirection(direction)];
+}
+
+void UIDelegate::UIClient::focus(WebKit::WebPageProxy*)
+{
+ if (!m_uiDelegate.m_delegateMethods.focusWebView)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+
+ [(id <WKUIDelegatePrivate>)delegate _focusWebView:m_uiDelegate.m_webView];
+}
+
+void UIDelegate::UIClient::unfocus(WebKit::WebPageProxy*)
+{
+ if (!m_uiDelegate.m_delegateMethods.unfocusWebView)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+
+ [(id <WKUIDelegatePrivate>)delegate _unfocusWebView:m_uiDelegate.m_webView];
+}
+
void UIDelegate::UIClient::showPage(WebPageProxy*)
{
- if (!m_uiDelegate.m_delegateMethods.webViewShow)
+ if (!m_uiDelegate.m_delegateMethods.showWebView)
return;
auto delegate = m_uiDelegate.m_delegate.get();
@@ -381,7 +432,7 @@
if (!delegate)
return;
- [(id <WKUIDelegatePrivate>)delegate _webViewShow:m_uiDelegate.m_webView];
+ [(id <WKUIDelegatePrivate>)delegate _showWebView:m_uiDelegate.m_webView];
}
bool UIDelegate::UIClient::runOpenPanel(WebPageProxy*, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, API::OpenPanelParameters* openPanelParameters, WebOpenPanelResultListenerProxy* listener)
Modified: trunk/Tools/ChangeLog (221098 => 221099)
--- trunk/Tools/ChangeLog 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Tools/ChangeLog 2017-08-23 20:35:49 UTC (rev 221099)
@@ -1,3 +1,19 @@
+2017-08-23 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate callbacks corresponding to WKPageUIClient's takeFocus, focus, and unfocus
+ https://bugs.webkit.org/show_bug.cgi?id=175896
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
+ (-[UITestDelegate _showWebView:]):
+ (TEST):
+ (tabEvent):
+ (synthesizeTab):
+ (-[FocusDelegate _webView:takeFocus:]):
+ (-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+ (-[UITestDelegate _webViewShow:]): Deleted.
+
2017-08-23 Eric Carlson <[email protected]>
Platform code should be able to safely log in release builds
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm (221098 => 221099)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-23 20:16:51 UTC (rev 221098)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-23 20:35:49 UTC (rev 221099)
@@ -31,9 +31,11 @@
#import "TestWKWebView.h"
#import "Utilities.h"
+#import <Carbon/Carbon.h>
#import <WebKit/WKUIDelegatePrivate.h>
#import <WebKit/WKWebView.h>
#import <wtf/RetainPtr.h>
+#import <wtf/mac/AppKitCompatibilityDeclarations.h>
@class UITestDelegate;
@@ -54,7 +56,7 @@
return createdWebView.get();
}
-- (void)_webViewShow:(WKWebView *)webView
+- (void)_showWebView:(WKWebView *)webView
{
webViewFromDelegateCallback = webView;
done = true;
@@ -74,7 +76,7 @@
@end
-TEST(WebKit2, ShowPage)
+TEST(WebKit2, ShowWebView)
{
delegate = adoptNS([[UITestDelegate alloc] init]);
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -87,6 +89,53 @@
ASSERT_EQ(webViewFromDelegateCallback, createdWebView);
}
+static NSEvent *tabEvent(NSWindow *window, NSEventType type, NSEventModifierFlags flags)
+{
+ 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];
+}
+
+static void synthesizeTab(NSWindow *window, NSView *view, bool withShiftDown)
+{
+ [view keyDown:tabEvent(window, NSEventTypeKeyDown, withShiftDown ? NSEventModifierFlagShift : 0)];
+ [view keyUp:tabEvent(window, NSEventTypeKeyUp, withShiftDown ? NSEventModifierFlagShift : 0)];
+}
+
+static RetainPtr<NSWindow> window;
+static _WKFocusDirection takenDirection;
+
+@interface FocusDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation FocusDelegate
+
+- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction
+{
+ takenDirection = direction;
+ done = true;
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+ completionHandler();
+ synthesizeTab(window.get(), webView, true);
+}
+
+@end
+
+TEST(WebKit2, Focus)
+{
+ window = adoptNS([[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 800, 600) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]);
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
+ [[window contentView] addSubview:webView.get()];
+ auto delegate = adoptNS([[FocusDelegate alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+ NSString *html = @"<script>function loaded() { document.getElementById('in').focus(); alert('ready'); }</script>"
+ "<body _onload_='loaded()'><input type='text' id='in'></body>";
+ [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com/"]];
+ TestWebKitAPI::Util::run(&done);
+ ASSERT_EQ(takenDirection, WKFocusDirectionBackward);
+}
+
#endif // PLATFORM(MAC)
#endif // WK_API_ENABLED