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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSToLengthConversionData.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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/resolver/FontBuilder.cpp » ('j') | 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 CSSToLengthConversionData::FontSizes::FontSizes(const ComputedStyle* style, 47 CSSToLengthConversionData::FontSizes::FontSizes(const ComputedStyle* style,
48 const ComputedStyle* rootStyle) 48 const ComputedStyle* rootStyle)
49 : FontSizes(style->computedFontSize(), 49 : FontSizes(style->computedFontSize(),
50 rootStyle ? rootStyle->computedFontSize() : 1.0f, 50 rootStyle ? rootStyle->computedFontSize() : 1.0f,
51 &style->font()) {} 51 &style->font()) {}
52 52
53 float CSSToLengthConversionData::FontSizes::ex() const { 53 float CSSToLengthConversionData::FontSizes::ex() const {
54 ASSERT(m_font); 54 ASSERT(m_font);
55 const SimpleFontData* fontData = m_font->primaryFont();
56 DCHECK(fontData);
57
55 // FIXME: We have a bug right now where the zoom will be applied twice to EX 58 // FIXME: We have a bug right now where the zoom will be applied twice to EX
56 // units. We really need to compute EX using fontMetrics for the original 59 // units. We really need to compute EX using fontMetrics for the original
57 // specifiedSize and not use our actual constructed layoutObject font. 60 // specifiedSize and not use our actual constructed layoutObject font.
58 if (!m_font->getFontMetrics().hasXHeight()) 61 if (!fontData || !fontData->getFontMetrics().hasXHeight())
59 return m_em / 2.0f; 62 return m_em / 2.0f;
60 return m_font->getFontMetrics().xHeight(); 63 return fontData->getFontMetrics().xHeight();
61 } 64 }
62 65
63 float CSSToLengthConversionData::FontSizes::ch() const { 66 float CSSToLengthConversionData::FontSizes::ch() const {
64 ASSERT(m_font); 67 DCHECK(m_font);
65 return m_font->getFontMetrics().zeroWidth(); 68 const SimpleFontData* fontData = m_font->primaryFont();
69 DCHECK(fontData);
70 return fontData ? fontData->getFontMetrics().zeroWidth() : 0;
66 } 71 }
67 72
68 CSSToLengthConversionData::ViewportSize::ViewportSize( 73 CSSToLengthConversionData::ViewportSize::ViewportSize(
69 const LayoutViewItem& layoutViewItem) 74 const LayoutViewItem& layoutViewItem)
70 : m_size(!layoutViewItem.isNull() 75 : m_size(!layoutViewItem.isNull()
71 ? layoutViewItem.viewportSizeForViewportUnits() 76 ? layoutViewItem.viewportSizeForViewportUnits()
72 : DoubleSize()) {} 77 : DoubleSize()) {}
73 78
74 CSSToLengthConversionData::CSSToLengthConversionData( 79 CSSToLengthConversionData::CSSToLengthConversionData(
75 const ComputedStyle* style, 80 const ComputedStyle* style,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 case CSSPrimitiveValue::UnitType::Chs: 176 case CSSPrimitiveValue::UnitType::Chs:
172 return value * chFontSize(); 177 return value * chFontSize();
173 178
174 default: 179 default:
175 ASSERT_NOT_REACHED(); 180 ASSERT_NOT_REACHED();
176 return 0; 181 return 0;
177 } 182 }
178 } 183 }
179 184
180 } // namespace blink 185 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/resolver/FontBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698