From 58d8e60c371326fcf45a295f7f26f2f757ee94ed Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Mon, 19 Aug 2013 04:26:17 -0500 Subject: [PATCH] Bug 904163 - Insure inputs that receive press-hold are focused. Fixes issues with selected text not being visible. r=ally --- browser/metro/base/content/ContextCommands.js | 3 ++- .../content/contenthandlers/SelectionHandler.js | 14 ++++++++++---- .../base/content/helperui/SelectionHelperUI.js | 11 +++++++---- .../tests/mochitest/browser_selection_inputs.js | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/browser/metro/base/content/ContextCommands.js b/browser/metro/base/content/ContextCommands.js index 4d368c81356a..80bec501bb56 100644 --- a/browser/metro/base/content/ContextCommands.js +++ b/browser/metro/base/content/ContextCommands.js @@ -111,7 +111,8 @@ var ContextCommands = { select: function cc_select() { SelectionHelperUI.openEditSession(ContextMenuUI.popupState.target, ContextMenuUI.popupState.xPos, - ContextMenuUI.popupState.yPos); + ContextMenuUI.popupState.yPos, + true); }, selectAll: function cc_selectAll() { diff --git a/browser/metro/base/content/contenthandlers/SelectionHandler.js b/browser/metro/base/content/contenthandlers/SelectionHandler.js index db3887a58d05..9cdf4034c202 100644 --- a/browser/metro/base/content/contenthandlers/SelectionHandler.js +++ b/browser/metro/base/content/contenthandlers/SelectionHandler.js @@ -56,19 +56,25 @@ var SelectionHandler = { /* * Selection start event handler */ - _onSelectionStart: function _onSelectionStart(aX, aY) { + _onSelectionStart: function _onSelectionStart(aJson) { // Init content window information - if (!this._initTargetInfo(aX, aY)) { + if (!this._initTargetInfo(aJson.xPos, aJson.yPos)) { this._onFail("failed to get target information"); return; } + // for context menu select command, which doesn't trigger + // form input focus changes. + if (aJson.setFocus && this._targetIsEditable) { + this._targetElement.focus(); + } + // Clear any existing selection from the document let selection = this._contentWindow.getSelection(); selection.removeAllRanges(); // Set our initial selection, aX and aY should be in client coordinates. - let framePoint = this._clientPointToFramePoint({ xPos: aX, yPos: aY }); + let framePoint = this._clientPointToFramePoint({ xPos: aJson.xPos, yPos: aJson.yPos }); if (!this._domWinUtils.selectAtPoint(framePoint.xPos, framePoint.yPos, Ci.nsIDOMWindowUtils.SELECT_WORDNOSPACE)) { this._onFail("failed to set selection at point"); @@ -498,7 +504,7 @@ var SelectionHandler = { let json = aMessage.json; switch (aMessage.name) { case "Browser:SelectionStart": - this._onSelectionStart(json.xPos, json.yPos); + this._onSelectionStart(json); break; case "Browser:SelectionAttach": diff --git a/browser/metro/base/content/helperui/SelectionHelperUI.js b/browser/metro/base/content/helperui/SelectionHelperUI.js index d36422706fe8..5d6fb286753e 100644 --- a/browser/metro/base/content/helperui/SelectionHelperUI.js +++ b/browser/metro/base/content/helperui/SelectionHelperUI.js @@ -380,23 +380,26 @@ var SelectionHelperUI = { /* * openEditSession - * + * * Attempts to select underlying text at a point and begins editing * the section. * * @param aMsgTarget - Browser or chrome message target * @param aX, aY - Browser relative client coordinates. + * @param aSetFocus - (optional) For form inputs, requests that the focus + * be set to the element. */ - openEditSession: function openEditSession(aMsgTarget, aX, aY) { + openEditSession: function openEditSession(aMsgTarget, aX, aY, aSetFocus) { if (!aMsgTarget || this.isActive) return; this._init(aMsgTarget); this._setupDebugOptions(); - + let setFocus = aSetFocus || false; // Send this over to SelectionHandler in content, they'll message us // back with information on the current selection. SelectionStart // takes client coordinates. this._sendAsyncMessage("Browser:SelectionStart", { + setFocus: setFocus, xPos: aX, yPos: aY }); @@ -404,7 +407,7 @@ var SelectionHelperUI = { /* * attachEditSession - * + * * Attaches to existing selection and begins editing. * * @param aMsgTarget - Browser or chrome message target diff --git a/browser/metro/base/tests/mochitest/browser_selection_inputs.js b/browser/metro/base/tests/mochitest/browser_selection_inputs.js index 677d82c8d55e..b2542edf87c7 100644 --- a/browser/metro/base/tests/mochitest/browser_selection_inputs.js +++ b/browser/metro/base/tests/mochitest/browser_selection_inputs.js @@ -59,7 +59,7 @@ gTests.push({ setUp: setUpAndTearDown, tearDown: setUpAndTearDown, run: function test() { - gInput.focus(); + gInput.blur(); gInput.selectionStart = gInput.selectionEnd = 0; let promise = waitForEvent(document, "popupshown"); @@ -81,6 +81,7 @@ gTests.push({ }, kCommonWaitMs, kCommonPollMs); is(getTrimmedSelection(gInput).toString(), "went", "selection test"); + is(gWindow.document.activeElement, gInput, "input focused"); }, });