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

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

Issue 734813004: Get rid of continuations. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/RenderInline.h ('k') | sky/engine/core/rendering/RenderObject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 RenderInline* RenderInline::createAnonymous(Document* document) 57 RenderInline* RenderInline::createAnonymous(Document* document)
58 { 58 {
59 RenderInline* renderer = new RenderInline(0); 59 RenderInline* renderer = new RenderInline(0);
60 renderer->setDocumentForAnonymous(document); 60 renderer->setDocumentForAnonymous(document);
61 return renderer; 61 return renderer;
62 } 62 }
63 63
64 void RenderInline::willBeDestroyed() 64 void RenderInline::willBeDestroyed()
65 { 65 {
66 #if ENABLE(ASSERT)
67 // Make sure we do not retain "this" in the continuation outline table map o f our containing blocks.
68 if (parent() && style()->hasOutline()) {
69 bool containingBlockPaintsContinuationOutline = continuation() || isInli neElementContinuation();
70 if (containingBlockPaintsContinuationOutline) {
71 if (RenderBlock* cb = containingBlock()) {
72 if (RenderBlock* cbCb = cb->containingBlock())
73 ASSERT(!cbCb->paintsContinuationOutline(this));
74 }
75 }
76 }
77 #endif
78
79 // Make sure to destroy anonymous children first while they are still connec ted to the rest of the tree, so that they will 66 // Make sure to destroy anonymous children first while they are still connec ted to the rest of the tree, so that they will
80 // properly dirty line boxes that they are removed from. Effects that do :b efore/:after only on hover could crash otherwise. 67 // properly dirty line boxes that they are removed from. Effects that do :b efore/:after only on hover could crash otherwise.
81 children()->destroyLeftoverChildren(); 68 children()->destroyLeftoverChildren();
82 69
83 // Destroy our continuation before anything other than anonymous children.
84 // The reason we don't destroy it before anonymous children is that they may
85 // have continuations of their own that are anonymous children of our contin uation.
86 RenderBoxModelObject* continuation = this->continuation();
87 if (continuation) {
88 continuation->destroy();
89 setContinuation(0);
90 }
91
92 if (!documentBeingDestroyed()) { 70 if (!documentBeingDestroyed()) {
93 if (firstLineBox()) { 71 if (firstLineBox()) {
94 // We can't wait for RenderBoxModelObject::destroy to clear the sele ction, 72 // We can't wait for RenderBoxModelObject::destroy to clear the sele ction,
95 // because by then we will have nuked the line boxes. 73 // because by then we will have nuked the line boxes.
96 // FIXME: The FrameSelection should be responsible for this when it 74 // FIXME: The FrameSelection should be responsible for this when it
97 // is notified of DOM mutations. 75 // is notified of DOM mutations.
98 if (isSelectionBorder()) 76 if (isSelectionBorder())
99 view()->clearSelection(); 77 view()->clearSelection();
100 78
101 // If line boxes are contained inside a root, that means we're an in line. 79 // If line boxes are contained inside a root, that means we're an in line.
102 // In that case, we need to remove all the line boxes so that the pa rent 80 // In that case, we need to remove all the line boxes so that the pa rent
103 // lines aren't pointing to deleted children. If the first line box does 81 // lines aren't pointing to deleted children. If the first line box does
104 // not have a parent that means they are either already disconnected or 82 // not have a parent that means they are either already disconnected or
105 // root lines that can just be destroyed without disconnecting. 83 // root lines that can just be destroyed without disconnecting.
106 if (firstLineBox()->parent()) { 84 if (firstLineBox()->parent()) {
107 for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLi neBox()) 85 for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLi neBox())
108 box->remove(); 86 box->remove();
109 } 87 }
110 } else if (parent()) 88 } else if (parent())
111 parent()->dirtyLinesFromChangedChild(this); 89 parent()->dirtyLinesFromChangedChild(this);
112 } 90 }
113 91
114 m_lineBoxes.deleteLineBoxes(); 92 m_lineBoxes.deleteLineBoxes();
115 93
116 RenderBoxModelObject::willBeDestroyed(); 94 RenderBoxModelObject::willBeDestroyed();
117 } 95 }
118 96
119 RenderInline* RenderInline::inlineElementContinuation() const
120 {
121 RenderBoxModelObject* continuation = this->continuation();
122 if (!continuation || continuation->isInline())
123 return toRenderInline(continuation);
124 return toRenderBlock(continuation)->inlineElementContinuation();
125 }
126
127 void RenderInline::updateFromStyle() 97 void RenderInline::updateFromStyle()
128 { 98 {
129 RenderBoxModelObject::updateFromStyle(); 99 RenderBoxModelObject::updateFromStyle();
130 100
131 // FIXME: Is this still needed. Was needed for run-ins, since run-in is cons idered a block display type. 101 // FIXME: Is this still needed. Was needed for run-ins, since run-in is cons idered a block display type.
132 setInline(true); 102 setInline(true);
133 103
134 // FIXME: Support transforms and reflections on inline flows someday. 104 // FIXME: Support transforms and reflections on inline flows someday.
135 setHasTransform(false); 105 setHasTransform(false);
136 } 106 }
137 107
138 static RenderObject* inFlowPositionedInlineAncestor(RenderObject* p)
139 {
140 while (p && p->isRenderInline()) {
141 if (p->isRelPositioned())
142 return p;
143 p = p->parent();
144 }
145 return 0;
146 }
147
148 static void updateStyleOfAnonymousBlockContinuations(RenderObject* block, const RenderStyle* newStyle, const RenderStyle* oldStyle)
149 {
150 for (;block && block->isAnonymousBlock(); block = block->nextSibling()) {
151 if (!toRenderBlock(block)->isAnonymousBlockContinuation())
152 continue;
153
154 if (!block->style()->isOutlineEquivalent(newStyle)) {
155 RefPtr<RenderStyle> blockStyle = RenderStyle::clone(block->style());
156 blockStyle->setOutlineFromStyle(*newStyle);
157 block->setStyle(blockStyle);
158 }
159
160 if (block->style()->position() != newStyle->position()) {
161 // If we are no longer in-flow positioned but our descendant block(s ) still have an in-flow positioned ancestor then
162 // their containing anonymous block should keep its in-flow position ing.
163 if (oldStyle->hasInFlowPosition()
164 && inFlowPositionedInlineAncestor(toRenderBlock(block)->inlineEl ementContinuation()))
165 continue;
166 // FIXME: We should share blockStyle with the outline case, but it f ails layout tests
167 // for dynamic position change of inlines containing block continuat ions. crbug.com/405222.
168 RefPtr<RenderStyle> blockStyle = RenderStyle::createAnonymousStyleWi thDisplay(block->style(), BLOCK);
169 blockStyle->setPosition(newStyle->position());
170 block->setStyle(blockStyle);
171 }
172 }
173 }
174
175 void RenderInline::styleDidChange(StyleDifference diff, const RenderStyle* oldSt yle) 108 void RenderInline::styleDidChange(StyleDifference diff, const RenderStyle* oldSt yle)
176 { 109 {
177 RenderBoxModelObject::styleDidChange(diff, oldStyle); 110 RenderBoxModelObject::styleDidChange(diff, oldStyle);
178 111
179 // Ensure that all of the split inlines pick up the new style. We
180 // only do this if we're an inline, since we don't want to propagate
181 // a block's style to the other inlines.
182 // e.g., <font>foo <h4>goo</h4> moo</font>. The <font> inlines before
183 // and after the block share the same style, but the block doesn't
184 // need to pass its style on to anyone else.
185 RenderStyle* newStyle = style();
186 RenderInline* continuation = inlineElementContinuation();
187 for (RenderInline* currCont = continuation; currCont; currCont = currCont->i nlineElementContinuation()) {
188 RenderBoxModelObject* nextCont = currCont->continuation();
189 currCont->setContinuation(0);
190 currCont->setStyle(newStyle);
191 currCont->setContinuation(nextCont);
192 }
193
194 // If an inline's in-flow positioning has changed then any descendant blocks will need to change their in-flow positioning accordingly.
195 // Do this by updating the position of the descendant blocks' containing ano nymous blocks - there may be more than one.
196 if (continuation && oldStyle
197 && (!newStyle->isOutlineEquivalent(oldStyle)
198 || (newStyle->position() != oldStyle->position() && (newStyle->hasIn FlowPosition() || oldStyle->hasInFlowPosition())))) {
199 // If any descendant blocks exist then they will be in the next anonymou s block and its siblings.
200 RenderObject* block = containingBlock()->nextSibling();
201 if (block && block->isAnonymousBlock())
202 updateStyleOfAnonymousBlockContinuations(block, newStyle, oldStyle);
203 }
204
205 if (!alwaysCreateLineBoxes()) { 112 if (!alwaysCreateLineBoxes()) {
113 RenderStyle* newStyle = style();
206 bool alwaysCreateLineBoxesNew = hasSelfPaintingLayer() || hasBoxDecorati onBackground() || newStyle->hasPadding() || newStyle->hasMargin() || newStyle->h asOutline(); 114 bool alwaysCreateLineBoxesNew = hasSelfPaintingLayer() || hasBoxDecorati onBackground() || newStyle->hasPadding() || newStyle->hasMargin() || newStyle->h asOutline();
207 if (oldStyle && alwaysCreateLineBoxesNew) { 115 if (oldStyle && alwaysCreateLineBoxesNew) {
208 dirtyLineBoxes(false); 116 dirtyLineBoxes(false);
209 setNeedsLayoutAndFullPaintInvalidation(); 117 setNeedsLayoutAndFullPaintInvalidation();
210 } 118 }
211 setAlwaysCreateLineBoxes(alwaysCreateLineBoxesNew); 119 setAlwaysCreateLineBoxes(alwaysCreateLineBoxesNew);
212 } 120 }
213 } 121 }
214 122
215 void RenderInline::setContinuation(RenderBoxModelObject* continuation)
216 {
217 RenderBoxModelObject::setContinuation(continuation);
218 if (continuation && continuation->isAnonymousBlock() && !continuation->style ()->isOutlineEquivalent(style())) {
219 // Push outline style to the block continuation.
220 RefPtr<RenderStyle> blockStyle = RenderStyle::clone(continuation->style( ));
221 blockStyle->setOutlineFromStyle(*style());
222 continuation->setStyle(blockStyle);
223 }
224 // FIXME: What if continuation is added when the inline has relative positio n? crbug.com/405222.
225 }
226
227 void RenderInline::updateAlwaysCreateLineBoxes(bool fullLayout) 123 void RenderInline::updateAlwaysCreateLineBoxes(bool fullLayout)
228 { 124 {
229 // Once we have been tainted once, just assume it will happen again. This wa y effects like hover highlighting that change the 125 // Once we have been tainted once, just assume it will happen again. This wa y effects like hover highlighting that change the
230 // background color will only cause a layout on the first rollover. 126 // background color will only cause a layout on the first rollover.
231 if (alwaysCreateLineBoxes()) 127 if (alwaysCreateLineBoxes())
232 return; 128 return;
233 129
234 RenderStyle* parentStyle = parent()->style(); 130 RenderStyle* parentStyle = parent()->style();
235 RenderInline* parentRenderInline = parent()->isRenderInline() ? toRenderInli ne(parent()) : 0; 131 RenderInline* parentRenderInline = parent()->isRenderInline() ? toRenderInli ne(parent()) : 0;
236 bool alwaysCreateLineBoxesNew = (parentRenderInline && parentRenderInline->a lwaysCreateLineBoxes()) 132 bool alwaysCreateLineBoxesNew = (parentRenderInline && parentRenderInline->a lwaysCreateLineBoxes())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 LayoutRect caretRect = localCaretRectForEmptyElement(borderAndPaddingWidth() , 0); 171 LayoutRect caretRect = localCaretRectForEmptyElement(borderAndPaddingWidth() , 0);
276 172
277 if (InlineBox* firstBox = firstLineBox()) 173 if (InlineBox* firstBox = firstLineBox())
278 caretRect.moveBy(roundedLayoutPoint(firstBox->topLeft())); 174 caretRect.moveBy(roundedLayoutPoint(firstBox->topLeft()));
279 175
280 return caretRect; 176 return caretRect;
281 } 177 }
282 178
283 void RenderInline::addChild(RenderObject* newChild, RenderObject* beforeChild) 179 void RenderInline::addChild(RenderObject* newChild, RenderObject* beforeChild)
284 { 180 {
285 if (continuation())
286 return addChildToContinuation(newChild, beforeChild);
287 return addChildIgnoringContinuation(newChild, beforeChild);
288 }
289
290 static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
291 {
292 if (renderer->isInline() && !renderer->isReplaced())
293 return toRenderInline(renderer)->continuation();
294 return toRenderBlock(renderer)->inlineElementContinuation();
295 }
296
297 RenderBoxModelObject* RenderInline::continuationBefore(RenderObject* beforeChild )
298 {
299 if (beforeChild && beforeChild->parent() == this)
300 return this;
301
302 RenderBoxModelObject* curr = nextContinuation(this);
303 RenderBoxModelObject* nextToLast = this;
304 RenderBoxModelObject* last = this;
305 while (curr) {
306 if (beforeChild && beforeChild->parent() == curr) {
307 if (curr->slowFirstChild() == beforeChild)
308 return last;
309 return curr;
310 }
311
312 nextToLast = last;
313 last = curr;
314 curr = nextContinuation(curr);
315 }
316
317 if (!beforeChild && !last->slowFirstChild())
318 return nextToLast;
319 return last;
320 }
321
322 void RenderInline::addChildIgnoringContinuation(RenderObject* newChild, RenderOb ject* beforeChild)
323 {
324 if (!newChild->isInline() && !newChild->isFloatingOrOutOfFlowPositioned()) {
325 // We are placing a block inside an inline. We have to perform a split o f this
326 // inline into continuations. This involves creating an anonymous block box to hold
327 // |newChild|. We then make that block box a continuation of this inlin e. We take all of
328 // the children after |beforeChild| and put them in a clone of this obje ct.
329 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisp lay(style(), BLOCK);
330
331 // If inside an inline affected by in-flow positioning the block needs t o be affected by it too.
332 // Giving the block a layer like this allows it to collect the x/y offse ts from inline parents later.
333 if (RenderObject* positionedAncestor = inFlowPositionedInlineAncestor(th is))
334 newStyle->setPosition(positionedAncestor->style()->position());
335
336 RenderBlockFlow* newBox = RenderBlockFlow::createAnonymous(&document());
337 newBox->setStyle(newStyle.release());
338 RenderBoxModelObject* oldContinuation = continuation();
339 setContinuation(newBox);
340
341 splitFlow(beforeChild, newBox, newChild, oldContinuation);
342 return;
343 }
344
345 RenderBoxModelObject::addChild(newChild, beforeChild); 181 RenderBoxModelObject::addChild(newChild, beforeChild);
346
347 newChild->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); 182 newChild->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
348 } 183 }
349 184
350 RenderInline* RenderInline::clone() const
351 {
352 RenderInline* cloneInline = new RenderInline(node());
353 cloneInline->setStyle(style());
354 return cloneInline;
355 }
356
357 void RenderInline::splitInlines(RenderBlock* fromBlock, RenderBlock* toBlock,
358 RenderBlock* middleBlock,
359 RenderObject* beforeChild, RenderBoxModelObject* oldCont)
360 {
361 // Create a clone of this inline.
362 RenderInline* cloneInline = clone();
363 cloneInline->setContinuation(oldCont);
364
365 // Now take all of the children from beforeChild to the end and remove
366 // them from |this| and place them in the clone.
367 RenderObject* o = beforeChild;
368 while (o) {
369 RenderObject* tmp = o;
370 o = tmp->nextSibling();
371 cloneInline->addChildIgnoringContinuation(children()->removeChildNode(th is, tmp), 0);
372 tmp->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
373 }
374
375 // Hook |clone| up as the continuation of the middle block.
376 middleBlock->setContinuation(cloneInline);
377
378 // We have been reparented and are now under the fromBlock. We need
379 // to walk up our inline parent chain until we hit the containing block.
380 // Once we hit the containing block we're done.
381 RenderBoxModelObject* curr = toRenderBoxModelObject(parent());
382 RenderBoxModelObject* currChild = this;
383
384 // FIXME: Because splitting is O(n^2) as tags nest pathologically, we cap th e depth at which we're willing to clone.
385 // There will eventually be a better approach to this problem that will let us nest to a much
386 // greater depth (see bugzilla bug 13430) but for now we have a limit. This *will* result in
387 // incorrect rendering, but the alternative is to hang forever.
388 unsigned splitDepth = 1;
389 const unsigned cMaxSplitDepth = 200;
390 while (curr && curr != fromBlock) {
391 ASSERT(curr->isRenderInline());
392 if (splitDepth < cMaxSplitDepth) {
393 // Create a new clone.
394 RenderInline* cloneChild = cloneInline;
395 cloneInline = toRenderInline(curr)->clone();
396
397 // Insert our child clone as the first child.
398 cloneInline->addChildIgnoringContinuation(cloneChild, 0);
399
400 // Hook the clone up as a continuation of |curr|.
401 RenderInline* inlineCurr = toRenderInline(curr);
402 oldCont = inlineCurr->continuation();
403 inlineCurr->setContinuation(cloneInline);
404 cloneInline->setContinuation(oldCont);
405
406 // Now we need to take all of the children starting from the first c hild
407 // *after* currChild and append them all to the clone.
408 o = currChild->nextSibling();
409 while (o) {
410 RenderObject* tmp = o;
411 o = tmp->nextSibling();
412 cloneInline->addChildIgnoringContinuation(inlineCurr->children() ->removeChildNode(curr, tmp), 0);
413 tmp->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation() ;
414 }
415 }
416
417 // Keep walking up the chain.
418 currChild = curr;
419 curr = toRenderBoxModelObject(curr->parent());
420 splitDepth++;
421 }
422
423 // Now we are at the block level. We need to put the clone into the toBlock.
424 toBlock->children()->appendChildNode(toBlock, cloneInline);
425
426 // Now take all the children after currChild and remove them from the fromBl ock
427 // and put them in the toBlock.
428 o = currChild->nextSibling();
429 while (o) {
430 RenderObject* tmp = o;
431 o = tmp->nextSibling();
432 toBlock->children()->appendChildNode(toBlock, fromBlock->children()->rem oveChildNode(fromBlock, tmp));
433 }
434 }
435
436 void RenderInline::splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox ,
437 RenderObject* newChild, RenderBoxModelObject* oldCo nt)
438 {
439 RenderBlock* pre = 0;
440 RenderBlock* block = containingBlock();
441
442 // Delete our line boxes before we do the inline split into continuations.
443 block->deleteLineBoxTree();
444
445 bool madeNewBeforeBlock = false;
446 if (block->isAnonymousBlock()) {
447 // We can reuse this block and make it the preBlock of the next continua tion.
448 pre = block;
449 pre->removePositionedObjects(0);
450 block = block->containingBlock();
451 } else {
452 // No anonymous block available for use. Make one.
453 pre = block->createAnonymousBlock();
454 madeNewBeforeBlock = true;
455 }
456
457 RenderBlock* post = toRenderBlock(pre->createAnonymousBoxWithSameTypeAs(bloc k));
458
459 RenderObject* boxFirst = madeNewBeforeBlock ? block->firstChild() : pre->nex tSibling();
460 if (madeNewBeforeBlock)
461 block->children()->insertChildNode(block, pre, boxFirst);
462 block->children()->insertChildNode(block, newBlockBox, boxFirst);
463 block->children()->insertChildNode(block, post, boxFirst);
464 block->setChildrenInline(false);
465
466 if (madeNewBeforeBlock) {
467 RenderObject* o = boxFirst;
468 while (o) {
469 RenderObject* no = o;
470 o = no->nextSibling();
471 pre->children()->appendChildNode(pre, block->children()->removeChild Node(block, no));
472 no->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
473 }
474 }
475
476 splitInlines(pre, post, newBlockBox, beforeChild, oldCont);
477
478 // We already know the newBlockBox isn't going to contain inline kids, so av oid wasting
479 // time in makeChildrenNonInline by just setting this explicitly up front.
480 newBlockBox->setChildrenInline(false);
481
482 newBlockBox->addChild(newChild);
483
484 // Always just do a full layout in order to ensure that line boxes (especial ly wrappers for images)
485 // get deleted properly. Because objects moves from the pre block into the post block, we want to
486 // make new line boxes instead of leaving the old line boxes around.
487 pre->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
488 block->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
489 post->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
490 }
491
492 void RenderInline::addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild)
493 {
494 RenderBoxModelObject* flow = continuationBefore(beforeChild);
495 ASSERT(!beforeChild || beforeChild->parent()->isRenderBlock() || beforeChild ->parent()->isRenderInline());
496 RenderBoxModelObject* beforeChildParent = 0;
497 if (beforeChild)
498 beforeChildParent = toRenderBoxModelObject(beforeChild->parent());
499 else {
500 RenderBoxModelObject* cont = nextContinuation(flow);
501 if (cont)
502 beforeChildParent = cont;
503 else
504 beforeChildParent = flow;
505 }
506
507 if (newChild->isFloatingOrOutOfFlowPositioned())
508 return beforeChildParent->addChildIgnoringContinuation(newChild, beforeC hild);
509
510 // A continuation always consists of two potential candidates: an inline or an anonymous
511 // block box holding block children.
512 bool childInline = newChild->isInline();
513 bool bcpInline = beforeChildParent->isInline();
514 bool flowInline = flow->isInline();
515
516 if (flow == beforeChildParent)
517 return flow->addChildIgnoringContinuation(newChild, beforeChild);
518 else {
519 // The goal here is to match up if we can, so that we can coalesce and c reate the
520 // minimal # of continuations needed for the inline.
521 if (childInline == bcpInline || (beforeChild && beforeChild->isInline()) )
522 return beforeChildParent->addChildIgnoringContinuation(newChild, bef oreChild);
523 if (flowInline == childInline)
524 return flow->addChildIgnoringContinuation(newChild, 0); // Just trea t like an append.
525 return beforeChildParent->addChildIgnoringContinuation(newChild, beforeC hild);
526 }
527 }
528
529 void RenderInline::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 185 void RenderInline::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
530 { 186 {
531 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this); 187 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
532 m_lineBoxes.paint(this, paintInfo, paintOffset); 188 m_lineBoxes.paint(this, paintInfo, paintOffset);
533 } 189 }
534 190
535 template<typename GeneratorContext> 191 template<typename GeneratorContext>
536 void RenderInline::generateLineBoxRects(GeneratorContext& yield) const 192 void RenderInline::generateLineBoxRects(GeneratorContext& yield) const
537 { 193 {
538 if (!alwaysCreateLineBoxes()) 194 if (!alwaysCreateLineBoxes())
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 Vector<IntRect>& m_rects; 268 Vector<IntRect>& m_rects;
613 const LayoutPoint& m_accumulatedOffset; 269 const LayoutPoint& m_accumulatedOffset;
614 }; 270 };
615 271
616 } // unnamed namespace 272 } // unnamed namespace
617 273
618 void RenderInline::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accu mulatedOffset) const 274 void RenderInline::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accu mulatedOffset) const
619 { 275 {
620 AbsoluteRectsGeneratorContext context(rects, accumulatedOffset); 276 AbsoluteRectsGeneratorContext context(rects, accumulatedOffset);
621 generateLineBoxRects(context); 277 generateLineBoxRects(context);
622
623 if (continuation()) {
624 if (continuation()->isBox()) {
625 RenderBox* box = toRenderBox(continuation());
626 continuation()->absoluteRects(rects, toLayoutPoint(accumulatedOffset - containingBlock()->location() + box->locationOffset()));
627 } else
628 continuation()->absoluteRects(rects, toLayoutPoint(accumulatedOffset - containingBlock()->location()));
629 }
630 } 278 }
631 279
632 280
633 namespace { 281 namespace {
634 282
635 class AbsoluteQuadsGeneratorContext { 283 class AbsoluteQuadsGeneratorContext {
636 public: 284 public:
637 AbsoluteQuadsGeneratorContext(const RenderInline* renderer, Vector<FloatQuad >& quads) 285 AbsoluteQuadsGeneratorContext(const RenderInline* renderer, Vector<FloatQuad >& quads)
638 : m_quads(quads) 286 : m_quads(quads)
639 , m_geometryMap() 287 , m_geometryMap()
640 { 288 {
641 m_geometryMap.pushMappingsToAncestor(renderer, 0); 289 m_geometryMap.pushMappingsToAncestor(renderer, 0);
642 } 290 }
643 291
644 void operator()(const FloatRect& rect) 292 void operator()(const FloatRect& rect)
645 { 293 {
646 m_quads.append(m_geometryMap.absoluteRect(rect)); 294 m_quads.append(m_geometryMap.absoluteRect(rect));
647 } 295 }
648 private: 296 private:
649 Vector<FloatQuad>& m_quads; 297 Vector<FloatQuad>& m_quads;
650 RenderGeometryMap m_geometryMap; 298 RenderGeometryMap m_geometryMap;
651 }; 299 };
652 300
653 } // unnamed namespace 301 } // unnamed namespace
654 302
655 void RenderInline::absoluteQuads(Vector<FloatQuad>& quads) const 303 void RenderInline::absoluteQuads(Vector<FloatQuad>& quads) const
656 { 304 {
657 AbsoluteQuadsGeneratorContext context(this, quads); 305 AbsoluteQuadsGeneratorContext context(this, quads);
658 generateLineBoxRects(context); 306 generateLineBoxRects(context);
659
660 if (continuation())
661 continuation()->absoluteQuads(quads);
662 } 307 }
663 308
664 LayoutUnit RenderInline::offsetLeft() const 309 LayoutUnit RenderInline::offsetLeft() const
665 { 310 {
666 LayoutPoint topLeft; 311 LayoutPoint topLeft;
667 if (InlineBox* firstBox = firstLineBoxIncludingCulling()) 312 if (InlineBox* firstBox = firstLineBoxIncludingCulling())
668 topLeft = flooredLayoutPoint(firstBox->topLeft()); 313 topLeft = flooredLayoutPoint(firstBox->topLeft());
669 return adjustedPositionRelativeToOffsetParent(topLeft).x(); 314 return adjustedPositionRelativeToOffsetParent(topLeft).x();
670 } 315 }
671 316
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // We can not use addNodeToRectBasedTestResult to determine if we fully enclose the hit-test area 424 // We can not use addNodeToRectBasedTestResult to determine if we fully enclose the hit-test area
780 // because it can only handle rectangular targets. 425 // because it can only handle rectangular targets.
781 result.addNodeToRectBasedTestResult(node(), request, locationInContainer ); 426 result.addNodeToRectBasedTestResult(node(), request, locationInContainer );
782 return regionResult.contains(tmpLocation.boundingBox()); 427 return regionResult.contains(tmpLocation.boundingBox());
783 } 428 }
784 return false; 429 return false;
785 } 430 }
786 431
787 PositionWithAffinity RenderInline::positionForPoint(const LayoutPoint& point) 432 PositionWithAffinity RenderInline::positionForPoint(const LayoutPoint& point)
788 { 433 {
434 // FIXME(sky): Now that we don't have continuations, can this whole function just be the following?
435 // return containingBlock()->positionForPoint(point);
436
789 // FIXME: Does not deal with relative positioned inlines (should it?) 437 // FIXME: Does not deal with relative positioned inlines (should it?)
790 RenderBlock* cb = containingBlock(); 438 RenderBlock* cb = containingBlock();
791 if (firstLineBox()) { 439 if (firstLineBox()) {
792 // This inline actually has a line box. We must have clicked in the bor der/padding of one of these boxes. We 440 // This inline actually has a line box. We must have clicked in the bor der/padding of one of these boxes. We
793 // should try to find a result by asking our containing block. 441 // should try to find a result by asking our containing block.
794 return cb->positionForPoint(point); 442 return cb->positionForPoint(point);
795 } 443 }
796 444
797 // Translate the coords from the pre-anonymous block to the post-anonymous b lock. 445 // Translate the coords from the pre-anonymous block to the post-anonymous b lock.
798 LayoutPoint parentBlockPoint = cb->location() + point;
799 RenderBoxModelObject* c = continuation();
800 while (c) {
801 RenderBox* contBlock = c->isInline() ? c->containingBlock() : toRenderBl ock(c);
802 if (c->isInline() || c->slowFirstChild())
803 return c->positionForPoint(parentBlockPoint - contBlock->locationOff set());
804 c = toRenderBlock(c)->inlineElementContinuation();
805 }
806
807 return RenderBoxModelObject::positionForPoint(point); 446 return RenderBoxModelObject::positionForPoint(point);
808 } 447 }
809 448
810 namespace { 449 namespace {
811 450
812 class LinesBoundingBoxGeneratorContext { 451 class LinesBoundingBoxGeneratorContext {
813 public: 452 public:
814 LinesBoundingBoxGeneratorContext(FloatRect& rect) : m_rect(rect) { } 453 LinesBoundingBoxGeneratorContext(FloatRect& rect) : m_rect(rect) { }
815 void operator()(const FloatRect& rect) 454 void operator()(const FloatRect& rect)
816 { 455 {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 LayoutUnit logicalTop = firstLineBox()->logicalTopVisualOverflow(firstRootBo x.lineTop()); 603 LayoutUnit logicalTop = firstLineBox()->logicalTopVisualOverflow(firstRootBo x.lineTop());
965 LayoutUnit logicalWidth = logicalRightSide - logicalLeftSide; 604 LayoutUnit logicalWidth = logicalRightSide - logicalLeftSide;
966 LayoutUnit logicalHeight = lastLineBox()->logicalBottomVisualOverflow(lastRo otBox.lineBottom()) - logicalTop; 605 LayoutUnit logicalHeight = lastLineBox()->logicalBottomVisualOverflow(lastRo otBox.lineBottom()) - logicalTop;
967 606
968 LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight); 607 LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight);
969 return rect; 608 return rect;
970 } 609 }
971 610
972 LayoutRect RenderInline::clippedOverflowRectForPaintInvalidation(const RenderLay erModelObject* paintInvalidationContainer, const PaintInvalidationState* paintIn validationState) const 611 LayoutRect RenderInline::clippedOverflowRectForPaintInvalidation(const RenderLay erModelObject* paintInvalidationContainer, const PaintInvalidationState* paintIn validationState) const
973 { 612 {
974 if (!firstLineBoxIncludingCulling() && !continuation()) 613 if (!firstLineBoxIncludingCulling())
975 return LayoutRect(); 614 return LayoutRect();
976 615
977 LayoutRect paintInvalidationRect(linesVisualOverflowBoundingBox()); 616 LayoutRect paintInvalidationRect(linesVisualOverflowBoundingBox());
978 bool hitPaintInvalidationContainer = false; 617 bool hitPaintInvalidationContainer = false;
979 618
980 // We need to add in the in-flow position offsets of any inlines (including us) up to our 619 // We need to add in the in-flow position offsets of any inlines (including us) up to our
981 // containing block. 620 // containing block.
982 RenderBlock* cb = containingBlock(); 621 RenderBlock* cb = containingBlock();
983 for (const RenderObject* inlineFlow = this; inlineFlow && inlineFlow->isRend erInline() && inlineFlow != cb; 622 for (const RenderObject* inlineFlow = this; inlineFlow && inlineFlow->isRend erInline() && inlineFlow != cb;
984 inlineFlow = inlineFlow->parent()) { 623 inlineFlow = inlineFlow->parent()) {
(...skipping 17 matching lines...) Expand all
1002 // FIXME: Passing paintInvalidationState directly to mapRectToPaintInvalidat ionBacking causes incorrect invalidations. 641 // FIXME: Passing paintInvalidationState directly to mapRectToPaintInvalidat ionBacking causes incorrect invalidations.
1003 // Should avoid slowRectMapping by properly adjusting paintInvalidationState . crbug.com/402994. 642 // Should avoid slowRectMapping by properly adjusting paintInvalidationState . crbug.com/402994.
1004 ForceHorriblySlowRectMapping slowRectMapping(paintInvalidationState); 643 ForceHorriblySlowRectMapping slowRectMapping(paintInvalidationState);
1005 cb->mapRectToPaintInvalidationBacking(paintInvalidationContainer, paintInval idationRect, paintInvalidationState); 644 cb->mapRectToPaintInvalidationBacking(paintInvalidationContainer, paintInval idationRect, paintInvalidationState);
1006 645
1007 if (outlineSize) { 646 if (outlineSize) {
1008 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling() ) { 647 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling() ) {
1009 if (!curr->isText()) 648 if (!curr->isText())
1010 paintInvalidationRect.unite(curr->rectWithOutlineForPaintInvalid ation(paintInvalidationContainer, outlineSize)); 649 paintInvalidationRect.unite(curr->rectWithOutlineForPaintInvalid ation(paintInvalidationContainer, outlineSize));
1011 } 650 }
1012
1013 if (continuation() && !continuation()->isInline() && continuation()->par ent())
1014 paintInvalidationRect.unite(continuation()->rectWithOutlineForPaintI nvalidation(paintInvalidationContainer, outlineSize));
1015 } 651 }
1016 652
1017 return paintInvalidationRect; 653 return paintInvalidationRect;
1018 } 654 }
1019 655
1020 LayoutRect RenderInline::rectWithOutlineForPaintInvalidation(const RenderLayerMo delObject* paintInvalidationContainer, LayoutUnit outlineWidth, const PaintInval idationState* paintInvalidationState) const 656 LayoutRect RenderInline::rectWithOutlineForPaintInvalidation(const RenderLayerMo delObject* paintInvalidationContainer, LayoutUnit outlineWidth, const PaintInval idationState* paintInvalidationState) const
1021 { 657 {
1022 LayoutRect r(RenderBoxModelObject::rectWithOutlineForPaintInvalidation(paint InvalidationContainer, outlineWidth, paintInvalidationState)); 658 LayoutRect r(RenderBoxModelObject::rectWithOutlineForPaintInvalidation(paint InvalidationContainer, outlineWidth, paintInvalidationState));
1023 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) { 659 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
1024 if (!curr->isText()) 660 if (!curr->isText())
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 // There can't be a transform between paintInvalidationContainer and o, because transforms create containers, so it should be safe 766 // There can't be a transform between paintInvalidationContainer and o, because transforms create containers, so it should be safe
1131 // to just subtract the delta between the paintInvalidationContainer and o. 767 // to just subtract the delta between the paintInvalidationContainer and o.
1132 LayoutSize containerOffset = paintInvalidationContainer->offsetFromAnces torContainer(o); 768 LayoutSize containerOffset = paintInvalidationContainer->offsetFromAnces torContainer(o);
1133 transformState.move(-containerOffset.width(), -containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTrans form); 769 transformState.move(-containerOffset.width(), -containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTrans form);
1134 return; 770 return;
1135 } 771 }
1136 772
1137 o->mapLocalToContainer(paintInvalidationContainer, transformState, mode, pai ntInvalidationState); 773 o->mapLocalToContainer(paintInvalidationContainer, transformState, mode, pai ntInvalidationState);
1138 } 774 }
1139 775
1140 void RenderInline::childBecameNonInline(RenderObject* child)
1141 {
1142 // We have to split the parent flow.
1143 RenderBlock* newBox = containingBlock()->createAnonymousBlock();
1144 RenderBoxModelObject* oldContinuation = continuation();
1145 setContinuation(newBox);
1146 RenderObject* beforeChild = child->nextSibling();
1147 children()->removeChildNode(this, child);
1148 splitFlow(beforeChild, newBox, child, oldContinuation);
1149 }
1150
1151 void RenderInline::updateHitTestResult(HitTestResult& result, const LayoutPoint& point) 776 void RenderInline::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
1152 { 777 {
1153 if (result.innerNode()) 778 if (result.innerNode())
1154 return; 779 return;
1155 780
1156 Node* n = node(); 781 Node* n = node();
1157 LayoutPoint localPoint(point); 782 LayoutPoint localPoint(point);
1158 if (n) { 783 if (n) {
1159 if (isInlineElementContinuation()) {
1160 // We're in the continuation of a split inline. Adjust our local po int to be in the coordinate space
1161 // of the principal renderer's containing block. This will end up b eing the innerNonSharedNode.
1162 RenderBlock* firstBlock = n->renderer()->containingBlock();
1163
1164 // Get our containing block.
1165 RenderBox* block = containingBlock();
1166 localPoint.moveBy(block->location() - firstBlock->locationOffset());
1167 }
1168
1169 result.setInnerNode(n); 784 result.setInnerNode(n);
1170 if (!result.innerNonSharedNode()) 785 if (!result.innerNonSharedNode())
1171 result.setInnerNonSharedNode(n); 786 result.setInnerNonSharedNode(n);
1172 result.setLocalPoint(localPoint); 787 result.setLocalPoint(localPoint);
1173 } 788 }
1174 } 789 }
1175 790
1176 void RenderInline::dirtyLineBoxes(bool fullLayout) 791 void RenderInline::dirtyLineBoxes(bool fullLayout)
1177 { 792 {
1178 if (fullLayout) { 793 if (fullLayout) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 }; 918 };
1304 919
1305 } // unnamed namespace 920 } // unnamed namespace
1306 921
1307 void RenderInline::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const 922 void RenderInline::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const
1308 { 923 {
1309 AbsoluteRectsIgnoringEmptyRectsGeneratorContext context(rects, additionalOff set); 924 AbsoluteRectsIgnoringEmptyRectsGeneratorContext context(rects, additionalOff set);
1310 generateLineBoxRects(context); 925 generateLineBoxRects(context);
1311 926
1312 addChildFocusRingRects(rects, additionalOffset, paintContainer); 927 addChildFocusRingRects(rects, additionalOffset, paintContainer);
1313
1314 if (continuation()) {
1315 // If the continuation doesn't paint into the same container, let its pa int invalidation container handle it.
1316 if (paintContainer != continuation()->containerForPaintInvalidation())
1317 return;
1318 if (continuation()->isInline())
1319 continuation()->addFocusRingRects(rects, flooredLayoutPoint(addition alOffset + continuation()->containingBlock()->location() - containingBlock()->lo cation()), paintContainer);
1320 else
1321 continuation()->addFocusRingRects(rects, flooredLayoutPoint(addition alOffset + toRenderBox(continuation())->location() - containingBlock()->location ()), paintContainer);
1322 }
1323 } 928 }
1324 929
1325 namespace { 930 namespace {
1326 931
1327 class AbsoluteLayoutRectsGeneratorContext { 932 class AbsoluteLayoutRectsGeneratorContext {
1328 public: 933 public:
1329 AbsoluteLayoutRectsGeneratorContext(Vector<LayoutRect>& rects, const LayoutP oint& accumulatedOffset) 934 AbsoluteLayoutRectsGeneratorContext(Vector<LayoutRect>& rects, const LayoutP oint& accumulatedOffset)
1330 : m_rects(rects) 935 : m_rects(rects)
1331 , m_accumulatedOffset(accumulatedOffset) { } 936 , m_accumulatedOffset(accumulatedOffset) { }
1332 937
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 pixelSnappedBox.maxY(), 1092 pixelSnappedBox.maxY(),
1488 pixelSnappedBox.maxX() + outlineWidth, 1093 pixelSnappedBox.maxX() + outlineWidth,
1489 pixelSnappedBox.maxY() + outlineWidth, 1094 pixelSnappedBox.maxY() + outlineWidth,
1490 BSBottom, outlineColor, outlineStyle, 1095 BSBottom, outlineColor, outlineStyle,
1491 outlineWidth, 1096 outlineWidth,
1492 outlineWidth, 1097 outlineWidth,
1493 antialias); 1098 antialias);
1494 } 1099 }
1495 1100
1496 } // namespace blink 1101 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderInline.h ('k') | sky/engine/core/rendering/RenderObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698