[Pkg-mozext-commits] [firegestures] 02/18: 'Search for selection' now works on textarea
David Prévot
taffit at moszumanska.debian.org
Sat May 23 10:58:41 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 607ed40834dba183c6a87d568044ea9fbbc58751
Author: Gomita <gomita at xuldev.org>
Date: Tue May 12 01:17:33 2015 +0900
'Search for selection' now works on textarea
---
chrome/content/firegestures/browser.js | 13 +++++++++++--
chrome/content/firegestures/remote.js | 28 +++++++++++++++++++++-------
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/chrome/content/firegestures/browser.js b/chrome/content/firegestures/browser.js
index f585a1e..a33c62d 100644
--- a/chrome/content/firegestures/browser.js
+++ b/chrome/content/firegestures/browser.js
@@ -81,7 +81,7 @@ var FireGestures = {
case "sourceNode":
// replace |sourceNode| of gesture handler by CPOW object
this._gestureHandler.sourceNode = aMsg.objects.elt;
- this._selectedText = aMsg.objects.elt.ownerDocument.getSelection().toString();
+ this._selectedText = aMsg.objects.sel;
break;
case "linkURLs":
this._linkURLs = aMsg.data.linkURLs;
@@ -664,10 +664,19 @@ var FireGestures = {
_selectedText: null,
getSelectedText: function() {
+ // [e10s]
if (this.isRemote) {
return this._selectedText;
}
- return this.focusedWindow.getSelection().toString();
+ var [elt, win] = BrowserUtils.getFocusSync(document);
+ var sel = win.getSelection().toString();
+ if (!sel && elt instanceof Ci.nsIDOMNSEditableElement) {
+ if (elt instanceof Ci.nsIDOMHTMLTextAreaElement ||
+ (elt instanceof Ci.nsIDOMHTMLInputElement && elt.mozIsTextField(true))) {
+ sel = elt.editor.selection.toString();
+ }
+ }
+ return sel;
},
gatherLinkURLsInSelection: function() {
diff --git a/chrome/content/firegestures/remote.js b/chrome/content/firegestures/remote.js
index 2e8379c..c3309a5 100644
--- a/chrome/content/firegestures/remote.js
+++ b/chrome/content/firegestures/remote.js
@@ -58,7 +58,7 @@ let FireGesturesRemote = {
log("onStartGesture: " + aData.toSource()); // #debug
this._startX = aData.x;
this._startY = aData.y;
- let { doc: doc, elt: elt } = this._elementFromPoint(aData.x, aData.y);
+ let { doc, elt } = this._elementFromPoint(aData.x, aData.y);
if (aData.type != "MozSwipeGesture" && aData.button == 0) {
// cancel starting gesture on form elements
let localName = elt.localName;
@@ -77,16 +77,30 @@ let FireGesturesRemote = {
win.setTimeout(function() { sel.removeAllRanges(); }, 10);
}
// tell parent browser the source node and some info
- sendSyncMessage("FireGesturesRemote:Response", { name: "sourceNode" }, { elt: elt });
+ let sel = this._getSelectedText(doc, elt);
+ sendSyncMessage("FireGesturesRemote:Response", { name: "sourceNode" }, { elt, sel });
},
_onSwipeGesture: function(aData) {
log("onSwipeGesture: " + aData.toSource()); // #debug
- let { elt: elt } = this._elementFromPoint(aData.x, aData.y);
- sendSyncMessage("FireGesturesRemote:Response", { name: "sourceNode" }, { elt: elt });
+ let { doc, elt } = this._elementFromPoint(aData.x, aData.y);
+ let sel = this._getSelectedText(doc, elt);
+ sendSyncMessage("FireGesturesRemote:Response", { name: "sourceNode" }, { elt, sel });
sendSyncMessage("FireGesturesRemote:Response", { name: "swipe" }, { direction: aData.direction });
},
+ _getSelectedText: function(doc, elt) {
+ // @see BrowserUtils.getSelectionDetails
+ let sel = doc.defaultView.getSelection().toString();
+ if (!sel && elt instanceof Ci.nsIDOMNSEditableElement) {
+ if (elt instanceof Ci.nsIDOMHTMLTextAreaElement ||
+ (elt instanceof Ci.nsIDOMHTMLInputElement && elt.mozIsTextField(true))) {
+ sel = elt.editor.selection.toString();
+ }
+ }
+ return sel;
+ },
+
handleEvent: function(event) {
switch (event.type) {
case "scroll":
@@ -111,7 +125,7 @@ let FireGesturesRemote = {
},
_onKeypressProgress: function FGR__onKeypressProgress(aData) {
- let { doc: doc, elt: elt } = this._elementFromPoint(aData.x, aData.y);
+ let { doc, elt } = this._elementFromPoint(aData.x, aData.y);
let linkURL = this.getLinkURL(elt);
if (!this._linkURLs)
this._linkURLs = [];
@@ -161,7 +175,7 @@ let FireGesturesRemote = {
},
_sendKeyEvent: function FGR__sendKeyEvent(aOptions) {
- let { elt: elt, doc: doc } = this._elementFromPoint(this._startX, this._startY);
+ let { doc, elt } = this._elementFromPoint(this._startX, this._startY);
let evt = doc.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress", true, true, null,
@@ -189,7 +203,7 @@ let FireGesturesRemote = {
elt = doc.elementFromPoint(x, y);
}
// log("_elementFromPoint: " + [doc.location, elt.localName, x, y].join(", ")); // #debug
- return { doc: doc, elt: elt };
+ return { doc, elt };
},
--
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