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