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