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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp

Issue 1974753002: Move block container specific parts of addChild() to LayoutBlockFlow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlock.cpp ('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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 2289
2290 void LayoutBlockFlow::addChild(LayoutObject* newChild, LayoutObject* beforeChild ) 2290 void LayoutBlockFlow::addChild(LayoutObject* newChild, LayoutObject* beforeChild )
2291 { 2291 {
2292 if (LayoutMultiColumnFlowThread* flowThread = multiColumnFlowThread()) { 2292 if (LayoutMultiColumnFlowThread* flowThread = multiColumnFlowThread()) {
2293 if (beforeChild == flowThread) 2293 if (beforeChild == flowThread)
2294 beforeChild = flowThread->firstChild(); 2294 beforeChild = flowThread->firstChild();
2295 ASSERT(!beforeChild || beforeChild->isDescendantOf(flowThread)); 2295 ASSERT(!beforeChild || beforeChild->isDescendantOf(flowThread));
2296 flowThread->addChild(newChild, beforeChild); 2296 flowThread->addChild(newChild, beforeChild);
2297 return; 2297 return;
2298 } 2298 }
2299 LayoutBlock::addChild(newChild, beforeChild); 2299
2300 if (beforeChild && beforeChild->parent() != this) {
2301 addChildBeforeDescendant(newChild, beforeChild);
2302 return;
2303 }
2304
2305 bool madeBoxesNonInline = false;
2306
2307 // A block has to either have all of its children inline, or all of its chil dren as blocks.
2308 // So, if our children are currently inline and a block child has to be inse rted, we move all our
2309 // inline children into anonymous block boxes.
2310 bool childIsBlockLevel = !newChild->isInline() && !newChild->isFloatingOrOut OfFlowPositioned();
2311 if (childrenInline()) {
2312 if (childIsBlockLevel) {
2313 // Wrap the inline content in anonymous blocks, to allow for the new block child to be
2314 // inserted.
2315 makeChildrenNonInline(beforeChild);
2316 madeBoxesNonInline = true;
2317
2318 if (beforeChild && beforeChild->parent() != this) {
2319 beforeChild = beforeChild->parent();
2320 ASSERT(beforeChild->isAnonymousBlock());
2321 ASSERT(beforeChild->parent() == this);
2322 }
2323 }
2324 } else if (!childIsBlockLevel) {
2325 // This block has block children. We may want to put the new child into an anomyous
2326 // block. Floats and out-of-flow children may live among either block or inline children,
2327 // so for such children, only put them inside an anonymous block if one already exists. If
2328 // the child is inline, on the other hand, we *have to* put it inside an anonymous block,
2329 // so create a new one if there is none for us there already.
2330 LayoutObject* afterChild = beforeChild ? beforeChild->previousSibling() : lastChild();
2331
2332 if (afterChild && afterChild->isAnonymousBlock()) {
2333 afterChild->addChild(newChild);
2334 return;
2335 }
2336
2337 if (newChild->isInline()) {
2338 // No suitable existing anonymous box - create a new one.
2339 LayoutBlockFlow* newBlock = toLayoutBlockFlow(createAnonymousBlock() );
2340 LayoutBox::addChild(newBlock, beforeChild);
2341 // Reparent adjacent floating or out-of-flow siblings to the new box .
2342 newBlock->reparentPrecedingFloatingOrOutOfFlowSiblings();
2343 newBlock->addChild(newChild);
2344 newBlock->reparentSubsequentFloatingOrOutOfFlowSiblings();
2345 return;
2346 }
2347 }
2348
2349 // Skip the LayoutBlock override, since that one deals with anonymous child insertion in a way
2350 // that isn't sufficient for us, and can only cause trouble at this point.
2351 LayoutBox::addChild(newChild, beforeChild);
2352
2353 if (madeBoxesNonInline && parent() && isAnonymousBlock() && parent()->isLayo utBlock()) {
2354 toLayoutBlock(parent())->removeLeftoverAnonymousBlock(this);
2355 // |this| may be dead now.
2356 }
2300 } 2357 }
2301 2358
2302 void LayoutBlockFlow::removeChild(LayoutObject* oldChild) 2359 void LayoutBlockFlow::removeChild(LayoutObject* oldChild)
2303 { 2360 {
2304 // No need to waste time in merging or removing empty anonymous blocks. 2361 // No need to waste time in merging or removing empty anonymous blocks.
2305 // We can just bail out if our document is getting destroyed. 2362 // We can just bail out if our document is getting destroyed.
2306 if (documentBeingDestroyed()) { 2363 if (documentBeingDestroyed()) {
2307 LayoutBox::removeChild(oldChild); 2364 LayoutBox::removeChild(oldChild);
2308 return; 2365 return;
2309 } 2366 }
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 if (!rect.isEmpty()) 3542 if (!rect.isEmpty())
3486 rects.append(rect); 3543 rects.append(rect);
3487 } 3544 }
3488 } 3545 }
3489 3546
3490 if (inlineElementContinuation) 3547 if (inlineElementContinuation)
3491 inlineElementContinuation->addOutlineRects(rects, additionalOffset + (in lineElementContinuation->containingBlock()->location() - location()), includeBlo ckOverflows); 3548 inlineElementContinuation->addOutlineRects(rects, additionalOffset + (in lineElementContinuation->containingBlock()->location() - location()), includeBlo ckOverflows);
3492 } 3549 }
3493 3550
3494 } // namespace blink 3551 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlock.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698