Title: [213176] trunk
Revision
213176
Author
wenson_hs...@apple.com
Date
2017-02-28 14:11:07 -0800 (Tue, 28 Feb 2017)

Log Message

Data interaction should support attachment elements
https://bugs.webkit.org/show_bug.cgi?id=168916
<rdar://problem/30664519>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Teaches DragController to recognize and initiate dragging on attachment elements, and also adds a new
convenience method to the WebItemProviderPasteboard for block enumeration of available UIItemProviders. Covered
by a new API test: DataInteractionTests.AttachmentElementItemProviders.

* page/DragController.cpp:
(WebCore::DragController::draggableElement):
(WebCore::DragController::startDrag):
* platform/ios/WebItemProviderPasteboard.h:
* platform/ios/WebItemProviderPasteboard.mm:
(-[WebItemProviderPasteboard enumerateItemProvidersWithBlock:]):

Source/WebKit2:

Teaches WKContentView to recognize attachment elements as data interactive content, and add an internal hook to
adjust the list of item providers before initiating data interaction.

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _adjustedDataInteractionItemProviders:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView pointIsInDataInteractionContent:]):

Tools:

Adds a new unit test verifying that a client injected bundle is able to augment UIItemProvider data vended to
the UI process.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html: Added.
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213175 => 213176)


--- trunk/Source/WebCore/ChangeLog	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/ChangeLog	2017-02-28 22:11:07 UTC (rev 213176)
@@ -1,3 +1,22 @@
+2017-02-28  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        <rdar://problem/30664519>
+
+        Reviewed by Ryosuke Niwa.
+
+        Teaches DragController to recognize and initiate dragging on attachment elements, and also adds a new
+        convenience method to the WebItemProviderPasteboard for block enumeration of available UIItemProviders. Covered
+        by a new API test: DataInteractionTests.AttachmentElementItemProviders.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::draggableElement):
+        (WebCore::DragController::startDrag):
+        * platform/ios/WebItemProviderPasteboard.h:
+        * platform/ios/WebItemProviderPasteboard.mm:
+        (-[WebItemProviderPasteboard enumerateItemProvidersWithBlock:]):
+
 2017-02-28  Mark Lam  <mark....@apple.com>
 
         Remove setExclusiveThread() and peers from the JSLock.

Modified: trunk/Source/WebCore/page/DragController.cpp (213175 => 213176)


--- trunk/Source/WebCore/page/DragController.cpp	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/page/DragController.cpp	2017-02-28 22:11:07 UTC (rev 213176)
@@ -64,6 +64,7 @@
 #include "PlatformKeyboardEvent.h"
 #include "PluginDocument.h"
 #include "PluginViewBase.h"
+#include "Position.h"
 #include "RenderFileUploadControl.h"
 #include "RenderImage.h"
 #include "RenderView.h"
@@ -75,6 +76,7 @@
 #include "StyleProperties.h"
 #include "Text.h"
 #include "TextEvent.h"
+#include "VisiblePosition.h"
 #include "htmlediting.h"
 #include "markup.h"
 
@@ -654,12 +656,20 @@
     if (!startElement)
         return nullptr;
 #if ENABLE(ATTACHMENT_ELEMENT)
-    // Unlike image elements, attachment elements are immediately selected upon mouse down,
-    // but for those elements we still want to use the single element drag behavior as long as
-    // the element is the only content of the selection.
-    const VisibleSelection& selection = sourceFrame->selection().selection();
-    if (selection.isRange() && is<HTMLAttachmentElement>(selection.start().anchorNode()) && selection.start().anchorNode() == selection.end().anchorNode())
-        state.type = DragSourceActionNone;
+    if (is<HTMLAttachmentElement>(startElement)) {
+        auto selection = sourceFrame->selection().selection();
+        bool isSingleAttachmentSelection = selection.start() == Position(startElement, Position::PositionIsBeforeAnchor) && selection.end() == Position(startElement, Position::PositionIsAfterAnchor);
+        bool isAttachmentElementInCurrentSelection = false;
+        if (auto selectedRange = selection.toNormalizedRange()) {
+            auto compareResult = selectedRange->compareNode(*startElement);
+            isAttachmentElementInCurrentSelection = !compareResult.hasException() && compareResult.releaseReturnValue() == Range::NODE_INSIDE;
+        }
+
+        if (!isAttachmentElementInCurrentSelection || isSingleAttachmentSelection) {
+            state.type = DragSourceActionAttachment;
+            return startElement;
+        }
+    }
 #endif
 
     for (auto* renderer = startElement->renderer(); renderer; renderer = renderer->parent()) {
@@ -997,11 +1007,22 @@
     }
 
 #if ENABLE(ATTACHMENT_ELEMENT)
-    if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
+    if (m_dragSourceAction & DragSourceActionAttachment) {
         if (!dataTransfer.pasteboard().hasData()) {
-            m_draggingAttachmentURL = attachmentURL;
             selectElement(element);
-            declareAndWriteAttachment(dataTransfer, element, attachmentURL);
+            if (!attachmentURL.isEmpty()) {
+                // Use the attachment URL specified by the file attribute to populate the pasteboard.
+                m_draggingAttachmentURL = attachmentURL;
+                declareAndWriteAttachment(dataTransfer, element, attachmentURL);
+            } else if (src.editor().client()) {
+#if PLATFORM(COCOA)
+                // Otherwise, if no file URL is specified, call out to the injected bundle to populate the pasteboard with data.
+                auto& editor = src.editor();
+                editor.willWriteSelectionToPasteboard(src.selection().toNormalizedRange());
+                editor.writeSelectionToPasteboard(dataTransfer.pasteboard());
+                editor.didWriteSelectionToPasteboard();
+#endif
+            }
         }
         
         m_client.willPerformDragSourceAction(DragSourceActionAttachment, dragOrigin, dataTransfer);

Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h (213175 => 213176)


--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h	2017-02-28 22:11:07 UTC (rev 213176)
@@ -45,6 +45,8 @@
 - (void)incrementPendingOperationCount;
 - (void)decrementPendingOperationCount;
 
+- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block;
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (213175 => 213176)


--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	2017-02-28 22:11:07 UTC (rev 213176)
@@ -248,6 +248,11 @@
     _pendingOperationCount--;
 }
 
+- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block
+{
+    [_itemProviders enumerateObjectsUsingBlock:block];
+}
+
 @end
 
 #endif // ENABLE(DATA_INTERACTION)

Modified: trunk/Source/WebKit2/ChangeLog (213175 => 213176)


--- trunk/Source/WebKit2/ChangeLog	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/ChangeLog	2017-02-28 22:11:07 UTC (rev 213176)
@@ -1,3 +1,21 @@
+2017-02-28  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        <rdar://problem/30664519>
+
+        Reviewed by Ryosuke Niwa.
+
+        Teaches WKContentView to recognize attachment elements as data interactive content, and add an internal hook to
+        adjust the list of item providers before initiating data interaction.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _adjustedDataInteractionItemProviders:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView pointIsInDataInteractionContent:]):
+
 2017-02-28  Yongjun Zhang  <yongjun_zh...@apple.com>
 
         Add delegate method to handle images with alternate data.

Modified: trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h (213175 => 213176)


--- trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h	2017-02-28 22:11:07 UTC (rev 213176)
@@ -40,6 +40,7 @@
 #import <UIKit/UIImagePickerController_Private.h>
 #import <UIKit/UIImage_Private.h>
 #import <UIKit/UIInterface_Private.h>
+#import <UIKit/UIItemProvider_Private.h>
 #import <UIKit/UIKeyboardImpl.h>
 #import <UIKit/UIKeyboardIntl.h>
 #import <UIKit/UIKeyboard_Private.h>

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


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-02-28 22:11:07 UTC (rev 213176)
@@ -3726,6 +3726,11 @@
 {
 }
 
+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
+{
+    return originalItemProviders;
+}
+
 #endif
 
 - (void)_didRelaunchProcess

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


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-02-28 22:11:07 UTC (rev 213176)
@@ -188,6 +188,8 @@
 - (void)_accessibilityRetrieveSpeakSelectionContent;
 - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content;
 
+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 #else
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (213175 => 213176)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2017-02-28 22:11:07 UTC (rev 213176)
@@ -1437,7 +1437,7 @@
     InteractionInformationRequest request(roundedIntPoint(point));
     [self ensurePositionInformationIsUpToDate:request];
 
-    if (_positionInformation.isImage || _positionInformation.isLink)
+    if (_positionInformation.isImage || _positionInformation.isLink || _positionInformation.isAttachment)
         return YES;
 
     return _positionInformation.hasSelectionAtPosition;

Modified: trunk/Tools/ChangeLog (213175 => 213176)


--- trunk/Tools/ChangeLog	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/ChangeLog	2017-02-28 22:11:07 UTC (rev 213176)
@@ -1,3 +1,20 @@
+2017-02-28  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        <rdar://problem/30664519>
+
+        Reviewed by Ryosuke Niwa.
+
+        Adds a new unit test verifying that a client injected bundle is able to augment UIItemProvider data vended to
+        the UI process.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html: Added.
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]):
+        (TestWebKitAPI::TEST):
+
 2017-02-28  Chris Dumez  <cdu...@apple.com>
 
         [iOS] Throttle requestAnimationFrame to 30fps in low power mode

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (213175 => 213176)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-28 22:11:07 UTC (rev 213176)
@@ -561,6 +561,7 @@
 		F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F415086C1DA040C10044BE9B /* play-audio-on-click.html */; };
 		F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
 		F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
+		F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; };
 		F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
 		F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
 		F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */; };
@@ -639,6 +640,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */,
 				8361F1781E610B4E00759B25 /* link-with-download-attribute-with-slashes.html in Copy Resources */,
 				F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */,
 				C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
@@ -1395,6 +1397,7 @@
 		F415086C1DA040C10044BE9B /* play-audio-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "play-audio-on-click.html"; sourceTree = "<group>"; };
 		F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKit2Cocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
 		F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-page-contenteditable.html"; sourceTree = "<group>"; };
+		F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; };
 		F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; };
 		F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "enormous-video-with-sound.html"; sourceTree = "<group>"; };
 		F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionSimulator.mm; sourceTree = "<group>"; };
@@ -1806,6 +1809,7 @@
 				51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
 				C25CCA0A1E513F490026CB8A /* LineBreaking.html */,
 				C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
+				F4856CA21E6498A8009D7EE7 /* attachment-element.html */,
 			);
 			name = Resources;
 			sourceTree = "<group>";

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html (0 => 213176)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html	2017-02-28 22:11:07 UTC (rev 213176)
@@ -0,0 +1,14 @@
+<meta name="viewport" content="width=device-width">
+<style>
+body, html {
+    padding: 0;
+    margin: 0;
+}
+
+attachment {
+    position: absolute;
+    top: 0;
+    left: 0;
+}
+</style>
+<attachment title="index.html" type="public.html" subtitle="0.1 KB"></attachment>

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (213175 => 213176)


--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-02-28 22:11:07 UTC (rev 213176)
@@ -30,8 +30,11 @@
 #import "DataInteractionSimulator.h"
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
+#import "WKWebViewConfigurationExtras.h"
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <UIKit/UIItemProvider_Private.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
 
 @implementation TestWKWebView (DataInteractionTests)
 
@@ -47,6 +50,22 @@
 
 @end
 
+@interface CustomItemProviderWebView : TestWKWebView
+@property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
+@end
+
+@implementation CustomItemProviderWebView
+
+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
+{
+    if (!self.convertItemProvidersBlock)
+        return [super _adjustedDataInteractionItemProviders:originalItemProviders];
+
+    return self.convertItemProvidersBlock(originalItemProviders);
+}
+
+@end
+
 static NSValue *makeCGRectValue(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
 {
     return [NSValue valueWithCGRect:CGRectMake(x, y, width, height)];
@@ -249,6 +268,33 @@
     EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 215, 174) ]]);
 }
 
+TEST(DataInteractionTests, AttachmentElementItemProviders)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = [WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"BundleEditingDelegatePlugIn"];
+    [configuration _setAttachmentElementEnabled:YES];
+    auto webView = adoptNS([[CustomItemProviderWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
+    [webView synchronouslyLoadTestPageNamed:@"attachment-element"];
+
+    NSString *injectedTypeIdentifier = @"org.webkit.data";
+    __block RetainPtr<NSString> injectedString;
+    [webView setConvertItemProvidersBlock:^NSArray *(NSArray *originalItemProviders)
+    {
+        for (UIItemProvider *provider in originalItemProviders) {
+            NSData *injectedData = [provider copyDataRepresentationForTypeIdentifier:injectedTypeIdentifier error:nil];
+            if (!injectedData.length)
+                continue;
+            injectedString = adoptNS([[NSString alloc] initWithData:injectedData encoding:NSUTF8StringEncoding]);
+            break;
+        }
+        return originalItemProviders;
+    }];
+
+    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+    [dataInteractionSimulator runFrom:CGPointMake(50, 50) to:CGPointMake(50, 400)];
+
+    EXPECT_WK_STREQ("hello", [injectedString UTF8String]);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(DATA_INTERACTION)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to