Bug 972428 - Grippers not appearing under the URL field when adding text. Handle both XUL and HTML input elements. r=jimm

This commit is contained in:
Aleh Zasypkin 2014-02-14 18:32:13 +01:00
parent ea7ba95d42
commit 889428e517
5 changed files with 71 additions and 10 deletions

View File

@ -295,7 +295,7 @@
if (event.mozInputSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH) {
if (typeof SelectionHelperUI != 'undefined') {
SelectionHelperUI.attachEditSession(ChromeSelectionHandler,
event.clientX, event.clientY, this);
event.clientX, event.clientY, event.target);
} else {
// If we don't have access to SelectionHelperUI then we are using this
// binding for browser content (e.g. about:config)

View File

@ -293,7 +293,7 @@
if (aShouldDismiss)
ContextUI.dismissTabs();
if (!InputSourceHelper.isPrecise && this.textLength) {
if (!InputSourceHelper.isPrecise) {
let inputRectangle = this.inputField.getBoundingClientRect();
SelectionHelperUI.attachEditSession(ChromeSelectionHandler,
inputRectangle.left, inputRectangle.top, this);

View File

@ -6,6 +6,8 @@
* Selection handler for chrome text inputs
*/
let Ci = Components.interfaces;
const kCaretMode = 1;
const kSelectionMode = 2;
@ -34,7 +36,8 @@ var ChromeSelectionHandler = {
this._domWinUtils = Util.getWindowUtils(window);
this._contentWindow = window;
this._targetElement = aJson.target;
this._targetIsEditable = this._targetElement instanceof Components.interfaces.nsIDOMXULTextBoxElement;
this._targetIsEditable = Util.isTextInput(this._targetElement) ||
this._targetElement instanceof Ci.nsIDOMXULTextBoxElement;
if (!this._targetIsEditable) {
this._onFail("not an editable?", this._targetElement);
return;
@ -46,6 +49,11 @@ var ChromeSelectionHandler = {
return;
}
if (!this._getTargetElementValue()) {
this._onFail("Target element does not contain any content to select.");
return;
}
if (!selection.isCollapsed) {
this._mode = kSelectionMode;
this._updateSelectionUI("start", true, true);
@ -380,19 +388,36 @@ var ChromeSelectionHandler = {
*/
_getSelection: function _getSelection() {
let targetElementEditor = this._getTargetElementEditor();
return targetElementEditor ? targetElementEditor.selection : null;
},
_getTargetElementValue: function _getTargetElementValue() {
if (this._targetElement instanceof Ci.nsIDOMXULTextBoxElement) {
return this._targetElement
.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement)
.editor.selection;
return this._targetElement.inputField.value;
} else if (Util.isTextInput(this._targetElement)) {
return this._targetElement.value;
}
return null;
},
_getSelectController: function _getSelectController() {
return this._targetElement
.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement)
.editor.selectionController;
let targetElementEditor = this._getTargetElementEditor();
return targetElementEditor ? targetElementEditor.selectionController : null;
},
_getTargetElementEditor: function() {
if (this._targetElement instanceof Ci.nsIDOMXULTextBoxElement) {
return this._targetElement.QueryInterface(Ci.nsIDOMXULTextBoxElement)
.editor;
} else if (Util.isTextInput(this._targetElement)) {
return this._targetElement.QueryInterface(Ci.nsIDOMNSEditableElement)
.editor;
}
return null;
}
};
ChromeSelectionHandler.__proto__ = new SelectionPrototype();

View File

@ -250,6 +250,39 @@ gTests.push({
}
});
gTests.push({
desc: "Bug 972428 - grippers not appearing under the URL field when adding " +
"text.",
run: function() {
let inputField = document.getElementById("urlbar-edit").inputField;
let inputFieldRectangle = inputField.getBoundingClientRect();
let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler");
// Reset URL to empty string
inputField.value = "";
inputField.blur();
// Activate URL input
sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5);
// Wait until ChromeSelectionHandler tries to attach selection
yield waitForCondition(() => chromeHandlerSpy.argsForCall.some(
(args) => args[0] == "Browser:SelectionAttach"));
ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible,
"Neither CaretUI nor SelectionUI is visible on empty input.");
inputField.value = "Test text";
sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
chromeHandlerSpy.restore();
}
});
function test() {
if (!isLandscapeMode()) {
todo(false, "browser_selection_tests need landscape mode to run.");

View File

@ -1033,11 +1033,14 @@ function runTests() {
function spyOnMethod(aObj, aMethod) {
let origFunc = aObj[aMethod];
let spy = function() {
spy.calledWith = Array.slice(arguments);
let callArguments = Array.slice(arguments);
spy.callCount++;
spy.calledWith = callArguments;
spy.argsForCall.push(callArguments);
return (spy.returnValue = origFunc.apply(aObj, arguments));
};
spy.callCount = 0;
spy.argsForCall = [];
spy.restore = function() {
return (aObj[aMethod] = origFunc);
};