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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2416033003: Remove unsafe getFontMetrics methods (Closed)
Patch Set: Address wkroman suggestions Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutText.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutText.cpp b/third_party/WebKit/Source/core/layout/LayoutText.cpp
index 4b8ed0a496b4e29bb6ac41e98ae247e7d2ba1931..a524f21e5166f32b51ee07716c6c958384762ea0 100644
--- a/third_party/WebKit/Source/core/layout/LayoutText.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutText.cpp
@@ -1316,9 +1316,15 @@ void LayoutText::computePreferredLogicalWidths(
m_lastLineLineMinWidth = currMaxWidth;
}
+ const SimpleFontData* fontData = f.primaryFont();
+ DCHECK(fontData);
+
GlyphOverflow glyphOverflow;
- glyphOverflow.setFromBounds(glyphBounds, f.getFontMetrics().floatAscent(),
- f.getFontMetrics().floatDescent(), m_maxWidth);
+ if (fontData) {
+ glyphOverflow.setFromBounds(
+ glyphBounds, fontData->getFontMetrics().floatAscent(),
+ fontData->getFontMetrics().floatDescent(), m_maxWidth);
+ }
// We shouldn't change our mind once we "know".
ASSERT(!m_knownToHaveNoOverflowAndNoFallbackFonts ||
(fallbackFonts.isEmpty() && glyphOverflow.isApproximatelyZero()));
@@ -1715,6 +1721,11 @@ float LayoutText::width(unsigned from,
if (!textLength())
return 0;
+ const SimpleFontData* fontData = f.primaryFont();
+ DCHECK(fontData);
+ if (!fontData)
+ return 0;
+
float w;
if (&f == &style()->font()) {
if (!style()->preserveNewline() && !from && len == textLength()) {
@@ -1726,8 +1737,8 @@ float LayoutText::width(unsigned from,
0, *fallbackFonts, *glyphBounds);
else
*glyphBounds =
- FloatRect(0, -f.getFontMetrics().floatAscent(), m_maxWidth,
- f.getFontMetrics().floatHeight());
+ FloatRect(0, -fontData->getFontMetrics().floatAscent(),
+ m_maxWidth, fontData->getFontMetrics().floatHeight());
w = m_maxWidth;
} else {
w = maxLogicalWidth();
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutMenuList.cpp ('k') | third_party/WebKit/Source/core/layout/LayoutTextControl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698