gecko/mobile/android/chrome/content/InputWidgetHelper.js
Ryan VanderMeulen f644566996 Backed out 7 changesets (bug 872147, bug 872143, bug 877467, bug 877200, bug 870063, bug 872149) for robocop-2 failures on a CLOSED TREE.
Backed out changeset 3a1e8e7ac07e (bug 870063)
Backed out changeset 8904d2bf5da0 (bug 877200)
Backed out changeset 80455a25276b (bug 872149)
Backed out changeset c3b5567f1271 (bug 872147)
Backed out changeset d3106edd4a5a (bug 872143)
Backed out changeset 4fd2ae88da98 (bug 870063)
Backed out changeset 1797dc46e862 (bug 877467)
2013-06-03 15:04:51 -04:00

89 lines
2.4 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var InputWidgetHelper = {
_uiBusy: false,
handleEvent: function(aEvent) {
this.handleClick(aEvent.target);
},
handleClick: function(aTarget) {
// if we're busy looking at a InputWidget we want to eat any clicks that
// come to us, but not to process them
if (this._uiBusy || !this._isValidInput(aTarget))
return;
this._uiBusy = true;
this.show(aTarget);
this._uiBusy = false;
},
show: function(aElement) {
let type = aElement.getAttribute('type');
let msg = {
type: "Prompt:Show",
title: Strings.browser.GetStringFromName("inputWidgetHelper." + aElement.getAttribute('type')),
buttons: [
Strings.browser.GetStringFromName("inputWidgetHelper.set"),
Strings.browser.GetStringFromName("inputWidgetHelper.clear"),
Strings.browser.GetStringFromName("inputWidgetHelper.cancel")
],
inputs: [
{ type: type, value: aElement.value }
]
};
let data = JSON.parse(sendMessageToJava(msg));
let changed = false;
if (data.button == -1) {
// This type is not supported with this android version.
return;
}
if (data.button == 1) {
// The user cleared the value.
if (aElement.value != "") {
aElement.value = "";
changed = true;
}
} else if (data.button == 0) {
// Commit the new value.
if (aElement.value != data[type]) {
aElement.value = data[type];
changed = true;
}
}
// Else the user canceled the input.
if (changed)
this.fireOnChange(aElement);
},
_isValidInput: function(aElement) {
if (!aElement instanceof HTMLInputElement)
return false;
let type = aElement.getAttribute('type');
if (type == "date" || type == "datetime" || type == "datetime-local" ||
type == "week" || type == "month" || type == "time") {
return true;
}
return false;
},
fireOnChange: function(aElement) {
let evt = aElement.ownerDocument.createEvent("Events");
evt.initEvent("change", true, true, aElement.defaultView, 0,
false, false,
false, false, null);
setTimeout(function() {
aElement.dispatchEvent(evt);
}, 0);
}
};