Changeset 213176 in webkit


Ignore:
Timestamp:
Feb 28, 2017 2:11:07 PM (7 years ago)
Author:
Wenson Hsieh
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):

Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r213175 r213176  
     12017-02-28  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Data interaction should support attachment elements
     4        https://bugs.webkit.org/show_bug.cgi?id=168916
     5        <rdar://problem/30664519>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Teaches DragController to recognize and initiate dragging on attachment elements, and also adds a new
     10        convenience method to the WebItemProviderPasteboard for block enumeration of available UIItemProviders. Covered
     11        by a new API test: DataInteractionTests.AttachmentElementItemProviders.
     12
     13        * page/DragController.cpp:
     14        (WebCore::DragController::draggableElement):
     15        (WebCore::DragController::startDrag):
     16        * platform/ios/WebItemProviderPasteboard.h:
     17        * platform/ios/WebItemProviderPasteboard.mm:
     18        (-[WebItemProviderPasteboard enumerateItemProvidersWithBlock:]):
     19
    1202017-02-28  Mark Lam  <mark.lam@apple.com>
    221
  • trunk/Source/WebCore/page/DragController.cpp

    r212930 r213176  
    6565#include "PluginDocument.h"
    6666#include "PluginViewBase.h"
     67#include "Position.h"
    6768#include "RenderFileUploadControl.h"
    6869#include "RenderImage.h"
     
    7677#include "Text.h"
    7778#include "TextEvent.h"
     79#include "VisiblePosition.h"
    7880#include "htmlediting.h"
    7981#include "markup.h"
     
    655657        return nullptr;
    656658#if ENABLE(ATTACHMENT_ELEMENT)
    657     // Unlike image elements, attachment elements are immediately selected upon mouse down,
    658     // but for those elements we still want to use the single element drag behavior as long as
    659     // the element is the only content of the selection.
    660     const VisibleSelection& selection = sourceFrame->selection().selection();
    661     if (selection.isRange() && is<HTMLAttachmentElement>(selection.start().anchorNode()) && selection.start().anchorNode() == selection.end().anchorNode())
    662         state.type = DragSourceActionNone;
     659    if (is<HTMLAttachmentElement>(startElement)) {
     660        auto selection = sourceFrame->selection().selection();
     661        bool isSingleAttachmentSelection = selection.start() == Position(startElement, Position::PositionIsBeforeAnchor) && selection.end() == Position(startElement, Position::PositionIsAfterAnchor);
     662        bool isAttachmentElementInCurrentSelection = false;
     663        if (auto selectedRange = selection.toNormalizedRange()) {
     664            auto compareResult = selectedRange->compareNode(*startElement);
     665            isAttachmentElementInCurrentSelection = !compareResult.hasException() && compareResult.releaseReturnValue() == Range::NODE_INSIDE;
     666        }
     667
     668        if (!isAttachmentElementInCurrentSelection || isSingleAttachmentSelection) {
     669            state.type = DragSourceActionAttachment;
     670            return startElement;
     671        }
     672    }
    663673#endif
    664674
     
    9981008
    9991009#if ENABLE(ATTACHMENT_ELEMENT)
    1000     if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
     1010    if (m_dragSourceAction & DragSourceActionAttachment) {
    10011011        if (!dataTransfer.pasteboard().hasData()) {
    1002             m_draggingAttachmentURL = attachmentURL;
    10031012            selectElement(element);
    1004             declareAndWriteAttachment(dataTransfer, element, attachmentURL);
     1013            if (!attachmentURL.isEmpty()) {
     1014                // Use the attachment URL specified by the file attribute to populate the pasteboard.
     1015                m_draggingAttachmentURL = attachmentURL;
     1016                declareAndWriteAttachment(dataTransfer, element, attachmentURL);
     1017            } else if (src.editor().client()) {
     1018#if PLATFORM(COCOA)
     1019                // Otherwise, if no file URL is specified, call out to the injected bundle to populate the pasteboard with data.
     1020                auto& editor = src.editor();
     1021                editor.willWriteSelectionToPasteboard(src.selection().toNormalizedRange());
     1022                editor.writeSelectionToPasteboard(dataTransfer.pasteboard());
     1023                editor.didWriteSelectionToPasteboard();
     1024#endif
     1025            }
    10051026        }
    10061027       
  • trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h

    r211716 r213176  
    4646- (void)decrementPendingOperationCount;
    4747
     48- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block;
     49
    4850@end
    4951
  • trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm

    r212734 r213176  
    249249}
    250250
     251- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block
     252{
     253    [_itemProviders enumerateObjectsUsingBlock:block];
     254}
     255
    251256@end
    252257
  • trunk/Source/WebKit2/ChangeLog

    r213170 r213176  
     12017-02-28  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Data interaction should support attachment elements
     4        https://bugs.webkit.org/show_bug.cgi?id=168916
     5        <rdar://problem/30664519>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Teaches WKContentView to recognize attachment elements as data interactive content, and add an internal hook to
     10        adjust the list of item providers before initiating data interaction.
     11
     12        * Platform/spi/ios/UIKitSPI.h:
     13        * UIProcess/API/Cocoa/WKWebView.mm:
     14        (-[WKWebView _adjustedDataInteractionItemProviders:]):
     15        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     16        * UIProcess/ios/WKContentViewInteraction.mm:
     17        (-[WKContentView pointIsInDataInteractionContent:]):
     18
    1192017-02-28  Yongjun Zhang  <yongjun_zhang@apple.com>
    220
  • trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h

    r212974 r213176  
    4141#import <UIKit/UIImage_Private.h>
    4242#import <UIKit/UIInterface_Private.h>
     43#import <UIKit/UIItemProvider_Private.h>
    4344#import <UIKit/UIKeyboardImpl.h>
    4445#import <UIKit/UIKeyboardIntl.h>
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r212974 r213176  
    37273727}
    37283728
     3729- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
     3730{
     3731    return originalItemProviders;
     3732}
     3733
    37293734#endif
    37303735
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r212974 r213176  
    189189- (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content;
    190190
     191- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders WK_API_AVAILABLE(ios(WK_IOS_TBA));
     192
    191193#else
    192194@property (readonly) NSColor *_pageExtendedBackgroundColor;
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r213170 r213176  
    14381438    [self ensurePositionInformationIsUpToDate:request];
    14391439
    1440     if (_positionInformation.isImage || _positionInformation.isLink)
     1440    if (_positionInformation.isImage || _positionInformation.isLink || _positionInformation.isAttachment)
    14411441        return YES;
    14421442
  • trunk/Tools/ChangeLog

    r213169 r213176  
     12017-02-28  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Data interaction should support attachment elements
     4        https://bugs.webkit.org/show_bug.cgi?id=168916
     5        <rdar://problem/30664519>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Adds a new unit test verifying that a client injected bundle is able to augment UIItemProvider data vended to
     10        the UI process.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html: Added.
     14        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
     15        (-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]):
     16        (TestWebKitAPI::TEST):
     17
    1182017-02-28  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r213163 r213176  
    562562                F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
    563563                F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
     564                F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; };
    564565                F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
    565566                F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
     
    640641                        dstSubfolderSpec = 7;
    641642                        files = (
     643                                F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */,
    642644                                8361F1781E610B4E00759B25 /* link-with-download-attribute-with-slashes.html in Copy Resources */,
    643645                                F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */,
     
    13961398                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; };
    13971399                F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-page-contenteditable.html"; sourceTree = "<group>"; };
     1400                F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; };
    13981401                F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; };
    13991402                F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "enormous-video-with-sound.html"; sourceTree = "<group>"; };
     
    18071810                                C25CCA0A1E513F490026CB8A /* LineBreaking.html */,
    18081811                                C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
     1812                                F4856CA21E6498A8009D7EE7 /* attachment-element.html */,
    18091813                        );
    18101814                        name = Resources;
  • trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

    r213091 r213176  
    3131#import "PlatformUtilities.h"
    3232#import "TestWKWebView.h"
     33#import "WKWebViewConfigurationExtras.h"
    3334#import <MobileCoreServices/MobileCoreServices.h>
    3435#import <UIKit/UIItemProvider_Private.h>
     36#import <WebKit/WKWebViewConfigurationPrivate.h>
     37#import <WebKit/WKWebViewPrivate.h>
    3538
    3639@implementation TestWKWebView (DataInteractionTests)
     
    4447{
    4548    return [self stringByEvaluatingJavaScript:@"editor.value"];
     49}
     50
     51@end
     52
     53@interface CustomItemProviderWebView : TestWKWebView
     54@property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
     55@end
     56
     57@implementation CustomItemProviderWebView
     58
     59- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
     60{
     61    if (!self.convertItemProvidersBlock)
     62        return [super _adjustedDataInteractionItemProviders:originalItemProviders];
     63
     64    return self.convertItemProvidersBlock(originalItemProviders);
    4665}
    4766
     
    250269}
    251270
     271TEST(DataInteractionTests, AttachmentElementItemProviders)
     272{
     273    RetainPtr<WKWebViewConfiguration> configuration = [WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"BundleEditingDelegatePlugIn"];
     274    [configuration _setAttachmentElementEnabled:YES];
     275    auto webView = adoptNS([[CustomItemProviderWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
     276    [webView synchronouslyLoadTestPageNamed:@"attachment-element"];
     277
     278    NSString *injectedTypeIdentifier = @"org.webkit.data";
     279    __block RetainPtr<NSString> injectedString;
     280    [webView setConvertItemProvidersBlock:^NSArray *(NSArray *originalItemProviders)
     281    {
     282        for (UIItemProvider *provider in originalItemProviders) {
     283            NSData *injectedData = [provider copyDataRepresentationForTypeIdentifier:injectedTypeIdentifier error:nil];
     284            if (!injectedData.length)
     285                continue;
     286            injectedString = adoptNS([[NSString alloc] initWithData:injectedData encoding:NSUTF8StringEncoding]);
     287            break;
     288        }
     289        return originalItemProviders;
     290    }];
     291
     292    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     293    [dataInteractionSimulator runFrom:CGPointMake(50, 50) to:CGPointMake(50, 400)];
     294
     295    EXPECT_WK_STREQ("hello", [injectedString UTF8String]);
     296}
     297
    252298} // namespace TestWebKitAPI
    253299
Note: See TracChangeset for help on using the changeset viewer.