Bug 758672 - Support mozKeyboard.setValue. r=fabrice

--HG--
extra : rebase_source : ab1014d247556d65dceb8c9da45a894ee5266ed4
This commit is contained in:
Vivien Nicolas 2012-06-06 14:19:33 +02:00
Родитель a52844af7a
Коммит 6d765a18aa
4 изменённых файлов: 35 добавлений и 9 удалений

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

@ -13,26 +13,30 @@ Cu.import("resource://gre/modules/Services.jsm");
dump("###################################### forms.js loaded\n");
let HTMLInputElement = Ci.nsIDOMHTMLInputElement;
let HTMLTextAreaElement = Ci.nsIDOMHTMLTextAreaElement;
let HTMLSelectElement = Ci.nsIDOMHTMLSelectElement;
let HTMLOptGroupElement = Ci.nsIDOMHTMLOptGroupElement;
let HTMLOptionElement = Ci.nsIDOMHTMLOptionElement;
let FormAssistant = {
init: function fa_init() {
addEventListener("focus", this, true, false);
addEventListener("click", this, true, false);
addEventListener("blur", this, true, false);
addMessageListener("Forms:Select:Choice", this);
addMessageListener("Forms:Input:Value", this);
Services.obs.addObserver(this, "xpcom-shutdown", false);
},
currentTarget: null,
handleEvent: function fa_handleEvent(evt) {
switch (evt.type) {
case "click":
case "focus": {
case "click": {
let target =
Services.fm.getFocusedElementForWindow(content, true, {}) ||
evt.target;
content.setTimeout(function(self) {
let target = evt.target;
if (target instanceof HTMLSelectElement) {
sendAsyncMessage("Forms:Input", self._getJSON(target));
self.currentTarget = target;
@ -41,6 +45,10 @@ let FormAssistant = {
target = target.parentNode;
sendAsyncMessage("Forms:Input", self._getJSON(target));
self.currentTarget = target;
} else if (target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement) {
sendAsyncMessage("Forms:Input", self._getJSON(target));
self.currentTarget = target;
}
}, 0, this);
break;
@ -69,13 +77,18 @@ let FormAssistant = {
},
receiveMessage: function fa_receiveMessage(msg) {
let target = this.currentTarget;
if (!target)
return;
let json = msg.json;
switch (msg.name) {
case "Forms:Select:Choice":
if (!this.currentTarget)
return;
case "Forms:Input:Value":
target.value = json.value;
break;
let options = this.currentTarget.options;
case "Forms:Select:Choice":
let options = target.options;
if ("index" in json) {
options.item(json.index).selected = true;
} else if ("indexes" in json) {

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

@ -38,7 +38,7 @@ XPCOMUtils.defineLazyServiceGetter(Services, 'fm',
let type = targetElement.type;
// FIXME/bug 344616 is input type='number'
// Until then, let's return 'number' even if the platform returns 'text'
let attributeType = targetElement.getAttribute('type');
let attributeType = targetElement.getAttribute('type') || '';
if (attributeType && attributeType.toLowerCase() === 'number')
type = 'number';

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

@ -71,6 +71,12 @@ MozKeyboard.prototype = {
});
},
setValue: function mozKeyboardSetValue(value) {
messageManager.sendAsyncMessage("Forms:Input:Value", {
"value": value
});
},
setSelectedOptions: function mozKeyboardSetSelectedOptions(indexes) {
messageManager.sendAsyncMessage("Forms:Select:Choice", {
"indexes": indexes || []

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

@ -30,5 +30,12 @@ interface nsIB2GKeyboard : nsISupports
// selection, then the last index specified in indexes will be selected.
void setSelectedOptions(in jsval indexes);
// Set the value on the currently focused element. This has to be used
// for special situations where the value had to be chosen amongst a
// list (type=month) or a widget (type=date, time, etc.).
// If the value passed in parameter isn't valid (in the term of HTML5
// Forms Validation), the value will simply be ignored by the element.
void setValue(in jsval value);
attribute nsIDOMEventListener onfocuschange;
};