Diff
Modified: trunk/Source/WebCore/ChangeLog (108260 => 108261)
--- trunk/Source/WebCore/ChangeLog 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/ChangeLog 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,3 +1,37 @@
+2012-02-18 Jon Lee <[email protected]>
+
+ HTML input file control "No File Selected" needs more room in some languages
+ https://bugs.webkit.org/show_bug.cgi?id=32366
+ <rdar://problem/4481028>
+
+ Reviewed by David Hyatt.
+
+ The patch exposes a function to return the "no file(s) selected" label text.
+
+ * rendering/RenderTheme.cpp:
+ (WebCore::RenderTheme::fileListDefaultLabel): Added to expose the text for the label in
+ file upload controls when nothing has been selected.
+ (WebCore::RenderTheme::fileListNameForWidth): Refactor to use fileListDefaultLabel().
+ * rendering/RenderTheme.h: Change fileListNameForWidth() to be a const function.
+
+ * rendering/RenderThemeMac.h: Update fileListNameForWidth() to be a const function for
+ platform implementations.
+ * rendering/RenderThemeMac.mm:
+ (WebCore::RenderThemeMac::fileListNameForWidth): Refactor to use fileListDefaultLabel().
+
+ Update fileListNameForWidth() to be a const function for platform implementations.
+ * platform/gtk/RenderThemeGtk.h:
+ * platform/gtk/RenderThemeGtk.cpp:
+ * platform/qt/RenderThemeQt.h:
+ * platform/qt/RenderThemeQt.cpp:
+
+ * rendering/RenderFileUploadControl.cpp:
+ (WebCore::RenderFileUploadControl::computePreferredLogicalWidths): Change the calculation
+ of the max preferred logical width. Calculate the length of the "no file(s) selected" text,
+ and include the button and after-button margin. Take the max of that and the original
+ default width, which was a string of 34 (defaultWidthNumChars) "0"'s, in the case that the
+ label text is too short.
+
2012-02-20 Gavin Barraclough <[email protected]>
Rubber stamped by Sam Weinig.
Modified: trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp (108260 => 108261)
--- trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp 2012-02-20 21:55:38 UTC (rev 108261)
@@ -701,7 +701,7 @@
return true;
}
-String RenderThemeGtk::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed)
+String RenderThemeGtk::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
{
if (width <= 0)
return String();
Modified: trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h (108260 => 108261)
--- trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h 2012-02-20 21:55:38 UTC (rev 108261)
@@ -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);
+ virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
void platformInit();
static void setTextInputBorders(RenderStyle*);
Modified: trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp (108260 => 108261)
--- trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp 2012-02-20 21:55:38 UTC (rev 108261)
@@ -845,7 +845,7 @@
return static_cast<QGuiApplication*>(qApp)->styleHints()->cursorFlashTime() / 1000.0 / 2.0;
}
-String RenderThemeQt::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width)
+String RenderThemeQt::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width) const
{
if (width <= 0)
return String();
Modified: trunk/Source/WebCore/platform/qt/RenderThemeQt.h (108260 => 108261)
--- trunk/Source/WebCore/platform/qt/RenderThemeQt.h 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/platform/qt/RenderThemeQt.h 2012-02-20 21:55:38 UTC (rev 108261)
@@ -151,7 +151,7 @@
#endif
virtual void computeSizeBasedOnStyle(RenderStyle*) const = 0;
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width);
+ virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width) const;
virtual QRect inflateButtonRect(const QRect& originalRect) const;
Modified: trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -178,10 +178,15 @@
else {
// Figure out how big the filename space needs to be for a given number of characters
// (using "0" as the nominal character).
- const UChar ch = '0';
- const String str = String(&ch, 1);
- float charWidth = font.width(constructTextRun(this, font, str, style, TextRun::AllowTrailingExpansion));
- m_maxPreferredLogicalWidth = (int)ceilf(charWidth * defaultWidthNumChars);
+ const UChar character = '0';
+ const String characterAsString = String(&character, 1);
+ float minDefaultLabelWidth = defaultWidthNumChars * font.width(constructTextRun(this, font, characterAsString, style, TextRun::AllowTrailingExpansion));
+
+ const String label = theme()->fileListDefaultLabel(node()->toInputElement()->multiple());
+ float defaultLabelWidth = font.width(constructTextRun(this, font, label, style, TextRun::AllowTrailingExpansion));
+ if (HTMLInputElement* button = uploadButton())
+ defaultLabelWidth += button->renderer()->maxPreferredLogicalWidth() + afterButtonSpacing;
+ m_maxPreferredLogicalWidth = static_cast<int>(ceilf(max(minDefaultLabelWidth, defaultLabelWidth)));
}
if (style->minWidth().isFixed() && style->minWidth().value() > 0) {
Modified: trunk/Source/WebCore/rendering/RenderFileUploadControl.h (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderFileUploadControl.h 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderFileUploadControl.h 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderTheme.cpp 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,7 +1,7 @@
/**
* This file is part of the theme implementation for form controls in WebCore.
*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Computer, Inc.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -1125,18 +1125,21 @@
return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
}
-String RenderTheme::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed)
+String RenderTheme::fileListDefaultLabel(bool multipleFilesAllowed) const
{
+ if (multipleFilesAllowed)
+ return fileButtonNoFilesSelectedLabel();
+ return fileButtonNoFileSelectedLabel();
+}
+
+String RenderTheme::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
+{
if (width <= 0)
return String();
String string;
- if (filenames.isEmpty()) {
- if (multipleFilesAllowed)
- string = fileButtonNoFilesSelectedLabel();
- else
- string = fileButtonNoFileSelectedLabel();
- }
+ if (filenames.isEmpty())
+ string = fileListDefaultLabel(multipleFilesAllowed);
else if (filenames.size() == 1)
string = pathGetFileName(filenames[0]);
else
Modified: trunk/Source/WebCore/rendering/RenderTheme.h (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderTheme.h 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderTheme.h 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,7 +1,7 @@
/*
* This file is part of the theme implementation for form controls in WebCore.
*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Computer, Inc.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -214,7 +214,8 @@
virtual bool popsMenuByArrowKeys() const { return false; }
virtual bool popsMenuBySpaceOrReturn() const { return false; }
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed);
+ virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
+ virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
protected:
// The platform selection color.
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderThemeMac.h 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h 2012-02-20 21:55:38 UTC (rev 108261)
@@ -1,7 +1,7 @@
/*
* This file is part of the theme implementation for form controls in WebCore.
*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Computer, Inc.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -175,7 +175,7 @@
virtual bool shouldShowPlaceholderWhenFocused() const;
private:
- virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed);
+ virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width, bool multipleFilesAllowed) const;
LayoutRect inflateRect(const LayoutRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (108260 => 108261)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2012-02-20 21:52:00 UTC (rev 108260)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2012-02-20 21:55:38 UTC (rev 108261)
@@ -2115,18 +2115,14 @@
return m_textField.get();
}
-String RenderThemeMac::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed)
+String RenderThemeMac::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed) const
{
if (width <= 0)
return String();
String strToTruncate;
- if (filenames.isEmpty()) {
- if (multipleFilesAllowed)
- strToTruncate = fileButtonNoFilesSelectedLabel();
- else
- strToTruncate = fileButtonNoFileSelectedLabel();
- }
+ if (filenames.isEmpty())
+ strToTruncate = fileListDefaultLabel(multipleFilesAllowed);
else if (filenames.size() == 1)
strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:(filenames[0])];
else