bug 666977 - Panning ends selection in progress r=mbrubeck

This commit is contained in:
Brad Lassey 2011-08-18 16:54:34 -04:00
Родитель 3d3566437c
Коммит 41e6c83e6a
2 изменённых файлов: 56 добавлений и 7 удалений

Просмотреть файл

@ -1343,6 +1343,20 @@ var SelectionHelper = {
handleEvent: function handleEvent(aEvent) {
switch (aEvent.type) {
case "PanBegin":
window.removeEventListener("PanBegin", this, true);
window.addEventListener("PanFinished", this, true);
this._start.hidden = true;
this._end.hidden = true;
break;
case "PanFinished":
window.removeEventListener("PanFinished", this, true);
try {
this.popupState.target.messageManager.sendAsyncMessage("Browser:SelectionMeasure", {});
} catch (e) {
Cu.reportError(e);
}
break
case "TapDown":
if (aEvent.target == this._start || aEvent.target == this._end) {
this.target = aEvent.target;
@ -1350,14 +1364,20 @@ var SelectionHelper = {
this.deltaY = (aEvent.clientY - this.target.top);
window.addEventListener("TapMove", this, true);
} else {
this.hide(aEvent);
window.addEventListener("PanBegin", this, true);
this.target = null;
}
break;
case "TapUp":
window.removeEventListener("TapMove", this, true);
this.target = null;
this.deltaX = -1;
this.deltaY = -1;
if (this.target) {
window.removeEventListener("TapMove", this, true);
this.target = null;
this.deltaX = -1;
this.deltaY = -1;
} else {
window.removeEventListener("PanBegin", self, true);
self.hide(aEvent);
}
break;
case "TapMove":
if (this.target) {
@ -1375,10 +1395,18 @@ var SelectionHelper = {
}
break;
case "resize":
case "keypress":
case "URLChanged":
case "SizeChanged":
case "ZoomChanged":
{
try {
this.popupState.target.messageManager.sendAsyncMessage("Browser:SelectionMeasure", {});
} catch (e) {
Cu.reportError(e);
}
break
}
case "URLChanged":
case "keypress":
this.hide(aEvent);
break;
}

Просмотреть файл

@ -1351,6 +1351,7 @@ var SelectionHandler = {
addMessageListener("Browser:SelectionStart", this);
addMessageListener("Browser:SelectionEnd", this);
addMessageListener("Browser:SelectionMove", this);
addMessageListener("Browser:SelectionMeasure", this);
},
getCurrentWindowAndOffset: function(x, y, offset) {
@ -1501,6 +1502,26 @@ var SelectionHandler = {
let range = selection.getRangeAt(0).QueryInterface(Ci.nsIDOMNSRange);
this.cache.rect = this._extractFromRange(range, this.cache.offset).rect;
break;
case "Browser:SelectionMeasure": {
let selection = this.contentWindow.getSelection();
let range = selection.getRangeAt(0).QueryInterface(Ci.nsIDOMNSRange);
if (!range)
return;
// Cache the selected text since the selection might be gone by the time we get the "end" message
this.selectedText = selection.toString().trim();
// If the range didn't have any text, let's bail
if (!this.selectedText.length) {
selection.removeAllRanges();
return;
}
this.cache = this._extractFromRange(range, this.cache.offset);
sendAsyncMessage("Browser:SelectionRange", this.cache);
break;
}
}
},