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

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

Issue 2149683002: Check for primaryFont in LayoutTextControl::getAvgCharWidth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase w/HEAD 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 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 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth ); ++i) 209 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth ); ++i)
210 fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWi thInvalidCharWidth[i])); 210 fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWi thInvalidCharWidth[i]));
211 } 211 }
212 212
213 return !fontFamiliesWithInvalidCharWidthMap->contains(family); 213 return !fontFamiliesWithInvalidCharWidthMap->contains(family);
214 } 214 }
215 215
216 float LayoutTextControl::getAvgCharWidth(const AtomicString& family) const 216 float LayoutTextControl::getAvgCharWidth(const AtomicString& family) const
217 { 217 {
218 const Font& font = style()->font(); 218 const Font& font = style()->font();
219
219 const SimpleFontData* primaryFont = font.primaryFont(); 220 const SimpleFontData* primaryFont = font.primaryFont();
220 if (hasValidAvgCharWidth(primaryFont, family)) 221 if (primaryFont && hasValidAvgCharWidth(primaryFont, family))
221 return roundf(primaryFont->avgCharWidth()); 222 return roundf(primaryFont->avgCharWidth());
222 223
223 const UChar ch = '0'; 224 const UChar ch = '0';
224 const String str = String(&ch, 1); 225 const String str = String(&ch, 1);
225 TextRun textRun = constructTextRun(font, str, styleRef(), TextRun::AllowTrai lingExpansion); 226 TextRun textRun = constructTextRun(font, str, styleRef(), TextRun::AllowTrai lingExpansion);
226 return font.width(textRun); 227 return font.width(textRun);
227 } 228 }
228 229
229 float LayoutTextControl::scaleEmToUnits(int x) const 230 float LayoutTextControl::scaleEmToUnits(int x) const
230 { 231 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element(); 286 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element();
286 LayoutObject* placeholderLayoutObject = placeholder ? placeholder->layoutObj ect() : nullptr; 287 LayoutObject* placeholderLayoutObject = placeholder ? placeholder->layoutObj ect() : nullptr;
287 if (!placeholderLayoutObject) 288 if (!placeholderLayoutObject)
288 return nullptr; 289 return nullptr;
289 if (relayoutChildren) 290 if (relayoutChildren)
290 layoutScope.setChildNeedsLayout(placeholderLayoutObject); 291 layoutScope.setChildNeedsLayout(placeholderLayoutObject);
291 return placeholderLayoutObject; 292 return placeholderLayoutObject;
292 } 293 }
293 294
294 } // namespace blink 295 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698