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

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

Issue 2416033003: Remove unsafe getFontMetrics methods (Closed)
Patch Set: 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc.
5 * All rights reserved. 5 * All rights reserved.
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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 for (; curr; curr = curr->nextLineBox()) 611 for (; curr; curr = curr->nextLineBox())
612 yield(LayoutRect(curr->topLeft(), curr->size())); 612 yield(LayoutRect(curr->topLeft(), curr->size()));
613 } 613 }
614 } 614 }
615 615
616 static inline void computeItemTopHeight(const LayoutInline* container, 616 static inline void computeItemTopHeight(const LayoutInline* container,
617 const RootInlineBox& rootBox, 617 const RootInlineBox& rootBox,
618 LayoutUnit* top, 618 LayoutUnit* top,
619 LayoutUnit* height) { 619 LayoutUnit* height) {
620 bool firstLine = rootBox.isFirstLineStyle(); 620 bool firstLine = rootBox.isFirstLineStyle();
621 auto metrics = rootBox.getLineLayoutItem().style(firstLine)->getFontMetrics(); 621 const SimpleFontData* fontData =
622 auto containerMetrics = container->style(firstLine)->getFontMetrics(); 622 rootBox.getLineLayoutItem().style(firstLine)->font().primaryFont();
623 const SimpleFontData* containerFontData =
624 container->style(firstLine)->font().primaryFont();
625 DCHECK(fontData && containerFontData);
626 if (!fontData || !containerFontData) {
627 *top = LayoutUnit();
628 *height = LayoutUnit();
629 return;
630 }
631 auto metrics = fontData->getFontMetrics();
632 auto containerMetrics = containerFontData->getFontMetrics();
623 *top = rootBox.logicalTop() + (metrics.ascent() - containerMetrics.ascent()); 633 *top = rootBox.logicalTop() + (metrics.ascent() - containerMetrics.ascent());
624 *height = LayoutUnit(containerMetrics.height()); 634 *height = LayoutUnit(containerMetrics.height());
625 } 635 }
626 636
627 template <typename GeneratorContext> 637 template <typename GeneratorContext>
628 void LayoutInline::generateCulledLineBoxRects( 638 void LayoutInline::generateCulledLineBoxRects(
629 GeneratorContext& yield, 639 GeneratorContext& yield,
630 const LayoutInline* container) const { 640 const LayoutInline* container) const {
631 if (!culledInlineFirstLineBox()) 641 if (!culledInlineFirstLineBox())
632 return; 642 return;
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 } 1343 }
1334 1344
1335 return LayoutUnit(style()->computedLineHeight()); 1345 return LayoutUnit(style()->computedLineHeight());
1336 } 1346 }
1337 1347
1338 int LayoutInline::baselinePosition(FontBaseline baselineType, 1348 int LayoutInline::baselinePosition(FontBaseline baselineType,
1339 bool firstLine, 1349 bool firstLine,
1340 LineDirectionMode direction, 1350 LineDirectionMode direction,
1341 LinePositionMode linePositionMode) const { 1351 LinePositionMode linePositionMode) const {
1342 ASSERT(linePositionMode == PositionOnContainingLine); 1352 ASSERT(linePositionMode == PositionOnContainingLine);
1343 const FontMetrics& fontMetrics = style(firstLine)->getFontMetrics(); 1353 const SimpleFontData* fontData = style(firstLine)->font().primaryFont();
1354 DCHECK(fontData);
1355 if (!fontData)
1356 return 0;
wkorman 2016/10/13 22:54:30 But then here 0 is the right value?
eae 2016/10/13 23:09:58 Changed to -1, good catch.
1357 const FontMetrics& fontMetrics = fontData->getFontMetrics();
1344 return (fontMetrics.ascent(baselineType) + 1358 return (fontMetrics.ascent(baselineType) +
1345 (lineHeight(firstLine, direction, linePositionMode) - 1359 (lineHeight(firstLine, direction, linePositionMode) -
1346 fontMetrics.height()) / 1360 fontMetrics.height()) /
1347 2) 1361 2)
1348 .toInt(); 1362 .toInt();
1349 } 1363 }
1350 1364
1351 LayoutSize LayoutInline::offsetForInFlowPositionedInline( 1365 LayoutSize LayoutInline::offsetForInFlowPositionedInline(
1352 const LayoutBox& child) const { 1366 const LayoutBox& child) const {
1353 // FIXME: This function isn't right with mixed writing modes. 1367 // FIXME: This function isn't right with mixed writing modes.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 paintInvalidator.invalidateDisplayItemClient(*box, invalidationReason); 1520 paintInvalidator.invalidateDisplayItemClient(*box, invalidationReason);
1507 } 1521 }
1508 1522
1509 // TODO(lunalu): Not to just dump 0, 0 as the x and y here 1523 // TODO(lunalu): Not to just dump 0, 0 as the x and y here
1510 LayoutRect LayoutInline::debugRect() const { 1524 LayoutRect LayoutInline::debugRect() const {
1511 IntRect linesBox = enclosingIntRect(linesBoundingBox()); 1525 IntRect linesBox = enclosingIntRect(linesBoundingBox());
1512 return LayoutRect(IntRect(0, 0, linesBox.width(), linesBox.height())); 1526 return LayoutRect(IntRect(0, 0, linesBox.width(), linesBox.height()));
1513 } 1527 }
1514 1528
1515 } // namespace blink 1529 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698