author | Jim Mathies <jmathies@mozilla.com> |
Fri, 05 Apr 2013 05:33:41 -0500 | |
changeset 127778 | d3a0bc6f68b128c4a83924bfb599d04d9e377afe |
parent 127777 | 5722966a3126e7d5e47476457fcb78a105034272 |
child 127779 | 10bcc9c3ca1d36c5cb186dd18d29c202ece77500 |
push id | 24512 |
push user | ryanvm@gmail.com |
push date | Fri, 05 Apr 2013 20:13:49 +0000 |
treeherder | mozilla-central@139b6ba547fa [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mbrubeck |
bugs | 856151 |
milestone | 23.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
browser/metro/base/content/helperui/SelectionHelperUI.js | file | annotate | diff | comparison | revisions |
--- a/browser/metro/base/content/helperui/SelectionHelperUI.js +++ b/browser/metro/base/content/helperui/SelectionHelperUI.js @@ -283,79 +283,86 @@ var SelectionHelperUI = { * Public apis */ /* * openEditSession * * Attempts to select underlying text at a point and begins editing * the section. + * + * @param aContent - Browser object + * @param aX, aY - Browser relative client coordinates. */ - openEditSession: function openEditSession(aContent, aClientX, aClientY) { - if (!aContent || this.isActive) + openEditSession: function openEditSession(aBrowser, aX, aY) { + if (!aBrowser || this.isActive) return; - this._init(aContent); + this._init(aBrowser); this._setupDebugOptions(); // 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: aClientX, - yPos: aClientY + xPos: aX, + yPos: aY }); }, /* * attachEditSession * * Attaches to existing selection and begins editing. + * + * @param aBrowser - Browser object + * @param aX, aY - Browser relative client coordinates. */ - attachEditSession: function attachEditSession(aContent, aClientX, aClientY) { - if (!aContent || this.isActive) + attachEditSession: function attachEditSession(aBrowser, aX, aY) { + if (!aBrowser || this.isActive) return; - this._init(aContent); + this._init(aBrowser); this._setupDebugOptions(); // 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._sendAsyncMessage("Browser:SelectionAttach", { - xPos: aClientX, - yPos: aClientY + xPos: aX, + yPos: aY }); }, /* * attachToCaret * * Initiates a touch caret selection session for a text input. * Can be called multiple times to move the caret marker around. * * Note the caret marker is pretty limited in functionality. The * only thing is can do is be displayed at the caret position. * Once the user starts a drag, the caret marker is hidden, and * the start and end markers take over. * - * @param aClientX, aClientY client coordiates of the tap that - * initiated the session. + * @param aBrowser - Browser object + * @param aX, aY - Browser relative client coordinates of the tap + * that initiated the session. */ - attachToCaret: function attachToCaret(aContent, aClientX, aClientY) { - if (!aContent) + attachToCaret: function attachToCaret(aBrowser, aX, aY) { + if (!aBrowser) return; if (!this.isActive) - this._init(aContent); + this._init(aBrowser); this._setupDebugOptions(); this._selectionHandlerActive = false; this._sendAsyncMessage("Browser:CaretAttach", { - xPos: aClientX, - yPos: aClientY + xPos: aX, + yPos: aY }); }, /* * canHandleContextMenuMsg * * Determines if we can handle a ContextMenuHandler message. */ @@ -520,49 +527,56 @@ var SelectionHelperUI = { // Start the selection monocle drag. SelectionHandler relies on this // for getting initialized. This will also trigger a message back for // monocle positioning. Note, markerDragMove is still on the stack in // this call! this._sendAsyncMessage("Browser:SelectionSwitchMode", { newMode: "selection", change: targetMark.tag, - xPos: targetMark.xPos, - yPos: targetMark.yPos, + xPos: this._msgTarget.xctob(targetMark.xPos, true), + yPos: this._msgTarget.yctob(targetMark.yPos, true), }); }, /* * _transitionFromSelectionToCaret * * Transitions from text selection mode to caret mode. + * + * @param aClientX, aClientY - client coordinates of the + * tap that initiates the change. */ - _transitionFromSelectionToCaret: function _transitionFromSelectionToCaret(aX, aY) { + _transitionFromSelectionToCaret: function _transitionFromSelectionToCaret(aClientX, aClientY) { // clear existing selection and shutdown SelectionHandler this._sendAsyncMessage("Browser:SelectionClear", { clearFocus: false }); this._sendAsyncMessage("Browser:SelectionClose"); // Reset some of our state this._selectionHandlerActive = false; this._activeSelectionRect = null; // Reset the monocles this._shutdownAllMarkers(); this._setupMonocleIdArray(); + // Translate to browser relative client coordinates + let coords = + this._msgTarget.ptClientToBrowser(aClientX, aClientY, true); + // Init SelectionHandler and turn on caret selection. Note the focus caret // will have been removed from the target element due to the shutdown call. // This won't set the caret position on its own. this._sendAsyncMessage("Browser:CaretAttach", { - xPos: aX, - yPos: aY + xPos: coords.x, + yPos: coords.y }); // Set the caret position - this._setCaretPositionAtPoint(aX, aY); + this._setCaretPositionAtPoint(coords.x, coords.y); }, /* * _setupDebugOptions * * Sends a message over to content instructing it to * turn on various debug features. */ @@ -615,16 +629,21 @@ var SelectionHelperUI = { // Ignore if the double tap isn't on our active selection rect. if (this._activeSelectionRect && Util.pointWithinRect(aEvent.clientX, aEvent.clientY, this._activeSelectionRect)) { return true; } return false; }, + /* + * _setCaretPositionAtPoint - sets the current caret position. + * + * @param aX, aY - browser relative client coordinates + */ _setCaretPositionAtPoint: function _setCaretPositionAtPoint(aX, aY) { let json = this._getMarkerBaseMessage(); json.change = "caret"; json.caret.xPos = aX; json.caret.yPos = aY; this._sendAsyncMessage("Browser:CaretUpdate", json); }, @@ -684,18 +703,22 @@ var SelectionHelperUI = { // Not so much if the target is a page or div. let pointInTargetElement = Util.pointWithinRect(aEvent.clientX, aEvent.clientY, this._targetElementRect); // If the tap is within an editable element and the caret monocle is // active, update the caret. if (this.caretMark.visible && pointInTargetElement) { + // _setCaretPositionAtPoint takes browser relative client coords + let coords = + this._msgTarget.ptClientToBrowser(aEvent.clientX, aEvent.clientY, + true); // Move the caret - this._setCaretPositionAtPoint(aEvent.clientX, aEvent.clientY); + this._setCaretPositionAtPoint(coords.x, coords.y); return; } // if the target is editable and the user clicks off the target // clear selection and remove focus from the input. if (this.caretMark.visible) { // shutdown and clear selection and remove focus this.closeEditSessionAndClear(true); @@ -740,55 +763,65 @@ var SelectionHelperUI = { */ _onDblTap: function _onDblTap(aEvent) { if (!this._hitTestSelection(aEvent)) { // Clear and close this.closeEditSessionAndClear(); return; } - // Select and close + let coords = + this._msgTarget.ptClientToBrowser(aEvent.clientX, aEvent.clientY, + true); + + // Select and close this._sendAsyncMessage("Browser:SelectionCopy", { - xPos: aEvent.clientX, - yPos: aEvent.clientY, + xPos: coords.x, + yPos: coords.y, }); aEvent.stopPropagation(); aEvent.preventDefault(); }, _onSelectionCopied: function _onSelectionCopied(json) { this.closeEditSessionAndClear(); }, _onSelectionRangeChange: function _onSelectionRangeChange(json) { // start and end contain client coordinates. if (json.updateStart) { - this.startMark.position(json.start.xPos, json.start.yPos); + this.startMark.position(this._msgTarget.xbtoc(json.start.xPos, true), + this._msgTarget.ybtoc(json.start.yPos, true)); this.startMark.show(); } if (json.updateEnd) { - this.endMark.position(json.end.xPos, json.end.yPos); + this.endMark.position(this._msgTarget.xbtoc(json.end.xPos, true), + this._msgTarget.ybtoc(json.end.yPos, true)); this.endMark.show(); } if (json.updateCaret) { // If selectionRangeFound is set SelectionHelper found a range we can // attach to. If not, there's no text in the control, and hence no caret // position information we can use. if (json.selectionRangeFound) { - this.caretMark.position(json.caret.xPos, json.caret.yPos); + this.caretMark.position(this._msgTarget.xbtoc(json.caret.xPos, true), + this._msgTarget.ybtoc(json.caret.yPos, true)); this.caretMark.show(); } else { // Don't display anything, just shutdown. this.closeEditSession(); } } - this._activeSelectionRect = json.selection; - this._targetElementRect = json.element; + this._targetIsEditable = json.targetIsEditable; + this._activeSelectionRect = + this._msgTarget.rectBrowserToClient(json.selection, true); + this._targetElementRect = + this._msgTarget.rectBrowserToClient(json.element, true); }, _onSelectionFail: function _onSelectionFail() { Util.dumpLn("failed to get a selection."); this.closeEditSession(); }, _onKeypress: function _onKeypress() { @@ -902,19 +935,28 @@ var SelectionHelperUI = { }, /* * Callbacks from markers */ _getMarkerBaseMessage: function _getMarkerBaseMessage() { return { - start: { xPos: this.startMark.xPos, yPos: this.startMark.yPos }, - end: { xPos: this.endMark.xPos, yPos: this.endMark.yPos }, - caret: { xPos: this.caretMark.xPos, yPos: this.caretMark.yPos }, + start: { + xPos: this._msgTarget.xctob(this.startMark.xPos, true), + yPos: this._msgTarget.yctob(this.startMark.yPos, true) + }, + end: { + xPos: this._msgTarget.xctob(this.endMark.xPos, true), + yPos: this._msgTarget.yctob(this.endMark.yPos, true) + }, + caret: { + xPos: this._msgTarget.xctob(this.caretMark.xPos, true), + yPos: this._msgTarget.yctob(this.caretMark.yPos, true) + }, }; }, markerDragStart: function markerDragStart(aMarker) { let json = this._getMarkerBaseMessage(); json.change = aMarker.tag; if (aMarker.tag == "caret") { this._sendAsyncMessage("Browser:CaretMove", json);