Reviewed by Dan Bernstein.
Make textarea and text input metrics more closely match IEs.
This involves:
-set text input width to size*avgCharWidth + maxCharWidth - avgCharWidth
-set textarea width to cols*avgCharWidth
-Make default CSS match IEs
-Correctly initializing m_avgCharWidth and m_maxCharWidth for each platform and SVG.
Those values for textarea and inputs were derived by doing a ton of manual
testing of IE's width values for various textareas and fonts. On Windows we match
IE exactly except for a couple fonts of the ~12 tested.
To get the average and max character width of a font, we do the following
for each platform:
-Win: TextMetrics expose avgCharWidth and maxCharWidth
-SVG: avgCharWidth = width of an '0', fallback on width of a space glyph, then m_xHeight
maxCharWidth = width of a 'W' for roman fonts, fallback on m_ascent
-Linux: avgCharWidth = width of an '0', fallback on m_xHeight
maxCharWidth = max of avgCharWidth and m_ascent
-Mac: Calculate the avgCharWidth and grab the maxCharWidth off the font.
If either one is non-positive, then calculate the value using the Linux approach.
Tests: fast/forms/text-control-intrinsic-widths.html
fast/forms/textarea-metrics.html
svg/custom/svg-fonts-in-text-controls.html
* css/html4.css:
* css/themeWin.css:
* platform/graphics/SimpleFontData.cpp:
(WebCore::SimpleFontData::SimpleFontData):
(WebCore::SimpleFontData::initCharWidths):
* platform/graphics/SimpleFontData.h:
(WebCore::SimpleFontData::maxCharWidth):
(WebCore::SimpleFontData::avgCharWidth):
* platform/graphics/chromium/SimpleFontDataChromiumWin.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/chromium/SimpleFontDataLinux.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/gtk/SimpleFontDataGtk.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/gtk/SimpleFontDataPango.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/mac/SimpleFontDataMac.mm:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/qt/SimpleFontDataQt.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/win/SimpleFontDataCairoWin.cpp:
(WebCore::SimpleFontData::platformInit):
(WebCore::SimpleFontData::platformCharWidthInit):
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::SimpleFontData::initGDIFont):
* platform/graphics/wx/SimpleFontDataWx.cpp:
(WebCore::SimpleFontData::platformCharWidthInit):
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::calcPrefWidths):
* rendering/RenderTextControlMultiLine.cpp:
(WebCore::RenderTextControlMultiLine::createInnerTextStyle):
* rendering/RenderTextControlSingleLine.cpp:
(WebCore::RenderTextControlSingleLine::preferredContentWidth):
git-svn-id: svn://svn.chromium.org/blink/trunk@43007 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f62cdc1..af9a2d7 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,69 @@
+2009-04-24 Ojan Vafai <ojan@chromium.org>
+
+ Reviewed by Dan Bernstein.
+
+ Make textarea and text input metrics more closely match IEs.
+
+ This involves:
+ -set text input width to size*avgCharWidth + maxCharWidth - avgCharWidth
+ -set textarea width to cols*avgCharWidth
+ -Make default CSS match IEs
+ -Correctly initializing m_avgCharWidth and m_maxCharWidth for each platform and SVG.
+
+ Those values for textarea and inputs were derived by doing a ton of manual
+ testing of IE's width values for various textareas and fonts. On Windows we match
+ IE exactly except for a couple fonts of the ~12 tested.
+
+ To get the average and max character width of a font, we do the following
+ for each platform:
+ -Win: TextMetrics expose avgCharWidth and maxCharWidth
+ -SVG: avgCharWidth = width of an '0', fallback on width of a space glyph, then m_xHeight
+ maxCharWidth = width of a 'W' for roman fonts, fallback on m_ascent
+ -Linux: avgCharWidth = width of an '0', fallback on m_xHeight
+ maxCharWidth = max of avgCharWidth and m_ascent
+ -Mac: Calculate the avgCharWidth and grab the maxCharWidth off the font.
+ If either one is non-positive, then calculate the value using the Linux approach.
+
+ Tests: fast/forms/text-control-intrinsic-widths.html
+ fast/forms/textarea-metrics.html
+ svg/custom/svg-fonts-in-text-controls.html
+
+ * css/html4.css:
+ * css/themeWin.css:
+ * platform/graphics/SimpleFontData.cpp:
+ (WebCore::SimpleFontData::SimpleFontData):
+ (WebCore::SimpleFontData::initCharWidths):
+ * platform/graphics/SimpleFontData.h:
+ (WebCore::SimpleFontData::maxCharWidth):
+ (WebCore::SimpleFontData::avgCharWidth):
+ * platform/graphics/chromium/SimpleFontDataChromiumWin.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/chromium/SimpleFontDataLinux.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/gtk/SimpleFontDataGtk.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/gtk/SimpleFontDataPango.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/mac/SimpleFontDataMac.mm:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/qt/SimpleFontDataQt.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/win/SimpleFontDataCGWin.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/win/SimpleFontDataCairoWin.cpp:
+ (WebCore::SimpleFontData::platformInit):
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * platform/graphics/win/SimpleFontDataWin.cpp:
+ (WebCore::SimpleFontData::initGDIFont):
+ * platform/graphics/wx/SimpleFontDataWx.cpp:
+ (WebCore::SimpleFontData::platformCharWidthInit):
+ * rendering/RenderTextControl.cpp:
+ (WebCore::RenderTextControl::calcPrefWidths):
+ * rendering/RenderTextControlMultiLine.cpp:
+ (WebCore::RenderTextControlMultiLine::createInnerTextStyle):
+ * rendering/RenderTextControlSingleLine.cpp:
+ (WebCore::RenderTextControlSingleLine::preferredContentWidth):
+
2009-04-29 Brady Eidson <beidson@apple.com>
Reviewed by Darin Adler.
diff --git a/WebCore/css/html4.css b/WebCore/css/html4.css
index d14d7a1..6646fff 100644
--- a/WebCore/css/html4.css
+++ b/WebCore/css/html4.css
@@ -359,6 +359,8 @@
-webkit-box-orient: vertical;
resize: auto;
cursor: auto;
+ margin: 1px 0;
+ padding: 2px;
}
input::-webkit-input-placeholder {
diff --git a/WebCore/css/themeWin.css b/WebCore/css/themeWin.css
index 69a7f2f..e6916bb2 100644
--- a/WebCore/css/themeWin.css
+++ b/WebCore/css/themeWin.css
@@ -107,8 +107,4 @@
textarea {
font-family: monospace;
- margin: 1px 0;
-
- /* Matches IE */
- padding: 2px;
}
diff --git a/WebCore/platform/graphics/SimpleFontData.cpp b/WebCore/platform/graphics/SimpleFontData.cpp
index a16a9b9..a2c51c9 100644
--- a/WebCore/platform/graphics/SimpleFontData.cpp
+++ b/WebCore/platform/graphics/SimpleFontData.cpp
@@ -35,6 +35,7 @@
#if ENABLE(SVG_FONTS)
#include "SVGFontData.h"
+#include "SVGFontElement.h"
#include "SVGFontFaceElement.h"
#include "SVGGlyphElement.h"
#endif
@@ -42,6 +43,8 @@
#include <wtf/MathExtras.h>
#include <wtf/UnusedParam.h>
+using namespace std;
+
namespace WebCore {
SimpleFontData::SimpleFontData(const FontPlatformData& f, bool customFont, bool loading, SVGFontData* svgFontData)
@@ -59,22 +62,36 @@
UNUSED_PARAM(svgFontData);
#else
if (SVGFontFaceElement* svgFontFaceElement = svgFontData ? svgFontData->svgFontFaceElement() : 0) {
- m_unitsPerEm = svgFontFaceElement->unitsPerEm();
+ m_unitsPerEm = svgFontFaceElement->unitsPerEm();
- double scale = f.size();
- if (m_unitsPerEm)
- scale /= m_unitsPerEm;
+ double scale = f.size();
+ if (m_unitsPerEm)
+ scale /= m_unitsPerEm;
m_ascent = static_cast<int>(svgFontFaceElement->ascent() * scale);
m_descent = static_cast<int>(svgFontFaceElement->descent() * scale);
m_xHeight = static_cast<int>(svgFontFaceElement->xHeight() * scale);
m_lineGap = 0.1f * f.size();
m_lineSpacing = m_ascent + m_descent + m_lineGap;
-
+
+ SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
+
+ Vector<SVGGlyphIdentifier> spaceGlyphs;
+ associatedFontElement->getGlyphIdentifiersForString(String(" ", 1), spaceGlyphs);
+ m_spaceWidth = spaceGlyphs.isEmpty() ? m_xHeight : static_cast<float>(spaceGlyphs.first().horizontalAdvanceX * scale);
+
+ Vector<SVGGlyphIdentifier> numeralZeroGlyphs;
+ associatedFontElement->getGlyphIdentifiersForString(String("0", 1), numeralZeroGlyphs);
+ m_avgCharWidth = numeralZeroGlyphs.isEmpty() ? m_spaceWidth : static_cast<float>(numeralZeroGlyphs.first().horizontalAdvanceX * scale);
+
+ Vector<SVGGlyphIdentifier> letterWGlyphs;
+ associatedFontElement->getGlyphIdentifiersForString(String("W", 1), letterWGlyphs);
+ m_maxCharWidth = letterWGlyphs.isEmpty() ? m_ascent : static_cast<float>(letterWGlyphs.first().horizontalAdvanceX * scale);
+
+ // FIXME: is there a way we can get the space glyph from the SVGGlyphIdentifier above?
m_spaceGlyph = 0;
- m_spaceWidth = 0;
- m_adjustedSpaceWidth = 0;
determinePitch();
+ m_adjustedSpaceWidth = roundf(m_spaceWidth);
m_missingGlyphData.fontData = this;
m_missingGlyphData.glyph = 0;
return;
@@ -83,6 +100,28 @@
platformInit();
platformGlyphInit();
+ platformCharWidthInit();
+}
+
+// Estimates of avgCharWidth and maxCharWidth for platforms that don't support accessing these values from the font.
+void SimpleFontData::initCharWidths()
+{
+ GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
+
+ // Treat the width of a '0' as the avgCharWidth.
+ if (m_avgCharWidth <= 0.f && glyphPageZero) {
+ static const UChar32 digitZeroChar = '0';
+ Glyph digitZeroGlyph = glyphPageZero->glyphDataForCharacter(digitZeroChar).glyph;
+ if (digitZeroGlyph)
+ m_avgCharWidth = widthForGlyph(digitZeroGlyph);
+ }
+
+ // If we can't retrieve the width of a '0', fall back to the x height.
+ if (m_avgCharWidth <= 0.f)
+ m_avgCharWidth = m_xHeight;
+
+ if (m_maxCharWidth <= 0.f)
+ m_maxCharWidth = max<float>(m_avgCharWidth, m_ascent);
}
#if !PLATFORM(QT)
diff --git a/WebCore/platform/graphics/SimpleFontData.h b/WebCore/platform/graphics/SimpleFontData.h
index d2dd0b9..09e9b6d 100644
--- a/WebCore/platform/graphics/SimpleFontData.h
+++ b/WebCore/platform/graphics/SimpleFontData.h
@@ -69,6 +69,8 @@
int descent() const { return m_descent; }
int lineSpacing() const { return m_lineSpacing; }
int lineGap() const { return m_lineGap; }
+ float maxCharWidth() const { return m_maxCharWidth; }
+ float avgCharWidth() const { return m_avgCharWidth; }
float xHeight() const { return m_xHeight; }
unsigned unitsPerEm() const { return m_unitsPerEm; }
@@ -137,8 +139,11 @@
private:
void platformInit();
void platformGlyphInit();
+ void platformCharWidthInit();
void platformDestroy();
+ void initCharWidths();
+
void commonInit();
#if PLATFORM(WIN)
@@ -152,6 +157,8 @@
int m_descent;
int m_lineSpacing;
int m_lineGap;
+ float m_maxCharWidth;
+ float m_avgCharWidth;
float m_xHeight;
unsigned m_unitsPerEm;
diff --git a/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp b/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp
index 06e997f..01dddad 100644
--- a/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp
+++ b/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp
@@ -91,6 +91,11 @@
ReleaseDC(0, dc);
}
+void SimpleFontData::platformCharWidthInit()
+{
+ // charwidths are set in platformInit.
+}
+
void SimpleFontData::platformDestroy()
{
// We don't hash this on Win32, so it's effectively owned by us.
diff --git a/WebCore/platform/graphics/chromium/SimpleFontDataLinux.cpp b/WebCore/platform/graphics/chromium/SimpleFontDataLinux.cpp
index a2b71f5..e4666a4 100644
--- a/WebCore/platform/graphics/chromium/SimpleFontDataLinux.cpp
+++ b/WebCore/platform/graphics/chromium/SimpleFontDataLinux.cpp
@@ -120,6 +120,11 @@
}
}
+void SimpleFontData::platformCharWidthInit()
+{
+ // charwidths are set in platformInit.
+}
+
void SimpleFontData::platformDestroy()
{
delete m_smallCapsFontData;
diff --git a/WebCore/platform/graphics/gtk/SimpleFontDataGtk.cpp b/WebCore/platform/graphics/gtk/SimpleFontDataGtk.cpp
index 4203a3c..ef24829 100644
--- a/WebCore/platform/graphics/gtk/SimpleFontDataGtk.cpp
+++ b/WebCore/platform/graphics/gtk/SimpleFontDataGtk.cpp
@@ -67,6 +67,13 @@
m_lineGap = m_lineSpacing - m_ascent - m_descent;
}
+void SimpleFontData::platformCharWidthInit()
+{
+ m_avgCharWidth = 0.f;
+ m_maxCharWidth = 0.f;
+ initCharWidths();
+}
+
void SimpleFontData::platformDestroy()
{
delete m_smallCapsFontData;
diff --git a/WebCore/platform/graphics/gtk/SimpleFontDataPango.cpp b/WebCore/platform/graphics/gtk/SimpleFontDataPango.cpp
index e345a8c..4d02bad 100644
--- a/WebCore/platform/graphics/gtk/SimpleFontDataPango.cpp
+++ b/WebCore/platform/graphics/gtk/SimpleFontDataPango.cpp
@@ -66,6 +66,13 @@
m_lineGap = m_lineSpacing - m_ascent - m_descent;
}
+void SimpleFontData::platformCharWidthInit()
+{
+ m_avgCharWidth = 0.f;
+ m_maxCharWidth = 0.f;
+ initCharWidths();
+}
+
void SimpleFontData::platformDestroy()
{
delete m_smallCapsFontData;
diff --git a/WebCore/platform/graphics/mac/SimpleFontDataMac.mm b/WebCore/platform/graphics/mac/SimpleFontDataMac.mm
index a3c10fa..6b9bfe1 100644
--- a/WebCore/platform/graphics/mac/SimpleFontDataMac.mm
+++ b/WebCore/platform/graphics/mac/SimpleFontDataMac.mm
@@ -274,6 +274,41 @@
m_xHeight = [m_font.font() xHeight];
}
+void SimpleFontData::platformCharWidthInit()
+{
+ m_avgCharWidth = 0.f;
+
+ // Calculate avgCharWidth according to http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6OS2.html
+ // We can try grabbing it out of the OS/2 table or via ATSFontGetHorizontalMetrics, but
+ // ATSFontGetHorizontalMetrics never seems to return a non-zero value and the OS/2 table
+ // contains zero for a large number of fonts.
+ GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
+ if (glyphPageZero) {
+ static int weights[] = { 64, 14, 27, 35, 100, 20, 14, 42, 63, 3, 6, 35, 20, 56, 56, 17, 4, 49, 56, 71, 31, 10, 18, 3, 18, 2, 166 };
+ int numGlyphs = 27;
+ ASSERT(numGlyphs == sizeof(weights) / sizeof(int));
+ // Compute the weighted sum of the space character and the lowercase letters in the Latin alphabet.
+ float sum = 0.f;
+ int totalWeight = 0;
+ for (int i = 0; i < numGlyphs; i++) {
+ Glyph glyph = glyphPageZero->glyphDataForCharacter((i < 26 ? i + 'a' : ' ')).glyph;
+ if (glyph) {
+ totalWeight += weights[i];
+ sum += widthForGlyph(glyph) * weights[i];
+ }
+ }
+ if (sum > 0.f && totalWeight > 0)
+ m_avgCharWidth = sum / totalWeight;
+ }
+
+ m_maxCharWidth = 0.f;
+ if (m_font.font())
+ m_maxCharWidth = [m_font.font() maximumAdvancement].width;
+
+ // Fallback to a cross-platform estimate, which will populate these values if they are non-positive.
+ initCharWidths();
+}
+
void SimpleFontData::platformDestroy()
{
#ifdef BUILDING_ON_TIGER
diff --git a/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp b/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp
index 6cf4e55..f87139f 100644
--- a/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp
+++ b/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp
@@ -59,6 +59,13 @@
m_missingGlyphData.glyph = 0;
}
+void SimpleFontData::platformCharWidthInit()
+{
+ m_avgCharWidth = 0.f;
+ m_maxCharWidth = 0.f;
+ initCharWidths();
+}
+
void SimpleFontData::platformDestroy()
{
}
diff --git a/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp b/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
index 8b5ab87..55636e8 100644
--- a/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
+++ b/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
@@ -116,6 +116,16 @@
}
}
+void SimpleFontData::platformCharWidthInit()
+{
+ // GDI Fonts init charwidths in initGDIFont.
+ if (!m_font.useGDI()) {
+ m_avgCharWidth = 0.f;
+ m_maxCharWidth = 0.f;
+ initCharWidths();
+ }
+}
+
void SimpleFontData::platformDestroy()
{
platformCommonDestroy();
diff --git a/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp b/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp
index 415f39c..1fa2b05 100644
--- a/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp
+++ b/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp
@@ -67,6 +67,8 @@
m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
m_lineGap = lroundf(textMetrics.tmExternalLeading * metricsMultiplier);
m_lineSpacing = m_ascent + m_descent + m_lineGap;
+ m_avgCharWidth = lroundf(textMetrics.tmAveCharWidth * metricsMultiplier);
+ m_maxCharWidth = lroundf(textMetrics.tmMaxCharWidth * metricsMultiplier);
OUTLINETEXTMETRIC metrics;
if (GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics) > 0) {
@@ -88,6 +90,11 @@
ReleaseDC(0, hdc);
}
+void SimpleFontData::platformCharWidthInit()
+{
+ // charwidths are set in platformInit.
+}
+
void SimpleFontData::platformDestroy()
{
cairo_font_face_destroy(m_font.fontFace());
diff --git a/WebCore/platform/graphics/win/SimpleFontDataWin.cpp b/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
index 9d5c3b9..561b1af 100644
--- a/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
+++ b/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
@@ -71,6 +71,8 @@
m_descent = textMetrics.tmDescent;
m_lineGap = textMetrics.tmExternalLeading;
m_lineSpacing = m_ascent + m_descent + m_lineGap;
+ m_avgCharWidth = textMetrics.tmAveCharWidth;
+ m_maxCharWidth = textMetrics.tmMaxCharWidth;
m_xHeight = m_ascent * 0.56f; // Best guess for xHeight if no x glyph is present.
GLYPHMETRICS gm;
diff --git a/WebCore/platform/graphics/wx/SimpleFontDataWx.cpp b/WebCore/platform/graphics/wx/SimpleFontDataWx.cpp
index d6a2dc3..1f1c410 100644
--- a/WebCore/platform/graphics/wx/SimpleFontDataWx.cpp
+++ b/WebCore/platform/graphics/wx/SimpleFontDataWx.cpp
@@ -57,6 +57,13 @@
}
}
+void SimpleFontData::platformCharWidthInit()
+{
+ m_avgCharWidth = 0.f;
+ m_maxCharWidth = 0.f;
+ initCharWidths();
+}
+
void SimpleFontData::platformDestroy()
{
delete m_smallCapsFontData;
diff --git a/WebCore/rendering/RenderTextControl.cpp b/WebCore/rendering/RenderTextControl.cpp
index c1244ca..9211da6 100644
--- a/WebCore/rendering/RenderTextControl.cpp
+++ b/WebCore/rendering/RenderTextControl.cpp
@@ -487,10 +487,8 @@
if (style()->width().isFixed() && style()->width().value() > 0)
m_minPrefWidth = m_maxPrefWidth = calcContentBoxWidth(style()->width().value());
else {
- // Figure out how big a text control needs to be for a given number of characters
- // (using "0" as the nominal character).
- const UChar ch = '0';
- float charWidth = style()->font().floatWidth(TextRun(&ch, 1, false, 0, 0, false, false, false));
+ // Use average character width. Matches IE.
+ float charWidth = style()->font().primaryFont()->avgCharWidth();
m_maxPrefWidth = preferredContentWidth(charWidth) + m_innerText->renderBox()->paddingLeft() + m_innerText->renderBox()->paddingRight();
}
diff --git a/WebCore/rendering/RenderTextControlMultiLine.cpp b/WebCore/rendering/RenderTextControlMultiLine.cpp
index 483f3aa..adf5cf2 100644
--- a/WebCore/rendering/RenderTextControlMultiLine.cpp
+++ b/WebCore/rendering/RenderTextControlMultiLine.cpp
@@ -118,10 +118,6 @@
textBlockStyle->setDisplay(BLOCK);
- // We're adding three extra pixels of padding to line textareas up with text fields.
- textBlockStyle->setPaddingLeft(Length(3, Fixed));
- textBlockStyle->setPaddingRight(Length(3, Fixed));
-
return textBlockStyle.release();
}
diff --git a/WebCore/rendering/RenderTextControlSingleLine.cpp b/WebCore/rendering/RenderTextControlSingleLine.cpp
index ab872c7..1a9e43e 100644
--- a/WebCore/rendering/RenderTextControlSingleLine.cpp
+++ b/WebCore/rendering/RenderTextControlSingleLine.cpp
@@ -39,6 +39,7 @@
#include "SearchPopupMenu.h"
#include "SelectionController.h"
#include "Settings.h"
+#include "SimpleFontData.h"
#include "TextControlInnerElements.h"
using namespace std;
@@ -404,6 +405,9 @@
int result = static_cast<int>(ceilf(charWidth * factor));
+ // For text inputs, IE adds some extra width.
+ result += style()->font().primaryFont()->maxCharWidth() - charWidth;
+
if (RenderBox* resultsRenderer = m_resultsButton ? m_resultsButton->renderBox() : 0)
result += resultsRenderer->borderLeft() + resultsRenderer->borderRight() +
resultsRenderer->paddingLeft() + resultsRenderer->paddingRight();