Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTextControlSingleLine.cpp

Issue 2145903002: Add heuristic to LayoutTextControl::hasValidAvgCharWidth() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 LayoutUnit LayoutTextControlSingleLine::preferredContentLogicalWidth(float charW idth) const 224 LayoutUnit LayoutTextControlSingleLine::preferredContentLogicalWidth(float charW idth) const
225 { 225 {
226 int factor; 226 int factor;
227 bool includesDecoration = inputElement()->sizeShouldIncludeDecoration(factor ); 227 bool includesDecoration = inputElement()->sizeShouldIncludeDecoration(factor );
228 if (factor <= 0) 228 if (factor <= 0)
229 factor = 20; 229 factor = 20;
230 230
231 LayoutUnit result = LayoutUnit::fromFloatCeil(charWidth * factor); 231 LayoutUnit result = LayoutUnit::fromFloatCeil(charWidth * factor);
232 232
233 float maxCharWidth = 0.f; 233 float maxCharWidth = 0.f;
234 AtomicString family = styleRef().font().getFontDescription().family().family (); 234 const Font& font = style()->font();
235 AtomicString family = font.getFontDescription().family().family();
235 // Match the default system font to the width of MS Shell Dlg, the default 236 // Match the default system font to the width of MS Shell Dlg, the default
236 // font for textareas in Firefox, Safari Win and IE for some encodings (in 237 // font for textareas in Firefox, Safari Win and IE for some encodings (in
237 // IE, the default font is encoding specific). 4027 is the (xMax - xMin) 238 // IE, the default font is encoding specific). 4027 is the (xMax - xMin)
238 // value in the "head" font table for MS Shell Dlg. 239 // value in the "head" font table for MS Shell Dlg.
239 if (LayoutTheme::theme().needsHackForTextControlWithFontFamily(family)) 240 if (LayoutTheme::theme().needsHackForTextControlWithFontFamily(family))
240 maxCharWidth = scaleEmToUnits(4027); 241 maxCharWidth = scaleEmToUnits(4027);
241 else if (hasValidAvgCharWidth(family)) 242 else if (hasValidAvgCharWidth(font.primaryFont(), family))
242 maxCharWidth = roundf(styleRef().font().primaryFont()->maxCharWidth()); 243 maxCharWidth = roundf(font.primaryFont()->maxCharWidth());
243 244
244 // For text inputs, IE adds some extra width. 245 // For text inputs, IE adds some extra width.
245 if (maxCharWidth > 0.f) 246 if (maxCharWidth > 0.f)
246 result += maxCharWidth - charWidth; 247 result += maxCharWidth - charWidth;
247 248
248 if (includesDecoration) { 249 if (includesDecoration) {
249 HTMLElement* spinButton = innerSpinButtonElement(); 250 HTMLElement* spinButton = innerSpinButtonElement();
250 if (LayoutBox* spinLayoutObject = spinButton ? spinButton->layoutBox() : 0) { 251 if (LayoutBox* spinLayoutObject = spinButton ? spinButton->layoutBox() : 0) {
251 result += spinLayoutObject->borderAndPaddingLogicalWidth(); 252 result += spinLayoutObject->borderAndPaddingLogicalWidth();
252 // Since the width of spinLayoutObject is not calculated yet, spinLa youtObject->logicalWidth() returns 0. 253 // Since the width of spinLayoutObject is not calculated yet, spinLa youtObject->logicalWidth() returns 0.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // inner-editor element overflows the INPUT box intentionally, however it 377 // inner-editor element overflows the INPUT box intentionally, however it
377 // shouldn't affect outside of the INPUT box. So we ignore child overflow. 378 // shouldn't affect outside of the INPUT box. So we ignore child overflow.
378 } 379 }
379 380
380 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const 381 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const
381 { 382 {
382 return toHTMLInputElement(node()); 383 return toHTMLInputElement(node());
383 } 384 }
384 385
385 } // namespace blink 386 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698