Closed Bug 1879701 Opened 8 months ago Closed 2 months ago

Show text selection context menu when mouse right click on the selected text

Categories

(GeckoView :: General, enhancement, P1)

All
Android
enhancement

Tracking

(firefox131 verified)

VERIFIED FIXED
131 Branch
Tracking Status
firefox131 --- verified

People

(Reporter: jackyzy823, Assigned: m_kato)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fxdroid])

Attachments

(5 files)

STR

  1. Select text range using mouse
  2. Right click the mouse on the selected text area

Expected:

The text selection toolbar shows (just like Chrome)

Actual:

Nothing happens.

If bug 1757352 implemented , we could also 1) do something in https://searchfox.org/mozilla-central/rev/9013524d23da6523a7ec4479b5682407a1323f6c/mobile/android/actors/ContentDelegateChild.sys.mjs#39 (such as check if there's text selection then showActionMode ) or 2) let SelectionActionDelegateChild listening on contextmenu event too ?

Blocks: 1894348

Following up on this, in option 1, do you know of a way to check for selected text with elementType or nearestParentAttribute?

For option 2, to me it looks like SelectionActionDelegateChild makes actions on the accessibility caret, whereas maybe the BasicSelectionActionDelegate is calling (onCreateActionMode)[https://searchfox.org/mozilla-central/rev/21823adb7d8117239b7021fa5997d3234369568a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/BasicSelectionActionDelegate.java#338] to actually creation and prepare the actions for selection. I'm not sure how onCreateActionMode gets called though. It works for long presses and needs to work for right clicks.

Flags: needinfo?(jackyzy823)

Hi

1, do you know of a way to check for selected text with elementType or nearestParentAttribute?

I'm not sure if i understood the question. I think it is no, the event target won't be text node. so there's no info about the selected text range. (unlike mozcaretstatechanged event)

[0] l learned from here https://bugzilla.mozilla.org/show_bug.cgi?id=1805341#c16
[1] https://searchfox.org/mozilla-central/source/layout/base/PresShell.cpp#12071-12083

I'm not sure how onCreateActionMode gets called though. It works for long presses and needs to work for right clicks.

Some calling chain:
[0] Child dispatch ShowSelectionAction to parent https://searchfox.org/mozilla-central/source/mobile/android/actors/SelectionActionDelegateChild.sys.mjs#389
[1] parent dispatch GeckoView:ShowSelectionAction to Geckoview https://searchfox.org/mozilla-central/rev/21823adb7d8117239b7021fa5997d3234369568a/mobile/shared/actors/SelectionActionDelegateParent.sys.mjs#50
[2] https://searchfox.org/mozilla-central/rev/21823adb7d8117239b7021fa5997d3234369568a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java#1152-1159
[3] Callback interface like onCreateActionMode for action modes Supplied to View#startActionMode(Callback) https://searchfox.org/mozilla-central/rev/21823adb7d8117239b7021fa5997d3234369568a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/BasicSelectionActionDelegate.java#477-501
[4] https://developer.android.com/reference/android/view/ActionMode.Callback

Flags: needinfo?(jackyzy823)

If possible, we should handle it on Gecko side.

Gotcha, thanks for providing the callback documentation for ActionMode, sounds like we'll need to update SelectionActionDelegateChild to include right clicks. It looks like "longpressonemptycontent", "releasecaret", "taponcaret", "updateposition" (https://searchfox.org/mozilla-central/rev/a44891c52387ca4bd7c35b50f0d335f3980ef36a/mobile/shared/actors/SelectionActionDelegateChild.sys.mjs#330-389) already starts the action menu. Is there an event we can add for right click, is that something the DOM selection team can help add on the Gecko side? (Tagging mcrr8, triage owner of the Dom selection team).

Flags: needinfo?(continuation)

Notes from today's pairing session with Cathy

Do we need to add events for a right click to start the existing action mode call chain?

potential events that deal with highlights
"longpressonemptycontent",
"releasecaret",
"taponcaret",
"updateposition",

We have found:

  • Where the right click gesture lives in Gecko
  • Where the right click is being handled for contextual menu in Gecko
  • Where the highlight call happens (selection action delegate) (moz caret state changed?)

We tested that Chrome does not do anything for right clickingon text; it only shows a contextual menu for right clicking on highlighted text.

Next time todo:

  • Figure out logging in CPP files
  • Should the right click trigger the action menu or should it reveal a contextual menu with the same expected actions?
  • Figure out how to either: propagate the right click to action mode OR show a contextual menu on highlighted with the same actions in Action Mode

I don't know who might be available to work on Selection. Maybe Hsin-Yi can provide some suggestions.

Flags: needinfo?(continuation) → needinfo?(htsai)

According to the discussion with Masayuki, the root cause here is that we don't support mouse input on mobile formally/by default. We agreed with makoto-san’s comment 5; ideally we should handle this on Gecko. We need thorough audits and tests to support the mouse input properly, and based on our best educated guess, this may not be easy tweaks. I will have to take this to our planning backlog.

In the meanwhile, I know that Makoto-san has more recent experiences in handling ui events on mobile. Please feel free to chime in to point us where the gecko change may be (looks like this?) or correct me. Thanks!

Flags: needinfo?(htsai)

Looking desktop implementation. contextmenu for text selection handles on browser side, not Gecko (and toolkit).

ContextMenu actor handles contextmenu event then use XUL popup via nsContextMenu. Also, on some situation, contextmenu handles by moz-input-box.js for input type=text or textarea.

Actually, we get a selected text, linked title and etc via SelectionUtils.sys.mjs. If contextmenu's event (MouseEvent) have some extra information (that is got from SelectionUtils now) in chrome only member, it may be more easy to implement this for non-Firefox desktop. But I guess that adding code isn't large even if we implement mobile only handler for contextmenu.

At least, it may be better to split contextmenu actor from ContentDelegate actor, like desktop's, or handle this event by SelectionActionDelegate actor too. And if we re-use desktop code, we add more common module or into SelectionUtils.

(Also, we need to re-check contextmenu event on mobile whether this is by mouse event or touch event).

Assignee: nobody → m_kato

Hey Makoto, thanks for assigning yourself to this.

Sounds like desktop already uses SelectionUtils.getSelectionDetails and passes that data as part of "contextmenu" event. Is that how mobile "contextmenu" event gets it or where does this event come from?

Additionally, Jackyzy mentioned in c1, setting layout.accessiblecaret.hide_carets_for_mouse_input to false could give the same behavior. Can you test this preference?

(In reply to Cathy Lu [:calu] from comment #12)

Hey Makoto, thanks for assigning yourself to this.

Sounds like desktop already uses SelectionUtils.getSelectionDetails and passes that data as part of "contextmenu" event. Is that how mobile "contextmenu" event gets it or where does this event come from?

We already dispatch contextmenu event by right mouse click (or long click by left button when by preference). Actually ContentDelegate actor handles this event to call GeckoView APIs for browser application.

Additionally, Jackyzy mentioned in c1, setting layout.accessiblecaret.hide_carets_for_mouse_input to false could give the same behavior. Can you test this preference?

Not related for this. Simply, we can open action menu if there is selected item. Current implementation of action menu depended on accessible caret events.

With "layout.accessiblecaret.hide_carets_for_mouse_input" , the action mode show automatically when left mouse mouseup after text range selection.

Take chrome's behavior as a reference.

Gotcha, thanks for the clarification. Also updated the title of the bug to open contextmenu and not action mode, based on product decision.

Summary: Show text selection menu when mouse right click on the selected text → Show text selection context menu when mouse right click on the selected text
Severity: -- → N/A
Priority: -- → P1
Whiteboard: [fxdroid]

Makoto, what do you think the targeted release is for this? Do you have an idea?

Flags: needinfo?(m_kato)

(In reply to Cathy Lu [:calu] from comment #18)

Makoto, what do you think the targeted release is for this? Do you have an idea?

I hope next train (129).

Flags: needinfo?(m_kato)

Actually, no way to detect whether contextmenu is by mouse or touch (long tap) since event.buttons value is same value (although Chrome is different). If C++ code, we will be able to get event source type. APZ caller sets button is 2, and WidgetMouseEvent's ContextMenuTrigger doesn't have long tap type.

But dom side will change event type for contextmenu by Bug 1675847, so after it, we can detect whether touch or mouse for contextmenu.

Thanks for the update, looks like the dependent patch has merged and context menu now specifies the input source.

Whiteboard: [fxdroid] → [fxdroid][geckoview:2024H2?]
Whiteboard: [fxdroid][geckoview:2024H2?] → [fxdroid]

When contextmenu event is fired by mouse and the selection of active element
isn't collapsed, we should show action menu instead of context menu.

Actually, action menu depends on accessible caret event, so I emulate this
event to handle action menu. Also, focus or selection for active element is
changed, action menu should be dismissed.

Desktop's Gecko uses some JavaScript modules for handling context menu, so
we also use it.

Attachment #9416307 - Attachment description: WIP: Bug 1879701 - Show action menu when contextmenu is dispatched by mouse. r=#geckoview-reviewers → Bug 1879701 - Show action menu when contextmenu is dispatched by mouse. r=#geckoview-reviewers
Pushed by m_kato@ga2.so-net.ne.jp: https://hg.mozilla.org/integration/autoland/rev/c8b5acde34f8 Show action menu when contextmenu is dispatched by mouse. r=geckoview-reviewers,calu
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 131 Branch

Hey QA, can you verify this fix that right clicking with a tablet mouse on tablets for selected text pulls up the action mode context mode?
Thanks!

Flags: qe-verify+
Attached image 1723017774146.JPEG

Verified as fixed on the latest Nightly 131.0a1 from 08/07 with Samsung Tab S8 Ultra 5G (Android 14) and an external mouse connected. The action menu is displayed after right clicking the selected text.
We've also verified that the "Context_menu" events are correctly sent here.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: