зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1283061 - HTMLInputElement type=file webkitdirectory/directory should show just 1 button, r=smaug
This commit is contained in:
Родитель
67f00dc15b
Коммит
5cddd3946d
|
@ -3165,7 +3165,13 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
|
|||
nsXPIDLString value;
|
||||
|
||||
if (mFilesOrDirectories.IsEmpty()) {
|
||||
if (HasAttr(kNameSpaceID_None, nsGkAtoms::multiple)) {
|
||||
if ((Preferences::GetBool("dom.input.dirpicker", false) &&
|
||||
HasAttr(kNameSpaceID_None, nsGkAtoms::directory)) ||
|
||||
(Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
|
||||
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) {
|
||||
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
||||
"NoDirSelected", value);
|
||||
} else if (HasAttr(kNameSpaceID_None, nsGkAtoms::multiple)) {
|
||||
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
||||
"NoFilesSelected", value);
|
||||
} else {
|
||||
|
@ -4405,12 +4411,10 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
|
|||
if (target &&
|
||||
target->GetParent() == this &&
|
||||
target->IsRootOfNativeAnonymousSubtree() &&
|
||||
(target->HasAttr(kNameSpaceID_None, nsGkAtoms::directory) ||
|
||||
target->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) {
|
||||
MOZ_ASSERT(Preferences::GetBool("dom.input.dirpicker", false) ||
|
||||
Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false),
|
||||
"No API or UI should have been exposed to allow this code to "
|
||||
"be reached");
|
||||
((Preferences::GetBool("dom.input.dirpicker", false) &&
|
||||
HasAttr(kNameSpaceID_None, nsGkAtoms::directory)) ||
|
||||
(Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
|
||||
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)))) {
|
||||
type = FILE_PICKER_DIRECTORY;
|
||||
}
|
||||
return InitFilePicker(type);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
Reset=Reset
|
||||
Submit=Submit Query
|
||||
Browse=Browse…
|
||||
ChooseFiles=Choose files…
|
||||
ChooseDirs=Choose folder…
|
||||
FileUpload=File Upload
|
||||
# LOCALIZATION NOTE (IsIndexPromptWithSpace): The last character of the string
|
||||
# should be a space (U+0020) in most locales. The prompt is followed by an
|
||||
|
@ -25,6 +23,10 @@ NoFileSelected=No file selected.
|
|||
# LOCALIZATION NOTE (NoFilesSelected): this string is shown on a
|
||||
# <input type='file' multiple> when there is no file selected yet.
|
||||
NoFilesSelected=No files selected.
|
||||
# LOCALIZATION NOTE (NoDirSelected): this string is shown on a
|
||||
# <input type='file' directory/webkitdirectory> when there is no directory
|
||||
# selected yet.
|
||||
NoDirSelected=No directory selected.
|
||||
# LOCALIZATION NOTE (XFilesSelected): this string is shown on a
|
||||
# <input type='file' multiple> when there are more than one selected file.
|
||||
# %S will be a number greater or equal to 2.
|
||||
|
|
|
@ -67,8 +67,7 @@ nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|||
}
|
||||
|
||||
nsContentUtils::DestroyAnonymousContent(&mTextContent);
|
||||
nsContentUtils::DestroyAnonymousContent(&mBrowseDirs);
|
||||
nsContentUtils::DestroyAnonymousContent(&mBrowseFiles);
|
||||
nsContentUtils::DestroyAnonymousContent(&mBrowseFilesOrDirs);
|
||||
|
||||
mMouseListener->ForgetFrame();
|
||||
nsBlockFrame::DestroyFrom(aDestructRoot);
|
||||
|
@ -127,19 +126,6 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|||
{
|
||||
nsCOMPtr<nsIDocument> doc = mContent->GetComposedDoc();
|
||||
|
||||
#if defined(ANDROID) || defined(MOZ_B2G)
|
||||
bool isDirPicker = false;
|
||||
bool isWebkitPicker = false;
|
||||
#else
|
||||
nsIContent* content = GetContent();
|
||||
bool isDirPicker =
|
||||
Preferences::GetBool("dom.input.dirpicker", false) &&
|
||||
content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::directory);
|
||||
bool isWebkitPicker =
|
||||
Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
|
||||
content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory);
|
||||
#endif
|
||||
|
||||
RefPtr<HTMLInputElement> fileContent = HTMLInputElement::FromContentOrNull(mContent);
|
||||
|
||||
// The access key is transferred to the "Choose files..." button only. In
|
||||
|
@ -148,35 +134,11 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|||
nsAutoString accessKey;
|
||||
fileContent->GetAccessKey(accessKey);
|
||||
|
||||
mBrowseFiles = MakeAnonButton(doc,
|
||||
isDirPicker || isWebkitPicker ? "ChooseFiles" : "Browse",
|
||||
fileContent, accessKey);
|
||||
if (!mBrowseFiles || !aElements.AppendElement(mBrowseFiles)) {
|
||||
mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent, accessKey);
|
||||
if (!mBrowseFilesOrDirs || !aElements.AppendElement(mBrowseFilesOrDirs)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (isDirPicker || isWebkitPicker) {
|
||||
mBrowseDirs = MakeAnonButton(doc, "ChooseDirs", fileContent, EmptyString());
|
||||
// Setting the 'directory' attribute is simply a means of allowing our
|
||||
// event handling code in HTMLInputElement.cpp to distinguish between a
|
||||
// click on the "Choose files" button from the "Choose a folder" button.
|
||||
if (!mBrowseDirs) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (isDirPicker) {
|
||||
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::directory,
|
||||
EmptyString(), false);
|
||||
} else {
|
||||
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory,
|
||||
EmptyString(), false);
|
||||
}
|
||||
|
||||
if (!aElements.AppendElement(mBrowseDirs)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Create and setup the text showing the selected files.
|
||||
RefPtr<NodeInfo> nodeInfo;
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
|
||||
|
@ -213,12 +175,8 @@ void
|
|||
nsFileControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
||||
uint32_t aFilter)
|
||||
{
|
||||
if (mBrowseFiles) {
|
||||
aElements.AppendElement(mBrowseFiles);
|
||||
}
|
||||
|
||||
if (mBrowseDirs) {
|
||||
aElements.AppendElement(mBrowseDirs);
|
||||
if (mBrowseFilesOrDirs) {
|
||||
aElements.AppendElement(mBrowseFilesOrDirs);
|
||||
}
|
||||
|
||||
if (mTextContent) {
|
||||
|
@ -343,17 +301,10 @@ nsFileControlFrame::SyncDisabledState()
|
|||
{
|
||||
EventStates eventStates = mContent->AsElement()->State();
|
||||
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
||||
mBrowseFiles->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
|
||||
true);
|
||||
if (mBrowseDirs) {
|
||||
mBrowseDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
|
||||
true);
|
||||
}
|
||||
mBrowseFilesOrDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
|
||||
EmptyString(), true);
|
||||
} else {
|
||||
mBrowseFiles->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
||||
if (mBrowseDirs) {
|
||||
mBrowseDirs->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
||||
}
|
||||
mBrowseFilesOrDirs->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,17 +315,11 @@ nsFileControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
|||
{
|
||||
if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::tabindex) {
|
||||
if (aModType == nsIDOMMutationEvent::REMOVAL) {
|
||||
mBrowseFiles->UnsetAttr(aNameSpaceID, aAttribute, true);
|
||||
if (mBrowseDirs) {
|
||||
mBrowseDirs->UnsetAttr(aNameSpaceID, aAttribute, true);
|
||||
}
|
||||
mBrowseFilesOrDirs->UnsetAttr(aNameSpaceID, aAttribute, true);
|
||||
} else {
|
||||
nsAutoString value;
|
||||
mContent->GetAttr(aNameSpaceID, aAttribute, value);
|
||||
mBrowseFiles->SetAttr(aNameSpaceID, aAttribute, value, true);
|
||||
if (mBrowseDirs) {
|
||||
mBrowseDirs->SetAttr(aNameSpaceID, aAttribute, value, true);
|
||||
}
|
||||
mBrowseFilesOrDirs->SetAttr(aNameSpaceID, aAttribute, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,15 +132,10 @@ protected:
|
|||
*/
|
||||
nsCOMPtr<nsIContent> mTextContent;
|
||||
/**
|
||||
* The button to open a directory picker.
|
||||
* The button to open a file or directory picker.
|
||||
* @see nsFileControlFrame::CreateAnonymousContent
|
||||
*/
|
||||
nsCOMPtr<nsIContent> mBrowseDirs;
|
||||
/**
|
||||
* The button to open a file picker.
|
||||
* @see nsFileControlFrame::CreateAnonymousContent
|
||||
*/
|
||||
nsCOMPtr<nsIContent> mBrowseFiles;
|
||||
nsCOMPtr<nsIContent> mBrowseFilesOrDirs;
|
||||
|
||||
/**
|
||||
* Drag and drop mouse listener.
|
||||
|
|
Загрузка…
Ссылка в новой задаче