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

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: cr comments 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
« no previous file with comments | « sky/engine/core/rendering/RenderParagraph.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 GapRects RenderParagraph::inlineSelectionGaps(RenderBlock* rootBlock, const Layo utPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
77 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLog icalRight, const PaintInfo* paintInfo)
78 {
79 GapRects result;
80
81 bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth;
82
83 if (!firstLineBox()) {
84 if (containsStart) {
85 // Go ahead and update our lastLogicalTop to be the bottom of the bl ock. <hr>s or empty blocks with height can trip this
86 // case.
87 lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock ) + logicalHeight();
88 lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeigh t());
89 lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHei ght());
90 }
91 return result;
92 }
93
94 RootInlineBox* lastSelectedLine = 0;
95 RootInlineBox* curr;
96 for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = cur r->nextRootBox()) { }
97
98 // Now paint the gaps for the lines.
99 for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) {
100 LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock();
101 LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock();
102
103 if (!containsStart && !lastSelectedLine && selectionState() != Selection Start && selectionState() != SelectionBoth) {
104 result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPos ition, offsetFromRootBlock, lastLogicalTop,
105 lastLogicalLeft, lastLogicalRight, selTop, paintInfo));
106 }
107
108 LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth() , selTop + selHeight);
109 logicalRect.move(offsetFromRootBlock);
110 LayoutRect physicalRect = rootBlock->logicalRectToPhysicalRect(rootBlock PhysicalPosition, logicalRect);
111 if (!paintInfo || (physicalRect.y() < paintInfo->rect.maxY() && physical Rect.maxY() > paintInfo->rect.y()))
112 result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosi tion, offsetFromRootBlock, selTop, selHeight, paintInfo));
113
114 lastSelectedLine = curr;
115 }
116
117 if (containsStart && !lastSelectedLine) {
118 // VisibleSelection must start just after our last line.
119 lastSelectedLine = lastRootBox();
120 }
121
122 if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) {
123 // Go ahead and update our lastY to be the bottom of the last selected l ine.
124 lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + lastSelectedLine->selectionBottom();
125 lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine ->selectionBottom());
126 lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLi ne->selectionBottom());
127 }
128 return result;
129 }
130
49 void RenderParagraph::addOverflowFromChildren() 131 void RenderParagraph::addOverflowFromChildren()
50 { 132 {
51 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); 133 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. 134 // 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()) 135 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElem ent() && style()->isLeftToRightDirection())
54 endPadding = 1; 136 endPadding = 1;
55 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { 137 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
56 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); 138 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
57 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom()); 139 LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), cu rr->lineBottom());
58 addContentsVisualOverflow(visualOverflow); 140 addContentsVisualOverflow(visualOverflow);
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1228
1147 if (styleToUse->collapseWhiteSpace()) 1229 if (styleToUse->collapseWhiteSpace())
1148 stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild); 1230 stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild);
1149 1231
1150 updatePreferredWidth(minLogicalWidth, inlineMin); 1232 updatePreferredWidth(minLogicalWidth, inlineMin);
1151 updatePreferredWidth(maxLogicalWidth, inlineMax); 1233 updatePreferredWidth(maxLogicalWidth, inlineMax);
1152 1234
1153 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); 1235 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
1154 } 1236 }
1155 1237
1238 int RenderParagraph::firstLineBoxBaseline() const
1239 {
1240 return firstLineBox() ? firstLineBox()->logicalTop() + style(true)->fontMetr ics().ascent(firstRootBox()->baselineType()) : -1;
1241 }
1242
1243 int RenderParagraph::lastLineBoxBaseline(LineDirectionMode lineDirection) const
1244 {
1245 if (!firstLineBox() && hasLineIfEmpty()) {
1246 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics();
1247 return fontMetrics.ascent()
1248 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f ontMetrics.height()) / 2
1249 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b orderRight() + paddingRight());
1250 }
1251 if (lastLineBox())
1252 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox ())->fontMetrics().ascent(lastRootBox()->baselineType());
1253 return -1;
1254 }
1255
1156 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidat ionLogicalBottom, LayoutUnit beforeEdge, LayoutUnit afterEdge) 1256 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidat ionLogicalBottom, LayoutUnit beforeEdge, LayoutUnit afterEdge)
1157 { 1257 {
1158 // Figure out if we should clear out our line boxes. 1258 // Figure out if we should clear out our line boxes.
1159 // FIXME: Handle resize eventually! 1259 // FIXME: Handle resize eventually!
1160 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ; 1260 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ;
1161 LineLayoutState layoutState(isFullLayout, paintInvalidationLogicalTop, paint InvalidationLogicalBottom); 1261 LineLayoutState layoutState(isFullLayout, paintInvalidationLogicalTop, paint InvalidationLogicalBottom);
1162 1262
1163 if (isFullLayout) { 1263 if (isFullLayout) {
1164 // Ensure the old line boxes will be erased. 1264 // Ensure the old line boxes will be erased.
1165 if (firstLineBox()) 1265 if (firstLineBox())
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 curr->adjustLogicalPosition(logicalLeft, 0); 1601 curr->adjustLogicalPosition(logicalLeft, 0);
1502 else 1602 else
1503 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0); 1603 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0);
1504 } 1604 }
1505 } 1605 }
1506 firstLine = false; 1606 firstLine = false;
1507 } 1607 }
1508 } 1608 }
1509 1609
1510 } // namespace blink 1610 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderParagraph.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698