33cbb0c4e0baf56f7a003f324055f1d0f00fe4ff
[WebKit-https.git] / 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 Apple Inc. All rights reserved.
7  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25
26 #include "config.h"
27 #include "RenderObject.h"
28
29 #include "AXObjectCache.h"
30 #include "CSSStyleSelector.h"
31 #include "FloatQuad.h"
32 #include "Frame.h"
33 #include "FrameView.h"
34 #include "GraphicsContext.h"
35 #include "HTMLNames.h"
36 #include "HitTestResult.h"
37 #include "Page.h"
38 #include "RenderArena.h"
39 #include "RenderCounter.h"
40 #include "RenderFlexibleBox.h"
41 #include "RenderImageGeneratedContent.h"
42 #include "RenderInline.h"
43 #include "RenderListItem.h"
44 #include "RenderTableCell.h"
45 #include "RenderTableCol.h"
46 #include "RenderTableRow.h"
47 #include "RenderTheme.h"
48 #include "RenderView.h"
49 #include "TransformState.h"
50 #include <algorithm>
51 #include <stdio.h>
52 #include <wtf/RefCountedLeakCounter.h>
53 #include <wtf/UnusedParam.h>
54
55 #if USE(ACCELERATED_COMPOSITING)
56 #include "RenderLayerCompositor.h"
57 #endif
58
59 #if ENABLE(WML)
60 #include "WMLNames.h"
61 #endif
62
63 using namespace std;
64
65 namespace WebCore {
66
67 using namespace HTMLNames;
68
69 #ifndef NDEBUG
70 static void* baseOfRenderObjectBeingDeleted;
71 #endif
72
73 bool RenderObject::s_affectsParentBlock = false;
74
75 void* RenderObject::operator new(size_t sz, RenderArena* renderArena) throw()
76 {
77     return renderArena->allocate(sz);
78 }
79
80 void RenderObject::operator delete(void* ptr, size_t sz)
81 {
82     ASSERT(baseOfRenderObjectBeingDeleted == ptr);
83
84     // Stash size where destroy can find it.
85     *(size_t *)ptr = sz;
86 }
87
88 RenderObject* RenderObject::createObject(Node* node, RenderStyle* style)
89 {
90     Document* doc = node->document();
91     RenderArena* arena = doc->renderArena();
92
93     // Minimal support for content properties replacing an entire element.
94     // Works only if we have exactly one piece of content and it's a URL.
95     // Otherwise acts as if we didn't support this feature.
96     const ContentData* contentData = style->contentData();
97     if (contentData && !contentData->next() && contentData->isImage() && doc != node) {
98         RenderImageGeneratedContent* image = new (arena) RenderImageGeneratedContent(node);
99         image->setStyle(style);
100         if (StyleImage* styleImage = contentData->image())
101             image->setStyleImage(styleImage);
102         return image;
103     }
104
105     RenderObject* o = 0;
106
107     switch (style->display()) {
108         case NONE:
109             break;
110         case INLINE:
111             o = new (arena) RenderInline(node);
112             break;
113         case BLOCK:
114             o = new (arena) RenderBlock(node);
115             break;
116         case INLINE_BLOCK:
117             o = new (arena) RenderBlock(node);
118             break;
119         case LIST_ITEM:
120             o = new (arena) RenderListItem(node);
121             break;
122         case RUN_IN:
123         case COMPACT:
124             o = new (arena) RenderBlock(node);
125             break;
126         case TABLE:
127         case INLINE_TABLE:
128             o = new (arena) RenderTable(node);
129             break;
130         case TABLE_ROW_GROUP:
131         case TABLE_HEADER_GROUP:
132         case TABLE_FOOTER_GROUP:
133             o = new (arena) RenderTableSection(node);
134             break;
135         case TABLE_ROW:
136             o = new (arena) RenderTableRow(node);
137             break;
138         case TABLE_COLUMN_GROUP:
139         case TABLE_COLUMN:
140             o = new (arena) RenderTableCol(node);
141             break;
142         case TABLE_CELL:
143             o = new (arena) RenderTableCell(node);
144             break;
145         case TABLE_CAPTION:
146 #if ENABLE(WCSS)
147         // As per the section 17.1 of the spec WAP-239-WCSS-20011026-a.pdf, 
148         // the marquee box inherits and extends the characteristics of the 
149         // principal block box ([CSS2] section 9.2.1).
150         case WAP_MARQUEE:
151 #endif
152             o = new (arena) RenderBlock(node);
153             break;
154         case BOX:
155         case INLINE_BOX:
156             o = new (arena) RenderFlexibleBox(node);
157             break;
158     }
159
160     return o;
161 }
162
163 #ifndef NDEBUG 
164 static WTF::RefCountedLeakCounter renderObjectCounter("RenderObject");
165 #endif
166
167 RenderObject::RenderObject(Node* node)
168     : CachedResourceClient()
169     , m_style(0)
170     , m_node(node)
171     , m_parent(0)
172     , m_previous(0)
173     , m_next(0)
174 #ifndef NDEBUG
175     , m_hasAXObject(false)
176     , m_setNeedsLayoutForbidden(false)
177 #endif
178     , m_needsLayout(false)
179     , m_needsPositionedMovementLayout(false)
180     , m_normalChildNeedsLayout(false)
181     , m_posChildNeedsLayout(false)
182     , m_prefWidthsDirty(false)
183     , m_floating(false)
184     , m_positioned(false)
185     , m_relPositioned(false)
186     , m_paintBackground(false)
187     , m_isAnonymous(node == node->document())
188     , m_isText(false)
189     , m_isBox(false)
190     , m_inline(true)
191     , m_replaced(false)
192     , m_isDragging(false)
193     , m_hasLayer(false)
194     , m_hasOverflowClip(false)
195     , m_hasTransform(false)
196     , m_hasReflection(false)
197     , m_hasOverrideSize(false)
198     , m_hasCounterNodeMap(false)
199     , m_everHadLayout(false)
200     , m_childrenInline(false)
201     , m_topMarginQuirk(false) 
202     , m_bottomMarginQuirk(false)
203     , m_hasMarkupTruncation(false)
204     , m_selectionState(SelectionNone)
205     , m_hasColumns(false)
206     , m_cellWidthChanged(false)
207     , m_replacedHasOverflow(false)
208 {
209 #ifndef NDEBUG
210     renderObjectCounter.increment();
211 #endif
212     ASSERT(node);
213 }
214
215 RenderObject::~RenderObject()
216 {
217     ASSERT(!node() || documentBeingDestroyed() || !document()->frame()->view() || document()->frame()->view()->layoutRoot() != this);
218 #ifndef NDEBUG
219     ASSERT(!m_hasAXObject);
220     renderObjectCounter.decrement();
221 #endif
222 }
223
224 RenderTheme* RenderObject::theme() const
225 {
226     ASSERT(document()->page());
227
228     return document()->page()->theme();
229 }
230
231 bool RenderObject::isDescendantOf(const RenderObject* obj) const
232 {
233     for (const RenderObject* r = this; r; r = r->m_parent) {
234         if (r == obj)
235             return true;
236     }
237     return false;
238 }
239
240 bool RenderObject::isBody() const
241 {
242     return node() && node()->hasTagName(bodyTag);
243 }
244
245 bool RenderObject::isHR() const
246 {
247     return node() && node()->hasTagName(hrTag);
248 }
249
250 bool RenderObject::isHTMLMarquee() const
251 {
252     return node() && node()->renderer() == this && node()->hasTagName(marqueeTag);
253 }
254
255 static void updateListMarkerNumbers(RenderObject* child)
256 {
257     for (RenderObject* sibling = child; sibling; sibling = sibling->nextSibling()) {
258         if (sibling->isListItem())
259             toRenderListItem(sibling)->updateValue();
260     }
261 }
262
263 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
264 {
265     RenderObjectChildList* children = virtualChildren();
266     ASSERT(children);
267     if (!children)
268         return;
269
270     bool needsTable = false;
271
272     if (newChild->isListItem())
273         updateListMarkerNumbers(beforeChild ? beforeChild : children->lastChild());
274     else if (newChild->isTableCol() && newChild->style()->display() == TABLE_COLUMN_GROUP)
275         needsTable = !isTable();
276     else if (newChild->isRenderBlock() && newChild->style()->display() == TABLE_CAPTION)
277         needsTable = !isTable();
278     else if (newChild->isTableSection())
279         needsTable = !isTable();
280     else if (newChild->isTableRow())
281         needsTable = !isTableSection();
282     else if (newChild->isTableCell()) {
283         needsTable = !isTableRow();
284         // I'm not 100% sure this is the best way to fix this, but without this
285         // change we recurse infinitely when trying to render the CSS2 test page:
286         // http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/htmlbodyheadrendering2.html.
287         // See Radar 2925291.
288         if (needsTable && isTableCell() && !children->firstChild() && !newChild->isTableCell())
289             needsTable = false;
290     }
291
292     if (needsTable) {
293         RenderTable* table;
294         RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
295         if (afterChild && afterChild->isAnonymous() && afterChild->isTable())
296             table = toRenderTable(afterChild);
297         else {
298             table = new (renderArena()) RenderTable(document() /* is anonymous */);
299             RefPtr<RenderStyle> newStyle = RenderStyle::create();
300             newStyle->inheritFrom(style());
301             newStyle->setDisplay(TABLE);
302             table->setStyle(newStyle.release());
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         RefPtr<StringImpl> textToTransform = toRenderText(newChild)->originalText();
313         if (textToTransform)
314             toRenderText(newChild)->setText(textToTransform.release(), true);
315     }
316 }
317
318 void RenderObject::removeChild(RenderObject* oldChild)
319 {
320     RenderObjectChildList* children = virtualChildren();
321     ASSERT(children);
322     if (!children)
323         return;
324
325     // We do this here instead of in removeChildNode, since the only extremely low-level uses of remove/appendChildNode
326     // cannot affect the positioned object list, and the floating object list is irrelevant (since the list gets cleared on
327     // layout anyway).
328     if (oldChild->isFloatingOrPositioned())
329         toRenderBox(oldChild)->removeFloatingOrPositionedChildFromBlockLists();
330         
331     children->removeChildNode(this, oldChild);
332 }
333
334 RenderObject* RenderObject::nextInPreOrder() const
335 {
336     if (RenderObject* o = firstChild())
337         return o;
338
339     return nextInPreOrderAfterChildren();
340 }
341
342 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
343 {
344     RenderObject* o;
345     if (!(o = nextSibling())) {
346         o = parent();
347         while (o && !o->nextSibling())
348             o = o->parent();
349         if (o)
350             o = o->nextSibling();
351     }
352
353     return o;
354 }
355
356 RenderObject* RenderObject::nextInPreOrder(RenderObject* stayWithin) const
357 {
358     if (RenderObject* o = firstChild())
359         return o;
360
361     return nextInPreOrderAfterChildren(stayWithin);
362 }
363
364 RenderObject* RenderObject::nextInPreOrderAfterChildren(RenderObject* stayWithin) const
365 {
366     if (this == stayWithin)
367         return 0;
368
369     RenderObject* o;
370     if (!(o = nextSibling())) {
371         o = parent();
372         while (o && !o->nextSibling()) {
373             if (o == stayWithin)
374                 return 0;
375             o = o->parent();
376         }
377         if (o)
378             o = o->nextSibling();
379     }
380
381     return o;
382 }
383
384 RenderObject* RenderObject::previousInPreOrder() const
385 {
386     if (RenderObject* o = previousSibling()) {
387         while (o->lastChild())
388             o = o->lastChild();
389         return o;
390     }
391
392     return parent();
393 }
394
395 RenderObject* RenderObject::childAt(unsigned index) const
396 {
397     RenderObject* child = firstChild();
398     for (unsigned i = 0; child && i < index; i++)
399         child = child->nextSibling();
400     return child;
401 }
402
403 RenderObject* RenderObject::firstLeafChild() const
404 {
405     RenderObject* r = firstChild();
406     while (r) {
407         RenderObject* n = 0;
408         n = r->firstChild();
409         if (!n)
410             break;
411         r = n;
412     }
413     return r;
414 }
415
416 RenderObject* RenderObject::lastLeafChild() const
417 {
418     RenderObject* r = lastChild();
419     while (r) {
420         RenderObject* n = 0;
421         n = r->lastChild();
422         if (!n)
423             break;
424         r = n;
425     }
426     return r;
427 }
428
429 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
430                       RenderLayer*& beforeChild)
431 {
432     if (obj->hasLayer()) {
433         if (!beforeChild && newObject) {
434             // We need to figure out the layer that follows newObject.  We only do
435             // this the first time we find a child layer, and then we update the
436             // pointer values for newObject and beforeChild used by everyone else.
437             beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
438             newObject = 0;
439         }
440         parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild);
441         return;
442     }
443
444     for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
445         addLayers(curr, parentLayer, newObject, beforeChild);
446 }
447
448 void RenderObject::addLayers(RenderLayer* parentLayer, RenderObject* newObject)
449 {
450     if (!parentLayer)
451         return;
452
453     RenderObject* object = newObject;
454     RenderLayer* beforeChild = 0;
455     WebCore::addLayers(this, parentLayer, object, beforeChild);
456 }
457
458 void RenderObject::removeLayers(RenderLayer* parentLayer)
459 {
460     if (!parentLayer)
461         return;
462
463     if (hasLayer()) {
464         parentLayer->removeChild(toRenderBoxModelObject(this)->layer());
465         return;
466     }
467
468     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
469         curr->removeLayers(parentLayer);
470 }
471
472 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
473 {
474     if (!newParent)
475         return;
476
477     if (hasLayer()) {
478         RenderLayer* layer = toRenderBoxModelObject(this)->layer();
479         ASSERT(oldParent == layer->parent());
480         if (oldParent)
481             oldParent->removeChild(layer);
482         newParent->addChild(layer);
483         return;
484     }
485
486     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
487         curr->moveLayers(oldParent, newParent);
488 }
489
490 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
491                                          bool checkParent)
492 {
493     // Error check the parent layer passed in.  If it's null, we can't find anything.
494     if (!parentLayer)
495         return 0;
496
497     // Step 1: If our layer is a child of the desired parent, then return our layer.
498     RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0;
499     if (ourLayer && ourLayer->parent() == parentLayer)
500         return ourLayer;
501
502     // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
503     // into our siblings trying to find the next layer whose parent is the desired parent.
504     if (!ourLayer || ourLayer == parentLayer) {
505         for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
506              curr; curr = curr->nextSibling()) {
507             RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
508             if (nextLayer)
509                 return nextLayer;
510         }
511     }
512
513     // Step 3: If our layer is the desired parent layer, then we're finished.  We didn't
514     // find anything.
515     if (parentLayer == ourLayer)
516         return 0;
517
518     // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
519     // follow us to see if we can locate a layer.
520     if (checkParent && parent())
521         return parent()->findNextLayer(parentLayer, this, true);
522
523     return 0;
524 }
525
526 RenderLayer* RenderObject::enclosingLayer() const
527 {
528     const RenderObject* curr = this;
529     while (curr) {
530         RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
531         if (layer)
532             return layer;
533         curr = curr->parent();
534     }
535     return 0;
536 }
537
538 RenderLayer* RenderObject::enclosingSelfPaintingLayer() const
539 {
540     const RenderObject* curr = this;
541     while (curr) {
542         RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
543         if (layer && layer->isSelfPaintingLayer())
544             return layer;
545         curr = curr->parent();
546     }
547     return 0;
548 }
549
550 RenderBox* RenderObject::enclosingBox() const
551 {
552     RenderObject* curr = const_cast<RenderObject*>(this);
553     while (curr) {
554         if (curr->isBox())
555             return toRenderBox(curr);
556         curr = curr->parent();
557     }
558     
559     ASSERT_NOT_REACHED();
560     return 0;
561 }
562
563 RenderBlock* RenderObject::firstLineBlock() const
564 {
565     return 0;
566 }
567
568 void RenderObject::setPrefWidthsDirty(bool b, bool markParents)
569 {
570     bool alreadyDirty = m_prefWidthsDirty;
571     m_prefWidthsDirty = b;
572     if (b && !alreadyDirty && markParents && (isText() || (style()->position() != FixedPosition && style()->position() != AbsolutePosition)))
573         invalidateContainerPrefWidths();
574 }
575
576 void RenderObject::invalidateContainerPrefWidths()
577 {
578     // In order to avoid pathological behavior when inlines are deeply nested, we do include them
579     // in the chain that we mark dirty (even though they're kind of irrelevant).
580     RenderObject* o = isTableCell() ? containingBlock() : container();
581     while (o && !o->m_prefWidthsDirty) {
582         // Don't invalidate the outermost object of an unrooted subtree. That object will be 
583         // invalidated when the subtree is added to the document.
584         RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
585         if (!container && !o->isRenderView())
586             break;
587
588         o->m_prefWidthsDirty = true;
589         if (o->style()->position() == FixedPosition || o->style()->position() == AbsolutePosition)
590             // A positioned object has no effect on the min/max width of its containing block ever.
591             // We can optimize this case and not go up any further.
592             break;
593         o = container;
594     }
595 }
596
597 void RenderObject::setLayerNeedsFullRepaint()
598 {
599     ASSERT(hasLayer());
600     toRenderBoxModelObject(this)->layer()->setNeedsFullRepaint(true);
601 }
602
603 RenderBlock* RenderObject::containingBlock() const
604 {
605     if (isTableCell()) {
606         const RenderTableCell* cell = toRenderTableCell(this);
607         if (parent() && cell->section())
608             return cell->table();
609         return 0;
610     }
611
612     if (isRenderView())
613         return const_cast<RenderView*>(toRenderView(this));
614
615     RenderObject* o = parent();
616     if (!isText() && m_style->position() == FixedPosition) {
617         while (o && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock()))
618             o = o->parent();
619     } else if (!isText() && m_style->position() == AbsolutePosition) {
620         while (o && (o->style()->position() == StaticPosition || (o->isInline() && !o->isReplaced())) && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
621             // For relpositioned inlines, we return the nearest enclosing block.  We don't try
622             // to return the inline itself.  This allows us to avoid having a positioned objects
623             // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
624             // from this method.  The container() method can actually be used to obtain the
625             // inline directly.
626             if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced())
627                 return o->containingBlock();
628             o = o->parent();
629         }
630     } else {
631         while (o && ((o->isInline() && !o->isReplaced()) || o->isTableRow() || o->isTableSection()
632                      || o->isTableCol() || o->isFrameSet() || o->isMedia()
633 #if ENABLE(SVG)
634                      || o->isSVGContainer() || o->isSVGRoot()
635 #endif
636                      ))
637             o = o->parent();
638     }
639
640     if (!o || !o->isRenderBlock())
641         return 0; // Probably doesn't happen any more, but leave just in case. -dwh
642
643     return toRenderBlock(o);
644 }
645
646 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
647 {
648     // Nobody will use multiple layers without wanting fancy positioning.
649     if (layer->next())
650         return true;
651
652     // Make sure we have a valid image.
653     StyleImage* img = layer->image();
654     if (!img || !img->canRender(renderer->style()->effectiveZoom()))
655         return false;
656
657     if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
658         return true;
659
660     if (layer->isSizeSet()) {
661         if (layer->size().width().isPercent() || layer->size().height().isPercent())
662             return true;
663     } else if (img->usesImageContainerSize())
664         return true;
665
666     return false;
667 }
668
669 bool RenderObject::mustRepaintBackgroundOrBorder() const
670 {
671     if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
672         return true;
673
674     // If we don't have a background/border/mask, then nothing to do.
675     if (!hasBoxDecorations())
676         return false;
677
678     if (mustRepaintFillLayers(this, style()->backgroundLayers()))
679         return true;
680      
681     // Our fill layers are ok.  Let's check border.
682     if (style()->hasBorder()) {
683         // Border images are not ok.
684         StyleImage* borderImage = style()->borderImage().image();
685         bool shouldPaintBorderImage = borderImage && borderImage->canRender(style()->effectiveZoom());
686
687         // If the image hasn't loaded, we're still using the normal border style.
688         if (shouldPaintBorderImage && borderImage->isLoaded())
689             return true;
690     }
691
692     return false;
693 }
694
695 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
696                                       BoxSide s, Color c, const Color& textcolor, EBorderStyle style,
697                                       int adjbw1, int adjbw2)
698 {
699     int width = (s == BSTop || s == BSBottom ? y2 - y1 : x2 - x1);
700
701     if (style == DOUBLE && width < 3)
702         style = SOLID;
703
704     if (!c.isValid()) {
705         if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
706             c.setRGB(238, 238, 238);
707         else
708             c = textcolor;
709     }
710
711     switch (style) {
712         case BNONE:
713         case BHIDDEN:
714             return;
715         case DOTTED:
716         case DASHED:
717             graphicsContext->setStrokeColor(c);
718             graphicsContext->setStrokeThickness(width);
719             graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
720
721             if (width > 0)
722                 switch (s) {
723                     case BSBottom:
724                     case BSTop:
725                         graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
726                         break;
727                     case BSRight:
728                     case BSLeft:
729                         graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
730                         break;
731                 }
732             break;
733         case DOUBLE: {
734             int third = (width + 1) / 3;
735
736             if (adjbw1 == 0 && adjbw2 == 0) {
737                 graphicsContext->setStrokeStyle(NoStroke);
738                 graphicsContext->setFillColor(c);
739                 switch (s) {
740                     case BSTop:
741                     case BSBottom:
742                         graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third));
743                         graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third));
744                         break;
745                     case BSLeft:
746                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
747                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
748                         break;
749                     case BSRight:
750                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
751                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
752                         break;
753                 }
754             } else {
755                 int adjbw1bigthird = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 3;
756                 int adjbw2bigthird = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 3;
757
758                 switch (s) {
759                     case BSTop:
760                         drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
761                                    y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third,
762                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
763                         drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
764                                    y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2,
765                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
766                         break;
767                     case BSLeft:
768                         drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
769                                    x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
770                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
771                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0),
772                                    x2, y2 - max((adjbw2 * 2 + 1) / 3, 0),
773                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
774                         break;
775                     case BSBottom:
776                         drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
777                                    y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third,
778                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
779                         drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
780                                    y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2,
781                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
782                         break;
783                     case BSRight:
784                         drawLineForBoxSide(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0),
785                                    x1 + third, y2 - max((adjbw2 * 2 + 1) / 3, 0),
786                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
787                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
788                                    x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
789                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
790                         break;
791                     default:
792                         break;
793                 }
794             }
795             break;
796         }
797         case RIDGE:
798         case GROOVE:
799         {
800             EBorderStyle s1;
801             EBorderStyle s2;
802             if (style == GROOVE) {
803                 s1 = INSET;
804                 s2 = OUTSET;
805             } else {
806                 s1 = OUTSET;
807                 s2 = INSET;
808             }
809
810             int adjbw1bighalf = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 2;
811             int adjbw2bighalf = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 2;
812
813             switch (s) {
814                 case BSTop:
815                     drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
816                                s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
817                     drawLineForBoxSide(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2,
818                                s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
819                     break;
820                 case BSLeft:
821                     drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2,
822                                s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
823                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2,
824                                s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
825                     break;
826                 case BSBottom:
827                     drawLineForBoxSide(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
828                                s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
829                     drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2,
830                                s, c, textcolor, s1, adjbw1/2, adjbw2/2);
831                     break;
832                 case BSRight:
833                     drawLineForBoxSide(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2,
834                                s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
835                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2,
836                                s, c, textcolor, s1, adjbw1/2, adjbw2/2);
837                     break;
838             }
839             break;
840         }
841         case INSET:
842             if (s == BSTop || s == BSLeft)
843                 c = c.dark();
844             // fall through
845         case OUTSET:
846             if (style == OUTSET && (s == BSBottom || s == BSRight))
847                 c = c.dark();
848             // fall through
849         case SOLID: {
850             graphicsContext->setStrokeStyle(NoStroke);
851             graphicsContext->setFillColor(c);
852             ASSERT(x2 >= x1);
853             ASSERT(y2 >= y1);
854             if (!adjbw1 && !adjbw2) {
855                 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
856                 return;
857             }
858             FloatPoint quad[4];
859             switch (s) {
860                 case BSTop:
861                     quad[0] = FloatPoint(x1 + max(-adjbw1, 0), y1);
862                     quad[1] = FloatPoint(x1 + max(adjbw1, 0), y2);
863                     quad[2] = FloatPoint(x2 - max(adjbw2, 0), y2);
864                     quad[3] = FloatPoint(x2 - max(-adjbw2, 0), y1);
865                     break;
866                 case BSBottom:
867                     quad[0] = FloatPoint(x1 + max(adjbw1, 0), y1);
868                     quad[1] = FloatPoint(x1 + max(-adjbw1, 0), y2);
869                     quad[2] = FloatPoint(x2 - max(-adjbw2, 0), y2);
870                     quad[3] = FloatPoint(x2 - max(adjbw2, 0), y1);
871                     break;
872                 case BSLeft:
873                     quad[0] = FloatPoint(x1, y1 + max(-adjbw1, 0));
874                     quad[1] = FloatPoint(x1, y2 - max(-adjbw2, 0));
875                     quad[2] = FloatPoint(x2, y2 - max(adjbw2, 0));
876                     quad[3] = FloatPoint(x2, y1 + max(adjbw1, 0));
877                     break;
878                 case BSRight:
879                     quad[0] = FloatPoint(x1, y1 + max(adjbw1, 0));
880                     quad[1] = FloatPoint(x1, y2 - max(adjbw2, 0));
881                     quad[2] = FloatPoint(x2, y2 - max(-adjbw2, 0));
882                     quad[3] = FloatPoint(x2, y1 + max(-adjbw1, 0));
883                     break;
884             }
885             graphicsContext->drawConvexPolygon(4, quad);
886             break;
887         }
888     }
889 }
890
891 void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius,
892                                      int angleStart, int angleSpan, BoxSide s, Color c, const Color& textColor,
893                                      EBorderStyle style, bool firstCorner)
894 {
895     if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2))
896         style = SOLID;
897
898     if (!c.isValid()) {
899         if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
900             c.setRGB(238, 238, 238);
901         else
902             c = textColor;
903     }
904
905     switch (style) {
906         case BNONE:
907         case BHIDDEN:
908             return;
909         case DOTTED:
910         case DASHED:
911             graphicsContext->setStrokeColor(c);
912             graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke);
913             graphicsContext->setStrokeThickness(thickness);
914             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
915             break;
916         case DOUBLE: {
917             float third = thickness / 3.0f;
918             float innerThird = (thickness + 1.0f) / 6.0f;
919             int shiftForInner = static_cast<int>(innerThird * 2.5f);
920
921             int outerY = y;
922             int outerHeight = radius.height() * 2;
923             int innerX = x + shiftForInner;
924             int innerY = y + shiftForInner;
925             int innerWidth = (radius.width() - shiftForInner) * 2;
926             int innerHeight = (radius.height() - shiftForInner) * 2;
927             if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) {
928                 outerHeight += 2;
929                 innerHeight += 2;
930             }
931
932             graphicsContext->setStrokeStyle(SolidStroke);
933             graphicsContext->setStrokeColor(c);
934             graphicsContext->setStrokeThickness(third);
935             graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan);
936             graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird);
937             graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan);
938             break;
939         }
940         case GROOVE:
941         case RIDGE: {
942             Color c2;
943             if ((style == RIDGE && (s == BSTop || s == BSLeft)) ||
944                     (style == GROOVE && (s == BSBottom || s == BSRight)))
945                 c2 = c.dark();
946             else {
947                 c2 = c;
948                 c = c.dark();
949             }
950
951             graphicsContext->setStrokeStyle(SolidStroke);
952             graphicsContext->setStrokeColor(c);
953             graphicsContext->setStrokeThickness(thickness);
954             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
955
956             float halfThickness = (thickness + 1.0f) / 4.0f;
957             int shiftForInner = static_cast<int>(halfThickness * 1.5f);
958             graphicsContext->setStrokeColor(c2);
959             graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness);
960             graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2,
961                                        (radius.height() - shiftForInner) * 2), angleStart, angleSpan);
962             break;
963         }
964         case INSET:
965             if (s == BSTop || s == BSLeft)
966                 c = c.dark();
967         case OUTSET:
968             if (style == OUTSET && (s == BSBottom || s == BSRight))
969                 c = c.dark();
970         case SOLID:
971             graphicsContext->setStrokeStyle(SolidStroke);
972             graphicsContext->setStrokeColor(c);
973             graphicsContext->setStrokeThickness(thickness);
974             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
975             break;
976     }
977 }
978
979 void RenderObject::addPDFURLRect(GraphicsContext* context, const IntRect& rect)
980 {
981     if (rect.isEmpty())
982         return;
983     Node* n = node();
984     if (!n || !n->isLink() || !n->isElementNode())
985         return;
986     const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
987     if (href.isNull())
988         return;
989     context->setURLForRect(n->document()->completeURL(href), rect);
990 }
991
992 void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style)
993 {
994     if (!hasOutline())
995         return;
996
997     int ow = style->outlineWidth();
998     EBorderStyle os = style->outlineStyle();
999
1000     Color oc = style->outlineColor();
1001     if (!oc.isValid())
1002         oc = style->color();
1003
1004     int offset = style->outlineOffset();
1005
1006     if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1007         if (!theme()->supportsFocusRing(style)) {
1008             // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1009             graphicsContext->initFocusRing(ow, offset);
1010             addFocusRingRects(graphicsContext, tx, ty);
1011             if (style->outlineStyleIsAuto())
1012                 graphicsContext->drawFocusRing(oc);
1013             else
1014                 addPDFURLRect(graphicsContext, graphicsContext->focusRingBoundingRect());
1015             graphicsContext->clearFocusRing();
1016         }
1017     }
1018
1019     if (style->outlineStyleIsAuto() || style->outlineStyle() == BNONE)
1020         return;
1021
1022     tx -= offset;
1023     ty -= offset;
1024     w += 2 * offset;
1025     h += 2 * offset;
1026
1027     if (h < 0 || w < 0)
1028         return;
1029
1030     drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow,
1031                BSLeft, Color(oc), style->color(), os, ow, ow);
1032
1033     drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty,
1034                BSTop, Color(oc), style->color(), os, ow, ow);
1035
1036     drawLineForBoxSide(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow,
1037                BSRight, Color(oc), style->color(), os, ow, ow);
1038
1039     drawLineForBoxSide(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow,
1040                BSBottom, Color(oc), style->color(), os, ow, ow);
1041 }
1042
1043 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms)
1044 {
1045     if (useTransforms) {
1046         Vector<FloatQuad> quads;
1047         absoluteQuads(quads);
1048
1049         size_t n = quads.size();
1050         if (!n)
1051             return IntRect();
1052     
1053         IntRect result = quads[0].enclosingBoundingBox();
1054         for (size_t i = 1; i < n; ++i)
1055             result.unite(quads[i].enclosingBoundingBox());
1056         return result;
1057     }
1058
1059     FloatPoint absPos = localToAbsolute();
1060     Vector<IntRect> rects;
1061     absoluteRects(rects, absPos.x(), absPos.y());
1062
1063     size_t n = rects.size();
1064     if (!n)
1065         return IntRect();
1066
1067     IntRect result = rects[0];
1068     for (size_t i = 1; i < n; ++i)
1069         result.unite(rects[i]);
1070     return result;
1071 }
1072
1073 void RenderObject::addAbsoluteRectForLayer(IntRect& result)
1074 {
1075     if (hasLayer())
1076         result.unite(absoluteBoundingBoxRect());
1077     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1078         current->addAbsoluteRectForLayer(result);
1079 }
1080
1081 IntRect RenderObject::paintingRootRect(IntRect& topLevelRect)
1082 {
1083     IntRect result = absoluteBoundingBoxRect();
1084     topLevelRect = result;
1085     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1086         current->addAbsoluteRectForLayer(result);
1087     return result;
1088 }
1089
1090 void RenderObject::paint(PaintInfo& /*paintInfo*/, int /*tx*/, int /*ty*/)
1091 {
1092 }
1093
1094 RenderBoxModelObject* RenderObject::containerForRepaint() const
1095 {
1096 #if USE(ACCELERATED_COMPOSITING)
1097     if (RenderView* v = view()) {
1098         if (v->usesCompositing()) {
1099             RenderLayer* compLayer = enclosingLayer()->enclosingCompositingLayer();
1100             return compLayer ? compLayer->renderer() : 0;
1101         }
1102     }
1103 #endif
1104     // Do root-relative repaint.
1105     return 0;
1106 }
1107
1108 void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const IntRect& r, bool immediate)
1109 {
1110     if (!repaintContainer || repaintContainer->isRenderView()) {
1111         RenderView* v = repaintContainer ? toRenderView(repaintContainer) : view();
1112         v->repaintViewRectangle(r, immediate);
1113     } else {
1114 #if USE(ACCELERATED_COMPOSITING)
1115         RenderView* v = view();
1116         if (v->usesCompositing()) {
1117             ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
1118             repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
1119         }
1120 #else
1121         ASSERT_NOT_REACHED();
1122 #endif
1123     }
1124 }
1125
1126 void RenderObject::repaint(bool immediate)
1127 {
1128     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1129     RenderView* view;
1130     if (!isRooted(&view))
1131         return;
1132
1133     if (view->printing())
1134         return; // Don't repaint if we're printing.
1135
1136     RenderBoxModelObject* repaintContainer = containerForRepaint();
1137     repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate);
1138 }
1139
1140 void RenderObject::repaintRectangle(const IntRect& r, bool immediate)
1141 {
1142     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1143     RenderView* view;
1144     if (!isRooted(&view))
1145         return;
1146
1147     if (view->printing())
1148         return; // Don't repaint if we're printing.
1149
1150     IntRect dirtyRect(r);
1151
1152     // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1153     // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1154     dirtyRect.move(view->layoutDelta());
1155
1156     RenderBoxModelObject* repaintContainer = containerForRepaint();
1157     computeRectForRepaint(repaintContainer, dirtyRect);
1158     repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate);
1159 }
1160
1161 bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const IntRect& oldBounds, const IntRect& oldOutlineBox)
1162 {
1163     RenderView* v = view();
1164     if (v->printing())
1165         return false; // Don't repaint if we're printing.
1166
1167     IntRect newBounds = clippedOverflowRectForRepaint(repaintContainer);
1168     IntRect newOutlineBox;
1169
1170     bool fullRepaint = selfNeedsLayout();
1171     // Presumably a background or a border exists if border-fit:lines was specified.
1172     if (!fullRepaint && style()->borderFit() == BorderFitLines)
1173         fullRepaint = true;
1174     if (!fullRepaint) {
1175         newOutlineBox = outlineBoundsForRepaint(repaintContainer);
1176         if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1177             fullRepaint = true;
1178     }
1179
1180     if (!repaintContainer)
1181         repaintContainer = v;
1182
1183     if (fullRepaint) {
1184         repaintUsingContainer(repaintContainer, oldBounds);
1185         if (newBounds != oldBounds)
1186             repaintUsingContainer(repaintContainer, newBounds);
1187         return true;
1188     }
1189
1190     if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1191         return false;
1192
1193     int deltaLeft = newBounds.x() - oldBounds.x();
1194     if (deltaLeft > 0)
1195         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1196     else if (deltaLeft < 0)
1197         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1198
1199     int deltaRight = newBounds.right() - oldBounds.right();
1200     if (deltaRight > 0)
1201         repaintUsingContainer(repaintContainer, IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height()));
1202     else if (deltaRight < 0)
1203         repaintUsingContainer(repaintContainer, IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height()));
1204
1205     int deltaTop = newBounds.y() - oldBounds.y();
1206     if (deltaTop > 0)
1207         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1208     else if (deltaTop < 0)
1209         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1210
1211     int deltaBottom = newBounds.bottom() - oldBounds.bottom();
1212     if (deltaBottom > 0)
1213         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom));
1214     else if (deltaBottom < 0)
1215         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom));
1216
1217     if (newOutlineBox == oldOutlineBox)
1218         return false;
1219
1220     // We didn't move, but we did change size.  Invalidate the delta, which will consist of possibly
1221     // two rectangles (but typically only one).
1222     RenderStyle* outlineStyle = outlineStyleForRepaint();
1223     int ow = outlineStyle->outlineSize();
1224     int width = abs(newOutlineBox.width() - oldOutlineBox.width());
1225     if (width) {
1226         int shadowLeft;
1227         int shadowRight;
1228         style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1229
1230         int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1231         int borderWidth = max(-outlineStyle->outlineOffset(), max(borderRight, max(style()->borderTopRightRadius().width(), style()->borderBottomRightRadius().width()))) + max(ow, shadowRight);
1232         IntRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
1233             newOutlineBox.y(),
1234             width + borderWidth,
1235             max(newOutlineBox.height(), oldOutlineBox.height()));
1236         int right = min(newBounds.right(), oldBounds.right());
1237         if (rightRect.x() < right) {
1238             rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1239             repaintUsingContainer(repaintContainer, rightRect);
1240         }
1241     }
1242     int height = abs(newOutlineBox.height() - oldOutlineBox.height());
1243     if (height) {
1244         int shadowTop;
1245         int shadowBottom;
1246         style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1247
1248         int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1249         int borderHeight = max(-outlineStyle->outlineOffset(), max(borderBottom, max(style()->borderBottomLeftRadius().height(), style()->borderBottomRightRadius().height()))) + max(ow, shadowBottom);
1250         IntRect bottomRect(newOutlineBox.x(),
1251             min(newOutlineBox.bottom(), oldOutlineBox.bottom()) - borderHeight,
1252             max(newOutlineBox.width(), oldOutlineBox.width()),
1253             height + borderHeight);
1254         int bottom = min(newBounds.bottom(), oldBounds.bottom());
1255         if (bottomRect.y() < bottom) {
1256             bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1257             repaintUsingContainer(repaintContainer, bottomRect);
1258         }
1259     }
1260     return false;
1261 }
1262
1263 void RenderObject::repaintDuringLayoutIfMoved(const IntRect&)
1264 {
1265 }
1266
1267 void RenderObject::repaintOverhangingFloats(bool)
1268 {
1269 }
1270
1271 bool RenderObject::checkForRepaintDuringLayout() const
1272 {
1273     // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=20885> It is probably safe to also require
1274     // m_everHadLayout. Currently, only RenderBlock::layoutBlock() adds this condition. See also
1275     // <https://bugs.webkit.org/show_bug.cgi?id=15129>.
1276     return !document()->view()->needsFullRepaint() && !hasLayer();
1277 }
1278
1279 IntRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth)
1280 {
1281     IntRect r(clippedOverflowRectForRepaint(repaintContainer));
1282     r.inflate(outlineWidth);
1283     return r;
1284 }
1285
1286 IntRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*)
1287 {
1288     ASSERT_NOT_REACHED();
1289     return IntRect();
1290 }
1291
1292 void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed)
1293 {
1294     if (repaintContainer == this)
1295         return;
1296
1297     if (RenderObject* o = parent()) {
1298         if (o->isBlockFlow()) {
1299             RenderBlock* cb = toRenderBlock(o);
1300             if (cb->hasColumns())
1301                 cb->adjustRectForColumns(rect);
1302         }
1303
1304         if (o->hasOverflowClip()) {
1305             // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
1306             // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
1307             // anyway if its size does change.
1308             RenderBox* boxParent = toRenderBox(o);
1309
1310             IntRect boxRect(0, 0, boxParent->layer()->width(), boxParent->layer()->height());
1311             int x = rect.x();
1312             int y = rect.y();
1313             boxParent->layer()->subtractScrolledContentOffset(x, y); // For overflow:auto/scroll/hidden.
1314             IntRect repaintRect(x, y, rect.width(), rect.height());
1315             rect = intersection(repaintRect, boxRect);
1316             if (rect.isEmpty())
1317                 return;
1318         }
1319
1320         o->computeRectForRepaint(repaintContainer, rect, fixed);
1321     }
1322 }
1323
1324 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1325 {
1326 }
1327
1328 #ifndef NDEBUG
1329
1330 void RenderObject::showTreeForThis() const
1331 {
1332     if (node())
1333         node()->showTreeForThis();
1334 }
1335
1336 #endif // NDEBUG
1337
1338 Color RenderObject::selectionBackgroundColor() const
1339 {
1340     Color color;
1341     if (style()->userSelect() != SELECT_NONE) {
1342          RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
1343         if (pseudoStyle && pseudoStyle->backgroundColor().isValid())
1344             color = pseudoStyle->backgroundColor().blendWithWhite();
1345         else
1346             color = document()->frame()->selection()->isFocusedAndActive() ?
1347                     theme()->activeSelectionBackgroundColor() :
1348                     theme()->inactiveSelectionBackgroundColor();
1349     }
1350
1351     return color;
1352 }
1353
1354 Color RenderObject::selectionForegroundColor() const
1355 {
1356     Color color;
1357     if (style()->userSelect() == SELECT_NONE)
1358         return color;
1359
1360     if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
1361         color = pseudoStyle->textFillColor();
1362         if (!color.isValid())
1363             color = pseudoStyle->color();
1364     } else
1365         color = document()->frame()->selection()->isFocusedAndActive() ?
1366                 theme()->activeSelectionForegroundColor() :
1367                 theme()->inactiveSelectionForegroundColor();
1368
1369     return color;
1370 }
1371
1372 Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
1373 {
1374     if (!dhtmlOK && !uaOK)
1375         return 0;
1376
1377     for (const RenderObject* curr = this; curr; curr = curr->parent()) {
1378         Node* elt = curr->node();
1379         if (elt && elt->nodeType() == Node::TEXT_NODE) {
1380             // Since there's no way for the author to address the -webkit-user-drag style for a text node,
1381             // we use our own judgement.
1382             if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
1383                 dhtmlWillDrag = false;
1384                 return curr->node();
1385             }
1386             if (elt->canStartSelection())
1387                 // In this case we have a click in the unselected portion of text.  If this text is
1388                 // selectable, we want to start the selection process instead of looking for a parent
1389                 // to try to drag.
1390                 return 0;
1391         } else {
1392             EUserDrag dragMode = curr->style()->userDrag();
1393             if (dhtmlOK && dragMode == DRAG_ELEMENT) {
1394                 dhtmlWillDrag = true;
1395                 return curr->node();
1396             }
1397             if (uaOK && dragMode == DRAG_AUTO
1398                     && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
1399                 dhtmlWillDrag = false;
1400                 return curr->node();
1401             }
1402         }
1403     }
1404     return 0;
1405 }
1406
1407 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1408 {
1409     view()->selectionStartEnd(spos, epos);
1410 }
1411
1412 void RenderObject::handleDynamicFloatPositionChange()
1413 {
1414     // We have gone from not affecting the inline status of the parent flow to suddenly
1415     // having an impact.  See if there is a mismatch between the parent flow's
1416     // childrenInline() state and our state.
1417     setInline(style()->isDisplayInlineType());
1418     if (isInline() != parent()->childrenInline()) {
1419         if (!isInline())
1420             toRenderBoxModelObject(parent())->childBecameNonInline(this);
1421         else {
1422             // An anonymous block must be made to wrap this inline.
1423             RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1424             RenderObjectChildList* childlist = parent()->virtualChildren();
1425             childlist->insertChildNode(parent(), block, this);
1426             block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1427         }
1428     }
1429 }
1430
1431 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
1432 {
1433     if (!isText() && style)
1434         setStyle(animation()->updateAnimations(this, style.get()));
1435     else
1436         setStyle(style);
1437 }
1438
1439 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1440 {
1441 #if USE(ACCELERATED_COMPOSITING)
1442     // If transform changed, and we are not composited, need to do a layout.
1443     if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1444         // Text nodes share style with their parents but transforms don't apply to them,
1445         // hence the !isText() check.
1446         // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1447         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
1448             diff = StyleDifferenceLayout;
1449         else if (diff < StyleDifferenceRecompositeLayer)
1450             diff = StyleDifferenceRecompositeLayer;
1451     }
1452
1453     // If opacity changed, and we are not composited, need to repaint (also
1454     // ignoring text nodes)
1455     if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
1456         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
1457             diff = StyleDifferenceRepaintLayer;
1458         else if (diff < StyleDifferenceRecompositeLayer)
1459             diff = StyleDifferenceRecompositeLayer;
1460     }
1461 #else
1462     UNUSED_PARAM(contextSensitiveProperties);
1463 #endif
1464
1465     // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1466     if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1467         diff = StyleDifferenceRepaint;
1468
1469     return diff;
1470 }
1471
1472 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1473 {
1474     if (m_style == style)
1475         return;
1476
1477     StyleDifference diff = StyleDifferenceEqual;
1478     unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1479     if (m_style)
1480         diff = m_style->diff(style.get(), contextSensitiveProperties);
1481
1482     diff = adjustStyleDifference(diff, contextSensitiveProperties);
1483
1484     styleWillChange(diff, style.get());
1485     
1486     RefPtr<RenderStyle> oldStyle = m_style.release();
1487     m_style = style;
1488
1489     updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1490     updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1491
1492     updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1493     updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1494
1495     // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1496     // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1497     if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
1498         toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
1499
1500     styleDidChange(diff, oldStyle.get());
1501
1502     if (!m_parent || isText())
1503         return;
1504
1505     // Now that the layer (if any) has been updated, we need to adjust the diff again,
1506     // check whether we should layout now, and decide if we need to repaint.
1507     StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1508     
1509     if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1510         if (updatedDiff == StyleDifferenceLayout)
1511             setNeedsLayoutAndPrefWidthsRecalc();
1512         else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1513             setNeedsPositionedMovementLayout();
1514     }
1515     
1516     if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
1517         // Do a repaint with the new style now, e.g., for example if we go from
1518         // not having an outline to having an outline.
1519         repaint();
1520     }
1521 }
1522
1523 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
1524 {
1525     m_style = style;
1526 }
1527
1528 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1529 {
1530     if (m_style) {
1531         // If our z-index changes value or our visibility changes,
1532         // we need to dirty our stacking context's z-order list.
1533         if (newStyle) {
1534             bool visibilityChanged = m_style->visibility() != newStyle->visibility() 
1535                 || m_style->zIndex() != newStyle->zIndex() 
1536                 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1537 #if ENABLE(DASHBOARD_SUPPORT)
1538             if (visibilityChanged)
1539                 document()->setDashboardRegionsDirty(true);
1540 #endif
1541             if (visibilityChanged && AXObjectCache::accessibilityEnabled())
1542                 document()->axObjectCache()->childrenChanged(this);
1543
1544             // Keep layer hierarchy visibility bits up to date if visibility changes.
1545             if (m_style->visibility() != newStyle->visibility()) {
1546                 if (RenderLayer* l = enclosingLayer()) {
1547                     if (newStyle->visibility() == VISIBLE)
1548                         l->setHasVisibleContent(true);
1549                     else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1550                         l->dirtyVisibleContentStatus();
1551                         if (diff > StyleDifferenceRepaintLayer)
1552                             repaint();
1553                     }
1554                 }
1555             }
1556         }
1557
1558         if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
1559             repaint();
1560         if (isFloating() && (m_style->floating() != newStyle->floating()))
1561             // For changes in float styles, we need to conceivably remove ourselves
1562             // from the floating objects list.
1563             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1564         else if (isPositioned() && (newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition))
1565             // For changes in positioning styles, we need to conceivably remove ourselves
1566             // from the positioned objects list.
1567             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1568
1569         s_affectsParentBlock = isFloatingOrPositioned() &&
1570             (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)
1571             && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
1572
1573         // reset style flags
1574         if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
1575             m_floating = false;
1576             m_positioned = false;
1577             m_relPositioned = false;
1578         }
1579         m_paintBackground = false;
1580         m_hasOverflowClip = false;
1581         m_hasTransform = false;
1582         m_hasReflection = false;
1583     } else
1584         s_affectsParentBlock = false;
1585
1586     if (view()->frameView()) {
1587         // FIXME: A better solution would be to only invalidate the fixed regions when scrolling.  It's overkill to
1588         // prevent the entire view from blitting on a scroll.
1589         bool newStyleSlowScroll = newStyle && (newStyle->position() == FixedPosition || newStyle->hasFixedBackgroundImage());
1590         bool oldStyleSlowScroll = m_style && (m_style->position() == FixedPosition || m_style->hasFixedBackgroundImage());
1591         if (oldStyleSlowScroll != newStyleSlowScroll) {
1592             if (oldStyleSlowScroll)
1593                 view()->frameView()->removeSlowRepaintObject();
1594             if (newStyleSlowScroll)
1595                 view()->frameView()->addSlowRepaintObject();
1596         }
1597     }
1598 }
1599
1600 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle*)
1601 {
1602     if (s_affectsParentBlock)
1603         handleDynamicFloatPositionChange();
1604
1605     if (!m_parent)
1606         return;
1607     
1608     if (diff == StyleDifferenceLayout)
1609         setNeedsLayoutAndPrefWidthsRecalc();
1610     else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
1611         setNeedsPositionedMovementLayout();
1612
1613     // Don't check for repaint here; we need to wait until the layer has been
1614     // updated by subclasses before we know if we have to repaint (in setStyle()).
1615 }
1616
1617 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
1618 {
1619     // Optimize the common case
1620     if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
1621         return;
1622     
1623     // Go through the new layers and addClients first, to avoid removing all clients of an image.
1624     for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
1625         if (currNew->image())
1626             currNew->image()->addClient(this);
1627     }
1628
1629     for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
1630         if (currOld->image())
1631             currOld->image()->removeClient(this);
1632     }
1633 }
1634
1635 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
1636 {
1637     if (oldImage != newImage) {
1638         if (oldImage)
1639             oldImage->removeClient(this);
1640         if (newImage)
1641             newImage->addClient(this);
1642     }
1643 }
1644
1645 IntRect RenderObject::viewRect() const
1646 {
1647     return view()->viewRect();
1648 }
1649
1650 FloatPoint RenderObject::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const
1651 {
1652     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
1653     mapLocalToContainer(0, fixed, useTransforms, transformState);
1654     transformState.flatten();
1655     
1656     return transformState.lastPlanarPoint();
1657 }
1658
1659 FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
1660 {
1661     TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
1662     mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
1663     transformState.flatten();
1664     
1665     return transformState.lastPlanarPoint();
1666 }
1667
1668 void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const
1669 {
1670     if (repaintContainer == this)
1671         return;
1672
1673     RenderObject* o = parent();
1674     if (!o)
1675         return;
1676
1677     if (o->hasOverflowClip())
1678         transformState.move(-toRenderBox(o)->layer()->scrolledContentOffset());
1679
1680     o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState);
1681 }
1682
1683 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
1684 {
1685     RenderObject* o = parent();
1686     if (o) {
1687         o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
1688         if (o->hasOverflowClip())
1689             transformState.move(toRenderBox(o)->layer()->scrolledContentOffset());
1690     }
1691 }
1692
1693 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
1694 {
1695 #if ENABLE(3D_RENDERING)
1696     // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
1697     // so check the layer's transform directly.
1698     return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
1699 #else
1700     UNUSED_PARAM(containerObject);
1701     return hasTransform();
1702 #endif
1703 }
1704
1705 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const IntSize& offsetInContainer, TransformationMatrix& transform) const
1706 {
1707     transform.makeIdentity();
1708     transform.translate(offsetInContainer.width(), offsetInContainer.height());
1709     RenderLayer* layer;
1710     if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform())
1711         transform.multLeft(layer->currentTransform());
1712     
1713 #if ENABLE(3D_RENDERING)
1714     if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
1715         // Perpsective on the container affects us, so we have to factor it in here.
1716         ASSERT(containerObject->hasLayer());
1717         FloatPoint perspectiveOrigin = toRenderBox(containerObject)->layer()->perspectiveOrigin();
1718
1719         TransformationMatrix perspectiveMatrix;
1720         perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
1721         
1722         transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
1723         transform.multiply(perspectiveMatrix);
1724         transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
1725     }
1726 #else
1727     UNUSED_PARAM(containerObject);
1728 #endif
1729 }
1730
1731 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed) const
1732 {
1733     TransformState transformState(TransformState::ApplyTransformDirection, FloatPoint(), &localQuad);
1734     mapLocalToContainer(repaintContainer, fixed, true, transformState);
1735     transformState.flatten();
1736     
1737     return transformState.lastPlanarQuad();
1738 }
1739
1740 IntSize RenderObject::offsetFromContainer(RenderObject* o) const
1741 {
1742     ASSERT(o == container());
1743
1744     IntSize offset;
1745     if (o->hasOverflowClip())
1746         offset -= toRenderBox(o)->layer()->scrolledContentOffset();
1747
1748     return offset;
1749 }
1750
1751 IntRect RenderObject::localCaretRect(InlineBox*, int, int* extraWidthToEndOfLine)
1752 {
1753     if (extraWidthToEndOfLine)
1754         *extraWidthToEndOfLine = 0;
1755
1756     return IntRect();
1757 }
1758
1759 RenderView* RenderObject::view() const
1760 {
1761     return toRenderView(document()->renderer());
1762 }
1763
1764 bool RenderObject::isRooted(RenderView** view)
1765 {
1766     RenderObject* o = this;
1767     while (o->parent())
1768         o = o->parent();
1769
1770     if (!o->isRenderView())
1771         return false;
1772
1773     if (view)
1774         *view = toRenderView(o);
1775
1776     return true;
1777 }
1778
1779 bool RenderObject::hasOutlineAnnotation() const
1780 {
1781     return node() && node()->isLink() && document()->printing();
1782 }
1783
1784 RenderObject* RenderObject::container() const
1785 {
1786     // This method is extremely similar to containingBlock(), but with a few notable
1787     // exceptions.
1788     // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
1789     // the object is not part of the primary document subtree yet.
1790     // (2) For normal flow elements, it just returns the parent.
1791     // (3) For absolute positioned elements, it will return a relative positioned inline.
1792     // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
1793     // the layout of the positioned object.  This does mean that calcAbsoluteHorizontal and
1794     // calcAbsoluteVertical have to use container().
1795     RenderObject* o = parent();
1796
1797     if (isText())
1798         return o;
1799
1800     EPosition pos = m_style->position();
1801     if (pos == FixedPosition) {
1802         // container() can be called on an object that is not in the
1803         // tree yet.  We don't call view() since it will assert if it
1804         // can't get back to the canvas.  Instead we just walk as high up
1805         // as we can.  If we're in the tree, we'll get the root.  If we
1806         // aren't we'll get the root of our little subtree (most likely
1807         // we'll just return 0).
1808         // FIXME: The definition of view() has changed to not crawl up the render tree.  It might
1809         // be safe now to use it.
1810         while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock()))
1811             o = o->parent();
1812     } else if (pos == AbsolutePosition) {
1813         // Same goes here.  We technically just want our containing block, but
1814         // we may not have one if we're part of an uninstalled subtree.  We'll
1815         // climb as high as we can though.
1816         while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock()))
1817             o = o->parent();
1818     }
1819
1820     return o;
1821 }
1822
1823 bool RenderObject::isSelectionBorder() const
1824 {
1825     SelectionState st = selectionState();
1826     return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
1827 }
1828
1829 void RenderObject::destroy()
1830 {
1831     // Destroy any leftover anonymous children.
1832     RenderObjectChildList* children = virtualChildren();
1833     if (children)
1834         children->destroyLeftoverChildren();
1835
1836     // If this renderer is being autoscrolled, stop the autoscroll timer
1837     if (document()->frame()->eventHandler()->autoscrollRenderer() == this)
1838         document()->frame()->eventHandler()->stopAutoscrollTimer(true);
1839
1840     if (m_hasCounterNodeMap)
1841         RenderCounter::destroyCounterNodes(this);
1842
1843     if (AXObjectCache::accessibilityEnabled()) {
1844         document()->axObjectCache()->childrenChanged(this->parent());
1845         document()->axObjectCache()->remove(this);
1846     }
1847     animation()->cancelAnimations(this);
1848
1849     // By default no ref-counting. RenderWidget::destroy() doesn't call
1850     // this function because it needs to do ref-counting. If anything
1851     // in this function changes, be sure to fix RenderWidget::destroy() as well.
1852
1853     remove();
1854
1855     // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
1856     // be moved into RenderBoxModelObject::destroy.
1857     if (hasLayer()) {
1858         setHasLayer(false);
1859         toRenderBoxModelObject(this)->destroyLayer();
1860     }
1861     arenaDelete(renderArena(), this);
1862 }
1863
1864 void RenderObject::arenaDelete(RenderArena* arena, void* base)
1865 {
1866     if (m_style) {
1867         for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
1868             if (StyleImage* backgroundImage = bgLayer->image())
1869                 backgroundImage->removeClient(this);
1870         }
1871
1872         for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
1873             if (StyleImage* maskImage = maskLayer->image())
1874                 maskImage->removeClient(this);
1875         }
1876
1877         if (StyleImage* borderImage = m_style->borderImage().image())
1878             borderImage->removeClient(this);
1879
1880         if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
1881             maskBoxImage->removeClient(this);
1882     }
1883
1884 #ifndef NDEBUG
1885     void* savedBase = baseOfRenderObjectBeingDeleted;
1886     baseOfRenderObjectBeingDeleted = base;
1887 #endif
1888     delete this;
1889 #ifndef NDEBUG
1890     baseOfRenderObjectBeingDeleted = savedBase;
1891 #endif
1892
1893     // Recover the size left there for us by operator delete and free the memory.
1894     arena->free(*(size_t*)base, base);
1895 }
1896
1897 VisiblePosition RenderObject::positionForCoordinates(int x, int y)
1898 {
1899     return positionForPoint(IntPoint(x, y));
1900 }
1901
1902 VisiblePosition RenderObject::positionForPoint(const IntPoint&)
1903 {
1904     return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
1905 }
1906
1907 void RenderObject::updateDragState(bool dragOn)
1908 {
1909     bool valueChanged = (dragOn != m_isDragging);
1910     m_isDragging = dragOn;
1911     if (valueChanged && style()->affectedByDragRules())
1912         node()->setNeedsStyleRecalc();
1913     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
1914         curr->updateDragState(dragOn);
1915 }
1916
1917 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const IntPoint& point, int tx, int ty, HitTestFilter hitTestFilter)
1918 {
1919     bool inside = false;
1920     if (hitTestFilter != HitTestSelf) {
1921         // First test the foreground layer (lines and inlines).
1922         inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestForeground);
1923
1924         // Test floats next.
1925         if (!inside)
1926             inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestFloat);
1927
1928         // Finally test to see if the mouse is in the background (within a child block's background).
1929         if (!inside)
1930             inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestChildBlockBackgrounds);
1931     }
1932
1933     // See if the mouse is inside us but not any of our descendants
1934     if (hitTestFilter != HitTestDescendants && !inside)
1935         inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestBlockBackground);
1936
1937     return inside;
1938 }
1939
1940 void RenderObject::updateHitTestResult(HitTestResult& result, const IntPoint& point)
1941 {
1942     if (result.innerNode())
1943         return;
1944
1945     Node* n = node();
1946     if (n) {
1947         result.setInnerNode(n);
1948         if (!result.innerNonSharedNode())
1949             result.setInnerNonSharedNode(n);
1950         result.setLocalPoint(point);
1951     }
1952 }
1953
1954 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int /*x*/, int /*y*/, int /*tx*/, int /*ty*/, HitTestAction)
1955 {
1956     return false;
1957 }
1958
1959 int RenderObject::lineHeight(bool firstLine, bool /*isRootLineBox*/) const
1960 {
1961     return style(firstLine)->computedLineHeight();
1962 }
1963
1964 int RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const
1965 {
1966     const Font& f = style(firstLine)->font();
1967     return f.ascent() + (lineHeight(firstLine, isRootLineBox) - f.height()) / 2;
1968 }
1969
1970 void RenderObject::scheduleRelayout()
1971 {
1972     if (isRenderView()) {
1973         FrameView* view = toRenderView(this)->frameView();
1974         if (view)
1975             view->scheduleRelayout();
1976     } else if (parent()) {
1977         FrameView* v = view() ? view()->frameView() : 0;
1978         if (v)
1979             v->scheduleRelayoutOfSubtree(this);
1980     }
1981 }
1982
1983 void RenderObject::layout()
1984 {
1985     ASSERT(needsLayout());
1986     RenderObject* child = firstChild();
1987     while (child) {
1988         child->layoutIfNeeded();
1989         ASSERT(!child->needsLayout());
1990         child = child->nextSibling();
1991     }
1992     setNeedsLayout(false);
1993 }
1994
1995 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
1996 {
1997     if (!document()->usesFirstLineRules())
1998         return 0;
1999
2000     ASSERT(!isText());
2001
2002     RefPtr<RenderStyle> result;
2003
2004     if (isBlockFlow()) {
2005         if (RenderBlock* firstLineBlock = this->firstLineBlock())
2006             result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0);
2007     } else if (!isAnonymous() && isRenderInline()) {
2008         RenderStyle* parentStyle = parent()->firstLineStyle();
2009         if (parentStyle != parent()->style())
2010             result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
2011     }
2012
2013     return result.release();
2014 }
2015
2016 RenderStyle* RenderObject::firstLineStyleSlowCase() const
2017 {
2018     ASSERT(document()->usesFirstLineRules());
2019
2020     RenderStyle* style = m_style.get();
2021     const RenderObject* renderer = isText() ? parent() : this;
2022     if (renderer->isBlockFlow()) {
2023         if (RenderBlock* firstLineBlock = renderer->firstLineBlock())
2024             style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2025     } else if (!renderer->isAnonymous() && renderer->isRenderInline()) {
2026         RenderStyle* parentStyle = renderer->parent()->firstLineStyle();
2027         if (parentStyle != renderer->parent()->style()) {
2028             // A first-line style is in effect. Cache a first-line style for ourselves.
2029             style->setHasPseudoStyle(FIRST_LINE_INHERITED);
2030             style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2031         }
2032     }
2033
2034     return style;
2035 }
2036
2037 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2038 {
2039     if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2040         return 0;
2041
2042     RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2043     if (cachedStyle)
2044         return cachedStyle;
2045     
2046     RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
2047     if (result)
2048         return style()->addCachedPseudoStyle(result.release());
2049     return 0;
2050 }
2051
2052 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2053 {
2054     if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
2055         return 0;
2056     
2057     if (!parentStyle) {
2058         ASSERT(!ownStyle);
2059         parentStyle = style();
2060     }
2061
2062     Node* n = node();
2063     while (n && !n->isElementNode())
2064         n = n->parentNode();
2065     if (!n)
2066         return 0;
2067
2068     RefPtr<RenderStyle> result;
2069     if (pseudo == FIRST_LINE_INHERITED) {
2070         result = document()->styleSelector()->styleForElement(static_cast<Element*>(n), parentStyle, false);
2071         result->setStyleType(FIRST_LINE_INHERITED);
2072     } else
2073         result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(n), parentStyle);
2074     return result.release();
2075 }
2076
2077 static Color decorationColor(RenderStyle* style)
2078 {
2079     Color result;
2080     if (style->textStrokeWidth() > 0) {
2081         // Prefer stroke color if possible but not if it's fully transparent.
2082         result = style->textStrokeColor();
2083         if (!result.isValid())
2084             result = style->color();
2085         if (result.alpha())
2086             return result;
2087     }
2088     
2089     result = style->textFillColor();
2090     if (!result.isValid())
2091         result = style->color();
2092     return result;
2093 }
2094
2095 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2096                                            Color& linethrough, bool quirksMode)
2097 {
2098     RenderObject* curr = this;
2099     do {
2100         int currDecs = curr->style()->textDecoration();
2101         if (currDecs) {
2102             if (currDecs & UNDERLINE) {
2103                 decorations &= ~UNDERLINE;
2104                 underline = decorationColor(curr->style());
2105             }
2106             if (currDecs & OVERLINE) {
2107                 decorations &= ~OVERLINE;
2108                 overline = decorationColor(curr->style());
2109             }
2110             if (currDecs & LINE_THROUGH) {
2111                 decorations &= ~LINE_THROUGH;
2112                 linethrough = decorationColor(curr->style());
2113             }
2114         }
2115         curr = curr->parent();
2116         if (curr && curr->isRenderBlock() && toRenderBlock(curr)->inlineContinuation())
2117             curr = toRenderBlock(curr)->inlineContinuation();
2118     } while (curr && decorations && (!quirksMode || !curr->node() ||
2119                                      (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2120
2121     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2122     if (decorations && curr) {
2123         if (decorations & UNDERLINE)
2124             underline = decorationColor(curr->style());
2125         if (decorations & OVERLINE)
2126             overline = decorationColor(curr->style());
2127         if (decorations & LINE_THROUGH)
2128             linethrough = decorationColor(curr->style());
2129     }
2130 }
2131
2132 #if ENABLE(DASHBOARD_SUPPORT)
2133 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2134 {
2135     // Convert the style regions to absolute coordinates.
2136     if (style()->visibility() != VISIBLE || !isBox())
2137         return;
2138     
2139     RenderBox* box = toRenderBox(this);
2140
2141     const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2142     unsigned i, count = styleRegions.size();
2143     for (i = 0; i < count; i++) {
2144         StyleDashboardRegion styleRegion = styleRegions[i];
2145
2146         int w = box->width();
2147         int h = box->height();
2148
2149         DashboardRegionValue region;
2150         region.label = styleRegion.label;
2151         region.bounds = IntRect(styleRegion.offset.left().value(),
2152                                 styleRegion.offset.top().value(),
2153                                 w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
2154                                 h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
2155         region.type = styleRegion.type;
2156
2157         region.clip = region.bounds;
2158         computeAbsoluteRepaintRect(region.clip);
2159         if (region.clip.height() < 0) {
2160             region.clip.setHeight(0);
2161             region.clip.setWidth(0);
2162         }
2163
2164         FloatPoint absPos = localToAbsolute();
2165         region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
2166         region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
2167
2168         if (document()->frame()) {
2169             float pageScaleFactor = document()->frame()->page()->chrome()->scaleFactor();
2170             if (pageScaleFactor != 1.0f) {
2171                 region.bounds.scale(pageScaleFactor);
2172                 region.clip.scale(pageScaleFactor);
2173             }
2174         }
2175
2176         regions.append(region);
2177     }
2178 }
2179
2180 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2181 {
2182     // RenderTexts don't have their own style, they just use their parent's style,
2183     // so we don't want to include them.
2184     if (isText())
2185         return;
2186
2187     addDashboardRegions(regions);
2188     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2189         curr->collectDashboardRegions(regions);
2190 }
2191 #endif
2192
2193 bool RenderObject::willRenderImage(CachedImage*)
2194 {
2195     // Without visibility we won't render (and therefore don't care about animation).
2196     if (style()->visibility() != VISIBLE)
2197         return false;
2198
2199     // 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)
2200     // then we don't want to render either.
2201     return !document()->inPageCache() && !document()->view()->isOffscreen();
2202 }
2203
2204 int RenderObject::maximalOutlineSize(PaintPhase p) const
2205 {
2206     if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2207         return 0;
2208     return toRenderView(document()->renderer())->maximalOutlineSize();
2209 }
2210
2211 int RenderObject::caretMinOffset() const
2212 {
2213     return 0;
2214 }
2215
2216 int RenderObject::caretMaxOffset() const
2217 {
2218     if (isReplaced())
2219         return node() ? max(1U, node()->childNodeCount()) : 1;
2220     if (isHR())
2221         return 1;
2222     return 0;
2223 }
2224
2225 unsigned RenderObject::caretMaxRenderedOffset() const
2226 {
2227     return 0;
2228 }
2229
2230 int RenderObject::previousOffset(int current) const
2231 {
2232     return current - 1;
2233 }
2234
2235 int RenderObject::previousOffsetForBackwardDeletion(int current) const
2236 {
2237     return current - 1;
2238 }
2239
2240 int RenderObject::nextOffset(int current) const
2241 {
2242     return current + 1;
2243 }
2244
2245 void RenderObject::adjustRectForOutlineAndShadow(IntRect& rect) const
2246 {
2247     int outlineSize = outlineStyleForRepaint()->outlineSize();
2248     if (ShadowData* boxShadow = style()->boxShadow()) {
2249         int shadowLeft = 0;
2250         int shadowRight = 0;
2251         int shadowTop = 0;
2252         int shadowBottom = 0;
2253
2254         do {
2255             if (boxShadow->style == Normal) {
2256                 shadowLeft = min(boxShadow->x - boxShadow->blur - boxShadow->spread - outlineSize, shadowLeft);
2257                 shadowRight = max(boxShadow->x + boxShadow->blur + boxShadow->spread + outlineSize, shadowRight);
2258                 shadowTop = min(boxShadow->y - boxShadow->blur - boxShadow->spread - outlineSize, shadowTop);
2259                 shadowBottom = max(boxShadow->y + boxShadow->blur + boxShadow->spread + outlineSize, shadowBottom);
2260             }
2261
2262             boxShadow = boxShadow->next;
2263         } while (boxShadow);
2264
2265         rect.move(shadowLeft, shadowTop);
2266         rect.setWidth(rect.width() - shadowLeft + shadowRight);
2267         rect.setHeight(rect.height() - shadowTop + shadowBottom);
2268     } else
2269         rect.inflate(outlineSize);
2270 }
2271
2272 AnimationController* RenderObject::animation() const
2273 {
2274     return document()->frame()->animation();
2275 }
2276
2277 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
2278 {
2279     imageChanged(static_cast<WrappedImagePtr>(image), rect);
2280 }
2281
2282 RenderBoxModelObject* RenderObject::offsetParent() const
2283 {
2284     // If any of the following holds true return null and stop this algorithm:
2285     // A is the root element.
2286     // A is the HTML body element.
2287     // The computed value of the position property for element A is fixed.
2288     if (isRoot() || isBody() || (isPositioned() && style()->position() == FixedPosition))
2289         return 0;
2290
2291     // If A is an area HTML element which has a map HTML element somewhere in the ancestor
2292     // chain return the nearest ancestor map HTML element and stop this algorithm.
2293     // FIXME: Implement!
2294     
2295     // Return the nearest ancestor element of A for which at least one of the following is
2296     // true and stop this algorithm if such an ancestor is found:
2297     //     * The computed value of the position property is not static.
2298     //     * It is the HTML body element.
2299     //     * The computed value of the position property of A is static and the ancestor
2300     //       is one of the following HTML elements: td, th, or table.
2301     //     * Our own extension: if there is a difference in the effective zoom
2302     bool skipTables = isPositioned() || isRelPositioned();
2303     float currZoom = style()->effectiveZoom();
2304     RenderObject* curr = parent();
2305     while (curr && (!curr->node() ||
2306                     (!curr->isPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
2307         Node* element = curr->node();
2308         if (!skipTables && element) {
2309             bool isTableElement = element->hasTagName(tableTag) ||
2310                                   element->hasTagName(tdTag) ||
2311                                   element->hasTagName(thTag);
2312
2313 #if ENABLE(WML)
2314             if (!isTableElement && element->isWMLElement())
2315                 isTableElement = element->hasTagName(WMLNames::tableTag) ||
2316                                  element->hasTagName(WMLNames::tdTag);
2317 #endif
2318
2319             if (isTableElement)
2320                 break;
2321         }
2322
2323         float newZoom = curr->style()->effectiveZoom();
2324         if (currZoom != newZoom)
2325             break;
2326         currZoom = newZoom;
2327         curr = curr->parent();
2328     }
2329     return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
2330 }
2331
2332 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
2333 {
2334     // If this is a non-anonymous renderer, then it's simple.
2335     if (Node* node = this->node())
2336         return VisiblePosition(node, offset, affinity);
2337
2338     // We don't want to cross the boundary between editable and non-editable
2339     // regions of the document, but that is either impossible or at least
2340     // extremely unlikely in any normal case because we stop as soon as we
2341     // find a single non-anonymous renderer.
2342
2343     // Find a nearby non-anonymous renderer.
2344     RenderObject* child = this;
2345     while (RenderObject* parent = child->parent()) {
2346         // Find non-anonymous content after.
2347         RenderObject* renderer = child;
2348         while ((renderer = renderer->nextInPreOrder(parent))) {
2349             if (Node* node = renderer->node())
2350                 return VisiblePosition(node, 0, DOWNSTREAM);
2351         }
2352
2353         // Find non-anonymous content before.
2354         renderer = child;
2355         while ((renderer = renderer->previousInPreOrder())) {
2356             if (renderer == parent)
2357                 break;
2358             if (Node* node = renderer->node())
2359                 return VisiblePosition(lastDeepEditingPositionForNode(node), DOWNSTREAM);
2360         }
2361
2362         // Use the parent itself unless it too is anonymous.
2363         if (Node* node = parent->node())
2364             return VisiblePosition(node, 0, DOWNSTREAM);
2365
2366         // Repeat at the next level up.
2367         child = parent;
2368     }
2369
2370     // Everything was anonymous. Give up.
2371     return VisiblePosition();
2372 }
2373
2374 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
2375 {
2376     if (position.isNotNull())
2377         return VisiblePosition(position);
2378
2379     ASSERT(!node());
2380     return createVisiblePosition(0, DOWNSTREAM);
2381 }
2382
2383 #if ENABLE(SVG)
2384
2385 FloatRect RenderObject::objectBoundingBox() const
2386 {
2387     ASSERT_NOT_REACHED();
2388     return FloatRect();
2389 }
2390
2391 // Returns the smallest rectangle enclosing all of the painted content
2392 // respecting clipping, masking, filters, opacity, stroke-width and markers
2393 FloatRect RenderObject::repaintRectInLocalCoordinates() const
2394 {
2395     ASSERT_NOT_REACHED();
2396     return FloatRect();
2397 }
2398
2399 TransformationMatrix RenderObject::localTransform() const
2400 {
2401     return TransformationMatrix();
2402 }
2403
2404 TransformationMatrix RenderObject::localToParentTransform() const
2405 {
2406     // FIXME: This double virtual call indirection is temporary until I can land the
2407     // rest of the of the localToParentTransform() support for SVG.
2408     return localTransform();
2409 }
2410
2411 TransformationMatrix RenderObject::absoluteTransform() const
2412 {
2413     // FIXME: This should use localToParentTransform(), but much of the SVG code
2414     // depends on RenderBox::absoluteTransform() being the sum of the localTransform()s of all parent renderers.
2415     if (parent())
2416         return localTransform() * parent()->absoluteTransform();
2417     return localTransform();
2418 }
2419
2420 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
2421 {
2422     ASSERT_NOT_REACHED();
2423     return false;
2424 }
2425
2426 #endif // ENABLE(SVG)
2427
2428 } // namespace WebCore
2429
2430 #ifndef NDEBUG
2431
2432 void showTree(const WebCore::RenderObject* ro)
2433 {
2434     if (ro)
2435         ro->showTreeForThis();
2436 }
2437
2438 #endif