| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/rendering/RenderParagraph.h" | 6 #include "sky/engine/core/rendering/RenderParagraph.h" |
| 7 | 7 |
| 8 #include "sky/engine/core/rendering/BidiRunForLine.h" | 8 #include "sky/engine/core/rendering/BidiRunForLine.h" |
| 9 #include "sky/engine/core/rendering/InlineIterator.h" | 9 #include "sky/engine/core/rendering/InlineIterator.h" |
| 10 #include "sky/engine/core/rendering/RenderLayer.h" | 10 #include "sky/engine/core/rendering/RenderLayer.h" |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 // Compute our overflow now. | 698 // Compute our overflow now. |
| 699 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxD
ataMap); | 699 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxD
ataMap); |
| 700 | 700 |
| 701 return lineBox; | 701 return lineBox; |
| 702 } | 702 } |
| 703 | 703 |
| 704 static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLi
ne, RootInlineBox* stopLine = 0) | 704 static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLi
ne, RootInlineBox* stopLine = 0) |
| 705 { | 705 { |
| 706 RootInlineBox* boxToDelete = startLine; | 706 RootInlineBox* boxToDelete = startLine; |
| 707 while (boxToDelete && boxToDelete != stopLine) { | 707 while (boxToDelete && boxToDelete != stopLine) { |
| 708 layoutState.updatePaintInvalidationRangeFromBox(boxToDelete); | |
| 709 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineB
oxTree(). | 708 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineB
oxTree(). |
| 710 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when tr
aversing. | 709 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when tr
aversing. |
| 711 RootInlineBox* next = boxToDelete->nextRootBox(); | 710 RootInlineBox* next = boxToDelete->nextRootBox(); |
| 712 boxToDelete->deleteLine(); | 711 boxToDelete->deleteLine(); |
| 713 boxToDelete = next; | 712 boxToDelete = next; |
| 714 } | 713 } |
| 715 } | 714 } |
| 716 | 715 |
| 717 void RenderParagraph::layoutRunsAndFloats(LineLayoutState& layoutState) | 716 void RenderParagraph::layoutRunsAndFloats(LineLayoutState& layoutState) |
| 718 { | 717 { |
| 719 // We want to skip ahead to the first dirty line | 718 // We want to skip ahead to the first dirty line |
| 720 InlineBidiResolver resolver; | 719 InlineBidiResolver resolver; |
| 721 RootInlineBox* startLine = determineStartPosition(layoutState, resolver); | 720 RootInlineBox* startLine = determineStartPosition(layoutState, resolver); |
| 722 | 721 |
| 723 // We also find the first clean line and extract these lines. We will add t
hem back | 722 // We also find the first clean line and extract these lines. We will add t
hem back |
| 724 // if we determine that we're able to synchronize after handling all our dir
ty lines. | 723 // if we determine that we're able to synchronize after handling all our dir
ty lines. |
| 725 InlineIterator cleanLineStart; | 724 InlineIterator cleanLineStart; |
| 726 BidiStatus cleanLineBidiStatus; | 725 BidiStatus cleanLineBidiStatus; |
| 727 if (!layoutState.isFullLayout() && startLine) | 726 if (!layoutState.isFullLayout() && startLine) |
| 728 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBi
diStatus); | 727 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBi
diStatus); |
| 729 | 728 |
| 730 if (startLine) { | 729 if (startLine) |
| 731 if (!layoutState.usesPaintInvalidationBounds()) | |
| 732 layoutState.setPaintInvalidationRange(logicalHeight()); | |
| 733 deleteLineRange(layoutState, startLine); | 730 deleteLineRange(layoutState, startLine); |
| 734 } | |
| 735 | 731 |
| 736 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineB
idiStatus); | 732 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineB
idiStatus); |
| 737 linkToEndLineIfNeeded(layoutState); | 733 linkToEndLineIfNeeded(layoutState); |
| 738 } | 734 } |
| 739 | 735 |
| 740 void RenderParagraph::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, | 736 void RenderParagraph::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, |
| 741 InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, | 737 InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, |
| 742 const BidiStatus& cleanLineBidiStatus) | 738 const BidiStatus& cleanLineBidiStatus) |
| 743 { | 739 { |
| 744 RenderStyle* styleToUse = style(); | 740 RenderStyle* styleToUse = style(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 802 |
| 807 // Now that the runs have been ordered, we create the line boxes. | 803 // Now that the runs have been ordered, we create the line boxes. |
| 808 // At the same time we figure out where border/padding/margin should
be applied for | 804 // At the same time we figure out where border/padding/margin should
be applied for |
| 809 // inline flow boxes. | 805 // inline flow boxes. |
| 810 | 806 |
| 811 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status
().context->level(), bidiRuns, endOfLine, layoutState.lineInfo(), verticalPositi
onCache, trailingSpaceRun, wordMeasurements); | 807 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status
().context->level(), bidiRuns, endOfLine, layoutState.lineInfo(), verticalPositi
onCache, trailingSpaceRun, wordMeasurements); |
| 812 | 808 |
| 813 bidiRuns.deleteRuns(); | 809 bidiRuns.deleteRuns(); |
| 814 resolver.markCurrentRunEmpty(); // FIXME: This can probably be repla
ced by an ASSERT (or just removed). | 810 resolver.markCurrentRunEmpty(); // FIXME: This can probably be repla
ced by an ASSERT (or just removed). |
| 815 | 811 |
| 816 if (lineBox) { | 812 if (lineBox) |
| 817 lineBox->setLineBreakInfo(endOfLine.object(), endOfLine.offset()
, resolver.status()); | 813 lineBox->setLineBreakInfo(endOfLine.object(), endOfLine.offset()
, resolver.status()); |
| 818 if (layoutState.usesPaintInvalidationBounds()) | |
| 819 layoutState.updatePaintInvalidationRangeFromBox(lineBox); | |
| 820 } | |
| 821 } | 814 } |
| 822 | 815 |
| 823 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) | 816 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) |
| 824 setStaticPositions(this, lineBreaker.positionedObjects()[i]); | 817 setStaticPositions(this, lineBreaker.positionedObjects()[i]); |
| 825 | 818 |
| 826 if (!layoutState.lineInfo().isEmpty()) | 819 if (!layoutState.lineInfo().isEmpty()) |
| 827 layoutState.lineInfo().setFirstLine(false); | 820 layoutState.lineInfo().setFirstLine(false); |
| 828 | 821 |
| 829 lineMidpointState.reset(); | 822 lineMidpointState.reset(); |
| 830 resolver.setPosition(endOfLine, numberOfIsolateAncestors(endOfLine)); | 823 resolver.setPosition(endOfLine, numberOfIsolateAncestors(endOfLine)); |
| 831 } | 824 } |
| 832 } | 825 } |
| 833 | 826 |
| 834 void RenderParagraph::linkToEndLineIfNeeded(LineLayoutState& layoutState) | 827 void RenderParagraph::linkToEndLineIfNeeded(LineLayoutState& layoutState) |
| 835 { | 828 { |
| 836 if (layoutState.endLine()) { | 829 if (layoutState.endLine()) { |
| 837 if (layoutState.endLineMatched()) { | 830 if (layoutState.endLineMatched()) { |
| 838 // Attach all the remaining lines, and then adjust their y-positions
as needed. | 831 // Attach all the remaining lines, and then adjust their y-positions
as needed. |
| 839 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop()
; | 832 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop()
; |
| 840 for (RootInlineBox* line = layoutState.endLine(); line; line = line-
>nextRootBox()) { | 833 for (RootInlineBox* line = layoutState.endLine(); line; line = line-
>nextRootBox()) { |
| 841 line->attachLine(); | 834 line->attachLine(); |
| 842 if (delta) { | 835 if (delta) |
| 843 layoutState.updatePaintInvalidationRangeFromBox(line, delta)
; | |
| 844 line->adjustBlockDirectionPosition(delta.toFloat()); | 836 line->adjustBlockDirectionPosition(delta.toFloat()); |
| 845 } | |
| 846 } | 837 } |
| 847 setLogicalHeight(lastRootBox()->lineBottomWithLeading()); | 838 setLogicalHeight(lastRootBox()->lineBottomWithLeading()); |
| 848 } else { | 839 } else { |
| 849 // Delete all the remaining lines. | 840 // Delete all the remaining lines. |
| 850 deleteLineRange(layoutState, layoutState.endLine()); | 841 deleteLineRange(layoutState, layoutState.endLine()); |
| 851 } | 842 } |
| 852 } | 843 } |
| 853 } | 844 } |
| 854 | 845 |
| 855 struct InlineMinMaxIterator { | 846 struct InlineMinMaxIterator { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics(); | 1227 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics(); |
| 1237 return fontMetrics.ascent() | 1228 return fontMetrics.ascent() |
| 1238 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f
ontMetrics.height()) / 2 | 1229 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f
ontMetrics.height()) / 2 |
| 1239 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b
orderRight() + paddingRight()); | 1230 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b
orderRight() + paddingRight()); |
| 1240 } | 1231 } |
| 1241 if (lastLineBox()) | 1232 if (lastLineBox()) |
| 1242 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox
())->fontMetrics().ascent(lastRootBox()->baselineType()); | 1233 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox
())->fontMetrics().ascent(lastRootBox()->baselineType()); |
| 1243 return -1; | 1234 return -1; |
| 1244 } | 1235 } |
| 1245 | 1236 |
| 1246 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope&
layoutScope, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidat
ionLogicalBottom, LayoutUnit beforeEdge, LayoutUnit afterEdge) | 1237 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope&
layoutScope, LayoutUnit beforeEdge, LayoutUnit afterEdge) |
| 1247 { | 1238 { |
| 1248 // Figure out if we should clear out our line boxes. | 1239 // Figure out if we should clear out our line boxes. |
| 1249 // FIXME: Handle resize eventually! | 1240 // FIXME: Handle resize eventually! |
| 1250 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren
; | 1241 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren
; |
| 1251 LineLayoutState layoutState(isFullLayout, paintInvalidationLogicalTop, paint
InvalidationLogicalBottom); | 1242 LineLayoutState layoutState(isFullLayout); |
| 1252 | 1243 |
| 1253 if (isFullLayout) | 1244 if (isFullLayout) |
| 1254 lineBoxes()->deleteLineBoxes(); | 1245 lineBoxes()->deleteLineBoxes(); |
| 1255 | 1246 |
| 1256 // Text truncation kicks in in two cases: | 1247 // Text truncation kicks in in two cases: |
| 1257 // 1) If your overflow isn't visible and your text-overflow-mode isn't c
lip. | 1248 // 1) If your overflow isn't visible and your text-overflow-mode isn't c
lip. |
| 1258 // 2) If you're an anonymous paragraph with a parent that satisfies #1. | 1249 // 2) If you're an anonymous paragraph with a parent that satisfies #1. |
| 1259 // FIXME: CSS3 says that descendants that are clipped must also know how to
truncate. This is insanely | 1250 // FIXME: CSS3 says that descendants that are clipped must also know how to
truncate. This is insanely |
| 1260 // difficult to figure out in general (especially in the middle of doing lay
out), so we only handle the | 1251 // difficult to figure out in general (especially in the middle of doing lay
out), so we only handle the |
| 1261 // simple case of an anonymous block truncating when it's parent is clipped. | 1252 // simple case of an anonymous block truncating when it's parent is clipped. |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 curr->adjustLogicalPosition(logicalLeft, 0); | 1573 curr->adjustLogicalPosition(logicalLeft, 0); |
| 1583 else | 1574 else |
| 1584 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW
idth - totalLogicalWidth), 0); | 1575 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW
idth - totalLogicalWidth), 0); |
| 1585 } | 1576 } |
| 1586 } | 1577 } |
| 1587 firstLine = false; | 1578 firstLine = false; |
| 1588 } | 1579 } |
| 1589 } | 1580 } |
| 1590 | 1581 |
| 1591 } // namespace blink | 1582 } // namespace blink |
| OLD | NEW |