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

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

Issue 1651703002: More explicit LayoutUnit conversions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@evenMoarConstructors
Patch Set: Traits vs Properties vs Pandas Created 4 years, 10 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) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved.
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 { 360 {
361 // The direction of the block should determine what happens with wide lines. 361 // The direction of the block should determine what happens with wide lines.
362 // In particular with RTL blocks, wide lines should still spill out to the l eft. 362 // In particular with RTL blocks, wide lines should still spill out to the l eft.
363 if (isLeftToRightDirection) { 363 if (isLeftToRightDirection) {
364 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) 364 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
365 trailingSpaceRun->m_box->setLogicalWidth(std::max(LayoutUnit(), trai lingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth) ); 365 trailingSpaceRun->m_box->setLogicalWidth(std::max(LayoutUnit(), trai lingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth) );
366 return; 366 return;
367 } 367 }
368 368
369 if (trailingSpaceRun) 369 if (trailingSpaceRun)
370 trailingSpaceRun->m_box->setLogicalWidth(0); 370 trailingSpaceRun->m_box->setLogicalWidth(LayoutUnit());
371 else if (totalLogicalWidth > availableLogicalWidth) 371 else if (totalLogicalWidth > availableLogicalWidth)
372 logicalLeft -= (totalLogicalWidth - availableLogicalWidth); 372 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
373 } 373 }
374 374
375 static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, LayoutUnit& logicalLeft, LayoutUnit& totalLogicalWidt h, LayoutUnit availableLogicalWidth) 375 static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, LayoutUnit& logicalLeft, LayoutUnit& totalLogicalWidt h, LayoutUnit availableLogicalWidth)
376 { 376 {
377 // Wide lines spill out of the block based off direction. 377 // Wide lines spill out of the block based off direction.
378 // So even if text-align is right, if direction is LTR, wide lines should ov erflow out of the right 378 // So even if text-align is right, if direction is LTR, wide lines should ov erflow out of the right
379 // side of the block. 379 // side of the block.
380 if (isLeftToRightDirection) { 380 if (isLeftToRightDirection) {
381 if (trailingSpaceRun) { 381 if (trailingSpaceRun) {
382 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); 382 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
383 trailingSpaceRun->m_box->setLogicalWidth(0); 383 trailingSpaceRun->m_box->setLogicalWidth(LayoutUnit());
384 } 384 }
385 if (totalLogicalWidth < availableLogicalWidth) 385 if (totalLogicalWidth < availableLogicalWidth)
386 logicalLeft += availableLogicalWidth - totalLogicalWidth; 386 logicalLeft += availableLogicalWidth - totalLogicalWidth;
387 return; 387 return;
388 } 388 }
389 389
390 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) { 390 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
391 trailingSpaceRun->m_box->setLogicalWidth(std::max(LayoutUnit(), trailing SpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); 391 trailingSpaceRun->m_box->setLogicalWidth(std::max(LayoutUnit(), trailing SpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
392 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); 392 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
393 } else { 393 } else {
(...skipping 20 matching lines...) Expand all
414 int startOverhang; 414 int startOverhang;
415 int endOverhang; 415 int endOverhang;
416 LayoutObject* nextObject = nullptr; 416 LayoutObject* nextObject = nullptr;
417 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNex tObject = runWithNextObject->next()) { 417 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNex tObject = runWithNextObject->next()) {
418 if (!runWithNextObject->m_object->isOutOfFlowPositioned() && !runWithNex tObject->m_box->isLineBreak()) { 418 if (!runWithNextObject->m_object->isOutOfFlowPositioned() && !runWithNex tObject->m_box->isLineBreak()) {
419 nextObject = runWithNextObject->m_object; 419 nextObject = runWithNextObject->m_object;
420 break; 420 break;
421 } 421 }
422 } 422 }
423 layoutRubyRun->getOverhang(lineInfo.isFirstLine(), layoutRubyRun->style()->i sLeftToRightDirection() ? previousObject : nextObject, layoutRubyRun->style()->i sLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhan g); 423 layoutRubyRun->getOverhang(lineInfo.isFirstLine(), layoutRubyRun->style()->i sLeftToRightDirection() ? previousObject : nextObject, layoutRubyRun->style()->i sLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhan g);
424 setMarginStartForChild(*layoutRubyRun, -startOverhang); 424 setMarginStartForChild(*layoutRubyRun, LayoutUnit(-startOverhang));
425 setMarginEndForChild(*layoutRubyRun, -endOverhang); 425 setMarginEndForChild(*layoutRubyRun, LayoutUnit(-endOverhang));
426 } 426 }
427 427
428 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo, 428 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo,
429 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver ticalPositionCache, WordMeasurements& wordMeasurements) 429 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver ticalPositionCache, WordMeasurements& wordMeasurements)
430 { 430 {
431 HashSet<const SimpleFontData*> fallbackFonts; 431 HashSet<const SimpleFontData*> fallbackFonts;
432 GlyphOverflow glyphOverflow; 432 GlyphOverflow glyphOverflow;
433 433
434 const Font& font = layoutText->style(lineInfo.isFirstLine())->font(); 434 const Font& font = layoutText->style(lineInfo.isFirstLine())->font();
435 435
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 break; 539 break;
540 case CENTER: 540 case CENTER:
541 case WEBKIT_CENTER: 541 case WEBKIT_CENTER:
542 updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection( ), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); 542 updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection( ), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
543 break; 543 break;
544 case JUSTIFY: 544 case JUSTIFY:
545 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth); 545 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
546 if (expansionOpportunityCount) { 546 if (expansionOpportunityCount) {
547 if (trailingSpaceRun) { 547 if (trailingSpaceRun) {
548 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); 548 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
549 trailingSpaceRun->m_box->setLogicalWidth(0); 549 trailingSpaceRun->m_box->setLogicalWidth(LayoutUnit());
550 } 550 }
551 break; 551 break;
552 } 552 }
553 // Fall through 553 // Fall through
554 case TASTART: 554 case TASTART:
555 if (direction == LTR) 555 if (direction == LTR)
556 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirectio n(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); 556 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirectio n(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
557 else 557 else
558 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirecti on(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); 558 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirecti on(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
559 break; 559 break;
(...skipping 24 matching lines...) Expand all
584 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block 584 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block
585 // box is only affected if it is the first child of its parent element." 585 // box is only affected if it is the first child of its parent element."
586 // CSS3 "text-indent", "each-line" affects the first line of the block conta iner as well as each line after a forced line break, 586 // CSS3 "text-indent", "each-line" affects the first line of the block conta iner as well as each line after a forced line break,
587 // but does not affect lines after a soft wrap break. 587 // but does not affect lines after a soft wrap break.
588 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent( )->slowFirstChild() != this); 588 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent( )->slowFirstChild() != this);
589 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox() ->endsWithBreak(); 589 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox() ->endsWithBreak();
590 IndentTextOrNot indentText = requiresIndent(isFirstLine, isAfterHardLineBrea k, styleRef()); 590 IndentTextOrNot indentText = requiresIndent(isFirstLine, isAfterHardLineBrea k, styleRef());
591 LayoutUnit lineLogicalLeft; 591 LayoutUnit lineLogicalLeft;
592 LayoutUnit lineLogicalRight; 592 LayoutUnit lineLogicalRight;
593 LayoutUnit availableLogicalWidth; 593 LayoutUnit availableLogicalWidth;
594 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availa bleLogicalWidth, isFirstLine, indentText, 0); 594 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availa bleLogicalWidth, isFirstLine, indentText, LayoutUnit());
595 bool needsWordSpacing; 595 bool needsWordSpacing;
596 596
597 if (firstRun && firstRun->m_object->isAtomicInlineLevel()) { 597 if (firstRun && firstRun->m_object->isAtomicInlineLevel()) {
598 LayoutBox* layoutBox = toLayoutBox(firstRun->m_object); 598 LayoutBox* layoutBox = toLayoutBox(firstRun->m_object);
599 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, av ailableLogicalWidth, isFirstLine, indentText, layoutBox->logicalHeight()); 599 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, av ailableLogicalWidth, isFirstLine, indentText, layoutBox->logicalHeight());
600 } 600 }
601 601
602 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, line LogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements); 602 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, line LogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
603 // The widths of all runs are now known. We can now place every inline box ( and 603 // The widths of all runs are now known. We can now place every inline box ( and
604 // compute accurate widths for the inline flow boxes). 604 // compute accurate widths for the inline flow boxes).
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 1876
1877 return !it.atEnd(); 1877 return !it.atEnd();
1878 } 1878 }
1879 1879
1880 1880
1881 void LayoutBlockFlow::addOverflowFromInlineChildren() 1881 void LayoutBlockFlow::addOverflowFromInlineChildren()
1882 { 1882 {
1883 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); 1883 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
1884 // FIXME: Need to find another way to do this, since scrollbars could show w hen we don't want them to. 1884 // FIXME: Need to find another way to do this, since scrollbars could show w hen we don't want them to.
1885 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElem ent() && style()->isLeftToRightDirection()) 1885 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElem ent() && style()->isLeftToRightDirection())
1886 endPadding = 1; 1886 endPadding = LayoutUnit(1);
1887 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { 1887 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
1888 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); 1888 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
1889 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom()); 1889 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom());
1890 addContentsVisualOverflow(visualOverflow); 1890 addContentsVisualOverflow(visualOverflow);
1891 } 1891 }
1892 1892
1893 if (!containsInlineWithOutlineAndContinuation()) 1893 if (!containsInlineWithOutlineAndContinuation())
1894 return; 1894 return;
1895 1895
1896 // Add outline rects of continuations of descendant inlines into visual over flow of this block. 1896 // Add outline rects of continuations of descendant inlines into visual over flow of this block.
1897 LayoutRect outlineBoundsOfAllContinuations; 1897 LayoutRect outlineBoundsOfAllContinuations;
1898 for (InlineWalker walker(this); !walker.atEnd(); walker.advance()) { 1898 for (InlineWalker walker(this); !walker.atEnd(); walker.advance()) {
1899 const LayoutObject& o = *walker.current(); 1899 const LayoutObject& o = *walker.current();
1900 if (!isInlineWithOutlineAndContinuation(o)) 1900 if (!isInlineWithOutlineAndContinuation(o))
1901 continue; 1901 continue;
1902 1902
1903 Vector<LayoutRect> outlineRects; 1903 Vector<LayoutRect> outlineRects;
1904 toLayoutInline(o).addOutlineRectsForContinuations(outlineRects, LayoutPo int(), o.outlineRectsShouldIncludeBlockVisualOverflow()); 1904 toLayoutInline(o).addOutlineRectsForContinuations(outlineRects, LayoutPo int(), o.outlineRectsShouldIncludeBlockVisualOverflow());
1905 if (!outlineRects.isEmpty()) { 1905 if (!outlineRects.isEmpty()) {
1906 LayoutRect outlineBounds = unionRectEvenIfEmpty(outlineRects); 1906 LayoutRect outlineBounds = unionRectEvenIfEmpty(outlineRects);
1907 outlineBounds.inflate(o.styleRef().outlineOutsetExtent()); 1907 outlineBounds.inflate(LayoutUnit(o.styleRef().outlineOutsetExtent()) );
1908 outlineBoundsOfAllContinuations.unite(outlineBounds); 1908 outlineBoundsOfAllContinuations.unite(outlineBounds);
1909 } 1909 }
1910 } 1910 }
1911 addContentsVisualOverflow(outlineBoundsOfAllContinuations); 1911 addContentsVisualOverflow(outlineBoundsOfAllContinuations);
1912 } 1912 }
1913 1913
1914 void LayoutBlockFlow::deleteEllipsisLineBoxes() 1914 void LayoutBlockFlow::deleteEllipsisLineBoxes()
1915 { 1915 {
1916 ETextAlign textAlign = style()->textAlign(); 1916 ETextAlign textAlign = style()->textAlign();
1917 IndentTextOrNot indentText = IndentText; 1917 IndentTextOrNot indentText = IndentText;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 if (!line || !line->isFirstLineStyle()) 2107 if (!line || !line->isFirstLineStyle())
2108 return reason; 2108 return reason;
2109 // It's the RootInlineBox that paints the ::first-line background. Note that since it may be 2109 // It's the RootInlineBox that paints the ::first-line background. Note that since it may be
2110 // expensive to figure out if the first line is affected by any ::first-line selectors at all, 2110 // expensive to figure out if the first line is affected by any ::first-line selectors at all,
2111 // we just invalidate it unconditionally, since that's typically cheaper. 2111 // we just invalidate it unconditionally, since that's typically cheaper.
2112 invalidateDisplayItemClient(*line); 2112 invalidateDisplayItemClient(*line);
2113 return reason; 2113 return reason;
2114 } 2114 }
2115 2115
2116 } // namespace blink 2116 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlock.cpp ('k') | third_party/WebKit/Source/core/layout/LayoutBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698