зеркало из https://github.com/mozilla/gecko-dev.git
Bug 842997 - Make SelectionHelperUI startup entry points json message agnostic. r=fyan
This commit is contained in:
Родитель
e1ef7cf40f
Коммит
d76f6f31ba
|
@ -22,18 +22,21 @@ const BrowserTouchHandler = {
|
||||||
onContentContextMenu: function onContentContextMenu(aMessage) {
|
onContentContextMenu: function onContentContextMenu(aMessage) {
|
||||||
// Note, target here is the target of the message manager message,
|
// Note, target here is the target of the message manager message,
|
||||||
// usually the browser.
|
// usually the browser.
|
||||||
let contextInfo = { name: aMessage.name,
|
|
||||||
json: aMessage.json,
|
|
||||||
target: aMessage.target };
|
|
||||||
// Touch input selection handling
|
// Touch input selection handling
|
||||||
if (!InputSourceHelper.isPrecise && !SelectionHelperUI.isActive &&
|
if (!InputSourceHelper.isPrecise &&
|
||||||
SelectionHelperUI.canHandle(aMessage)) {
|
!SelectionHelperUI.isActive &&
|
||||||
SelectionHelperUI.openEditSession(aMessage);
|
SelectionHelperUI.canHandleContextMenuMsg(aMessage)) {
|
||||||
|
SelectionHelperUI.openEditSession(aMessage.target,
|
||||||
|
aMessage.json.xPos,
|
||||||
|
aMessage.json.yPos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we have context menu item(s) that apply to what
|
// Check to see if we have context menu item(s) that apply to what
|
||||||
// was clicked on.
|
// was clicked on.
|
||||||
|
let contextInfo = { name: aMessage.name,
|
||||||
|
json: aMessage.json,
|
||||||
|
target: aMessage.target };
|
||||||
if (ContextMenuUI.showContextMenu(contextInfo)) {
|
if (ContextMenuUI.showContextMenu(contextInfo)) {
|
||||||
let event = document.createEvent("Events");
|
let event = document.createEvent("Events");
|
||||||
event.initEvent("CancelTouchSequence", true, false);
|
event.initEvent("CancelTouchSequence", true, false);
|
||||||
|
|
|
@ -100,24 +100,20 @@ var ContextCommands = {
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function cc_select() {
|
select: function cc_select() {
|
||||||
let contextInfo = { name: "",
|
SelectionHelperUI.openEditSession(ContextMenuUI.popupState.target,
|
||||||
json: ContextMenuUI.popupState,
|
ContextMenuUI.popupState.xPos,
|
||||||
target: ContextMenuUI.popupState.target };
|
ContextMenuUI.popupState.yPos);
|
||||||
SelectionHelperUI.openEditSession(contextInfo);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
selectAll: function cc_selectAll() {
|
selectAll: function cc_selectAll() {
|
||||||
let target = ContextMenuUI.popupState.target;
|
let target = ContextMenuUI.popupState.target;
|
||||||
if (target.localName == "browser") {
|
if (target.localName == "browser") {
|
||||||
// content
|
// content
|
||||||
let x = ContextMenuUI.popupState.x;
|
let x = ContextMenuUI.popupState.xPos;
|
||||||
let y = ContextMenuUI.popupState.y;
|
let y = ContextMenuUI.popupState.yPos;
|
||||||
let json = {x: x, y: y, command: "select-all" };
|
let json = {x: x, y: y, command: "select-all" };
|
||||||
target.messageManager.sendAsyncMessage("Browser:ContextCommand", json);
|
target.messageManager.sendAsyncMessage("Browser:ContextCommand", json);
|
||||||
let contextInfo = { name: "",
|
SelectionHelperUI.attachEditSession(target, x, y);
|
||||||
json: ContextMenuUI.popupState,
|
|
||||||
target: ContextMenuUI.popupState.target };
|
|
||||||
SelectionHelperUI.attachEditSession(contextInfo);
|
|
||||||
} else {
|
} else {
|
||||||
// chrome
|
// chrome
|
||||||
target.editor.selectAll();
|
target.editor.selectAll();
|
||||||
|
|
|
@ -191,7 +191,7 @@ Marker.prototype = {
|
||||||
|
|
||||||
var SelectionHelperUI = {
|
var SelectionHelperUI = {
|
||||||
_debugEvents: false,
|
_debugEvents: false,
|
||||||
_popupState: null,
|
_msgTarget: null,
|
||||||
_startMark: null,
|
_startMark: null,
|
||||||
_endMark: null,
|
_endMark: null,
|
||||||
_target: null,
|
_target: null,
|
||||||
|
@ -223,38 +223,22 @@ var SelectionHelperUI = {
|
||||||
* Attempts to select underlying text at a point and begins editing
|
* Attempts to select underlying text at a point and begins editing
|
||||||
* the section.
|
* the section.
|
||||||
*/
|
*/
|
||||||
openEditSession: function openEditSession(aMessage) {
|
openEditSession: function openEditSession(aContent, aClientX, aClientY) {
|
||||||
/*
|
if (!aContent || this.isActive)
|
||||||
* aMessage - from _onContentContextMenu in ContextMenuHandler
|
return;
|
||||||
* name: aMessage.name,
|
this._init(aContent);
|
||||||
* target: aMessage.target
|
|
||||||
* json:
|
|
||||||
* types: [],
|
|
||||||
* label: "",
|
|
||||||
* linkURL: "",
|
|
||||||
* linkTitle: "",
|
|
||||||
* linkProtocol: null,
|
|
||||||
* mediaURL: "",
|
|
||||||
* xPos: aEvent.x,
|
|
||||||
* yPos: aEvent.y
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._popupState = aMessage.json;
|
|
||||||
this._popupState._target = aMessage.target;
|
|
||||||
|
|
||||||
this._init();
|
|
||||||
|
|
||||||
// Set the track bounds for each marker NIY
|
// Set the track bounds for each marker NIY
|
||||||
this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
|
this.startMark.setTrackBounds(aClientX, aClientY);
|
||||||
this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
|
this.endMark.setTrackBounds(aClientX, aClientY);
|
||||||
|
|
||||||
// Send this over to SelectionHandler in content, they'll message us
|
// Send this over to SelectionHandler in content, they'll message us
|
||||||
// back with information on the current selection. SelectionStart
|
// back with information on the current selection. SelectionStart
|
||||||
// takes client coordinates.
|
// takes client coordinates.
|
||||||
this._selectionHandlerActive = false;
|
this._selectionHandlerActive = false;
|
||||||
this._sendAsyncMessage("Browser:SelectionStart", {
|
this._sendAsyncMessage("Browser:SelectionStart", {
|
||||||
xPos: this._popupState.xPos,
|
xPos: aClientX,
|
||||||
yPos: this._popupState.yPos
|
yPos: aClientY
|
||||||
});
|
});
|
||||||
|
|
||||||
this._setupDebugOptions();
|
this._setupDebugOptions();
|
||||||
|
@ -265,36 +249,33 @@ var SelectionHelperUI = {
|
||||||
*
|
*
|
||||||
* Attaches to existing selection and begins editing.
|
* Attaches to existing selection and begins editing.
|
||||||
*/
|
*/
|
||||||
attachEditSession: function attachEditSession(aMessage) {
|
attachEditSession: function attachEditSession(aContent, aClientX, aClientY) {
|
||||||
if (aMessage.target == undefined)
|
if (!aContent || this.isActive)
|
||||||
return;
|
return;
|
||||||
this._popupState = aMessage.json;
|
this._init(aContent);
|
||||||
this._popupState._target = aMessage.target;
|
|
||||||
|
|
||||||
this._init();
|
|
||||||
|
|
||||||
// Set the track bounds for each marker NIY
|
// Set the track bounds for each marker NIY
|
||||||
this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
|
this.startMark.setTrackBounds(aClientX, aClientY);
|
||||||
this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
|
this.endMark.setTrackBounds(aClientX, aClientY);
|
||||||
|
|
||||||
// Send this over to SelectionHandler in content, they'll message us
|
// Send this over to SelectionHandler in content, they'll message us
|
||||||
// back with information on the current selection. SelectionAttach
|
// back with information on the current selection. SelectionAttach
|
||||||
// takes client coordinates.
|
// takes client coordinates.
|
||||||
this._selectionHandlerActive = false;
|
this._selectionHandlerActive = false;
|
||||||
this._popupState._target.messageManager.sendAsyncMessage(
|
this._sendAsyncMessage("Browser:SelectionAttach", {
|
||||||
"Browser:SelectionAttach",
|
xPos: aClientX,
|
||||||
{ xPos: this._popupState.xPos,
|
yPos: aClientY
|
||||||
yPos: this._popupState.yPos });
|
});
|
||||||
|
|
||||||
this._setupDebugOptions();
|
this._setupDebugOptions();
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* canHandle
|
* canHandleContextMenuMsg
|
||||||
*
|
*
|
||||||
* Determines if we can handle a ContextMenuHandler message.
|
* Determines if we can handle a ContextMenuHandler message.
|
||||||
*/
|
*/
|
||||||
canHandle: function canHandle(aMessage) {
|
canHandleContextMenuMsg: function canHandleContextMenuMsg(aMessage) {
|
||||||
if (aMessage.json.types.indexOf("content-text") != -1)
|
if (aMessage.json.types.indexOf("content-text") != -1)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -306,8 +287,7 @@ var SelectionHelperUI = {
|
||||||
* Determines if an edit session is currently active.
|
* Determines if an edit session is currently active.
|
||||||
*/
|
*/
|
||||||
get isActive() {
|
get isActive() {
|
||||||
return (this._popupState != null &&
|
return (this._msgTarget &&
|
||||||
this._popupState._target != null &&
|
|
||||||
this._selectionHandlerActive);
|
this._selectionHandlerActive);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -337,7 +317,10 @@ var SelectionHelperUI = {
|
||||||
* Internal
|
* Internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_init: function _init() {
|
_init: function _init(aMsgTarget) {
|
||||||
|
// store the target message manager
|
||||||
|
this._msgTarget = aMsgTarget;
|
||||||
|
|
||||||
// SelectionHandler messages
|
// SelectionHandler messages
|
||||||
messageManager.addMessageListener("Content:SelectionRange", this);
|
messageManager.addMessageListener("Content:SelectionRange", this);
|
||||||
messageManager.addMessageListener("Content:SelectionCopied", this);
|
messageManager.addMessageListener("Content:SelectionCopied", this);
|
||||||
|
@ -399,7 +382,7 @@ var SelectionHelperUI = {
|
||||||
delete this._startMark;
|
delete this._startMark;
|
||||||
delete this._endMark;
|
delete this._endMark;
|
||||||
|
|
||||||
this._popupState = null;
|
this._msgTarget = null;
|
||||||
this._activeSelectionRect = null;
|
this._activeSelectionRect = null;
|
||||||
this._selectionHandlerActive = false;
|
this._selectionHandlerActive = false;
|
||||||
|
|
||||||
|
@ -444,12 +427,12 @@ var SelectionHelperUI = {
|
||||||
* SelectionHandler.
|
* SelectionHandler.
|
||||||
*/
|
*/
|
||||||
_sendAsyncMessage: function _sendAsyncMessage(aMsg, aJson) {
|
_sendAsyncMessage: function _sendAsyncMessage(aMsg, aJson) {
|
||||||
if (!this._popupState || !this._popupState._target) {
|
if (!this._msgTarget) {
|
||||||
if (this._debugEvents)
|
if (this._debugEvents)
|
||||||
Util.dumpLn("SelectionHelperUI sendAsyncMessage could not send", aMsg);
|
Util.dumpLn("SelectionHelperUI sendAsyncMessage could not send", aMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._popupState._target.messageManager.sendAsyncMessage(aMsg, aJson);
|
this._msgTarget.messageManager.sendAsyncMessage(aMsg, aJson);
|
||||||
},
|
},
|
||||||
|
|
||||||
_checkForActiveDrag: function _checkForActiveDrag() {
|
_checkForActiveDrag: function _checkForActiveDrag() {
|
||||||
|
@ -646,20 +629,6 @@ var SelectionHelperUI = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_getMarkerBaseMessage: function _getMarkerBaseMessage() {
|
_getMarkerBaseMessage: function _getMarkerBaseMessage() {
|
||||||
/*
|
|
||||||
This appears to be adjusted for scroll and scale. It should only
|
|
||||||
adjust for scale, content handles scroll offsets.
|
|
||||||
let startPos =
|
|
||||||
this._popupState._target.transformBrowserToClient(this.startMark.xPos,
|
|
||||||
this.startMark.yPos);
|
|
||||||
let endPos =
|
|
||||||
this._popupState._target.transformBrowserToClient(this.endMark.xPos,
|
|
||||||
this.endMark.yPos);
|
|
||||||
return {
|
|
||||||
start: { xPos: startPos.x, yPos: startPos.y },
|
|
||||||
end: { xPos: endPos.x, yPos: endPos.y },
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
return {
|
return {
|
||||||
start: { xPos: this.startMark.xPos, yPos: this.startMark.yPos },
|
start: { xPos: this.startMark.xPos, yPos: this.startMark.yPos },
|
||||||
end: { xPos: this.endMark.xPos, yPos: this.endMark.yPos },
|
end: { xPos: this.endMark.xPos, yPos: this.endMark.yPos },
|
||||||
|
|
|
@ -147,10 +147,8 @@ var TouchModule = {
|
||||||
// content and triggers selection of text, so fire up the SelectionHelperUI
|
// content and triggers selection of text, so fire up the SelectionHelperUI
|
||||||
// once selection is present.
|
// once selection is present.
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
let contextInfo = { name: "",
|
SelectionHelperUI.attachEditSession(Browser.selectedTab.browser,
|
||||||
json: { xPos: aEvent.clientX, yPos: aEvent.clientY },
|
aEvent.clientX, aEvent.clientY);
|
||||||
target: Browser.selectedTab.browser };
|
|
||||||
SelectionHelperUI.attachEditSession(contextInfo);
|
|
||||||
}, 50);
|
}, 50);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче