Diff
Modified: trunk/Source/WebCore/ChangeLog (110559 => 110560)
--- trunk/Source/WebCore/ChangeLog 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/ChangeLog 2012-03-13 14:38:27 UTC (rev 110560)
@@ -1,3 +1,35 @@
+2012-03-12 Kinuko Yasuda <[email protected]>
+
+ File upload control should use File.name() rather than File.path() to show chosen filenames
+ https://bugs.webkit.org/show_bug.cgi?id=80970
+
+ In some rare cases (e.g. files from FileSystem API or files created
+ using the newly added WebKit API) File.name has different displayName
+ from the basename of file.path, and in the file uploader controller we
+ should use File.name rather than File.path.
+
+ Reviewed by Kent Tamura.
+
+ No new tests: existing tests should pass as this should not change
+ behavior in regular use cases. (New behavior where File.name differs
+ from File.path can be only tested in chromeos environment, therefore
+ not adding new tests for that)
+
+ * platform/gtk/RenderThemeGtk.cpp:
+ (WebCore::RenderThemeGtk::fileListNameForWidth): Updated to handle FileList.
+ * platform/gtk/RenderThemeGtk.h:
+ * platform/qt/RenderThemeQt.cpp:
+ (WebCore::RenderThemeQt::fileListNameForWidth): Updated to handle FileList.
+ * platform/qt/RenderThemeQt.h:
+ * rendering/RenderFileUploadControl.cpp:
+ (WebCore::RenderFileUploadControl::fileTextValue): Changed to pass FileList rather than FileList->paths().
+ * rendering/RenderTheme.cpp:
+ (WebCore::RenderTheme::fileListNameForWidth): Updated to handle FileList and use File.name for displaying the file name.
+ * rendering/RenderTheme.h:
+ * rendering/RenderThemeMac.h:
+ * rendering/RenderThemeMac.mm:
+ (WebCore::RenderThemeMac::fileListNameForWidth): Updated to handle FileList.
+
2012-03-13 Kinuko Yasuda <[email protected]>
Allow WebFileChooser to return extra file info (like displayName) in addition to mere file paths
Modified: trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp (110559 => 110560)
--- trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp 2012-03-13 14:38:27 UTC (rev 110560)
@@ -26,6 +26,7 @@
#include "RenderThemeGtk.h"
#include "CSSValueKeywords.h"
+#include "FileList.h"
#include "FileSystem.h"
#include "GOwnPtr.h"
#include "Gradient.h"
@@ -701,7 +702,7 @@
return true;
}
-String RenderThemeGtk::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
+String RenderThemeGtk::fileListNameForWidth(const FileList* fileList, const Font& font, int width, bool multipleFilesAllowed) const
{
if (width <= 0)
return String();
@@ -710,12 +711,11 @@
if (multipleFilesAllowed)
string = fileButtonNoFilesSelectedLabel();
- if (filenames.size() == 1) {
- CString systemFilename = fileSystemRepresentation(filenames[0]);
+ if (fileList->length() == 1) {
+ CString systemFilename = fileSystemRepresentation(fileList->item(0)->path());
gchar* systemBasename = g_path_get_basename(systemFilename.data());
- stringByAdoptingFileSystemRepresentation(systemBasename, string);
- } else if (filenames.size() > 1)
- return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
+ } else if (fileList->length() > 1)
+ return StringTruncator::rightTruncate(multipleFileUploadText(fileList->length()), width, font, StringTruncator::EnableRoundingHacks);
return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
}
Modified: trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h (110559 => 110560)
--- trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h 2012-03-13 14:38:27 UTC (rev 110560)
@@ -181,7 +181,7 @@
virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&);
private:
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
+ virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const OVERRIDE;
void platformInit();
static void setTextInputBorders(RenderStyle*);
Modified: trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp (110559 => 110560)
--- trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp 2012-03-13 14:38:27 UTC (rev 110560)
@@ -35,6 +35,7 @@
#include "Chrome.h"
#include "ChromeClient.h"
#include "Color.h"
+#include "FileList.h"
#include "Font.h"
#include "FontSelector.h"
#include "GraphicsContext.h"
@@ -868,20 +869,20 @@
return static_cast<QGuiApplication*>(qApp)->styleHints()->cursorFlashTime() / 1000.0 / 2.0;
}
-String RenderThemeQt::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width) const
+String RenderThemeQt::fileListNameForWidth(const FileList* fileList, const Font& font, int width) const
{
if (width <= 0)
return String();
String string;
- if (filenames.isEmpty())
+ if (fileList->isEmpty())
string = fileButtonNoFileSelectedLabel();
- else if (filenames.size() == 1) {
- String fname = filenames[0];
+ else if (fileList->length() == 1) {
+ String fname = fileList->item(0)->path();
QFontMetrics fm(font.font());
string = fm.elidedText(fname, Qt::ElideLeft, width);
} else {
- int n = filenames.size();
+ int n = fileList->length();
string = QCoreApplication::translate("QWebPage", "%n file(s)",
"number of chosen file",
QCoreApplication::DefaultCodec, n);
Modified: trunk/Source/WebCore/platform/qt/RenderThemeQt.h (110559 => 110560)
--- trunk/Source/WebCore/platform/qt/RenderThemeQt.h 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/platform/qt/RenderThemeQt.h 2012-03-13 14:38:27 UTC (rev 110560)
@@ -155,7 +155,7 @@
#endif
virtual void computeSizeBasedOnStyle(RenderStyle*) const = 0;
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width) const;
+ virtual String fileListNameForWidth(const FileList*, const Font&, int width) const OVERRIDE;
virtual QRect inflateButtonRect(const QRect& originalRect) const;
Modified: trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp (110559 => 110560)
--- trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp 2012-03-13 14:38:27 UTC (rev 110560)
@@ -236,7 +236,7 @@
{
HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
ASSERT(input->files());
- return theme()->fileListNameForWidth(input->files()->paths(), style()->font(), maxFilenameWidth(), input->multiple());
+ return theme()->fileListNameForWidth(input->files(), style()->font(), maxFilenameWidth(), input->multiple());
}
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (110559 => 110560)
--- trunk/Source/WebCore/rendering/RenderTheme.cpp 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp 2012-03-13 14:38:27 UTC (rev 110560)
@@ -24,6 +24,7 @@
#include "CSSValueKeywords.h"
#include "Document.h"
+#include "FileList.h"
#include "FileSystem.h"
#include "FloatConversion.h"
#include "FocusController.h"
@@ -1137,18 +1138,18 @@
return fileButtonNoFileSelectedLabel();
}
-String RenderTheme::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
+String RenderTheme::fileListNameForWidth(const FileList* fileList, const Font& font, int width, bool multipleFilesAllowed) const
{
if (width <= 0)
return String();
String string;
- if (filenames.isEmpty())
+ if (fileList->isEmpty())
string = fileListDefaultLabel(multipleFilesAllowed);
- else if (filenames.size() == 1)
- string = pathGetFileName(filenames[0]);
+ else if (fileList->length() == 1)
+ string = fileList->item(0)->name();
else
- return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
+ return StringTruncator::rightTruncate(multipleFileUploadText(fileList->length()), width, font, StringTruncator::EnableRoundingHacks);
return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
}
Modified: trunk/Source/WebCore/rendering/RenderTheme.h (110559 => 110560)
--- trunk/Source/WebCore/rendering/RenderTheme.h 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/rendering/RenderTheme.h 2012-03-13 14:38:27 UTC (rev 110560)
@@ -36,6 +36,7 @@
namespace WebCore {
class Element;
+class FileList;
class HTMLInputElement;
class PopupMenu;
class RenderMenuList;
@@ -215,7 +216,7 @@
virtual bool popsMenuBySpaceOrReturn() const { return false; }
virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
+ virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
protected:
// The platform selection color.
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (110559 => 110560)
--- trunk/Source/WebCore/rendering/RenderThemeMac.h 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h 2012-03-13 14:38:27 UTC (rev 110560)
@@ -177,7 +177,7 @@
virtual bool shouldShowPlaceholderWhenFocused() const;
private:
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
+ virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const OVERRIDE;
LayoutRect inflateRect(const LayoutRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (110559 => 110560)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2012-03-13 14:09:46 UTC (rev 110559)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2012-03-13 14:38:27 UTC (rev 110560)
@@ -26,6 +26,7 @@
#import "CSSValueKeywords.h"
#import "Document.h"
#import "Element.h"
+#import "FileList.h"
#import "FrameView.h"
#import "GraphicsContextCG.h"
#import "HTMLInputElement.h"
@@ -2142,18 +2143,18 @@
return m_textField.get();
}
-String RenderThemeMac::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
+String RenderThemeMac::fileListNameForWidth(const FileList* fileList, const Font& font, int width, bool multipleFilesAllowed) const
{
if (width <= 0)
return String();
String strToTruncate;
- if (filenames.isEmpty())
+ if (fileList->isEmpty())
strToTruncate = fileListDefaultLabel(multipleFilesAllowed);
- else if (filenames.size() == 1)
- strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:(filenames[0])];
+ else if (fileList->length() == 1)
+ strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:(fileList->item(0)->path())];
else
- return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
+ return StringTruncator::rightTruncate(multipleFileUploadText(fileList->length()), width, font, StringTruncator::EnableRoundingHacks);
return StringTruncator::centerTruncate(strToTruncate, width, font, StringTruncator::EnableRoundingHacks);
}