HTML input file control "No File Selected" needs more room in some languages
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Feb 2012 21:55:38 +0000 (21:55 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Feb 2012 21:55:38 +0000 (21:55 +0000)
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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108261 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/RenderThemeGtk.cpp
Source/WebCore/platform/gtk/RenderThemeGtk.h
Source/WebCore/platform/qt/RenderThemeQt.cpp
Source/WebCore/platform/qt/RenderThemeQt.h
Source/WebCore/rendering/RenderFileUploadControl.cpp
Source/WebCore/rendering/RenderFileUploadControl.h
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm

index 357aed1..66b088e 100644 (file)
@@ -1,3 +1,37 @@
+2012-02-18  Jon Lee  <jonlee@apple.com>
+
+        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  <barraclough@apple.com>
 
         Rubber stamped by Sam Weinig.
index f1620a7..bb67eaf 100644 (file)
@@ -701,7 +701,7 @@ static bool stringByAdoptingFileSystemRepresentation(gchar* systemFilename, Stri
     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();
index ad7990e..c26f9c9 100644 (file)
@@ -181,7 +181,7 @@ protected:
     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*);
index 18df290..00b8b1c 100644 (file)
@@ -845,7 +845,7 @@ double RenderThemeQt::caretBlinkInterval() const
     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();
index 1393536..cdaaa98 100644 (file)
@@ -151,7 +151,7 @@ protected:
 #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;
 
index 7ca411a..a927f3f 100644 (file)
@@ -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 @@ void RenderFileUploadControl::computePreferredLogicalWidths()
     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) {
index 30ee623..11d959d 100644 (file)
@@ -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
index d93a27e..6be2f5e 100644 (file)
@@ -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 @@ Color RenderTheme::focusRingColor()
     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
index c243b78..f65b852 100644 (file)
@@ -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 @@ public:
     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.
index dc1af04..25065c4 100644 (file)
@@ -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 @@ protected:
     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;
 
index e405f6c..cd566e8 100644 (file)
@@ -2115,18 +2115,14 @@ NSTextFieldCell* RenderThemeMac::textField() const
     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