Bug 1431255 - Part VI, Redirect target in ContextMenu.jsm to HTMLMediaElement draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Fri, 06 Jul 2018 13:26:59 +0800
changeset 829411 f6add5c8ca965242271523e7188f0e4e7cf15704
parent 829410 331b637785390c0b82582685bc635aae1e3a60fb
child 829412 ae88953d15d97c5b9fe6693cf14c59a3a2f3919a
push id118779
push usertimdream@gmail.com
push dateWed, 15 Aug 2018 23:50:47 +0000
bugs1431255
milestone63.0a1
Bug 1431255 - Part VI, Redirect target in ContextMenu.jsm to HTMLMediaElement Set the referenced node to that of the containing media element so related menu items will be shown in the context menu. MozReview-Commit-ID: 4BKlINHmTSb
browser/actors/ContextMenuChild.jsm
--- a/browser/actors/ContextMenuChild.jsm
+++ b/browser/actors/ContextMenuChild.jsm
@@ -686,17 +686,33 @@ class ContextMenuChild extends ActorChil
     this.context = Object.create(null);
     const context = this.context;
 
     context.timeStamp = aEvent.timeStamp;
     context.screenX = aEvent.screenX;
     context.screenY = aEvent.screenY;
     context.mozInputSource = aEvent.mozInputSource;
 
-    const node = aEvent.composedTarget;
+    let node = aEvent.composedTarget;
+
+    // Set the node to containing <video>/<audio> if the node
+    // is in the videocontrols UA Widget.
+    if (this.content.ShadowRoot) {
+      let n = node;
+      while (n) {
+        if (n instanceof this.content.ShadowRoot) {
+          if (n.host instanceof this.content.HTMLMediaElement) {
+            node = n.host;
+            break;
+          }
+          break;
+        }
+        n = n.parentNode;
+      }
+    }
 
     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
     context.shouldDisplay = true;
 
     if (node.nodeType == node.DOCUMENT_NODE ||
         // Don't display for XUL element unless <label class="text-link">
         (node.namespaceURI == XUL_NS && !this._isXULTextLinkLabel(node))) {