CSSRegions: Crash when attaching a region to the removed named flow
[WebKit-https.git] / Source / WebCore / rendering / RenderObject.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  *           (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
7  * Copyright (C) 2009 Google Inc. All rights reserved.
8  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public License
21  * along with this library; see the file COPYING.LIB.  If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  */
26
27 #include "config.h"
28 #include "RenderObject.h"
29
30 #include "AXObjectCache.h"
31 #include "Chrome.h"
32 #include "ContentData.h"
33 #include "CursorList.h"
34 #include "DashArray.h"
35 #include "EditingBoundary.h"
36 #include "FloatQuad.h"
37 #include "FlowThreadController.h"
38 #include "Frame.h"
39 #include "FrameView.h"
40 #include "GraphicsContext.h"
41 #include "HTMLElement.h"
42 #include "HTMLNames.h"
43 #include "HitTestResult.h"
44 #include "Page.h"
45 #include "RenderArena.h"
46 #include "RenderCounter.h"
47 #include "RenderDeprecatedFlexibleBox.h"
48 #include "RenderFlexibleBox.h"
49 #include "RenderGeometryMap.h"
50 #include "RenderGrid.h"
51 #include "RenderImage.h"
52 #include "RenderImageResourceStyleImage.h"
53 #include "RenderInline.h"
54 #include "RenderLayer.h"
55 #include "RenderListItem.h"
56 #include "RenderMultiColumnBlock.h"
57 #include "RenderNamedFlowThread.h"
58 #include "RenderRegion.h"
59 #include "RenderRuby.h"
60 #include "RenderRubyText.h"
61 #include "RenderScrollbarPart.h"
62 #include "RenderTableCaption.h"
63 #include "RenderTableCell.h"
64 #include "RenderTableCol.h"
65 #include "RenderTableRow.h"
66 #include "RenderTheme.h"
67 #include "RenderView.h"
68 #include "Settings.h"
69 #include "StyleResolver.h"
70 #include "TransformState.h"
71 #include "htmlediting.h"
72 #include <algorithm>
73 #include <stdio.h>
74 #include <wtf/RefCountedLeakCounter.h>
75 #include <wtf/UnusedParam.h>
76
77 #if USE(ACCELERATED_COMPOSITING)
78 #include "RenderLayerCompositor.h"
79 #endif
80
81 #if ENABLE(SVG)
82 #include "RenderSVGResourceContainer.h"
83 #include "SVGRenderSupport.h"
84 #endif
85
86 using namespace std;
87
88 namespace WebCore {
89
90 using namespace HTMLNames;
91
92 #ifndef NDEBUG
93 static void* baseOfRenderObjectBeingDeleted;
94 #endif
95
96 struct SameSizeAsRenderObject {
97     virtual ~SameSizeAsRenderObject() { } // Allocate vtable pointer.
98     void* pointers[5];
99 #ifndef NDEBUG
100     unsigned m_debugBitfields : 2;
101 #endif
102     unsigned m_bitfields;
103 };
104
105 COMPILE_ASSERT(sizeof(RenderObject) == sizeof(SameSizeAsRenderObject), RenderObject_should_stay_small);
106
107 bool RenderObject::s_affectsParentBlock = false;
108
109 RenderObjectAncestorLineboxDirtySet* RenderObject::s_ancestorLineboxDirtySet = 0;
110
111 void* RenderObject::operator new(size_t sz, RenderArena* renderArena)
112 {
113     return renderArena->allocate(sz);
114 }
115
116 void RenderObject::operator delete(void* ptr, size_t sz)
117 {
118     ASSERT(baseOfRenderObjectBeingDeleted == ptr);
119
120     // Stash size where destroy can find it.
121     *(size_t *)ptr = sz;
122 }
123
124 RenderObject* RenderObject::createObject(Node* node, RenderStyle* style)
125 {
126     Document* doc = node->document();
127     RenderArena* arena = doc->renderArena();
128
129     // Minimal support for content properties replacing an entire element.
130     // Works only if we have exactly one piece of content and it's a URL.
131     // Otherwise acts as if we didn't support this feature.
132     const ContentData* contentData = style->contentData();
133     if (contentData && !contentData->next() && contentData->isImage() && doc != node) {
134         RenderImage* image = new (arena) RenderImage(node);
135         image->setStyle(style);
136         if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image()) {
137             image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
138             image->setIsGeneratedContent();
139         } else
140             image->setImageResource(RenderImageResource::create());
141         return image;
142     }
143
144     if (node->hasTagName(rubyTag)) {
145         if (style->display() == INLINE)
146             return new (arena) RenderRubyAsInline(node);
147         else if (style->display() == BLOCK)
148             return new (arena) RenderRubyAsBlock(node);
149     }
150     // treat <rt> as ruby text ONLY if it still has its default treatment of block
151     if (node->hasTagName(rtTag) && style->display() == BLOCK)
152         return new (arena) RenderRubyText(node);
153     if (doc->cssRegionsEnabled() && style->isDisplayRegionType() && !style->regionThread().isEmpty() && doc->renderView())
154         return new (arena) RenderRegion(node, 0);
155     switch (style->display()) {
156     case NONE:
157         return 0;
158     case INLINE:
159         return new (arena) RenderInline(node);
160     case BLOCK:
161     case INLINE_BLOCK:
162     case RUN_IN:
163     case COMPACT:
164         if ((!style->hasAutoColumnCount() || !style->hasAutoColumnWidth()) && doc->regionBasedColumnsEnabled())
165             return new (arena) RenderMultiColumnBlock(node);
166         return new (arena) RenderBlock(node);
167     case LIST_ITEM:
168         return new (arena) RenderListItem(node);
169     case TABLE:
170     case INLINE_TABLE:
171         return new (arena) RenderTable(node);
172     case TABLE_ROW_GROUP:
173     case TABLE_HEADER_GROUP:
174     case TABLE_FOOTER_GROUP:
175         return new (arena) RenderTableSection(node);
176     case TABLE_ROW:
177         return new (arena) RenderTableRow(node);
178     case TABLE_COLUMN_GROUP:
179     case TABLE_COLUMN:
180         return new (arena) RenderTableCol(node);
181     case TABLE_CELL:
182         return new (arena) RenderTableCell(node);
183     case TABLE_CAPTION:
184         return new (arena) RenderTableCaption(node);
185     case BOX:
186     case INLINE_BOX:
187         return new (arena) RenderDeprecatedFlexibleBox(node);
188 #if ENABLE(CSS3_FLEXBOX)
189     case FLEX:
190     case INLINE_FLEX:
191         return new (arena) RenderFlexibleBox(node);
192 #endif
193     case GRID:
194     case INLINE_GRID:
195         return new (arena) RenderGrid(node);
196     }
197
198     return 0;
199 }
200
201 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject"));
202
203 RenderObject::RenderObject(Node* node)
204     : CachedImageClient()
205     , m_style(0)
206     , m_node(node)
207     , m_parent(0)
208     , m_previous(0)
209     , m_next(0)
210 #ifndef NDEBUG
211     , m_hasAXObject(false)
212     , m_setNeedsLayoutForbidden(false)
213 #endif
214     , m_bitfields(node)
215 {
216 #ifndef NDEBUG
217     renderObjectCounter.increment();
218 #endif
219     ASSERT(node);
220 }
221
222 RenderObject::~RenderObject()
223 {
224 #ifndef NDEBUG
225     ASSERT(!m_hasAXObject);
226     renderObjectCounter.decrement();
227 #endif
228 }
229
230 RenderTheme* RenderObject::theme() const
231 {
232     ASSERT(document()->page());
233
234     return document()->page()->theme();
235 }
236
237 bool RenderObject::isDescendantOf(const RenderObject* obj) const
238 {
239     for (const RenderObject* r = this; r; r = r->m_parent) {
240         if (r == obj)
241             return true;
242     }
243     return false;
244 }
245
246 bool RenderObject::isBody() const
247 {
248     return node() && node()->hasTagName(bodyTag);
249 }
250
251 bool RenderObject::isHR() const
252 {
253     return node() && node()->hasTagName(hrTag);
254 }
255
256 bool RenderObject::isLegend() const
257 {
258     return node() && node()->hasTagName(legendTag);
259 }
260
261 bool RenderObject::isHTMLMarquee() const
262 {
263     return node() && node()->renderer() == this && node()->hasTagName(marqueeTag);
264 }
265
266 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
267 {
268     RenderObjectChildList* children = virtualChildren();
269     ASSERT(children);
270     if (!children)
271         return;
272
273     bool needsTable = false;
274
275     if (newChild->isRenderTableCol()) {
276         RenderTableCol* newTableColumn = toRenderTableCol(newChild);
277         bool isColumnInColumnGroup = newTableColumn->isTableColumn() && isRenderTableCol();
278         needsTable = !isTable() && !isColumnInColumnGroup;
279     } else if (newChild->isTableCaption())
280         needsTable = !isTable();
281     else if (newChild->isTableSection())
282         needsTable = !isTable();
283     else if (newChild->isTableRow())
284         needsTable = !isTableSection();
285     else if (newChild->isTableCell())
286         needsTable = !isTableRow();
287
288     if (needsTable) {
289         RenderTable* table;
290         RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
291         if (afterChild && afterChild->isAnonymous() && afterChild->isTable() && !afterChild->isBeforeContent())
292             table = toRenderTable(afterChild);
293         else {
294             table = RenderTable::createAnonymousWithParentRenderer(this);
295             addChild(table, beforeChild);
296         }
297         table->addChild(newChild);
298     } else
299         children->insertChildNode(this, newChild, beforeChild);
300
301     if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE)
302         toRenderText(newChild)->transformText();
303
304     // SVG creates renderers for <g display="none">, as SVG requires children of hidden
305     // <g>s to have renderers - at least that's how our implementation works. Consider:
306     // <g display="none"><foreignObject><body style="position: relative">FOO...
307     // - requiresLayer() would return true for the <body>, creating a new RenderLayer
308     // - when the document is painted, both layers are painted. The <body> layer doesn't
309     //   know that it's inside a "hidden SVG subtree", and thus paints, even if it shouldn't.
310     // To avoid the problem alltogether, detect early if we're inside a hidden SVG subtree
311     // and stop creating layers at all for these cases - they're not used anyways.
312     if (newChild->hasLayer() && !layerCreationAllowedForSubtree())
313         toRenderBoxModelObject(newChild)->layer()->removeOnlyThisLayer();
314 }
315
316 void RenderObject::removeChild(RenderObject* oldChild)
317 {
318     RenderObjectChildList* children = virtualChildren();
319     ASSERT(children);
320     if (!children)
321         return;
322
323     children->removeChildNode(this, oldChild);
324 }
325
326 RenderObject* RenderObject::nextInPreOrder() const
327 {
328     if (RenderObject* o = firstChild())
329         return o;
330
331     return nextInPreOrderAfterChildren();
332 }
333
334 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
335 {
336     RenderObject* o;
337     if (!(o = nextSibling())) {
338         o = parent();
339         while (o && !o->nextSibling())
340             o = o->parent();
341         if (o)
342             o = o->nextSibling();
343     }
344
345     return o;
346 }
347
348 RenderObject* RenderObject::nextInPreOrder(const RenderObject* stayWithin) const
349 {
350     if (RenderObject* o = firstChild())
351         return o;
352
353     return nextInPreOrderAfterChildren(stayWithin);
354 }
355
356 RenderObject* RenderObject::nextInPreOrderAfterChildren(const RenderObject* stayWithin) const
357 {
358     if (this == stayWithin)
359         return 0;
360
361     const RenderObject* current = this;
362     RenderObject* next;
363     while (!(next = current->nextSibling())) {
364         current = current->parent();
365         if (!current || current == stayWithin)
366             return 0;
367     }
368     return next;
369 }
370
371 RenderObject* RenderObject::previousInPreOrder() const
372 {
373     if (RenderObject* o = previousSibling()) {
374         while (o->lastChild())
375             o = o->lastChild();
376         return o;
377     }
378
379     return parent();
380 }
381
382 RenderObject* RenderObject::previousInPreOrder(const RenderObject* stayWithin) const
383 {
384     if (this == stayWithin)
385         return 0;
386
387     return previousInPreOrder();
388 }
389
390 RenderObject* RenderObject::childAt(unsigned index) const
391 {
392     RenderObject* child = firstChild();
393     for (unsigned i = 0; child && i < index; i++)
394         child = child->nextSibling();
395     return child;
396 }
397
398 RenderObject* RenderObject::firstLeafChild() const
399 {
400     RenderObject* r = firstChild();
401     while (r) {
402         RenderObject* n = 0;
403         n = r->firstChild();
404         if (!n)
405             break;
406         r = n;
407     }
408     return r;
409 }
410
411 RenderObject* RenderObject::lastLeafChild() const
412 {
413     RenderObject* r = lastChild();
414     while (r) {
415         RenderObject* n = 0;
416         n = r->lastChild();
417         if (!n)
418             break;
419         r = n;
420     }
421     return r;
422 }
423
424 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
425                       RenderLayer*& beforeChild)
426 {
427     if (obj->hasLayer()) {
428         if (!beforeChild && newObject) {
429             // We need to figure out the layer that follows newObject.  We only do
430             // this the first time we find a child layer, and then we update the
431             // pointer values for newObject and beforeChild used by everyone else.
432             beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
433             newObject = 0;
434         }
435         parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild);
436         return;
437     }
438
439     for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
440         addLayers(curr, parentLayer, newObject, beforeChild);
441 }
442
443 void RenderObject::addLayers(RenderLayer* parentLayer)
444 {
445     if (!parentLayer)
446         return;
447
448     RenderObject* object = this;
449     RenderLayer* beforeChild = 0;
450     WebCore::addLayers(this, parentLayer, object, beforeChild);
451 }
452
453 void RenderObject::removeLayers(RenderLayer* parentLayer)
454 {
455     if (!parentLayer)
456         return;
457
458     if (hasLayer()) {
459         parentLayer->removeChild(toRenderBoxModelObject(this)->layer());
460         return;
461     }
462
463     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
464         curr->removeLayers(parentLayer);
465 }
466
467 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
468 {
469     if (!newParent)
470         return;
471
472     if (hasLayer()) {
473         RenderLayer* layer = toRenderBoxModelObject(this)->layer();
474         ASSERT(oldParent == layer->parent());
475         if (oldParent)
476             oldParent->removeChild(layer);
477         newParent->addChild(layer);
478         return;
479     }
480
481     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
482         curr->moveLayers(oldParent, newParent);
483 }
484
485 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
486                                          bool checkParent)
487 {
488     // Error check the parent layer passed in.  If it's null, we can't find anything.
489     if (!parentLayer)
490         return 0;
491
492     // Step 1: If our layer is a child of the desired parent, then return our layer.
493     RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0;
494     if (ourLayer && ourLayer->parent() == parentLayer)
495         return ourLayer;
496
497     // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
498     // into our siblings trying to find the next layer whose parent is the desired parent.
499     if (!ourLayer || ourLayer == parentLayer) {
500         for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
501              curr; curr = curr->nextSibling()) {
502             RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
503             if (nextLayer)
504                 return nextLayer;
505         }
506     }
507
508     // Step 3: If our layer is the desired parent layer, then we're finished.  We didn't
509     // find anything.
510     if (parentLayer == ourLayer)
511         return 0;
512
513     // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
514     // follow us to see if we can locate a layer.
515     if (checkParent && parent())
516         return parent()->findNextLayer(parentLayer, this, true);
517
518     return 0;
519 }
520
521 RenderLayer* RenderObject::enclosingLayer() const
522 {
523     const RenderObject* curr = this;
524     while (curr) {
525         RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
526         if (layer)
527             return layer;
528         curr = curr->parent();
529     }
530     return 0;
531 }
532
533 bool RenderObject::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
534 {
535     RenderLayer* enclosingLayer = this->enclosingLayer();
536     if (!enclosingLayer)
537         return false;
538
539     enclosingLayer->scrollRectToVisible(rect, alignX, alignY);
540     return true;
541 }
542
543 RenderBox* RenderObject::enclosingBox() const
544 {
545     RenderObject* curr = const_cast<RenderObject*>(this);
546     while (curr) {
547         if (curr->isBox())
548             return toRenderBox(curr);
549         curr = curr->parent();
550     }
551     
552     ASSERT_NOT_REACHED();
553     return 0;
554 }
555
556 RenderBoxModelObject* RenderObject::enclosingBoxModelObject() const
557 {
558     RenderObject* curr = const_cast<RenderObject*>(this);
559     while (curr) {
560         if (curr->isBoxModelObject())
561             return toRenderBoxModelObject(curr);
562         curr = curr->parent();
563     }
564
565     ASSERT_NOT_REACHED();
566     return 0;
567 }
568
569 RenderFlowThread* RenderObject::enclosingRenderFlowThread() const
570 {   
571     if (!inRenderFlowThread())
572         return 0;
573     
574     // See if we have the thread cached because we're in the middle of layout.
575     RenderFlowThread* flowThread = view()->flowThreadController()->currentRenderFlowThread();
576     if (flowThread)
577         return flowThread;
578     
579     // Not in the middle of layout so have to find the thread the slow way.
580     RenderObject* curr = const_cast<RenderObject*>(this);
581     while (curr) {
582         if (curr->isRenderFlowThread())
583             return toRenderFlowThread(curr);
584         curr = curr->parent();
585     }
586     return 0;
587 }
588
589 RenderBlock* RenderObject::firstLineBlock() const
590 {
591     return 0;
592 }
593
594 static inline bool objectIsRelayoutBoundary(const RenderObject* object)
595 {
596     // FIXME: In future it may be possible to broaden these conditions in order to improve performance.
597     if (object->isTextControl())
598         return true;
599
600 #if ENABLE(SVG)
601     if (object->isSVGRoot())
602         return true;
603 #endif
604
605     if (!object->hasOverflowClip())
606         return false;
607
608     if (object->style()->width().isIntrinsicOrAuto() || object->style()->height().isIntrinsicOrAuto() || object->style()->height().isPercent())
609         return false;
610
611     // Table parts can't be relayout roots since the table is responsible for layouting all the parts.
612     if (object->isTablePart())
613         return false;
614
615     return true;
616 }
617
618 void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot)
619 {
620     ASSERT(!scheduleRelayout || !newRoot);
621
622     RenderObject* object = container();
623     RenderObject* last = this;
624
625     bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout();
626
627     while (object) {
628         // Don't mark the outermost object of an unrooted subtree. That object will be
629         // marked when the subtree is added to the document.
630         RenderObject* container = object->container();
631         if (!container && !object->isRenderView())
632             return;
633         if (!last->isText() && last->style()->isOutOfFlowPositioned()) {
634             bool willSkipRelativelyPositionedInlines = !object->isRenderBlock() || object->isAnonymousBlock();
635             // Skip relatively positioned inlines and anonymous blocks to get to the enclosing RenderBlock.
636             while (object && (!object->isRenderBlock() || object->isAnonymousBlock()))
637                 object = object->container();
638             if (!object || object->posChildNeedsLayout())
639                 return;
640             if (willSkipRelativelyPositionedInlines)
641                 container = object->container();
642             object->setPosChildNeedsLayout(true);
643             simplifiedNormalFlowLayout = true;
644             ASSERT(!object->isSetNeedsLayoutForbidden());
645         } else if (simplifiedNormalFlowLayout) {
646             if (object->needsSimplifiedNormalFlowLayout())
647                 return;
648             object->setNeedsSimplifiedNormalFlowLayout(true);
649             ASSERT(!object->isSetNeedsLayoutForbidden());
650         } else {
651             if (object->normalChildNeedsLayout())
652                 return;
653             object->setNormalChildNeedsLayout(true);
654             ASSERT(!object->isSetNeedsLayoutForbidden());
655         }
656
657         if (object == newRoot)
658             return;
659
660         last = object;
661         if (scheduleRelayout && objectIsRelayoutBoundary(last))
662             break;
663         object = container;
664     }
665
666     if (scheduleRelayout)
667         last->scheduleRelayout();
668 }
669
670 #ifndef NDEBUG
671 void RenderObject::checkBlockPositionedObjectsNeedLayout()
672 {
673     ASSERT(!needsLayout());
674
675     if (isRenderBlock())
676         toRenderBlock(this)->checkPositionedObjectsNeedLayout();
677 }
678 #endif
679
680 void RenderObject::setPreferredLogicalWidthsDirty(bool shouldBeDirty, MarkingBehavior markParents)
681 {
682     bool alreadyDirty = preferredLogicalWidthsDirty();
683     m_bitfields.setPreferredLogicalWidthsDirty(shouldBeDirty);
684     if (shouldBeDirty && !alreadyDirty && markParents == MarkContainingBlockChain && (isText() || !style()->isOutOfFlowPositioned()))
685         invalidateContainerPreferredLogicalWidths();
686 }
687
688 void RenderObject::invalidateContainerPreferredLogicalWidths()
689 {
690     // In order to avoid pathological behavior when inlines are deeply nested, we do include them
691     // in the chain that we mark dirty (even though they're kind of irrelevant).
692     RenderObject* o = isTableCell() ? containingBlock() : container();
693     while (o && !o->preferredLogicalWidthsDirty()) {
694         // Don't invalidate the outermost object of an unrooted subtree. That object will be 
695         // invalidated when the subtree is added to the document.
696         RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
697         if (!container && !o->isRenderView())
698             break;
699
700         o->m_bitfields.setPreferredLogicalWidthsDirty(true);
701         if (o->style()->isOutOfFlowPositioned())
702             // A positioned object has no effect on the min/max width of its containing block ever.
703             // We can optimize this case and not go up any further.
704             break;
705         o = container;
706     }
707 }
708
709 void RenderObject::setLayerNeedsFullRepaint()
710 {
711     ASSERT(hasLayer());
712     toRenderBoxModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaint);
713 }
714
715 void RenderObject::setLayerNeedsFullRepaintForPositionedMovementLayout()
716 {
717     ASSERT(hasLayer());
718     toRenderBoxModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaintForPositionedMovementLayout);
719 }
720
721 RenderBlock* RenderObject::containingBlock() const
722 {
723     RenderObject* o = parent();
724     if (!o && isRenderScrollbarPart())
725         o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
726     if (!isText() && m_style->position() == FixedPosition) {
727         while (o) {
728             if (o->isRenderView())
729                 break;
730             if (o->hasTransform() && o->isRenderBlock())
731                 break;
732             // The render flow thread is the top most containing block
733             // for the fixed positioned elements.
734             if (o->isRenderFlowThread())
735                 break;
736 #if ENABLE(SVG)
737             // foreignObject is the containing block for its contents.
738             if (o->isSVGForeignObject())
739                 break;
740 #endif
741             o = o->parent();
742         }
743         ASSERT(!o->isAnonymousBlock());
744     } else if (!isText() && m_style->position() == AbsolutePosition) {
745         while (o) {
746             // For relpositioned inlines, we return the nearest non-anonymous enclosing block. We don't try
747             // to return the inline itself.  This allows us to avoid having a positioned objects
748             // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
749             // from this method.  The container() method can actually be used to obtain the
750             // inline directly.
751             if (!o->style()->position() == StaticPosition && !(o->isInline() && !o->isReplaced()))
752                 break;
753             if (o->isRenderView())
754                 break;
755             if (o->hasTransform() && o->isRenderBlock())
756                 break;
757
758             if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced()) {
759                 o = o->containingBlock();
760                 break;
761             }
762 #if ENABLE(SVG)
763             if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it
764                 break;
765 #endif
766
767             o = o->parent();
768         }
769
770         while (o && o->isAnonymousBlock())
771             o = o->containingBlock();
772     } else {
773         while (o && ((o->isInline() && !o->isReplaced()) || !o->isRenderBlock()))
774             o = o->parent();
775     }
776
777     if (!o || !o->isRenderBlock())
778         return 0; // This can still happen in case of an orphaned tree
779
780     return toRenderBlock(o);
781 }
782
783 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
784 {
785     // Nobody will use multiple layers without wanting fancy positioning.
786     if (layer->next())
787         return true;
788
789     // Make sure we have a valid image.
790     StyleImage* img = layer->image();
791     if (!img || !img->canRender(renderer, renderer->style()->effectiveZoom()))
792         return false;
793
794     if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
795         return true;
796
797     if (layer->size().type == SizeLength) {
798         if (layer->size().size.width().isPercent() || layer->size().size.height().isPercent())
799             return true;
800     } else if (layer->size().type == Contain || layer->size().type == Cover || img->usesImageContainerSize())
801         return true;
802
803     return false;
804 }
805
806 bool RenderObject::borderImageIsLoadedAndCanBeRendered() const
807 {
808     ASSERT(style()->hasBorder());
809
810     StyleImage* borderImage = style()->borderImage().image();
811     return borderImage && borderImage->canRender(this, style()->effectiveZoom()) && borderImage->isLoaded();
812 }
813
814 bool RenderObject::mustRepaintBackgroundOrBorder() const
815 {
816     if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
817         return true;
818
819     // If we don't have a background/border/mask, then nothing to do.
820     if (!hasBoxDecorations())
821         return false;
822
823     if (mustRepaintFillLayers(this, style()->backgroundLayers()))
824         return true;
825      
826     // Our fill layers are ok.  Let's check border.
827     if (style()->hasBorder() && borderImageIsLoadedAndCanBeRendered())
828         return true;
829
830     return false;
831 }
832
833 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
834                                       BoxSide side, Color color, EBorderStyle style,
835                                       int adjacentWidth1, int adjacentWidth2, bool antialias)
836 {
837     int thickness;
838     int length;
839     if (side == BSTop || side == BSBottom) {
840         thickness = y2 - y1;
841         length = x2 - x1;
842     } else {
843         thickness = x2 - x1;
844         length = y2 - y1;
845     }
846
847     // FIXME: We really would like this check to be an ASSERT as we don't want to draw empty borders. However
848     // nothing guarantees that the following recursive calls to drawLineForBoxSide will have non-null dimensions.
849     if (!thickness || !length)
850         return;
851
852     if (style == DOUBLE && thickness < 3)
853         style = SOLID;
854
855     switch (style) {
856         case BNONE:
857         case BHIDDEN:
858             return;
859         case DOTTED:
860         case DASHED: {
861             graphicsContext->setStrokeColor(color, m_style->colorSpace());
862             graphicsContext->setStrokeThickness(thickness);
863             StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
864             graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
865
866             if (thickness > 0) {
867                 bool wasAntialiased = graphicsContext->shouldAntialias();
868                 graphicsContext->setShouldAntialias(antialias);
869
870                 switch (side) {
871                     case BSBottom:
872                     case BSTop:
873                         graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
874                         break;
875                     case BSRight:
876                     case BSLeft:
877                         graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
878                         break;
879                 }
880                 graphicsContext->setShouldAntialias(wasAntialiased);
881                 graphicsContext->setStrokeStyle(oldStrokeStyle);
882             }
883             break;
884         }
885         case DOUBLE: {
886             int thirdOfThickness = (thickness + 1) / 3;
887             ASSERT(thirdOfThickness);
888
889             if (adjacentWidth1 == 0 && adjacentWidth2 == 0) {
890                 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
891                 graphicsContext->setStrokeStyle(NoStroke);
892                 graphicsContext->setFillColor(color, m_style->colorSpace());
893                 
894                 bool wasAntialiased = graphicsContext->shouldAntialias();
895                 graphicsContext->setShouldAntialias(antialias);
896
897                 switch (side) {
898                     case BSTop:
899                     case BSBottom:
900                         graphicsContext->drawRect(IntRect(x1, y1, length, thirdOfThickness));
901                         graphicsContext->drawRect(IntRect(x1, y2 - thirdOfThickness, length, thirdOfThickness));
902                         break;
903                     case BSLeft:
904                     case BSRight:
905                         // FIXME: Why do we offset the border by 1 in this case but not the other one?
906                         if (length > 1) {
907                             graphicsContext->drawRect(IntRect(x1, y1 + 1, thirdOfThickness, length - 1));
908                             graphicsContext->drawRect(IntRect(x2 - thirdOfThickness, y1 + 1, thirdOfThickness, length - 1));
909                         }
910                         break;
911                 }
912
913                 graphicsContext->setShouldAntialias(wasAntialiased);
914                 graphicsContext->setStrokeStyle(oldStrokeStyle);
915             } else {
916                 int adjacent1BigThird = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3;
917                 int adjacent2BigThird = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3;
918
919                 switch (side) {
920                     case BSTop:
921                         drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
922                                    y1, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
923                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
924                         drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
925                                    y2 - thirdOfThickness, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y2,
926                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
927                         break;
928                     case BSLeft:
929                         drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
930                                    x1 + thirdOfThickness, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
931                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
932                         drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
933                                    x2, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
934                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
935                         break;
936                     case BSBottom:
937                         drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
938                                    y1, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
939                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
940                         drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
941                                    y2 - thirdOfThickness, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y2,
942                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
943                         break;
944                     case BSRight:
945                         drawLineForBoxSide(graphicsContext, x1, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
946                                    x1 + thirdOfThickness, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
947                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
948                         drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
949                                    x2, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
950                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
951                         break;
952                     default:
953                         break;
954                 }
955             }
956             break;
957         }
958         case RIDGE:
959         case GROOVE: {
960             EBorderStyle s1;
961             EBorderStyle s2;
962             if (style == GROOVE) {
963                 s1 = INSET;
964                 s2 = OUTSET;
965             } else {
966                 s1 = OUTSET;
967                 s2 = INSET;
968             }
969
970             int adjacent1BigHalf = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2;
971             int adjacent2BigHalf = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2;
972
973             switch (side) {
974                 case BSTop:
975                     drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1, 0) / 2, y1, x2 - max(-adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
976                                side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
977                     drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjacentWidth2 + 1, 0) / 2, y2,
978                                side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
979                     break;
980                 case BSLeft:
981                     drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjacentWidth2, 0) / 2,
982                                side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
983                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjacentWidth1 + 1, 0) / 2, x2, y2 - max(adjacentWidth2 + 1, 0) / 2,
984                                side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
985                     break;
986                 case BSBottom:
987                     drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1, 0) / 2, y1, x2 - max(adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
988                                side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
989                     drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjacentWidth2 + 1, 0) / 2, y2,
990                                side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
991                     break;
992                 case BSRight:
993                     drawLineForBoxSide(graphicsContext, x1, y1 + max(adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjacentWidth2, 0) / 2,
994                                side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
995                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjacentWidth1 + 1, 0) / 2, x2, y2 - max(-adjacentWidth2 + 1, 0) / 2,
996                                side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
997                     break;
998             }
999             break;
1000         }
1001         case INSET:
1002             // FIXME: Maybe we should lighten the colors on one side like Firefox.
1003             // https://bugs.webkit.org/show_bug.cgi?id=58608
1004             if (side == BSTop || side == BSLeft)
1005                 color = color.dark();
1006             // fall through
1007         case OUTSET:
1008             if (style == OUTSET && (side == BSBottom || side == BSRight))
1009                 color = color.dark();
1010             // fall through
1011         case SOLID: {
1012             StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
1013             graphicsContext->setStrokeStyle(NoStroke);
1014             graphicsContext->setFillColor(color, m_style->colorSpace());
1015             ASSERT(x2 >= x1);
1016             ASSERT(y2 >= y1);
1017             if (!adjacentWidth1 && !adjacentWidth2) {
1018                 // Turn off antialiasing to match the behavior of drawConvexPolygon();
1019                 // this matters for rects in transformed contexts.
1020                 bool wasAntialiased = graphicsContext->shouldAntialias();
1021                 graphicsContext->setShouldAntialias(antialias);
1022                 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1023                 graphicsContext->setShouldAntialias(wasAntialiased);
1024                 graphicsContext->setStrokeStyle(oldStrokeStyle);
1025                 return;
1026             }
1027             FloatPoint quad[4];
1028             switch (side) {
1029                 case BSTop:
1030                     quad[0] = FloatPoint(x1 + max(-adjacentWidth1, 0), y1);
1031                     quad[1] = FloatPoint(x1 + max(adjacentWidth1, 0), y2);
1032                     quad[2] = FloatPoint(x2 - max(adjacentWidth2, 0), y2);
1033                     quad[3] = FloatPoint(x2 - max(-adjacentWidth2, 0), y1);
1034                     break;
1035                 case BSBottom:
1036                     quad[0] = FloatPoint(x1 + max(adjacentWidth1, 0), y1);
1037                     quad[1] = FloatPoint(x1 + max(-adjacentWidth1, 0), y2);
1038                     quad[2] = FloatPoint(x2 - max(-adjacentWidth2, 0), y2);
1039                     quad[3] = FloatPoint(x2 - max(adjacentWidth2, 0), y1);
1040                     break;
1041                 case BSLeft:
1042                     quad[0] = FloatPoint(x1, y1 + max(-adjacentWidth1, 0));
1043                     quad[1] = FloatPoint(x1, y2 - max(-adjacentWidth2, 0));
1044                     quad[2] = FloatPoint(x2, y2 - max(adjacentWidth2, 0));
1045                     quad[3] = FloatPoint(x2, y1 + max(adjacentWidth1, 0));
1046                     break;
1047                 case BSRight:
1048                     quad[0] = FloatPoint(x1, y1 + max(adjacentWidth1, 0));
1049                     quad[1] = FloatPoint(x1, y2 - max(adjacentWidth2, 0));
1050                     quad[2] = FloatPoint(x2, y2 - max(-adjacentWidth2, 0));
1051                     quad[3] = FloatPoint(x2, y1 + max(-adjacentWidth1, 0));
1052                     break;
1053             }
1054
1055             graphicsContext->drawConvexPolygon(4, quad, antialias);
1056             graphicsContext->setStrokeStyle(oldStrokeStyle);
1057             break;
1058         }
1059     }
1060 }
1061
1062 void RenderObject::paintFocusRing(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style)
1063 {
1064     Vector<IntRect> focusRingRects;
1065     addFocusRingRects(focusRingRects, paintOffset);
1066     if (style->outlineStyleIsAuto())
1067         context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
1068     else
1069         addPDFURLRect(context, unionRect(focusRingRects));
1070 }
1071
1072 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
1073 {
1074     if (rect.isEmpty())
1075         return;
1076     Node* n = node();
1077     if (!n || !n->isLink() || !n->isElementNode())
1078         return;
1079     const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
1080     if (href.isNull())
1081         return;
1082     context->setURLForRect(n->document()->completeURL(href), pixelSnappedIntRect(rect));
1083 }
1084
1085 void RenderObject::paintOutline(GraphicsContext* graphicsContext, const LayoutRect& paintRect)
1086 {
1087     if (!hasOutline())
1088         return;
1089
1090     RenderStyle* styleToUse = style();
1091     LayoutUnit outlineWidth = styleToUse->outlineWidth();
1092     EBorderStyle outlineStyle = styleToUse->outlineStyle();
1093
1094     Color outlineColor = styleToUse->visitedDependentColor(CSSPropertyOutlineColor);
1095
1096     int outlineOffset = styleToUse->outlineOffset();
1097
1098     if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1099         if (!theme()->supportsFocusRing(styleToUse)) {
1100             // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1101             paintFocusRing(graphicsContext, paintRect.location(), styleToUse);
1102         }
1103     }
1104
1105     if (styleToUse->outlineStyleIsAuto() || styleToUse->outlineStyle() == BNONE)
1106         return;
1107
1108     IntRect inner = pixelSnappedIntRect(paintRect);
1109     inner.inflate(outlineOffset);
1110
1111     IntRect outer = pixelSnappedIntRect(inner);
1112     outer.inflate(outlineWidth);
1113
1114     // FIXME: This prevents outlines from painting inside the object. See bug 12042
1115     if (outer.isEmpty())
1116         return;
1117
1118     bool useTransparencyLayer = outlineColor.hasAlpha();
1119     if (useTransparencyLayer) {
1120         if (outlineStyle == SOLID) {
1121             Path path;
1122             path.addRect(outer);
1123             path.addRect(inner);
1124             graphicsContext->setFillRule(RULE_EVENODD);
1125             graphicsContext->setFillColor(outlineColor, styleToUse->colorSpace());
1126             graphicsContext->fillPath(path);
1127             return;
1128         }
1129         graphicsContext->beginTransparencyLayer(static_cast<float>(outlineColor.alpha()) / 255);
1130         outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineColor.blue());
1131     }
1132
1133     int leftOuter = outer.x();
1134     int leftInner = inner.x();
1135     int rightOuter = outer.maxX();
1136     int rightInner = inner.maxX();
1137     int topOuter = outer.y();
1138     int topInner = inner.y();
1139     int bottomOuter = outer.maxY();
1140     int bottomInner = inner.maxY();
1141     
1142     drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1143     drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInner, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1144     drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottomOuter, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1145     drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bottomOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1146
1147     if (useTransparencyLayer)
1148         graphicsContext->endTransparencyLayer();
1149 }
1150
1151 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) const
1152 {
1153     if (useTransforms) {
1154         Vector<FloatQuad> quads;
1155         absoluteQuads(quads);
1156
1157         size_t n = quads.size();
1158         if (!n)
1159             return IntRect();
1160     
1161         IntRect result = quads[0].enclosingBoundingBox();
1162         for (size_t i = 1; i < n; ++i)
1163             result.unite(quads[i].enclosingBoundingBox());
1164         return result;
1165     }
1166
1167     FloatPoint absPos = localToAbsolute();
1168     Vector<IntRect> rects;
1169     absoluteRects(rects, flooredLayoutPoint(absPos));
1170
1171     size_t n = rects.size();
1172     if (!n)
1173         return IntRect();
1174
1175     LayoutRect result = rects[0];
1176     for (size_t i = 1; i < n; ++i)
1177         result.unite(rects[i]);
1178     return pixelSnappedIntRect(result);
1179 }
1180
1181 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1182 {
1183     Vector<IntRect> rects;
1184     // FIXME: addFocusRingRects() needs to be passed this transform-unaware
1185     // localToAbsolute() offset here because RenderInline::addFocusRingRects()
1186     // implicitly assumes that. This doesn't work correctly with transformed
1187     // descendants.
1188     FloatPoint absolutePoint = localToAbsolute();
1189     addFocusRingRects(rects, flooredLayoutPoint(absolutePoint));
1190     size_t count = rects.size(); 
1191     for (size_t i = 0; i < count; ++i) {
1192         IntRect rect = rects[i];
1193         rect.move(-absolutePoint.x(), -absolutePoint.y());
1194         quads.append(localToAbsoluteQuad(FloatQuad(rect)));
1195     }
1196 }
1197
1198 void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
1199 {
1200     if (hasLayer())
1201         result.unite(absoluteBoundingBoxRectIgnoringTransforms());
1202     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1203         current->addAbsoluteRectForLayer(result);
1204 }
1205
1206 LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect)
1207 {
1208     LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms();
1209     topLevelRect = result;
1210     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1211         current->addAbsoluteRectForLayer(result);
1212     return result;
1213 }
1214
1215 void RenderObject::paint(PaintInfo&, const LayoutPoint&)
1216 {
1217 }
1218
1219 RenderBoxModelObject* RenderObject::containerForRepaint() const
1220 {
1221     RenderView* v = view();
1222     if (!v)
1223         return 0;
1224     
1225     RenderBoxModelObject* repaintContainer = 0;
1226
1227 #if USE(ACCELERATED_COMPOSITING)
1228     if (v->usesCompositing()) {
1229         if (RenderLayer* parentLayer = enclosingLayer()) {
1230             RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint();
1231             if (compLayer)
1232                 repaintContainer = compLayer->renderer();
1233         }
1234     }
1235 #endif
1236     
1237 #if ENABLE(CSS_FILTERS)
1238     if (RenderLayer* parentLayer = enclosingLayer()) {
1239         RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer();
1240         if (enclosingFilterLayer)
1241             return enclosingFilterLayer->renderer();
1242     }
1243 #endif
1244
1245     // If we have a flow thread, then we need to do individual repaints within the RenderRegions instead.
1246     // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change
1247     // repainting to do individual region repaints.
1248     // FIXME: Composited layers inside a flow thread will bypass this mechanism and will malfunction. It's not
1249     // clear how to address this problem for composited descendants of a RenderFlowThread.
1250     if (!repaintContainer && inRenderFlowThread())
1251         repaintContainer = enclosingRenderFlowThread();
1252     return repaintContainer;
1253 }
1254
1255 void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect& r, bool immediate)
1256 {
1257     if (!repaintContainer) {
1258         view()->repaintViewRectangle(r, immediate);
1259         return;
1260     }
1261
1262     if (repaintContainer->isRenderFlowThread()) {
1263         toRenderFlowThread(repaintContainer)->repaintRectangleInRegions(r, immediate);
1264         return;
1265     }
1266
1267 #if ENABLE(CSS_FILTERS)
1268     if (repaintContainer->hasFilter() && repaintContainer->layer() && repaintContainer->layer()->requiresFullLayerImageForFilters()) {
1269         repaintContainer->layer()->setFilterBackendNeedsRepaintingInRect(r, immediate);
1270         return;
1271     }
1272 #endif
1273
1274 #if USE(ACCELERATED_COMPOSITING)
1275     RenderView* v = view();
1276     if (repaintContainer->isRenderView()) {
1277         ASSERT(repaintContainer == v);
1278         bool viewHasCompositedLayer = v->hasLayer() && v->layer()->isComposited();
1279         if (!viewHasCompositedLayer || v->layer()->backing()->paintsIntoWindow()) {
1280             LayoutRect repaintRectangle = r;
1281             if (viewHasCompositedLayer &&  v->layer()->transform())
1282                 repaintRectangle = v->layer()->transform()->mapRect(r);
1283             v->repaintViewRectangle(repaintRectangle, immediate);
1284             return;
1285         }
1286     }
1287     
1288     if (v->usesCompositing()) {
1289         ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
1290         repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
1291     }
1292 #else
1293     if (repaintContainer->isRenderView())
1294         toRenderView(repaintContainer)->repaintViewRectangle(r, immediate);
1295 #endif
1296 }
1297
1298 void RenderObject::repaint(bool immediate)
1299 {
1300     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1301     RenderView* view;
1302     if (!isRooted(&view))
1303         return;
1304
1305     if (view->printing())
1306         return; // Don't repaint if we're printing.
1307
1308     RenderBoxModelObject* repaintContainer = containerForRepaint();
1309     repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate);
1310 }
1311
1312 void RenderObject::repaintRectangle(const LayoutRect& r, bool immediate)
1313 {
1314     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1315     RenderView* view;
1316     if (!isRooted(&view))
1317         return;
1318
1319     if (view->printing())
1320         return; // Don't repaint if we're printing.
1321
1322     LayoutRect dirtyRect(r);
1323
1324     // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1325     // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1326     dirtyRect.move(view->layoutDelta());
1327
1328     RenderBoxModelObject* repaintContainer = containerForRepaint();
1329     computeRectForRepaint(repaintContainer, dirtyRect);
1330     repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate);
1331 }
1332
1333 IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const
1334 {
1335     return pixelSnappedIntRect(absoluteClippedOverflowRect());
1336 }
1337
1338 bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr, const LayoutRect* newOutlineBoxRectPtr)
1339 {
1340     RenderView* v = view();
1341     if (v->printing())
1342         return false; // Don't repaint if we're printing.
1343
1344     // This ASSERT fails due to animations.  See https://bugs.webkit.org/show_bug.cgi?id=37048
1345     // ASSERT(!newBoundsPtr || *newBoundsPtr == clippedOverflowRectForRepaint(repaintContainer));
1346     LayoutRect newBounds = newBoundsPtr ? *newBoundsPtr : clippedOverflowRectForRepaint(repaintContainer);
1347     LayoutRect newOutlineBox;
1348
1349     bool fullRepaint = selfNeedsLayout();
1350     // Presumably a background or a border exists if border-fit:lines was specified.
1351     if (!fullRepaint && style()->borderFit() == BorderFitLines)
1352         fullRepaint = true;
1353     if (!fullRepaint) {
1354         // This ASSERT fails due to animations.  See https://bugs.webkit.org/show_bug.cgi?id=37048
1355         // ASSERT(!newOutlineBoxRectPtr || *newOutlineBoxRectPtr == outlineBoundsForRepaint(repaintContainer));
1356         newOutlineBox = newOutlineBoxRectPtr ? *newOutlineBoxRectPtr : outlineBoundsForRepaint(repaintContainer);
1357         if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1358             fullRepaint = true;
1359     }
1360
1361     if (!repaintContainer)
1362         repaintContainer = v;
1363
1364     if (fullRepaint) {
1365         repaintUsingContainer(repaintContainer, oldBounds);
1366         if (newBounds != oldBounds)
1367             repaintUsingContainer(repaintContainer, newBounds);
1368         return true;
1369     }
1370
1371     if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1372         return false;
1373
1374     LayoutUnit deltaLeft = newBounds.x() - oldBounds.x();
1375     if (deltaLeft > 0)
1376         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1377     else if (deltaLeft < 0)
1378         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1379
1380     LayoutUnit deltaRight = newBounds.maxX() - oldBounds.maxX();
1381     if (deltaRight > 0)
1382         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.maxX(), newBounds.y(), deltaRight, newBounds.height()));
1383     else if (deltaRight < 0)
1384         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.maxX(), oldBounds.y(), -deltaRight, oldBounds.height()));
1385
1386     LayoutUnit deltaTop = newBounds.y() - oldBounds.y();
1387     if (deltaTop > 0)
1388         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1389     else if (deltaTop < 0)
1390         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1391
1392     LayoutUnit deltaBottom = newBounds.maxY() - oldBounds.maxY();
1393     if (deltaBottom > 0)
1394         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), oldBounds.maxY(), newBounds.width(), deltaBottom));
1395     else if (deltaBottom < 0)
1396         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), newBounds.maxY(), oldBounds.width(), -deltaBottom));
1397
1398     if (newOutlineBox == oldOutlineBox)
1399         return false;
1400
1401     // We didn't move, but we did change size.  Invalidate the delta, which will consist of possibly
1402     // two rectangles (but typically only one).
1403     RenderStyle* outlineStyle = outlineStyleForRepaint();
1404     LayoutUnit ow = outlineStyle->outlineSize();
1405     LayoutUnit width = absoluteValue(newOutlineBox.width() - oldOutlineBox.width());
1406     if (width) {
1407         LayoutUnit shadowLeft;
1408         LayoutUnit shadowRight;
1409         style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1410
1411         int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1412         LayoutUnit boxWidth = isBox() ? toRenderBox(this)->width() : ZERO_LAYOUT_UNIT;
1413         LayoutUnit borderWidth = max<LayoutUnit>(-outlineStyle->outlineOffset(), max<LayoutUnit>(borderRight, max<LayoutUnit>(valueForLength(style()->borderTopRightRadius().width(), boxWidth, v), valueForLength(style()->borderBottomRightRadius().width(), boxWidth, v)))) + max<LayoutUnit>(ow, shadowRight);
1414         LayoutRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
1415             newOutlineBox.y(),
1416             width + borderWidth,
1417             max(newOutlineBox.height(), oldOutlineBox.height()));
1418         LayoutUnit right = min<LayoutUnit>(newBounds.maxX(), oldBounds.maxX());
1419         if (rightRect.x() < right) {
1420             rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1421             repaintUsingContainer(repaintContainer, rightRect);
1422         }
1423     }
1424     LayoutUnit height = absoluteValue(newOutlineBox.height() - oldOutlineBox.height());
1425     if (height) {
1426         LayoutUnit shadowTop;
1427         LayoutUnit shadowBottom;
1428         style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1429
1430         int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1431         LayoutUnit boxHeight = isBox() ? toRenderBox(this)->height() : ZERO_LAYOUT_UNIT;
1432         LayoutUnit borderHeight = max<LayoutUnit>(-outlineStyle->outlineOffset(), max<LayoutUnit>(borderBottom, max<LayoutUnit>(valueForLength(style()->borderBottomLeftRadius().height(), boxHeight, v), valueForLength(style()->borderBottomRightRadius().height(), boxHeight, v)))) + max<LayoutUnit>(ow, shadowBottom);
1433         LayoutRect bottomRect(newOutlineBox.x(),
1434             min(newOutlineBox.maxY(), oldOutlineBox.maxY()) - borderHeight,
1435             max(newOutlineBox.width(), oldOutlineBox.width()),
1436             height + borderHeight);
1437         LayoutUnit bottom = min(newBounds.maxY(), oldBounds.maxY());
1438         if (bottomRect.y() < bottom) {
1439             bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1440             repaintUsingContainer(repaintContainer, bottomRect);
1441         }
1442     }
1443     return false;
1444 }
1445
1446 void RenderObject::repaintDuringLayoutIfMoved(const LayoutRect&)
1447 {
1448 }
1449
1450 void RenderObject::repaintOverhangingFloats(bool)
1451 {
1452 }
1453
1454 bool RenderObject::checkForRepaintDuringLayout() const
1455 {
1456     return !document()->view()->needsFullRepaint() && !hasLayer() && everHadLayout();
1457 }
1458
1459 LayoutRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, LayoutUnit outlineWidth) const
1460 {
1461     LayoutRect r(clippedOverflowRectForRepaint(repaintContainer));
1462     r.inflate(outlineWidth);
1463     return r;
1464 }
1465
1466 LayoutRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*) const
1467 {
1468     ASSERT_NOT_REACHED();
1469     return LayoutRect();
1470 }
1471
1472 void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
1473 {
1474     if (repaintContainer == this)
1475         return;
1476
1477     if (RenderObject* o = parent()) {
1478         if (o->isBlockFlow()) {
1479             RenderBlock* cb = toRenderBlock(o);
1480             if (cb->hasColumns())
1481                 cb->adjustRectForColumns(rect);
1482         }
1483
1484         if (o->hasOverflowClip()) {
1485             // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
1486             // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
1487             // anyway if its size does change.
1488             RenderBox* boxParent = toRenderBox(o);
1489
1490             LayoutRect repaintRect(rect);
1491             repaintRect.move(-boxParent->scrolledContentOffset()); // For overflow:auto/scroll/hidden.
1492
1493             LayoutRect boxRect(LayoutPoint(), boxParent->cachedSizeForOverflowClip());
1494             rect = intersection(repaintRect, boxRect);
1495             if (rect.isEmpty())
1496                 return;
1497         }
1498
1499         o->computeRectForRepaint(repaintContainer, rect, fixed);
1500     }
1501 }
1502
1503 void RenderObject::computeFloatRectForRepaint(RenderBoxModelObject*, FloatRect&, bool) const
1504 {
1505     ASSERT_NOT_REACHED();
1506 }
1507
1508 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1509 {
1510 }
1511
1512 #ifndef NDEBUG
1513
1514 void RenderObject::showTreeForThis() const
1515 {
1516     if (node())
1517         node()->showTreeForThis();
1518 }
1519
1520 void RenderObject::showRenderTreeForThis() const
1521 {
1522     showRenderTree(this, 0);
1523 }
1524
1525 void RenderObject::showLineTreeForThis() const
1526 {
1527     if (containingBlock())
1528         containingBlock()->showLineTreeAndMark(0, 0, 0, 0, this);
1529 }
1530
1531 void RenderObject::showRenderObject() const
1532 {
1533     showRenderObject(0);
1534 }
1535
1536 void RenderObject::showRenderObject(int printedCharacters) const
1537 {
1538     // As this function is intended to be used when debugging, the
1539     // this pointer may be 0.
1540     if (!this) {
1541         fputs("(null)\n", stderr);
1542         return;
1543     }
1544
1545     printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
1546
1547     if (node()) {
1548         if (printedCharacters)
1549             for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
1550                 fputc(' ', stderr);
1551         fputc('\t', stderr);
1552         node()->showNode();
1553     } else
1554         fputc('\n', stderr);
1555 }
1556
1557 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
1558 {
1559     int printedCharacters = 0;
1560     if (markedObject1 == this && markedLabel1)
1561         printedCharacters += fprintf(stderr, "%s", markedLabel1);
1562     if (markedObject2 == this && markedLabel2)
1563         printedCharacters += fprintf(stderr, "%s", markedLabel2);
1564     for (; printedCharacters < depth * 2; printedCharacters++)
1565         fputc(' ', stderr);
1566
1567     showRenderObject(printedCharacters);
1568     if (!this)
1569         return;
1570
1571     for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
1572         child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
1573 }
1574
1575 #endif // NDEBUG
1576
1577 Color RenderObject::selectionBackgroundColor() const
1578 {
1579     Color color;
1580     if (style()->userSelect() != SELECT_NONE) {
1581         RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
1582         if (pseudoStyle && pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
1583             color = pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).blendWithWhite();
1584         else
1585             color = frame()->selection()->isFocusedAndActive() ?
1586                     theme()->activeSelectionBackgroundColor() :
1587                     theme()->inactiveSelectionBackgroundColor();
1588     }
1589
1590     return color;
1591 }
1592
1593 Color RenderObject::selectionColor(int colorProperty) const
1594 {
1595     Color color;
1596     // If the element is unselectable, or we are only painting the selection,
1597     // don't override the foreground color with the selection foreground color.
1598     if (style()->userSelect() == SELECT_NONE
1599         || (frame()->view()->paintBehavior() & PaintBehaviorSelectionOnly))
1600         return color;
1601
1602     if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
1603         color = pseudoStyle->visitedDependentColor(colorProperty);
1604         if (!color.isValid())
1605             color = pseudoStyle->visitedDependentColor(CSSPropertyColor);
1606     } else
1607         color = frame()->selection()->isFocusedAndActive() ?
1608                 theme()->activeSelectionForegroundColor() :
1609                 theme()->inactiveSelectionForegroundColor();
1610
1611     return color;
1612 }
1613
1614 Color RenderObject::selectionForegroundColor() const
1615 {
1616     return selectionColor(CSSPropertyWebkitTextFillColor);
1617 }
1618
1619 Color RenderObject::selectionEmphasisMarkColor() const
1620 {
1621     return selectionColor(CSSPropertyWebkitTextEmphasisColor);
1622 }
1623
1624 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1625 {
1626     view()->selectionStartEnd(spos, epos);
1627 }
1628
1629 void RenderObject::handleDynamicFloatPositionChange()
1630 {
1631     // We have gone from not affecting the inline status of the parent flow to suddenly
1632     // having an impact.  See if there is a mismatch between the parent flow's
1633     // childrenInline() state and our state.
1634     setInline(style()->isDisplayInlineType());
1635     if (isInline() != parent()->childrenInline()) {
1636         if (!isInline())
1637             toRenderBoxModelObject(parent())->childBecameNonInline(this);
1638         else {
1639             // An anonymous block must be made to wrap this inline.
1640             RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1641             RenderObjectChildList* childlist = parent()->virtualChildren();
1642             childlist->insertChildNode(parent(), block, this);
1643             block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1644         }
1645     }
1646 }
1647
1648 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
1649 {
1650     if (!isText() && style)
1651         setStyle(animation()->updateAnimations(this, style.get()));
1652     else
1653         setStyle(style);
1654 }
1655
1656 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1657 {
1658 #if USE(ACCELERATED_COMPOSITING)
1659     // If transform changed, and we are not composited, need to do a layout.
1660     if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1661         // Text nodes share style with their parents but transforms don't apply to them,
1662         // hence the !isText() check.
1663         // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1664         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) {
1665             // We need to set at least SimplifiedLayout, but if PositionedMovementOnly is already set
1666             // then we actually need SimplifiedLayoutAndPositionedMovement.
1667             if (!hasLayer())
1668                 diff = StyleDifferenceLayout; // FIXME: Do this for now since SimplifiedLayout cannot handle updating floating objects lists.
1669             else if (diff < StyleDifferenceLayoutPositionedMovementOnly)
1670                 diff = StyleDifferenceSimplifiedLayout;
1671             else if (diff < StyleDifferenceSimplifiedLayout)
1672                 diff = StyleDifferenceSimplifiedLayoutAndPositionedMovement;
1673         } else if (diff < StyleDifferenceRecompositeLayer)
1674             diff = StyleDifferenceRecompositeLayer;
1675     }
1676
1677     // If opacity changed, and we are not composited, need to repaint (also
1678     // ignoring text nodes)
1679     if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
1680         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
1681             diff = StyleDifferenceRepaintLayer;
1682         else if (diff < StyleDifferenceRecompositeLayer)
1683             diff = StyleDifferenceRecompositeLayer;
1684     }
1685     
1686 #if ENABLE(CSS_FILTERS)
1687     if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer()) {
1688         RenderLayer* layer = toRenderBoxModelObject(this)->layer();
1689         if (!layer->isComposited() || layer->paintsWithFilters())
1690             diff = StyleDifferenceRepaintLayer;
1691         else if (diff < StyleDifferenceRecompositeLayer)
1692             diff = StyleDifferenceRecompositeLayer;
1693     }
1694 #endif
1695     
1696     // The answer to requiresLayer() for plugins and iframes can change outside of the style system,
1697     // since it depends on whether we decide to composite these elements. When the layer status of
1698     // one of these elements changes, we need to force a layout.
1699     if (diff == StyleDifferenceEqual && style() && isBoxModelObject()) {
1700         if (hasLayer() != toRenderBoxModelObject(this)->requiresLayer())
1701             diff = StyleDifferenceLayout;
1702     }
1703 #else
1704     UNUSED_PARAM(contextSensitiveProperties);
1705 #endif
1706
1707     // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1708     if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1709         diff = StyleDifferenceRepaint;
1710
1711     return diff;
1712 }
1713
1714 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1715 {
1716     if (m_style == style) {
1717 #if USE(ACCELERATED_COMPOSITING)
1718         // We need to run through adjustStyleDifference() for iframes and plugins, so
1719         // style sharing is disabled for them. That should ensure that we never hit this code path.
1720         ASSERT(!isRenderIFrame() && !isEmbeddedObject());
1721 #endif
1722         return;
1723     }
1724
1725     StyleDifference diff = StyleDifferenceEqual;
1726     unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1727     if (m_style)
1728         diff = m_style->diff(style.get(), contextSensitiveProperties);
1729
1730     diff = adjustStyleDifference(diff, contextSensitiveProperties);
1731
1732     styleWillChange(diff, style.get());
1733     
1734     RefPtr<RenderStyle> oldStyle = m_style.release();
1735     m_style = style;
1736
1737     updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1738     updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1739
1740     updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1741     updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1742
1743     // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1744     // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1745     if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
1746         toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
1747
1748     bool doesNotNeedLayout = !m_parent || isText();
1749
1750     styleDidChange(diff, oldStyle.get());
1751
1752     // FIXME: |this| might be destroyed here. This can currently happen for a RenderTextFragment when
1753     // its first-letter block gets an update in RenderTextFragment::styleDidChange. For RenderTextFragment(s),
1754     // we will safely bail out with the doesNotNeedLayout flag. We might want to broaden this condition
1755     // in the future as we move renderer changes out of layout and into style changes.
1756     if (doesNotNeedLayout)
1757         return;
1758
1759     // Now that the layer (if any) has been updated, we need to adjust the diff again,
1760     // check whether we should layout now, and decide if we need to repaint.
1761     StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1762     
1763     if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1764         if (updatedDiff == StyleDifferenceLayout)
1765             setNeedsLayoutAndPrefWidthsRecalc();
1766         else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1767             setNeedsPositionedMovementLayout();
1768         else if (updatedDiff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1769             setNeedsPositionedMovementLayout();
1770             setNeedsSimplifiedNormalFlowLayout();
1771         } else if (updatedDiff == StyleDifferenceSimplifiedLayout)
1772             setNeedsSimplifiedNormalFlowLayout();
1773     }
1774     
1775     if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
1776         // Do a repaint with the new style now, e.g., for example if we go from
1777         // not having an outline to having an outline.
1778         repaint();
1779     }
1780 }
1781
1782 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
1783 {
1784     m_style = style;
1785 }
1786
1787 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1788 {
1789     if (m_style) {
1790         // If our z-index changes value or our visibility changes,
1791         // we need to dirty our stacking context's z-order list.
1792         if (newStyle) {
1793             bool visibilityChanged = m_style->visibility() != newStyle->visibility() 
1794                 || m_style->zIndex() != newStyle->zIndex() 
1795                 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1796 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
1797             if (visibilityChanged)
1798                 document()->setDashboardRegionsDirty(true);
1799 #endif
1800             if (visibilityChanged && AXObjectCache::accessibilityEnabled())
1801                 document()->axObjectCache()->childrenChanged(this);
1802
1803             // Keep layer hierarchy visibility bits up to date if visibility changes.
1804             if (m_style->visibility() != newStyle->visibility()) {
1805                 if (RenderLayer* l = enclosingLayer()) {
1806                     if (newStyle->visibility() == VISIBLE)
1807                         l->setHasVisibleContent();
1808                     else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1809                         l->dirtyVisibleContentStatus();
1810                         if (diff > StyleDifferenceRepaintLayer)
1811                             repaint();
1812                     }
1813                 }
1814             }
1815         }
1816
1817         if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
1818             repaint();
1819         if (isFloating() && (m_style->floating() != newStyle->floating()))
1820             // For changes in float styles, we need to conceivably remove ourselves
1821             // from the floating objects list.
1822             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1823         else if (isOutOfFlowPositioned() && (m_style->position() != newStyle->position()))
1824             // For changes in positioning styles, we need to conceivably remove ourselves
1825             // from the positioned objects list.
1826             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1827
1828         s_affectsParentBlock = isFloatingOrOutOfFlowPositioned()
1829             && (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)
1830             && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
1831
1832         // reset style flags
1833         if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
1834             setFloating(false);
1835             setPositioned(false);
1836             setRelPositioned(false);
1837         }
1838         setHorizontalWritingMode(true);
1839         setPaintBackground(false);
1840         setHasOverflowClip(false);
1841         setHasTransform(false);
1842         setHasReflection(false);
1843     } else
1844         s_affectsParentBlock = false;
1845
1846     if (view()->frameView()) {
1847         bool shouldBlitOnFixedBackgroundImage = false;
1848 #if ENABLE(FAST_MOBILE_SCROLLING)
1849         // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
1850         // when scrolling a page with a fixed background image. As an optimization, assuming there are
1851         // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
1852         // ignore the CSS property "background-attachment: fixed".
1853 #if PLATFORM(QT)
1854         if (view()->frameView()->delegatesScrolling())
1855 #endif
1856             shouldBlitOnFixedBackgroundImage = true;
1857 #endif
1858
1859         bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage();
1860         bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage();
1861         if (oldStyleSlowScroll != newStyleSlowScroll) {
1862             if (oldStyleSlowScroll)
1863                 view()->frameView()->removeSlowRepaintObject();
1864             if (newStyleSlowScroll)
1865                 view()->frameView()->addSlowRepaintObject();
1866         }
1867     }
1868 }
1869
1870 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderStyle* b)
1871 {
1872     ASSERT(a->cursors() != b->cursors());
1873     return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
1874 }
1875
1876 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
1877 {
1878     return a->cursor() == b->cursor() && (a->cursors() == b->cursors() || areNonIdenticalCursorListsEqual(a, b));
1879 }
1880
1881 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
1882 {
1883     if (s_affectsParentBlock)
1884         handleDynamicFloatPositionChange();
1885
1886     if (!m_parent)
1887         return;
1888     
1889     if (diff == StyleDifferenceLayout || diff == StyleDifferenceSimplifiedLayout) {
1890         RenderCounter::rendererStyleChanged(this, oldStyle, m_style.get());
1891
1892         // If the object already needs layout, then setNeedsLayout won't do
1893         // any work. But if the containing block has changed, then we may need
1894         // to mark the new containing blocks for layout. The change that can
1895         // directly affect the containing block of this object is a change to
1896         // the position style.
1897         if (needsLayout() && oldStyle->position() != m_style->position())
1898             markContainingBlocksForLayout();
1899
1900         if (diff == StyleDifferenceLayout)
1901             setNeedsLayoutAndPrefWidthsRecalc();
1902         else
1903             setNeedsSimplifiedNormalFlowLayout();
1904     } else if (diff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1905         setNeedsPositionedMovementLayout();
1906         setNeedsSimplifiedNormalFlowLayout();
1907     } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
1908         setNeedsPositionedMovementLayout();
1909
1910     // Don't check for repaint here; we need to wait until the layer has been
1911     // updated by subclasses before we know if we have to repaint (in setStyle()).
1912
1913     if (oldStyle && !areCursorsEqual(oldStyle, style())) {
1914         if (Frame* frame = this->frame())
1915             frame->eventHandler()->dispatchFakeMouseMoveEventSoon();
1916     }
1917 }
1918
1919 void RenderObject::propagateStyleToAnonymousChildren(bool blockChildrenOnly)
1920 {
1921     // FIXME: We could save this call when the change only affected non-inherited properties.
1922     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
1923         if (!child->isAnonymous() || child->style()->styleType() != NOPSEUDO)
1924             continue;
1925
1926         if (blockChildrenOnly && !child->isRenderBlock())
1927             continue;
1928
1929 #if ENABLE(FULLSCREEN_API)
1930         if (child->isRenderFullScreen() || child->isRenderFullScreenPlaceholder())
1931             continue;
1932 #endif
1933
1934         RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), child->style()->display());
1935         if (style()->specifiesColumns()) {
1936             if (child->style()->specifiesColumns())
1937                 newStyle->inheritColumnPropertiesFrom(style());
1938             if (child->style()->columnSpan())
1939                 newStyle->setColumnSpan(ColumnSpanAll);
1940         }
1941
1942         // Preserve the position style of anonymous block continuations as they can have relative position when
1943         // they contain block descendants of relative positioned inlines.
1944         if (child->isRelPositioned() && toRenderBlock(child)->isAnonymousBlockContinuation())
1945             newStyle->setPosition(child->style()->position());
1946
1947         child->setStyle(newStyle.release());
1948     }
1949 }
1950
1951 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
1952 {
1953     // Optimize the common case
1954     if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
1955         return;
1956     
1957     // Go through the new layers and addClients first, to avoid removing all clients of an image.
1958     for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
1959         if (currNew->image())
1960             currNew->image()->addClient(this);
1961     }
1962
1963     for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
1964         if (currOld->image())
1965             currOld->image()->removeClient(this);
1966     }
1967 }
1968
1969 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
1970 {
1971     if (oldImage != newImage) {
1972         if (oldImage)
1973             oldImage->removeClient(this);
1974         if (newImage)
1975             newImage->addClient(this);
1976     }
1977 }
1978
1979 LayoutRect RenderObject::viewRect() const
1980 {
1981     return view()->viewRect();
1982 }
1983
1984 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, bool fixed, bool useTransforms) const
1985 {
1986     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
1987     MapLocalToContainerFlags mode = ApplyContainerFlip;
1988     if (fixed)
1989         mode |= IsFixed;
1990     if (useTransforms)
1991         mode |= UseTransforms;
1992     mapLocalToContainer(0, transformState, mode);
1993     transformState.flatten();
1994     
1995     return transformState.lastPlanarPoint();
1996 }
1997
1998 FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, bool fixed, bool useTransforms) const
1999 {
2000     TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
2001     mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2002     transformState.flatten();
2003     
2004     return transformState.lastPlanarPoint();
2005 }
2006
2007 void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, TransformState& transformState, MapLocalToContainerFlags mode, bool* wasFixed) const
2008 {
2009     if (repaintContainer == this)
2010         return;
2011
2012     RenderObject* o = parent();
2013     if (!o)
2014         return;
2015
2016     // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2017     LayoutPoint centerPoint = roundedLayoutPoint(transformState.mappedPoint());
2018     if (mode & ApplyContainerFlip && o->isBox()) {
2019         if (o->style()->isFlippedBlocksWritingMode())
2020             transformState.move(toRenderBox(o)->flipForWritingModeIncludingColumns(roundedLayoutPoint(transformState.mappedPoint())) - centerPoint);
2021         mode &= ~ApplyContainerFlip;
2022     }
2023
2024     LayoutSize columnOffset;
2025     o->adjustForColumns(columnOffset, roundedLayoutPoint(transformState.mappedPoint()));
2026     if (!columnOffset.isZero())
2027         transformState.move(columnOffset);
2028
2029     if (o->hasOverflowClip())
2030         transformState.move(-toRenderBox(o)->scrolledContentOffset());
2031
2032     o->mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2033 }
2034
2035 const RenderObject* RenderObject::pushMappingToContainer(const RenderBoxModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
2036 {
2037     ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this);
2038
2039     RenderObject* container = parent();
2040     if (!container)
2041         return 0;
2042
2043     // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2044     LayoutSize offset;
2045     if (container->hasOverflowClip())
2046         offset = -toRenderBox(container)->scrolledContentOffset();
2047
2048     geometryMap.push(this, offset, hasColumns());
2049     
2050     return container;
2051 }
2052
2053 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
2054 {
2055     RenderObject* o = parent();
2056     if (o) {
2057         o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2058         if (o->hasOverflowClip())
2059             transformState.move(toRenderBox(o)->scrolledContentOffset());
2060     }
2061 }
2062
2063 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
2064 {
2065 #if ENABLE(3D_RENDERING)
2066     // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
2067     // so check the layer's transform directly.
2068     return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
2069 #else
2070     UNUSED_PARAM(containerObject);
2071     return hasTransform();
2072 #endif
2073 }
2074
2075 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const
2076 {
2077     transform.makeIdentity();
2078     transform.translate(offsetInContainer.width(), offsetInContainer.height());
2079     RenderLayer* layer;
2080     if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform())
2081         transform.multiply(layer->currentTransform());
2082     
2083 #if ENABLE(3D_RENDERING)
2084     if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
2085         // Perpsective on the container affects us, so we have to factor it in here.
2086         ASSERT(containerObject->hasLayer());
2087         FloatPoint perspectiveOrigin = toRenderBoxModelObject(containerObject)->layer()->perspectiveOrigin();
2088
2089         TransformationMatrix perspectiveMatrix;
2090         perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
2091         
2092         transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
2093         transform = perspectiveMatrix * transform;
2094         transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
2095     }
2096 #else
2097     UNUSED_PARAM(containerObject);
2098 #endif
2099 }
2100
2101 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2102 {
2103     // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(),
2104     // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks.
2105     TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad);
2106     MapLocalToContainerFlags mode = ApplyContainerFlip | UseTransforms;
2107     if (fixed)
2108         mode |= IsFixed;
2109     mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2110     transformState.flatten();
2111     
2112     return transformState.lastPlanarQuad();
2113 }
2114
2115 FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2116 {
2117     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2118     MapLocalToContainerFlags mode = ApplyContainerFlip | UseTransforms;
2119     if (fixed)
2120         mode |= IsFixed;
2121     mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2122     transformState.flatten();
2123
2124     return transformState.lastPlanarPoint();
2125 }
2126
2127 LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
2128 {
2129     ASSERT(o == container());
2130
2131     LayoutSize offset;
2132
2133     o->adjustForColumns(offset, point);
2134
2135     if (o->hasOverflowClip())
2136         offset -= toRenderBox(o)->scrolledContentOffset();
2137
2138     if (offsetDependsOnPoint)
2139         *offsetDependsOnPoint = hasColumns();
2140
2141     return offset;
2142 }
2143
2144 LayoutSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
2145 {
2146     LayoutSize offset;
2147     LayoutPoint referencePoint;
2148     const RenderObject* currContainer = this;
2149     do {
2150         RenderObject* nextContainer = currContainer->container();
2151         ASSERT(nextContainer);  // This means we reached the top without finding container.
2152         if (!nextContainer)
2153             break;
2154         ASSERT(!currContainer->hasTransform());
2155         LayoutSize currentOffset = currContainer->offsetFromContainer(nextContainer, referencePoint);
2156         offset += currentOffset;
2157         referencePoint.move(currentOffset);
2158         currContainer = nextContainer;
2159     } while (currContainer != container);
2160
2161     return offset;
2162 }
2163
2164 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
2165 {
2166     if (extraWidthToEndOfLine)
2167         *extraWidthToEndOfLine = 0;
2168
2169     return LayoutRect();
2170 }
2171
2172 bool RenderObject::isRooted(RenderView** view)
2173 {
2174     RenderObject* o = this;
2175     while (o->parent())
2176         o = o->parent();
2177
2178     if (!o->isRenderView())
2179         return false;
2180
2181     if (view)
2182         *view = toRenderView(o);
2183
2184     return true;
2185 }
2186
2187 RenderObject* RenderObject::rendererForRootBackground()
2188 {
2189     ASSERT(isRoot());
2190     if (!hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) {
2191         // Locate the <body> element using the DOM. This is easier than trying
2192         // to crawl around a render tree with potential :before/:after content and
2193         // anonymous blocks created by inline <body> tags etc. We can locate the <body>
2194         // render object very easily via the DOM.
2195         HTMLElement* body = document()->body();
2196         RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
2197         if (bodyObject)
2198             return bodyObject;
2199     }
2200     
2201     return this;
2202 }
2203
2204 RespectImageOrientationEnum RenderObject::shouldRespectImageOrientation() const
2205 {
2206     // Respect the image's orientation if it's being used as a full-page image or it's
2207     // an <img> and the setting to respect it everywhere is set.
2208     return document()->isImageDocument() || (document()->settings() && document()->settings()->shouldRespectImageOrientation() && node() && (node()->hasTagName(HTMLNames::imgTag) || node()->hasTagName(HTMLNames::webkitInnerImageTag))) ? RespectImageOrientation : DoNotRespectImageOrientation;
2209 }
2210
2211 bool RenderObject::hasOutlineAnnotation() const
2212 {
2213     return node() && node()->isLink() && document()->printing();
2214 }
2215
2216 RenderObject* RenderObject::container(const RenderBoxModelObject* repaintContainer, bool* repaintContainerSkipped) const
2217 {
2218     if (repaintContainerSkipped)
2219         *repaintContainerSkipped = false;
2220
2221     // This method is extremely similar to containingBlock(), but with a few notable
2222     // exceptions.
2223     // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2224     // the object is not part of the primary document subtree yet.
2225     // (2) For normal flow elements, it just returns the parent.
2226     // (3) For absolute positioned elements, it will return a relative positioned inline.
2227     // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2228     // the layout of the positioned object.  This does mean that computePositionedLogicalWidth and
2229     // computePositionedLogicalHeight have to use container().
2230     RenderObject* o = parent();
2231
2232     if (isText())
2233         return o;
2234
2235     EPosition pos = m_style->position();
2236     if (pos == FixedPosition) {
2237         // container() can be called on an object that is not in the
2238         // tree yet.  We don't call view() since it will assert if it
2239         // can't get back to the canvas.  Instead we just walk as high up
2240         // as we can.  If we're in the tree, we'll get the root.  If we
2241         // aren't we'll get the root of our little subtree (most likely
2242         // we'll just return 0).
2243         // FIXME: The definition of view() has changed to not crawl up the render tree.  It might
2244         // be safe now to use it.
2245         while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) {
2246 #if ENABLE(SVG)
2247             // foreignObject is the containing block for its contents.
2248             if (o->isSVGForeignObject())
2249                 break;
2250 #endif
2251             // The render flow thread is the top most containing block
2252             // for the fixed positioned elements.
2253             if (o->isRenderFlowThread())
2254                 break;
2255
2256             if (repaintContainerSkipped && o == repaintContainer)
2257                 *repaintContainerSkipped = true;
2258
2259             o = o->parent();
2260         }
2261     } else if (pos == AbsolutePosition) {
2262         // Same goes here.  We technically just want our containing block, but
2263         // we may not have one if we're part of an uninstalled subtree.  We'll
2264         // climb as high as we can though.
2265         while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
2266 #if ENABLE(SVG)
2267             if (o->isSVGForeignObject()) // foreignObject is the containing block for contents inside it
2268                 break;
2269 #endif
2270             if (repaintContainerSkipped && o == repaintContainer)
2271                 *repaintContainerSkipped = true;
2272
2273             o = o->parent();
2274         }
2275     }
2276
2277     return o;
2278 }
2279
2280 bool RenderObject::isSelectionBorder() const
2281 {
2282     SelectionState st = selectionState();
2283     return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2284 }
2285
2286 inline void RenderObject::clearLayoutRootIfNeeded() const
2287 {
2288     if (!documentBeingDestroyed() && frame()) {
2289         if (FrameView* view = frame()->view()) {
2290             if (view->layoutRoot() == this) {
2291                 ASSERT_NOT_REACHED();
2292                 // This indicates a failure to layout the child, which is why
2293                 // the layout root is still set to |this|. Make sure to clear it
2294                 // since we are getting destroyed.
2295                 view->clearLayoutRoot();
2296             }
2297         }
2298     }
2299 }
2300
2301 void RenderObject::willBeDestroyed()
2302 {
2303     // Destroy any leftover anonymous children.
2304     RenderObjectChildList* children = virtualChildren();
2305     if (children)
2306         children->destroyLeftoverChildren();
2307
2308     // If this renderer is being autoscrolled, stop the autoscroll timer
2309     
2310     // FIXME: RenderObject::destroy should not get called with a renderer whose document
2311     // has a null frame, so we assert this. However, we don't want release builds to crash which is why we
2312     // check that the frame is not null.
2313     ASSERT(frame());
2314     if (frame() && frame()->eventHandler()->autoscrollRenderer() == this)
2315         frame()->eventHandler()->stopAutoscrollTimer(true);
2316
2317     if (AXObjectCache::accessibilityEnabled()) {
2318         document()->axObjectCache()->childrenChanged(this->parent());
2319         document()->axObjectCache()->remove(this);
2320     }
2321     animation()->cancelAnimations(this);
2322
2323     remove();
2324
2325 #ifndef NDEBUG
2326     if (!documentBeingDestroyed() && view() && view()->hasRenderNamedFlowThreads()) {
2327         // After remove, the object and the associated information should not be in any flow thread.
2328         const RenderNamedFlowThreadList* flowThreadList = view()->flowThreadController()->renderNamedFlowThreadList();
2329         for (RenderNamedFlowThreadList::const_iterator iter = flowThreadList->begin(); iter != flowThreadList->end(); ++iter) {
2330             const RenderNamedFlowThread* renderFlowThread = *iter;
2331             ASSERT(!renderFlowThread->hasChild(this));
2332             ASSERT(!renderFlowThread->hasChildInfo(this));
2333         }
2334     }
2335 #endif
2336
2337     // If this renderer had a parent, remove should have destroyed any counters
2338     // attached to this renderer and marked the affected other counters for
2339     // reevaluation. This apparently redundant check is here for the case when
2340     // this renderer had no parent at the time remove() was called.
2341
2342     if (hasCounterNodeMap())
2343         RenderCounter::destroyCounterNodes(this);
2344
2345     // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
2346     // be moved into RenderBoxModelObject::destroy.
2347     if (hasLayer()) {
2348         setHasLayer(false);
2349         toRenderBoxModelObject(this)->destroyLayer();
2350     }
2351
2352     setAncestorLineBoxDirty(false);
2353
2354     clearLayoutRootIfNeeded();
2355 }
2356
2357 void RenderObject::destroyAndCleanupAnonymousWrappers()
2358 {
2359     RenderObject* parent = this->parent();
2360
2361     // If the tree is destroyed or our parent is not anonymous, there is no need for a clean-up phase.
2362     if (documentBeingDestroyed() || !parent || !parent->isAnonymous()) {
2363         destroy();
2364         return;
2365     }
2366
2367     bool parentIsLeftOverAnonymousWrapper = false;
2368
2369     // Currently we only remove anonymous cells' wrapper but we should remove all unneeded
2370     // wrappers. See http://webkit.org/b/52123 as an example where this is needed.
2371     if (parent->isTableCell())
2372         parentIsLeftOverAnonymousWrapper = parent->firstChild() == this && parent->lastChild() == this;
2373
2374     destroy();
2375
2376     // WARNING: |this| is deleted here.
2377
2378     if (parentIsLeftOverAnonymousWrapper) {
2379         ASSERT(!parent->firstChild());
2380         parent->destroyAndCleanupAnonymousWrappers();
2381     }
2382 }
2383
2384 void RenderObject::destroy()
2385 {
2386     willBeDestroyed();
2387     arenaDelete(renderArena(), this);
2388 }
2389
2390 void RenderObject::arenaDelete(RenderArena* arena, void* base)
2391 {
2392     if (m_style) {
2393         for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2394             if (StyleImage* backgroundImage = bgLayer->image())
2395                 backgroundImage->removeClient(this);
2396         }
2397
2398         for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
2399             if (StyleImage* maskImage = maskLayer->image())
2400                 maskImage->removeClient(this);
2401         }
2402
2403         if (StyleImage* borderImage = m_style->borderImage().image())
2404             borderImage->removeClient(this);
2405
2406         if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
2407             maskBoxImage->removeClient(this);
2408     }
2409
2410 #ifndef NDEBUG
2411     void* savedBase = baseOfRenderObjectBeingDeleted;
2412     baseOfRenderObjectBeingDeleted = base;
2413 #endif
2414     delete this;
2415 #ifndef NDEBUG
2416     baseOfRenderObjectBeingDeleted = savedBase;
2417 #endif
2418
2419     // Recover the size left there for us by operator delete and free the memory.
2420     arena->free(*(size_t*)base, base);
2421 }
2422
2423 VisiblePosition RenderObject::positionForPoint(const LayoutPoint&)
2424 {
2425     return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
2426 }
2427
2428 void RenderObject::updateDragState(bool dragOn)
2429 {
2430     bool valueChanged = (dragOn != isDragging());
2431     setIsDragging(dragOn);
2432     if (valueChanged && style()->affectedByDragRules() && node())
2433         node()->setNeedsStyleRecalc();
2434     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2435         curr->updateDragState(dragOn);
2436 }
2437
2438 bool RenderObject::isComposited() const
2439 {
2440     return hasLayer() && toRenderBoxModelObject(this)->layer()->isComposited();
2441 }
2442
2443 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter)
2444 {
2445     bool inside = false;
2446     if (hitTestFilter != HitTestSelf) {
2447         // First test the foreground layer (lines and inlines).
2448         inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestForeground);
2449
2450         // Test floats next.
2451         if (!inside)
2452             inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestFloat);
2453
2454         // Finally test to see if the mouse is in the background (within a child block's background).
2455         if (!inside)
2456             inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestChildBlockBackgrounds);
2457     }
2458
2459     // See if the mouse is inside us but not any of our descendants
2460     if (hitTestFilter != HitTestDescendants && !inside)
2461         inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestBlockBackground);
2462
2463     return inside;
2464 }
2465
2466 void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
2467 {
2468     if (result.innerNode())
2469         return;
2470
2471     Node* n = node();
2472     if (n) {
2473         result.setInnerNode(n);
2474         if (!result.innerNonSharedNode())
2475             result.setInnerNonSharedNode(n);
2476         result.setLocalPoint(point);
2477     }
2478 }
2479
2480 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& /*pointInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction)
2481 {
2482     return false;
2483 }
2484
2485 void RenderObject::scheduleRelayout()
2486 {
2487     if (isRenderView()) {
2488         FrameView* view = toRenderView(this)->frameView();
2489         if (view)
2490             view->scheduleRelayout();
2491     } else {
2492         if (isRooted()) {
2493             if (RenderView* renderView = view()) {
2494                 if (FrameView* frameView = renderView->frameView())
2495                     frameView->scheduleRelayoutOfSubtree(this);
2496             }
2497         }
2498     }
2499 }
2500
2501 void RenderObject::layout()
2502 {
2503     ASSERT(needsLayout());
2504     RenderObject* child = firstChild();
2505     while (child) {
2506         child->layoutIfNeeded();
2507         ASSERT(!child->needsLayout());
2508         child = child->nextSibling();
2509     }
2510     setNeedsLayout(false);
2511 }
2512
2513 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
2514 {
2515     if (!document()->usesFirstLineRules())
2516         return 0;
2517
2518     ASSERT(!isText());
2519
2520     RefPtr<RenderStyle> result;
2521
2522     if (isBlockFlow()) {
2523         if (RenderBlock* firstLineBlock = this->firstLineBlock())
2524             result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0);
2525     } else if (!isAnonymous() && isRenderInline()) {
2526         RenderStyle* parentStyle = parent()->firstLineStyle();
2527         if (parentStyle != parent()->style())
2528             result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
2529     }
2530
2531     return result.release();
2532 }
2533
2534 RenderStyle* RenderObject::firstLineStyleSlowCase() const
2535 {
2536     ASSERT(document()->usesFirstLineRules());
2537
2538     RenderStyle* style = m_style.get();
2539     const RenderObject* renderer = isText() ? parent() : this;
2540     if (renderer->isBlockFlow()) {
2541         if (RenderBlock* firstLineBlock = renderer->firstLineBlock())
2542             style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2543     } else if (!renderer->isAnonymous() && renderer->isRenderInline()) {
2544         RenderStyle* parentStyle = renderer->parent()->firstLineStyle();
2545         if (parentStyle != renderer->parent()->style()) {
2546             // A first-line style is in effect. Cache a first-line style for ourselves.
2547             renderer->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
2548             style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2549         }
2550     }
2551
2552     return style;
2553 }
2554
2555 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2556 {
2557     if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2558         return 0;
2559
2560     RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2561     if (cachedStyle)
2562         return cachedStyle;
2563     
2564     RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
2565     if (result)
2566         return style()->addCachedPseudoStyle(result.release());
2567     return 0;
2568 }
2569
2570 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2571 {
2572     if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
2573         return 0;
2574     
2575     if (!parentStyle) {
2576         ASSERT(!ownStyle);
2577         parentStyle = style();
2578     }
2579
2580     // FIXME: This "find nearest element parent" should be a helper function.
2581     Node* n = node();
2582     while (n && !n->isElementNode())
2583         n = n->parentNode();
2584     if (!n)
2585         return 0;
2586     Element* element = toElement(n);
2587
2588     if (pseudo == FIRST_LINE_INHERITED) {
2589         RefPtr<RenderStyle> result = document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
2590         result->setStyleType(FIRST_LINE_INHERITED);
2591         return result.release();
2592     }
2593     return document()->styleResolver()->pseudoStyleForElement(pseudo, element, parentStyle);
2594 }
2595
2596 static Color decorationColor(RenderStyle* style)
2597 {
2598     Color result;
2599     if (style->textStrokeWidth() > 0) {
2600         // Prefer stroke color if possible but not if it's fully transparent.
2601         result = style->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
2602         if (result.alpha())
2603             return result;
2604     }
2605     
2606     result = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
2607     return result;
2608 }
2609
2610 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2611                                            Color& linethrough, bool quirksMode, bool firstlineStyle)
2612 {
2613     RenderObject* curr = this;
2614     RenderStyle* styleToUse = 0;
2615     do {
2616         styleToUse = curr->style(firstlineStyle);
2617         int currDecs = styleToUse->textDecoration();
2618         if (currDecs) {
2619             if (currDecs & UNDERLINE) {
2620                 decorations &= ~UNDERLINE;
2621                 underline = decorationColor(styleToUse);
2622             }
2623             if (currDecs & OVERLINE) {
2624                 decorations &= ~OVERLINE;
2625                 overline = decorationColor(styleToUse);
2626             }
2627             if (currDecs & LINE_THROUGH) {
2628                 decorations &= ~LINE_THROUGH;
2629                 linethrough = decorationColor(styleToUse);
2630             }
2631         }
2632         if (curr->isRubyText())
2633             return;
2634         curr = curr->parent();
2635         if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
2636             curr = toRenderBlock(curr)->continuation();
2637     } while (curr && decorations && (!quirksMode || !curr->node() ||
2638                                      (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2639
2640     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2641     if (decorations && curr) {
2642         styleToUse = curr->style(firstlineStyle);
2643         if (decorations & UNDERLINE)
2644             underline = decorationColor(styleToUse);
2645         if (decorations & OVERLINE)
2646             overline = decorationColor(styleToUse);
2647         if (decorations & LINE_THROUGH)
2648             linethrough = decorationColor(styleToUse);
2649     }
2650 }
2651
2652 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
2653 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2654 {
2655     // Convert the style regions to absolute coordinates.
2656     if (style()->visibility() != VISIBLE || !isBox())
2657         return;
2658     
2659     RenderBox* box = toRenderBox(this);
2660
2661     const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2662     unsigned i, count = styleRegions.size();
2663     for (i = 0; i < count; i++) {
2664         StyleDashboardRegion styleRegion = styleRegions[i];
2665
2666         LayoutUnit w = box->width();
2667         LayoutUnit h = box->height();
2668
2669         DashboardRegionValue region;
2670         region.label = styleRegion.label;
2671         region.bounds = LayoutRect(styleRegion.offset.left().value(),
2672                                    styleRegion.offset.top().value(),
2673                                    w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
2674                                    h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
2675         region.type = styleRegion.type;
2676
2677         region.clip = region.bounds;
2678         computeAbsoluteRepaintRect(region.clip);
2679         if (region.clip.height() < 0) {
2680             region.clip.setHeight(0);
2681             region.clip.setWidth(0);
2682         }
2683
2684         FloatPoint absPos = localToAbsolute();
2685         region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
2686         region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
2687
2688         regions.append(region);
2689     }
2690 }
2691
2692 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2693 {
2694     // RenderTexts don't have their own style, they just use their parent's style,
2695     // so we don't want to include them.
2696     if (isText())
2697         return;
2698
2699     addDashboardRegions(regions);
2700     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2701         curr->collectDashboardRegions(regions);
2702 }
2703 #endif
2704
2705 bool RenderObject::willRenderImage(CachedImage*)
2706 {
2707     // Without visibility we won't render (and therefore don't care about animation).
2708     if (style()->visibility() != VISIBLE)
2709         return false;
2710
2711     // We will not render a new image when Active DOM is suspended
2712     if (document()->activeDOMObjectsAreSuspended())
2713         return false;
2714
2715     // If we're not in a window (i.e., we're dormant from being put in the b/f cache or in a background tab)
2716     // then we don't want to render either.
2717     if (document()->inPageCache() || document()->view()->isOffscreen())
2718         return false;
2719
2720     // If the document is being destroyed or has not been attached, then this
2721     // RenderObject will not be rendered.
2722     if (!view())
2723         return false;
2724
2725     // If a renderer is outside the viewport, we won't render.
2726     return viewRect().intersects(absoluteClippedOverflowRect());
2727 }
2728
2729 int RenderObject::maximalOutlineSize(PaintPhase p) const
2730 {
2731     if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2732         return 0;
2733     return toRenderView(document()->renderer())->maximalOutlineSize();
2734 }
2735
2736 int RenderObject::caretMinOffset() const
2737 {
2738     return 0;
2739 }
2740
2741 int RenderObject::caretMaxOffset() const
2742 {
2743     if (isReplaced())
2744         return node() ? max(1U, node()->childNodeCount()) : 1;
2745     if (isHR())
2746         return 1;
2747     return 0;
2748 }
2749
2750 int RenderObject::previousOffset(int current) const
2751 {
2752     return current - 1;
2753 }
2754
2755 int RenderObject::previousOffsetForBackwardDeletion(int current) const
2756 {
2757     return current - 1;
2758 }
2759
2760 int RenderObject::nextOffset(int current) const
2761 {
2762     return current + 1;
2763 }
2764
2765 void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const
2766 {
2767     int outlineSize = outlineStyleForRepaint()->outlineSize();
2768     if (const ShadowData* boxShadow = style()->boxShadow()) {
2769         boxShadow->adjustRectForShadow(rect, outlineSize);
2770         return;
2771     }
2772
2773     rect.inflate(outlineSize);
2774 }
2775
2776 AnimationController* RenderObject::animation() const
2777 {
2778     return frame()->animation();
2779 }
2780
2781 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
2782 {
2783     imageChanged(static_cast<WrappedImagePtr>(image), rect);
2784 }
2785
2786 RenderBoxModelObject* RenderObject::offsetParent() const
2787 {
2788     // If any of the following holds true return null and stop this algorithm:
2789     // A is the root element.
2790     // A is the HTML body element.
2791     // The computed value of the position property for element A is fixed.
2792     if (isRoot() || isBody() || (isOutOfFlowPositioned() && style()->position() == FixedPosition))
2793         return 0;
2794
2795     // If A is an area HTML element which has a map HTML element somewhere in the ancestor
2796     // chain return the nearest ancestor map HTML element and stop this algorithm.
2797     // FIXME: Implement!
2798     
2799     // Return the nearest ancestor element of A for which at least one of the following is
2800     // true and stop this algorithm if such an ancestor is found:
2801     //     * The computed value of the position property is not static.
2802     //     * It is the HTML body element.
2803     //     * The computed value of the position property of A is static and the ancestor
2804     //       is one of the following HTML elements: td, th, or table.
2805     //     * Our own extension: if there is a difference in the effective zoom
2806
2807     bool skipTables = isOutOfFlowPositioned() || isRelPositioned();
2808     float currZoom = style()->effectiveZoom();
2809     RenderObject* curr = parent();
2810     while (curr && (!curr->node() || (!curr->isOutOfFlowPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
2811         Node* element = curr->node();
2812         if (!skipTables && element && (element->hasTagName(tableTag) || element->hasTagName(tdTag) || element->hasTagName(thTag)))
2813             break;
2814
2815         float newZoom = curr->style()->effectiveZoom();
2816         if (currZoom != newZoom)
2817             break;
2818         currZoom = newZoom;
2819         curr = curr->parent();
2820     }
2821     return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
2822 }
2823
2824 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
2825 {
2826     // If this is a non-anonymous renderer in an editable area, then it's simple.
2827     if (Node* node = this->node()) {
2828         if (!node->rendererIsEditable()) {
2829             // If it can be found, we prefer a visually equivalent position that is editable. 
2830             Position position = createLegacyEditingPosition(node, offset);
2831             Position candidate = position.downstream(CanCrossEditingBoundary);
2832             if (candidate.deprecatedNode()->rendererIsEditable())
2833                 return VisiblePosition(candidate, affinity);
2834             candidate = position.upstream(CanCrossEditingBoundary);
2835             if (candidate.deprecatedNode()->rendererIsEditable())
2836                 return VisiblePosition(candidate, affinity);
2837         }
2838         // FIXME: Eliminate legacy editing positions
2839         return VisiblePosition(createLegacyEditingPosition(node, offset), affinity);
2840     }
2841
2842     // We don't want to cross the boundary between editable and non-editable
2843     // regions of the document, but that is either impossible or at least
2844     // extremely unlikely in any normal case because we stop as soon as we
2845     // find a single non-anonymous renderer.
2846
2847     // Find a nearby non-anonymous renderer.
2848     RenderObject* child = this;
2849     while (RenderObject* parent = child->parent()) {
2850         // Find non-anonymous content after.
2851         RenderObject* renderer = child;
2852         while ((renderer = renderer->nextInPreOrder(parent))) {
2853             if (Node* node = renderer->node())
2854                 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2855         }
2856
2857         // Find non-anonymous content before.
2858         renderer = child;
2859         while ((renderer = renderer->previousInPreOrder())) {
2860             if (renderer == parent)
2861                 break;
2862             if (Node* node = renderer->node())
2863                 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
2864         }
2865
2866         // Use the parent itself unless it too is anonymous.
2867         if (Node* node = parent->node())
2868             return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2869
2870         // Repeat at the next level up.
2871         child = parent;
2872     }
2873
2874     // Everything was anonymous. Give up.
2875     return VisiblePosition();
2876 }
2877
2878 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
2879 {
2880     if (position.isNotNull())
2881         return VisiblePosition(position);
2882
2883     ASSERT(!node());
2884     return createVisiblePosition(0, DOWNSTREAM);
2885 }
2886
2887 CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
2888 {
2889     return SetCursorBasedOnStyle;
2890 }
2891
2892 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
2893 {
2894     if (needsLayout())
2895         return false;
2896
2897     RenderBlock* containingBlock = this->containingBlock();
2898     return containingBlock ? !containingBlock->needsLayout() : true;
2899 }
2900
2901 // We only create "generated" child renderers like one for first-letter if:
2902 // - the firstLetterBlock can have children in the DOM and
2903 // - the block doesn't have any special assumption on its text children.
2904 // This correctly prevents form controls from having such renderers.
2905 bool RenderObject::canHaveGeneratedChildren() const
2906 {
2907     return canHaveChildren();
2908 }
2909
2910 bool RenderObject::canBeReplacedWithInlineRunIn() const
2911 {
2912     return true;
2913 }
2914
2915 #if ENABLE(SVG)
2916
2917 RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
2918 {
2919     ASSERT_NOT_REACHED();
2920     return 0;
2921 }
2922
2923 void RenderObject::setNeedsBoundariesUpdate()
2924 {
2925     if (RenderObject* renderer = parent())
2926         renderer->setNeedsBoundariesUpdate();
2927 }
2928
2929 FloatRect RenderObject::objectBoundingBox() const
2930 {
2931     ASSERT_NOT_REACHED();
2932     return FloatRect();
2933 }
2934
2935 FloatRect RenderObject::strokeBoundingBox() const
2936 {
2937     ASSERT_NOT_REACHED();
2938     return FloatRect();
2939 }
2940
2941 // Returns the smallest rectangle enclosing all of the painted content
2942 // respecting clipping, masking, filters, opacity, stroke-width and markers
2943 FloatRect RenderObject::repaintRectInLocalCoordinates() const
2944 {
2945     ASSERT_NOT_REACHED();
2946     return FloatRect();
2947 }
2948
2949 AffineTransform RenderObject::localTransform() const
2950 {
2951     static const AffineTransform identity;
2952     return identity;
2953 }
2954
2955 const AffineTransform& RenderObject::localToParentTransform() const
2956 {
2957     static const AffineTransform identity;
2958     return identity;
2959 }
2960
2961 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
2962 {
2963     ASSERT_NOT_REACHED();
2964     return false;
2965 }
2966
2967 #endif // ENABLE(SVG)
2968
2969 } // namespace WebCore
2970
2971 #ifndef NDEBUG
2972
2973 void showTree(const WebCore::RenderObject* object)
2974 {
2975     if (object)
2976         object->showTreeForThis();
2977 }
2978
2979 void showLineTree(const WebCore::RenderObject* object)
2980 {
2981     if (object)
2982         object->showLineTreeForThis();
2983 }
2984
2985 void showRenderTree(const WebCore::RenderObject* object1)
2986 {
2987     showRenderTree(object1, 0);
2988 }
2989
2990 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
2991 {
2992     if (object1) {
2993         const WebCore::RenderObject* root = object1;
2994         while (root->parent())
2995             root = root->parent();
2996         root->showRenderTreeAndMark(object1, "*", object2, "-", 0);
2997     }
2998 }
2999
3000 #endif