[Pkg-mozext-commits] [firegestures] 08/13: display context menu by nsIDOMWindowUtils

David Prévot taffit at moszumanska.debian.org
Thu Jan 1 18:34:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository firegestures.

commit 20cf9b0a1e2253cf5e93de7510c96e1b1217470b
Author: Gomita <gomita at xuldev.org>
Date:   Sun Dec 28 03:47:24 2014 +0900

    display context menu by nsIDOMWindowUtils
---
 chrome/content/firegestures/remote.js | 15 ------------
 components/xdGestureHandler.js        | 44 +++++++----------------------------
 2 files changed, 8 insertions(+), 51 deletions(-)

diff --git a/chrome/content/firegestures/remote.js b/chrome/content/firegestures/remote.js
index 209c4f0..a8985d3 100644
--- a/chrome/content/firegestures/remote.js
+++ b/chrome/content/firegestures/remote.js
@@ -23,7 +23,6 @@ let FireGesturesRemote = {
 		addMessageListener("FireGestures:KeypressStart", this);
 		addMessageListener("FireGestures:KeypressProgress", this);
 		addMessageListener("FireGestures:KeypressStop", this);
-		addMessageListener("FireGestures:ContextMenu", this);
 		addMessageListener("FireGestures:DoCommand", this);
 		addMessageListener("FireGestures:SendKeyEvent", this);
 		addMessageListener("FireGestures:CreateTrail", this);
@@ -38,7 +37,6 @@ let FireGesturesRemote = {
 			case "FireGestures:KeypressStart"   : this._onKeypressStart(); break;
 			case "FireGestures:KeypressProgress": this._onKeypressProgress(aMsg.data); break;
 			case "FireGestures:KeypressStop"    : this._onKeypressStop(); break;
-			case "FireGestures:ContextMenu" : this._displayContextMenu(aMsg.data); break;
 			case "FireGestures:DoCommand"   : this._doCommand(aMsg.data); break;
 			case "FireGestures:SendKeyEvent": this._sendKeyEvent(aMsg.data); break;
 			case "FireGestures:CreateTrail" : this._createTrail(aMsg.data); break;
@@ -148,19 +146,6 @@ let FireGesturesRemote = {
 
 	/* ::::: Commands ::::: */
 
-	_displayContextMenu: function FGR__displayContextMenu(aData) {
-		// log("_displayContextMenu: " + aData.toSource());	// #debug
-		let { doc: doc, elt: elt, x: x, y: y } = this._elementFromPoint(aData.x, aData.y);
-		// open the context menu artificially
-		let evt = doc.createEvent("MouseEvents");
-		evt.initMouseEvent(
-			"contextmenu", true, true, doc.defaultView, 0,
-			aData.x, aData.y, x, y,
-			false, false, false, false, 2, null
-		);
-		elt.dispatchEvent(evt);
-	},
-
 	_doCommand: function FGR__doCommand(aData) {
 		if (docShell.isCommandEnabled(aData.cmd))
 			docShell.doCommand(aData.cmd);
diff --git a/components/xdGestureHandler.js b/components/xdGestureHandler.js
index 750ee74..0d5cf59 100644
--- a/components/xdGestureHandler.js
+++ b/components/xdGestureHandler.js
@@ -312,7 +312,14 @@ xdGestureHandler.prototype = {
 					// [Linux][Mac] display context menu artificially
 					if (this._shouldFireContext) {
 						this._shouldFireContext = false;
-						this._displayContextMenu(event);
+						this._enableContextMenu(true);
+						// synthesize contextmenu event by nsIDOMWindowUtils
+						var win = this._drawArea.ownerDocument.defaultView;
+						var x = event.screenX - win.document.documentElement.boxObject.screenX;
+						var y = event.screenY - win.document.documentElement.boxObject.screenY;
+						win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).
+						    sendMouseEvent("contextmenu", x, y, 2, 1, null);
+						log("*** synthesize contextmenu event (" + x + ", " + y + ")");	// #debug
 					}
 				}
 				break;
@@ -320,7 +327,6 @@ xdGestureHandler.prototype = {
 				// [Linux] if right-click without holding left-button, display context menu artificially
 				if (!this._isMouseDownL && this._isMouseDownR) {
 					// #debug-begin
-					log("*** display context menu artificially");
 					if (PLATFORM == "Windows_NT")
 						alert("Assertion failed!\ndisplay context menu artificially");
 					// #debug-end
@@ -430,40 +436,6 @@ xdGestureHandler.prototype = {
 		return this._suppressAlt ? event.altKey : false;
 	},
 
-	_displayContextMenu: function FGH__displayContextMenu(event) {
-		if ("nsContextMenu" in this._drawArea.ownerDocument.defaultView) {
-			// this fixes the problem: the list of alternative words doesn't display in the context menu
-			// when right-clicking on a misspelled word, because of a wrong value of |document.popupRangeOffset|.
-			with (this._drawArea.ownerDocument.defaultView) {
-				if (!nsContextMenu.prototype._setTargetInternal) {
-					nsContextMenu.prototype._setTargetInternal = nsContextMenu.prototype.setTarget;
-					nsContextMenu.prototype.setTarget = function(aNode, aRangeParent, aRangeOffset) {
-						this._setTargetInternal(aNode, aRangeParent, this._rangeOffset);
-					};
-					log("*** REPLACED nsContextMenu.prototype.setTarget");	// #debug
-				}
-				nsContextMenu.prototype._rangeOffset = event.rangeOffset;
-			}
-		}
-		this._enableContextMenu(true);
-		if (this._isRemote) {
-			// [e10s] display context menu on remote browser
-			this._gestureObserver.sendAsyncMessage("FireGestures:ContextMenu", {
-				x: event.screenX - this._drawArea.mCurrentBrowser.boxObject.screenX, 
-				y: event.screenY - this._drawArea.mCurrentBrowser.boxObject.screenY, 
-			});
-			return;
-		}
-		// open the context menu artificially
-		var evt = event.originalTarget.ownerDocument.createEvent("MouseEvents");
-		evt.initMouseEvent(
-			"contextmenu", true, true, event.originalTarget.ownerDocument.defaultView, 0,
-			event.screenX, event.screenY, event.clientX, event.clientY,
-			false, false, false, false, 2, null
-		);
-		event.originalTarget.dispatchEvent(evt);
-	},
-
 	_enableContextMenu: function FGH__enableContextMenu(aEnable) {
 		// If 'dom.event.contextmenu.enabled' is false,
 		// there is a problem that context menu is not suppressed

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firegestures.git



More information about the Pkg-mozext-commits mailing list