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

Side by Side Diff: third_party/WebKit/Source/core/layout/line/InlineBox.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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 width().toFloat(), height().toFloat(), 139 width().toFloat(), height().toFloat(),
140 baselinePosition(AlphabeticBaseline), 140 baselinePosition(AlphabeticBaseline),
141 baselinePosition(IdeographicBaseline)); 141 baselinePosition(IdeographicBaseline));
142 } 142 }
143 #endif 143 #endif
144 144
145 LayoutUnit InlineBox::logicalHeight() const { 145 LayoutUnit InlineBox::logicalHeight() const {
146 if (hasVirtualLogicalHeight()) 146 if (hasVirtualLogicalHeight())
147 return virtualLogicalHeight(); 147 return virtualLogicalHeight();
148 148
149 if (getLineLayoutItem().isText()) 149 const SimpleFontData* fontData =
150 return m_bitfields.isText() ? LayoutUnit(getLineLayoutItem() 150 getLineLayoutItem().style(isFirstLineStyle())->font().primaryFont();
151 .style(isFirstLineStyle()) 151 if (getLineLayoutItem().isText()) {
152 ->getFontMetrics() 152 DCHECK(fontData);
153 .height()) 153 return m_bitfields.isText() && fontData
154 : LayoutUnit(); 154 ? LayoutUnit(fontData->getFontMetrics().height())
155 : LayoutUnit();
156 }
155 if (getLineLayoutItem().isBox() && parent()) 157 if (getLineLayoutItem().isBox() && parent())
156 return isHorizontal() ? LineLayoutBox(getLineLayoutItem()).size().height() 158 return isHorizontal() ? LineLayoutBox(getLineLayoutItem()).size().height()
157 : LineLayoutBox(getLineLayoutItem()).size().width(); 159 : LineLayoutBox(getLineLayoutItem()).size().width();
158 160
159 ASSERT(isInlineFlowBox()); 161 ASSERT(isInlineFlowBox());
160 LineLayoutBoxModel flowObject = boxModelObject(); 162 LineLayoutBoxModel flowObject = boxModelObject();
161 const FontMetrics& fontMetrics = 163 DCHECK(fontData);
162 getLineLayoutItem().style(isFirstLineStyle())->getFontMetrics(); 164 LayoutUnit result(fontData ? fontData->getFontMetrics().height() : 0);
163 LayoutUnit result(fontMetrics.height());
164 if (parent()) 165 if (parent())
165 result += flowObject.borderAndPaddingLogicalHeight(); 166 result += flowObject.borderAndPaddingLogicalHeight();
166 return result; 167 return result;
167 } 168 }
168 169
169 int InlineBox::baselinePosition(FontBaseline baselineType) const { 170 int InlineBox::baselinePosition(FontBaseline baselineType) const {
170 return boxModelObject().baselinePosition( 171 return boxModelObject().baselinePosition(
171 baselineType, m_bitfields.firstLine(), 172 baselineType, m_bitfields.firstLine(),
172 isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); 173 isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine);
173 } 174 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 419 }
419 420
420 void showLineTree(const blink::InlineBox* b) { 421 void showLineTree(const blink::InlineBox* b) {
421 if (b) 422 if (b)
422 b->showLineTreeForThis(); 423 b->showLineTreeForThis();
423 else 424 else
424 fprintf(stderr, "Cannot showLineTree for (nil) InlineBox.\n"); 425 fprintf(stderr, "Cannot showLineTree for (nil) InlineBox.\n");
425 } 426 }
426 427
427 #endif 428 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698