File: render_container.cpp

package info (click to toggle)
khtml 5.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,940 kB
  • sloc: cpp: 206,281; java: 4,060; ansic: 2,829; perl: 2,313; yacc: 1,497; python: 339; sh: 141; xml: 37; makefile: 7
file content (791 lines) | stat: -rw-r--r-- 27,187 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/**
 * This file is part of the html renderer for KDE.
 *
 * Copyright (C) 2001-2003 Lars Knoll (knoll@kde.org)
 *           (C) 2001 Antti Koivisto (koivisto@kde.org)
 *           (C) 2000-2003 Dirk Mueller (mueller@kde.org)
 *           (C) 2002-2007 Apple Computer, Inc.
 *           (C) 2007 Germain Garand (germain@ebooksfrance.org)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

//#define DEBUG_LAYOUT

#include "rendering/render_container.h"
#include "rendering/render_table.h"
#include "rendering/render_text.h"
#include "rendering/render_image.h"
#include "rendering/render_canvas.h"
#include "rendering/render_generated.h"
#include "rendering/render_inline.h"
#include "rendering/render_layer.h"
#include "rendering/render_position.h"
#include "xml/dom_docimpl.h"
#include "xml/dom_position.h"
#include "css/css_valueimpl.h"

#include "khtml_debug.h"
#include <assert.h>
#include <limits.h>

using DOM::Position;
using namespace khtml;

RenderContainer::RenderContainer(DOM::NodeImpl *node)
    : RenderObject(node)
{
    m_first = nullptr;
    m_last = nullptr;
}

void RenderContainer::addChild(RenderObject *newChild, RenderObject *beforeChild)
{
#ifdef DEBUG_LAYOUT
    // qCDebug(KHTML_LOG) << this << ": " <<  renderName() << "(RenderObject)::addChild( " << newChild << ": " <<
    // newChild->renderName() << ", " << (beforeChild ? beforeChild->renderName() : "0") << " )";
#endif
    // protect ourselves from deletion
    setDoNotDelete(true);

    bool needsTable = false;

    if (!newChild->isText() && !newChild->isReplaced()) {
        switch (newChild->style()->display()) {
        case INLINE:
        case BLOCK:
        case LIST_ITEM:
        case RUN_IN:
        case COMPACT:
        case INLINE_BLOCK:
        case TABLE:
        case INLINE_TABLE:
            break;
        case TABLE_COLUMN:
            if (isTableCol()) {
                break;
            }
        // nobreak
        case TABLE_COLUMN_GROUP:
        case TABLE_CAPTION:
        case TABLE_ROW_GROUP:
        case TABLE_HEADER_GROUP:
        case TABLE_FOOTER_GROUP:

            //qCDebug(KHTML_LOG) << "adding section";
            if (!isTable()) {
                needsTable = true;
            }
            break;
        case TABLE_ROW:
            //qCDebug(KHTML_LOG) << "adding row";
            if (!isTableSection()) {
                needsTable = true;
            }
            break;
        case TABLE_CELL:
            //qCDebug(KHTML_LOG) << "adding cell";
            if (!isTableRow()) {
                needsTable = true;
            }
            // I'm not 100% sure this is the best way to fix this, but without this
            // change we recurse infinitely when trying to render the CSS2 test page:
            // http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/htmlbodyheadrendering2.html.
            if (isTableCell() && !firstChild() && !newChild->isTableCell()) {
                needsTable = false;
            }

            break;
        case NONE:
            // RenderHtml and some others can have display:none
            // KHTMLAssert(false);
            break;
        }
    }

    if (needsTable) {
        RenderTable *table;
        RenderObject *last = beforeChild ? beforeChild->previousSibling() : lastChild();
        if (last && last->isTable() && last->isAnonymous()) {
            table = static_cast<RenderTable *>(last);
        } else {
            //qCDebug(KHTML_LOG) << "creating anonymous table, before=" << beforeChild;
            table = new(renderArena()) RenderTable(document() /* is anonymous */);
            RenderStyle *newStyle = new RenderStyle();
            newStyle->inheritFrom(style());
            newStyle->setDisplay(TABLE);
            newStyle->setFlowAroundFloats(true);
            table->setParent(this);   // so it finds the arena
            table->setStyle(newStyle);
            table->setParent(nullptr);
            addChild(table, beforeChild);
        }
        table->addChild(newChild);
    } else {
        // just add it...
        insertChildNode(newChild, beforeChild);
    }

    if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE) {
        DOM::DOMStringImpl *textToTransform =  static_cast<RenderText *>(newChild)->originalString();
        if (textToTransform) {
            static_cast<RenderText *>(newChild)->setText(textToTransform, true);
        }
    }
    newChild->attach();

    setDoNotDelete(false);
}

RenderObject *RenderContainer::removeChildNode(RenderObject *oldChild)
{
    KHTMLAssert(oldChild->parent() == this);
    bool inCleanup = documentBeingDestroyed();

    if (!inCleanup) {
        oldChild->setNeedsLayoutAndMinMaxRecalc(); // Dirty the containing block chain
        oldChild->setNeedsLayout(false);   // The child itself does not need to layout - it's going away.

        // Repaint, so that the area exposed when the child
        // disappears gets repainted properly.
        if (oldChild->height() && oldChild->width()) {
            oldChild->repaint();
        }
    }

    // detach the place holder box
    if (oldChild->isBox()) {
        RenderBox *rb = static_cast<RenderBox *>(oldChild);
        InlineBox *ph = rb->placeHolderBox();
        if (ph) {
            ph->detach(rb->renderArena(), inCleanup /*NoRemove*/);
            rb->setPlaceHolderBox(nullptr);
        }
    }

    if (!inCleanup) {
        // if we remove visible child from an invisible parent, we don't know the layer visibility any more
        RenderLayer *layer = nullptr;
        if (m_style->visibility() != VISIBLE && oldChild->style()->visibility() == VISIBLE && !oldChild->layer()) {
            layer = enclosingLayer();
            if (layer) {
                layer->dirtyVisibleContentStatus();
            }
        }

        // Keep our layer hierarchy updated.
        if (oldChild->firstChild() || oldChild->layer()) {
            if (!layer) {
                layer = enclosingLayer();
            }
            oldChild->removeLayers(layer);
        }
        // remove the child from any special layout lists
        oldChild->removeFromObjectLists();

        // keep our fixed object lists updated.
        if (oldChild->style()->hasFixedBackgroundImage() || oldChild->style()->position() == PFIXED) {
            if (oldChild->style()->hasFixedBackgroundImage()) {
                canvas()->removeStaticObject(oldChild);
            }
            if (oldChild->style()->position() == PFIXED) {
                canvas()->removeStaticObject(oldChild, true);
            }
        }

        if (oldChild->isPosWithStaticDim() && childrenInline()) {
            dirtyLinesFromChangedChild(oldChild);
        }

        // We are about to take out node from the rendering tree and therefore
        // it's possible that we're modifying the line box tree too.
        // In order to properly recalculate it later we need
        // to delete all the boxes from the current flow of the removed child. (vtokarev)
        // In particular that's relevant when we're merging split inline flow. (continuations)
        // We're taking the render objects from one block and insert into another
        // so we have to force line box tree recalculation
        if (oldChild->isInline()) {
            if (oldChild->isText()) {
                InlineTextBox *box = static_cast<RenderText *>(oldChild)->firstTextBox();
                InlineTextBox *nextTextBox;
                assert(!box || box->parent());
                // delete all the text boxes
                for (; box; box = nextTextBox) {
                    nextTextBox = box->nextTextBox();
                    box->remove();
                    box->deleteLine(renderArena());
                }
            } else if (oldChild->isInlineFlow()) {
                InlineFlowBox *box = static_cast<RenderFlow *>(oldChild)->firstLineBox();
                InlineFlowBox *nextFlowBox;
                assert(!box || box->parent());
                // delete all the flow
                for (; box; box = nextFlowBox) {
                    nextFlowBox = box->nextFlowBox();
                    box->remove();
                    box->deleteLine(renderArena());
                }
            }
        }

        // if oldChild is the start or end of the selection, then clear
        // the selection to avoid problems of invalid pointers

        // ### This is not the "proper" solution... ideally the selection
        // ### should be maintained based on DOM Nodes and a Range, which
        // ### gets adjusted appropriately when nodes are deleted/inserted
        // ### near etc. But this at least prevents crashes caused when
        // ### the start or end of the selection is deleted and then
        // ### accessed when the user next selects something.

        if (oldChild->isSelectionBorder()) {
            canvas()->clearSelection();
        }
    }

    // remove the child from the render-tree
    if (oldChild->previousSibling()) {
        oldChild->previousSibling()->setNextSibling(oldChild->nextSibling());
    }
    if (oldChild->nextSibling()) {
        oldChild->nextSibling()->setPreviousSibling(oldChild->previousSibling());
    }

    if (m_first == oldChild) {
        m_first = oldChild->nextSibling();
    }
    if (m_last == oldChild) {
        m_last = oldChild->previousSibling();
    }

    oldChild->setPreviousSibling(nullptr);
    oldChild->setNextSibling(nullptr);
    oldChild->setParent(nullptr);

    return oldChild;
}

void RenderContainer::setStyle(RenderStyle *_style)
{
    RenderObject::setStyle(_style);

    // If we are a pseudo-container we need to restyle the children
    if (style()->isGenerated()) {
        // ### we could save this call when the change only affected
        // non inherited properties
        RenderStyle *pseudoStyle = new RenderStyle();
        pseudoStyle->inheritFrom(style());
        pseudoStyle->ref();
        RenderObject *child = firstChild();
        while (child != nullptr) {
            child->setStyle(pseudoStyle);
            child = child->nextSibling();
        }
        pseudoStyle->deref();
    }
}

static bool inUpdatePseudoChildren = false;

void RenderContainer::updatePseudoChildren()
{
    if (inUpdatePseudoChildren) {
        return;
    }
    inUpdatePseudoChildren = true;

    // In CSS2, before/after pseudo-content cannot nest.  Check this first.
    // Remove when CSS 3 Generated Content becomes Candidate Recommendation
    if (style()->styleType() == RenderStyle::BEFORE
            || style()->styleType() == RenderStyle::AFTER) {
        return;
    }

    updatePseudoChild(RenderStyle::BEFORE);
    updatePseudoChild(RenderStyle::AFTER);
    // updatePseudoChild(RenderStyle::MARKER, marker());

    inUpdatePseudoChildren = false;
}

void RenderContainer::updatePseudoChild(RenderStyle::PseudoId type)
{
    // The head manages generated content for its continuations
    if (isInlineContinuation()) {
        return;
    }

    RenderStyle *pseudo = style()->getPseudoStyle(type);

    RenderObject *child = pseudoContainer(type);

    // Whether or not we currently have generated content attached.
    bool oldContentPresent = child && (child->style()->styleType() == type);

    // Whether or not we now want generated content.
    bool newContentWanted = pseudo && pseudo->display() != NONE;

    // No generated content
    if (!oldContentPresent && !newContentWanted) {
        return;
    }

    bool movedContent = (type == RenderStyle::AFTER && isRenderInline() && continuation());

    // Whether or not we want the same old content.
    bool sameOldContent = oldContentPresent && newContentWanted && !movedContent
                          && (child->style()->contentDataEquivalent(pseudo));

    // No change in content, update style
    if (sameOldContent) {
        child->setStyle(pseudo);
        return;
    }

    // If we don't want generated content any longer, or if we have generated content,
    // but it's no longer identical to the new content data we want to build
    // render objects for, then we nuke all of the old generated content.
    if (oldContentPresent && (!newContentWanted || !sameOldContent)) {
        // The child needs to be removed.
        oldContentPresent = false;
        child->detach();
        child = nullptr;
    }

    // If we have no pseudo-style or if the pseudo's display type is NONE, then we
    // have no generated content and can now return.
    if (!newContentWanted) {
        return;
    }

    // Generated content consists of a single container that houses multiple children (specified
    // by the content property).  This pseudo container gets the pseudo style set on it.
    RenderContainer *pseudoContainer = nullptr;
    pseudoContainer = RenderFlow::createFlow(element(), pseudo, renderArena());
    pseudoContainer->setIsAnonymous(true);
    pseudoContainer->createGeneratedContent();

    // Only add the container if it had content
    if (pseudoContainer->firstChild()) {
        addPseudoContainer(pseudoContainer);
        pseudoContainer->close();
    }
}

void RenderContainer::createGeneratedContent()
{
    RenderStyle *pseudo = style();
    RenderStyle *style = new RenderStyle();
    style->ref();
    style->inheritFrom(pseudo);

    // Now walk our list of generated content and create render objects for every type
    // we encounter.
    for (ContentData *contentData = pseudo->contentData();
            contentData; contentData = contentData->_nextContent) {
        if (contentData->_contentType == CONTENT_TEXT) {
            RenderText *t = new(renderArena()) RenderText(node(), nullptr);
            t->setIsAnonymous(true);
            t->setStyle(style);
            t->setText(contentData->contentText());
            addChild(t);
        } else if (contentData->_contentType == CONTENT_OBJECT) {
            RenderImage *img = new(renderArena()) RenderImage(node());
            img->setIsAnonymous(true);
            img->setStyle(style);
            img->setContentObject(contentData->contentObject());
            addChild(img);
        } else if (contentData->_contentType == CONTENT_COUNTER) {
            // really a counter or just a glyph?
            EListStyleType type = (EListStyleType)contentData->contentCounter()->listStyle();
            RenderObject *t = nullptr;
            if (isListStyleCounted(type)) {
                t = new(renderArena()) RenderCounter(node(), contentData->contentCounter());
            } else {
                t = new(renderArena()) RenderGlyph(node(), type);
            }
            t->setIsAnonymous(true);
            t->setStyle(style);
            addChild(t);
        } else if (contentData->_contentType == CONTENT_QUOTE) {
            RenderQuote *t = new(renderArena()) RenderQuote(node(), contentData->contentQuote());
            t->setIsAnonymous(true);
            t->setStyle(style);
            addChild(t);
        }
    }
    style->deref();
}

RenderContainer *RenderContainer::pseudoContainer(RenderStyle::PseudoId type) const
{
    RenderObject *child = nullptr;
    switch (type) {
    case RenderStyle::AFTER:
        child = lastChild();
        break;
    case RenderStyle::BEFORE:
        child = firstChild();
        break;
    case RenderStyle::REPLACED:
        child = lastChild();
        if (child && child->style()->styleType() == RenderStyle::AFTER) {
            child = child->previousSibling();
        }
        break;
    default:
        child = nullptr;
    }

    if (child && child->style()->styleType() == type) {
        assert(child->isRenderBlock() || child->isRenderInline());
        return static_cast<RenderContainer *>(child);
    }
    if (type == RenderStyle::AFTER) {
        // check continuations
        if (continuation()) {
            return continuation()->pseudoContainer(type);
        }
    }
    if (child && child->isAnonymousBlock()) {
        return static_cast<RenderBlock *>(child)->pseudoContainer(type);
    }
    return nullptr;
}

void RenderContainer::addPseudoContainer(RenderObject *child)
{
    RenderStyle::PseudoId type = child->style()->styleType();
    switch (type) {
    case RenderStyle::AFTER: {
        RenderObject *o = this;
        while (o->continuation()) {
            o = o->continuation();
        }

        // Coalesce inlines
        if (child->style()->display() == INLINE && o->lastChild() && o->lastChild()->isAnonymousBlock()) {
            o->lastChild()->addChild(child, nullptr);
        } else {
            o->addChild(child, nullptr);
        }
        break;
    }
    case RenderStyle::BEFORE:
        // Coalesce inlines
        if (child->style()->display() == INLINE && firstChild() && firstChild()->isAnonymousBlock()) {
            firstChild()->addChild(child, firstChild()->firstChild());
        } else {
            addChild(child, firstChild());
        }
        break;
    case RenderStyle::REPLACED:
        addChild(child, pseudoContainer(RenderStyle::AFTER));
        break;
    default:
        break;
    }
}

void RenderContainer::updateReplacedContent()
{
    // Only for normal elements
    if (!style() || style()->styleType() != RenderStyle::NOPSEUDO) {
        return;
    }

    // delete old generated content
    RenderContainer *container = pseudoContainer(RenderStyle::REPLACED);
    if (container) {
        container->detach();
    }

    if (style()->useNormalContent()) {
        return;
    }

    // create generated content
    RenderStyle *pseudo = style()->getPseudoStyle(RenderStyle::REPLACED);
    if (!pseudo) {
        pseudo = new RenderStyle();
        pseudo->inheritFrom(style());
        pseudo->setStyleType(RenderStyle::REPLACED);
    }
    if (pseudo->useNormalContent()) {
        pseudo->setContentData(style()->contentData());
    }

    container = RenderFlow::createFlow(node(), pseudo, renderArena());
    container->setIsAnonymous(true);
    container->createGeneratedContent();

    addChild(container, pseudoContainer(RenderStyle::AFTER));
}

void RenderContainer::appendChildNode(RenderObject *newChild)
{
    KHTMLAssert(newChild->parent() == nullptr);

    newChild->setParent(this);
    RenderObject *lChild = lastChild();

    if (lChild) {
        newChild->setPreviousSibling(lChild);
        lChild->setNextSibling(newChild);
    } else {
        setFirstChild(newChild);
    }

    setLastChild(newChild);

    // Keep our layer hierarchy updated.  Optimize for the common case where we don't have any children
    // and don't have a layer attached to ourselves.
    RenderLayer *layer = nullptr;
    if (newChild->firstChild() || newChild->layer()) {
        layer = enclosingLayer();
        newChild->addLayers(layer, newChild);
        // keep our fixed object lists updated.
        if (newChild->style() && (newChild->style()->hasFixedBackgroundImage() || newChild->style()->position() == PFIXED)) {
            if (newChild->style()->hasFixedBackgroundImage()) {
                canvas()->addStaticObject(newChild);
            }
            if (newChild->style()->position() == PFIXED) {
                canvas()->addStaticObject(newChild, true);
            }
        }
    }

    // if the new child is visible but this object was not, tell the layer it has some visible content
    // that needs to be drawn and layer visibility optimization can't be used
    if (style()->visibility() != VISIBLE && newChild->style()->visibility() == VISIBLE && !newChild->layer()) {
        if (!layer) {
            layer = enclosingLayer();
        }
        if (layer) {
            layer->setHasVisibleContent(true);
        }
    }

    if (!newChild->isFloatingOrPositioned() && childrenInline()) {
        dirtyLinesFromChangedChild(newChild);
    }

    newChild->setNeedsLayoutAndMinMaxRecalc(); // Goes up the containing block hierarchy.

    if (!normalChildNeedsLayout()) {
        // We may supply the static position for an absolute positioned child.
        if (newChild->firstChild() || newChild->isPosWithStaticDim() || !newChild->isPositioned()) {
            setChildNeedsLayout(true);
        } else {
            assert(!newChild->inPosObjectList());
            newChild->containingBlock()->insertPositionedObject(newChild);
        }
    }
}

void RenderContainer::insertChildNode(RenderObject *child, RenderObject *beforeChild)
{
    if (!beforeChild) {
        appendChildNode(child);
        return;
    }

    KHTMLAssert(!child->parent());
    while (beforeChild->parent() != this && beforeChild->parent()->isAnonymous()) {
        beforeChild = beforeChild->parent();
    }
    KHTMLAssert(beforeChild->parent() == this);

    if (beforeChild == firstChild()) {
        setFirstChild(child);
    }

    RenderObject *prev = beforeChild->previousSibling();
    child->setNextSibling(beforeChild);
    beforeChild->setPreviousSibling(child);
    if (prev) {
        prev->setNextSibling(child);
    }
    child->setPreviousSibling(prev);
    child->setParent(this);

    // Keep our layer hierarchy updated.  Optimize for the common case where we don't have any children
    // and don't have a layer attached to ourselves.
    RenderLayer *layer = nullptr;
    if (child->firstChild() || child->layer()) {
        layer = enclosingLayer();
        child->addLayers(layer, child);
        // keep our fixed object lists updated.
        if (child->style() && (child->style()->hasFixedBackgroundImage() || child->style()->position() == PFIXED)) {
            if (child->style()->hasFixedBackgroundImage()) {
                canvas()->addStaticObject(child);
            }
            if (child->style()->position() == PFIXED) {
                canvas()->addStaticObject(child, true);
            }
        }

    }

    // if the new child is visible but this object was not, tell the layer it has some visible content
    // that needs to be drawn and layer visibility optimization can't be used
    if (style()->visibility() != VISIBLE && child->style()->visibility() == VISIBLE && !child->layer()) {
        if (!layer) {
            layer = enclosingLayer();
        }
        if (layer) {
            layer->setHasVisibleContent(true);
        }
    }

    if (!child->isFloating() && childrenInline()) {
        dirtyLinesFromChangedChild(child);
    }

    child->setNeedsLayoutAndMinMaxRecalc();

    if (!normalChildNeedsLayout()) {
        // We may supply the static position for an absolute positioned child.
        if (child->firstChild() || child->isPosWithStaticDim() || !child->isPositioned()) {
            setChildNeedsLayout(true);
        } else {
            assert(!child->inPosObjectList());
            child->containingBlock()->insertPositionedObject(child);
        }
    }
}

void RenderContainer::layout()
{
    KHTMLAssert(needsLayout());
    KHTMLAssert(minMaxKnown());
    const bool pagedMode = canvas()->pagedMode();
    RenderObject *child = firstChild();
    while (child) {
        if (pagedMode) {
            child->setNeedsLayout(true);
        }
        child->layoutIfNeeded();
        if (child->containsPageBreak()) {
            setContainsPageBreak(true);
        }
        if (child->needsPageClear()) {
            setNeedsPageClear(true);
        }
        child = child->nextSibling();
    }
    setNeedsLayout(false);
}

void RenderContainer::removeSuperfluousAnonymousBlockChild(RenderObject *child)
{
    KHTMLAssert(child->parent() == this && child->isAnonymousBlock());

    if (child->doNotDelete() || child->continuation()) {
        return;
    }

    RenderObject *childSFirstChild = child->firstChild();
    RenderObject *childSLastChild = child->lastChild();

    if (childSFirstChild) {
        RenderObject *o = childSFirstChild;
        while (o) {
            o->setParent(this);
            o = o->nextSibling();
        }
        childSFirstChild->setPreviousSibling(child->previousSibling());
        childSLastChild->setNextSibling(child->nextSibling());
        if (child->previousSibling()) {
            child->previousSibling()->setNextSibling(childSFirstChild);
        }
        if (child->nextSibling()) {
            child->nextSibling()->setPreviousSibling(childSLastChild);
        }
        if (child == firstChild()) {
            m_first = childSFirstChild;
        }
        if (child == lastChild()) {
            m_last = childSLastChild;
        }
    } else {
        if (child->previousSibling()) {
            child->previousSibling()->setNextSibling(child->nextSibling());
        }
        if (child->nextSibling()) {
            child->nextSibling()->setPreviousSibling(child->previousSibling());
        }
        if (child == firstChild()) {
            m_first = child->nextSibling();
        }
        if (child == lastChild()) {
            m_last = child->previousSibling();
        }
    }
    child->setParent(nullptr);
    child->setPreviousSibling(nullptr);
    child->setNextSibling(nullptr);
    if (!child->isText()) {
        RenderContainer *c = static_cast<RenderContainer *>(child);
        c->m_first = nullptr;
        c->m_next = nullptr;
    }
    child->detach();
}

RenderPosition RenderContainer::positionForCoordinates(int _x, int _y)
{
    // no children...return this render object's element, if there is one, and offset 0
    if (!firstChild()) {
        return RenderPosition(element(), 0);
    }

    // look for the geometrically-closest child and pass off to that child
    int min = INT_MAX;
    RenderObject *closestRenderer = firstChild();
    for (RenderObject *renderer = firstChild(); renderer; renderer = renderer->nextSibling()) {
        int absx, absy;
        renderer->absolutePosition(absx, absy);

        int top = absy + borderTop() + paddingTop();
        int bottom = top + renderer->contentHeight();
        int left = absx + borderLeft() + paddingLeft();
        int right = left + renderer->contentWidth();

        int cmp;
        cmp = abs(_y - top);    if (cmp < min) {
            closestRenderer = renderer;
            min = cmp;
        }
        cmp = abs(_y - bottom); if (cmp < min) {
            closestRenderer = renderer;
            min = cmp;
        }
        cmp = abs(_x - left);   if (cmp < min) {
            closestRenderer = renderer;
            min = cmp;
        }
        cmp = abs(_x - right);  if (cmp < min) {
            closestRenderer = renderer;
            min = cmp;
        }
    }

    return closestRenderer->positionForCoordinates(_x, _y);
}

#undef DEBUG_LAYOUT