Bug 1282870 - HTMLInputElement.webkitdirectory should show a DirPicker, r=smaug

This commit is contained in:
Andrea Marchesini 2016-06-29 13:29:04 +02:00
Родитель a5248d463f
Коммит 851369b631
1 изменённых файлов: 18 добавлений и 4 удалений

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

@ -129,11 +129,15 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
#if defined(ANDROID) || defined(MOZ_B2G) #if defined(ANDROID) || defined(MOZ_B2G)
bool isDirPicker = false; bool isDirPicker = false;
bool isWebkitPicker = false;
#else #else
nsIContent* content = GetContent(); nsIContent* content = GetContent();
bool isDirPicker = bool isDirPicker =
Preferences::GetBool("dom.input.dirpicker", false) && Preferences::GetBool("dom.input.dirpicker", false) &&
content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::directory); content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::directory);
bool isWebkitPicker =
Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory);
#endif #endif
RefPtr<HTMLInputElement> fileContent = HTMLInputElement::FromContentOrNull(mContent); RefPtr<HTMLInputElement> fileContent = HTMLInputElement::FromContentOrNull(mContent);
@ -144,13 +148,14 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
nsAutoString accessKey; nsAutoString accessKey;
fileContent->GetAccessKey(accessKey); fileContent->GetAccessKey(accessKey);
mBrowseFiles = MakeAnonButton(doc, isDirPicker ? "ChooseFiles" : "Browse", mBrowseFiles = MakeAnonButton(doc,
isDirPicker || isWebkitPicker ? "ChooseFiles" : "Browse",
fileContent, accessKey); fileContent, accessKey);
if (!mBrowseFiles || !aElements.AppendElement(mBrowseFiles)) { if (!mBrowseFiles || !aElements.AppendElement(mBrowseFiles)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
if (isDirPicker) { if (isDirPicker || isWebkitPicker) {
mBrowseDirs = MakeAnonButton(doc, "ChooseDirs", fileContent, EmptyString()); mBrowseDirs = MakeAnonButton(doc, "ChooseDirs", fileContent, EmptyString());
// Setting the 'directory' attribute is simply a means of allowing our // Setting the 'directory' attribute is simply a means of allowing our
// event handling code in HTMLInputElement.cpp to distinguish between a // event handling code in HTMLInputElement.cpp to distinguish between a
@ -158,8 +163,17 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
if (!mBrowseDirs) { if (!mBrowseDirs) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::directory,
EmptyString(), false); nsIContent* content = GetContent();
MOZ_ASSERT(content);
if (isDirPicker) {
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::directory,
EmptyString(), false);
} else {
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory,
EmptyString(), false);
}
if (!aElements.AppendElement(mBrowseDirs)) { if (!aElements.AppendElement(mBrowseDirs)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }