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