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/)
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.
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.
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.
28 #include "core/rendering/RenderObject.h"
30 #include "HTMLNames.h"
31 #include "RuntimeEnabledFeatures.h"
32 #include "core/accessibility/AXObjectCache.h"
33 #include "core/animation/ActiveAnimations.h"
34 #include "core/css/resolver/StyleResolver.h"
35 #include "core/editing/EditingBoundary.h"
36 #include "core/editing/FrameSelection.h"
37 #include "core/editing/htmlediting.h"
38 #include "core/fetch/ResourceLoadPriorityOptimizer.h"
39 #include "core/fetch/ResourceLoader.h"
40 #include "core/html/HTMLAnchorElement.h"
41 #include "core/html/HTMLElement.h"
42 #include "core/html/HTMLHtmlElement.h"
43 #include "core/html/HTMLTableElement.h"
44 #include "core/page/AutoscrollController.h"
45 #include "core/page/EventHandler.h"
46 #include "core/frame/Frame.h"
47 #include "core/frame/FrameView.h"
48 #include "core/page/Page.h"
49 #include "core/frame/Settings.h"
50 #include "core/frame/UseCounter.h"
51 #include "core/rendering/CompositedLayerMapping.h"
52 #include "core/rendering/FlowThreadController.h"
53 #include "core/rendering/HitTestResult.h"
54 #include "core/rendering/LayoutRectRecorder.h"
55 #include "core/rendering/RenderCounter.h"
56 #include "core/rendering/RenderDeprecatedFlexibleBox.h"
57 #include "core/rendering/RenderFlexibleBox.h"
58 #include "core/rendering/RenderFlowThread.h"
59 #include "core/rendering/RenderGeometryMap.h"
60 #include "core/rendering/RenderGrid.h"
61 #include "core/rendering/RenderImage.h"
62 #include "core/rendering/RenderImageResourceStyleImage.h"
63 #include "core/rendering/RenderInline.h"
64 #include "core/rendering/RenderLayer.h"
65 #include "core/rendering/RenderLayerCompositor.h"
66 #include "core/rendering/RenderListItem.h"
67 #include "core/rendering/RenderMarquee.h"
68 #include "core/rendering/RenderMultiColumnBlock.h"
69 #include "core/rendering/RenderScrollbarPart.h"
70 #include "core/rendering/RenderTableCaption.h"
71 #include "core/rendering/RenderTableCell.h"
72 #include "core/rendering/RenderTableCol.h"
73 #include "core/rendering/RenderTableRow.h"
74 #include "core/rendering/RenderTheme.h"
75 #include "core/rendering/RenderView.h"
76 #include "core/rendering/style/ContentData.h"
77 #include "core/rendering/style/CursorList.h"
78 #include "core/rendering/style/ShadowList.h"
79 #include "core/rendering/svg/SVGRenderSupport.h"
80 #include "platform/Partitions.h"
81 #include "platform/geometry/TransformState.h"
82 #include "platform/graphics/GraphicsContext.h"
83 #include "wtf/RefCountedLeakCounter.h"
84 #include "wtf/text/StringBuilder.h"
94 using namespace HTMLNames;
98 RenderObject::SetLayoutNeededForbiddenScope::SetLayoutNeededForbiddenScope(RenderObject* renderObject)
99 : m_renderObject(renderObject)
100 , m_preexistingForbidden(m_renderObject->isSetNeedsLayoutForbidden())
102 m_renderObject->setNeedsLayoutIsForbidden(true);
105 RenderObject::SetLayoutNeededForbiddenScope::~SetLayoutNeededForbiddenScope()
107 m_renderObject->setNeedsLayoutIsForbidden(m_preexistingForbidden);
111 struct SameSizeAsRenderObject {
112 virtual ~SameSizeAsRenderObject() { } // Allocate vtable pointer.
115 unsigned m_debugBitfields : 2;
117 unsigned m_bitfields;
118 unsigned m_bitfields2;
119 LayoutRect rects[2]; // Stores the old/new repaint rects.
122 COMPILE_ASSERT(sizeof(RenderObject) == sizeof(SameSizeAsRenderObject), RenderObject_should_stay_small);
124 bool RenderObject::s_affectsParentBlock = false;
126 void* RenderObject::operator new(size_t sz)
128 ASSERT(isMainThread());
129 return partitionAlloc(Partitions::getRenderingPartition(), sz);
132 void RenderObject::operator delete(void* ptr)
134 ASSERT(isMainThread());
138 RenderObject* RenderObject::createObject(Element* element, RenderStyle* style)
140 // Minimal support for content properties replacing an entire element.
141 // Works only if we have exactly one piece of content and it's a URL.
142 // Otherwise acts as if we didn't support this feature.
143 const ContentData* contentData = style->contentData();
144 if (contentData && !contentData->next() && contentData->isImage() && !element->isPseudoElement()) {
145 RenderImage* image = new RenderImage(element);
146 // RenderImageResourceStyleImage requires a style being present on the image but we don't want to
147 // trigger a style change now as the node is not fully attached. Moving this code to style change
148 // doesn't make sense as it should be run once at renderer creation.
149 image->setStyleInternal(style);
150 if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image()) {
151 image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
152 image->setIsGeneratedContent();
154 image->setImageResource(RenderImageResource::create());
155 image->setStyleInternal(0);
159 switch (style->display()) {
163 return new RenderInline(element);
166 if ((!style->hasAutoColumnCount() || !style->hasAutoColumnWidth()) && element->document().regionBasedColumnsEnabled())
167 return new RenderMultiColumnBlock(element);
168 return new RenderBlockFlow(element);
170 return new RenderListItem(element);
173 return new RenderTable(element);
174 case TABLE_ROW_GROUP:
175 case TABLE_HEADER_GROUP:
176 case TABLE_FOOTER_GROUP:
177 return new RenderTableSection(element);
179 return new RenderTableRow(element);
180 case TABLE_COLUMN_GROUP:
182 return new RenderTableCol(element);
184 return new RenderTableCell(element);
186 return new RenderTableCaption(element);
189 return new RenderDeprecatedFlexibleBox(element);
192 return new RenderFlexibleBox(element);
195 return new RenderGrid(element);
201 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject"));
203 RenderObject::RenderObject(Node* node)
204 : ImageResourceClient()
211 , m_hasAXObject(false)
212 , m_setNeedsLayoutForbidden(false)
217 renderObjectCounter.increment();
221 RenderObject::~RenderObject()
223 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->removeRenderObject(this);
225 ASSERT(!m_hasAXObject);
226 renderObjectCounter.decrement();
230 String RenderObject::debugName() const
233 name.append(renderName());
235 if (Node* node = this->node()) {
237 name.append(node->debugName());
240 return name.toString();
243 bool RenderObject::isDescendantOf(const RenderObject* obj) const
245 for (const RenderObject* r = this; r; r = r->m_parent) {
252 bool RenderObject::isBody() const
254 return node() && node()->hasTagName(bodyTag);
257 bool RenderObject::isHR() const
259 return node() && node()->hasTagName(hrTag);
262 bool RenderObject::isLegend() const
264 return node() && node()->hasTagName(legendTag);
267 void RenderObject::setFlowThreadStateIncludingDescendants(FlowThreadState state)
269 for (RenderObject *object = this; object; object = object->nextInPreOrder(this)) {
270 // If object is a fragmentation context it already updated the descendants flag accordingly.
271 if (object->isRenderFlowThread())
273 ASSERT(state != object->flowThreadState());
274 object->setFlowThreadState(state);
278 bool RenderObject::requiresAnonymousTableWrappers(const RenderObject* newChild) const
280 // Check should agree with:
281 // CSS 2.1 Tables: 17.2.1 Anonymous table objects
282 // http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes
283 if (newChild->isRenderTableCol()) {
284 const RenderTableCol* newTableColumn = toRenderTableCol(newChild);
285 bool isColumnInColumnGroup = newTableColumn->isTableColumn() && isRenderTableCol();
286 return !isTable() && !isColumnInColumnGroup;
287 } else if (newChild->isTableCaption())
289 else if (newChild->isTableSection())
291 else if (newChild->isTableRow())
292 return !isTableSection();
293 else if (newChild->isTableCell())
294 return !isTableRow();
298 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
300 RenderObjectChildList* children = virtualChildren();
305 if (requiresAnonymousTableWrappers(newChild)) {
306 // Generate an anonymous table or reuse existing one from previous child
307 // Per: 17.2.1 Anonymous table objects 3. Generate missing parents
308 // http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes
310 RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
311 if (afterChild && afterChild->isAnonymous() && afterChild->isTable() && !afterChild->isBeforeContent())
312 table = toRenderTable(afterChild);
314 table = RenderTable::createAnonymousWithParentRenderer(this);
315 addChild(table, beforeChild);
317 table->addChild(newChild);
319 children->insertChildNode(this, newChild, beforeChild);
321 if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE)
322 toRenderText(newChild)->transformText();
324 // SVG creates renderers for <g display="none">, as SVG requires children of hidden
325 // <g>s to have renderers - at least that's how our implementation works. Consider:
326 // <g display="none"><foreignObject><body style="position: relative">FOO...
327 // - layerTypeRequired() would return true for the <body>, creating a new RenderLayer
328 // - when the document is painted, both layers are painted. The <body> layer doesn't
329 // know that it's inside a "hidden SVG subtree", and thus paints, even if it shouldn't.
330 // To avoid the problem alltogether, detect early if we're inside a hidden SVG subtree
331 // and stop creating layers at all for these cases - they're not used anyways.
332 if (newChild->hasLayer() && !layerCreationAllowedForSubtree())
333 toRenderLayerModelObject(newChild)->layer()->removeOnlyThisLayer();
336 void RenderObject::removeChild(RenderObject* oldChild)
338 RenderObjectChildList* children = virtualChildren();
343 children->removeChildNode(this, oldChild);
346 RenderObject* RenderObject::nextInPreOrder() const
348 if (RenderObject* o = firstChild())
351 return nextInPreOrderAfterChildren();
354 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
357 if (!(o = nextSibling())) {
359 while (o && !o->nextSibling())
362 o = o->nextSibling();
368 RenderObject* RenderObject::nextInPreOrder(const RenderObject* stayWithin) const
370 if (RenderObject* o = firstChild())
373 return nextInPreOrderAfterChildren(stayWithin);
376 RenderObject* RenderObject::nextInPreOrderAfterChildren(const RenderObject* stayWithin) const
378 if (this == stayWithin)
381 const RenderObject* current = this;
383 while (!(next = current->nextSibling())) {
384 current = current->parent();
385 if (!current || current == stayWithin)
391 RenderObject* RenderObject::previousInPreOrder() const
393 if (RenderObject* o = previousSibling()) {
394 while (o->lastChild())
402 RenderObject* RenderObject::previousInPreOrder(const RenderObject* stayWithin) const
404 if (this == stayWithin)
407 return previousInPreOrder();
410 RenderObject* RenderObject::childAt(unsigned index) const
412 RenderObject* child = firstChild();
413 for (unsigned i = 0; child && i < index; i++)
414 child = child->nextSibling();
418 RenderObject* RenderObject::lastLeafChild() const
420 RenderObject* r = lastChild();
431 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
432 RenderLayer*& beforeChild)
434 if (obj->hasLayer()) {
435 if (!beforeChild && newObject) {
436 // We need to figure out the layer that follows newObject. We only do
437 // this the first time we find a child layer, and then we update the
438 // pointer values for newObject and beforeChild used by everyone else.
439 beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
442 parentLayer->addChild(toRenderLayerModelObject(obj)->layer(), beforeChild);
446 for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
447 addLayers(curr, parentLayer, newObject, beforeChild);
450 void RenderObject::addLayers(RenderLayer* parentLayer)
455 RenderObject* object = this;
456 RenderLayer* beforeChild = 0;
457 WebCore::addLayers(this, parentLayer, object, beforeChild);
460 void RenderObject::removeLayers(RenderLayer* parentLayer)
466 parentLayer->removeChild(toRenderLayerModelObject(this)->layer());
470 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
471 curr->removeLayers(parentLayer);
474 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
480 RenderLayer* layer = toRenderLayerModelObject(this)->layer();
481 ASSERT(oldParent == layer->parent());
483 oldParent->removeChild(layer);
484 newParent->addChild(layer);
488 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
489 curr->moveLayers(oldParent, newParent);
492 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
495 // Error check the parent layer passed in. If it's null, we can't find anything.
499 // Step 1: If our layer is a child of the desired parent, then return our layer.
500 RenderLayer* ourLayer = hasLayer() ? toRenderLayerModelObject(this)->layer() : 0;
501 if (ourLayer && ourLayer->parent() == parentLayer)
504 // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
505 // into our siblings trying to find the next layer whose parent is the desired parent.
506 if (!ourLayer || ourLayer == parentLayer) {
507 for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
508 curr; curr = curr->nextSibling()) {
509 RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
515 // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
517 if (parentLayer == ourLayer)
520 // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
521 // follow us to see if we can locate a layer.
522 if (checkParent && parent())
523 return parent()->findNextLayer(parentLayer, this, true);
528 RenderLayer* RenderObject::enclosingLayer() const
530 const RenderObject* curr = this;
532 RenderLayer* layer = curr->hasLayer() ? toRenderLayerModelObject(curr)->layer() : 0;
535 curr = curr->parent();
540 bool RenderObject::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
542 RenderBox* enclosingBox = this->enclosingBox();
546 enclosingBox->scrollRectToVisible(rect, alignX, alignY);
550 RenderBox* RenderObject::enclosingBox() const
552 RenderObject* curr = const_cast<RenderObject*>(this);
555 return toRenderBox(curr);
556 curr = curr->parent();
559 ASSERT_NOT_REACHED();
563 RenderBoxModelObject* RenderObject::enclosingBoxModelObject() const
565 RenderObject* curr = const_cast<RenderObject*>(this);
567 if (curr->isBoxModelObject())
568 return toRenderBoxModelObject(curr);
569 curr = curr->parent();
572 ASSERT_NOT_REACHED();
576 RenderBox* RenderObject::enclosingScrollableBox() const
578 for (RenderObject* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
579 if (!ancestor->isBox())
582 RenderBox* ancestorBox = toRenderBox(ancestor);
583 if (ancestorBox->canBeScrolledAndHasScrollableArea())
590 RenderFlowThread* RenderObject::locateFlowThreadContainingBlock() const
592 ASSERT(flowThreadState() != NotInsideFlowThread);
594 // See if we have the thread cached because we're in the middle of layout.
595 RenderFlowThread* flowThread = view()->flowThreadController()->currentRenderFlowThread();
599 // Not in the middle of layout so have to find the thread the slow way.
600 RenderObject* curr = const_cast<RenderObject*>(this);
602 if (curr->isRenderFlowThread())
603 return toRenderFlowThread(curr);
604 curr = curr->containingBlock();
609 RenderBlock* RenderObject::firstLineBlock() const
614 static inline bool objectIsRelayoutBoundary(const RenderObject* object)
616 // FIXME: In future it may be possible to broaden these conditions in order to improve performance.
617 if (object->isTextControl())
620 if (object->isSVGRoot())
623 if (!object->hasOverflowClip())
626 if (object->style()->width().isIntrinsicOrAuto() || object->style()->height().isIntrinsicOrAuto() || object->style()->height().isPercent())
629 // Table parts can't be relayout roots since the table is responsible for layouting all the parts.
630 if (object->isTablePart())
636 void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot, SubtreeLayoutScope* layouter)
638 ASSERT(!scheduleRelayout || !newRoot);
639 ASSERT(!isSetNeedsLayoutForbidden());
640 ASSERT(!layouter || this != layouter->root());
642 RenderObject* object = container();
643 RenderObject* last = this;
645 bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout();
648 if (object->selfNeedsLayout())
651 // Don't mark the outermost object of an unrooted subtree. That object will be
652 // marked when the subtree is added to the document.
653 RenderObject* container = object->container();
654 if (!container && !object->isRenderView())
656 if (!last->isText() && last->style()->hasOutOfFlowPosition()) {
657 bool willSkipRelativelyPositionedInlines = !object->isRenderBlock() || object->isAnonymousBlock();
658 // Skip relatively positioned inlines and anonymous blocks to get to the enclosing RenderBlock.
659 while (object && (!object->isRenderBlock() || object->isAnonymousBlock()))
660 object = object->container();
661 if (!object || object->posChildNeedsLayout())
663 if (willSkipRelativelyPositionedInlines)
664 container = object->container();
665 object->setPosChildNeedsLayout(true);
666 simplifiedNormalFlowLayout = true;
667 ASSERT(!object->isSetNeedsLayoutForbidden());
668 } else if (simplifiedNormalFlowLayout) {
669 if (object->needsSimplifiedNormalFlowLayout())
671 object->setNeedsSimplifiedNormalFlowLayout(true);
672 ASSERT(!object->isSetNeedsLayoutForbidden());
674 if (object->normalChildNeedsLayout())
676 object->setNormalChildNeedsLayout(true);
677 ASSERT(!object->isSetNeedsLayoutForbidden());
681 layouter->addRendererToLayout(object);
682 if (object == layouter->root())
686 if (object == newRoot)
690 if (scheduleRelayout && objectIsRelayoutBoundary(last))
695 if (scheduleRelayout)
696 last->scheduleRelayout();
700 void RenderObject::checkBlockPositionedObjectsNeedLayout()
702 ASSERT(!needsLayout());
705 toRenderBlock(this)->checkPositionedObjectsNeedLayout();
708 void RenderObject::checkNotInPartialLayout()
710 // During partial layout, setNeedsLayout(true or false) should not be called.
711 ASSERT(!frameView()->partialLayout().isStopping());
715 void RenderObject::setPreferredLogicalWidthsDirty(MarkingBehavior markParents)
717 bool alreadyDirty = preferredLogicalWidthsDirty();
718 m_bitfields.setPreferredLogicalWidthsDirty(true);
719 if (!alreadyDirty && markParents == MarkContainingBlockChain && (isText() || !style()->hasOutOfFlowPosition()))
720 invalidateContainerPreferredLogicalWidths();
723 void RenderObject::clearPreferredLogicalWidthsDirty()
725 m_bitfields.setPreferredLogicalWidthsDirty(false);
728 void RenderObject::invalidateContainerPreferredLogicalWidths()
730 // In order to avoid pathological behavior when inlines are deeply nested, we do include them
731 // in the chain that we mark dirty (even though they're kind of irrelevant).
732 RenderObject* o = isTableCell() ? containingBlock() : container();
733 while (o && !o->preferredLogicalWidthsDirty()) {
734 // Don't invalidate the outermost object of an unrooted subtree. That object will be
735 // invalidated when the subtree is added to the document.
736 RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
737 if (!container && !o->isRenderView())
740 o->m_bitfields.setPreferredLogicalWidthsDirty(true);
741 if (o->style()->hasOutOfFlowPosition())
742 // A positioned object has no effect on the min/max width of its containing block ever.
743 // We can optimize this case and not go up any further.
749 void RenderObject::setLayerNeedsFullRepaint()
752 toRenderLayerModelObject(this)->layer()->repainter().setRepaintStatus(NeedsFullRepaint);
755 void RenderObject::setLayerNeedsFullRepaintForPositionedMovementLayout()
758 toRenderLayerModelObject(this)->layer()->repainter().setRepaintStatus(NeedsFullRepaintForPositionedMovementLayout);
761 RenderBlock* RenderObject::containerForFixedPosition(const RenderLayerModelObject* repaintContainer, bool* repaintContainerSkipped) const
763 ASSERT(!repaintContainerSkipped || !*repaintContainerSkipped);
765 ASSERT(style()->position() == FixedPosition);
767 RenderObject* ancestor = parent();
768 for (; ancestor && !ancestor->canContainFixedPositionObjects(); ancestor = ancestor->parent()) {
769 if (repaintContainerSkipped && ancestor == repaintContainer)
770 *repaintContainerSkipped = true;
773 ASSERT(!ancestor || !ancestor->isAnonymousBlock());
774 return toRenderBlock(ancestor);
777 RenderBlock* RenderObject::containingBlock() const
779 RenderObject* o = parent();
780 if (!o && isRenderScrollbarPart())
781 o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
782 if (!isText() && m_style->position() == FixedPosition) {
783 return containerForFixedPosition();
784 } else if (!isText() && m_style->position() == AbsolutePosition) {
786 // For relpositioned inlines, we return the nearest non-anonymous enclosing block. We don't try
787 // to return the inline itself. This allows us to avoid having a positioned objects
788 // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
789 // from this method. The container() method can actually be used to obtain the
791 if (o->style()->position() != StaticPosition && (!o->isInline() || o->isReplaced()))
794 if (o->canContainAbsolutePositionObjects())
797 if (o->style()->hasInFlowPosition() && o->isInline() && !o->isReplaced()) {
798 o = o->containingBlock();
805 if (o && !o->isRenderBlock())
806 o = o->containingBlock();
808 while (o && o->isAnonymousBlock())
809 o = o->containingBlock();
811 while (o && ((o->isInline() && !o->isReplaced()) || !o->isRenderBlock()))
815 if (!o || !o->isRenderBlock())
816 return 0; // This can still happen in case of an orphaned tree
818 return toRenderBlock(o);
821 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
823 // Nobody will use multiple layers without wanting fancy positioning.
827 // Make sure we have a valid image.
828 StyleImage* img = layer->image();
829 if (!img || !img->canRender(renderer, renderer->style()->effectiveZoom()))
832 if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
835 EFillSizeType sizeType = layer->sizeType();
837 if (sizeType == Contain || sizeType == Cover)
840 if (sizeType == SizeLength) {
841 if (layer->sizeLength().width().isPercent() || layer->sizeLength().height().isPercent())
843 if (img->isGeneratedImage() && (layer->sizeLength().width().isAuto() || layer->sizeLength().height().isAuto()))
845 } else if (img->usesImageContainerSize()) {
852 bool RenderObject::borderImageIsLoadedAndCanBeRendered() const
854 ASSERT(style()->hasBorder());
856 StyleImage* borderImage = style()->borderImage().image();
857 return borderImage && borderImage->canRender(this, style()->effectiveZoom()) && borderImage->isLoaded();
860 bool RenderObject::mustRepaintBackgroundOrBorder() const
862 if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
865 // If we don't have a background/border/mask, then nothing to do.
866 if (!hasBoxDecorations())
869 if (mustRepaintFillLayers(this, style()->backgroundLayers()))
872 // Our fill layers are ok. Let's check border.
873 if (style()->hasBorder() && borderImageIsLoadedAndCanBeRendered())
879 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
880 BoxSide side, Color color, EBorderStyle style,
881 int adjacentWidth1, int adjacentWidth2, bool antialias)
885 if (side == BSTop || side == BSBottom) {
893 // FIXME: We really would like this check to be an ASSERT as we don't want to draw empty borders. However
894 // nothing guarantees that the following recursive calls to drawLineForBoxSide will have non-null dimensions.
895 if (!thickness || !length)
898 if (style == DOUBLE && thickness < 3)
907 drawDashedOrDottedBoxSide(graphicsContext, x1, y1, x2, y2, side,
908 color, thickness, style, antialias);
911 drawDoubleBoxSide(graphicsContext, x1, y1, x2, y2, length, side, color,
912 thickness, adjacentWidth1, adjacentWidth2, antialias);
916 drawRidgeOrGrooveBoxSide(graphicsContext, x1, y1, x2, y2, side, color,
917 style, adjacentWidth1, adjacentWidth2, antialias);
920 // FIXME: Maybe we should lighten the colors on one side like Firefox.
921 // https://bugs.webkit.org/show_bug.cgi?id=58608
922 if (side == BSTop || side == BSLeft)
923 color = color.dark();
926 if (style == OUTSET && (side == BSBottom || side == BSRight))
927 color = color.dark();
930 drawSolidBoxSide(graphicsContext, x1, y1, x2, y2, side, color, adjacentWidth1, adjacentWidth2, antialias);
935 void RenderObject::drawDashedOrDottedBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
936 BoxSide side, Color color, int thickness, EBorderStyle style, bool antialias)
941 bool wasAntialiased = graphicsContext->shouldAntialias();
942 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
943 graphicsContext->setShouldAntialias(antialias);
944 graphicsContext->setStrokeColor(color);
945 graphicsContext->setStrokeThickness(thickness);
946 graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
951 graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
955 graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
958 graphicsContext->setShouldAntialias(wasAntialiased);
959 graphicsContext->setStrokeStyle(oldStrokeStyle);
962 void RenderObject::drawDoubleBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
963 int length, BoxSide side, Color color, int thickness, int adjacentWidth1, int adjacentWidth2, bool antialias)
965 int thirdOfThickness = (thickness + 1) / 3;
966 ASSERT(thirdOfThickness);
968 if (!adjacentWidth1 && !adjacentWidth2) {
969 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
970 graphicsContext->setStrokeStyle(NoStroke);
971 graphicsContext->setFillColor(color);
973 bool wasAntialiased = graphicsContext->shouldAntialias();
974 graphicsContext->setShouldAntialias(antialias);
979 graphicsContext->drawRect(IntRect(x1, y1, length, thirdOfThickness));
980 graphicsContext->drawRect(IntRect(x1, y2 - thirdOfThickness, length, thirdOfThickness));
984 // FIXME: Why do we offset the border by 1 in this case but not the other one?
986 graphicsContext->drawRect(IntRect(x1, y1 + 1, thirdOfThickness, length - 1));
987 graphicsContext->drawRect(IntRect(x2 - thirdOfThickness, y1 + 1, thirdOfThickness, length - 1));
992 graphicsContext->setShouldAntialias(wasAntialiased);
993 graphicsContext->setStrokeStyle(oldStrokeStyle);
997 int adjacent1BigThird = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3;
998 int adjacent2BigThird = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3;
1002 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
1003 y1, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
1004 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1005 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
1006 y2 - thirdOfThickness, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y2,
1007 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1010 drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
1011 x1 + thirdOfThickness, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
1012 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1013 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
1014 x2, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
1015 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1018 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
1019 y1, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
1020 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1021 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
1022 y2 - thirdOfThickness, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y2,
1023 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1026 drawLineForBoxSide(graphicsContext, x1, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
1027 x1 + thirdOfThickness, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
1028 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1029 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
1030 x2, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
1031 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
1038 void RenderObject::drawRidgeOrGrooveBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
1039 BoxSide side, Color color, EBorderStyle style, int adjacentWidth1, int adjacentWidth2, bool antialias)
1043 if (style == GROOVE) {
1051 int adjacent1BigHalf = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2;
1052 int adjacent2BigHalf = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2;
1056 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1, 0) / 2, y1, x2 - max(-adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
1057 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
1058 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjacentWidth2 + 1, 0) / 2, y2,
1059 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1062 drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjacentWidth2, 0) / 2,
1063 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
1064 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjacentWidth1 + 1, 0) / 2, x2, y2 - max(adjacentWidth2 + 1, 0) / 2,
1065 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1068 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1, 0) / 2, y1, x2 - max(adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
1069 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
1070 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjacentWidth2 + 1, 0) / 2, y2,
1071 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1074 drawLineForBoxSide(graphicsContext, x1, y1 + max(adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjacentWidth2, 0) / 2,
1075 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
1076 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjacentWidth1 + 1, 0) / 2, x2, y2 - max(-adjacentWidth2 + 1, 0) / 2,
1077 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1082 void RenderObject::drawSolidBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
1083 BoxSide side, Color color, int adjacentWidth1, int adjacentWidth2, bool antialias)
1085 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
1086 graphicsContext->setStrokeStyle(NoStroke);
1087 graphicsContext->setFillColor(color);
1090 if (!adjacentWidth1 && !adjacentWidth2) {
1091 // Turn off antialiasing to match the behavior of drawConvexPolygon();
1092 // this matters for rects in transformed contexts.
1093 bool wasAntialiased = graphicsContext->shouldAntialias();
1094 graphicsContext->setShouldAntialias(antialias);
1095 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1096 graphicsContext->setShouldAntialias(wasAntialiased);
1097 graphicsContext->setStrokeStyle(oldStrokeStyle);
1103 quad[0] = FloatPoint(x1 + max(-adjacentWidth1, 0), y1);
1104 quad[1] = FloatPoint(x1 + max(adjacentWidth1, 0), y2);
1105 quad[2] = FloatPoint(x2 - max(adjacentWidth2, 0), y2);
1106 quad[3] = FloatPoint(x2 - max(-adjacentWidth2, 0), y1);
1109 quad[0] = FloatPoint(x1 + max(adjacentWidth1, 0), y1);
1110 quad[1] = FloatPoint(x1 + max(-adjacentWidth1, 0), y2);
1111 quad[2] = FloatPoint(x2 - max(-adjacentWidth2, 0), y2);
1112 quad[3] = FloatPoint(x2 - max(adjacentWidth2, 0), y1);
1115 quad[0] = FloatPoint(x1, y1 + max(-adjacentWidth1, 0));
1116 quad[1] = FloatPoint(x1, y2 - max(-adjacentWidth2, 0));
1117 quad[2] = FloatPoint(x2, y2 - max(adjacentWidth2, 0));
1118 quad[3] = FloatPoint(x2, y1 + max(adjacentWidth1, 0));
1121 quad[0] = FloatPoint(x1, y1 + max(adjacentWidth1, 0));
1122 quad[1] = FloatPoint(x1, y2 - max(adjacentWidth2, 0));
1123 quad[2] = FloatPoint(x2, y2 - max(-adjacentWidth2, 0));
1124 quad[3] = FloatPoint(x2, y1 + max(-adjacentWidth1, 0));
1128 graphicsContext->drawConvexPolygon(4, quad, antialias);
1129 graphicsContext->setStrokeStyle(oldStrokeStyle);
1132 void RenderObject::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paintOffset, RenderStyle* style)
1134 Vector<IntRect> focusRingRects;
1135 addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer());
1136 if (style->outlineStyleIsAuto())
1137 paintInfo.context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), resolveColor(style, CSSPropertyOutlineColor));
1139 addPDFURLRect(paintInfo.context, unionRect(focusRingRects));
1142 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
1147 if (!n || !n->isLink() || !n->isElementNode())
1149 const AtomicString& href = toElement(n)->getAttribute(hrefAttr);
1152 KURL url = n->document().completeURL(href);
1155 if (context->supportsURLFragments() && url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(url, n->document().baseURL())) {
1156 String name = url.fragmentIdentifier();
1157 if (document().findAnchor(name))
1158 context->setURLFragmentForRect(name, pixelSnappedIntRect(rect));
1161 context->setURLForRect(url, pixelSnappedIntRect(rect));
1164 void RenderObject::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRect)
1169 RenderStyle* styleToUse = style();
1170 LayoutUnit outlineWidth = styleToUse->outlineWidth();
1172 int outlineOffset = styleToUse->outlineOffset();
1174 if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1175 if (RenderTheme::theme().shouldDrawDefaultFocusRing(this)) {
1176 // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1177 paintFocusRing(paintInfo, paintRect.location(), styleToUse);
1181 if (styleToUse->outlineStyleIsAuto() || styleToUse->outlineStyle() == BNONE)
1184 IntRect inner = pixelSnappedIntRect(paintRect);
1185 inner.inflate(outlineOffset);
1187 IntRect outer = pixelSnappedIntRect(inner);
1188 outer.inflate(outlineWidth);
1190 // FIXME: This prevents outlines from painting inside the object. See bug 12042
1191 if (outer.isEmpty())
1194 EBorderStyle outlineStyle = styleToUse->outlineStyle();
1195 Color outlineColor = resolveColor(styleToUse, CSSPropertyOutlineColor);
1197 GraphicsContext* graphicsContext = paintInfo.context;
1198 bool useTransparencyLayer = outlineColor.hasAlpha();
1199 if (useTransparencyLayer) {
1200 if (outlineStyle == SOLID) {
1202 path.addRect(outer);
1203 path.addRect(inner);
1204 graphicsContext->setFillRule(RULE_EVENODD);
1205 graphicsContext->setFillColor(outlineColor);
1206 graphicsContext->fillPath(path);
1209 graphicsContext->beginTransparencyLayer(static_cast<float>(outlineColor.alpha()) / 255);
1210 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineColor.blue());
1213 int leftOuter = outer.x();
1214 int leftInner = inner.x();
1215 int rightOuter = outer.maxX();
1216 int rightInner = inner.maxX();
1217 int topOuter = outer.y();
1218 int topInner = inner.y();
1219 int bottomOuter = outer.maxY();
1220 int bottomInner = inner.maxY();
1222 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1223 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInner, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1224 drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottomOuter, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1225 drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bottomOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1227 if (useTransparencyLayer)
1228 graphicsContext->endLayer();
1231 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) const
1233 if (useTransforms) {
1234 Vector<FloatQuad> quads;
1235 absoluteQuads(quads);
1237 size_t n = quads.size();
1241 IntRect result = quads[0].enclosingBoundingBox();
1242 for (size_t i = 1; i < n; ++i)
1243 result.unite(quads[i].enclosingBoundingBox());
1247 FloatPoint absPos = localToAbsolute();
1248 Vector<IntRect> rects;
1249 absoluteRects(rects, flooredLayoutPoint(absPos));
1251 size_t n = rects.size();
1255 LayoutRect result = rects[0];
1256 for (size_t i = 1; i < n; ++i)
1257 result.unite(rects[i]);
1258 return pixelSnappedIntRect(result);
1261 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1263 Vector<IntRect> rects;
1264 // FIXME: addFocusRingRects() needs to be passed this transform-unaware
1265 // localToAbsolute() offset here because RenderInline::addFocusRingRects()
1266 // implicitly assumes that. This doesn't work correctly with transformed
1268 FloatPoint absolutePoint = localToAbsolute();
1269 addFocusRingRects(rects, flooredLayoutPoint(absolutePoint));
1270 size_t count = rects.size();
1271 for (size_t i = 0; i < count; ++i) {
1272 IntRect rect = rects[i];
1273 rect.move(-absolutePoint.x(), -absolutePoint.y());
1274 quads.append(localToAbsoluteQuad(FloatQuad(rect)));
1278 FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range)
1280 if (!range || !range->startContainer())
1283 range->ownerDocument().updateLayout();
1285 Vector<FloatQuad> quads;
1286 range->textQuads(quads);
1289 for (size_t i = 0; i < quads.size(); ++i)
1290 result.unite(quads[i].boundingBox());
1295 void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
1298 result.unite(absoluteBoundingBoxRectIgnoringTransforms());
1299 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1300 current->addAbsoluteRectForLayer(result);
1303 LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect)
1305 LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms();
1306 topLevelRect = result;
1307 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1308 current->addAbsoluteRectForLayer(result);
1312 void RenderObject::paint(PaintInfo&, const LayoutPoint&)
1316 RenderLayerModelObject* RenderObject::containerForRepaint() const
1318 RenderView* v = view();
1322 RenderLayerModelObject* repaintContainer = 0;
1324 if (v->usesCompositing()) {
1325 if (RenderLayer* parentLayer = enclosingLayer()) {
1326 // FIXME: CompositingState is not necessarily up to date for many callers of this function.
1327 DisableCompositingQueryAsserts disabler;
1329 RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint();
1331 repaintContainer = compLayer->renderer();
1335 if (document().view()->hasSoftwareFilters()) {
1336 if (RenderLayer* parentLayer = enclosingLayer()) {
1337 RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer();
1338 if (enclosingFilterLayer)
1339 return enclosingFilterLayer->renderer();
1343 // If we have a flow thread, then we need to do individual repaints within the RenderRegions instead.
1344 // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change
1345 // repainting to do individual region repaints.
1346 RenderFlowThread* parentRenderFlowThread = flowThreadContainingBlock();
1347 if (parentRenderFlowThread) {
1348 // The ancestor document will do the reparenting when the repaint propagates further up.
1349 // We're just a seamless child document, and we don't need to do the hacking.
1350 if (parentRenderFlowThread->document() != document())
1351 return repaintContainer;
1352 // If we have already found a repaint container then we will repaint into that container only if it is part of the same
1353 // flow thread. Otherwise we will need to catch the repaint call and send it to the flow thread.
1354 RenderFlowThread* repaintContainerFlowThread = repaintContainer ? repaintContainer->flowThreadContainingBlock() : 0;
1355 if (!repaintContainerFlowThread || repaintContainerFlowThread != parentRenderFlowThread)
1356 repaintContainer = parentRenderFlowThread;
1358 return repaintContainer;
1361 void RenderObject::repaintUsingContainer(const RenderLayerModelObject* repaintContainer, const IntRect& r) const
1363 if (!repaintContainer) {
1364 view()->repaintViewRectangle(r);
1368 // FIXME: Don't read compositing state here since we do this in the middle of recalc/layout.
1369 DisableCompositingQueryAsserts disabler;
1370 if (repaintContainer->compositingState() == PaintsIntoGroupedBacking) {
1371 ASSERT(repaintContainer->groupedMapping());
1373 // Not clean, but if squashing layer does not yet exist here (e.g. repaint invalidation coming from within recomputing compositing requirements)
1374 // then it's ok to just exit here, since the squashing layer will get repainted when it is newly created.
1375 if (!repaintContainer->groupedMapping()->squashingLayer())
1379 IntRect offsetRect(r);
1381 // First, convert the repaint rect into the space of the repaintContainer
1382 TransformState transformState(TransformState::ApplyTransformDirection, FloatQuad(FloatRect(r)));
1383 mapLocalToContainer(repaintContainer, transformState, ApplyContainerFlip);
1384 transformState.flatten();
1385 offsetRect = transformState.lastPlanarQuad().enclosingBoundingBox();
1387 // FIXME: the repaint rect computed below could be tighter in uncommon nested transform cases, if we passed the quad
1388 // directly to the next chunk of code.
1390 // Then, convert the repaint rect from repaintConainer space into the squashing GraphicsLayer's coordinates.
1391 if (repaintContainer->hasTransform())
1392 offsetRect = repaintContainer->layer()->transform()->mapRect(r);
1393 offsetRect.move(-repaintContainer->layer()->offsetFromSquashingLayerOrigin());
1394 repaintContainer->groupedMapping()->squashingLayer()->setNeedsDisplayInRect(offsetRect);
1398 if (repaintContainer->isRenderFlowThread()) {
1399 toRenderFlowThread(repaintContainer)->repaintRectangleInRegions(r);
1403 if (repaintContainer->hasFilter() && repaintContainer->layer()->requiresFullLayerImageForFilters()) {
1404 repaintContainer->layer()->repainter().setFilterBackendNeedsRepaintingInRect(r);
1408 RenderView* v = view();
1409 if (repaintContainer->isRenderView()) {
1410 ASSERT(repaintContainer == v);
1411 bool viewHasCompositedLayer = v->hasLayer() && v->layer()->compositingState() == PaintsIntoOwnBacking;
1412 if (!viewHasCompositedLayer) {
1413 v->repaintViewRectangle(r);
1418 if (v->usesCompositing()) {
1419 ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->compositingState() == PaintsIntoOwnBacking);
1420 repaintContainer->layer()->repainter().setBackingNeedsRepaintInRect(r);
1424 void RenderObject::repaint() const
1426 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1428 if (!isRooted(&view))
1431 if (view->document().printing())
1432 return; // Don't repaint if we're printing.
1434 // FIXME: really, we're in the repaint phase here, and the following queries are legal.
1435 // Until those states are fully fledged, I'll just disable the ASSERTS.
1436 DisableCompositingQueryAsserts disabler;
1437 RenderLayerModelObject* repaintContainer = containerForRepaint();
1438 repaintUsingContainer(repaintContainer ? repaintContainer : view, pixelSnappedIntRect(clippedOverflowRectForRepaint(repaintContainer)));
1441 void RenderObject::repaintRectangle(const LayoutRect& r) const
1443 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1445 if (!isRooted(&view))
1448 if (view->document().printing())
1449 return; // Don't repaint if we're printing.
1451 LayoutRect dirtyRect(r);
1453 if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) {
1454 // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1455 // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1456 dirtyRect.move(view->layoutDelta());
1459 RenderLayerModelObject* repaintContainer = containerForRepaint();
1460 computeRectForRepaint(repaintContainer, dirtyRect);
1461 repaintUsingContainer(repaintContainer ? repaintContainer : view, pixelSnappedIntRect(dirtyRect));
1464 IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const
1466 return pixelSnappedIntRect(absoluteClippedOverflowRect());
1469 bool RenderObject::repaintAfterLayoutIfNeeded(const RenderLayerModelObject* repaintContainer, bool wasSelfLayout,
1470 const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox,
1471 const LayoutRect* newBoundsPtr, const LayoutRect* newOutlineBoxRectPtr)
1473 RenderView* v = view();
1474 if (v->document().printing())
1475 return false; // Don't repaint if we're printing.
1477 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1478 // ASSERT(!newBoundsPtr || *newBoundsPtr == clippedOverflowRectForRepaint(repaintContainer));
1479 LayoutRect newBounds = newBoundsPtr ? *newBoundsPtr : clippedOverflowRectForRepaint(repaintContainer);
1480 LayoutRect newOutlineBox;
1482 bool fullRepaint = wasSelfLayout;
1483 // Presumably a background or a border exists if border-fit:lines was specified.
1484 if (!fullRepaint && style()->borderFit() == BorderFitLines)
1486 if (!fullRepaint && style()->hasBorderRadius()) {
1487 // If a border-radius exists and width/height is smaller than
1488 // radius width/height, we cannot use delta-repaint.
1489 RoundedRect oldRoundedRect = style()->getRoundedBorderFor(oldBounds);
1490 RoundedRect newRoundedRect = style()->getRoundedBorderFor(newBounds);
1491 fullRepaint = oldRoundedRect.radii() != newRoundedRect.radii();
1494 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1495 // ASSERT(!newOutlineBoxRectPtr || *newOutlineBoxRectPtr == outlineBoundsForRepaint(repaintContainer));
1496 newOutlineBox = newOutlineBoxRectPtr ? *newOutlineBoxRectPtr : outlineBoundsForRepaint(repaintContainer);
1497 if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1501 if (!repaintContainer)
1502 repaintContainer = v;
1505 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds));
1506 if (newBounds != oldBounds)
1507 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds));
1511 if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1514 LayoutUnit deltaLeft = newBounds.x() - oldBounds.x();
1516 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1517 else if (deltaLeft < 0)
1518 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1520 LayoutUnit deltaRight = newBounds.maxX() - oldBounds.maxX();
1522 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.maxX(), newBounds.y(), deltaRight, newBounds.height()));
1523 else if (deltaRight < 0)
1524 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.maxX(), oldBounds.y(), -deltaRight, oldBounds.height()));
1526 LayoutUnit deltaTop = newBounds.y() - oldBounds.y();
1528 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1529 else if (deltaTop < 0)
1530 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1532 LayoutUnit deltaBottom = newBounds.maxY() - oldBounds.maxY();
1533 if (deltaBottom > 0)
1534 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), oldBounds.maxY(), newBounds.width(), deltaBottom));
1535 else if (deltaBottom < 0)
1536 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), newBounds.maxY(), oldBounds.width(), -deltaBottom));
1538 if (newOutlineBox == oldOutlineBox)
1541 // We didn't move, but we did change size. Invalidate the delta, which will consist of possibly
1542 // two rectangles (but typically only one).
1543 RenderStyle* outlineStyle = outlineStyleForRepaint();
1544 LayoutUnit outlineWidth = outlineStyle->outlineSize();
1545 LayoutBoxExtent insetShadowExtent = style()->getBoxShadowInsetExtent();
1546 LayoutUnit width = absoluteValue(newOutlineBox.width() - oldOutlineBox.width());
1548 LayoutUnit shadowLeft;
1549 LayoutUnit shadowRight;
1550 style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1551 int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1552 LayoutUnit boxWidth = isBox() ? toRenderBox(this)->width() : LayoutUnit();
1553 LayoutUnit minInsetRightShadowExtent = min<LayoutUnit>(-insetShadowExtent.right(), min<LayoutUnit>(newBounds.width(), oldBounds.width()));
1554 LayoutUnit borderWidth = max<LayoutUnit>(borderRight, max<LayoutUnit>(valueForLength(style()->borderTopRightRadius().width(), boxWidth), valueForLength(style()->borderBottomRightRadius().width(), boxWidth)));
1555 LayoutUnit decorationsLeftWidth = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderWidth + minInsetRightShadowExtent) + max<LayoutUnit>(outlineWidth, -shadowLeft);
1556 LayoutUnit decorationsRightWidth = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderWidth + minInsetRightShadowExtent) + max<LayoutUnit>(outlineWidth, shadowRight);
1557 LayoutRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - decorationsLeftWidth,
1559 width + decorationsLeftWidth + decorationsRightWidth,
1560 max(newOutlineBox.height(), oldOutlineBox.height()));
1561 LayoutUnit right = min<LayoutUnit>(newBounds.maxX(), oldBounds.maxX());
1562 if (rightRect.x() < right) {
1563 rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1564 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(rightRect));
1567 LayoutUnit height = absoluteValue(newOutlineBox.height() - oldOutlineBox.height());
1569 LayoutUnit shadowTop;
1570 LayoutUnit shadowBottom;
1571 style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1572 int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1573 LayoutUnit boxHeight = isBox() ? toRenderBox(this)->height() : LayoutUnit();
1574 LayoutUnit minInsetBottomShadowExtent = min<LayoutUnit>(-insetShadowExtent.bottom(), min<LayoutUnit>(newBounds.height(), oldBounds.height()));
1575 LayoutUnit borderHeight = max<LayoutUnit>(borderBottom, max<LayoutUnit>(valueForLength(style()->borderBottomLeftRadius().height(), boxHeight), valueForLength(style()->borderBottomRightRadius().height(), boxHeight)));
1576 LayoutUnit decorationsTopHeight = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderHeight + minInsetBottomShadowExtent) + max<LayoutUnit>(outlineWidth, -shadowTop);
1577 LayoutUnit decorationsBottomHeight = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderHeight + minInsetBottomShadowExtent) + max<LayoutUnit>(outlineWidth, shadowBottom);
1578 LayoutRect bottomRect(newOutlineBox.x(),
1579 min(newOutlineBox.maxY(), oldOutlineBox.maxY()) - decorationsTopHeight,
1580 max(newOutlineBox.width(), oldOutlineBox.width()),
1581 height + decorationsTopHeight + decorationsBottomHeight);
1582 LayoutUnit bottom = min(newBounds.maxY(), oldBounds.maxY());
1583 if (bottomRect.y() < bottom) {
1584 bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1585 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(bottomRect));
1591 void RenderObject::repaintOverflow()
1595 bool RenderObject::checkForRepaint() const
1597 return !document().view()->needsFullRepaint() && !hasLayer() && everHadLayout();
1600 bool RenderObject::checkForRepaintDuringLayout() const
1602 return !RuntimeEnabledFeatures::repaintAfterLayoutEnabled() && checkForRepaint();
1605 LayoutRect RenderObject::rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const
1607 LayoutRect r(clippedOverflowRectForRepaint(repaintContainer));
1608 r.inflate(outlineWidth);
1612 LayoutRect RenderObject::clippedOverflowRectForRepaint(const RenderLayerModelObject*) const
1614 ASSERT_NOT_REACHED();
1615 return LayoutRect();
1618 void RenderObject::computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
1620 if (repaintContainer == this)
1623 if (RenderObject* o = parent()) {
1624 if (o->isRenderBlockFlow()) {
1625 RenderBlock* cb = toRenderBlock(o);
1626 if (cb->hasColumns())
1627 cb->adjustRectForColumns(rect);
1630 if (o->hasOverflowClip()) {
1631 RenderBox* boxParent = toRenderBox(o);
1632 boxParent->applyCachedClipAndScrollOffsetForRepaint(rect);
1637 o->computeRectForRepaint(repaintContainer, rect, fixed);
1641 void RenderObject::computeFloatRectForRepaint(const RenderLayerModelObject*, FloatRect&, bool) const
1643 ASSERT_NOT_REACHED();
1646 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1652 void RenderObject::showTreeForThis() const
1655 node()->showTreeForThis();
1658 void RenderObject::showRenderTreeForThis() const
1660 showRenderTree(this, 0);
1663 void RenderObject::showLineTreeForThis() const
1665 if (containingBlock())
1666 containingBlock()->showLineTreeAndMark(0, 0, 0, 0, this);
1669 void RenderObject::showRenderObject() const
1671 showRenderObject(0);
1674 void RenderObject::showRenderObject(int printedCharacters) const
1676 // As this function is intended to be used when debugging, the
1677 // this pointer may be 0.
1679 fputs("(null)\n", stderr);
1683 printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
1686 if (printedCharacters)
1687 for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
1689 fputc('\t', stderr);
1692 fputc('\n', stderr);
1695 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
1697 int printedCharacters = 0;
1698 if (markedObject1 == this && markedLabel1)
1699 printedCharacters += fprintf(stderr, "%s", markedLabel1);
1700 if (markedObject2 == this && markedLabel2)
1701 printedCharacters += fprintf(stderr, "%s", markedLabel2);
1702 for (; printedCharacters < depth * 2; printedCharacters++)
1705 showRenderObject(printedCharacters);
1709 for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
1710 child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
1715 bool RenderObject::isSelectable() const
1717 return !isInert() && !(style()->userSelect() == SELECT_NONE && style()->userModify() == READ_ONLY);
1720 Color RenderObject::selectionBackgroundColor() const
1722 if (!isSelectable())
1723 return Color::transparent;
1725 if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(PseudoStyleRequest(SELECTION)))
1726 return resolveColor(pseudoStyle.get(), CSSPropertyBackgroundColor).blendWithWhite();
1727 return frame()->selection().isFocusedAndActive() ?
1728 RenderTheme::theme().activeSelectionBackgroundColor() :
1729 RenderTheme::theme().inactiveSelectionBackgroundColor();
1732 Color RenderObject::selectionColor(int colorProperty) const
1734 // If the element is unselectable, or we are only painting the selection,
1735 // don't override the foreground color with the selection foreground color.
1736 if (!isSelectable() || (frame()->view()->paintBehavior() & PaintBehaviorSelectionOnly))
1737 return resolveColor(colorProperty);
1739 if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(PseudoStyleRequest(SELECTION)))
1740 return resolveColor(pseudoStyle.get(), colorProperty);
1741 if (!RenderTheme::theme().supportsSelectionForegroundColors())
1742 return resolveColor(colorProperty);
1743 return frame()->selection().isFocusedAndActive() ?
1744 RenderTheme::theme().activeSelectionForegroundColor() :
1745 RenderTheme::theme().inactiveSelectionForegroundColor();
1748 Color RenderObject::selectionForegroundColor() const
1750 return selectionColor(CSSPropertyWebkitTextFillColor);
1753 Color RenderObject::selectionEmphasisMarkColor() const
1755 return selectionColor(CSSPropertyWebkitTextEmphasisColor);
1758 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1760 view()->selectionStartEnd(spos, epos);
1763 void RenderObject::handleDynamicFloatPositionChange()
1765 // We have gone from not affecting the inline status of the parent flow to suddenly
1766 // having an impact. See if there is a mismatch between the parent flow's
1767 // childrenInline() state and our state.
1768 setInline(style()->isDisplayInlineType());
1769 if (isInline() != parent()->childrenInline()) {
1771 toRenderBoxModelObject(parent())->childBecameNonInline(this);
1773 // An anonymous block must be made to wrap this inline.
1774 RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1775 RenderObjectChildList* childlist = parent()->virtualChildren();
1776 childlist->insertChildNode(parent(), block, this);
1777 block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1782 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1784 // FIXME: We call this from within style recalc, but we read compositingState below!
1785 DisableCompositingQueryAsserts disabler;
1787 // If transform changed, and the layer does not paint into its own separate backing, then we need to do a layout.
1788 // FIXME: The comment above is what the code does, but it is technically not following spec. This means we will
1789 // not to layout for 3d transforms, but we should be invoking a simplified relayout. Is it possible we are avoiding
1790 // doing this for some performance reason at this time?
1791 if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1792 // Text nodes share style with their parents but transforms don't apply to them,
1793 // hence the !isText() check.
1794 // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1795 if (!isText() && (!hasLayer() || toRenderLayerModelObject(this)->layer()->compositingState() != PaintsIntoOwnBacking)) {
1796 // We need to set at least SimplifiedLayout, but if PositionedMovementOnly is already set
1797 // then we actually need SimplifiedLayoutAndPositionedMovement.
1799 diff = StyleDifferenceLayout; // FIXME: Do this for now since SimplifiedLayout cannot handle updating floating objects lists.
1800 else if (diff < StyleDifferenceLayoutPositionedMovementOnly)
1801 diff = StyleDifferenceSimplifiedLayout;
1802 else if (diff < StyleDifferenceSimplifiedLayout)
1803 diff = StyleDifferenceSimplifiedLayoutAndPositionedMovement;
1804 } else if (diff < StyleDifferenceRecompositeLayer)
1805 diff = StyleDifferenceRecompositeLayer;
1808 // If opacity or filters changed, and the layer does not paint into its own separate backing, then we need to repaint (also
1809 // ignoring text nodes)
1810 if (contextSensitiveProperties & ContextSensitivePropertyOpacity && diff <= StyleDifferenceRepaintLayer) {
1811 if (!isText() && (!hasLayer() || toRenderLayerModelObject(this)->layer()->compositingState() != PaintsIntoOwnBacking))
1812 diff = StyleDifferenceRepaintLayer;
1813 else if (diff < StyleDifferenceRecompositeLayer)
1814 diff = StyleDifferenceRecompositeLayer;
1816 if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer() && diff <= StyleDifferenceRepaintLayer) {
1817 RenderLayer* layer = toRenderLayerModelObject(this)->layer();
1818 if (layer->compositingState() != PaintsIntoOwnBacking || layer->paintsWithFilters())
1819 diff = StyleDifferenceRepaintLayer;
1820 else if (diff < StyleDifferenceRecompositeLayer)
1821 diff = StyleDifferenceRecompositeLayer;
1824 // The answer to layerTypeRequired() for plugins, iframes, and canvas can change without the actual
1825 // style changing, since it depends on whether we decide to composite these elements. When the
1826 // layer status of one of these elements changes, we need to force a layout.
1827 if (diff == StyleDifferenceEqual && style() && isLayerModelObject()) {
1828 bool requiresLayer = toRenderLayerModelObject(this)->layerTypeRequired() != NoLayer;
1829 if (hasLayer() != requiresLayer)
1830 diff = StyleDifferenceLayout;
1833 // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1834 if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1835 diff = StyleDifferenceRepaint;
1840 void RenderObject::setPseudoStyle(PassRefPtr<RenderStyle> pseudoStyle)
1842 ASSERT(pseudoStyle->styleType() == BEFORE || pseudoStyle->styleType() == AFTER);
1844 // FIXME: We should consider just making all pseudo items use an inherited style.
1846 // Images are special and must inherit the pseudoStyle so the width and height of
1847 // the pseudo element doesn't change the size of the image. In all other cases we
1848 // can just share the style.
1850 // Quotes are also RenderInline, so we need to create an inherited style to avoid
1851 // getting an inline with positioning or an invalid display.
1853 if (isImage() || isQuote()) {
1854 RefPtr<RenderStyle> style = RenderStyle::create();
1855 style->inheritFrom(pseudoStyle.get());
1856 setStyle(style.release());
1860 setStyle(pseudoStyle);
1863 inline bool RenderObject::hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor() const
1865 if (style()->hasBorder() || style()->hasOutline())
1867 for (const RenderObject* r = firstChild(); r; r = r->nextSibling()) {
1868 if (r->isText() && !toRenderText(r)->isAllCollapsibleWhitespace())
1870 if (r->style()->hasOutline() || r->style()->hasBorder())
1876 inline bool RenderObject::shouldRepaintForStyleDifference(StyleDifference diff) const
1878 return diff == StyleDifferenceRepaint || (diff == StyleDifferenceRepaintIfTextOrColorChange && hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor());
1881 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1883 if (m_style == style) {
1884 // We need to run through adjustStyleDifference() for iframes, plugins, and canvas so
1885 // style sharing is disabled for them. That should ensure that we never hit this code path.
1886 ASSERT(!isRenderIFrame() && !isEmbeddedObject() && !isCanvas());
1890 StyleDifference diff = StyleDifferenceEqual;
1891 unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1893 diff = m_style->diff(style.get(), contextSensitiveProperties);
1895 diff = adjustStyleDifference(diff, contextSensitiveProperties);
1897 styleWillChange(diff, style.get());
1899 RefPtr<RenderStyle> oldStyle = m_style.release();
1900 setStyleInternal(style);
1902 updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1903 updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1905 updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1906 updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1908 updateShapeImage(oldStyle ? oldStyle->shapeInside() : 0, m_style ? m_style->shapeInside() : 0);
1909 updateShapeImage(oldStyle ? oldStyle->shapeOutside() : 0, m_style ? m_style->shapeOutside() : 0);
1911 // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1912 // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1913 // FIXME: Do this more cleanly. http://crbug.com/273904
1914 if (m_style->outlineWidth() > 0 && m_style->outlineSize() > view()->maximalOutlineSize())
1915 view()->setMaximalOutlineSize(m_style->outlineSize());
1917 bool doesNotNeedLayout = !m_parent || isText();
1919 styleDidChange(diff, oldStyle.get());
1921 // FIXME: |this| might be destroyed here. This can currently happen for a RenderTextFragment when
1922 // its first-letter block gets an update in RenderTextFragment::styleDidChange. For RenderTextFragment(s),
1923 // we will safely bail out with the doesNotNeedLayout flag. We might want to broaden this condition
1924 // in the future as we move renderer changes out of layout and into style changes.
1925 if (doesNotNeedLayout)
1928 // Now that the layer (if any) has been updated, we need to adjust the diff again,
1929 // check whether we should layout now, and decide if we need to repaint.
1930 StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1932 if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1933 if (updatedDiff == StyleDifferenceLayout)
1934 setNeedsLayoutAndPrefWidthsRecalc();
1935 else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1936 setNeedsPositionedMovementLayout();
1937 else if (updatedDiff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1938 setNeedsPositionedMovementLayout();
1939 setNeedsSimplifiedNormalFlowLayout();
1940 } else if (updatedDiff == StyleDifferenceSimplifiedLayout)
1941 setNeedsSimplifiedNormalFlowLayout();
1944 if (updatedDiff == StyleDifferenceRepaintLayer || shouldRepaintForStyleDifference(updatedDiff)) {
1945 // Do a repaint with the new style now, e.g., for example if we go from
1946 // not having an outline to having an outline.
1951 static inline bool rendererHasBackground(const RenderObject* renderer)
1953 return renderer && renderer->hasBackground();
1956 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1959 // If our z-index changes value or our visibility changes,
1960 // we need to dirty our stacking context's z-order list.
1962 bool visibilityChanged = m_style->visibility() != newStyle->visibility()
1963 || m_style->zIndex() != newStyle->zIndex()
1964 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1965 if (visibilityChanged) {
1966 document().setAnnotatedRegionsDirty(true);
1967 if (AXObjectCache* cache = document().existingAXObjectCache())
1968 cache->childrenChanged(parent());
1971 // Keep layer hierarchy visibility bits up to date if visibility changes.
1972 if (m_style->visibility() != newStyle->visibility()) {
1973 if (RenderLayer* l = enclosingLayer()) {
1974 if (newStyle->visibility() == VISIBLE)
1975 l->setHasVisibleContent();
1976 else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1977 l->dirtyVisibleContentStatus();
1978 if (diff > StyleDifferenceRepaintLayer)
1985 if (m_parent && (newStyle->outlineSize() < m_style->outlineSize() || shouldRepaintForStyleDifference(diff)))
1987 if (isFloating() && (m_style->floating() != newStyle->floating()))
1988 // For changes in float styles, we need to conceivably remove ourselves
1989 // from the floating objects list.
1990 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1991 else if (isOutOfFlowPositioned() && (m_style->position() != newStyle->position()))
1992 // For changes in positioning styles, we need to conceivably remove ourselves
1993 // from the positioned objects list.
1994 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1996 s_affectsParentBlock = isFloatingOrOutOfFlowPositioned()
1997 && (!newStyle->isFloating() && !newStyle->hasOutOfFlowPosition())
1998 && parent() && (parent()->isRenderBlockFlow() || parent()->isRenderInline());
2000 // Clearing these bits is required to avoid leaving stale renderers.
2001 // FIXME: We shouldn't need that hack if our logic was totally correct.
2002 if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
2004 clearPositionedState();
2007 s_affectsParentBlock = false;
2009 if (view()->frameView()) {
2010 bool shouldBlitOnFixedBackgroundImage = false;
2011 #if ENABLE(FAST_MOBILE_SCROLLING)
2012 // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
2013 // when scrolling a page with a fixed background image. As an optimization, assuming there are
2014 // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
2015 // ignore the CSS property "background-attachment: fixed".
2016 shouldBlitOnFixedBackgroundImage = true;
2019 bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage();
2020 bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage();
2022 bool drawsRootBackground = isRoot() || (isBody() && !rendererHasBackground(document().documentElement()->renderer()));
2023 if (drawsRootBackground && !shouldBlitOnFixedBackgroundImage) {
2024 if (view()->compositor()->supportsFixedRootBackgroundCompositing()) {
2025 if (newStyleSlowScroll && newStyle->hasEntirelyFixedBackground())
2026 newStyleSlowScroll = false;
2028 if (oldStyleSlowScroll && m_style->hasEntirelyFixedBackground())
2029 oldStyleSlowScroll = false;
2033 if (oldStyleSlowScroll != newStyleSlowScroll) {
2034 if (oldStyleSlowScroll)
2035 view()->frameView()->removeSlowRepaintObject();
2036 if (newStyleSlowScroll)
2037 view()->frameView()->addSlowRepaintObject();
2042 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderStyle* b)
2044 ASSERT(a->cursors() != b->cursors());
2045 return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
2048 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
2050 return a->cursor() == b->cursor() && (a->cursors() == b->cursors() || areNonIdenticalCursorListsEqual(a, b));
2053 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
2055 if (s_affectsParentBlock)
2056 handleDynamicFloatPositionChange();
2061 if (diff == StyleDifferenceLayout || diff == StyleDifferenceSimplifiedLayout) {
2062 RenderCounter::rendererStyleChanged(*this, oldStyle, m_style.get());
2064 // If the object already needs layout, then setNeedsLayout won't do
2065 // any work. But if the containing block has changed, then we may need
2066 // to mark the new containing blocks for layout. The change that can
2067 // directly affect the containing block of this object is a change to
2068 // the position style.
2069 if (needsLayout() && oldStyle->position() != m_style->position())
2070 markContainingBlocksForLayout();
2072 if (diff == StyleDifferenceLayout)
2073 setNeedsLayoutAndPrefWidthsRecalc();
2075 setNeedsSimplifiedNormalFlowLayout();
2076 } else if (diff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
2077 setNeedsPositionedMovementLayout();
2078 setNeedsSimplifiedNormalFlowLayout();
2079 } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
2080 setNeedsPositionedMovementLayout();
2082 // Don't check for repaint here; we need to wait until the layer has been
2083 // updated by subclasses before we know if we have to repaint (in setStyle()).
2085 if (oldStyle && !areCursorsEqual(oldStyle, style())) {
2086 if (Frame* frame = this->frame())
2087 frame->eventHandler().scheduleCursorUpdate();
2091 void RenderObject::propagateStyleToAnonymousChildren(bool blockChildrenOnly)
2093 // FIXME: We could save this call when the change only affected non-inherited properties.
2094 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
2095 if (!child->isAnonymous() || child->style()->styleType() != NOPSEUDO)
2098 if (blockChildrenOnly && !child->isRenderBlock())
2101 if (child->isRenderFullScreen() || child->isRenderFullScreenPlaceholder())
2104 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), child->style()->display());
2105 if (style()->specifiesColumns()) {
2106 if (child->style()->specifiesColumns())
2107 newStyle->inheritColumnPropertiesFrom(style());
2108 if (child->style()->columnSpan())
2109 newStyle->setColumnSpan(ColumnSpanAll);
2112 // Preserve the position style of anonymous block continuations as they can have relative or sticky position when
2113 // they contain block descendants of relative or sticky positioned inlines.
2114 if (child->isInFlowPositioned() && toRenderBlock(child)->isAnonymousBlockContinuation())
2115 newStyle->setPosition(child->style()->position());
2117 child->setStyle(newStyle.release());
2121 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
2123 // Optimize the common case
2124 if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
2127 // Go through the new layers and addClients first, to avoid removing all clients of an image.
2128 for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
2129 if (currNew->image())
2130 currNew->image()->addClient(this);
2133 for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
2134 if (currOld->image())
2135 currOld->image()->removeClient(this);
2139 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
2141 if (oldImage != newImage) {
2143 oldImage->removeClient(this);
2145 newImage->addClient(this);
2149 void RenderObject::updateShapeImage(const ShapeValue* oldShapeValue, const ShapeValue* newShapeValue)
2151 if (oldShapeValue || newShapeValue)
2152 updateImage(oldShapeValue ? oldShapeValue->image() : 0, newShapeValue ? newShapeValue->image() : 0);
2155 LayoutRect RenderObject::viewRect() const
2157 return view()->viewRect();
2160 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, MapCoordinatesFlags mode) const
2162 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2163 mapLocalToContainer(0, transformState, mode | ApplyContainerFlip);
2164 transformState.flatten();
2166 return transformState.lastPlanarPoint();
2169 FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, MapCoordinatesFlags mode) const
2171 TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
2172 mapAbsoluteToLocalPoint(mode, transformState);
2173 transformState.flatten();
2175 return transformState.lastPlanarPoint();
2178 FloatQuad RenderObject::absoluteToLocalQuad(const FloatQuad& quad, MapCoordinatesFlags mode) const
2180 TransformState transformState(TransformState::UnapplyInverseTransformDirection, quad.boundingBox().center(), quad);
2181 mapAbsoluteToLocalPoint(mode, transformState);
2182 transformState.flatten();
2183 return transformState.lastPlanarQuad();
2186 void RenderObject::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const
2188 if (repaintContainer == this)
2191 RenderObject* o = parent();
2195 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2196 LayoutPoint centerPoint = roundedLayoutPoint(transformState.mappedPoint());
2197 if (mode & ApplyContainerFlip && o->isBox()) {
2198 if (o->style()->isFlippedBlocksWritingMode())
2199 transformState.move(toRenderBox(o)->flipForWritingModeIncludingColumns(roundedLayoutPoint(transformState.mappedPoint())) - centerPoint);
2200 mode &= ~ApplyContainerFlip;
2203 LayoutSize columnOffset;
2204 o->adjustForColumns(columnOffset, roundedLayoutPoint(transformState.mappedPoint()));
2205 if (!columnOffset.isZero())
2206 transformState.move(columnOffset);
2208 if (o->hasOverflowClip())
2209 transformState.move(-toRenderBox(o)->scrolledContentOffset());
2211 o->mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2214 const RenderObject* RenderObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
2216 ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this);
2218 RenderObject* container = parent();
2222 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2224 if (container->hasOverflowClip())
2225 offset = -toRenderBox(container)->scrolledContentOffset();
2227 geometryMap.push(this, offset, hasColumns());
2232 void RenderObject::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformState& transformState) const
2234 RenderObject* o = parent();
2236 o->mapAbsoluteToLocalPoint(mode, transformState);
2237 if (o->hasOverflowClip())
2238 transformState.move(toRenderBox(o)->scrolledContentOffset());
2242 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
2244 // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
2245 // so check the layer's transform directly.
2246 return (hasLayer() && toRenderLayerModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
2249 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const
2251 transform.makeIdentity();
2252 transform.translate(offsetInContainer.width(), offsetInContainer.height());
2254 if (hasLayer() && (layer = toRenderLayerModelObject(this)->layer()) && layer->transform())
2255 transform.multiply(layer->currentTransform());
2257 if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
2258 // Perpsective on the container affects us, so we have to factor it in here.
2259 ASSERT(containerObject->hasLayer());
2260 FloatPoint perspectiveOrigin = toRenderLayerModelObject(containerObject)->layer()->perspectiveOrigin();
2262 TransformationMatrix perspectiveMatrix;
2263 perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
2265 transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
2266 transform = perspectiveMatrix * transform;
2267 transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
2271 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags mode, bool* wasFixed) const
2273 // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(),
2274 // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks.
2275 TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad);
2276 mapLocalToContainer(repaintContainer, transformState, mode | ApplyContainerFlip | UseTransforms, wasFixed);
2277 transformState.flatten();
2279 return transformState.lastPlanarQuad();
2282 FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags mode, bool* wasFixed) const
2284 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2285 mapLocalToContainer(repaintContainer, transformState, mode | ApplyContainerFlip | UseTransforms, wasFixed);
2286 transformState.flatten();
2288 return transformState.lastPlanarPoint();
2291 LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
2293 ASSERT(o == container());
2297 o->adjustForColumns(offset, point);
2299 if (o->hasOverflowClip())
2300 offset -= toRenderBox(o)->scrolledContentOffset();
2302 if (offsetDependsOnPoint)
2303 *offsetDependsOnPoint = hasColumns() || o->isRenderFlowThread();
2308 LayoutSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
2311 LayoutPoint referencePoint;
2312 const RenderObject* currContainer = this;
2314 RenderObject* nextContainer = currContainer->container();
2315 ASSERT(nextContainer); // This means we reached the top without finding container.
2318 ASSERT(!currContainer->hasTransform());
2319 LayoutSize currentOffset = currContainer->offsetFromContainer(nextContainer, referencePoint);
2320 offset += currentOffset;
2321 referencePoint.move(currentOffset);
2322 currContainer = nextContainer;
2323 } while (currContainer != container);
2328 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
2330 if (extraWidthToEndOfLine)
2331 *extraWidthToEndOfLine = 0;
2333 return LayoutRect();
2336 void RenderObject::computeLayerHitTestRects(LayerHitTestRects& layerRects) const
2338 // Figure out what layer our container is in. Any offset (or new layer) for this
2339 // renderer within it's container will be applied in addLayerHitTestRects.
2340 LayoutPoint layerOffset;
2341 const RenderLayer* currentLayer = 0;
2344 RenderObject* container = this->container();
2346 currentLayer = container->enclosingLayer();
2347 if (currentLayer && currentLayer->renderer() != container) {
2348 layerOffset.move(container->offsetFromAncestorContainer(currentLayer->renderer()));
2349 // If the layer itself is scrolled, we have to undo the subtraction of its scroll
2350 // offset since we want the offset relative to the scrolling content, not the
2352 if (currentLayer->renderer()->hasOverflowClip())
2353 layerOffset.move(currentLayer->renderBox()->scrolledContentOffset());
2356 currentLayer = enclosingLayer();
2362 this->addLayerHitTestRects(layerRects, currentLayer, layerOffset, LayoutRect());
2365 void RenderObject::addLayerHitTestRects(LayerHitTestRects& layerRects, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
2367 ASSERT(currentLayer);
2368 ASSERT(currentLayer == this->enclosingLayer());
2370 // Compute the rects for this renderer only and add them to the results.
2371 // Note that we could avoid passing the offset and instead adjust each result, but this
2372 // seems slightly simpler.
2373 Vector<LayoutRect> ownRects;
2374 LayoutRect newContainerRect;
2375 computeSelfHitTestRects(ownRects, layerOffset);
2377 // When we get to have a lot of rects on a layer, the performance cost of tracking those
2378 // rects outweighs the benefit of doing compositor thread hit testing.
2379 // FIXME: This limit needs to be low due to the O(n^2) algorithm in
2380 // WebLayer::setTouchEventHandlerRegion - crbug.com/300282.
2381 const size_t maxRectsPerLayer = 100;
2383 LayerHitTestRects::iterator iter = layerRects.find(currentLayer);
2384 Vector<WebCore::LayoutRect>* iterValue;
2385 if (iter == layerRects.end())
2386 iterValue = &layerRects.add(currentLayer, Vector<LayoutRect>()).storedValue->value;
2388 iterValue = &iter->value;
2389 for (size_t i = 0; i < ownRects.size(); i++) {
2390 if (!containerRect.contains(ownRects[i])) {
2391 iterValue->append(ownRects[i]);
2392 if (iterValue->size() > maxRectsPerLayer) {
2393 // Just mark the entire layer instead, and switch to walking the layer
2394 // tree instead of the render tree.
2395 layerRects.remove(currentLayer);
2396 currentLayer->addLayerHitTestRects(layerRects);
2399 if (newContainerRect.isEmpty())
2400 newContainerRect = ownRects[i];
2403 if (newContainerRect.isEmpty())
2404 newContainerRect = containerRect;
2406 // If it's possible for children to have rects outside our bounds, then we need to descend into
2407 // the children and compute them.
2408 // Ideally there would be other cases where we could detect that children couldn't have rects
2409 // outside our bounds and prune the tree walk.
2410 // Note that we don't use Region here because Union is O(N) - better to just keep a list of
2411 // partially redundant rectangles. If we find examples where this is expensive, then we could
2412 // rewrite Region to be more efficient. See https://bugs.webkit.org/show_bug.cgi?id=100814.
2413 if (!isRenderView()) {
2414 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
2415 curr->addLayerHitTestRects(layerRects, currentLayer, layerOffset, newContainerRect);
2420 bool RenderObject::isRooted(RenderView** view) const
2422 const RenderObject* o = this;
2426 if (!o->isRenderView())
2430 *view = const_cast<RenderView*>(toRenderView(o));
2435 RenderObject* RenderObject::rendererForRootBackground()
2438 if (!hasBackground() && node() && node()->hasTagName(htmlTag)) {
2439 // Locate the <body> element using the DOM. This is easier than trying
2440 // to crawl around a render tree with potential :before/:after content and
2441 // anonymous blocks created by inline <body> tags etc. We can locate the <body>
2442 // render object very easily via the DOM.
2443 HTMLElement* body = document().body();
2444 RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
2452 RespectImageOrientationEnum RenderObject::shouldRespectImageOrientation() const
2454 // Respect the image's orientation if it's being used as a full-page image or it's
2455 // an <img> and the setting to respect it everywhere is set.
2456 return document().isImageDocument()
2457 || (document().settings() && document().settings()->shouldRespectImageOrientation() && node() && node()->hasTagName(HTMLNames::imgTag)) ? RespectImageOrientation : DoNotRespectImageOrientation;
2460 bool RenderObject::hasOutlineAnnotation() const
2462 return node() && node()->isLink() && document().printing();
2465 bool RenderObject::hasEntirelyFixedBackground() const
2467 return m_style->hasEntirelyFixedBackground();
2470 RenderObject* RenderObject::container(const RenderLayerModelObject* repaintContainer, bool* repaintContainerSkipped) const
2472 if (repaintContainerSkipped)
2473 *repaintContainerSkipped = false;
2475 // This method is extremely similar to containingBlock(), but with a few notable
2477 // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2478 // the object is not part of the primary document subtree yet.
2479 // (2) For normal flow elements, it just returns the parent.
2480 // (3) For absolute positioned elements, it will return a relative positioned inline.
2481 // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2482 // the layout of the positioned object. This does mean that computePositionedLogicalWidth and
2483 // computePositionedLogicalHeight have to use container().
2484 RenderObject* o = parent();
2489 EPosition pos = m_style->position();
2490 if (pos == FixedPosition) {
2491 return containerForFixedPosition(repaintContainer, repaintContainerSkipped);
2492 } else if (pos == AbsolutePosition) {
2493 // We technically just want our containing block, but
2494 // we may not have one if we're part of an uninstalled
2495 // subtree. We'll climb as high as we can though.
2497 if (o->style()->position() != StaticPosition)
2500 if (o->canContainFixedPositionObjects())
2503 if (repaintContainerSkipped && o == repaintContainer)
2504 *repaintContainerSkipped = true;
2513 bool RenderObject::isSelectionBorder() const
2515 SelectionState st = selectionState();
2516 return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2519 inline void RenderObject::clearLayoutRootIfNeeded() const
2522 if (FrameView* view = frame()->view()) {
2523 if (view->layoutRoot() == this) {
2524 if (!documentBeingDestroyed())
2525 ASSERT_NOT_REACHED();
2526 // This indicates a failure to layout the child, which is why
2527 // the layout root is still set to |this|. Make sure to clear it
2528 // since we are getting destroyed.
2529 view->clearLayoutSubtreeRoot();
2535 void RenderObject::willBeDestroyed()
2537 // Destroy any leftover anonymous children.
2538 RenderObjectChildList* children = virtualChildren();
2540 children->destroyLeftoverChildren();
2542 // If this renderer is being autoscrolled, stop the autoscrolling.
2543 if (Frame* frame = this->frame()) {
2545 frame->page()->autoscrollController().stopAutoscrollIfNeeded(this);
2548 // For accessibility management, notify the parent of the imminent change to its child set.
2549 // We do it now, before remove(), while the parent pointer is still available.
2550 if (AXObjectCache* cache = document().existingAXObjectCache())
2551 cache->childrenChanged(this->parent());
2555 // The remove() call above may invoke axObjectCache()->childrenChanged() on the parent, which may require the AX render
2556 // object for this renderer. So we remove the AX render object now, after the renderer is removed.
2557 if (AXObjectCache* cache = document().existingAXObjectCache())
2558 cache->remove(this);
2560 // If this renderer had a parent, remove should have destroyed any counters
2561 // attached to this renderer and marked the affected other counters for
2562 // reevaluation. This apparently redundant check is here for the case when
2563 // this renderer had no parent at the time remove() was called.
2565 if (hasCounterNodeMap())
2566 RenderCounter::destroyCounterNodes(*this);
2568 setAncestorLineBoxDirty(false);
2570 clearLayoutRootIfNeeded();
2573 void RenderObject::insertedIntoTree()
2575 // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion.
2577 // Keep our layer hierarchy updated. Optimize for the common case where we don't have any children
2578 // and don't have a layer attached to ourselves.
2579 RenderLayer* layer = 0;
2580 if (firstChild() || hasLayer()) {
2581 layer = parent()->enclosingLayer();
2585 // If |this| is visible but this object was not, tell the layer it has some visible content
2586 // that needs to be drawn and layer visibility optimization can't be used
2587 if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
2589 layer = parent()->enclosingLayer();
2591 layer->setHasVisibleContent();
2594 if (!isFloating() && parent()->childrenInline())
2595 parent()->dirtyLinesFromChangedChild(this);
2598 void RenderObject::willBeRemovedFromTree()
2600 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first.
2602 // If we remove a visible child from an invisible parent, we don't know the layer visibility any more.
2603 RenderLayer* layer = 0;
2604 if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
2605 if ((layer = parent()->enclosingLayer()))
2606 layer->dirtyVisibleContentStatus();
2609 // Keep our layer hierarchy updated.
2610 if (firstChild() || hasLayer()) {
2612 layer = parent()->enclosingLayer();
2613 removeLayers(layer);
2616 if (isOutOfFlowPositioned() && parent()->childrenInline())
2617 parent()->dirtyLinesFromChangedChild(this);
2619 removeFromRenderFlowThread();
2621 // Update cached boundaries in SVG renderers if a child is removed.
2622 if (parent()->isSVG())
2623 parent()->setNeedsBoundariesUpdate();
2626 void RenderObject::removeFromRenderFlowThread()
2628 if (flowThreadState() == NotInsideFlowThread)
2631 // Sometimes we remove the element from the flow, but it's not destroyed at that time.
2632 // It's only until later when we actually destroy it and remove all the children from it.
2633 // Currently, that happens for firstLetter elements and list markers.
2634 // Pass in the flow thread so that we don't have to look it up for all the children.
2635 removeFromRenderFlowThreadRecursive(flowThreadContainingBlock());
2638 void RenderObject::removeFromRenderFlowThreadRecursive(RenderFlowThread* renderFlowThread)
2640 if (const RenderObjectChildList* children = virtualChildren()) {
2641 for (RenderObject* child = children->firstChild(); child; child = child->nextSibling())
2642 child->removeFromRenderFlowThreadRecursive(renderFlowThread);
2645 setFlowThreadState(NotInsideFlowThread);
2648 void RenderObject::destroyAndCleanupAnonymousWrappers()
2650 // If the tree is destroyed, there is no need for a clean-up phase.
2651 if (documentBeingDestroyed()) {
2656 RenderObject* destroyRoot = this;
2657 for (RenderObject* destroyRootParent = destroyRoot->parent(); destroyRootParent && destroyRootParent->isAnonymous(); destroyRoot = destroyRootParent, destroyRootParent = destroyRootParent->parent()) {
2658 // Anonymous block continuations are tracked and destroyed elsewhere (see the bottom of RenderBlock::removeChild)
2659 if (destroyRootParent->isRenderBlock() && toRenderBlock(destroyRootParent)->isAnonymousBlockContinuation())
2661 // Render flow threads are tracked by the FlowThreadController, so we can't destroy them here.
2662 // Column spans are tracked elsewhere.
2663 if (destroyRootParent->isRenderFlowThread() || destroyRootParent->isAnonymousColumnSpanBlock())
2666 if (destroyRootParent->firstChild() != this || destroyRootParent->lastChild() != this)
2670 destroyRoot->destroy();
2672 // WARNING: |this| is deleted here.
2675 void RenderObject::removeShapeImageClient(ShapeValue* shapeValue)
2679 if (StyleImage* shapeImage = shapeValue->image())
2680 shapeImage->removeClient(this);
2683 void RenderObject::destroy()
2689 void RenderObject::postDestroy()
2691 // It seems ugly that this is not in willBeDestroyed().
2693 for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2694 if (StyleImage* backgroundImage = bgLayer->image())
2695 backgroundImage->removeClient(this);
2698 for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
2699 if (StyleImage* maskImage = maskLayer->image())
2700 maskImage->removeClient(this);
2703 if (StyleImage* borderImage = m_style->borderImage().image())
2704 borderImage->removeClient(this);
2706 if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
2707 maskBoxImage->removeClient(this);
2709 removeShapeImageClient(m_style->shapeInside());
2710 removeShapeImageClient(m_style->shapeOutside());
2716 PositionWithAffinity RenderObject::positionForPoint(const LayoutPoint&)
2718 return createPositionWithAffinity(caretMinOffset(), DOWNSTREAM);
2721 void RenderObject::updateDragState(bool dragOn)
2723 bool valueChanged = (dragOn != isDragging());
2724 setIsDragging(dragOn);
2725 if (valueChanged && node()) {
2726 if (node()->isElementNode() && toElement(node())->childrenAffectedByDrag())
2727 node()->setNeedsStyleRecalc(SubtreeStyleChange);
2728 else if (style()->affectedByDrag())
2729 node()->setNeedsStyleRecalc(LocalStyleChange);
2731 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2732 curr->updateDragState(dragOn);
2735 CompositingState RenderObject::compositingState() const
2737 return hasLayer() ? toRenderLayerModelObject(this)->layer()->compositingState() : NotComposited;
2740 bool RenderObject::acceleratedCompositingForOverflowScrollEnabled() const
2742 const Settings* settings = document().settings();
2743 return settings && settings->acceleratedCompositingForOverflowScrollEnabled();
2746 // FIXME: This is a temporary flag and should be removed once accelerated
2747 // overflow scroll is ready (crbug.com/254111).
2748 bool RenderObject::compositorDrivenAcceleratedScrollingEnabled() const
2750 if (!acceleratedCompositingForOverflowScrollEnabled())
2753 const Settings* settings = document().settings();
2754 return settings && settings->compositorDrivenAcceleratedScrollingEnabled();
2757 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter)
2759 bool inside = false;
2760 if (hitTestFilter != HitTestSelf) {
2761 // First test the foreground layer (lines and inlines).
2762 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestForeground);
2764 // Test floats next.
2766 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestFloat);
2768 // Finally test to see if the mouse is in the background (within a child block's background).
2770 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestChildBlockBackgrounds);
2773 // See if the mouse is inside us but not any of our descendants
2774 if (hitTestFilter != HitTestDescendants && !inside)
2775 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestBlockBackground);
2780 void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
2782 if (result.innerNode())
2785 Node* node = this->node();
2787 // If we hit the anonymous renderers inside generated content we should
2788 // actually hit the generated content so walk up to the PseudoElement.
2789 if (!node && parent() && parent()->isBeforeOrAfterContent()) {
2790 for (RenderObject* renderer = parent(); renderer && !node; renderer = renderer->parent())
2791 node = renderer->node();
2795 result.setInnerNode(node);
2796 if (!result.innerNonSharedNode())
2797 result.setInnerNonSharedNode(node);
2798 result.setLocalPoint(point);
2802 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& /*locationInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction)
2807 void RenderObject::scheduleRelayout()
2809 if (isRenderView()) {
2810 FrameView* view = toRenderView(this)->frameView();
2812 view->scheduleRelayout();
2815 if (RenderView* renderView = view()) {
2816 if (FrameView* frameView = renderView->frameView())
2817 frameView->scheduleRelayoutOfSubtree(this);
2823 void RenderObject::forceLayout()
2825 setSelfNeedsLayout(true);
2826 setShouldDoFullRepaintAfterLayout(true);
2830 // FIXME: Does this do anything different than forceLayout given that we don't walk
2831 // the containing block chain. If not, we should change all callers to use forceLayout.
2832 void RenderObject::forceChildLayout()
2834 setNormalChildNeedsLayout(true);
2838 enum StyleCacheState {
2843 static PassRefPtr<RenderStyle> firstLineStyleForCachedUncachedType(StyleCacheState type, const RenderObject* renderer, RenderStyle* style)
2845 const RenderObject* rendererForFirstLineStyle = renderer;
2846 if (renderer->isBeforeOrAfterContent())
2847 rendererForFirstLineStyle = renderer->parent();
2849 if (rendererForFirstLineStyle->isRenderBlockFlow() || rendererForFirstLineStyle->isRenderButton()) {
2850 if (RenderBlock* firstLineBlock = rendererForFirstLineStyle->firstLineBlock()) {
2852 return firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2853 return firstLineBlock->getUncachedPseudoStyle(PseudoStyleRequest(FIRST_LINE), style, firstLineBlock == renderer ? style : 0);
2855 } else if (!rendererForFirstLineStyle->isAnonymous() && rendererForFirstLineStyle->isRenderInline()) {
2856 RenderStyle* parentStyle = rendererForFirstLineStyle->parent()->firstLineStyle();
2857 if (parentStyle != rendererForFirstLineStyle->parent()->style()) {
2858 if (type == Cached) {
2859 // A first-line style is in effect. Cache a first-line style for ourselves.
2860 rendererForFirstLineStyle->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
2861 return rendererForFirstLineStyle->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2863 return rendererForFirstLineStyle->getUncachedPseudoStyle(PseudoStyleRequest(FIRST_LINE_INHERITED), parentStyle, style);
2869 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
2871 if (!document().styleEngine()->usesFirstLineRules())
2876 return firstLineStyleForCachedUncachedType(Uncached, this, style);
2879 RenderStyle* RenderObject::cachedFirstLineStyle() const
2881 ASSERT(document().styleEngine()->usesFirstLineRules());
2883 if (RefPtr<RenderStyle> style = firstLineStyleForCachedUncachedType(Cached, isText() ? parent() : this, m_style.get()))
2886 return m_style.get();
2889 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2891 if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2894 RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2898 RefPtr<RenderStyle> result = getUncachedPseudoStyle(PseudoStyleRequest(pseudo), parentStyle);
2900 return style()->addCachedPseudoStyle(result.release());
2904 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2906 if (pseudoStyleRequest.pseudoId < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudoStyleRequest.pseudoId))
2911 parentStyle = style();
2914 // FIXME: This "find nearest element parent" should be a helper function.
2916 while (n && !n->isElementNode())
2917 n = n->parentNode();
2920 Element* element = toElement(n);
2922 if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
2923 RefPtr<RenderStyle> result = document().ensureStyleResolver().styleForElement(element, parentStyle, DisallowStyleSharing);
2924 result->setStyleType(FIRST_LINE_INHERITED);
2925 return result.release();
2928 return document().ensureStyleResolver().pseudoStyleForElement(element, pseudoStyleRequest, parentStyle);
2931 bool RenderObject::hasBlendMode() const
2933 return RuntimeEnabledFeatures::cssCompositingEnabled() && style() && style()->hasBlendMode();
2936 static Color decorationColor(const RenderObject* object, RenderStyle* style)
2938 // Check for text decoration color first.
2939 StyleColor result = style->visitedDependentDecorationColor();
2940 if (!result.isCurrentColor())
2941 return result.color();
2943 if (style->textStrokeWidth() > 0) {
2944 // Prefer stroke color if possible but not if it's fully transparent.
2945 Color textStrokeColor = object->resolveColor(style, CSSPropertyWebkitTextStrokeColor);
2946 if (textStrokeColor.alpha())
2947 return textStrokeColor;
2950 return object->resolveColor(style, CSSPropertyWebkitTextFillColor);
2953 void RenderObject::getTextDecorationColors(unsigned decorations, Color& underline, Color& overline,
2954 Color& linethrough, bool quirksMode, bool firstlineStyle)
2956 RenderObject* curr = this;
2957 RenderStyle* styleToUse = 0;
2958 unsigned currDecs = TextDecorationNone;
2961 styleToUse = curr->style(firstlineStyle);
2962 currDecs = styleToUse->textDecoration();
2963 currDecs &= decorations;
2964 resultColor = decorationColor(this, styleToUse);
2965 // Parameter 'decorations' is cast as an int to enable the bitwise operations below.
2967 if (currDecs & TextDecorationUnderline) {
2968 decorations &= ~TextDecorationUnderline;
2969 underline = resultColor;
2971 if (currDecs & TextDecorationOverline) {
2972 decorations &= ~TextDecorationOverline;
2973 overline = resultColor;
2975 if (currDecs & TextDecorationLineThrough) {
2976 decorations &= ~TextDecorationLineThrough;
2977 linethrough = resultColor;
2980 if (curr->isRubyText())
2982 curr = curr->parent();
2983 if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
2984 curr = toRenderBlock(curr)->continuation();
2985 } while (curr && decorations && (!quirksMode || !curr->node() || (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2987 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2988 if (decorations && curr) {
2989 styleToUse = curr->style(firstlineStyle);
2990 resultColor = decorationColor(this, styleToUse);
2991 if (decorations & TextDecorationUnderline)
2992 underline = resultColor;
2993 if (decorations & TextDecorationOverline)
2994 overline = resultColor;
2995 if (decorations & TextDecorationLineThrough)
2996 linethrough = resultColor;
3000 void RenderObject::addAnnotatedRegions(Vector<AnnotatedRegionValue>& regions)
3002 // Convert the style regions to absolute coordinates.
3003 if (style()->visibility() != VISIBLE || !isBox())
3006 if (style()->getDraggableRegionMode() == DraggableRegionNone)
3009 RenderBox* box = toRenderBox(this);
3010 FloatRect localBounds(FloatPoint(), FloatSize(box->width(), box->height()));
3011 FloatRect absBounds = localToAbsoluteQuad(localBounds).boundingBox();
3013 AnnotatedRegionValue region;
3014 region.draggable = style()->getDraggableRegionMode() == DraggableRegionDrag;
3015 region.bounds = LayoutRect(absBounds);
3016 regions.append(region);
3019 void RenderObject::collectAnnotatedRegions(Vector<AnnotatedRegionValue>& regions)
3021 // RenderTexts don't have their own style, they just use their parent's style,
3022 // so we don't want to include them.
3026 addAnnotatedRegions(regions);
3027 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
3028 curr->collectAnnotatedRegions(regions);
3031 bool RenderObject::willRenderImage(ImageResource*)
3033 // Without visibility we won't render (and therefore don't care about animation).
3034 if (style()->visibility() != VISIBLE)
3037 // We will not render a new image when Active DOM is suspended
3038 if (document().activeDOMObjectsAreSuspended())
3041 // If we're not in a window (i.e., we're dormant from being in a background tab)
3042 // then we don't want to render either.
3043 return document().view()->isVisible();
3046 int RenderObject::maximalOutlineSize(PaintPhase p) const
3048 if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
3050 return view()->maximalOutlineSize();
3053 int RenderObject::caretMinOffset() const
3058 int RenderObject::caretMaxOffset() const
3061 return node() ? max(1U, node()->childNodeCount()) : 1;
3067 int RenderObject::previousOffset(int current) const
3072 int RenderObject::previousOffsetForBackwardDeletion(int current) const
3077 int RenderObject::nextOffset(int current) const
3082 void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const
3084 int outlineSize = outlineStyleForRepaint()->outlineSize();
3085 if (const ShadowList* boxShadow = style()->boxShadow()) {
3086 boxShadow->adjustRectForShadow(rect, outlineSize);
3090 rect.inflate(outlineSize);
3093 bool RenderObject::isInert() const
3095 const RenderObject* renderer = this;
3096 while (!renderer->node())
3097 renderer = renderer->parent();
3098 return renderer->node()->isInert();
3101 void RenderObject::imageChanged(ImageResource* image, const IntRect* rect)
3103 imageChanged(static_cast<WrappedImagePtr>(image), rect);
3106 Element* RenderObject::offsetParent() const
3108 if (isRoot() || isBody())
3111 if (isOutOfFlowPositioned() && style()->position() == FixedPosition)
3114 // If A is an area HTML element which has a map HTML element somewhere in the ancestor
3115 // chain return the nearest ancestor map HTML element and stop this algorithm.
3116 // FIXME: Implement!
3118 float effectiveZoom = style()->effectiveZoom();
3120 for (RenderObject* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
3121 // Spec: http://www.w3.org/TR/cssom-view/#offset-attributes
3123 node = ancestor->node();
3128 if (ancestor->isPositioned())
3131 if (node->hasTagName(bodyTag))
3134 if (!isPositioned() && (node->hasTagName(tableTag) || node->hasTagName(tdTag) || node->hasTagName(thTag)))
3137 // Webkit specific extension where offsetParent stops at zoom level changes.
3138 if (effectiveZoom != ancestor->style()->effectiveZoom())
3142 return node && node->isElementNode() ? toElement(node) : 0;
3145 PositionWithAffinity RenderObject::createPositionWithAffinity(int offset, EAffinity affinity)
3147 // If this is a non-anonymous renderer in an editable area, then it's simple.
3148 if (Node* node = nonPseudoNode()) {
3149 if (!node->rendererIsEditable()) {
3150 // If it can be found, we prefer a visually equivalent position that is editable.
3151 Position position = createLegacyEditingPosition(node, offset);
3152 Position candidate = position.downstream(CanCrossEditingBoundary);
3153 if (candidate.deprecatedNode()->rendererIsEditable())
3154 return PositionWithAffinity(candidate, affinity);
3155 candidate = position.upstream(CanCrossEditingBoundary);
3156 if (candidate.deprecatedNode()->rendererIsEditable())
3157 return PositionWithAffinity(candidate, affinity);
3159 // FIXME: Eliminate legacy editing positions
3160 return PositionWithAffinity(createLegacyEditingPosition(node, offset), affinity);
3163 // We don't want to cross the boundary between editable and non-editable
3164 // regions of the document, but that is either impossible or at least
3165 // extremely unlikely in any normal case because we stop as soon as we
3166 // find a single non-anonymous renderer.
3168 // Find a nearby non-anonymous renderer.
3169 RenderObject* child = this;
3170 while (RenderObject* parent = child->parent()) {
3171 // Find non-anonymous content after.
3172 RenderObject* renderer = child;
3173 while ((renderer = renderer->nextInPreOrder(parent))) {
3174 if (Node* node = renderer->nonPseudoNode())
3175 return PositionWithAffinity(firstPositionInOrBeforeNode(node), DOWNSTREAM);
3178 // Find non-anonymous content before.
3180 while ((renderer = renderer->previousInPreOrder())) {
3181 if (renderer == parent)
3183 if (Node* node = renderer->nonPseudoNode())
3184 return PositionWithAffinity(lastPositionInOrAfterNode(node), DOWNSTREAM);
3187 // Use the parent itself unless it too is anonymous.
3188 if (Node* node = parent->nonPseudoNode())
3189 return PositionWithAffinity(firstPositionInOrBeforeNode(node), DOWNSTREAM);
3191 // Repeat at the next level up.
3195 // Everything was anonymous. Give up.
3196 return PositionWithAffinity();
3199 PositionWithAffinity RenderObject::createPositionWithAffinity(const Position& position)
3201 if (position.isNotNull())
3202 return PositionWithAffinity(position);
3205 return createPositionWithAffinity(0, DOWNSTREAM);
3208 CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
3210 return SetCursorBasedOnStyle;
3213 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
3218 RenderBlock* containingBlock = this->containingBlock();
3219 return containingBlock ? !containingBlock->needsLayout() : true;
3222 // We only create "generated" child renderers like one for first-letter if:
3223 // - the firstLetterBlock can have children in the DOM and
3224 // - the block doesn't have any special assumption on its text children.
3225 // This correctly prevents form controls from having such renderers.
3226 bool RenderObject::canHaveGeneratedChildren() const
3228 return canHaveChildren();
3231 void RenderObject::setNeedsBoundariesUpdate()
3233 if (RenderObject* renderer = parent())
3234 renderer->setNeedsBoundariesUpdate();
3237 FloatRect RenderObject::objectBoundingBox() const
3239 ASSERT_NOT_REACHED();
3243 FloatRect RenderObject::strokeBoundingBox() const
3245 ASSERT_NOT_REACHED();
3249 // Returns the smallest rectangle enclosing all of the painted content
3250 // respecting clipping, masking, filters, opacity, stroke-width and markers
3251 FloatRect RenderObject::repaintRectInLocalCoordinates() const
3253 ASSERT_NOT_REACHED();
3257 AffineTransform RenderObject::localTransform() const
3259 static const AffineTransform identity;
3263 const AffineTransform& RenderObject::localToParentTransform() const
3265 static const AffineTransform identity;
3269 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
3271 ASSERT_NOT_REACHED();
3275 bool RenderObject::isRelayoutBoundaryForInspector() const
3277 return objectIsRelayoutBoundary(this);
3280 } // namespace WebCore
3284 void showTree(const WebCore::RenderObject* object)
3287 object->showTreeForThis();
3290 void showLineTree(const WebCore::RenderObject* object)
3293 object->showLineTreeForThis();
3296 void showRenderTree(const WebCore::RenderObject* object1)
3298 showRenderTree(object1, 0);
3301 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
3304 const WebCore::RenderObject* root = object1;
3305 while (root->parent())
3306 root = root->parent();
3307 root->showRenderTreeAndMark(object1, "*", object2, "-", 0);