Bug 178056 - dragenter and dragleave shouldn't use the same data transfer object
Summary: dragenter and dragleave shouldn't use the same data transfer object
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks: 178060
  Show dependency treegraph
 
Reported: 2017-10-07 18:27 PDT by Ryosuke Niwa
Modified: 2017-10-09 11:55 PDT (History)
10 users (show)

See Also:


Attachments
Fixes the bug and refactors code (28.73 KB, patch)
2017-10-07 18:39 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Skipped the test on Windows (29.49 KB, patch)
2017-10-07 20:25 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch for landing (30.33 KB, patch)
2017-10-08 02:29 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2017-10-07 18:27:13 PDT
We're supposed to be creating a distinct DataTransfer object for each dragenter & dragleave event we fire.
Comment 1 Ryosuke Niwa 2017-10-07 18:39:12 PDT
Created attachment 323111 [details]
Fixes the bug and refactors code
Comment 2 Ryosuke Niwa 2017-10-07 20:25:47 PDT
Created attachment 323117 [details]
Skipped the test on Windows
Comment 3 Darin Adler 2017-10-07 23:41:04 PDT
Comment on attachment 323117 [details]
Skipped the test on Windows

View in context: https://bugs.webkit.org/attachment.cgi?id=323117&action=review

> Source/WebCore/page/DragController.cpp:697
> +    if (!destinationOperation)
> +        operation = defaultOperationForDrag(sourceOperation);
> +    else if (!(sourceOperation & *destinationOperation)) // The element picked an operation which is not supported by the source
>          operation = DragOperationNone;
> -    }
> +    else
> +        operation = *destinationOperation;

Stylistic question about * vs. using the value() function on optionals. I almost always use the named function, but I am not sure it’s better.

> Source/WebCore/page/EventHandler.cpp:2277
> +bool EventHandler::dispatchDragEnterOrDragOverEvent(const AtomicString& eventType, Element& target, const PlatformMouseEvent& event,
> +    std::unique_ptr<Pasteboard>&& pasteborad, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)

Out arguments are kind of ugly. Sure would be nice if it could all be in the return value instead of a return value plus an out argument.

> Source/WebCore/page/EventHandler.cpp:2289
> +bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, std::function<std::unique_ptr<Pasteboard>()> makePasteboard, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)

Ditto.

Also, a std::function can be expensive to copy, so it would be nice if it was a const&, assuming it’s always called synchronously and not saved for later.
Comment 4 Wenson Hsieh 2017-10-08 00:17:24 PDT
Comment on attachment 323117 [details]
Skipped the test on Windows

View in context: https://bugs.webkit.org/attachment.cgi?id=323117&action=review

>> Source/WebCore/page/EventHandler.cpp:2277
>> +    std::unique_ptr<Pasteboard>&& pasteborad, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)
> 
> Out arguments are kind of ugly. Sure would be nice if it could all be in the return value instead of a return value plus an out argument.

Nit - "pasteborad" => "pasteboard"
Comment 5 Darin Adler 2017-10-08 00:22:29 PDT
$ git grep borad

Found this typo in ChangeLog, but not in any pre-existing code.
Comment 6 Ryosuke Niwa 2017-10-08 00:52:27 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 323117 [details]
> Skipped the test on Windows
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=323117&action=review
> 
> > Source/WebCore/page/DragController.cpp:697
> > +    if (!destinationOperation)
> > +        operation = defaultOperationForDrag(sourceOperation);
> > +    else if (!(sourceOperation & *destinationOperation)) // The element picked an operation which is not supported by the source
> >          operation = DragOperationNone;
> > -    }
> > +    else
> > +        operation = *destinationOperation;
> 
> Stylistic question about * vs. using the value() function on optionals. I
> almost always use the named function, but I am not sure it’s better.

Fixed to use .value().

> > Source/WebCore/page/EventHandler.cpp:2277
> > +bool EventHandler::dispatchDragEnterOrDragOverEvent(const AtomicString& eventType, Element& target, const PlatformMouseEvent& event,
> > +    std::unique_ptr<Pasteboard>&& pasteborad, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)
> 
> Out arguments are kind of ugly. Sure would be nice if it could all be in the
> return value instead of a return value plus an out argument.

Okay. I'm gonna add the following struct and make this function return that.

    struct DragTargetResponse {
        bool accept;
        std::optional<DragOperation> operation;
    };


> > Source/WebCore/page/EventHandler.cpp:2289
> > +bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, std::function<std::unique_ptr<Pasteboard>()> makePasteboard, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)
> 
> Ditto.
> 
> Also, a std::function can be expensive to copy, so it would be nice if it
> was a const&, assuming it’s always called synchronously and not saved for
> later.

Oops, that's a good catch. Fixed.
Comment 7 Ryosuke Niwa 2017-10-08 00:53:17 PDT
(In reply to Wenson Hsieh from comment #4)
> Comment on attachment 323117 [details]
> Skipped the test on Windows
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=323117&action=review
> 
> >> Source/WebCore/page/EventHandler.cpp:2277
> >> +    std::unique_ptr<Pasteboard>&& pasteborad, DragOperation sourceOperation, bool draggingFiles, std::optional<DragOperation>& destinationOperation)
> > 
> > Out arguments are kind of ugly. Sure would be nice if it could all be in the return value instead of a return value plus an out argument.
> 
> Nit - "pasteborad" => "pasteboard"

Fixed.
Comment 8 Ryosuke Niwa 2017-10-08 02:29:26 PDT
Created attachment 323132 [details]
Patch for landing
Comment 9 WebKit Commit Bot 2017-10-08 03:08:56 PDT
Comment on attachment 323132 [details]
Patch for landing

Clearing flags on attachment: 323132

Committed r223031: <http://trac.webkit.org/changeset/223031>
Comment 10 WebKit Commit Bot 2017-10-08 03:08:58 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2017-10-08 03:11:08 PDT
<rdar://problem/34875120>
Comment 12 Matt Lewis 2017-10-09 09:40:21 PDT
This patch caused a build break on windows:

https://build.webkit.org/builders/Apple%20Win%20Release%20%28Build%29/builds/5053
https://build.webkit.org/builders/Apple%20Win%20Release%20%28Build%29/builds/5053/steps/compile-webkit/logs/stdio

Error:

C:\cygwin\home\buildbot\slave\win-release\build\Source\WebCore\page\EventHandler.cpp(2285): error C2440: 'return': cannot convert from 'initializer list' to 'WebCore::EventHandler::DragTargetResponse' [C:\cygwin\home\buildbot\slave\win-release\build\WebKitBuild\Release\Source\WebCore\WebCore.vcxproj]
  C:\cygwin\home\buildbot\slave\win-release\build\Source\WebCore\page\EventHandler.cpp(2285): note: No constructor could take the source type, or constructor overload resolution was ambiguous

If this can't be addressed quickly, we will need to revert the patch.
Comment 13 Ryosuke Niwa 2017-10-09 11:55:16 PDT
Wenson fixed it in
https://trac.webkit.org/changeset/223050
https://trac.webkit.org/changeset/223054

Thanks, Wenson!