author | Vivien Nicolas <21@vingtetun.org> |
Wed, 06 Jun 2012 14:19:33 +0200 | |
changeset 95956 | fc203943d6bc0b89d688ceb24dc02a84fe691d3a |
parent 95955 | 2e509c91883aaed7cb11a9b0c2ae29cfd61f0a70 |
child 95957 | d1c8728bebaaf061ec1cd71ccfdc1d931aa9c54c |
push id | 10318 |
push user | vnicolas@mozilla.com |
push date | Wed, 06 Jun 2012 12:26:57 +0000 |
treeherder | mozilla-inbound@ecf7c8f799eb [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | fabrice |
bugs | 758672 |
milestone | 16.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
|
--- a/b2g/chrome/content/forms.js +++ b/b2g/chrome/content/forms.js @@ -8,44 +8,52 @@ let Ci = Components.interfaces; let Cc = Components.classes; let Cu = Components.utils; 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; } else if (target instanceof HTMLOptionElement && target.parentNode instanceof HTMLSelectElement) { 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; } case "blur": { let target = this.currentTarget; if (!target) @@ -64,23 +72,28 @@ let FormAssistant = { }, 0); break; } } }, receiveMessage: function fa_receiveMessage(msg) { + let target = this.currentTarget; + if (!target) + return; + let json = msg.json; switch (msg.name) { + case "Forms:Input:Value": + target.value = json.value; + break; + case "Forms:Select:Choice": - if (!this.currentTarget) - return; - - let options = this.currentTarget.options; + let options = target.options; if ("index" in json) { options.item(json.index).selected = true; } else if ("indexes" in json) { for (let i = 0; i < options.length; i++) { options.item(i).selected = (json.indexes.indexOf(i) != -1); } } break;
--- a/b2g/chrome/content/webapi.js +++ b/b2g/chrome/content/webapi.js @@ -33,17 +33,17 @@ XPCOMUtils.defineLazyServiceGetter(Servi // in gecko. let readonly = targetElement.getAttribute('readonly'); if (readonly) return false; 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'; fireEvent('showime', { type: type }); return true; } let constructor = {
--- a/b2g/components/MozKeyboard.js +++ b/b2g/components/MozKeyboard.js @@ -66,16 +66,22 @@ MozKeyboard.prototype = { }, setSelectedOption: function mozKeyboardSetSelectedOption(index) { messageManager.sendAsyncMessage("Forms:Select:Choice", { "index": index }); }, + setValue: function mozKeyboardSetValue(value) { + messageManager.sendAsyncMessage("Forms:Input:Value", { + "value": value + }); + }, + setSelectedOptions: function mozKeyboardSetSelectedOptions(indexes) { messageManager.sendAsyncMessage("Forms:Select:Choice", { "indexes": indexes || [] }); }, set onfocuschange(val) { this._focusHandler = val;
--- a/b2g/components/b2g.idl +++ b/b2g/components/b2g.idl @@ -25,10 +25,17 @@ interface nsIB2GKeyboard : nsISupports void setSelectedOption(in jsval index); // Select the <select> options specified by indexes. All other options // will be deselected. // If this method is called for a <select> that does not support multiple // 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; };