Bug 155390

Summary: eventMayStartDrag() does not check for shiftKey or isOverLink
Product: WebKit Reporter: Antonio Gomes <tonikitoo>
Component: UI EventsAssignee: Antonio Gomes <tonikitoo>
Status: RESOLVED WONTFIX    
Severity: Normal CC: achristensen, commit-queue, darin, dbates, enrica
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 155314    
Attachments:
Description Flags
Patch v2.1
none
Patch v1.
none
Patch v1.1 - fix iOS build.
none
Patch v1.2 - fix iOS build.
darin: review+
Patch for landing.
none
Patch for landing. none

Description Antonio Gomes 2016-03-12 05:50:32 PST
This is a follow up of Darin's comment in https://bugs.webkit.org/show_bug.cgi?id=155314#c9.

Basically in bug 155314, in order to make shift+click not trigger drag-n-drop when extending an existing selection, we changed the way m_mouseDownMayStartDrag is set on EventHandler::handleMousePressEvent, as shown below:

-    m_mouseDownMayStartDrag = singleClick;
+    m_mouseDownMayStartDrag = singleClick && (!event.event().shiftKey() || event.isOverLink());

Although makes a desired change in WebKit's editing behavior (as per [1] and [2]), it makes this setter code get out of sync with eventMayStartDrag.

Bug is about investigating the implications, and sync both pieces up again.

[1] https://bugs.webkit.org/show_bug.cgi?id=155314#c4
[2] https://bugs.webkit.org/show_bug.cgi?id=155314#c8
Comment 1 Antonio Gomes 2016-03-12 05:53:13 PST
Relevant commit:

commit ad24ce63d491cafd164c9a233aef4b7ad6deedba
Author: enrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 12 23:51:59 2011 +0000

    Implement non-activating clicks to allow dragging out of a background window.
    https://bugs.webkit.org/show_bug.cgi?id=55053
    <rdar://problem/9042197>
    
    Source/WebCore: (...)
Comment 2 Antonio Gomes 2016-03-13 07:41:26 PDT
Created attachment 273892 [details]
Patch v2.1

Proper expected results.
Comment 3 Antonio Gomes 2016-03-30 11:48:56 PDT
Created attachment 275206 [details]
Patch v1.
Comment 4 Antonio Gomes 2016-03-30 12:07:12 PDT
Created attachment 275207 [details]
Patch v1.1 - fix iOS build.
Comment 5 Antonio Gomes 2016-03-30 21:43:18 PDT
Created attachment 275265 [details]
Patch v1.2 - fix iOS build.
Comment 6 Darin Adler 2016-03-31 08:49:11 PDT
Comment on attachment 275265 [details]
Patch v1.2 - fix iOS build.

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

> Source/WebCore/page/EventHandler.cpp:741
> +static bool checkMouseEventPrerequisitesForTriggerDragging(const MouseEventWithHitTestResults& event)

It’s not good to have a function that returns a boolean be named with the verb "check". I think this should be named "eventShouldTriggerDragging".

> Source/WebCore/page/EventHandler.cpp:743
> +    PlatformMouseEvent platformEvent = event.event();

I don’t think we want to copy the platform event here. If event() returns a reference then we should put the result into a reference and not copy it. I’d use the type auto&.

I kind of hate the word platform in the name of this local variable.

> Source/WebCore/page/EventHandler.cpp:747
> +    // Single mouse down on links or images can always trigger drag-n-drop.

It’s a little strange to have the words "single mouse down" here *after* the code that checks for single mouse down. It would be nicer to have the code say what the comment says. That could mean, for example, a helper function called isSingleMouseDownOnLinkOrImage. The words used in the comment are often a clue to what great names for the actual code would be.
Comment 7 Antonio Gomes 2016-03-31 11:06:25 PDT
Created attachment 275301 [details]
Patch for landing.
Comment 8 WebKit Commit Bot 2016-03-31 11:07:57 PDT
Attachment 275301 [details] did not pass style-queue:


ERROR: Source/WebCore/page/EventHandler.cpp:752:  Extra space before last semicolon. If this should be an empty statement, use { } instead.  [whitespace/semicolon] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Antonio Gomes 2016-03-31 11:12:48 PDT
Created attachment 275302 [details]
Patch for landing.
Comment 10 WebKit Commit Bot 2016-03-31 12:25:43 PDT
Comment on attachment 275302 [details]
Patch for landing.

Clearing flags on attachment: 275302

Committed r198909: <http://trac.webkit.org/changeset/198909>
Comment 11 WebKit Commit Bot 2016-03-31 12:25:48 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Alex Christensen 2016-04-11 16:18:35 PDT
This was reopened because it was rolled out in http://trac.webkit.org/changeset/199317
When double-clicking and dragging text to highlight (such as on this very bugzilla page), this patch made it so we would drag the text instead of highlighting more.
Comment 13 Darin Adler 2016-04-11 17:14:07 PDT
Before landing this again we should make a test case for the "double click and drag" case.
Comment 14 Antonio Gomes 2016-04-11 21:05:52 PDT
(In reply to comment #12)
> This was reopened because it was rolled out in
> http://trac.webkit.org/changeset/199317
> When double-clicking and dragging text to highlight (such as on this very
> bugzilla page), this patch made it so we would drag the text instead of
> highlighting more.

Easily reproducible here too.

I will make sure new patch will be accompanied by a layout test for the double click + drag = select (not drag'n drop) case.
Comment 15 Antonio Gomes 2016-04-15 10:38:31 PDT
Prior to bug 155314, the "can event start drag" logic in  EventHandler::handleMousePressEvent was not taking links and images explicitly into account. We fixed this as part of bug 155314, by making it an explicit check and adding tests.

Then, we filed this bug here (bug 155390) to pair up the logics EventHandler::handleMousePressEvent and EventHandler::eventMayStartDrag with regards to taking images and links into account to start dragging.

The point is, after understanding the situation a bit better...

By the time bug 155314 was fixed, we actually did pair up the logic in EventHandler::handleMousePressEvent and EventHandler::eventMayStartDrag.
This is because the ::eventMayStartDrag already calls DragController::draggableElement which does take links and images into account to trigger dragging.

Last, about the 'shiftKey' check that happens in EventHandler::eventMayStartDrag but does not happen in EventHandler::eventMayStartDrag, IMO it does not make sense for now to add it to the later, because of the how/why ::eventMayStartDrag method is used.

Current ::eventMayStartDrag is called by WebPage (see Source/WebKit2//WebProcess/WebPage/mac/WebPageMac.mm) in order to delay bringing a background host window foreground. It currently only affects dragging a selected content, and I do not think this bug should change this behavior.

I believe this bug is non-actionable. Thus, WONTFIX.