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
+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.
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();
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*);
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();
#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;
/*
- * 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
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) {
/*
- * 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
/**
* 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
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
/*
* 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
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.
/*
* 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
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;
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