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