Bug 78855 - [chromium] On Android, allow right-click to select word.
Summary: [chromium] On Android, allow right-click to select word.
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oli Lan
URL:
Keywords:
Depends on:
Blocks: 66687
  Show dependency treegraph
 
Reported: 2012-02-16 15:57 PST by Oli Lan
Modified: 2012-05-09 10:55 PDT (History)
6 users (show)

See Also:


Attachments
Patch (2.83 KB, patch)
2012-02-16 16:01 PST, Oli Lan
eric: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oli Lan 2012-02-16 15:57:36 PST
[chromium] On Android, allow right-click to select word.
Comment 1 Oli Lan 2012-02-16 16:01:09 PST
Created attachment 127460 [details]
Patch
Comment 2 Eric Seidel (no email) 2012-02-16 16:06:07 PST
Comment on attachment 127460 [details]
Patch

Do you want to do this at the WebKit layer?  Or should this be the defaultEventHandler for block elements?
Comment 3 Eric Seidel (no email) 2012-02-16 16:07:24 PST
rniwa should be able to offer some thoughts as to where to impelement this behavior.

We implement double-click, triple-click in WebCore iirc, (word-based, and paragraph-based selection on Mac).
Comment 4 Eric Seidel (no email) 2012-02-16 16:08:11 PST
Comment on attachment 127460 [details]
Patch

I'm pretty sure this is not where you want this code to go.  I recommend asking rniwa in #webkit.  He'll have suggestions.  Darin Adler, and Enrica are also good people for Selection-related questions.
Comment 5 Tony Chang 2012-02-16 16:14:02 PST
See the shouldSelectOnContextualMenuClick() in editing/EditingBehavior.h and the code in EventHandler::sendContextMenuEvent that checks that value.
Comment 6 Ryosuke Niwa 2012-02-16 16:21:45 PST
What Tony said. The patch posted here doesn't look right.
Comment 7 Oli Lan 2012-02-16 17:21:09 PST
Thanks for the comments.

One reason that this was implemented this way is that when the selection occurs we don't want to generate a context menu. So it seemed like it wouldn't be right to call through to EventHandler's sendContextMenuEvent() when we don't want to send a context menu event, so I thought changes to mouseDown were necessary in order to not call mouseContextMenu.

I guess instead we could allow it to go through to sendContextMenuEvent, leverage the existing shouldSelectOnContextualMenuClick, and ignore or suppress the context menu event. How does that sound?
Comment 8 Eric Seidel (no email) 2012-02-16 17:26:00 PST
For better or worse, the web allows pages to disable text selection.  It's unclear to me if this implementation would still allow this.

In any case, it is my impression that this feature is well-trodden territory in WebCore.  I'm sorry I don't have the context to give you the exact lines of code to change, but you should be able to implement this very similarly to how double-click/tripple-click work.  I'm happy to do some code spelunking tomorrow to help you find the right hooks if they're not obvious from rniwa/tony's comment's above.
Comment 9 Oli Lan 2012-02-16 18:06:02 PST
Yes, I agree this should respect the page's request to disable selection. The original patch does attempt to do that, though it seems we need a new approach generally.

Implement similar to double/triple click: OK, so it sounds to me like that means the place to implement would be in EventHandler::handleMousePressEvent or EventHandler::handleMousePressEventSingleClick, using (a new) EditingBehavior to guard the new behaviour. Similar to how double-clicks work, we would use EventHandler::selectClosestWordFromMouseEvent to make the selection.

Better?
Comment 10 Tony Chang 2012-02-21 10:21:32 PST
(In reply to comment #7)
> 
> One reason that this was implemented this way is that when the selection occurs we don't want to generate a context menu. So it seemed like it wouldn't be right to call through to EventHandler's sendContextMenuEvent() when we don't want to send a context menu event, so I thought changes to mouseDown were necessary in order to not call mouseContextMenu.

Even though we're not going to show a context menu, don't we still need to fire the DOM event? That is, the web page should still see the event fired on a long click and be able to cancel it (which would prevent the selection from happening).

I tried this on Chrome on Android to see the behavior: a selection toolbar shows up instead of a context menu.  It might be better to put the logic for what to show in the showContextMenu callback in WebViewClient (i.e., sometimes show the context menu, sometimes show the selection toolbar).  Hopefully there's enough information in WebContextMenuData, or maybe you can add addition information there as needed.

I agree that it's a bit weird that showContextMenu doesn't show a context menu, but I think we do want to trigger this behavior off of the context menu event succeeding.  Maybe we could rename the callback.
Comment 11 Oli Lan 2012-02-21 10:41:25 PST
> That is, the web page should still see the event fired on a long click and be able to cancel it (which would prevent the selection from happening).

It doesn't seem right to me that a page that wants to disallow context menus would also disallow selection if we did it this way. 'Longpress to select' on Android is the equivalent of dragging to select on other platforms - it's not the equivalent of pulling up a context menu. If a page wants to disallow selection, I'd have thought that using something like -webkit-user-select would make more sense.

My new suggested approach as in my previous comment is that we implement this in EventHandler::handleMousePressEventSingleClick, so that this becomes a new behaviour associated with a right-click. WebViewImpl::mouseDown can still fire a context menu event, and on the browser side we will ignore it if it is from a selection.

How does that sound?
Comment 12 Ryosuke Niwa 2012-02-21 11:08:47 PST
(In reply to comment #10)
> (In reply to comment #7)
> > 
> > One reason that this was implemented this way is that when the selection occurs we don't want to generate a context menu. So it seemed like it wouldn't be right to call through to EventHandler's sendContextMenuEvent() when we don't want to send a context menu event, so I thought changes to mouseDown were necessary in order to not call mouseContextMenu.
> 
> Even though we're not going to show a context menu, don't we still need to fire the DOM event? That is, the web page should still see the event fired on a long click and be able to cancel it (which would prevent the selection from happening).

You mean contextmenu event? I don't think we should be firing that event unless we're intending to show a context menu. Any web sites that want to cancel selection would be able to do so by canceling selectstart so this shouldn't be an issue for them.

Furthermore, this may result in websites showing its own contextmenu after canceling the event, which would be inconsistent with the platform convention.

http://www.w3.org/TR/html5/interactive-elements.html#context-menus
*If the user requested a context menu using a pointing device*
The user agent must dispatch an event with the name contextmenu...

Clearly, the user would never request a contextmenu on Android. I'll also note that we should check Safari's behavior on iOS.

(In reply to comment #11)
> > That is, the web page should still see the event fired on a long click and be able to cancel it (which would prevent the selection from happening).
> 
> It doesn't seem right to me that a page that wants to disallow context menus would also disallow selection if we did it this way. 'Longpress to select' on Android is the equivalent of dragging to select on other platforms - it's not the equivalent of pulling up a context menu. If a page wants to disallow selection, I'd have thought that using something like -webkit-user-select would make more sense.
> 
> My new suggested approach as in my previous comment is that we implement this in EventHandler::handleMousePressEventSingleClick, so that this becomes a new behaviour associated with a right-click. WebViewImpl::mouseDown can still fire a context menu event, and on the browser side we will ignore it if it is from a selection.

I don't think we should fire a contextmenu event if we're not intending to show contextmenu.
Comment 13 Tony Chang 2012-02-21 12:14:47 PST
My line of thinking was that a page might want to disable all longpress events, but on Android, that action is sometimes a contextmenu event and sometimes a text selection event.  Disabling the single event requires knowing to handle both cases.

Maybe this is already possible by just grabbing the mouse down event and checking the button?
Comment 14 Oli Lan 2012-02-23 04:28:23 PST
> Maybe this is already possible by just grabbing the mouse down event and checking the button?

That's what my original patch does, isn't it? What we've just discussed is basically the motivation for that approach - checking in WebViewImpl::mouseDown for a right mouse click and performing a selection instead of sending a context menu event.
Comment 15 Tony Chang 2012-02-23 10:14:47 PST
(In reply to comment #14)
> > Maybe this is already possible by just grabbing the mouse down event and checking the button?
> 
> That's what my original patch does, isn't it? What we've just discussed is basically the motivation for that approach - checking in WebViewImpl::mouseDown for a right mouse click and performing a selection instead of sending a context menu event.

Sorry, I was asking if this code runs before or after the javascript event for the mouse down is run on the page.  I.e., is it possible for a page to cancel text selection by canceling the mouse down event.

Also, what happens if the user cancels the select start event?  Does it show a context menu?
Comment 16 Adam Barth 2012-05-08 22:42:16 PDT
This patch appears to be stalled.  What do we need to do to make progress here.  Oli, do you have thoughts on Tony's questions in Comment #15 ?
Comment 17 Oli Lan 2012-05-09 02:33:10 PDT
I've been taking another look at this, and I now think the approach originally proposed of having right-click perform selection is not ideal. Instead, I think this would make more sense as part of gesture handling, meaning most of the change would move to a GestureLongPress handler within handleInputEvent. That should avoid any troublesome interactions with context menus or mousedown events.

Does that sound reasonable?
Comment 18 Adam Barth 2012-05-09 08:40:25 PDT
> Does that sound reasonable?

Other folks might have opinions, but that seems like a reasonable approach to me.  Thanks.
Comment 19 Tony Chang 2012-05-09 10:20:16 PDT
Sounds fine to me too.  Should we obsolete this bug?
Comment 20 Oli Lan 2012-05-09 10:55:38 PDT
Yes, this can be closed now. Thanks for the reviews.