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