mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 838705 - Show the file names or "No file selected" in a <input type='file'> tooltip. r=ttaubert
This commit is contained in:
parent
4604f9a9ec
commit
4958c0d6e2
@ -24,6 +24,7 @@ MOCHITEST_BROWSER_FILES = \
|
||||
browser_default_image_filename.js \
|
||||
browser_Troubleshoot.js \
|
||||
browser_Deprecated.js \
|
||||
browser_input_file_tooltips.js \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
38
toolkit/content/tests/browser/browser_input_file_tooltips.js
Normal file
38
toolkit/content/tests/browser/browser_input_file_tooltips.js
Normal file
@ -0,0 +1,38 @@
|
||||
function test()
|
||||
{
|
||||
let data = [
|
||||
{ value: "/tmp", result: "tmp" },
|
||||
{ title: "foo", result: "foo" },
|
||||
{ result: "No file selected." },
|
||||
{ multiple: true, result: "No files selected." },
|
||||
{ required: true, result: "Please select a file." }
|
||||
];
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let tooltip = document.getElementById("aHTMLTooltip");
|
||||
|
||||
for (let test of data) {
|
||||
let input = doc.createElement('input');
|
||||
doc.body.appendChild(input);
|
||||
input.type = 'file';
|
||||
if (test.title) {
|
||||
input.setAttribute('title', test.title);
|
||||
}
|
||||
if (test.value) {
|
||||
if (test.value == "/tmp" && navigator.platform.indexOf('Win') != -1) {
|
||||
test.value = "C:\\Temp";
|
||||
test.result = "Temp";
|
||||
}
|
||||
input.value = test.value;
|
||||
}
|
||||
if (test.multiple) {
|
||||
input.multiple = true;
|
||||
}
|
||||
if (test.required) {
|
||||
input.required = true;
|
||||
}
|
||||
|
||||
ok(tooltip.fillInPageTooltip(input));
|
||||
is(tooltip.getAttribute('label'), test.result);
|
||||
}
|
||||
}
|
@ -563,6 +563,29 @@
|
||||
titleText = tipElement.validationMessage || null;
|
||||
}
|
||||
|
||||
// If the element is an <input type='file'> without a title, we should show
|
||||
// the current file selection.
|
||||
if (!titleText &&
|
||||
tipElement instanceof HTMLInputElement &&
|
||||
tipElement.type == 'file' &&
|
||||
!tipElement.hasAttribute('title')) {
|
||||
let files = tipElement.files;
|
||||
|
||||
if (files.length == 0) {
|
||||
var bundle = Services.strings.createBundle("chrome://global/locale/layout/HtmlForm.properties");
|
||||
if (tipElement.multiple) {
|
||||
titleText = bundle.GetStringFromName("NoFilesSelected");
|
||||
} else {
|
||||
titleText = bundle.GetStringFromName("NoFileSelected");
|
||||
}
|
||||
} else {
|
||||
titleText = files[0].name;
|
||||
for (let i=1; i<files.length; ++i) {
|
||||
titleText += "\n" + files[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((titleText == null) && (XLinkTitleText == null) &&
|
||||
(SVGTitleText == null) && tipElement) {
|
||||
if (tipElement.nodeType == Node.ELEMENT_NODE &&
|
||||
|
Loading…
Reference in New Issue
Block a user