Bug 1295914 - Improve the label of the button of folder picker. r=baku, r=mstange, r=karlt, r=jimm, a=abillings, l10n=flod
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 24 Aug 2016 02:07:21 +0300
changeset 332923 e58e63e362ff2a402bc7f22f0193097d07c418f1
parent 332922 433caaa37ccff62cfc755946b69bdf958b8dbeb5
child 332924 e02ff365129834713735afeb44d9d4b4490687e1
push id9950
push userryanvm@gmail.com
push dateFri, 26 Aug 2016 14:18:44 +0000
treeherdermozilla-aurora@e58e63e362ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, mstange, karlt, jimm, abillings
bugs1295914
milestone50.0a2
Bug 1295914 - Improve the label of the button of folder picker. r=baku, r=mstange, r=karlt, r=jimm, a=abillings, l10n=flod
dom/html/HTMLInputElement.cpp
dom/ipc/FilePickerParent.cpp
dom/ipc/FilePickerParent.h
dom/ipc/PFilePicker.ipdl
dom/locales/en-US/chrome/layout/HtmlForm.properties
widget/cocoa/nsFilePicker.mm
widget/gtk/nsFilePicker.cpp
widget/nsBaseFilePicker.cpp
widget/nsBaseFilePicker.h
widget/nsFilePickerProxy.cpp
widget/nsIFilePicker.idl
widget/windows/nsFilePicker.cpp
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -931,19 +931,24 @@ HTMLInputElement::InitFilePicker(FilePic
 
   if (IsPopupBlocked()) {
     win->FirePopupBlockedEvent(doc, nullptr, EmptyString(), EmptyString());
     return NS_OK;
   }
 
   // Get Loc title
   nsXPIDLString title;
+  nsXPIDLString okButtonLabel;
   if (aType == FILE_PICKER_DIRECTORY) {
     nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
                                        "DirectoryUpload", title);
+
+    nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
+                                       "DirectoryPickerOkButtonLabel",
+                                       okButtonLabel);
   } else {
     nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
                                        "FileUpload", title);
   }
 
   nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
   if (!filePicker)
     return NS_ERROR_FAILURE;
@@ -956,16 +961,20 @@ HTMLInputElement::InitFilePicker(FilePic
     mode = static_cast<int16_t>(nsIFilePicker::modeOpenMultiple);
   } else {
     mode = static_cast<int16_t>(nsIFilePicker::modeOpen);
   }
 
   nsresult rv = filePicker->Init(win, title, mode);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (!okButtonLabel.IsEmpty()) {
+    filePicker->SetOkButtonLabel(okButtonLabel);
+  }
+
   // Native directory pickers ignore file type filters, so we don't spend
   // cycles adding them for FILE_PICKER_DIRECTORY.
   if (HasAttr(kNameSpaceID_None, nsGkAtoms::accept) &&
       aType != FILE_PICKER_DIRECTORY) {
     SetFilePickerFiltersFromAccept(filePicker);
   } else {
     filePicker->AppendFilters(nsIFilePicker::filterAll);
   }
--- a/dom/ipc/FilePickerParent.cpp
+++ b/dom/ipc/FilePickerParent.cpp
@@ -246,32 +246,34 @@ FilePickerParent::CreateFilePicker()
 
 bool
 FilePickerParent::RecvOpen(const int16_t& aSelectedType,
                            const bool& aAddToRecentDocs,
                            const nsString& aDefaultFile,
                            const nsString& aDefaultExtension,
                            InfallibleTArray<nsString>&& aFilters,
                            InfallibleTArray<nsString>&& aFilterNames,
-                           const nsString& aDisplayDirectory)
+                           const nsString& aDisplayDirectory,
+                           const nsString& aOkButtonLabel)
 {
   if (!CreateFilePicker()) {
     Unused << Send__delete__(this, void_t(), nsIFilePicker::returnCancel);
     return true;
   }
 
   mFilePicker->SetAddToRecentDocs(aAddToRecentDocs);
 
   for (uint32_t i = 0; i < aFilters.Length(); ++i) {
     mFilePicker->AppendFilter(aFilterNames[i], aFilters[i]);
   }
 
   mFilePicker->SetDefaultString(aDefaultFile);
   mFilePicker->SetDefaultExtension(aDefaultExtension);
   mFilePicker->SetFilterIndex(aSelectedType);
+  mFilePicker->SetOkButtonLabel(aOkButtonLabel);
 
   if (!aDisplayDirectory.IsEmpty()) {
     nsCOMPtr<nsIFile> localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
     if (localFile) {
       localFile->InitWithPath(aDisplayDirectory);
       mFilePicker->SetDisplayDirectory(localFile);
     }
   }
--- a/dom/ipc/FilePickerParent.h
+++ b/dom/ipc/FilePickerParent.h
@@ -46,17 +46,18 @@ class FilePickerParent : public PFilePic
   void SendFilesOrDirectories(const nsTArray<BlobImplOrString>& aData);
 
   virtual bool RecvOpen(const int16_t& aSelectedType,
                         const bool& aAddToRecentDocs,
                         const nsString& aDefaultFile,
                         const nsString& aDefaultExtension,
                         InfallibleTArray<nsString>&& aFilters,
                         InfallibleTArray<nsString>&& aFilterNames,
-                        const nsString& aDisplayDirectory) override;
+                        const nsString& aDisplayDirectory,
+                        const nsString& aOkButtonLabel) override;
 
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   class FilePickerShownCallback : public nsIFilePickerShownCallback
   {
   public:
     explicit FilePickerShownCallback(FilePickerParent* aFilePickerParent)
       : mFilePickerParent(aFilePickerParent)
--- a/dom/ipc/PFilePicker.ipdl
+++ b/dom/ipc/PFilePicker.ipdl
@@ -31,16 +31,16 @@ union MaybeInputData
 
 protocol PFilePicker
 {
   manager PBrowser;
 
 parent:
     async Open(int16_t selectedType, bool addToRecentDocs, nsString defaultFile,
                nsString defaultExtension, nsString[] filters, nsString[] filterNames,
-               nsString displayDirectory);
+               nsString displayDirectory, nsString okButtonLabel);
 
 child:
     async __delete__(MaybeInputData data, int16_t result);
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/locales/en-US/chrome/layout/HtmlForm.properties
+++ b/dom/locales/en-US/chrome/layout/HtmlForm.properties
@@ -2,16 +2,17 @@
 # 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/.
 
 Reset=Reset
 Submit=Submit Query
 Browse=Browse…
 FileUpload=File Upload
 DirectoryUpload=Select Folder to Upload
+DirectoryPickerOkButtonLabel=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 
 # input field. The space needs be escaped in the property file to avoid 
 # trimming.
 IsIndexPromptWithSpace=This is a searchable index. Enter search keywords:\u0020
 ForgotPostWarning=Form contains enctype=%S, but does not contain method=post.  Submitting normally with method=GET and no enctype instead.
 ForgotFileEnctypeWarning=Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form.  The file will not be sent.
 # LOCALIZATION NOTE (DefaultFormSubject): %S will be replaced with brandShortName
--- a/widget/cocoa/nsFilePicker.mm
+++ b/widget/cocoa/nsFilePicker.mm
@@ -560,16 +560,20 @@ nsFilePicker::GetFilterList()
 // the OS will provide a sensible default.
 void
 nsFilePicker::SetDialogTitle(const nsString& inTitle, id aPanel)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   [aPanel setTitle:[NSString stringWithCharacters:(const unichar*)inTitle.get() length:inTitle.Length()]];
 
+  if (!mOkButtonLabel.IsEmpty()) {
+    [aPanel setPrompt:[NSString stringWithCharacters:(const unichar*)mOkButtonLabel.get() length:mOkButtonLabel.Length()]];
+  }
+
   NS_OBJC_END_TRY_ABORT_BLOCK;
 } 
 
 // Converts path from an nsIFile into a NSString path
 // If it fails, returns an empty string.
 NSString *
 nsFilePicker::PanelDefaultDirectory()
 {
--- a/widget/gtk/nsFilePicker.cpp
+++ b/widget/gtk/nsFilePicker.cpp
@@ -378,18 +378,26 @@ nsFilePicker::Open(nsIFilePickerShownCal
 
   nsXPIDLCString title;
   title.Adopt(ToNewUTF8String(mTitle));
 
   GtkWindow *parent_widget =
     GTK_WINDOW(mParentWidget->GetNativeData(NS_NATIVE_SHELLWIDGET));
 
   GtkFileChooserAction action = GetGtkFileChooserAction(mMode);
-  const gchar *accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE)
-                               ? GTK_STOCK_SAVE : GTK_STOCK_OPEN;
+
+  const gchar* accept_button;
+  NS_ConvertUTF16toUTF8 buttonLabel(mOkButtonLabel);
+  if (!mOkButtonLabel.IsEmpty()) {
+    accept_button = buttonLabel.get();
+  } else {
+    accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE) ?
+                    GTK_STOCK_SAVE : GTK_STOCK_OPEN;
+  }
+
   GtkWidget *file_chooser =
       gtk_file_chooser_dialog_new(title, parent_widget, action,
                                   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                   accept_button, GTK_RESPONSE_ACCEPT,
                                   nullptr);
   gtk_dialog_set_alternative_button_order(GTK_DIALOG(file_chooser),
                                           GTK_RESPONSE_ACCEPT,
                                           GTK_RESPONSE_CANCEL,
--- a/widget/nsBaseFilePicker.cpp
+++ b/widget/nsBaseFilePicker.cpp
@@ -339,16 +339,30 @@ nsBaseFilePicker::SetAddToRecentDocs(boo
 NS_IMETHODIMP
 nsBaseFilePicker::GetMode(int16_t* aMode)
 {
   *aMode = mMode;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsBaseFilePicker::SetOkButtonLabel(const nsAString& aLabel)
+{
+  mOkButtonLabel = aLabel;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsBaseFilePicker::GetOkButtonLabel(nsAString& aLabel)
+{
+  aLabel = mOkButtonLabel;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsBaseFilePicker::GetDomFileOrDirectory(nsISupports** aValue)
 {
   nsCOMPtr<nsIFile> localFile;
   nsresult rv = GetFile(getter_AddRefs(localFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!localFile) {
     *aValue = nullptr;
--- a/widget/nsBaseFilePicker.h
+++ b/widget/nsBaseFilePicker.h
@@ -7,16 +7,17 @@
 #ifndef nsBaseFilePicker_h__
 #define nsBaseFilePicker_h__
 
 #include "nsISupports.h"
 #include "nsIFilePicker.h"
 #include "nsISimpleEnumerator.h"
 #include "nsArrayEnumerator.h"
 #include "nsCOMPtr.h"
+#include "nsString.h"
 
 class nsPIDOMWindowOuter;
 class nsIWidget;
 
 class nsBaseFilePicker : public nsIFilePicker
 {
 public:
   nsBaseFilePicker(); 
@@ -31,24 +32,27 @@ public:
   NS_IMETHOD GetFilterIndex(int32_t *aFilterIndex);
   NS_IMETHOD SetFilterIndex(int32_t aFilterIndex);
   NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
   NS_IMETHOD GetDisplayDirectory(nsIFile * *aDisplayDirectory);
   NS_IMETHOD SetDisplayDirectory(nsIFile * aDisplayDirectory);
   NS_IMETHOD GetAddToRecentDocs(bool *aFlag);
   NS_IMETHOD SetAddToRecentDocs(bool aFlag);
   NS_IMETHOD GetMode(int16_t *aMode);
+  NS_IMETHOD SetOkButtonLabel(const nsAString& aLabel);
+  NS_IMETHOD GetOkButtonLabel(nsAString& aLabel);
 
   NS_IMETHOD GetDomFileOrDirectory(nsISupports** aValue);
   NS_IMETHOD GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aValue);
 
 protected:
 
   virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle) = 0;
 
   bool mAddToRecentDocs;
   nsCOMPtr<nsIFile> mDisplayDirectory;
 
   nsCOMPtr<nsPIDOMWindowOuter> mParent;
   int16_t mMode;
+  nsString mOkButtonLabel;
 };
 
 #endif // nsBaseFilePicker_h__
--- a/widget/nsFilePickerProxy.cpp
+++ b/widget/nsFilePickerProxy.cpp
@@ -132,17 +132,17 @@ nsFilePickerProxy::Open(nsIFilePickerSho
   mCallback = aCallback;
 
   nsString displayDirectory;
   if (mDisplayDirectory) {
     mDisplayDirectory->GetPath(displayDirectory);
   }
 
   SendOpen(mSelectedType, mAddToRecentDocs, mDefault, mDefaultExtension,
-           mFilters, mFilterNames, displayDirectory);
+           mFilters, mFilterNames, displayDirectory, mOkButtonLabel);
 
   return NS_OK;
 }
 
 bool
 nsFilePickerProxy::Recv__delete__(const MaybeInputData& aData,
                                   const int16_t& aResult)
 {
--- a/widget/nsIFilePicker.idl
+++ b/widget/nsIFilePicker.idl
@@ -179,9 +179,16 @@ interface nsIFilePicker : nsISupports
   */
   void open(in nsIFilePickerShownCallback aFilePickerShownCallback);
 
  /**
   * The picker's mode, as set by the 'mode' argument passed to init()
   * (one of the modeOpen et. al. constants specified above).
   */
   readonly attribute short mode;
+
+  /**
+   * If set to non-empty string, the nsIFilePicker implementation
+   * may use okButtonLabel as the label for the button the user uses to accept
+   * file selection.
+   */
+  attribute AString okButtonLabel;
 };
--- a/widget/windows/nsFilePicker.cpp
+++ b/widget/windows/nsFilePicker.cpp
@@ -590,16 +590,21 @@ nsFilePicker::ShowFolderPicker(const nsS
   dialog->Advise(this, &mFDECookie);
 
   // options
   FILEOPENDIALOGOPTIONS fos = FOS_PICKFOLDERS;
   dialog->SetOptions(fos);
  
   // initial strings
   dialog->SetTitle(mTitle.get());
+
+  if (!mOkButtonLabel.IsEmpty()) {
+    dialog->SetOkButtonLabel(mOkButtonLabel.get());
+  }
+
   if (!aInitialDir.IsEmpty()) {
     RefPtr<IShellItem> folder;
     if (SUCCEEDED(
           WinUtils::SHCreateItemFromParsingName(aInitialDir.get(), nullptr,
                                                 IID_IShellItem,
                                                 getter_AddRefs(folder)))) {
       dialog->SetFolder(folder);
     }