Changeset 283563 in webkit


Ignore:
Timestamp:
Oct 5, 2021 11:40:31 AM (10 months ago)
Author:
timothy_horton@apple.com
Message:

<model> should be draggable, similar to <img>
https://bugs.webkit.org/show_bug.cgi?id=229246

Reviewed by Wenson Hsieh.

Source/WebCore:

  • page/DragActions.h:

(WebCore::anyDragSourceAction):

  • page/DragController.cpp:

(WebCore::DragController::draggableElement const):
(WebCore::DragController::startDrag):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dragHysteresisExceeded const):
Make <model> draggable, vending a PasteboardImage with the model data and correct MIME type.
We currently make a DragImage from a node snapshot, but later will want a richer DragImage.

Source/WebKit:

  • UIProcess/ios/DragDropInteractionState.mm:

(WebKit::shouldUseDragImageToCreatePreviewForDragSource):
For now, use the Web-Content-process-painted node-snapshot DragImage for the targeted preview on iOS.

Source/WebKitLegacy/mac:

  • WebView/WebView.mm:

(kit):
Do nothing for <model> drags in legacy WebKit.

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit/cube.usdz: Added.
  • TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:

(-[ModelLoadingMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):
Add a test that ensures that dragging a <model> works.

Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r283562 r283563  
     12021-10-05  Tim Horton  <timothy_horton@apple.com>
     2
     3        <model> should be draggable, similar to <img>
     4        https://bugs.webkit.org/show_bug.cgi?id=229246
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * page/DragActions.h:
     9        (WebCore::anyDragSourceAction):
     10        * page/DragController.cpp:
     11        (WebCore::DragController::draggableElement const):
     12        (WebCore::DragController::startDrag):
     13        * page/EventHandler.cpp:
     14        (WebCore::EventHandler::dragHysteresisExceeded const):
     15        Make <model> draggable, vending a PasteboardImage with the model data and correct MIME type.
     16        We currently make a DragImage from a node snapshot, but later will want a richer DragImage.
     17
    1182021-10-05  Gabriel Nava Marino  <gnavamarino@apple.com>
    219
  • trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h

    r282567 r283563  
    7474    void enterFullscreen();
    7575
     76    bool isDraggableIgnoringAttributes() const final { return true; }
     77
    7678private:
    7779    HTMLModelElement(const QualifiedName&, Document&);
  • trunk/Source/WebCore/page/DragActions.h

    r263178 r283563  
    4747// See WebDragSourceAction.
    4848enum class DragSourceAction : uint8_t {
    49     DHTML      = 1,
    50     Image      = 2,
    51     Link       = 4,
    52     Selection  = 8,
     49    DHTML      = 1 << 0,
     50    Image      = 1 << 1,
     51    Link       = 1 << 2,
     52    Selection  = 1 << 3,
    5353#if ENABLE(ATTACHMENT_ELEMENT)
    54     Attachment = 16,
     54    Attachment = 1 << 4,
    5555#endif
    5656#if ENABLE(INPUT_TYPE_COLOR)
    57     Color      = 32,
     57    Color      = 1 << 5,
     58#endif
     59#if ENABLE(MODEL_ELEMENT)
     60    Model      = 1 << 6,
    5861#endif
    5962};
     
    7174#if ENABLE(INPUT_TYPE_COLOR)
    7275        , DragSourceAction::Color
     76#endif
     77#if ENABLE(MODEL_ELEMENT)
     78        , DragSourceAction::Model
    7379#endif
    7480    };
     
    145151        , WebCore::DragSourceAction::Color
    146152#endif
     153#if ENABLE(MODEL_ELEMENT)
     154        , WebCore::DragSourceAction::Model
     155#endif
    147156    >;
    148157};
  • trunk/Source/WebCore/page/DragController.cpp

    r282799 r283563  
    5959#include "HTMLImageElement.h"
    6060#include "HTMLInputElement.h"
     61#include "HTMLModelElement.h"
    6162#include "HTMLParserIdioms.h"
    6263#include "HTMLPlugInElement.h"
     
    6566#include "Image.h"
    6667#include "ImageOrientation.h"
     68#include "Model.h"
    6769#include "MoveSelectionCommand.h"
    6870#include "Page.h"
     
    753755}
    754756
     757#if ENABLE(MODEL_ELEMENT)
     758
     759static bool modelElementIsDraggable(const HTMLModelElement& modelElement)
     760{
     761    return !!modelElement.model();
     762}
     763
     764#endif
     765
    755766#if ENABLE(ATTACHMENT_ELEMENT)
    756767
     
    825836            }
    826837#endif
     838#if ENABLE(MODEL_ELEMENT)
     839            if (m_dragSourceAction.contains(DragSourceAction::Model) && is<HTMLModelElement>(*element) && modelElementIsDraggable(downcast<HTMLModelElement>(*element))) {
     840                state.type.add(DragSourceAction::Model);
     841                return element;
     842            }
     843#endif
    827844        }
    828845    }
     
    12351252
    12361253        client().willPerformDragSourceAction(DragSourceAction::Color, dragOrigin, dataTransfer);
     1254        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { });
     1255        return true;
     1256    }
     1257#endif
     1258
     1259#if ENABLE(MODEL_ELEMENT)
     1260    bool isModel = is<HTMLModelElement>(state.source);
     1261    if (isModel && m_dragSourceAction.contains(DragSourceAction::Model)) {
     1262        auto& modelElement = downcast<HTMLModelElement>(*state.source);
     1263        dragImage = DragImage { createDragImageForNode(src, modelElement) };
     1264
     1265        PasteboardImage pasteboardImage;
     1266        pasteboardImage.suggestedName = modelElement.currentSrc().lastPathComponent().toString();
     1267        pasteboardImage.resourceMIMEType = modelElement.model()->mimeType();
     1268        pasteboardImage.resourceData = modelElement.model()->data();
     1269        dataTransfer.pasteboard().write(pasteboardImage);
     1270
     1271        dragImageOffset = IntPoint { dragImageSize(dragImage.get()) };
     1272        dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, false);
     1273
     1274        client().willPerformDragSourceAction(DragSourceAction::Model, dragOrigin, dataTransfer);
    12371275        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { });
    12381276        return true;
  • trunk/Source/WebCore/page/EventHandler.cpp

    r283335 r283563  
    38873887        case DragSourceAction::Attachment:
    38883888#endif
     3889#if ENABLE(MODEL_ELEMENT)
     3890        case DragSourceAction::Model:
     3891#endif
    38893892            threshold = ImageDragHysteresis;
    38903893            break;
  • trunk/Source/WebKit/ChangeLog

    r283560 r283563  
     12021-10-05  Tim Horton  <timothy_horton@apple.com>
     2
     3        <model> should be draggable, similar to <img>
     4        https://bugs.webkit.org/show_bug.cgi?id=229246
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * UIProcess/ios/DragDropInteractionState.mm:
     9        (WebKit::shouldUseDragImageToCreatePreviewForDragSource):
     10        For now, use the Web-Content-process-painted node-snapshot DragImage for the targeted preview on iOS.
     11
    1122021-10-05  Tim Horton  <timothy_horton@apple.com>
    213
  • trunk/Source/WebKit/UIProcess/ios/DragDropInteractionState.mm

    r278253 r283563  
    104104#endif
    105105
     106#if ENABLE(MODEL_ELEMENT)
     107    if (source.action.contains(DragSourceAction::Model))
     108        return true;
     109#endif
     110
    106111    return source.action.containsAny({ DragSourceAction::DHTML, DragSourceAction::Image });
    107112}
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r283476 r283563  
     12021-10-05  Tim Horton  <timothy_horton@apple.com>
     2
     3        <model> should be draggable, similar to <img>
     4        https://bugs.webkit.org/show_bug.cgi?id=229246
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebView/WebView.mm:
     9        (kit):
     10        Do nothing for <model> drags in legacy WebKit.
     11
    1122021-10-03  David Kilzer  <ddkilzer@apple.com>
    213
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r282848 r283563  
    720720        break;
    721721#endif
     722#if ENABLE(MODEL_ELEMENT)
     723    case WebCore::DragSourceAction::Model:
     724        break;
     725#endif
    722726    }
    723727
  • trunk/Tools/ChangeLog

    r283559 r283563  
     12021-10-05  Tim Horton  <timothy_horton@apple.com>
     2
     3        <model> should be draggable, similar to <img>
     4        https://bugs.webkit.org/show_bug.cgi?id=229246
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit/cube.usdz: Added.
     10        * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
     11        (-[ModelLoadingMessageHandler userContentController:didReceiveScriptMessage:]):
     12        (TestWebKitAPI::TEST):
     13        Add a test that ensures that dragging a <model> works.
     14
    1152021-10-05  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r283553 r283563  
    176176                2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
    177177                2DD87145265F23B4005F997C /* BifurcatedGraphicsContextTestsCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DD87144265F23B4005F997C /* BifurcatedGraphicsContextTestsCG.cpp */; };
     178                2DDD4DA4270B8B3500659A61 /* cube.usdz in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DDD4DA3270B8B3300659A61 /* cube.usdz */; };
    178179                2DE71AFE1D49C0BD00904094 /* AnimatedResize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */; };
    179180                2DE71B001D49C3ED00904094 /* blinking-div.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DE71AFF1D49C2F000904094 /* blinking-div.html */; };
     
    14601461                                7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
    14611462                                4995A6F025E8772000E5F0A9 /* csp-document-uri-report.html in Copy Resources */,
     1463                                2DDD4DA4270B8B3500659A61 /* cube.usdz in Copy Resources */,
    14621464                                F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */,
    14631465                                290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */,
     
    19871989                2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "lots-of-text-vertical-lr.html"; sourceTree = "<group>"; };
    19881990                2DD87144265F23B4005F997C /* BifurcatedGraphicsContextTestsCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BifurcatedGraphicsContextTestsCG.cpp; path = cg/BifurcatedGraphicsContextTestsCG.cpp; sourceTree = "<group>"; };
     1991                2DDD4DA3270B8B3300659A61 /* cube.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = cube.usdz; sourceTree = "<group>"; };
    19891992                2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnimatedResize.mm; sourceTree = "<group>"; };
    19901993                2DE71AFF1D49C2F000904094 /* blinking-div.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "blinking-div.html"; sourceTree = "<group>"; };
     
    46294632                                9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */,
    46304633                                5C9E56861DF9148E00C9EE33 /* contentBlockerCheck.html */,
     4634                                2DDD4DA3270B8B3300659A61 /* cube.usdz */,
    46314635                                290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
    46324636                                118153432208B7AC00B2CCD2 /* deferred-script-load.html */,
  • trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm

    r273308 r283563  
    3232#import "NSItemProviderAdditions.h"
    3333#import "PlatformUtilities.h"
     34#import "TestURLSchemeHandler.h"
    3435#import "TestWKWebView.h"
    3536#import "UIKitSPI.h"
     
    4445#import <WebKit/WKWebViewConfigurationPrivate.h>
    4546#import <WebKit/WebItemProviderPasteboard.h>
     47#import <WebKit/_WKExperimentalFeature.h>
    4648#import <WebKit/_WKProcessPoolConfiguration.h>
    4749#import <wtf/Seconds.h>
     
    9294
    9395@end
     96
     97@interface ModelLoadingMessageHandler : NSObject <WKScriptMessageHandler>
     98
     99@property (nonatomic) BOOL didLoadModel;
     100
     101@end
     102
     103@implementation ModelLoadingMessageHandler
     104- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
     105{
     106    EXPECT_WK_STREQ(@"READY", [message body]);
     107    _didLoadModel = true;
     108}
     109@end
     110
    94111
    95112static void loadTestPageAndEnsureInputSession(DragAndDropSimulator *simulator, NSString *testPageName)
     
    21572174}
    21582175
     2176TEST(DragAndDropTests, CanStartDragOnModel)
     2177{
     2178    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     2179    for (_WKExperimentalFeature *feature in [WKPreferences _experimentalFeatures]) {
     2180        if ([feature.key isEqualToString:@"ModelElementEnabled"])
     2181            [[configuration preferences] _setEnabled:YES forFeature:feature];
     2182    }
     2183
     2184    // FIXME: Remove this after <rdar://problem/83863149> is fixed.
     2185    // It should not be necessary to use WKURLSchemeHandler here, but CFNetwork does not correctly identify USDZ files.
     2186    auto handler = adoptNS([TestURLSchemeHandler new]);
     2187    RetainPtr<NSData> modelData = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:@"cube" withExtension:@"usdz" subdirectory:@"TestWebKitAPI.resources"]];
     2188    [handler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
     2189        NSURLResponse *response = [[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"model/vnd.usdz+zip" expectedContentLength:[modelData length] textEncodingName:nil] autorelease];
     2190        [task didReceiveResponse:response];
     2191        [task didReceiveData:modelData.get()];
     2192        [task didFinish];
     2193    }];
     2194
     2195    auto messageHandler = adoptNS([[ModelLoadingMessageHandler alloc] init]);
     2196    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"modelLoading"];
     2197    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"model"];
     2198   
     2199    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
     2200    [webView synchronouslyLoadHTMLString:@"<model><source src='model://cube.usdz'></model><script>document.getElementsByTagName('model')[0].ready.then(() => { window.webkit.messageHandlers.modelLoading.postMessage('READY') });</script>"];
     2201
     2202    while (![messageHandler didLoadModel])
     2203        Util::spinRunLoop();
     2204
     2205    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);
     2206    [simulator runFrom:CGPointMake(20, 20) to:CGPointMake(100, 100)];
     2207
     2208    NSArray *registeredTypes = [[simulator sourceItemProviders].firstObject registeredTypeIdentifiers];
     2209    EXPECT_WK_STREQ("com.pixar.universal-scene-description-mobile", [registeredTypes firstObject]);
     2210}
     2211
    21592212} // namespace TestWebKitAPI
    21602213
Note: See TracChangeset for help on using the changeset viewer.