Bug 842997 - Make SelectionHelperUI startup entry points json message agnostic. r=fyan

This commit is contained in:
Jim Mathies 2013-03-19 12:43:17 -05:00
Родитель e1ef7cf40f
Коммит d76f6f31ba
4 изменённых файлов: 45 добавлений и 79 удалений

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

@ -22,18 +22,21 @@ const BrowserTouchHandler = {
onContentContextMenu: function onContentContextMenu(aMessage) {
// Note, target here is the target of the message manager message,
// usually the browser.
let contextInfo = { name: aMessage.name,
json: aMessage.json,
target: aMessage.target };
// Touch input selection handling
if (!InputSourceHelper.isPrecise && !SelectionHelperUI.isActive &&
SelectionHelperUI.canHandle(aMessage)) {
SelectionHelperUI.openEditSession(aMessage);
if (!InputSourceHelper.isPrecise &&
!SelectionHelperUI.isActive &&
SelectionHelperUI.canHandleContextMenuMsg(aMessage)) {
SelectionHelperUI.openEditSession(aMessage.target,
aMessage.json.xPos,
aMessage.json.yPos);
return;
}
// Check to see if we have context menu item(s) that apply to what
// was clicked on.
let contextInfo = { name: aMessage.name,
json: aMessage.json,
target: aMessage.target };
if (ContextMenuUI.showContextMenu(contextInfo)) {
let event = document.createEvent("Events");
event.initEvent("CancelTouchSequence", true, false);

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

@ -100,24 +100,20 @@ var ContextCommands = {
},
select: function cc_select() {
let contextInfo = { name: "",
json: ContextMenuUI.popupState,
target: ContextMenuUI.popupState.target };
SelectionHelperUI.openEditSession(contextInfo);
SelectionHelperUI.openEditSession(ContextMenuUI.popupState.target,
ContextMenuUI.popupState.xPos,
ContextMenuUI.popupState.yPos);
},
selectAll: function cc_selectAll() {
let target = ContextMenuUI.popupState.target;
if (target.localName == "browser") {
// content
let x = ContextMenuUI.popupState.x;
let y = ContextMenuUI.popupState.y;
let x = ContextMenuUI.popupState.xPos;
let y = ContextMenuUI.popupState.yPos;
let json = {x: x, y: y, command: "select-all" };
target.messageManager.sendAsyncMessage("Browser:ContextCommand", json);
let contextInfo = { name: "",
json: ContextMenuUI.popupState,
target: ContextMenuUI.popupState.target };
SelectionHelperUI.attachEditSession(contextInfo);
SelectionHelperUI.attachEditSession(target, x, y);
} else {
// chrome
target.editor.selectAll();

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

@ -191,7 +191,7 @@ Marker.prototype = {
var SelectionHelperUI = {
_debugEvents: false,
_popupState: null,
_msgTarget: null,
_startMark: null,
_endMark: null,
_target: null,
@ -223,38 +223,22 @@ var SelectionHelperUI = {
* Attempts to select underlying text at a point and begins editing
* the section.
*/
openEditSession: function openEditSession(aMessage) {
/*
* aMessage - from _onContentContextMenu in ContextMenuHandler
* name: aMessage.name,
* 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();
openEditSession: function openEditSession(aContent, aClientX, aClientY) {
if (!aContent || this.isActive)
return;
this._init(aContent);
// Set the track bounds for each marker NIY
this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
this.startMark.setTrackBounds(aClientX, aClientY);
this.endMark.setTrackBounds(aClientX, aClientY);
// Send this over to SelectionHandler in content, they'll message us
// back with information on the current selection. SelectionStart
// takes client coordinates.
this._selectionHandlerActive = false;
this._sendAsyncMessage("Browser:SelectionStart", {
xPos: this._popupState.xPos,
yPos: this._popupState.yPos
xPos: aClientX,
yPos: aClientY
});
this._setupDebugOptions();
@ -265,36 +249,33 @@ var SelectionHelperUI = {
*
* Attaches to existing selection and begins editing.
*/
attachEditSession: function attachEditSession(aMessage) {
if (aMessage.target == undefined)
attachEditSession: function attachEditSession(aContent, aClientX, aClientY) {
if (!aContent || this.isActive)
return;
this._popupState = aMessage.json;
this._popupState._target = aMessage.target;
this._init();
this._init(aContent);
// Set the track bounds for each marker NIY
this.startMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
this.endMark.setTrackBounds(this._popupState.xPos, this._popupState.yPos);
this.startMark.setTrackBounds(aClientX, aClientY);
this.endMark.setTrackBounds(aClientX, aClientY);
// Send this over to SelectionHandler in content, they'll message us
// back with information on the current selection. SelectionAttach
// takes client coordinates.
this._selectionHandlerActive = false;
this._popupState._target.messageManager.sendAsyncMessage(
"Browser:SelectionAttach",
{ xPos: this._popupState.xPos,
yPos: this._popupState.yPos });
this._sendAsyncMessage("Browser:SelectionAttach", {
xPos: aClientX,
yPos: aClientY
});
this._setupDebugOptions();
},
/*
* canHandle
* canHandleContextMenuMsg
*
* Determines if we can handle a ContextMenuHandler message.
*/
canHandle: function canHandle(aMessage) {
canHandleContextMenuMsg: function canHandleContextMenuMsg(aMessage) {
if (aMessage.json.types.indexOf("content-text") != -1)
return true;
return false;
@ -306,8 +287,7 @@ var SelectionHelperUI = {
* Determines if an edit session is currently active.
*/
get isActive() {
return (this._popupState != null &&
this._popupState._target != null &&
return (this._msgTarget &&
this._selectionHandlerActive);
},
@ -337,7 +317,10 @@ var SelectionHelperUI = {
* Internal
*/
_init: function _init() {
_init: function _init(aMsgTarget) {
// store the target message manager
this._msgTarget = aMsgTarget;
// SelectionHandler messages
messageManager.addMessageListener("Content:SelectionRange", this);
messageManager.addMessageListener("Content:SelectionCopied", this);
@ -399,7 +382,7 @@ var SelectionHelperUI = {
delete this._startMark;
delete this._endMark;
this._popupState = null;
this._msgTarget = null;
this._activeSelectionRect = null;
this._selectionHandlerActive = false;
@ -444,12 +427,12 @@ var SelectionHelperUI = {
* SelectionHandler.
*/
_sendAsyncMessage: function _sendAsyncMessage(aMsg, aJson) {
if (!this._popupState || !this._popupState._target) {
if (!this._msgTarget) {
if (this._debugEvents)
Util.dumpLn("SelectionHelperUI sendAsyncMessage could not send", aMsg);
return;
}
this._popupState._target.messageManager.sendAsyncMessage(aMsg, aJson);
this._msgTarget.messageManager.sendAsyncMessage(aMsg, aJson);
},
_checkForActiveDrag: function _checkForActiveDrag() {
@ -646,20 +629,6 @@ var SelectionHelperUI = {
*/
_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 {
start: { xPos: this.startMark.xPos, yPos: this.startMark.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
// once selection is present.
setTimeout(function () {
let contextInfo = { name: "",
json: { xPos: aEvent.clientX, yPos: aEvent.clientY },
target: Browser.selectedTab.browser };
SelectionHelperUI.attachEditSession(contextInfo);
SelectionHelperUI.attachEditSession(Browser.selectedTab.browser,
aEvent.clientX, aEvent.clientY);
}, 50);
break;
}