Shadow DOM for img element
[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, doc->renderView()->flowThreadController()->ensureRenderFlowThreadWithName(style->regionThread()));
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 width = (side == BSTop || side == BSBottom ? y2 - y1 : x2 - x1);
838
839     if (style == DOUBLE && width < 3)
840         style = SOLID;
841
842     switch (style) {
843         case BNONE:
844         case BHIDDEN:
845             return;
846         case DOTTED:
847         case DASHED: {
848             graphicsContext->setStrokeColor(color, m_style->colorSpace());
849             graphicsContext->setStrokeThickness(width);
850             StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
851             graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
852
853             if (width > 0) {
854                 bool wasAntialiased = graphicsContext->shouldAntialias();
855                 graphicsContext->setShouldAntialias(antialias);
856
857                 switch (side) {
858                     case BSBottom:
859                     case BSTop:
860                         graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
861                         break;
862                     case BSRight:
863                     case BSLeft:
864                         graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
865                         break;
866                 }
867                 graphicsContext->setShouldAntialias(wasAntialiased);
868                 graphicsContext->setStrokeStyle(oldStrokeStyle);
869             }
870             break;
871         }
872         case DOUBLE: {
873             int third = (width + 1) / 3;
874
875             if (adjacentWidth1 == 0 && adjacentWidth2 == 0) {
876                 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
877                 graphicsContext->setStrokeStyle(NoStroke);
878                 graphicsContext->setFillColor(color, m_style->colorSpace());
879                 
880                 bool wasAntialiased = graphicsContext->shouldAntialias();
881                 graphicsContext->setShouldAntialias(antialias);
882
883                 switch (side) {
884                     case BSTop:
885                     case BSBottom:
886                         graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third));
887                         graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third));
888                         break;
889                     case BSLeft:
890                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
891                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
892                         break;
893                     case BSRight:
894                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
895                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
896                         break;
897                 }
898
899                 graphicsContext->setShouldAntialias(wasAntialiased);
900                 graphicsContext->setStrokeStyle(oldStrokeStyle);
901             } else {
902                 int adjacent1BigThird = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3;
903                 int adjacent2BigThird = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3;
904
905                 switch (side) {
906                     case BSTop:
907                         drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
908                                    y1, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y1 + third,
909                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
910                         drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
911                                    y2 - third, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y2,
912                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
913                         break;
914                     case BSLeft:
915                         drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
916                                    x1 + third, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
917                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
918                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
919                                    x2, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
920                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
921                         break;
922                     case BSBottom:
923                         drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
924                                    y1, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y1 + third,
925                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
926                         drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
927                                    y2 - third, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y2,
928                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
929                         break;
930                     case BSRight:
931                         drawLineForBoxSide(graphicsContext, x1, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
932                                    x1 + third, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
933                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
934                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
935                                    x2, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
936                                    side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
937                         break;
938                     default:
939                         break;
940                 }
941             }
942             break;
943         }
944         case RIDGE:
945         case GROOVE: {
946             EBorderStyle s1;
947             EBorderStyle s2;
948             if (style == GROOVE) {
949                 s1 = INSET;
950                 s2 = OUTSET;
951             } else {
952                 s1 = OUTSET;
953                 s2 = INSET;
954             }
955
956             int adjacent1BigHalf = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2;
957             int adjacent2BigHalf = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2;
958
959             switch (side) {
960                 case BSTop:
961                     drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1, 0) / 2, y1, x2 - max(-adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
962                                side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
963                     drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjacentWidth2 + 1, 0) / 2, y2,
964                                side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
965                     break;
966                 case BSLeft:
967                     drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjacentWidth2, 0) / 2,
968                                side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
969                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjacentWidth1 + 1, 0) / 2, x2, y2 - max(adjacentWidth2 + 1, 0) / 2,
970                                side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
971                     break;
972                 case BSBottom:
973                     drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1, 0) / 2, y1, x2 - max(adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
974                                side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
975                     drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjacentWidth2 + 1, 0) / 2, y2,
976                                side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
977                     break;
978                 case BSRight:
979                     drawLineForBoxSide(graphicsContext, x1, y1 + max(adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjacentWidth2, 0) / 2,
980                                side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
981                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjacentWidth1 + 1, 0) / 2, x2, y2 - max(-adjacentWidth2 + 1, 0) / 2,
982                                side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
983                     break;
984             }
985             break;
986         }
987         case INSET:
988             // FIXME: Maybe we should lighten the colors on one side like Firefox.
989             // https://bugs.webkit.org/show_bug.cgi?id=58608
990             if (side == BSTop || side == BSLeft)
991                 color = color.dark();
992             // fall through
993         case OUTSET:
994             if (style == OUTSET && (side == BSBottom || side == BSRight))
995                 color = color.dark();
996             // fall through
997         case SOLID: {
998             StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
999             graphicsContext->setStrokeStyle(NoStroke);
1000             graphicsContext->setFillColor(color, m_style->colorSpace());
1001             ASSERT(x2 >= x1);
1002             ASSERT(y2 >= y1);
1003             if (!adjacentWidth1 && !adjacentWidth2) {
1004                 // Turn off antialiasing to match the behavior of drawConvexPolygon();
1005                 // this matters for rects in transformed contexts.
1006                 bool wasAntialiased = graphicsContext->shouldAntialias();
1007                 graphicsContext->setShouldAntialias(antialias);
1008                 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1009                 graphicsContext->setShouldAntialias(wasAntialiased);
1010                 graphicsContext->setStrokeStyle(oldStrokeStyle);
1011                 return;
1012             }
1013             FloatPoint quad[4];
1014             switch (side) {
1015                 case BSTop:
1016                     quad[0] = FloatPoint(x1 + max(-adjacentWidth1, 0), y1);
1017                     quad[1] = FloatPoint(x1 + max(adjacentWidth1, 0), y2);
1018                     quad[2] = FloatPoint(x2 - max(adjacentWidth2, 0), y2);
1019                     quad[3] = FloatPoint(x2 - max(-adjacentWidth2, 0), y1);
1020                     break;
1021                 case BSBottom:
1022                     quad[0] = FloatPoint(x1 + max(adjacentWidth1, 0), y1);
1023                     quad[1] = FloatPoint(x1 + max(-adjacentWidth1, 0), y2);
1024                     quad[2] = FloatPoint(x2 - max(-adjacentWidth2, 0), y2);
1025                     quad[3] = FloatPoint(x2 - max(adjacentWidth2, 0), y1);
1026                     break;
1027                 case BSLeft:
1028                     quad[0] = FloatPoint(x1, y1 + max(-adjacentWidth1, 0));
1029                     quad[1] = FloatPoint(x1, y2 - max(-adjacentWidth2, 0));
1030                     quad[2] = FloatPoint(x2, y2 - max(adjacentWidth2, 0));
1031                     quad[3] = FloatPoint(x2, y1 + max(adjacentWidth1, 0));
1032                     break;
1033                 case BSRight:
1034                     quad[0] = FloatPoint(x1, y1 + max(adjacentWidth1, 0));
1035                     quad[1] = FloatPoint(x1, y2 - max(adjacentWidth2, 0));
1036                     quad[2] = FloatPoint(x2, y2 - max(-adjacentWidth2, 0));
1037                     quad[3] = FloatPoint(x2, y1 + max(-adjacentWidth1, 0));
1038                     break;
1039             }
1040
1041             graphicsContext->drawConvexPolygon(4, quad, antialias);
1042             graphicsContext->setStrokeStyle(oldStrokeStyle);
1043             break;
1044         }
1045     }
1046 }
1047
1048 void RenderObject::paintFocusRing(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style)
1049 {
1050     Vector<IntRect> focusRingRects;
1051     addFocusRingRects(focusRingRects, paintOffset);
1052     if (style->outlineStyleIsAuto())
1053         context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
1054     else
1055         addPDFURLRect(context, unionRect(focusRingRects));
1056 }
1057
1058 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
1059 {
1060     if (rect.isEmpty())
1061         return;
1062     Node* n = node();
1063     if (!n || !n->isLink() || !n->isElementNode())
1064         return;
1065     const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
1066     if (href.isNull())
1067         return;
1068     context->setURLForRect(n->document()->completeURL(href), pixelSnappedIntRect(rect));
1069 }
1070
1071 void RenderObject::paintOutline(GraphicsContext* graphicsContext, const LayoutRect& paintRect)
1072 {
1073     if (!hasOutline())
1074         return;
1075
1076     RenderStyle* styleToUse = style();
1077     LayoutUnit outlineWidth = styleToUse->outlineWidth();
1078     EBorderStyle outlineStyle = styleToUse->outlineStyle();
1079
1080     Color outlineColor = styleToUse->visitedDependentColor(CSSPropertyOutlineColor);
1081
1082     int outlineOffset = styleToUse->outlineOffset();
1083
1084     if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1085         if (!theme()->supportsFocusRing(styleToUse)) {
1086             // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1087             paintFocusRing(graphicsContext, paintRect.location(), styleToUse);
1088         }
1089     }
1090
1091     if (styleToUse->outlineStyleIsAuto() || styleToUse->outlineStyle() == BNONE)
1092         return;
1093
1094     IntRect inner = pixelSnappedIntRect(paintRect);
1095     inner.inflate(outlineOffset);
1096
1097     IntRect outer = pixelSnappedIntRect(inner);
1098     outer.inflate(outlineWidth);
1099
1100     // FIXME: This prevents outlines from painting inside the object. See bug 12042
1101     if (outer.isEmpty())
1102         return;
1103
1104     bool useTransparencyLayer = outlineColor.hasAlpha();
1105     if (useTransparencyLayer) {
1106         if (outlineStyle == SOLID) {
1107             Path path;
1108             path.addRect(outer);
1109             path.addRect(inner);
1110             graphicsContext->setFillRule(RULE_EVENODD);
1111             graphicsContext->setFillColor(outlineColor, styleToUse->colorSpace());
1112             graphicsContext->fillPath(path);
1113             return;
1114         }
1115         graphicsContext->beginTransparencyLayer(static_cast<float>(outlineColor.alpha()) / 255);
1116         outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineColor.blue());
1117     }
1118
1119     int leftOuter = outer.x();
1120     int leftInner = inner.x();
1121     int rightOuter = outer.maxX();
1122     int rightInner = inner.maxX();
1123     int topOuter = outer.y();
1124     int topInner = inner.y();
1125     int bottomOuter = outer.maxY();
1126     int bottomInner = inner.maxY();
1127     
1128     drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1129     drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInner, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1130     drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottomOuter, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1131     drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bottomOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1132
1133     if (useTransparencyLayer)
1134         graphicsContext->endTransparencyLayer();
1135 }
1136
1137 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) const
1138 {
1139     if (useTransforms) {
1140         Vector<FloatQuad> quads;
1141         absoluteQuads(quads);
1142
1143         size_t n = quads.size();
1144         if (!n)
1145             return IntRect();
1146     
1147         IntRect result = quads[0].enclosingBoundingBox();
1148         for (size_t i = 1; i < n; ++i)
1149             result.unite(quads[i].enclosingBoundingBox());
1150         return result;
1151     }
1152
1153     FloatPoint absPos = localToAbsolute();
1154     Vector<IntRect> rects;
1155     absoluteRects(rects, flooredLayoutPoint(absPos));
1156
1157     size_t n = rects.size();
1158     if (!n)
1159         return IntRect();
1160
1161     LayoutRect result = rects[0];
1162     for (size_t i = 1; i < n; ++i)
1163         result.unite(rects[i]);
1164     return pixelSnappedIntRect(result);
1165 }
1166
1167 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1168 {
1169     Vector<IntRect> rects;
1170     // FIXME: addFocusRingRects() needs to be passed this transform-unaware
1171     // localToAbsolute() offset here because RenderInline::addFocusRingRects()
1172     // implicitly assumes that. This doesn't work correctly with transformed
1173     // descendants.
1174     FloatPoint absolutePoint = localToAbsolute();
1175     addFocusRingRects(rects, flooredLayoutPoint(absolutePoint));
1176     size_t count = rects.size(); 
1177     for (size_t i = 0; i < count; ++i) {
1178         IntRect rect = rects[i];
1179         rect.move(-absolutePoint.x(), -absolutePoint.y());
1180         quads.append(localToAbsoluteQuad(FloatQuad(rect)));
1181     }
1182 }
1183
1184 void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
1185 {
1186     if (hasLayer())
1187         result.unite(absoluteBoundingBoxRectIgnoringTransforms());
1188     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1189         current->addAbsoluteRectForLayer(result);
1190 }
1191
1192 LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect)
1193 {
1194     LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms();
1195     topLevelRect = result;
1196     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1197         current->addAbsoluteRectForLayer(result);
1198     return result;
1199 }
1200
1201 void RenderObject::paint(PaintInfo&, const LayoutPoint&)
1202 {
1203 }
1204
1205 RenderBoxModelObject* RenderObject::containerForRepaint() const
1206 {
1207     RenderView* v = view();
1208     if (!v)
1209         return 0;
1210     
1211     RenderBoxModelObject* repaintContainer = 0;
1212
1213 #if USE(ACCELERATED_COMPOSITING)
1214     if (v->usesCompositing()) {
1215         if (RenderLayer* parentLayer = enclosingLayer()) {
1216             RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint();
1217             if (compLayer)
1218                 repaintContainer = compLayer->renderer();
1219         }
1220     }
1221 #endif
1222     
1223 #if ENABLE(CSS_FILTERS)
1224     if (RenderLayer* parentLayer = enclosingLayer()) {
1225         RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer();
1226         if (enclosingFilterLayer)
1227             return enclosingFilterLayer->renderer();
1228     }
1229 #endif
1230
1231     // If we have a flow thread, then we need to do individual repaints within the RenderRegions instead.
1232     // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change
1233     // repainting to do individual region repaints.
1234     // FIXME: Composited layers inside a flow thread will bypass this mechanism and will malfunction. It's not
1235     // clear how to address this problem for composited descendants of a RenderFlowThread.
1236     if (!repaintContainer && inRenderFlowThread())
1237         repaintContainer = enclosingRenderFlowThread();
1238     return repaintContainer;
1239 }
1240
1241 void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect& r, bool immediate)
1242 {
1243     if (!repaintContainer) {
1244         view()->repaintViewRectangle(r, immediate);
1245         return;
1246     }
1247
1248     if (repaintContainer->isRenderFlowThread()) {
1249         toRenderFlowThread(repaintContainer)->repaintRectangleInRegions(r, immediate);
1250         return;
1251     }
1252
1253 #if ENABLE(CSS_FILTERS)
1254     if (repaintContainer->hasFilter() && repaintContainer->layer() && repaintContainer->layer()->requiresFullLayerImageForFilters()) {
1255         repaintContainer->layer()->setFilterBackendNeedsRepaintingInRect(r, immediate);
1256         return;
1257     }
1258 #endif
1259
1260 #if USE(ACCELERATED_COMPOSITING)
1261     RenderView* v = view();
1262     if (repaintContainer->isRenderView()) {
1263         ASSERT(repaintContainer == v);
1264         bool viewHasCompositedLayer = v->hasLayer() && v->layer()->isComposited();
1265         if (!viewHasCompositedLayer || v->layer()->backing()->paintsIntoWindow()) {
1266             LayoutRect repaintRectangle = r;
1267             if (viewHasCompositedLayer &&  v->layer()->transform())
1268                 repaintRectangle = v->layer()->transform()->mapRect(r);
1269             v->repaintViewRectangle(repaintRectangle, immediate);
1270             return;
1271         }
1272     }
1273     
1274     if (v->usesCompositing()) {
1275         ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
1276         repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
1277     }
1278 #else
1279     if (repaintContainer->isRenderView())
1280         toRenderView(repaintContainer)->repaintViewRectangle(r, immediate);
1281 #endif
1282 }
1283
1284 void RenderObject::repaint(bool immediate)
1285 {
1286     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1287     RenderView* view;
1288     if (!isRooted(&view))
1289         return;
1290
1291     if (view->printing())
1292         return; // Don't repaint if we're printing.
1293
1294     RenderBoxModelObject* repaintContainer = containerForRepaint();
1295     repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate);
1296 }
1297
1298 void RenderObject::repaintRectangle(const LayoutRect& r, 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     LayoutRect dirtyRect(r);
1309
1310     // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1311     // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1312     dirtyRect.move(view->layoutDelta());
1313
1314     RenderBoxModelObject* repaintContainer = containerForRepaint();
1315     computeRectForRepaint(repaintContainer, dirtyRect);
1316     repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate);
1317 }
1318
1319 IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const
1320 {
1321     return pixelSnappedIntRect(absoluteClippedOverflowRect());
1322 }
1323
1324 bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr, const LayoutRect* newOutlineBoxRectPtr)
1325 {
1326     RenderView* v = view();
1327     if (v->printing())
1328         return false; // Don't repaint if we're printing.
1329
1330     // This ASSERT fails due to animations.  See https://bugs.webkit.org/show_bug.cgi?id=37048
1331     // ASSERT(!newBoundsPtr || *newBoundsPtr == clippedOverflowRectForRepaint(repaintContainer));
1332     LayoutRect newBounds = newBoundsPtr ? *newBoundsPtr : clippedOverflowRectForRepaint(repaintContainer);
1333     LayoutRect newOutlineBox;
1334
1335     bool fullRepaint = selfNeedsLayout();
1336     // Presumably a background or a border exists if border-fit:lines was specified.
1337     if (!fullRepaint && style()->borderFit() == BorderFitLines)
1338         fullRepaint = true;
1339     if (!fullRepaint) {
1340         // This ASSERT fails due to animations.  See https://bugs.webkit.org/show_bug.cgi?id=37048
1341         // ASSERT(!newOutlineBoxRectPtr || *newOutlineBoxRectPtr == outlineBoundsForRepaint(repaintContainer));
1342         newOutlineBox = newOutlineBoxRectPtr ? *newOutlineBoxRectPtr : outlineBoundsForRepaint(repaintContainer);
1343         if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1344             fullRepaint = true;
1345     }
1346
1347     if (!repaintContainer)
1348         repaintContainer = v;
1349
1350     if (fullRepaint) {
1351         repaintUsingContainer(repaintContainer, oldBounds);
1352         if (newBounds != oldBounds)
1353             repaintUsingContainer(repaintContainer, newBounds);
1354         return true;
1355     }
1356
1357     if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1358         return false;
1359
1360     LayoutUnit deltaLeft = newBounds.x() - oldBounds.x();
1361     if (deltaLeft > 0)
1362         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1363     else if (deltaLeft < 0)
1364         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1365
1366     LayoutUnit deltaRight = newBounds.maxX() - oldBounds.maxX();
1367     if (deltaRight > 0)
1368         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.maxX(), newBounds.y(), deltaRight, newBounds.height()));
1369     else if (deltaRight < 0)
1370         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.maxX(), oldBounds.y(), -deltaRight, oldBounds.height()));
1371
1372     LayoutUnit deltaTop = newBounds.y() - oldBounds.y();
1373     if (deltaTop > 0)
1374         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1375     else if (deltaTop < 0)
1376         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1377
1378     LayoutUnit deltaBottom = newBounds.maxY() - oldBounds.maxY();
1379     if (deltaBottom > 0)
1380         repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), oldBounds.maxY(), newBounds.width(), deltaBottom));
1381     else if (deltaBottom < 0)
1382         repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), newBounds.maxY(), oldBounds.width(), -deltaBottom));
1383
1384     if (newOutlineBox == oldOutlineBox)
1385         return false;
1386
1387     // We didn't move, but we did change size.  Invalidate the delta, which will consist of possibly
1388     // two rectangles (but typically only one).
1389     RenderStyle* outlineStyle = outlineStyleForRepaint();
1390     LayoutUnit ow = outlineStyle->outlineSize();
1391     LayoutUnit width = absoluteValue(newOutlineBox.width() - oldOutlineBox.width());
1392     if (width) {
1393         LayoutUnit shadowLeft;
1394         LayoutUnit shadowRight;
1395         style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1396
1397         int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1398         LayoutUnit boxWidth = isBox() ? toRenderBox(this)->width() : ZERO_LAYOUT_UNIT;
1399         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);
1400         LayoutRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
1401             newOutlineBox.y(),
1402             width + borderWidth,
1403             max(newOutlineBox.height(), oldOutlineBox.height()));
1404         LayoutUnit right = min<LayoutUnit>(newBounds.maxX(), oldBounds.maxX());
1405         if (rightRect.x() < right) {
1406             rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1407             repaintUsingContainer(repaintContainer, rightRect);
1408         }
1409     }
1410     LayoutUnit height = absoluteValue(newOutlineBox.height() - oldOutlineBox.height());
1411     if (height) {
1412         LayoutUnit shadowTop;
1413         LayoutUnit shadowBottom;
1414         style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1415
1416         int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1417         LayoutUnit boxHeight = isBox() ? toRenderBox(this)->height() : ZERO_LAYOUT_UNIT;
1418         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);
1419         LayoutRect bottomRect(newOutlineBox.x(),
1420             min(newOutlineBox.maxY(), oldOutlineBox.maxY()) - borderHeight,
1421             max(newOutlineBox.width(), oldOutlineBox.width()),
1422             height + borderHeight);
1423         LayoutUnit bottom = min(newBounds.maxY(), oldBounds.maxY());
1424         if (bottomRect.y() < bottom) {
1425             bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1426             repaintUsingContainer(repaintContainer, bottomRect);
1427         }
1428     }
1429     return false;
1430 }
1431
1432 void RenderObject::repaintDuringLayoutIfMoved(const LayoutRect&)
1433 {
1434 }
1435
1436 void RenderObject::repaintOverhangingFloats(bool)
1437 {
1438 }
1439
1440 bool RenderObject::checkForRepaintDuringLayout() const
1441 {
1442     // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=20885> It is probably safe to also require
1443     // m_everHadLayout. Currently, only RenderBlock::layoutBlock() adds this condition. See also
1444     // <https://bugs.webkit.org/show_bug.cgi?id=15129>.
1445     return !document()->view()->needsFullRepaint() && !hasLayer();
1446 }
1447
1448 LayoutRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, LayoutUnit outlineWidth) const
1449 {
1450     LayoutRect r(clippedOverflowRectForRepaint(repaintContainer));
1451     r.inflate(outlineWidth);
1452     return r;
1453 }
1454
1455 LayoutRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*) const
1456 {
1457     ASSERT_NOT_REACHED();
1458     return LayoutRect();
1459 }
1460
1461 void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
1462 {
1463     if (repaintContainer == this)
1464         return;
1465
1466     if (RenderObject* o = parent()) {
1467         if (o->isBlockFlow()) {
1468             RenderBlock* cb = toRenderBlock(o);
1469             if (cb->hasColumns())
1470                 cb->adjustRectForColumns(rect);
1471         }
1472
1473         if (o->hasOverflowClip()) {
1474             // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
1475             // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
1476             // anyway if its size does change.
1477             RenderBox* boxParent = toRenderBox(o);
1478
1479             LayoutRect repaintRect(rect);
1480             repaintRect.move(-boxParent->scrolledContentOffset()); // For overflow:auto/scroll/hidden.
1481
1482             LayoutRect boxRect(LayoutPoint(), boxParent->cachedSizeForOverflowClip());
1483             rect = intersection(repaintRect, boxRect);
1484             if (rect.isEmpty())
1485                 return;
1486         }
1487
1488         o->computeRectForRepaint(repaintContainer, rect, fixed);
1489     }
1490 }
1491
1492 void RenderObject::computeFloatRectForRepaint(RenderBoxModelObject*, FloatRect&, bool) const
1493 {
1494     ASSERT_NOT_REACHED();
1495 }
1496
1497 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1498 {
1499 }
1500
1501 #ifndef NDEBUG
1502
1503 void RenderObject::showTreeForThis() const
1504 {
1505     if (node())
1506         node()->showTreeForThis();
1507 }
1508
1509 void RenderObject::showRenderTreeForThis() const
1510 {
1511     showRenderTree(this, 0);
1512 }
1513
1514 void RenderObject::showLineTreeForThis() const
1515 {
1516     if (containingBlock())
1517         containingBlock()->showLineTreeAndMark(0, 0, 0, 0, this);
1518 }
1519
1520 void RenderObject::showRenderObject() const
1521 {
1522     showRenderObject(0);
1523 }
1524
1525 void RenderObject::showRenderObject(int printedCharacters) const
1526 {
1527     // As this function is intended to be used when debugging, the
1528     // this pointer may be 0.
1529     if (!this) {
1530         fputs("(null)\n", stderr);
1531         return;
1532     }
1533
1534     printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
1535
1536     if (node()) {
1537         if (printedCharacters)
1538             for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
1539                 fputc(' ', stderr);
1540         fputc('\t', stderr);
1541         node()->showNode();
1542     } else
1543         fputc('\n', stderr);
1544 }
1545
1546 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
1547 {
1548     int printedCharacters = 0;
1549     if (markedObject1 == this && markedLabel1)
1550         printedCharacters += fprintf(stderr, "%s", markedLabel1);
1551     if (markedObject2 == this && markedLabel2)
1552         printedCharacters += fprintf(stderr, "%s", markedLabel2);
1553     for (; printedCharacters < depth * 2; printedCharacters++)
1554         fputc(' ', stderr);
1555
1556     showRenderObject(printedCharacters);
1557     if (!this)
1558         return;
1559
1560     for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
1561         child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
1562 }
1563
1564 #endif // NDEBUG
1565
1566 Color RenderObject::selectionBackgroundColor() const
1567 {
1568     Color color;
1569     if (style()->userSelect() != SELECT_NONE) {
1570         RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
1571         if (pseudoStyle && pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
1572             color = pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).blendWithWhite();
1573         else
1574             color = frame()->selection()->isFocusedAndActive() ?
1575                     theme()->activeSelectionBackgroundColor() :
1576                     theme()->inactiveSelectionBackgroundColor();
1577     }
1578
1579     return color;
1580 }
1581
1582 Color RenderObject::selectionColor(int colorProperty) const
1583 {
1584     Color color;
1585     // If the element is unselectable, or we are only painting the selection,
1586     // don't override the foreground color with the selection foreground color.
1587     if (style()->userSelect() == SELECT_NONE
1588         || (frame()->view()->paintBehavior() & PaintBehaviorSelectionOnly))
1589         return color;
1590
1591     if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
1592         color = pseudoStyle->visitedDependentColor(colorProperty);
1593         if (!color.isValid())
1594             color = pseudoStyle->visitedDependentColor(CSSPropertyColor);
1595     } else
1596         color = frame()->selection()->isFocusedAndActive() ?
1597                 theme()->activeSelectionForegroundColor() :
1598                 theme()->inactiveSelectionForegroundColor();
1599
1600     return color;
1601 }
1602
1603 Color RenderObject::selectionForegroundColor() const
1604 {
1605     return selectionColor(CSSPropertyWebkitTextFillColor);
1606 }
1607
1608 Color RenderObject::selectionEmphasisMarkColor() const
1609 {
1610     return selectionColor(CSSPropertyWebkitTextEmphasisColor);
1611 }
1612
1613 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1614 {
1615     view()->selectionStartEnd(spos, epos);
1616 }
1617
1618 void RenderObject::handleDynamicFloatPositionChange()
1619 {
1620     // We have gone from not affecting the inline status of the parent flow to suddenly
1621     // having an impact.  See if there is a mismatch between the parent flow's
1622     // childrenInline() state and our state.
1623     setInline(style()->isDisplayInlineType());
1624     if (isInline() != parent()->childrenInline()) {
1625         if (!isInline())
1626             toRenderBoxModelObject(parent())->childBecameNonInline(this);
1627         else {
1628             // An anonymous block must be made to wrap this inline.
1629             RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1630             RenderObjectChildList* childlist = parent()->virtualChildren();
1631             childlist->insertChildNode(parent(), block, this);
1632             block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1633         }
1634     }
1635 }
1636
1637 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
1638 {
1639     if (!isText() && style)
1640         setStyle(animation()->updateAnimations(this, style.get()));
1641     else
1642         setStyle(style);
1643 }
1644
1645 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1646 {
1647 #if USE(ACCELERATED_COMPOSITING)
1648     // If transform changed, and we are not composited, need to do a layout.
1649     if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1650         // Text nodes share style with their parents but transforms don't apply to them,
1651         // hence the !isText() check.
1652         // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1653         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) {
1654             // We need to set at least SimplifiedLayout, but if PositionedMovementOnly is already set
1655             // then we actually need SimplifiedLayoutAndPositionedMovement.
1656             if (!hasLayer())
1657                 diff = StyleDifferenceLayout; // FIXME: Do this for now since SimplifiedLayout cannot handle updating floating objects lists.
1658             else if (diff < StyleDifferenceLayoutPositionedMovementOnly)
1659                 diff = StyleDifferenceSimplifiedLayout;
1660             else if (diff < StyleDifferenceSimplifiedLayout)
1661                 diff = StyleDifferenceSimplifiedLayoutAndPositionedMovement;
1662         } else if (diff < StyleDifferenceRecompositeLayer)
1663             diff = StyleDifferenceRecompositeLayer;
1664     }
1665
1666     // If opacity changed, and we are not composited, need to repaint (also
1667     // ignoring text nodes)
1668     if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
1669         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
1670             diff = StyleDifferenceRepaintLayer;
1671         else if (diff < StyleDifferenceRecompositeLayer)
1672             diff = StyleDifferenceRecompositeLayer;
1673     }
1674     
1675 #if ENABLE(CSS_FILTERS)
1676     if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer()) {
1677         RenderLayer* layer = toRenderBoxModelObject(this)->layer();
1678         if (!layer->isComposited() || layer->paintsWithFilters())
1679             diff = StyleDifferenceRepaintLayer;
1680         else if (diff < StyleDifferenceRecompositeLayer)
1681             diff = StyleDifferenceRecompositeLayer;
1682     }
1683 #endif
1684     
1685     // The answer to requiresLayer() for plugins and iframes can change outside of the style system,
1686     // since it depends on whether we decide to composite these elements. When the layer status of
1687     // one of these elements changes, we need to force a layout.
1688     if (diff == StyleDifferenceEqual && style() && isBoxModelObject()) {
1689         if (hasLayer() != toRenderBoxModelObject(this)->requiresLayer())
1690             diff = StyleDifferenceLayout;
1691     }
1692 #else
1693     UNUSED_PARAM(contextSensitiveProperties);
1694 #endif
1695
1696     // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1697     if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1698         diff = StyleDifferenceRepaint;
1699
1700     return diff;
1701 }
1702
1703 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1704 {
1705     if (m_style == style) {
1706 #if USE(ACCELERATED_COMPOSITING)
1707         // We need to run through adjustStyleDifference() for iframes and plugins, so
1708         // style sharing is disabled for them. That should ensure that we never hit this code path.
1709         ASSERT(!isRenderIFrame() && !isEmbeddedObject() &&!isApplet());
1710 #endif
1711         return;
1712     }
1713
1714     StyleDifference diff = StyleDifferenceEqual;
1715     unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1716     if (m_style)
1717         diff = m_style->diff(style.get(), contextSensitiveProperties);
1718
1719     diff = adjustStyleDifference(diff, contextSensitiveProperties);
1720
1721     styleWillChange(diff, style.get());
1722     
1723     RefPtr<RenderStyle> oldStyle = m_style.release();
1724     m_style = style;
1725
1726     updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1727     updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1728
1729     updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1730     updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1731
1732     // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1733     // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1734     if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
1735         toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
1736
1737     bool doesNotNeedLayout = !m_parent || isText();
1738
1739     styleDidChange(diff, oldStyle.get());
1740
1741     // FIXME: |this| might be destroyed here. This can currently happen for a RenderTextFragment when
1742     // its first-letter block gets an update in RenderTextFragment::styleDidChange. For RenderTextFragment(s),
1743     // we will safely bail out with the doesNotNeedLayout flag. We might want to broaden this condition
1744     // in the future as we move renderer changes out of layout and into style changes.
1745     if (doesNotNeedLayout)
1746         return;
1747
1748     // Now that the layer (if any) has been updated, we need to adjust the diff again,
1749     // check whether we should layout now, and decide if we need to repaint.
1750     StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1751     
1752     if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1753         if (updatedDiff == StyleDifferenceLayout)
1754             setNeedsLayoutAndPrefWidthsRecalc();
1755         else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1756             setNeedsPositionedMovementLayout();
1757         else if (updatedDiff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1758             setNeedsPositionedMovementLayout();
1759             setNeedsSimplifiedNormalFlowLayout();
1760         } else if (updatedDiff == StyleDifferenceSimplifiedLayout)
1761             setNeedsSimplifiedNormalFlowLayout();
1762     }
1763     
1764     if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
1765         // Do a repaint with the new style now, e.g., for example if we go from
1766         // not having an outline to having an outline.
1767         repaint();
1768     }
1769 }
1770
1771 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
1772 {
1773     m_style = style;
1774 }
1775
1776 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1777 {
1778     if (m_style) {
1779         // If our z-index changes value or our visibility changes,
1780         // we need to dirty our stacking context's z-order list.
1781         if (newStyle) {
1782             bool visibilityChanged = m_style->visibility() != newStyle->visibility() 
1783                 || m_style->zIndex() != newStyle->zIndex() 
1784                 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1785 #if ENABLE(DASHBOARD_SUPPORT)
1786             if (visibilityChanged)
1787                 document()->setDashboardRegionsDirty(true);
1788 #endif
1789             if (visibilityChanged && AXObjectCache::accessibilityEnabled())
1790                 document()->axObjectCache()->childrenChanged(this);
1791
1792             // Keep layer hierarchy visibility bits up to date if visibility changes.
1793             if (m_style->visibility() != newStyle->visibility()) {
1794                 if (RenderLayer* l = enclosingLayer()) {
1795                     if (newStyle->visibility() == VISIBLE)
1796                         l->setHasVisibleContent();
1797                     else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1798                         l->dirtyVisibleContentStatus();
1799                         if (diff > StyleDifferenceRepaintLayer)
1800                             repaint();
1801                     }
1802                 }
1803             }
1804         }
1805
1806         if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
1807             repaint();
1808         if (isFloating() && (m_style->floating() != newStyle->floating()))
1809             // For changes in float styles, we need to conceivably remove ourselves
1810             // from the floating objects list.
1811             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1812         else if (isOutOfFlowPositioned() && (m_style->position() != newStyle->position()))
1813             // For changes in positioning styles, we need to conceivably remove ourselves
1814             // from the positioned objects list.
1815             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1816
1817         s_affectsParentBlock = isFloatingOrOutOfFlowPositioned()
1818             && (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)
1819             && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
1820
1821         // reset style flags
1822         if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
1823             setFloating(false);
1824             setPositioned(false);
1825             setRelPositioned(false);
1826         }
1827         setHorizontalWritingMode(true);
1828         setPaintBackground(false);
1829         setHasOverflowClip(false);
1830         setHasTransform(false);
1831         setHasReflection(false);
1832     } else
1833         s_affectsParentBlock = false;
1834
1835     if (view()->frameView()) {
1836         bool shouldBlitOnFixedBackgroundImage = false;
1837 #if ENABLE(FAST_MOBILE_SCROLLING)
1838         // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
1839         // when scrolling a page with a fixed background image. As an optimization, assuming there are
1840         // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
1841         // ignore the CSS property "background-attachment: fixed".
1842 #if PLATFORM(QT)
1843         if (view()->frameView()->delegatesScrolling())
1844 #endif
1845             shouldBlitOnFixedBackgroundImage = true;
1846 #endif
1847
1848         bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage();
1849         bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage();
1850         if (oldStyleSlowScroll != newStyleSlowScroll) {
1851             if (oldStyleSlowScroll)
1852                 view()->frameView()->removeSlowRepaintObject();
1853             if (newStyleSlowScroll)
1854                 view()->frameView()->addSlowRepaintObject();
1855         }
1856     }
1857 }
1858
1859 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderStyle* b)
1860 {
1861     ASSERT(a->cursors() != b->cursors());
1862     return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
1863 }
1864
1865 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
1866 {
1867     return a->cursor() == b->cursor() && (a->cursors() == b->cursors() || areNonIdenticalCursorListsEqual(a, b));
1868 }
1869
1870 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
1871 {
1872     if (s_affectsParentBlock)
1873         handleDynamicFloatPositionChange();
1874
1875     if (!m_parent)
1876         return;
1877     
1878     if (diff == StyleDifferenceLayout || diff == StyleDifferenceSimplifiedLayout) {
1879         RenderCounter::rendererStyleChanged(this, oldStyle, m_style.get());
1880
1881         // If the object already needs layout, then setNeedsLayout won't do
1882         // any work. But if the containing block has changed, then we may need
1883         // to mark the new containing blocks for layout. The change that can
1884         // directly affect the containing block of this object is a change to
1885         // the position style.
1886         if (needsLayout() && oldStyle->position() != m_style->position())
1887             markContainingBlocksForLayout();
1888
1889         if (diff == StyleDifferenceLayout)
1890             setNeedsLayoutAndPrefWidthsRecalc();
1891         else
1892             setNeedsSimplifiedNormalFlowLayout();
1893     } else if (diff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1894         setNeedsPositionedMovementLayout();
1895         setNeedsSimplifiedNormalFlowLayout();
1896     } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
1897         setNeedsPositionedMovementLayout();
1898
1899     // Don't check for repaint here; we need to wait until the layer has been
1900     // updated by subclasses before we know if we have to repaint (in setStyle()).
1901
1902     if (oldStyle && !areCursorsEqual(oldStyle, style())) {
1903         if (Frame* frame = this->frame())
1904             frame->eventHandler()->dispatchFakeMouseMoveEventSoon();
1905     }
1906 }
1907
1908 void RenderObject::propagateStyleToAnonymousChildren(bool blockChildrenOnly)
1909 {
1910     // FIXME: We could save this call when the change only affected non-inherited properties.
1911     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
1912         if (!child->isAnonymous() || child->style()->styleType() != NOPSEUDO)
1913             continue;
1914
1915         if (blockChildrenOnly && !child->isRenderBlock())
1916             continue;
1917
1918 #if ENABLE(FULLSCREEN_API)
1919         if (child->isRenderFullScreen() || child->isRenderFullScreenPlaceholder())
1920             continue;
1921 #endif
1922
1923         RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), child->style()->display());
1924         if (style()->specifiesColumns()) {
1925             if (child->style()->specifiesColumns())
1926                 newStyle->inheritColumnPropertiesFrom(style());
1927             if (child->style()->columnSpan())
1928                 newStyle->setColumnSpan(ColumnSpanAll);
1929         }
1930
1931         // Preserve the position style of anonymous block continuations as they can have relative position when
1932         // they contain block descendants of relative positioned inlines.
1933         if (child->isRelPositioned() && toRenderBlock(child)->isAnonymousBlockContinuation())
1934             newStyle->setPosition(child->style()->position());
1935
1936         child->setStyle(newStyle.release());
1937     }
1938 }
1939
1940 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
1941 {
1942     // Optimize the common case
1943     if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
1944         return;
1945     
1946     // Go through the new layers and addClients first, to avoid removing all clients of an image.
1947     for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
1948         if (currNew->image())
1949             currNew->image()->addClient(this);
1950     }
1951
1952     for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
1953         if (currOld->image())
1954             currOld->image()->removeClient(this);
1955     }
1956 }
1957
1958 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
1959 {
1960     if (oldImage != newImage) {
1961         if (oldImage)
1962             oldImage->removeClient(this);
1963         if (newImage)
1964             newImage->addClient(this);
1965     }
1966 }
1967
1968 LayoutRect RenderObject::viewRect() const
1969 {
1970     return view()->viewRect();
1971 }
1972
1973 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, bool fixed, bool useTransforms) const
1974 {
1975     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
1976     mapLocalToContainer(0, fixed, useTransforms, transformState);
1977     transformState.flatten();
1978     
1979     return transformState.lastPlanarPoint();
1980 }
1981
1982 FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, bool fixed, bool useTransforms) const
1983 {
1984     TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
1985     mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
1986     transformState.flatten();
1987     
1988     return transformState.lastPlanarPoint();
1989 }
1990
1991 void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState, ApplyContainerFlipOrNot, bool* wasFixed) const
1992 {
1993     if (repaintContainer == this)
1994         return;
1995
1996     RenderObject* o = parent();
1997     if (!o)
1998         return;
1999
2000     // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2001     LayoutPoint centerPoint = roundedLayoutPoint(transformState.mappedPoint());
2002     if (o->isBox() && o->style()->isFlippedBlocksWritingMode())
2003         transformState.move(toRenderBox(o)->flipForWritingModeIncludingColumns(roundedLayoutPoint(transformState.mappedPoint())) - centerPoint);
2004
2005     LayoutSize columnOffset;
2006     o->adjustForColumns(columnOffset, roundedLayoutPoint(transformState.mappedPoint()));
2007     if (!columnOffset.isZero())
2008         transformState.move(columnOffset);
2009
2010     if (o->hasOverflowClip())
2011         transformState.move(-toRenderBox(o)->scrolledContentOffset());
2012
2013     o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState, DoNotApplyContainerFlip, wasFixed);
2014 }
2015
2016 const RenderObject* RenderObject::pushMappingToContainer(const RenderBoxModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
2017 {
2018     ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this);
2019
2020     RenderObject* container = parent();
2021     if (!container)
2022         return 0;
2023
2024     // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2025     LayoutSize offset;
2026     if (container->hasOverflowClip())
2027         offset = -toRenderBox(container)->scrolledContentOffset();
2028
2029     geometryMap.push(this, offset, hasColumns());
2030     
2031     return container;
2032 }
2033
2034 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
2035 {
2036     RenderObject* o = parent();
2037     if (o) {
2038         o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2039         if (o->hasOverflowClip())
2040             transformState.move(toRenderBox(o)->scrolledContentOffset());
2041     }
2042 }
2043
2044 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
2045 {
2046 #if ENABLE(3D_RENDERING)
2047     // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
2048     // so check the layer's transform directly.
2049     return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
2050 #else
2051     UNUSED_PARAM(containerObject);
2052     return hasTransform();
2053 #endif
2054 }
2055
2056 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const
2057 {
2058     transform.makeIdentity();
2059     transform.translate(offsetInContainer.width(), offsetInContainer.height());
2060     RenderLayer* layer;
2061     if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform())
2062         transform.multiply(layer->currentTransform());
2063     
2064 #if ENABLE(3D_RENDERING)
2065     if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
2066         // Perpsective on the container affects us, so we have to factor it in here.
2067         ASSERT(containerObject->hasLayer());
2068         FloatPoint perspectiveOrigin = toRenderBoxModelObject(containerObject)->layer()->perspectiveOrigin();
2069
2070         TransformationMatrix perspectiveMatrix;
2071         perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
2072         
2073         transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
2074         transform = perspectiveMatrix * transform;
2075         transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
2076     }
2077 #else
2078     UNUSED_PARAM(containerObject);
2079 #endif
2080 }
2081
2082 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2083 {
2084     // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(),
2085     // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks.
2086     TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad);
2087     mapLocalToContainer(repaintContainer, fixed, true, transformState, ApplyContainerFlip, wasFixed);
2088     transformState.flatten();
2089     
2090     return transformState.lastPlanarQuad();
2091 }
2092
2093 FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2094 {
2095     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2096     mapLocalToContainer(repaintContainer, fixed, true, transformState, ApplyContainerFlip, wasFixed);
2097     transformState.flatten();
2098
2099     return transformState.lastPlanarPoint();
2100 }
2101
2102 LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
2103 {
2104     ASSERT(o == container());
2105
2106     LayoutSize offset;
2107
2108     o->adjustForColumns(offset, point);
2109
2110     if (o->hasOverflowClip())
2111         offset -= toRenderBox(o)->scrolledContentOffset();
2112
2113     if (offsetDependsOnPoint)
2114         *offsetDependsOnPoint = hasColumns();
2115
2116     return offset;
2117 }
2118
2119 LayoutSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
2120 {
2121     LayoutSize offset;
2122     LayoutPoint referencePoint;
2123     const RenderObject* currContainer = this;
2124     do {
2125         RenderObject* nextContainer = currContainer->container();
2126         ASSERT(nextContainer);  // This means we reached the top without finding container.
2127         if (!nextContainer)
2128             break;
2129         ASSERT(!currContainer->hasTransform());
2130         LayoutSize currentOffset = currContainer->offsetFromContainer(nextContainer, referencePoint);
2131         offset += currentOffset;
2132         referencePoint.move(currentOffset);
2133         currContainer = nextContainer;
2134     } while (currContainer != container);
2135
2136     return offset;
2137 }
2138
2139 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
2140 {
2141     if (extraWidthToEndOfLine)
2142         *extraWidthToEndOfLine = 0;
2143
2144     return LayoutRect();
2145 }
2146
2147 bool RenderObject::isRooted(RenderView** view)
2148 {
2149     RenderObject* o = this;
2150     while (o->parent())
2151         o = o->parent();
2152
2153     if (!o->isRenderView())
2154         return false;
2155
2156     if (view)
2157         *view = toRenderView(o);
2158
2159     return true;
2160 }
2161
2162 RenderObject* RenderObject::rendererForRootBackground()
2163 {
2164     ASSERT(isRoot());
2165     if (!hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) {
2166         // Locate the <body> element using the DOM. This is easier than trying
2167         // to crawl around a render tree with potential :before/:after content and
2168         // anonymous blocks created by inline <body> tags etc. We can locate the <body>
2169         // render object very easily via the DOM.
2170         HTMLElement* body = document()->body();
2171         RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
2172         if (bodyObject)
2173             return bodyObject;
2174     }
2175     
2176     return this;
2177 }
2178
2179 RespectImageOrientationEnum RenderObject::shouldRespectImageOrientation() const
2180 {
2181     // Respect the image's orientation if it's being used as a full-page image or it's
2182     // an <img> and the setting to respect it everywhere is set.
2183     return document()->isImageDocument() || (document()->settings() && document()->settings()->shouldRespectImageOrientation() && node() && (node()->hasTagName(HTMLNames::imgTag) || node()->hasTagName(HTMLNames::webkitInnerImageTag))) ? RespectImageOrientation : DoNotRespectImageOrientation;
2184 }
2185
2186 bool RenderObject::hasOutlineAnnotation() const
2187 {
2188     return node() && node()->isLink() && document()->printing();
2189 }
2190
2191 RenderObject* RenderObject::container(const RenderBoxModelObject* repaintContainer, bool* repaintContainerSkipped) const
2192 {
2193     if (repaintContainerSkipped)
2194         *repaintContainerSkipped = false;
2195
2196     // This method is extremely similar to containingBlock(), but with a few notable
2197     // exceptions.
2198     // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2199     // the object is not part of the primary document subtree yet.
2200     // (2) For normal flow elements, it just returns the parent.
2201     // (3) For absolute positioned elements, it will return a relative positioned inline.
2202     // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2203     // the layout of the positioned object.  This does mean that computePositionedLogicalWidth and
2204     // computePositionedLogicalHeight have to use container().
2205     RenderObject* o = parent();
2206
2207     if (isText())
2208         return o;
2209
2210     EPosition pos = m_style->position();
2211     if (pos == FixedPosition) {
2212         // container() can be called on an object that is not in the
2213         // tree yet.  We don't call view() since it will assert if it
2214         // can't get back to the canvas.  Instead we just walk as high up
2215         // as we can.  If we're in the tree, we'll get the root.  If we
2216         // aren't we'll get the root of our little subtree (most likely
2217         // we'll just return 0).
2218         // FIXME: The definition of view() has changed to not crawl up the render tree.  It might
2219         // be safe now to use it.
2220         while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) {
2221 #if ENABLE(SVG)
2222             // foreignObject is the containing block for its contents.
2223             if (o->isSVGForeignObject())
2224                 break;
2225 #endif
2226             // The render flow thread is the top most containing block
2227             // for the fixed positioned elements.
2228             if (o->isRenderFlowThread())
2229                 break;
2230
2231             if (repaintContainerSkipped && o == repaintContainer)
2232                 *repaintContainerSkipped = true;
2233
2234             o = o->parent();
2235         }
2236     } else if (pos == AbsolutePosition) {
2237         // Same goes here.  We technically just want our containing block, but
2238         // we may not have one if we're part of an uninstalled subtree.  We'll
2239         // climb as high as we can though.
2240         while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
2241 #if ENABLE(SVG)
2242             if (o->isSVGForeignObject()) // foreignObject is the containing block for contents inside it
2243                 break;
2244 #endif
2245             if (repaintContainerSkipped && o == repaintContainer)
2246                 *repaintContainerSkipped = true;
2247
2248             o = o->parent();
2249         }
2250     }
2251
2252     return o;
2253 }
2254
2255 bool RenderObject::isSelectionBorder() const
2256 {
2257     SelectionState st = selectionState();
2258     return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2259 }
2260
2261 inline void RenderObject::clearLayoutRootIfNeeded() const
2262 {
2263     if (!documentBeingDestroyed() && frame()) {
2264         if (FrameView* view = frame()->view()) {
2265             if (view->layoutRoot() == this) {
2266                 ASSERT_NOT_REACHED();
2267                 // This indicates a failure to layout the child, which is why
2268                 // the layout root is still set to |this|. Make sure to clear it
2269                 // since we are getting destroyed.
2270                 view->clearLayoutRoot();
2271             }
2272         }
2273     }
2274 }
2275
2276 void RenderObject::willBeDestroyed()
2277 {
2278     // Destroy any leftover anonymous children.
2279     RenderObjectChildList* children = virtualChildren();
2280     if (children)
2281         children->destroyLeftoverChildren();
2282
2283     // If this renderer is being autoscrolled, stop the autoscroll timer
2284     
2285     // FIXME: RenderObject::destroy should not get called with a renderer whose document
2286     // has a null frame, so we assert this. However, we don't want release builds to crash which is why we
2287     // check that the frame is not null.
2288     ASSERT(frame());
2289     if (frame() && frame()->eventHandler()->autoscrollRenderer() == this)
2290         frame()->eventHandler()->stopAutoscrollTimer(true);
2291
2292     if (AXObjectCache::accessibilityEnabled()) {
2293         document()->axObjectCache()->childrenChanged(this->parent());
2294         document()->axObjectCache()->remove(this);
2295     }
2296     animation()->cancelAnimations(this);
2297
2298     remove();
2299
2300 #ifndef NDEBUG
2301     if (!documentBeingDestroyed() && view() && view()->hasRenderNamedFlowThreads()) {
2302         // After remove, the object and the associated information should not be in any flow thread.
2303         const RenderNamedFlowThreadList* flowThreadList = view()->flowThreadController()->renderNamedFlowThreadList();
2304         for (RenderNamedFlowThreadList::const_iterator iter = flowThreadList->begin(); iter != flowThreadList->end(); ++iter) {
2305             const RenderNamedFlowThread* renderFlowThread = *iter;
2306             ASSERT(!renderFlowThread->hasChild(this));
2307             ASSERT(!renderFlowThread->hasChildInfo(this));
2308         }
2309     }
2310 #endif
2311
2312     // If this renderer had a parent, remove should have destroyed any counters
2313     // attached to this renderer and marked the affected other counters for
2314     // reevaluation. This apparently redundant check is here for the case when
2315     // this renderer had no parent at the time remove() was called.
2316
2317     if (hasCounterNodeMap())
2318         RenderCounter::destroyCounterNodes(this);
2319
2320     // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
2321     // be moved into RenderBoxModelObject::destroy.
2322     if (hasLayer()) {
2323         setHasLayer(false);
2324         toRenderBoxModelObject(this)->destroyLayer();
2325     }
2326
2327     setAncestorLineBoxDirty(false);
2328
2329     clearLayoutRootIfNeeded();
2330 }
2331
2332 void RenderObject::destroyAndCleanupAnonymousWrappers()
2333 {
2334     RenderObject* parent = this->parent();
2335
2336     // If the tree is destroyed or our parent is not anonymous, there is no need for a clean-up phase.
2337     if (documentBeingDestroyed() || !parent || !parent->isAnonymous()) {
2338         destroy();
2339         return;
2340     }
2341
2342     bool parentIsLeftOverAnonymousWrapper = false;
2343
2344     // Currently we only remove anonymous cells' wrapper but we should remove all unneeded
2345     // wrappers. See http://webkit.org/b/52123 as an example where this is needed.
2346     if (parent->isTableCell())
2347         parentIsLeftOverAnonymousWrapper = parent->firstChild() == this && parent->lastChild() == this;
2348
2349     destroy();
2350
2351     // WARNING: |this| is deleted here.
2352
2353     if (parentIsLeftOverAnonymousWrapper) {
2354         ASSERT(!parent->firstChild());
2355         parent->destroyAndCleanupAnonymousWrappers();
2356     }
2357 }
2358
2359 void RenderObject::destroy()
2360 {
2361     willBeDestroyed();
2362     arenaDelete(renderArena(), this);
2363 }
2364
2365 void RenderObject::arenaDelete(RenderArena* arena, void* base)
2366 {
2367     if (m_style) {
2368         for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2369             if (StyleImage* backgroundImage = bgLayer->image())
2370                 backgroundImage->removeClient(this);
2371         }
2372
2373         for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
2374             if (StyleImage* maskImage = maskLayer->image())
2375                 maskImage->removeClient(this);
2376         }
2377
2378         if (StyleImage* borderImage = m_style->borderImage().image())
2379             borderImage->removeClient(this);
2380
2381         if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
2382             maskBoxImage->removeClient(this);
2383     }
2384
2385 #ifndef NDEBUG
2386     void* savedBase = baseOfRenderObjectBeingDeleted;
2387     baseOfRenderObjectBeingDeleted = base;
2388 #endif
2389     delete this;
2390 #ifndef NDEBUG
2391     baseOfRenderObjectBeingDeleted = savedBase;
2392 #endif
2393
2394     // Recover the size left there for us by operator delete and free the memory.
2395     arena->free(*(size_t*)base, base);
2396 }
2397
2398 VisiblePosition RenderObject::positionForPoint(const LayoutPoint&)
2399 {
2400     return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
2401 }
2402
2403 void RenderObject::updateDragState(bool dragOn)
2404 {
2405     bool valueChanged = (dragOn != isDragging());
2406     setIsDragging(dragOn);
2407     if (valueChanged && style()->affectedByDragRules() && node())
2408         node()->setNeedsStyleRecalc();
2409     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2410         curr->updateDragState(dragOn);
2411 }
2412
2413 bool RenderObject::isComposited() const
2414 {
2415     return hasLayer() && toRenderBoxModelObject(this)->layer()->isComposited();
2416 }
2417
2418 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter)
2419 {
2420     bool inside = false;
2421     if (hitTestFilter != HitTestSelf) {
2422         // First test the foreground layer (lines and inlines).
2423         inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestForeground);
2424
2425         // Test floats next.
2426         if (!inside)
2427             inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestFloat);
2428
2429         // Finally test to see if the mouse is in the background (within a child block's background).
2430         if (!inside)
2431             inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestChildBlockBackgrounds);
2432     }
2433
2434     // See if the mouse is inside us but not any of our descendants
2435     if (hitTestFilter != HitTestDescendants && !inside)
2436         inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestBlockBackground);
2437
2438     return inside;
2439 }
2440
2441 void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
2442 {
2443     if (result.innerNode())
2444         return;
2445
2446     Node* n = node();
2447     if (n) {
2448         result.setInnerNode(n);
2449         if (!result.innerNonSharedNode())
2450             result.setInnerNonSharedNode(n);
2451         result.setLocalPoint(point);
2452     }
2453 }
2454
2455 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& /*pointInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction)
2456 {
2457     return false;
2458 }
2459
2460 void RenderObject::scheduleRelayout()
2461 {
2462     if (isRenderView()) {
2463         FrameView* view = toRenderView(this)->frameView();
2464         if (view)
2465             view->scheduleRelayout();
2466     } else {
2467         if (isRooted()) {
2468             if (RenderView* renderView = view()) {
2469                 if (FrameView* frameView = renderView->frameView())
2470                     frameView->scheduleRelayoutOfSubtree(this);
2471             }
2472         }
2473     }
2474 }
2475
2476 void RenderObject::layout()
2477 {
2478     ASSERT(needsLayout());
2479     RenderObject* child = firstChild();
2480     while (child) {
2481         child->layoutIfNeeded();
2482         ASSERT(!child->needsLayout());
2483         child = child->nextSibling();
2484     }
2485     setNeedsLayout(false);
2486 }
2487
2488 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
2489 {
2490     if (!document()->usesFirstLineRules())
2491         return 0;
2492
2493     ASSERT(!isText());
2494
2495     RefPtr<RenderStyle> result;
2496
2497     if (isBlockFlow()) {
2498         if (RenderBlock* firstLineBlock = this->firstLineBlock())
2499             result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0);
2500     } else if (!isAnonymous() && isRenderInline()) {
2501         RenderStyle* parentStyle = parent()->firstLineStyle();
2502         if (parentStyle != parent()->style())
2503             result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
2504     }
2505
2506     return result.release();
2507 }
2508
2509 RenderStyle* RenderObject::firstLineStyleSlowCase() const
2510 {
2511     ASSERT(document()->usesFirstLineRules());
2512
2513     RenderStyle* style = m_style.get();
2514     const RenderObject* renderer = isText() ? parent() : this;
2515     if (renderer->isBlockFlow()) {
2516         if (RenderBlock* firstLineBlock = renderer->firstLineBlock())
2517             style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2518     } else if (!renderer->isAnonymous() && renderer->isRenderInline()) {
2519         RenderStyle* parentStyle = renderer->parent()->firstLineStyle();
2520         if (parentStyle != renderer->parent()->style()) {
2521             // A first-line style is in effect. Cache a first-line style for ourselves.
2522             renderer->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
2523             style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2524         }
2525     }
2526
2527     return style;
2528 }
2529
2530 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2531 {
2532     if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2533         return 0;
2534
2535     RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2536     if (cachedStyle)
2537         return cachedStyle;
2538     
2539     RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
2540     if (result)
2541         return style()->addCachedPseudoStyle(result.release());
2542     return 0;
2543 }
2544
2545 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2546 {
2547     if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
2548         return 0;
2549     
2550     if (!parentStyle) {
2551         ASSERT(!ownStyle);
2552         parentStyle = style();
2553     }
2554
2555     // FIXME: This "find nearest element parent" should be a helper function.
2556     Node* n = node();
2557     while (n && !n->isElementNode())
2558         n = n->parentNode();
2559     if (!n)
2560         return 0;
2561     Element* element = toElement(n);
2562
2563     if (pseudo == FIRST_LINE_INHERITED) {
2564         RefPtr<RenderStyle> result = document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
2565         result->setStyleType(FIRST_LINE_INHERITED);
2566         return result.release();
2567     }
2568     return document()->styleResolver()->pseudoStyleForElement(pseudo, element, parentStyle);
2569 }
2570
2571 static Color decorationColor(RenderStyle* style)
2572 {
2573     Color result;
2574     if (style->textStrokeWidth() > 0) {
2575         // Prefer stroke color if possible but not if it's fully transparent.
2576         result = style->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
2577         if (result.alpha())
2578             return result;
2579     }
2580     
2581     result = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
2582     return result;
2583 }
2584
2585 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2586                                            Color& linethrough, bool quirksMode, bool firstlineStyle)
2587 {
2588     RenderObject* curr = this;
2589     RenderStyle* styleToUse = 0;
2590     do {
2591         styleToUse = curr->style(firstlineStyle);
2592         int currDecs = styleToUse->textDecoration();
2593         if (currDecs) {
2594             if (currDecs & UNDERLINE) {
2595                 decorations &= ~UNDERLINE;
2596                 underline = decorationColor(styleToUse);
2597             }
2598             if (currDecs & OVERLINE) {
2599                 decorations &= ~OVERLINE;
2600                 overline = decorationColor(styleToUse);
2601             }
2602             if (currDecs & LINE_THROUGH) {
2603                 decorations &= ~LINE_THROUGH;
2604                 linethrough = decorationColor(styleToUse);
2605             }
2606         }
2607         if (curr->isRubyText())
2608             return;
2609         curr = curr->parent();
2610         if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
2611             curr = toRenderBlock(curr)->continuation();
2612     } while (curr && decorations && (!quirksMode || !curr->node() ||
2613                                      (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2614
2615     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2616     if (decorations && curr) {
2617         styleToUse = curr->style(firstlineStyle);
2618         if (decorations & UNDERLINE)
2619             underline = decorationColor(styleToUse);
2620         if (decorations & OVERLINE)
2621             overline = decorationColor(styleToUse);
2622         if (decorations & LINE_THROUGH)
2623             linethrough = decorationColor(styleToUse);
2624     }
2625 }
2626
2627 #if ENABLE(DASHBOARD_SUPPORT)
2628 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2629 {
2630     // Convert the style regions to absolute coordinates.
2631     if (style()->visibility() != VISIBLE || !isBox())
2632         return;
2633     
2634     RenderBox* box = toRenderBox(this);
2635
2636     const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2637     unsigned i, count = styleRegions.size();
2638     for (i = 0; i < count; i++) {
2639         StyleDashboardRegion styleRegion = styleRegions[i];
2640
2641         LayoutUnit w = box->width();
2642         LayoutUnit h = box->height();
2643
2644         DashboardRegionValue region;
2645         region.label = styleRegion.label;
2646         region.bounds = LayoutRect(styleRegion.offset.left().value(),
2647                                    styleRegion.offset.top().value(),
2648                                    w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
2649                                    h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
2650         region.type = styleRegion.type;
2651
2652         region.clip = region.bounds;
2653         computeAbsoluteRepaintRect(region.clip);
2654         if (region.clip.height() < 0) {
2655             region.clip.setHeight(0);
2656             region.clip.setWidth(0);
2657         }
2658
2659         FloatPoint absPos = localToAbsolute();
2660         region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
2661         region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
2662
2663         regions.append(region);
2664     }
2665 }
2666
2667 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2668 {
2669     // RenderTexts don't have their own style, they just use their parent's style,
2670     // so we don't want to include them.
2671     if (isText())
2672         return;
2673
2674     addDashboardRegions(regions);
2675     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2676         curr->collectDashboardRegions(regions);
2677 }
2678 #endif
2679
2680 bool RenderObject::willRenderImage(CachedImage*)
2681 {
2682     // Without visibility we won't render (and therefore don't care about animation).
2683     if (style()->visibility() != VISIBLE)
2684         return false;
2685
2686     // We will not render a new image when Active DOM is suspended
2687     if (document()->activeDOMObjectsAreSuspended())
2688         return false;
2689
2690     // 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)
2691     // then we don't want to render either.
2692     if (document()->inPageCache() || document()->view()->isOffscreen())
2693         return false;
2694
2695     // If a renderer is outside the viewport, we won't render.
2696     return viewRect().intersects(absoluteClippedOverflowRect());
2697 }
2698
2699 int RenderObject::maximalOutlineSize(PaintPhase p) const
2700 {
2701     if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2702         return 0;
2703     return toRenderView(document()->renderer())->maximalOutlineSize();
2704 }
2705
2706 int RenderObject::caretMinOffset() const
2707 {
2708     return 0;
2709 }
2710
2711 int RenderObject::caretMaxOffset() const
2712 {
2713     if (isReplaced())
2714         return node() ? max(1U, node()->childNodeCount()) : 1;
2715     if (isHR())
2716         return 1;
2717     return 0;
2718 }
2719
2720 int RenderObject::previousOffset(int current) const
2721 {
2722     return current - 1;
2723 }
2724
2725 int RenderObject::previousOffsetForBackwardDeletion(int current) const
2726 {
2727     return current - 1;
2728 }
2729
2730 int RenderObject::nextOffset(int current) const
2731 {
2732     return current + 1;
2733 }
2734
2735 void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const
2736 {
2737     int outlineSize = outlineStyleForRepaint()->outlineSize();
2738     if (const ShadowData* boxShadow = style()->boxShadow()) {
2739         boxShadow->adjustRectForShadow(rect, outlineSize);
2740         return;
2741     }
2742
2743     rect.inflate(outlineSize);
2744 }
2745
2746 AnimationController* RenderObject::animation() const
2747 {
2748     return frame()->animation();
2749 }
2750
2751 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
2752 {
2753     imageChanged(static_cast<WrappedImagePtr>(image), rect);
2754 }
2755
2756 RenderBoxModelObject* RenderObject::offsetParent() const
2757 {
2758     // If any of the following holds true return null and stop this algorithm:
2759     // A is the root element.
2760     // A is the HTML body element.
2761     // The computed value of the position property for element A is fixed.
2762     if (isRoot() || isBody() || (isOutOfFlowPositioned() && style()->position() == FixedPosition))
2763         return 0;
2764
2765     // If A is an area HTML element which has a map HTML element somewhere in the ancestor
2766     // chain return the nearest ancestor map HTML element and stop this algorithm.
2767     // FIXME: Implement!
2768     
2769     // Return the nearest ancestor element of A for which at least one of the following is
2770     // true and stop this algorithm if such an ancestor is found:
2771     //     * The computed value of the position property is not static.
2772     //     * It is the HTML body element.
2773     //     * The computed value of the position property of A is static and the ancestor
2774     //       is one of the following HTML elements: td, th, or table.
2775     //     * Our own extension: if there is a difference in the effective zoom
2776
2777     bool skipTables = isOutOfFlowPositioned() || isRelPositioned();
2778     float currZoom = style()->effectiveZoom();
2779     RenderObject* curr = parent();
2780     while (curr && (!curr->node() || (!curr->isOutOfFlowPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
2781         Node* element = curr->node();
2782         if (!skipTables && element && (element->hasTagName(tableTag) || element->hasTagName(tdTag) || element->hasTagName(thTag)))
2783             break;
2784
2785         float newZoom = curr->style()->effectiveZoom();
2786         if (currZoom != newZoom)
2787             break;
2788         currZoom = newZoom;
2789         curr = curr->parent();
2790     }
2791     return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
2792 }
2793
2794 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
2795 {
2796     // If this is a non-anonymous renderer in an editable area, then it's simple.
2797     if (Node* node = this->node()) {
2798         if (!node->rendererIsEditable()) {
2799             // If it can be found, we prefer a visually equivalent position that is editable. 
2800             Position position = createLegacyEditingPosition(node, offset);
2801             Position candidate = position.downstream(CanCrossEditingBoundary);
2802             if (candidate.deprecatedNode()->rendererIsEditable())
2803                 return VisiblePosition(candidate, affinity);
2804             candidate = position.upstream(CanCrossEditingBoundary);
2805             if (candidate.deprecatedNode()->rendererIsEditable())
2806                 return VisiblePosition(candidate, affinity);
2807         }
2808         // FIXME: Eliminate legacy editing positions
2809         return VisiblePosition(createLegacyEditingPosition(node, offset), affinity);
2810     }
2811
2812     // We don't want to cross the boundary between editable and non-editable
2813     // regions of the document, but that is either impossible or at least
2814     // extremely unlikely in any normal case because we stop as soon as we
2815     // find a single non-anonymous renderer.
2816
2817     // Find a nearby non-anonymous renderer.
2818     RenderObject* child = this;
2819     while (RenderObject* parent = child->parent()) {
2820         // Find non-anonymous content after.
2821         RenderObject* renderer = child;
2822         while ((renderer = renderer->nextInPreOrder(parent))) {
2823             if (Node* node = renderer->node())
2824                 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2825         }
2826
2827         // Find non-anonymous content before.
2828         renderer = child;
2829         while ((renderer = renderer->previousInPreOrder())) {
2830             if (renderer == parent)
2831                 break;
2832             if (Node* node = renderer->node())
2833                 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
2834         }
2835
2836         // Use the parent itself unless it too is anonymous.
2837         if (Node* node = parent->node())
2838             return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2839
2840         // Repeat at the next level up.
2841         child = parent;
2842     }
2843
2844     // Everything was anonymous. Give up.
2845     return VisiblePosition();
2846 }
2847
2848 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
2849 {
2850     if (position.isNotNull())
2851         return VisiblePosition(position);
2852
2853     ASSERT(!node());
2854     return createVisiblePosition(0, DOWNSTREAM);
2855 }
2856
2857 CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
2858 {
2859     return SetCursorBasedOnStyle;
2860 }
2861
2862 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
2863 {
2864     if (needsLayout())
2865         return false;
2866
2867     RenderBlock* containingBlock = this->containingBlock();
2868     return containingBlock ? !containingBlock->needsLayout() : true;
2869 }
2870
2871 // We only create "generated" child renderers like one for first-letter if:
2872 // - the firstLetterBlock can have children in the DOM and
2873 // - the block doesn't have any special assumption on its text children.
2874 // This correctly prevents form controls from having such renderers.
2875 bool RenderObject::canHaveGeneratedChildren() const
2876 {
2877     return canHaveChildren();
2878 }
2879
2880 #if ENABLE(SVG)
2881
2882 RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
2883 {
2884     ASSERT_NOT_REACHED();
2885     return 0;
2886 }
2887
2888 void RenderObject::setNeedsBoundariesUpdate()
2889 {
2890     if (RenderObject* renderer = parent())
2891         renderer->setNeedsBoundariesUpdate();
2892 }
2893
2894 FloatRect RenderObject::objectBoundingBox() const
2895 {
2896     ASSERT_NOT_REACHED();
2897     return FloatRect();
2898 }
2899
2900 FloatRect RenderObject::strokeBoundingBox() const
2901 {
2902     ASSERT_NOT_REACHED();
2903     return FloatRect();
2904 }
2905
2906 // Returns the smallest rectangle enclosing all of the painted content
2907 // respecting clipping, masking, filters, opacity, stroke-width and markers
2908 FloatRect RenderObject::repaintRectInLocalCoordinates() const
2909 {
2910     ASSERT_NOT_REACHED();
2911     return FloatRect();
2912 }
2913
2914 AffineTransform RenderObject::localTransform() const
2915 {
2916     static const AffineTransform identity;
2917     return identity;
2918 }
2919
2920 const AffineTransform& RenderObject::localToParentTransform() const
2921 {
2922     static const AffineTransform identity;
2923     return identity;
2924 }
2925
2926 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
2927 {
2928     ASSERT_NOT_REACHED();
2929     return false;
2930 }
2931
2932 #endif // ENABLE(SVG)
2933
2934 } // namespace WebCore
2935
2936 #ifndef NDEBUG
2937
2938 void showTree(const WebCore::RenderObject* object)
2939 {
2940     if (object)
2941         object->showTreeForThis();
2942 }
2943
2944 void showLineTree(const WebCore::RenderObject* object)
2945 {
2946     if (object)
2947         object->showLineTreeForThis();
2948 }
2949
2950 void showRenderTree(const WebCore::RenderObject* object1)
2951 {
2952     showRenderTree(object1, 0);
2953 }
2954
2955 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
2956 {
2957     if (object1) {
2958         const WebCore::RenderObject* root = object1;
2959         while (root->parent())
2960             root = root->parent();
2961         root->showRenderTreeAndMark(object1, "*", object2, "-", 0);
2962     }
2963 }
2964
2965 #endif