mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 904163 - Insure inputs that receive press-hold are focused. Fixes issues with selected text not being visible. r=ally
This commit is contained in:
parent
601263a118
commit
58d8e60c37
@ -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() {
|
||||
|
@ -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":
|
||||
|
@ -386,17 +386,20 @@ var SelectionHelperUI = {
|
||||
*
|
||||
* @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
|
||||
});
|
||||
|
@ -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");
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user