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