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

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

Issue 1068683002: Delete RenderBlockFlow. (Closed) Base URL: https://github.com/domokit/mojo.git@block
Patch Set: Created 5 years, 8 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 // 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"
11 #include "sky/engine/core/rendering/RenderObjectInlines.h" 11 #include "sky/engine/core/rendering/RenderObjectInlines.h"
12 #include "sky/engine/core/rendering/RenderView.h" 12 #include "sky/engine/core/rendering/RenderView.h"
13 #include "sky/engine/core/rendering/TextRunConstructor.h" 13 #include "sky/engine/core/rendering/TextRunConstructor.h"
14 #include "sky/engine/core/rendering/TrailingFloatsRootInlineBox.h"
15 #include "sky/engine/core/rendering/VerticalPositionCache.h" 14 #include "sky/engine/core/rendering/VerticalPositionCache.h"
16 #include "sky/engine/core/rendering/line/BreakingContextInlineHeaders.h" 15 #include "sky/engine/core/rendering/line/BreakingContextInlineHeaders.h"
17 #include "sky/engine/core/rendering/line/LineLayoutState.h" 16 #include "sky/engine/core/rendering/line/LineLayoutState.h"
18 #include "sky/engine/core/rendering/line/LineWidth.h" 17 #include "sky/engine/core/rendering/line/LineWidth.h"
19 #include "sky/engine/core/rendering/line/RenderTextInfo.h" 18 #include "sky/engine/core/rendering/line/RenderTextInfo.h"
20 #include "sky/engine/core/rendering/line/WordMeasurement.h" 19 #include "sky/engine/core/rendering/line/WordMeasurement.h"
21 #include "sky/engine/platform/fonts/Character.h" 20 #include "sky/engine/platform/fonts/Character.h"
22 #include "sky/engine/platform/text/BidiResolver.h" 21 #include "sky/engine/platform/text/BidiResolver.h"
23 #include "sky/engine/wtf/RefCountedLeakCounter.h" 22 #include "sky/engine/wtf/RefCountedLeakCounter.h"
24 #include "sky/engine/wtf/StdLibExtras.h" 23 #include "sky/engine/wtf/StdLibExtras.h"
25 #include "sky/engine/wtf/Vector.h" 24 #include "sky/engine/wtf/Vector.h"
26 #include "sky/engine/wtf/unicode/CharacterNames.h" 25 #include "sky/engine/wtf/unicode/CharacterNames.h"
27 26
28 27
29 namespace blink { 28 namespace blink {
30 29
31 using namespace WTF::Unicode; 30 using namespace WTF::Unicode;
32 31
33 RenderParagraph::RenderParagraph(ContainerNode* node) 32 RenderParagraph::RenderParagraph(ContainerNode* node)
34 : RenderBlockFlow(node) 33 : RenderBlock(node)
35 { 34 {
36 } 35 }
37 36
38 RenderParagraph::~RenderParagraph() 37 RenderParagraph::~RenderParagraph()
39 { 38 {
40 } 39 }
41 40
42 const char* RenderParagraph::renderName() const 41 const char* RenderParagraph::renderName() const
43 { 42 {
44 if (isAnonymous()) 43 if (isAnonymous())
45 return "RenderParagraph (anonymous)"; 44 return "RenderParagraph (anonymous)";
46 return "RenderParagraph"; 45 return "RenderParagraph";
47 } 46 }
48 47
49 RenderParagraph* RenderParagraph::createAnonymous(Document& document) 48 RenderParagraph* RenderParagraph::createAnonymous(Document& document)
50 { 49 {
51 RenderParagraph* renderer = new RenderParagraph(0); 50 RenderParagraph* renderer = new RenderParagraph(0);
52 renderer->setDocumentForAnonymous(&document); 51 renderer->setDocumentForAnonymous(&document);
53 return renderer; 52 return renderer;
54 } 53 }
55 54
55 LayoutUnit RenderParagraph::logicalLeftSelectionOffset(RenderBlock* rootBlock, L ayoutUnit position)
56 {
57 LayoutUnit logicalLeft = logicalLeftOffsetForLine(false);
58 if (logicalLeft == logicalLeftOffsetForContent())
59 return RenderBlock::logicalLeftSelectionOffset(rootBlock, position);
60
61 RenderBlock* cb = this;
62 while (cb != rootBlock) {
63 logicalLeft += cb->logicalLeft();
64 cb = cb->containingBlock();
65 }
66 return logicalLeft;
67 }
68
69 LayoutUnit RenderParagraph::logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position)
70 {
71 LayoutUnit logicalRight = logicalRightOffsetForLine(false);
72 if (logicalRight == logicalRightOffsetForContent())
73 return RenderBlock::logicalRightSelectionOffset(rootBlock, position);
74
75 RenderBlock* cb = this;
76 while (cb != rootBlock) {
77 logicalRight += cb->logicalLeft();
78 cb = cb->containingBlock();
79 }
80 return logicalRight;
81 }
82
56 RootInlineBox* RenderParagraph::lineAtIndex(int i) const 83 RootInlineBox* RenderParagraph::lineAtIndex(int i) const
57 { 84 {
58 ASSERT(i >= 0); 85 ASSERT(i >= 0);
59 86
60 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) { 87 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) {
61 if (!i--) 88 if (!i--)
62 return box; 89 return box;
63 } 90 }
64 91
65 return 0; 92 return 0;
66 } 93 }
67 94
68 int RenderParagraph::lineCount(const RootInlineBox* stopRootInlineBox, bool* fou nd) const 95 int RenderParagraph::lineCount(const RootInlineBox* stopRootInlineBox, bool* fou nd) const
69 { 96 {
70 int count = 0; 97 int count = 0;
71 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) { 98 for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) {
72 count++; 99 count++;
73 if (box == stopRootInlineBox) { 100 if (box == stopRootInlineBox) {
74 if (found) 101 if (found)
75 *found = true; 102 *found = true;
76 break; 103 break;
77 } 104 }
78 } 105 }
79 106
80 return count; 107 return count;
81 } 108 }
82 109
110 void RenderParagraph::deleteLineBoxTree()
111 {
112 m_lineBoxes.deleteLineBoxTree();
113 }
114
83 GapRects RenderParagraph::inlineSelectionGaps(RenderBlock* rootBlock, const Layo utPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, 115 GapRects RenderParagraph::inlineSelectionGaps(RenderBlock* rootBlock, const Layo utPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
84 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLog icalRight, const PaintInfo* paintInfo) 116 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLog icalRight, const PaintInfo* paintInfo)
85 { 117 {
86 GapRects result; 118 GapRects result;
87 119
88 bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth; 120 bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth;
89 121
90 if (!firstLineBox()) { 122 if (!firstLineBox()) {
91 if (containsStart) { 123 if (containsStart) {
92 // Go ahead and update our lastLogicalTop to be the bottom of the bl ock. <hr>s or empty blocks with height can trip this 124 // Go ahead and update our lastLogicalTop to be the bottom of the bl ock. <hr>s or empty blocks with height can trip this
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 afterLowest = lowestDirtyLine; 236 afterLowest = lowestDirtyLine;
205 lowestDirtyLine = lowestDirtyLine->prevRootBox(); 237 lowestDirtyLine = lowestDirtyLine->prevRootBox();
206 } 238 }
207 239
208 while (afterLowest && afterLowest != highest && (afterLowest->lineBottomWith Leading() >= logicalTop || afterLowest->lineBottomWithLeading() < 0)) { 240 while (afterLowest && afterLowest != highest && (afterLowest->lineBottomWith Leading() >= logicalTop || afterLowest->lineBottomWithLeading() < 0)) {
209 afterLowest->markDirty(); 241 afterLowest->markDirty();
210 afterLowest = afterLowest->prevRootBox(); 242 afterLowest = afterLowest->prevRootBox();
211 } 243 }
212 } 244 }
213 245
214 static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRo otLineBox, bool isOnlyRun = false) 246 static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, B idiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float av ailableLogicalWidth)
247 {
248 // The direction of the block should determine what happens with wide lines.
249 // In particular with RTL blocks, wide lines should still spill out to the l eft.
250 if (isLeftToRightDirection) {
251 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
252 trailingSpaceRun->m_box->setLogicalWidth(std::max<float>(0, trailing SpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
253 return;
254 }
255
256 if (trailingSpaceRun)
257 trailingSpaceRun->m_box->setLogicalWidth(0);
258 else if (totalLogicalWidth > availableLogicalWidth)
259 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
260 }
261
262 static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float a vailableLogicalWidth)
263 {
264 // Wide lines spill out of the block based off direction.
265 // So even if text-align is right, if direction is LTR, wide lines should ov erflow out of the right
266 // side of the block.
267 if (isLeftToRightDirection) {
268 if (trailingSpaceRun) {
269 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
270 trailingSpaceRun->m_box->setLogicalWidth(0);
271 }
272 if (totalLogicalWidth < availableLogicalWidth)
273 logicalLeft += availableLogicalWidth - totalLogicalWidth;
274 return;
275 }
276
277 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
278 trailingSpaceRun->m_box->setLogicalWidth(std::max<float>(0, trailingSpac eRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
279 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
280 } else
281 logicalLeft += availableLogicalWidth - totalLogicalWidth;
282 }
283
284 static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
285 {
286 float trailingSpaceWidth = 0;
287 if (trailingSpaceRun) {
288 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
289 trailingSpaceWidth = std::min(trailingSpaceRun->m_box->logicalWidth(), ( availableLogicalWidth - totalLogicalWidth + 1) / 2);
290 trailingSpaceRun->m_box->setLogicalWidth(std::max<float>(0, trailingSpac eWidth));
291 }
292 if (isLeftToRightDirection)
293 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidt h) / 2, 0);
294 else
295 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLog icalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
296 }
297
298 void RenderParagraph::updateLogicalWidthForAlignment(const ETextAlign& textAlign , const RootInlineBox* rootInlineBox, BidiRun* trailingSpaceRun, float& logicalL eft, float& totalLogicalWidth, float& availableLogicalWidth, unsigned expansionO pportunityCount)
299 {
300 TextDirection direction;
301 if (rootInlineBox && rootInlineBox->renderer().style()->unicodeBidi() == Pla intext)
302 direction = rootInlineBox->direction();
303 else
304 direction = style()->direction();
305
306 // Armed with the total width of the line (without justification),
307 // we now examine our text-align property in order to determine where to pos ition the
308 // objects horizontally. The total width of the line can be increased if we end up
309 // justifying text.
310 switch (textAlign) {
311 case LEFT:
312 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
313 break;
314 case RIGHT:
315 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection() , trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
316 break;
317 case CENTER:
318 updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection( ), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
319 break;
320 case JUSTIFY:
321 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
322 if (expansionOpportunityCount) {
323 if (trailingSpaceRun) {
324 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
325 trailingSpaceRun->m_box->setLogicalWidth(0);
326 }
327 break;
328 }
329 // Fall through
330 case TASTART:
331 if (direction == LTR)
332 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirectio n(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
333 else
334 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirecti on(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
335 break;
336 case TAEND:
337 if (direction == LTR)
338 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirecti on(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
339 else
340 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirectio n(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
341 break;
342 }
343 }
344
345 RootInlineBox* RenderParagraph::createAndAppendRootInlineBox()
346 {
347 RootInlineBox* rootBox = createRootInlineBox();
348 m_lineBoxes.appendLineBox(rootBox);
349 return rootBox;
350 }
351
352 RootInlineBox* RenderParagraph::createRootInlineBox()
353 {
354 return new RootInlineBox(*this);
355 }
356
357 InlineBox* RenderParagraph::createInlineBoxForRenderer(RenderObject* obj, bool i sRootLineBox, bool isOnlyRun)
215 { 358 {
216 if (isRootLineBox) 359 if (isRootLineBox)
217 return toRenderBlockFlow(obj)->createAndAppendRootInlineBox(); 360 return toRenderParagraph(obj)->createAndAppendRootInlineBox();
218 361
219 if (obj->isText()) { 362 if (obj->isText()) {
220 InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox(); 363 InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox();
221 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode 364 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
222 // (Note the use of strict mode. In "almost strict" mode, we don't trea t the box for <br> as text.) 365 // (Note the use of strict mode. In "almost strict" mode, we don't trea t the box for <br> as text.)
223 return textBox; 366 return textBox;
224 } 367 }
225 368
226 if (obj->isBox()) 369 if (obj->isBox())
227 return toRenderBox(obj)->createInlineBox(); 370 return toRenderBox(obj)->createInlineBox();
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics(); 1378 const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics();
1236 return fontMetrics.ascent() 1379 return fontMetrics.ascent()
1237 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f ontMetrics.height()) / 2 1380 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f ontMetrics.height()) / 2
1238 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b orderRight() + paddingRight()); 1381 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : b orderRight() + paddingRight());
1239 } 1382 }
1240 if (lastLineBox()) 1383 if (lastLineBox())
1241 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox ())->fontMetrics().ascent(lastRootBox()->baselineType()); 1384 return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox ())->fontMetrics().ascent(lastRootBox()->baselineType());
1242 return -1; 1385 return -1;
1243 } 1386 }
1244 1387
1388 void RenderParagraph::layout()
1389 {
1390 ASSERT(needsLayout());
1391 ASSERT(isInlineBlock() || !isInline());
1392
1393 if (simplifiedLayout())
1394 return;
1395
1396 SubtreeLayoutScope layoutScope(*this);
1397
1398 LayoutUnit oldLeft = logicalLeft();
1399 bool logicalWidthChanged = updateLogicalWidthAndColumnWidth();
1400 bool relayoutChildren = logicalWidthChanged;
1401
1402 LayoutUnit beforeEdge = borderBefore() + paddingBefore();
1403 LayoutUnit afterEdge = borderAfter() + paddingAfter();
1404 LayoutUnit previousHeight = logicalHeight();
1405 setLogicalHeight(beforeEdge);
1406
1407 layoutChildren(relayoutChildren, layoutScope, beforeEdge, afterEdge);
1408
1409 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
1410
1411 updateLogicalHeight();
1412
1413 if (previousHeight != logicalHeight())
1414 relayoutChildren = true;
1415
1416 layoutPositionedObjects(relayoutChildren, oldLeft != logicalLeft() ? ForcedL ayoutAfterContainingBlockMoved : DefaultLayout);
1417
1418 // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway).
1419 computeOverflow(oldClientAfterEdge);
1420
1421 updateLayerTransformAfterLayout();
1422
1423 clearNeedsLayout();
1424 }
1425
1245 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit beforeEdge, LayoutUnit afterEdge) 1426 void RenderParagraph::layoutChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit beforeEdge, LayoutUnit afterEdge)
1246 { 1427 {
1247 // Figure out if we should clear out our line boxes. 1428 // Figure out if we should clear out our line boxes.
1248 // FIXME: Handle resize eventually! 1429 // FIXME: Handle resize eventually!
1249 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ; 1430 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren ;
1250 LineLayoutState layoutState(isFullLayout); 1431 LineLayoutState layoutState(isFullLayout);
1251 1432
1252 if (isFullLayout) 1433 if (isFullLayout)
1253 lineBoxes()->deleteLineBoxes(); 1434 lineBoxes()->deleteLineBoxes();
1254 1435
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 curr->adjustLogicalPosition(logicalLeft, 0); 1762 curr->adjustLogicalPosition(logicalLeft, 0);
1582 else 1763 else
1583 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0); 1764 curr->adjustLogicalPosition(logicalLeft - (availableLogicalW idth - totalLogicalWidth), 0);
1584 } 1765 }
1585 } 1766 }
1586 firstLine = false; 1767 firstLine = false;
1587 } 1768 }
1588 } 1769 }
1589 1770
1590 } // namespace blink 1771 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698