Bug 1805341 Comment 18 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Thanks for your help, :botond.

I found that desktop version also complains about this when getting [refererrInfo](https://searchfox.org/mozilla-central/source/browser/actors/ContextMenuChild.sys.mjs#600) .

```
JavaScript error: resource:///actors/ContextMenuChild.sys.mjs, line 600: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIReferrerInfo.initWithElement]
```

--------------------------------

After modifying like this in `dom/events/EventStateManager.cpp`, Fenix and Desktop could trigger context menu.
```diff
@@ -2121,8 +2133,14 @@ void EventStateManager::FireContextClick() {
       AutoHandlingUserInputStatePusher userInpStatePusher(true, &event);
 
       // dispatch to DOM
-      RefPtr<nsIContent> gestureDownContent = mGestureDownContent;
+      nsIContent* targetEvent = mGestureDownContent;
+      while (targetEvent && !targetEvent->IsElement()) {
+        targetEvent = targetEvent->GetFlattenedTreeParent();
+      }
+
+      RefPtr<nsIContent> gestureDownContent = targetEvent;
       RefPtr<nsPresContext> presContext = mPresContext;
```

----------

However there's a problem.

In Fenix, if i `mousedown` on the link and hold , the contextmenu will show,  and then when i don't move mouse and then `mouseup` on the link , then navigating to the link will happens.  If i move mouse out of the link then `mouseup`, this won't happen.

In desktop this won't happen.

I'm not sure if this is intentional .
Thanks for your help, :botond.

I found that desktop version also complains about this when getting [refererrInfo](https://searchfox.org/mozilla-central/source/browser/actors/ContextMenuChild.sys.mjs#600) .

```
JavaScript error: resource:///actors/ContextMenuChild.sys.mjs, line 600: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIReferrerInfo.initWithElement]
```

--------------------------------

After modifying like this in `dom/events/EventStateManager.cpp`, Fenix and Desktop could trigger context menu.
```diff
@@ -2121,8 +2133,14 @@ void EventStateManager::FireContextClick() {
       AutoHandlingUserInputStatePusher userInpStatePusher(true, &event);
 
       // dispatch to DOM
-      RefPtr<nsIContent> gestureDownContent = mGestureDownContent;
+      nsIContent* targetEvent = mGestureDownContent;
+      while (targetEvent && !targetEvent->IsElement()) {
+        targetEvent = targetEvent->GetFlattenedTreeParent();
+      }
+
+      RefPtr<nsIContent> gestureDownContent = targetEvent;
       RefPtr<nsPresContext> presContext = mPresContext;
```

----------

However there's a problem.

In Fenix, if i `mousedown` on the link and hold , the contextmenu will show,  and then when i don't move mouse and then `mouseup` on the link , then navigating to the link will happens.  If i move mouse out of the link then `mouseup`, this won't happen.

In desktop this won't happen.

I'm not sure if this is intentional .


------
Update:
It looks desktop won't dispatch "mouseup" event  (so "click" won't be dispatched too).
I think this is not correct too :( 
"mouseup" event should be dispatched, "click" should be prevented.
Thanks for your help, :botond.

I found that desktop version also complains about this when getting [refererrInfo](https://searchfox.org/mozilla-central/source/browser/actors/ContextMenuChild.sys.mjs#600) .

```
JavaScript error: resource:///actors/ContextMenuChild.sys.mjs, line 600: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIReferrerInfo.initWithElement]
```

--------------------------------

After modifying like this in `dom/events/EventStateManager.cpp`, Fenix and Desktop could trigger context menu.
```diff
@@ -2121,8 +2133,14 @@ void EventStateManager::FireContextClick() {
       AutoHandlingUserInputStatePusher userInpStatePusher(true, &event);
 
       // dispatch to DOM
-      RefPtr<nsIContent> gestureDownContent = mGestureDownContent;
+      nsIContent* targetEvent = mGestureDownContent;
+      while (targetEvent && !targetEvent->IsElement()) {
+        targetEvent = targetEvent->GetFlattenedTreeParent();
+      }
+
+      RefPtr<nsIContent> gestureDownContent = targetEvent;
       RefPtr<nsPresContext> presContext = mPresContext;
```

----------

However there's a problem.

In Fenix, if i `mousedown` on the link and hold , the contextmenu will show,  and then when i don't move mouse and then `mouseup` on the link , then navigating to the link will happens.  If i move mouse out of the link then `mouseup`, this won't happen.

In desktop this won't happen.

I'm not sure if this is intentional .


------
Update:
It looks desktop won't dispatch "mouseup" event when contextmenu shown and mouse up. (so "click" won't be dispatched too).
I think this is not correct too :( 
"mouseup" event should be dispatched, "click" should be prevented.

Further investigate on Desktop, When contextmenu shown, mouse down then mouse up in the area beside the target and the menu, then only one "mouseup" event will dispatched (no mousedown event ) .

Back to Bug 1805341 Comment 18