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

Side by Side Diff: sky/engine/core/rendering/RenderParagraph.cpp

Issue 762073002: Split more Paragraph-specific code from RenderBlock into RenderParagraph (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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 // 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 28 matching lines...) Expand all
39 { 39 {
40 } 40 }
41 41
42 RenderParagraph* RenderParagraph::createAnonymous(Document& document) 42 RenderParagraph* RenderParagraph::createAnonymous(Document& document)
43 { 43 {
44 RenderParagraph* renderer = new RenderParagraph(0); 44 RenderParagraph* renderer = new RenderParagraph(0);
45 renderer->setDocumentForAnonymous(&document); 45 renderer->setDocumentForAnonymous(&document);
46 return renderer; 46 return renderer;
47 } 47 }
48 48
49 RootInlineBox* RenderParagraph::lineAtIndex(int i) const
50 {
51 ASSERT(i >= 0);
52
53 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) {
54 if (!i--)
55 return box;
56 }
57
58 return 0;
59 }
60
61 int RenderParagraph::lineCount(const RootInlineBox* stopRootInlineBox, bool* fou nd) const
62 {
63 int count = 0;
64 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) {
65 count++;
66 if (box == stopRootInlineBox) {
67 if (found)
68 *found = true;
69 break;
70 }
71 }
72
73 return count;
74 }
75
76 int RenderParagraph::heightForLineCount(int l)
77 {
78 int count = 0;
79 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) {
80 if (++count == l)
81 return box->lineBottom() + borderBottom() + paddingBottom();
82 }
83
84 return -1;
85 }
86
87 GapRects RenderParagraph::inlineSelectionGaps(RenderBlock* rootBlock, const Layo utPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
88 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLog icalRight, const PaintInfo* paintInfo)
89 {
90 GapRects result;
91
92 bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth;
93
94 if (!firstLineBox()) {
95 if (containsStart) {
96 // Go ahead and update our lastLogicalTop to be the bottom of the bl ock. <hr>s or empty blocks with height can trip this
97 // case.
98 lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock ) + logicalHeight();
99 lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeigh t());
100 lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHei ght());
101 }
102 return result;
103 }
104
105 RootInlineBox* lastSelectedLine = 0;
106 RootInlineBox* curr;
107 for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = cur r->nextRootBox()) { }
108
109 // Now paint the gaps for the lines.
110 for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) {
111 LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock();
112 LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock();
113
114 if (!containsStart && !lastSelectedLine && selectionState() != Selection Start && selectionState() != SelectionBoth) {
115 result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPos ition, offsetFromRootBlock, lastLogicalTop,
116 lastLogicalLeft, lastLogicalRight, selTop, paintInfo));
117 }
118
119 LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth() , selTop + selHeight);
120 logicalRect.move(offsetFromRootBlock);
121 LayoutRect physicalRect = rootBlock->logicalRectToPhysicalRect(rootBlock PhysicalPosition, logicalRect);
122 if (!paintInfo || (physicalRect.y() < paintInfo->rect.maxY() && physical Rect.maxY() > paintInfo->rect.y()))
123 result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosi tion, offsetFromRootBlock, selTop, selHeight, paintInfo));
124
125 lastSelectedLine = curr;
126 }
127
128 if (containsStart && !lastSelectedLine) {
129 // VisibleSelection must start just after our last line.
130 lastSelectedLine = lastRootBox();
131 }
132
133 if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) {
134 // Go ahead and update our lastY to be the bottom of the last selected l ine.
135 lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + lastSelectedLine->selectionBottom();
136 lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine ->selectionBottom());
137 lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLi ne->selectionBottom());
138 }
139 return result;
140 }
141
49 void RenderParagraph::addOverflowFromChildren() 142 void RenderParagraph::addOverflowFromChildren()
50 { 143 {
51 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); 144 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
52 // FIXME: Need to find another way to do this, since scrollbars could show w hen we don't want them to. 145 // FIXME: Need to find another way to do this, since scrollbars could show w hen we don't want them to.
53 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElem ent() && style()->isLeftToRightDirection()) 146 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElem ent() && style()->isLeftToRightDirection())
54 endPadding = 1; 147 endPadding = 1;
55 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { 148 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
56 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); 149 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
57 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom()); 150 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom());
58 addContentsVisualOverflow(visualOverflow); 151 addContentsVisualOverflow(visualOverflow);
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1239
1147 if (styleToUse->collapseWhiteSpace()) 1240 if (styleToUse->collapseWhiteSpace())
1148 stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild); 1241 stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild);
1149 1242
1150 updatePreferredWidth(minLogicalWidth, inlineMin); 1243 updatePreferredWidth(minLogicalWidth, inlineMin);
1151 updatePreferredWidth(maxLogicalWidth, inlineMax); 1244 updatePreferredWidth(maxLogicalWidth, inlineMax);
1152 1245
1153 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); 1246 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
1154 } 1247 }
1155 1248
1249 int RenderParagraph::firstLineBoxBaseline() const
1250 {
1251 return firstLineBox() ? firstLineBox()->logicalTop() + style(true)->fontMetr ics().ascent(firstRootBox()->baselineType()) : -1;
1252 }
1253
1254 int RenderParagraph::lastLineBoxBaseline(LineDirectionMode lineDirection) const
1255 {
1256 if (!firstLineBox() && hasLineIfEmpty()) {
1257 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics();
1258 return fontMetrics.ascent()
1259 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f ontMetrics.height()) / 2
1260 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b orderRight() + paddingRight());
1261 }
1262 if (lastLineBox())
1263 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox ())->fontMetrics().ascent(lastRootBox()->baselineType());
1264 return -1;
1265 }
1266
1156 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidat ionLogicalBottom, LayoutUnit beforeEdge, LayoutUnit afterEdge) 1267 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidat ionLogicalBottom, LayoutUnit beforeEdge, LayoutUnit afterEdge)
1157 { 1268 {
1158 // Figure out if we should clear out our line boxes. 1269 // Figure out if we should clear out our line boxes.
1159 // FIXME: Handle resize eventually! 1270 // FIXME: Handle resize eventually!
1160 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ; 1271 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ;
1161 LineLayoutState layoutState(isFullLayout, paintInvalidationLogicalTop, paint InvalidationLogicalBottom); 1272 LineLayoutState layoutState(isFullLayout, paintInvalidationLogicalTop, paint InvalidationLogicalBottom);
1162 1273
1163 if (isFullLayout) { 1274 if (isFullLayout) {
1164 // Ensure the old line boxes will be erased. 1275 // Ensure the old line boxes will be erased.
1165 if (firstLineBox()) 1276 if (firstLineBox())
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 curr->adjustLogicalPosition(logicalLeft, 0); 1612 curr->adjustLogicalPosition(logicalLeft, 0);
1502 else 1613 else
1503 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0); 1614 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0);
1504 } 1615 }
1505 } 1616 }
1506 firstLine = false; 1617 firstLine = false;
1507 } 1618 }
1508 } 1619 }
1509 1620
1510 } // namespace blink 1621 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698