Title: [219034] trunk
Revision
219034
Author
[email protected]
Date
2017-06-30 19:25:59 -0700 (Fri, 30 Jun 2017)

Log Message

Add API to get WKActivatedElementInfo
https://bugs.webkit.org/show_bug.cgi?id=174001
<rdar://problem/29165518>
        
Source/WebKit2:

Adding a way to get a WKActivatedElementInfo for a point on a WKWebView.

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView requestActivatedElementAtPosition:completionBlock:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
(+[_WKActivatedElementInfo infoWithType:withInteractionInformationAtPosition:]):
(-[_WKActivatedElementInfo infoWithType:withInteractionInformationAtPosition:]):
* UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:

Tools:

Tests for now SPI to get activatedElementInfo.

Reviewed by Tim Horton.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/WKRequestActivatedElementInfo.mm: Added.
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (219033 => 219034)


--- trunk/Source/WebKit2/ChangeLog	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-01 02:25:59 UTC (rev 219034)
@@ -1,3 +1,21 @@
+2017-06-30  Megan Gardner  <[email protected]>
+
+        Add API to get WKActivatedElementInfo
+        https://bugs.webkit.org/show_bug.cgi?id=174001
+        <rdar://problem/29165518>
+        
+        Adding a way to get a WKActivatedElementInfo for a point on a WKWebView.
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView requestActivatedElementAtPosition:completionBlock:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
+        (+[_WKActivatedElementInfo infoWithType:withInteractionInformationAtPosition:]):
+        (-[_WKActivatedElementInfo infoWithType:withInteractionInformationAtPosition:]):
+        * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
+
 2017-06-30  Tim Horton  <[email protected]>
 
         Use API instead of SPI for content inset adjustment behavior

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (219033 => 219034)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-07-01 02:25:59 UTC (rev 219034)
@@ -81,6 +81,7 @@
 #import "WebProcessProxy.h"
 #import "WebURLSchemeHandlerCocoa.h"
 #import "WebViewImpl.h"
+#import "_WKActivatedElementInfoInternal.h"
 #import "_WKDiagnosticLoggingDelegate.h"
 #import "_WKFindDelegate.h"
 #import "_WKFrameHandleInternal.h"
@@ -5254,6 +5255,16 @@
     } forRequest:WebKit::InteractionInformationRequest(WebCore::roundedIntPoint(position))];
 }
 
+- (void)_requestActivatedElementAtPosition:(CGPoint)position completionBlock:(void (^)(_WKActivatedElementInfo *))block
+{
+    auto infoRequest = WebKit::InteractionInformationRequest(WebCore::roundedIntPoint(position));
+    infoRequest.includeSnapshot = true;
+    
+    [_contentView doAfterPositionInformationUpdate:[capturedBlock = makeBlockPtr(block)] (WebKit::InteractionInformationAtPosition information) {
+        capturedBlock([_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:information]);
+    } forRequest:infoRequest];
+}
+
 - (CGRect)_contentVisibleRect
 {
     return [self convertRect:[self bounds] toView:self._currentContentView];

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (219033 => 219034)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-07-01 02:25:59 UTC (rev 219034)
@@ -27,6 +27,7 @@
 
 #if WK_API_ENABLED
 
+#import <WebKit/_WKActivatedElementInfo.h>
 #import <WebKit/_WKFindOptions.h>
 #import <WebKit/_WKLayoutMode.h>
 #import <WebKit/_WKRenderingProgressEvents.h>
@@ -363,6 +364,8 @@
 - (_WKDraggableElementInfo *)_draggableElementAtPosition:(CGPoint)position WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_requestDraggableElementAtPosition:(CGPoint)position completionBlock:(void (^)(_WKDraggableElementInfo *))block WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+- (void)_requestActivatedElementAtPosition:(CGPoint)position completionBlock:(void (^)(_WKActivatedElementInfo *))block WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 #endif // TARGET_OS_IPHONE
 
 #if !TARGET_OS_IPHONE

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h (219033 => 219034)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h	2017-07-01 02:25:59 UTC (rev 219034)
@@ -37,6 +37,7 @@
     _WKActivatedElementTypeLink,
     _WKActivatedElementTypeImage,
     _WKActivatedElementTypeAttachment WK_API_AVAILABLE(macosx(10.12), ios(10.0)),
+    _WKActivatedElementTypeUnspecified WK_API_AVAILABLE(macosx(10.13), ios(11.0)),
 } WK_API_AVAILABLE(macosx(10.10), ios(8.0));
 
 WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm (219033 => 219034)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm	2017-07-01 02:25:59 UTC (rev 219034)
@@ -54,6 +54,36 @@
 #endif
 }
 
++ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information
+{
+    return [[[self alloc] _initWithInteractionInformationAtPosition:information] autorelease];
+}
+
+- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information
+{
+    if (!(self = [super init]))
+        return nil;
+    
+    _URL = information.url;
+    _interactionLocation = information.request.point;
+    _title = information.title;
+    _boundingRect = information.bounds;
+    
+    if (information.isAttachment)
+        _type = _WKActivatedElementTypeAttachment;
+    else if (information.isImage)
+        _type = _WKActivatedElementTypeImage;
+    else if (information.isLink)
+        _type = _WKActivatedElementTypeLink;
+    else
+        _type = _WKActivatedElementTypeUnspecified;
+    
+    _image = information.image;
+    _ID = information.idAttribute;
+    
+    return self;
+}
+
 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image
 {
     return [self _initWithType:type URL:url location:location title:title ID:ID rect:rect image:image userInfo:nil];

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h (219033 => 219034)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h	2017-07-01 02:25:59 UTC (rev 219034)
@@ -23,6 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#import "InteractionInformationAtPosition.h"
 #import "_WKActivatedElementInfo.h"
 
 #if WK_API_ENABLED
@@ -33,6 +34,8 @@
 
 @interface _WKActivatedElementInfo ()
 
++ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information;
+- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information;
 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image;
 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image userInfo:(NSDictionary *)userInfo;
 

Modified: trunk/Tools/ChangeLog (219033 => 219034)


--- trunk/Tools/ChangeLog	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Tools/ChangeLog	2017-07-01 02:25:59 UTC (rev 219034)
@@ -1,3 +1,17 @@
+2017-06-30  Megan Gardner  <[email protected]>
+
+        Add API to get WKActivatedElementInfo
+        https://bugs.webkit.org/show_bug.cgi?id=174001
+        <rdar://problem/29165518>
+        
+        Tests for now SPI to get activatedElementInfo.
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKRequestActivatedElementInfo.mm: Added.
+        (TestWebKitAPI::TEST):
+
 2017-06-30  Chris Dumez  <[email protected]>
 
         Move store logic from WebResourceLoadStatisticsManager to WebResourceLoadStatisticsStore

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (219033 => 219034)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-07-01 01:44:46 UTC (rev 219033)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-07-01 02:25:59 UTC (rev 219034)
@@ -132,6 +132,7 @@
 		3FBD1B4A1D3D66AB00E6D6FA /* FullscreenLayoutConstraints.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3FBD1B491D39D1DB00E6D6FA /* FullscreenLayoutConstraints.html */; };
 		3FCC4FE51EC4E8520076E37C /* PictureInPictureDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3FCC4FE41EC4E8520076E37C /* PictureInPictureDelegate.mm */; };
 		3FCC4FE81EC4E8CA0076E37C /* PictureInPictureDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3FCC4FE61EC4E87E0076E37C /* PictureInPictureDelegate.html */; };
+		44817A2F1F0486BF00003810 /* WKRequestActivatedElementInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */; };
 		448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
 		46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; };
 		4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */; };
@@ -1142,6 +1143,7 @@
 		41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
 		440A1D3814A0103A008A66F2 /* URL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URL.cpp; sourceTree = "<group>"; };
 		442BBF681C91CAD90017087F /* RefLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefLogger.cpp; sourceTree = "<group>"; };
+		44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRequestActivatedElementInfo.mm; sourceTree = "<group>"; };
 		448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentUtilitiesTest.cpp; sourceTree = "<group>"; };
 		44A622C114A0E2B60048515B /* WTFStringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFStringUtilities.h; sourceTree = "<group>"; };
 		46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; };
@@ -1889,6 +1891,7 @@
 				A14AAB611E78D7DE00C1ADC2 /* WKPDFView.mm */,
 				2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */,
 				2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */,
+				44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */,
 				5E4B1D2C1D404C6100053621 /* WKScrollViewDelegateCrash.mm */,
 				51C683DD1EA134DB00650183 /* WKURLSchemeHandler-1.mm */,
 				5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */,
@@ -3229,6 +3232,7 @@
 				7C54A4BE1AA11CCA00380F78 /* WKBundleFileHandle.cpp in Sources */,
 				51D124981E763B02002B2820 /* WKHTTPCookieStore.mm in Sources */,
 				7CCE7F1D1A411AE600447C4C /* WKImageCreateCGImageCrash.cpp in Sources */,
+				44817A2F1F0486BF00003810 /* WKRequestActivatedElementInfo.mm in Sources */,
 				375E0E171D66674400EFEC2C /* WKNSNumber.mm in Sources */,
 				37B47E301D64E7CA005F4EFF /* WKObject.mm in Sources */,
 				7C89D2AC1A69B80D003A5FDE /* WKPageConfiguration.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKRequestActivatedElementInfo.mm (0 => 219034)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKRequestActivatedElementInfo.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKRequestActivatedElementInfo.mm	2017-07-01 02:25:59 UTC (rev 219034)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebView.h>
+#import <WebKit/_WKActivatedElementInfo.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+namespace TestWebKitAPI {
+    
+TEST(WebKit2, ReqestActivatedElementInfoForLink)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style = 'margin: 0px;'><a href='' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    
+    __block bool finished = false;
+    [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
+        
+        EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeLink);
+        EXPECT_WK_STREQ(elementInfo.URL.absoluteString, "testURL.test");
+        EXPECT_WK_STREQ(elementInfo.title, "HitTestLinkTitle");
+        EXPECT_WK_STREQ(elementInfo.ID, @"testID");
+        EXPECT_TRUE(elementInfo.image != nil);
+        EXPECT_EQ(elementInfo.boundingRect.size.width, 320);
+        EXPECT_EQ(elementInfo.boundingRect.size.height, 500);
+        EXPECT_EQ(elementInfo.image.size.width, 320);
+        EXPECT_EQ(elementInfo.image.size.height, 500);
+        
+        finished = true;
+    }];
+    
+    TestWebKitAPI::Util::run(&finished);
+}
+    
+TEST(WebKit2, ReqestActivatedElementInfoForBlank)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style = 'margin: 0px;'></body></html>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    
+    __block bool finished = false;
+    [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
+        
+        EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeUnspecified);
+        EXPECT_EQ(elementInfo.boundingRect.size.width, 320);
+        EXPECT_EQ(elementInfo.boundingRect.size.height, 500);
+        
+        finished = true;
+    }];
+    
+    TestWebKitAPI::Util::run(&finished);
+}
+    
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to