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