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 "RenderObject.h"
30 #include "AXObjectCache.h"
32 #include "ContentData.h"
33 #include "CursorList.h"
34 #include "DashArray.h"
35 #include "EditingBoundary.h"
36 #include "FloatQuad.h"
37 #include "FlowThreadController.h"
39 #include "FrameView.h"
40 #include "GraphicsContext.h"
41 #include "HTMLElement.h"
42 #include "HTMLNames.h"
43 #include "HitTestResult.h"
45 #include "RenderArena.h"
46 #include "RenderCounter.h"
47 #include "RenderDeprecatedFlexibleBox.h"
48 #include "RenderFlexibleBox.h"
49 #include "RenderGeometryMap.h"
50 #include "RenderGrid.h"
51 #include "RenderImage.h"
52 #include "RenderImageResourceStyleImage.h"
53 #include "RenderInline.h"
54 #include "RenderLayer.h"
55 #include "RenderListItem.h"
56 #include "RenderMultiColumnBlock.h"
57 #include "RenderNamedFlowThread.h"
58 #include "RenderRegion.h"
59 #include "RenderRuby.h"
60 #include "RenderRubyText.h"
61 #include "RenderScrollbarPart.h"
62 #include "RenderTableCaption.h"
63 #include "RenderTableCell.h"
64 #include "RenderTableCol.h"
65 #include "RenderTableRow.h"
66 #include "RenderTheme.h"
67 #include "RenderView.h"
69 #include "StyleResolver.h"
70 #include "TransformState.h"
71 #include "htmlediting.h"
74 #include <wtf/RefCountedLeakCounter.h>
75 #include <wtf/UnusedParam.h>
77 #if USE(ACCELERATED_COMPOSITING)
78 #include "RenderLayerCompositor.h"
82 #include "RenderSVGResourceContainer.h"
83 #include "SVGRenderSupport.h"
90 using namespace HTMLNames;
93 static void* baseOfRenderObjectBeingDeleted;
96 struct SameSizeAsRenderObject {
97 virtual ~SameSizeAsRenderObject() { } // Allocate vtable pointer.
100 unsigned m_debugBitfields : 2;
102 unsigned m_bitfields;
105 COMPILE_ASSERT(sizeof(RenderObject) == sizeof(SameSizeAsRenderObject), RenderObject_should_stay_small);
107 bool RenderObject::s_affectsParentBlock = false;
109 RenderObjectAncestorLineboxDirtySet* RenderObject::s_ancestorLineboxDirtySet = 0;
111 void* RenderObject::operator new(size_t sz, RenderArena* renderArena)
113 return renderArena->allocate(sz);
116 void RenderObject::operator delete(void* ptr, size_t sz)
118 ASSERT(baseOfRenderObjectBeingDeleted == ptr);
120 // Stash size where destroy can find it.
124 RenderObject* RenderObject::createObject(Node* node, RenderStyle* style)
126 Document* doc = node->document();
127 RenderArena* arena = doc->renderArena();
129 // Minimal support for content properties replacing an entire element.
130 // Works only if we have exactly one piece of content and it's a URL.
131 // Otherwise acts as if we didn't support this feature.
132 const ContentData* contentData = style->contentData();
133 if (contentData && !contentData->next() && contentData->isImage() && doc != node) {
134 RenderImage* image = new (arena) RenderImage(node);
135 image->setStyle(style);
136 if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image()) {
137 image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
138 image->setIsGeneratedContent();
140 image->setImageResource(RenderImageResource::create());
144 if (node->hasTagName(rubyTag)) {
145 if (style->display() == INLINE)
146 return new (arena) RenderRubyAsInline(node);
147 else if (style->display() == BLOCK)
148 return new (arena) RenderRubyAsBlock(node);
150 // treat <rt> as ruby text ONLY if it still has its default treatment of block
151 if (node->hasTagName(rtTag) && style->display() == BLOCK)
152 return new (arena) RenderRubyText(node);
153 if (doc->cssRegionsEnabled() && style->isDisplayRegionType() && !style->regionThread().isEmpty() && doc->renderView())
154 return new (arena) RenderRegion(node, doc->renderView()->flowThreadController()->ensureRenderFlowThreadWithName(style->regionThread()));
155 switch (style->display()) {
159 return new (arena) RenderInline(node);
164 if ((!style->hasAutoColumnCount() || !style->hasAutoColumnWidth()) && doc->regionBasedColumnsEnabled())
165 return new (arena) RenderMultiColumnBlock(node);
166 return new (arena) RenderBlock(node);
168 return new (arena) RenderListItem(node);
171 return new (arena) RenderTable(node);
172 case TABLE_ROW_GROUP:
173 case TABLE_HEADER_GROUP:
174 case TABLE_FOOTER_GROUP:
175 return new (arena) RenderTableSection(node);
177 return new (arena) RenderTableRow(node);
178 case TABLE_COLUMN_GROUP:
180 return new (arena) RenderTableCol(node);
182 return new (arena) RenderTableCell(node);
184 return new (arena) RenderTableCaption(node);
187 return new (arena) RenderDeprecatedFlexibleBox(node);
188 #if ENABLE(CSS3_FLEXBOX)
191 return new (arena) RenderFlexibleBox(node);
195 return new (arena) RenderGrid(node);
201 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject"));
203 RenderObject::RenderObject(Node* node)
204 : CachedImageClient()
211 , m_hasAXObject(false)
212 , m_setNeedsLayoutForbidden(false)
217 renderObjectCounter.increment();
222 RenderObject::~RenderObject()
225 ASSERT(!m_hasAXObject);
226 renderObjectCounter.decrement();
230 RenderTheme* RenderObject::theme() const
232 ASSERT(document()->page());
234 return document()->page()->theme();
237 bool RenderObject::isDescendantOf(const RenderObject* obj) const
239 for (const RenderObject* r = this; r; r = r->m_parent) {
246 bool RenderObject::isBody() const
248 return node() && node()->hasTagName(bodyTag);
251 bool RenderObject::isHR() const
253 return node() && node()->hasTagName(hrTag);
256 bool RenderObject::isLegend() const
258 return node() && node()->hasTagName(legendTag);
261 bool RenderObject::isHTMLMarquee() const
263 return node() && node()->renderer() == this && node()->hasTagName(marqueeTag);
266 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
268 RenderObjectChildList* children = virtualChildren();
273 bool needsTable = false;
275 if (newChild->isRenderTableCol()) {
276 RenderTableCol* newTableColumn = toRenderTableCol(newChild);
277 bool isColumnInColumnGroup = newTableColumn->isTableColumn() && isRenderTableCol();
278 needsTable = !isTable() && !isColumnInColumnGroup;
279 } else if (newChild->isTableCaption())
280 needsTable = !isTable();
281 else if (newChild->isTableSection())
282 needsTable = !isTable();
283 else if (newChild->isTableRow())
284 needsTable = !isTableSection();
285 else if (newChild->isTableCell())
286 needsTable = !isTableRow();
290 RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
291 if (afterChild && afterChild->isAnonymous() && afterChild->isTable() && !afterChild->isBeforeContent())
292 table = toRenderTable(afterChild);
294 table = RenderTable::createAnonymousWithParentRenderer(this);
295 addChild(table, beforeChild);
297 table->addChild(newChild);
299 children->insertChildNode(this, newChild, beforeChild);
301 if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE)
302 toRenderText(newChild)->transformText();
304 // SVG creates renderers for <g display="none">, as SVG requires children of hidden
305 // <g>s to have renderers - at least that's how our implementation works. Consider:
306 // <g display="none"><foreignObject><body style="position: relative">FOO...
307 // - requiresLayer() would return true for the <body>, creating a new RenderLayer
308 // - when the document is painted, both layers are painted. The <body> layer doesn't
309 // know that it's inside a "hidden SVG subtree", and thus paints, even if it shouldn't.
310 // To avoid the problem alltogether, detect early if we're inside a hidden SVG subtree
311 // and stop creating layers at all for these cases - they're not used anyways.
312 if (newChild->hasLayer() && !layerCreationAllowedForSubtree())
313 toRenderBoxModelObject(newChild)->layer()->removeOnlyThisLayer();
316 void RenderObject::removeChild(RenderObject* oldChild)
318 RenderObjectChildList* children = virtualChildren();
323 children->removeChildNode(this, oldChild);
326 RenderObject* RenderObject::nextInPreOrder() const
328 if (RenderObject* o = firstChild())
331 return nextInPreOrderAfterChildren();
334 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
337 if (!(o = nextSibling())) {
339 while (o && !o->nextSibling())
342 o = o->nextSibling();
348 RenderObject* RenderObject::nextInPreOrder(const RenderObject* stayWithin) const
350 if (RenderObject* o = firstChild())
353 return nextInPreOrderAfterChildren(stayWithin);
356 RenderObject* RenderObject::nextInPreOrderAfterChildren(const RenderObject* stayWithin) const
358 if (this == stayWithin)
361 const RenderObject* current = this;
363 while (!(next = current->nextSibling())) {
364 current = current->parent();
365 if (!current || current == stayWithin)
371 RenderObject* RenderObject::previousInPreOrder() const
373 if (RenderObject* o = previousSibling()) {
374 while (o->lastChild())
382 RenderObject* RenderObject::previousInPreOrder(const RenderObject* stayWithin) const
384 if (this == stayWithin)
387 return previousInPreOrder();
390 RenderObject* RenderObject::childAt(unsigned index) const
392 RenderObject* child = firstChild();
393 for (unsigned i = 0; child && i < index; i++)
394 child = child->nextSibling();
398 RenderObject* RenderObject::firstLeafChild() const
400 RenderObject* r = firstChild();
411 RenderObject* RenderObject::lastLeafChild() const
413 RenderObject* r = lastChild();
424 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
425 RenderLayer*& beforeChild)
427 if (obj->hasLayer()) {
428 if (!beforeChild && newObject) {
429 // We need to figure out the layer that follows newObject. We only do
430 // this the first time we find a child layer, and then we update the
431 // pointer values for newObject and beforeChild used by everyone else.
432 beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
435 parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild);
439 for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
440 addLayers(curr, parentLayer, newObject, beforeChild);
443 void RenderObject::addLayers(RenderLayer* parentLayer)
448 RenderObject* object = this;
449 RenderLayer* beforeChild = 0;
450 WebCore::addLayers(this, parentLayer, object, beforeChild);
453 void RenderObject::removeLayers(RenderLayer* parentLayer)
459 parentLayer->removeChild(toRenderBoxModelObject(this)->layer());
463 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
464 curr->removeLayers(parentLayer);
467 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
473 RenderLayer* layer = toRenderBoxModelObject(this)->layer();
474 ASSERT(oldParent == layer->parent());
476 oldParent->removeChild(layer);
477 newParent->addChild(layer);
481 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
482 curr->moveLayers(oldParent, newParent);
485 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
488 // Error check the parent layer passed in. If it's null, we can't find anything.
492 // Step 1: If our layer is a child of the desired parent, then return our layer.
493 RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0;
494 if (ourLayer && ourLayer->parent() == parentLayer)
497 // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
498 // into our siblings trying to find the next layer whose parent is the desired parent.
499 if (!ourLayer || ourLayer == parentLayer) {
500 for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
501 curr; curr = curr->nextSibling()) {
502 RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
508 // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
510 if (parentLayer == ourLayer)
513 // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
514 // follow us to see if we can locate a layer.
515 if (checkParent && parent())
516 return parent()->findNextLayer(parentLayer, this, true);
521 RenderLayer* RenderObject::enclosingLayer() const
523 const RenderObject* curr = this;
525 RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
528 curr = curr->parent();
533 bool RenderObject::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
535 RenderLayer* enclosingLayer = this->enclosingLayer();
539 enclosingLayer->scrollRectToVisible(rect, alignX, alignY);
543 RenderBox* RenderObject::enclosingBox() const
545 RenderObject* curr = const_cast<RenderObject*>(this);
548 return toRenderBox(curr);
549 curr = curr->parent();
552 ASSERT_NOT_REACHED();
556 RenderBoxModelObject* RenderObject::enclosingBoxModelObject() const
558 RenderObject* curr = const_cast<RenderObject*>(this);
560 if (curr->isBoxModelObject())
561 return toRenderBoxModelObject(curr);
562 curr = curr->parent();
565 ASSERT_NOT_REACHED();
569 RenderFlowThread* RenderObject::enclosingRenderFlowThread() const
571 if (!inRenderFlowThread())
574 // See if we have the thread cached because we're in the middle of layout.
575 RenderFlowThread* flowThread = view()->flowThreadController()->currentRenderFlowThread();
579 // Not in the middle of layout so have to find the thread the slow way.
580 RenderObject* curr = const_cast<RenderObject*>(this);
582 if (curr->isRenderFlowThread())
583 return toRenderFlowThread(curr);
584 curr = curr->parent();
589 RenderBlock* RenderObject::firstLineBlock() const
594 static inline bool objectIsRelayoutBoundary(const RenderObject* object)
596 // FIXME: In future it may be possible to broaden these conditions in order to improve performance.
597 if (object->isTextControl())
601 if (object->isSVGRoot())
605 if (!object->hasOverflowClip())
608 if (object->style()->width().isIntrinsicOrAuto() || object->style()->height().isIntrinsicOrAuto() || object->style()->height().isPercent())
611 // Table parts can't be relayout roots since the table is responsible for layouting all the parts.
612 if (object->isTablePart())
618 void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot)
620 ASSERT(!scheduleRelayout || !newRoot);
622 RenderObject* object = container();
623 RenderObject* last = this;
625 bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout();
628 // Don't mark the outermost object of an unrooted subtree. That object will be
629 // marked when the subtree is added to the document.
630 RenderObject* container = object->container();
631 if (!container && !object->isRenderView())
633 if (!last->isText() && last->style()->isOutOfFlowPositioned()) {
634 bool willSkipRelativelyPositionedInlines = !object->isRenderBlock() || object->isAnonymousBlock();
635 // Skip relatively positioned inlines and anonymous blocks to get to the enclosing RenderBlock.
636 while (object && (!object->isRenderBlock() || object->isAnonymousBlock()))
637 object = object->container();
638 if (!object || object->posChildNeedsLayout())
640 if (willSkipRelativelyPositionedInlines)
641 container = object->container();
642 object->setPosChildNeedsLayout(true);
643 simplifiedNormalFlowLayout = true;
644 ASSERT(!object->isSetNeedsLayoutForbidden());
645 } else if (simplifiedNormalFlowLayout) {
646 if (object->needsSimplifiedNormalFlowLayout())
648 object->setNeedsSimplifiedNormalFlowLayout(true);
649 ASSERT(!object->isSetNeedsLayoutForbidden());
651 if (object->normalChildNeedsLayout())
653 object->setNormalChildNeedsLayout(true);
654 ASSERT(!object->isSetNeedsLayoutForbidden());
657 if (object == newRoot)
661 if (scheduleRelayout && objectIsRelayoutBoundary(last))
666 if (scheduleRelayout)
667 last->scheduleRelayout();
671 void RenderObject::checkBlockPositionedObjectsNeedLayout()
673 ASSERT(!needsLayout());
676 toRenderBlock(this)->checkPositionedObjectsNeedLayout();
680 void RenderObject::setPreferredLogicalWidthsDirty(bool shouldBeDirty, MarkingBehavior markParents)
682 bool alreadyDirty = preferredLogicalWidthsDirty();
683 m_bitfields.setPreferredLogicalWidthsDirty(shouldBeDirty);
684 if (shouldBeDirty && !alreadyDirty && markParents == MarkContainingBlockChain && (isText() || !style()->isOutOfFlowPositioned()))
685 invalidateContainerPreferredLogicalWidths();
688 void RenderObject::invalidateContainerPreferredLogicalWidths()
690 // In order to avoid pathological behavior when inlines are deeply nested, we do include them
691 // in the chain that we mark dirty (even though they're kind of irrelevant).
692 RenderObject* o = isTableCell() ? containingBlock() : container();
693 while (o && !o->preferredLogicalWidthsDirty()) {
694 // Don't invalidate the outermost object of an unrooted subtree. That object will be
695 // invalidated when the subtree is added to the document.
696 RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
697 if (!container && !o->isRenderView())
700 o->m_bitfields.setPreferredLogicalWidthsDirty(true);
701 if (o->style()->isOutOfFlowPositioned())
702 // A positioned object has no effect on the min/max width of its containing block ever.
703 // We can optimize this case and not go up any further.
709 void RenderObject::setLayerNeedsFullRepaint()
712 toRenderBoxModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaint);
715 void RenderObject::setLayerNeedsFullRepaintForPositionedMovementLayout()
718 toRenderBoxModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaintForPositionedMovementLayout);
721 RenderBlock* RenderObject::containingBlock() const
723 RenderObject* o = parent();
724 if (!o && isRenderScrollbarPart())
725 o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
726 if (!isText() && m_style->position() == FixedPosition) {
728 if (o->isRenderView())
730 if (o->hasTransform() && o->isRenderBlock())
732 // The render flow thread is the top most containing block
733 // for the fixed positioned elements.
734 if (o->isRenderFlowThread())
737 // foreignObject is the containing block for its contents.
738 if (o->isSVGForeignObject())
743 ASSERT(!o->isAnonymousBlock());
744 } else if (!isText() && m_style->position() == AbsolutePosition) {
746 // For relpositioned inlines, we return the nearest non-anonymous enclosing block. We don't try
747 // to return the inline itself. This allows us to avoid having a positioned objects
748 // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
749 // from this method. The container() method can actually be used to obtain the
751 if (!o->style()->position() == StaticPosition && !(o->isInline() && !o->isReplaced()))
753 if (o->isRenderView())
755 if (o->hasTransform() && o->isRenderBlock())
758 if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced()) {
759 o = o->containingBlock();
763 if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it
770 while (o && o->isAnonymousBlock())
771 o = o->containingBlock();
773 while (o && ((o->isInline() && !o->isReplaced()) || !o->isRenderBlock()))
777 if (!o || !o->isRenderBlock())
778 return 0; // This can still happen in case of an orphaned tree
780 return toRenderBlock(o);
783 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
785 // Nobody will use multiple layers without wanting fancy positioning.
789 // Make sure we have a valid image.
790 StyleImage* img = layer->image();
791 if (!img || !img->canRender(renderer, renderer->style()->effectiveZoom()))
794 if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
797 if (layer->size().type == SizeLength) {
798 if (layer->size().size.width().isPercent() || layer->size().size.height().isPercent())
800 } else if (layer->size().type == Contain || layer->size().type == Cover || img->usesImageContainerSize())
806 bool RenderObject::borderImageIsLoadedAndCanBeRendered() const
808 ASSERT(style()->hasBorder());
810 StyleImage* borderImage = style()->borderImage().image();
811 return borderImage && borderImage->canRender(this, style()->effectiveZoom()) && borderImage->isLoaded();
814 bool RenderObject::mustRepaintBackgroundOrBorder() const
816 if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
819 // If we don't have a background/border/mask, then nothing to do.
820 if (!hasBoxDecorations())
823 if (mustRepaintFillLayers(this, style()->backgroundLayers()))
826 // Our fill layers are ok. Let's check border.
827 if (style()->hasBorder() && borderImageIsLoadedAndCanBeRendered())
833 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
834 BoxSide side, Color color, EBorderStyle style,
835 int adjacentWidth1, int adjacentWidth2, bool antialias)
837 int width = (side == BSTop || side == BSBottom ? y2 - y1 : x2 - x1);
839 // FIXME: We really would like this check to be an ASSERT as we don't want to draw 0px borders. However
840 // nothing guarantees that the following recursive calls to drawLineForBoxSide will have non-null width.
844 if (style == DOUBLE && width < 3)
853 graphicsContext->setStrokeColor(color, m_style->colorSpace());
854 graphicsContext->setStrokeThickness(width);
855 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
856 graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
859 bool wasAntialiased = graphicsContext->shouldAntialias();
860 graphicsContext->setShouldAntialias(antialias);
865 graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
869 graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
872 graphicsContext->setShouldAntialias(wasAntialiased);
873 graphicsContext->setStrokeStyle(oldStrokeStyle);
878 int third = (width + 1) / 3;
880 if (adjacentWidth1 == 0 && adjacentWidth2 == 0) {
881 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
882 graphicsContext->setStrokeStyle(NoStroke);
883 graphicsContext->setFillColor(color, m_style->colorSpace());
885 bool wasAntialiased = graphicsContext->shouldAntialias();
886 graphicsContext->setShouldAntialias(antialias);
891 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third));
892 graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third));
895 graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
896 graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
899 graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
900 graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
904 graphicsContext->setShouldAntialias(wasAntialiased);
905 graphicsContext->setStrokeStyle(oldStrokeStyle);
907 int adjacent1BigThird = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3;
908 int adjacent2BigThird = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3;
912 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
913 y1, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y1 + third,
914 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
915 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
916 y2 - third, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y2,
917 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
920 drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
921 x1 + third, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
922 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
923 drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
924 x2, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
925 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
928 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
929 y1, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y1 + third,
930 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
931 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
932 y2 - third, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y2,
933 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
936 drawLineForBoxSide(graphicsContext, x1, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
937 x1 + third, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
938 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
939 drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
940 x2, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
941 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
953 if (style == GROOVE) {
961 int adjacent1BigHalf = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2;
962 int adjacent2BigHalf = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2;
966 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1, 0) / 2, y1, x2 - max(-adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
967 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
968 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjacentWidth2 + 1, 0) / 2, y2,
969 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
972 drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjacentWidth2, 0) / 2,
973 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
974 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjacentWidth1 + 1, 0) / 2, x2, y2 - max(adjacentWidth2 + 1, 0) / 2,
975 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
978 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1, 0) / 2, y1, x2 - max(adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
979 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
980 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjacentWidth2 + 1, 0) / 2, y2,
981 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
984 drawLineForBoxSide(graphicsContext, x1, y1 + max(adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjacentWidth2, 0) / 2,
985 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
986 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjacentWidth1 + 1, 0) / 2, x2, y2 - max(-adjacentWidth2 + 1, 0) / 2,
987 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
993 // FIXME: Maybe we should lighten the colors on one side like Firefox.
994 // https://bugs.webkit.org/show_bug.cgi?id=58608
995 if (side == BSTop || side == BSLeft)
996 color = color.dark();
999 if (style == OUTSET && (side == BSBottom || side == BSRight))
1000 color = color.dark();
1003 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
1004 graphicsContext->setStrokeStyle(NoStroke);
1005 graphicsContext->setFillColor(color, m_style->colorSpace());
1008 if (!adjacentWidth1 && !adjacentWidth2) {
1009 // Turn off antialiasing to match the behavior of drawConvexPolygon();
1010 // this matters for rects in transformed contexts.
1011 bool wasAntialiased = graphicsContext->shouldAntialias();
1012 graphicsContext->setShouldAntialias(antialias);
1013 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1014 graphicsContext->setShouldAntialias(wasAntialiased);
1015 graphicsContext->setStrokeStyle(oldStrokeStyle);
1021 quad[0] = FloatPoint(x1 + max(-adjacentWidth1, 0), y1);
1022 quad[1] = FloatPoint(x1 + max(adjacentWidth1, 0), y2);
1023 quad[2] = FloatPoint(x2 - max(adjacentWidth2, 0), y2);
1024 quad[3] = FloatPoint(x2 - max(-adjacentWidth2, 0), y1);
1027 quad[0] = FloatPoint(x1 + max(adjacentWidth1, 0), y1);
1028 quad[1] = FloatPoint(x1 + max(-adjacentWidth1, 0), y2);
1029 quad[2] = FloatPoint(x2 - max(-adjacentWidth2, 0), y2);
1030 quad[3] = FloatPoint(x2 - max(adjacentWidth2, 0), y1);
1033 quad[0] = FloatPoint(x1, y1 + max(-adjacentWidth1, 0));
1034 quad[1] = FloatPoint(x1, y2 - max(-adjacentWidth2, 0));
1035 quad[2] = FloatPoint(x2, y2 - max(adjacentWidth2, 0));
1036 quad[3] = FloatPoint(x2, y1 + max(adjacentWidth1, 0));
1039 quad[0] = FloatPoint(x1, y1 + max(adjacentWidth1, 0));
1040 quad[1] = FloatPoint(x1, y2 - max(adjacentWidth2, 0));
1041 quad[2] = FloatPoint(x2, y2 - max(-adjacentWidth2, 0));
1042 quad[3] = FloatPoint(x2, y1 + max(-adjacentWidth1, 0));
1046 graphicsContext->drawConvexPolygon(4, quad, antialias);
1047 graphicsContext->setStrokeStyle(oldStrokeStyle);
1053 void RenderObject::paintFocusRing(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style)
1055 Vector<IntRect> focusRingRects;
1056 addFocusRingRects(focusRingRects, paintOffset);
1057 if (style->outlineStyleIsAuto())
1058 context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
1060 addPDFURLRect(context, unionRect(focusRingRects));
1063 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
1068 if (!n || !n->isLink() || !n->isElementNode())
1070 const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
1073 context->setURLForRect(n->document()->completeURL(href), pixelSnappedIntRect(rect));
1076 void RenderObject::paintOutline(GraphicsContext* graphicsContext, const LayoutRect& paintRect)
1081 RenderStyle* styleToUse = style();
1082 LayoutUnit outlineWidth = styleToUse->outlineWidth();
1083 EBorderStyle outlineStyle = styleToUse->outlineStyle();
1085 Color outlineColor = styleToUse->visitedDependentColor(CSSPropertyOutlineColor);
1087 int outlineOffset = styleToUse->outlineOffset();
1089 if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1090 if (!theme()->supportsFocusRing(styleToUse)) {
1091 // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1092 paintFocusRing(graphicsContext, paintRect.location(), styleToUse);
1096 if (styleToUse->outlineStyleIsAuto() || styleToUse->outlineStyle() == BNONE)
1099 IntRect inner = pixelSnappedIntRect(paintRect);
1100 inner.inflate(outlineOffset);
1102 IntRect outer = pixelSnappedIntRect(inner);
1103 outer.inflate(outlineWidth);
1105 // FIXME: This prevents outlines from painting inside the object. See bug 12042
1106 if (outer.isEmpty())
1109 bool useTransparencyLayer = outlineColor.hasAlpha();
1110 if (useTransparencyLayer) {
1111 if (outlineStyle == SOLID) {
1113 path.addRect(outer);
1114 path.addRect(inner);
1115 graphicsContext->setFillRule(RULE_EVENODD);
1116 graphicsContext->setFillColor(outlineColor, styleToUse->colorSpace());
1117 graphicsContext->fillPath(path);
1120 graphicsContext->beginTransparencyLayer(static_cast<float>(outlineColor.alpha()) / 255);
1121 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineColor.blue());
1124 int leftOuter = outer.x();
1125 int leftInner = inner.x();
1126 int rightOuter = outer.maxX();
1127 int rightInner = inner.maxX();
1128 int topOuter = outer.y();
1129 int topInner = inner.y();
1130 int bottomOuter = outer.maxY();
1131 int bottomInner = inner.maxY();
1133 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1134 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInner, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1135 drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottomOuter, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1136 drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bottomOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1138 if (useTransparencyLayer)
1139 graphicsContext->endTransparencyLayer();
1142 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) const
1144 if (useTransforms) {
1145 Vector<FloatQuad> quads;
1146 absoluteQuads(quads);
1148 size_t n = quads.size();
1152 IntRect result = quads[0].enclosingBoundingBox();
1153 for (size_t i = 1; i < n; ++i)
1154 result.unite(quads[i].enclosingBoundingBox());
1158 FloatPoint absPos = localToAbsolute();
1159 Vector<IntRect> rects;
1160 absoluteRects(rects, flooredLayoutPoint(absPos));
1162 size_t n = rects.size();
1166 LayoutRect result = rects[0];
1167 for (size_t i = 1; i < n; ++i)
1168 result.unite(rects[i]);
1169 return pixelSnappedIntRect(result);
1172 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1174 Vector<IntRect> rects;
1175 // FIXME: addFocusRingRects() needs to be passed this transform-unaware
1176 // localToAbsolute() offset here because RenderInline::addFocusRingRects()
1177 // implicitly assumes that. This doesn't work correctly with transformed
1179 FloatPoint absolutePoint = localToAbsolute();
1180 addFocusRingRects(rects, flooredLayoutPoint(absolutePoint));
1181 size_t count = rects.size();
1182 for (size_t i = 0; i < count; ++i) {
1183 IntRect rect = rects[i];
1184 rect.move(-absolutePoint.x(), -absolutePoint.y());
1185 quads.append(localToAbsoluteQuad(FloatQuad(rect)));
1189 void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
1192 result.unite(absoluteBoundingBoxRectIgnoringTransforms());
1193 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1194 current->addAbsoluteRectForLayer(result);
1197 LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect)
1199 LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms();
1200 topLevelRect = result;
1201 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1202 current->addAbsoluteRectForLayer(result);
1206 void RenderObject::paint(PaintInfo&, const LayoutPoint&)
1210 RenderBoxModelObject* RenderObject::containerForRepaint() const
1212 RenderView* v = view();
1216 RenderBoxModelObject* repaintContainer = 0;
1218 #if USE(ACCELERATED_COMPOSITING)
1219 if (v->usesCompositing()) {
1220 if (RenderLayer* parentLayer = enclosingLayer()) {
1221 RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint();
1223 repaintContainer = compLayer->renderer();
1228 #if ENABLE(CSS_FILTERS)
1229 if (RenderLayer* parentLayer = enclosingLayer()) {
1230 RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer();
1231 if (enclosingFilterLayer)
1232 return enclosingFilterLayer->renderer();
1236 // If we have a flow thread, then we need to do individual repaints within the RenderRegions instead.
1237 // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change
1238 // repainting to do individual region repaints.
1239 // FIXME: Composited layers inside a flow thread will bypass this mechanism and will malfunction. It's not
1240 // clear how to address this problem for composited descendants of a RenderFlowThread.
1241 if (!repaintContainer && inRenderFlowThread())
1242 repaintContainer = enclosingRenderFlowThread();
1243 return repaintContainer;
1246 void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect& r, bool immediate)
1248 if (!repaintContainer) {
1249 view()->repaintViewRectangle(r, immediate);
1253 if (repaintContainer->isRenderFlowThread()) {
1254 toRenderFlowThread(repaintContainer)->repaintRectangleInRegions(r, immediate);
1258 #if ENABLE(CSS_FILTERS)
1259 if (repaintContainer->hasFilter() && repaintContainer->layer() && repaintContainer->layer()->requiresFullLayerImageForFilters()) {
1260 repaintContainer->layer()->setFilterBackendNeedsRepaintingInRect(r, immediate);
1265 #if USE(ACCELERATED_COMPOSITING)
1266 RenderView* v = view();
1267 if (repaintContainer->isRenderView()) {
1268 ASSERT(repaintContainer == v);
1269 bool viewHasCompositedLayer = v->hasLayer() && v->layer()->isComposited();
1270 if (!viewHasCompositedLayer || v->layer()->backing()->paintsIntoWindow()) {
1271 LayoutRect repaintRectangle = r;
1272 if (viewHasCompositedLayer && v->layer()->transform())
1273 repaintRectangle = v->layer()->transform()->mapRect(r);
1274 v->repaintViewRectangle(repaintRectangle, immediate);
1279 if (v->usesCompositing()) {
1280 ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
1281 repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
1284 if (repaintContainer->isRenderView())
1285 toRenderView(repaintContainer)->repaintViewRectangle(r, immediate);
1289 void RenderObject::repaint(bool immediate)
1291 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1293 if (!isRooted(&view))
1296 if (view->printing())
1297 return; // Don't repaint if we're printing.
1299 RenderBoxModelObject* repaintContainer = containerForRepaint();
1300 repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate);
1303 void RenderObject::repaintRectangle(const LayoutRect& r, bool immediate)
1305 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1307 if (!isRooted(&view))
1310 if (view->printing())
1311 return; // Don't repaint if we're printing.
1313 LayoutRect dirtyRect(r);
1315 // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1316 // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1317 dirtyRect.move(view->layoutDelta());
1319 RenderBoxModelObject* repaintContainer = containerForRepaint();
1320 computeRectForRepaint(repaintContainer, dirtyRect);
1321 repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate);
1324 IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const
1326 return pixelSnappedIntRect(absoluteClippedOverflowRect());
1329 bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr, const LayoutRect* newOutlineBoxRectPtr)
1331 RenderView* v = view();
1333 return false; // Don't repaint if we're printing.
1335 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1336 // ASSERT(!newBoundsPtr || *newBoundsPtr == clippedOverflowRectForRepaint(repaintContainer));
1337 LayoutRect newBounds = newBoundsPtr ? *newBoundsPtr : clippedOverflowRectForRepaint(repaintContainer);
1338 LayoutRect newOutlineBox;
1340 bool fullRepaint = selfNeedsLayout();
1341 // Presumably a background or a border exists if border-fit:lines was specified.
1342 if (!fullRepaint && style()->borderFit() == BorderFitLines)
1345 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1346 // ASSERT(!newOutlineBoxRectPtr || *newOutlineBoxRectPtr == outlineBoundsForRepaint(repaintContainer));
1347 newOutlineBox = newOutlineBoxRectPtr ? *newOutlineBoxRectPtr : outlineBoundsForRepaint(repaintContainer);
1348 if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1352 if (!repaintContainer)
1353 repaintContainer = v;
1356 repaintUsingContainer(repaintContainer, oldBounds);
1357 if (newBounds != oldBounds)
1358 repaintUsingContainer(repaintContainer, newBounds);
1362 if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1365 LayoutUnit deltaLeft = newBounds.x() - oldBounds.x();
1367 repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1368 else if (deltaLeft < 0)
1369 repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1371 LayoutUnit deltaRight = newBounds.maxX() - oldBounds.maxX();
1373 repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.maxX(), newBounds.y(), deltaRight, newBounds.height()));
1374 else if (deltaRight < 0)
1375 repaintUsingContainer(repaintContainer, LayoutRect(newBounds.maxX(), oldBounds.y(), -deltaRight, oldBounds.height()));
1377 LayoutUnit deltaTop = newBounds.y() - oldBounds.y();
1379 repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1380 else if (deltaTop < 0)
1381 repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1383 LayoutUnit deltaBottom = newBounds.maxY() - oldBounds.maxY();
1384 if (deltaBottom > 0)
1385 repaintUsingContainer(repaintContainer, LayoutRect(newBounds.x(), oldBounds.maxY(), newBounds.width(), deltaBottom));
1386 else if (deltaBottom < 0)
1387 repaintUsingContainer(repaintContainer, LayoutRect(oldBounds.x(), newBounds.maxY(), oldBounds.width(), -deltaBottom));
1389 if (newOutlineBox == oldOutlineBox)
1392 // We didn't move, but we did change size. Invalidate the delta, which will consist of possibly
1393 // two rectangles (but typically only one).
1394 RenderStyle* outlineStyle = outlineStyleForRepaint();
1395 LayoutUnit ow = outlineStyle->outlineSize();
1396 LayoutUnit width = absoluteValue(newOutlineBox.width() - oldOutlineBox.width());
1398 LayoutUnit shadowLeft;
1399 LayoutUnit shadowRight;
1400 style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1402 int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1403 LayoutUnit boxWidth = isBox() ? toRenderBox(this)->width() : ZERO_LAYOUT_UNIT;
1404 LayoutUnit borderWidth = max<LayoutUnit>(-outlineStyle->outlineOffset(), max<LayoutUnit>(borderRight, max<LayoutUnit>(valueForLength(style()->borderTopRightRadius().width(), boxWidth, v), valueForLength(style()->borderBottomRightRadius().width(), boxWidth, v)))) + max<LayoutUnit>(ow, shadowRight);
1405 LayoutRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
1407 width + borderWidth,
1408 max(newOutlineBox.height(), oldOutlineBox.height()));
1409 LayoutUnit right = min<LayoutUnit>(newBounds.maxX(), oldBounds.maxX());
1410 if (rightRect.x() < right) {
1411 rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1412 repaintUsingContainer(repaintContainer, rightRect);
1415 LayoutUnit height = absoluteValue(newOutlineBox.height() - oldOutlineBox.height());
1417 LayoutUnit shadowTop;
1418 LayoutUnit shadowBottom;
1419 style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1421 int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1422 LayoutUnit boxHeight = isBox() ? toRenderBox(this)->height() : ZERO_LAYOUT_UNIT;
1423 LayoutUnit borderHeight = max<LayoutUnit>(-outlineStyle->outlineOffset(), max<LayoutUnit>(borderBottom, max<LayoutUnit>(valueForLength(style()->borderBottomLeftRadius().height(), boxHeight, v), valueForLength(style()->borderBottomRightRadius().height(), boxHeight, v)))) + max<LayoutUnit>(ow, shadowBottom);
1424 LayoutRect bottomRect(newOutlineBox.x(),
1425 min(newOutlineBox.maxY(), oldOutlineBox.maxY()) - borderHeight,
1426 max(newOutlineBox.width(), oldOutlineBox.width()),
1427 height + borderHeight);
1428 LayoutUnit bottom = min(newBounds.maxY(), oldBounds.maxY());
1429 if (bottomRect.y() < bottom) {
1430 bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1431 repaintUsingContainer(repaintContainer, bottomRect);
1437 void RenderObject::repaintDuringLayoutIfMoved(const LayoutRect&)
1441 void RenderObject::repaintOverhangingFloats(bool)
1445 bool RenderObject::checkForRepaintDuringLayout() const
1447 // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=20885> It is probably safe to also require
1448 // m_everHadLayout. Currently, only RenderBlock::layoutBlock() adds this condition. See also
1449 // <https://bugs.webkit.org/show_bug.cgi?id=15129>.
1450 return !document()->view()->needsFullRepaint() && !hasLayer();
1453 LayoutRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, LayoutUnit outlineWidth) const
1455 LayoutRect r(clippedOverflowRectForRepaint(repaintContainer));
1456 r.inflate(outlineWidth);
1460 LayoutRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*) const
1462 ASSERT_NOT_REACHED();
1463 return LayoutRect();
1466 void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
1468 if (repaintContainer == this)
1471 if (RenderObject* o = parent()) {
1472 if (o->isBlockFlow()) {
1473 RenderBlock* cb = toRenderBlock(o);
1474 if (cb->hasColumns())
1475 cb->adjustRectForColumns(rect);
1478 if (o->hasOverflowClip()) {
1479 // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
1480 // layer's size instead. Even if the layer's size is wrong, the layer itself will repaint
1481 // anyway if its size does change.
1482 RenderBox* boxParent = toRenderBox(o);
1484 LayoutRect repaintRect(rect);
1485 repaintRect.move(-boxParent->scrolledContentOffset()); // For overflow:auto/scroll/hidden.
1487 LayoutRect boxRect(LayoutPoint(), boxParent->cachedSizeForOverflowClip());
1488 rect = intersection(repaintRect, boxRect);
1493 o->computeRectForRepaint(repaintContainer, rect, fixed);
1497 void RenderObject::computeFloatRectForRepaint(RenderBoxModelObject*, FloatRect&, bool) const
1499 ASSERT_NOT_REACHED();
1502 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1508 void RenderObject::showTreeForThis() const
1511 node()->showTreeForThis();
1514 void RenderObject::showRenderTreeForThis() const
1516 showRenderTree(this, 0);
1519 void RenderObject::showLineTreeForThis() const
1521 if (containingBlock())
1522 containingBlock()->showLineTreeAndMark(0, 0, 0, 0, this);
1525 void RenderObject::showRenderObject() const
1527 showRenderObject(0);
1530 void RenderObject::showRenderObject(int printedCharacters) const
1532 // As this function is intended to be used when debugging, the
1533 // this pointer may be 0.
1535 fputs("(null)\n", stderr);
1539 printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
1542 if (printedCharacters)
1543 for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
1545 fputc('\t', stderr);
1548 fputc('\n', stderr);
1551 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
1553 int printedCharacters = 0;
1554 if (markedObject1 == this && markedLabel1)
1555 printedCharacters += fprintf(stderr, "%s", markedLabel1);
1556 if (markedObject2 == this && markedLabel2)
1557 printedCharacters += fprintf(stderr, "%s", markedLabel2);
1558 for (; printedCharacters < depth * 2; printedCharacters++)
1561 showRenderObject(printedCharacters);
1565 for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
1566 child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
1571 Color RenderObject::selectionBackgroundColor() const
1574 if (style()->userSelect() != SELECT_NONE) {
1575 RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
1576 if (pseudoStyle && pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
1577 color = pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).blendWithWhite();
1579 color = frame()->selection()->isFocusedAndActive() ?
1580 theme()->activeSelectionBackgroundColor() :
1581 theme()->inactiveSelectionBackgroundColor();
1587 Color RenderObject::selectionColor(int colorProperty) const
1590 // If the element is unselectable, or we are only painting the selection,
1591 // don't override the foreground color with the selection foreground color.
1592 if (style()->userSelect() == SELECT_NONE
1593 || (frame()->view()->paintBehavior() & PaintBehaviorSelectionOnly))
1596 if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
1597 color = pseudoStyle->visitedDependentColor(colorProperty);
1598 if (!color.isValid())
1599 color = pseudoStyle->visitedDependentColor(CSSPropertyColor);
1601 color = frame()->selection()->isFocusedAndActive() ?
1602 theme()->activeSelectionForegroundColor() :
1603 theme()->inactiveSelectionForegroundColor();
1608 Color RenderObject::selectionForegroundColor() const
1610 return selectionColor(CSSPropertyWebkitTextFillColor);
1613 Color RenderObject::selectionEmphasisMarkColor() const
1615 return selectionColor(CSSPropertyWebkitTextEmphasisColor);
1618 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1620 view()->selectionStartEnd(spos, epos);
1623 void RenderObject::handleDynamicFloatPositionChange()
1625 // We have gone from not affecting the inline status of the parent flow to suddenly
1626 // having an impact. See if there is a mismatch between the parent flow's
1627 // childrenInline() state and our state.
1628 setInline(style()->isDisplayInlineType());
1629 if (isInline() != parent()->childrenInline()) {
1631 toRenderBoxModelObject(parent())->childBecameNonInline(this);
1633 // An anonymous block must be made to wrap this inline.
1634 RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1635 RenderObjectChildList* childlist = parent()->virtualChildren();
1636 childlist->insertChildNode(parent(), block, this);
1637 block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1642 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
1644 if (!isText() && style)
1645 setStyle(animation()->updateAnimations(this, style.get()));
1650 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1652 #if USE(ACCELERATED_COMPOSITING)
1653 // If transform changed, and we are not composited, need to do a layout.
1654 if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1655 // Text nodes share style with their parents but transforms don't apply to them,
1656 // hence the !isText() check.
1657 // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1658 if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) {
1659 // We need to set at least SimplifiedLayout, but if PositionedMovementOnly is already set
1660 // then we actually need SimplifiedLayoutAndPositionedMovement.
1662 diff = StyleDifferenceLayout; // FIXME: Do this for now since SimplifiedLayout cannot handle updating floating objects lists.
1663 else if (diff < StyleDifferenceLayoutPositionedMovementOnly)
1664 diff = StyleDifferenceSimplifiedLayout;
1665 else if (diff < StyleDifferenceSimplifiedLayout)
1666 diff = StyleDifferenceSimplifiedLayoutAndPositionedMovement;
1667 } else if (diff < StyleDifferenceRecompositeLayer)
1668 diff = StyleDifferenceRecompositeLayer;
1671 // If opacity changed, and we are not composited, need to repaint (also
1672 // ignoring text nodes)
1673 if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
1674 if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
1675 diff = StyleDifferenceRepaintLayer;
1676 else if (diff < StyleDifferenceRecompositeLayer)
1677 diff = StyleDifferenceRecompositeLayer;
1680 #if ENABLE(CSS_FILTERS)
1681 if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer()) {
1682 RenderLayer* layer = toRenderBoxModelObject(this)->layer();
1683 if (!layer->isComposited() || layer->paintsWithFilters())
1684 diff = StyleDifferenceRepaintLayer;
1685 else if (diff < StyleDifferenceRecompositeLayer)
1686 diff = StyleDifferenceRecompositeLayer;
1690 // The answer to requiresLayer() for plugins and iframes can change outside of the style system,
1691 // since it depends on whether we decide to composite these elements. When the layer status of
1692 // one of these elements changes, we need to force a layout.
1693 if (diff == StyleDifferenceEqual && style() && isBoxModelObject()) {
1694 if (hasLayer() != toRenderBoxModelObject(this)->requiresLayer())
1695 diff = StyleDifferenceLayout;
1698 UNUSED_PARAM(contextSensitiveProperties);
1701 // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1702 if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1703 diff = StyleDifferenceRepaint;
1708 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1710 if (m_style == style) {
1711 #if USE(ACCELERATED_COMPOSITING)
1712 // We need to run through adjustStyleDifference() for iframes and plugins, so
1713 // style sharing is disabled for them. That should ensure that we never hit this code path.
1714 ASSERT(!isRenderIFrame() && !isEmbeddedObject());
1719 StyleDifference diff = StyleDifferenceEqual;
1720 unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1722 diff = m_style->diff(style.get(), contextSensitiveProperties);
1724 diff = adjustStyleDifference(diff, contextSensitiveProperties);
1726 styleWillChange(diff, style.get());
1728 RefPtr<RenderStyle> oldStyle = m_style.release();
1731 updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1732 updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1734 updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1735 updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1737 // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1738 // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1739 if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
1740 toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
1742 bool doesNotNeedLayout = !m_parent || isText();
1744 styleDidChange(diff, oldStyle.get());
1746 // FIXME: |this| might be destroyed here. This can currently happen for a RenderTextFragment when
1747 // its first-letter block gets an update in RenderTextFragment::styleDidChange. For RenderTextFragment(s),
1748 // we will safely bail out with the doesNotNeedLayout flag. We might want to broaden this condition
1749 // in the future as we move renderer changes out of layout and into style changes.
1750 if (doesNotNeedLayout)
1753 // Now that the layer (if any) has been updated, we need to adjust the diff again,
1754 // check whether we should layout now, and decide if we need to repaint.
1755 StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1757 if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1758 if (updatedDiff == StyleDifferenceLayout)
1759 setNeedsLayoutAndPrefWidthsRecalc();
1760 else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1761 setNeedsPositionedMovementLayout();
1762 else if (updatedDiff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1763 setNeedsPositionedMovementLayout();
1764 setNeedsSimplifiedNormalFlowLayout();
1765 } else if (updatedDiff == StyleDifferenceSimplifiedLayout)
1766 setNeedsSimplifiedNormalFlowLayout();
1769 if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
1770 // Do a repaint with the new style now, e.g., for example if we go from
1771 // not having an outline to having an outline.
1776 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
1781 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1784 // If our z-index changes value or our visibility changes,
1785 // we need to dirty our stacking context's z-order list.
1787 bool visibilityChanged = m_style->visibility() != newStyle->visibility()
1788 || m_style->zIndex() != newStyle->zIndex()
1789 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1790 #if ENABLE(DASHBOARD_SUPPORT)
1791 if (visibilityChanged)
1792 document()->setDashboardRegionsDirty(true);
1794 if (visibilityChanged && AXObjectCache::accessibilityEnabled())
1795 document()->axObjectCache()->childrenChanged(this);
1797 // Keep layer hierarchy visibility bits up to date if visibility changes.
1798 if (m_style->visibility() != newStyle->visibility()) {
1799 if (RenderLayer* l = enclosingLayer()) {
1800 if (newStyle->visibility() == VISIBLE)
1801 l->setHasVisibleContent();
1802 else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1803 l->dirtyVisibleContentStatus();
1804 if (diff > StyleDifferenceRepaintLayer)
1811 if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
1813 if (isFloating() && (m_style->floating() != newStyle->floating()))
1814 // For changes in float styles, we need to conceivably remove ourselves
1815 // from the floating objects list.
1816 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1817 else if (isOutOfFlowPositioned() && (m_style->position() != newStyle->position()))
1818 // For changes in positioning styles, we need to conceivably remove ourselves
1819 // from the positioned objects list.
1820 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1822 s_affectsParentBlock = isFloatingOrOutOfFlowPositioned()
1823 && (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)
1824 && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
1826 // reset style flags
1827 if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
1829 setPositioned(false);
1830 setRelPositioned(false);
1832 setHorizontalWritingMode(true);
1833 setPaintBackground(false);
1834 setHasOverflowClip(false);
1835 setHasTransform(false);
1836 setHasReflection(false);
1838 s_affectsParentBlock = false;
1840 if (view()->frameView()) {
1841 bool shouldBlitOnFixedBackgroundImage = false;
1842 #if ENABLE(FAST_MOBILE_SCROLLING)
1843 // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
1844 // when scrolling a page with a fixed background image. As an optimization, assuming there are
1845 // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
1846 // ignore the CSS property "background-attachment: fixed".
1847 #if (PLATFORM(QT) || OS(TIZEN))
1848 if (view()->frameView()->delegatesScrolling())
1850 shouldBlitOnFixedBackgroundImage = true;
1853 bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage();
1854 bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage();
1855 if (oldStyleSlowScroll != newStyleSlowScroll) {
1856 if (oldStyleSlowScroll)
1857 view()->frameView()->removeSlowRepaintObject();
1858 if (newStyleSlowScroll)
1859 view()->frameView()->addSlowRepaintObject();
1864 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderStyle* b)
1866 ASSERT(a->cursors() != b->cursors());
1867 return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
1870 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
1872 return a->cursor() == b->cursor() && (a->cursors() == b->cursors() || areNonIdenticalCursorListsEqual(a, b));
1875 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
1877 if (s_affectsParentBlock)
1878 handleDynamicFloatPositionChange();
1883 if (diff == StyleDifferenceLayout || diff == StyleDifferenceSimplifiedLayout) {
1884 RenderCounter::rendererStyleChanged(this, oldStyle, m_style.get());
1886 // If the object already needs layout, then setNeedsLayout won't do
1887 // any work. But if the containing block has changed, then we may need
1888 // to mark the new containing blocks for layout. The change that can
1889 // directly affect the containing block of this object is a change to
1890 // the position style.
1891 if (needsLayout() && oldStyle->position() != m_style->position())
1892 markContainingBlocksForLayout();
1894 if (diff == StyleDifferenceLayout)
1895 setNeedsLayoutAndPrefWidthsRecalc();
1897 setNeedsSimplifiedNormalFlowLayout();
1898 } else if (diff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1899 setNeedsPositionedMovementLayout();
1900 setNeedsSimplifiedNormalFlowLayout();
1901 } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
1902 setNeedsPositionedMovementLayout();
1904 // Don't check for repaint here; we need to wait until the layer has been
1905 // updated by subclasses before we know if we have to repaint (in setStyle()).
1907 if (oldStyle && !areCursorsEqual(oldStyle, style())) {
1908 if (Frame* frame = this->frame())
1909 frame->eventHandler()->dispatchFakeMouseMoveEventSoon();
1913 void RenderObject::propagateStyleToAnonymousChildren(bool blockChildrenOnly)
1915 // FIXME: We could save this call when the change only affected non-inherited properties.
1916 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
1917 if (!child->isAnonymous() || child->style()->styleType() != NOPSEUDO)
1920 if (blockChildrenOnly && !child->isRenderBlock())
1923 #if ENABLE(FULLSCREEN_API)
1924 if (child->isRenderFullScreen() || child->isRenderFullScreenPlaceholder())
1928 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), child->style()->display());
1929 if (style()->specifiesColumns()) {
1930 if (child->style()->specifiesColumns())
1931 newStyle->inheritColumnPropertiesFrom(style());
1932 if (child->style()->columnSpan())
1933 newStyle->setColumnSpan(ColumnSpanAll);
1936 // Preserve the position style of anonymous block continuations as they can have relative position when
1937 // they contain block descendants of relative positioned inlines.
1938 if (child->isRelPositioned() && toRenderBlock(child)->isAnonymousBlockContinuation())
1939 newStyle->setPosition(child->style()->position());
1941 child->setStyle(newStyle.release());
1945 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
1947 // Optimize the common case
1948 if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
1951 // Go through the new layers and addClients first, to avoid removing all clients of an image.
1952 for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
1953 if (currNew->image())
1954 currNew->image()->addClient(this);
1957 for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
1958 if (currOld->image())
1959 currOld->image()->removeClient(this);
1963 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
1965 if (oldImage != newImage) {
1967 oldImage->removeClient(this);
1969 newImage->addClient(this);
1973 LayoutRect RenderObject::viewRect() const
1975 return view()->viewRect();
1978 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, bool fixed, bool useTransforms) const
1980 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
1981 mapLocalToContainer(0, fixed, useTransforms, transformState);
1982 transformState.flatten();
1984 return transformState.lastPlanarPoint();
1987 FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, bool fixed, bool useTransforms) const
1989 TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
1990 mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
1991 transformState.flatten();
1993 return transformState.lastPlanarPoint();
1996 void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState, ApplyContainerFlipOrNot applyContainerFlip, bool* wasFixed) const
1998 if (repaintContainer == this)
2001 RenderObject* o = parent();
2005 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2006 LayoutPoint centerPoint = roundedLayoutPoint(transformState.mappedPoint());
2007 if (applyContainerFlip && o->isBox()) {
2008 if (o->style()->isFlippedBlocksWritingMode())
2009 transformState.move(toRenderBox(o)->flipForWritingModeIncludingColumns(roundedLayoutPoint(transformState.mappedPoint())) - centerPoint);
2010 applyContainerFlip = DoNotApplyContainerFlip;
2013 LayoutSize columnOffset;
2014 o->adjustForColumns(columnOffset, roundedLayoutPoint(transformState.mappedPoint()));
2015 if (!columnOffset.isZero())
2016 transformState.move(columnOffset);
2018 if (o->hasOverflowClip())
2019 transformState.move(-toRenderBox(o)->scrolledContentOffset());
2021 o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState, applyContainerFlip, wasFixed);
2024 const RenderObject* RenderObject::pushMappingToContainer(const RenderBoxModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
2026 ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this);
2028 RenderObject* container = parent();
2032 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2034 if (container->hasOverflowClip())
2035 offset = -toRenderBox(container)->scrolledContentOffset();
2037 geometryMap.push(this, offset, hasColumns());
2042 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
2044 RenderObject* o = parent();
2046 o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2047 if (o->hasOverflowClip())
2048 transformState.move(toRenderBox(o)->scrolledContentOffset());
2052 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
2054 #if ENABLE(3D_RENDERING)
2055 // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
2056 // so check the layer's transform directly.
2057 return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
2059 UNUSED_PARAM(containerObject);
2060 return hasTransform();
2064 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const
2066 transform.makeIdentity();
2067 transform.translate(offsetInContainer.width(), offsetInContainer.height());
2069 if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform())
2070 transform.multiply(layer->currentTransform());
2072 #if ENABLE(3D_RENDERING)
2073 if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
2074 // Perpsective on the container affects us, so we have to factor it in here.
2075 ASSERT(containerObject->hasLayer());
2076 FloatPoint perspectiveOrigin = toRenderBoxModelObject(containerObject)->layer()->perspectiveOrigin();
2078 TransformationMatrix perspectiveMatrix;
2079 perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
2081 transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
2082 transform = perspectiveMatrix * transform;
2083 transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
2086 UNUSED_PARAM(containerObject);
2090 #if ENABLE(TIZEN_NOT_USE_TRANSFORM_INFO_WHEN_GETTING_CARET_RECT)
2091 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed, bool useTransforms) const
2093 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2096 // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(),
2097 // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks.
2098 TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad);
2100 #if ENABLE(TIZEN_NOT_USE_TRANSFORM_INFO_WHEN_GETTING_CARET_RECT)
2101 mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState, ApplyContainerFlip, wasFixed);
2103 mapLocalToContainer(repaintContainer, fixed, true, transformState, ApplyContainerFlip, wasFixed);
2106 transformState.flatten();
2108 return transformState.lastPlanarQuad();
2111 FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, RenderBoxModelObject* repaintContainer, bool fixed, bool* wasFixed) const
2113 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2114 mapLocalToContainer(repaintContainer, fixed, true, transformState, ApplyContainerFlip, wasFixed);
2115 transformState.flatten();
2117 return transformState.lastPlanarPoint();
2120 LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
2122 ASSERT(o == container());
2126 o->adjustForColumns(offset, point);
2128 if (o->hasOverflowClip())
2129 offset -= toRenderBox(o)->scrolledContentOffset();
2131 if (offsetDependsOnPoint)
2132 *offsetDependsOnPoint = hasColumns();
2137 LayoutSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
2140 LayoutPoint referencePoint;
2141 const RenderObject* currContainer = this;
2143 RenderObject* nextContainer = currContainer->container();
2144 ASSERT(nextContainer); // This means we reached the top without finding container.
2147 ASSERT(!currContainer->hasTransform());
2148 LayoutSize currentOffset = currContainer->offsetFromContainer(nextContainer, referencePoint);
2149 offset += currentOffset;
2150 referencePoint.move(currentOffset);
2151 currContainer = nextContainer;
2152 } while (currContainer != container);
2157 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
2159 if (extraWidthToEndOfLine)
2160 *extraWidthToEndOfLine = 0;
2162 return LayoutRect();
2165 bool RenderObject::isRooted(RenderView** view)
2167 RenderObject* o = this;
2171 if (!o->isRenderView())
2175 *view = toRenderView(o);
2180 RenderObject* RenderObject::rendererForRootBackground()
2183 if (!hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) {
2184 // Locate the <body> element using the DOM. This is easier than trying
2185 // to crawl around a render tree with potential :before/:after content and
2186 // anonymous blocks created by inline <body> tags etc. We can locate the <body>
2187 // render object very easily via the DOM.
2188 HTMLElement* body = document()->body();
2189 RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
2197 RespectImageOrientationEnum RenderObject::shouldRespectImageOrientation() const
2199 // Respect the image's orientation if it's being used as a full-page image or it's
2200 // an <img> and the setting to respect it everywhere is set.
2201 return document()->isImageDocument() || (document()->settings() && document()->settings()->shouldRespectImageOrientation() && node() && (node()->hasTagName(HTMLNames::imgTag) || node()->hasTagName(HTMLNames::webkitInnerImageTag))) ? RespectImageOrientation : DoNotRespectImageOrientation;
2204 bool RenderObject::hasOutlineAnnotation() const
2206 return node() && node()->isLink() && document()->printing();
2209 RenderObject* RenderObject::container(const RenderBoxModelObject* repaintContainer, bool* repaintContainerSkipped) const
2211 if (repaintContainerSkipped)
2212 *repaintContainerSkipped = false;
2214 // This method is extremely similar to containingBlock(), but with a few notable
2216 // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2217 // the object is not part of the primary document subtree yet.
2218 // (2) For normal flow elements, it just returns the parent.
2219 // (3) For absolute positioned elements, it will return a relative positioned inline.
2220 // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2221 // the layout of the positioned object. This does mean that computePositionedLogicalWidth and
2222 // computePositionedLogicalHeight have to use container().
2223 RenderObject* o = parent();
2228 EPosition pos = m_style->position();
2229 if (pos == FixedPosition) {
2230 // container() can be called on an object that is not in the
2231 // tree yet. We don't call view() since it will assert if it
2232 // can't get back to the canvas. Instead we just walk as high up
2233 // as we can. If we're in the tree, we'll get the root. If we
2234 // aren't we'll get the root of our little subtree (most likely
2235 // we'll just return 0).
2236 // FIXME: The definition of view() has changed to not crawl up the render tree. It might
2237 // be safe now to use it.
2238 while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) {
2240 // foreignObject is the containing block for its contents.
2241 if (o->isSVGForeignObject())
2244 // The render flow thread is the top most containing block
2245 // for the fixed positioned elements.
2246 if (o->isRenderFlowThread())
2249 if (repaintContainerSkipped && o == repaintContainer)
2250 *repaintContainerSkipped = true;
2254 } else if (pos == AbsolutePosition) {
2255 // Same goes here. We technically just want our containing block, but
2256 // we may not have one if we're part of an uninstalled subtree. We'll
2257 // climb as high as we can though.
2258 while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
2260 if (o->isSVGForeignObject()) // foreignObject is the containing block for contents inside it
2263 if (repaintContainerSkipped && o == repaintContainer)
2264 *repaintContainerSkipped = true;
2273 bool RenderObject::isSelectionBorder() const
2275 SelectionState st = selectionState();
2276 return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2279 inline void RenderObject::clearLayoutRootIfNeeded() const
2281 if (!documentBeingDestroyed() && frame()) {
2282 if (FrameView* view = frame()->view()) {
2283 if (view->layoutRoot() == this) {
2284 ASSERT_NOT_REACHED();
2285 // This indicates a failure to layout the child, which is why
2286 // the layout root is still set to |this|. Make sure to clear it
2287 // since we are getting destroyed.
2288 view->clearLayoutRoot();
2294 void RenderObject::willBeDestroyed()
2296 // Destroy any leftover anonymous children.
2297 RenderObjectChildList* children = virtualChildren();
2299 children->destroyLeftoverChildren();
2301 // If this renderer is being autoscrolled, stop the autoscroll timer
2303 // FIXME: RenderObject::destroy should not get called with a renderer whose document
2304 // has a null frame, so we assert this. However, we don't want release builds to crash which is why we
2305 // check that the frame is not null.
2307 if (frame() && frame()->eventHandler()->autoscrollRenderer() == this)
2308 frame()->eventHandler()->stopAutoscrollTimer(true);
2311 if (frame() && frame()->page())
2312 frame()->page()->chrome()->client()->rendererWillBeDestroyed(this);
2315 if (AXObjectCache::accessibilityEnabled()) {
2316 document()->axObjectCache()->childrenChanged(this->parent());
2317 document()->axObjectCache()->remove(this);
2319 animation()->cancelAnimations(this);
2324 if (!documentBeingDestroyed() && view() && view()->hasRenderNamedFlowThreads()) {
2325 // After remove, the object and the associated information should not be in any flow thread.
2326 const RenderNamedFlowThreadList* flowThreadList = view()->flowThreadController()->renderNamedFlowThreadList();
2327 for (RenderNamedFlowThreadList::const_iterator iter = flowThreadList->begin(); iter != flowThreadList->end(); ++iter) {
2328 const RenderNamedFlowThread* renderFlowThread = *iter;
2329 ASSERT(!renderFlowThread->hasChild(this));
2330 ASSERT(!renderFlowThread->hasChildInfo(this));
2335 // If this renderer had a parent, remove should have destroyed any counters
2336 // attached to this renderer and marked the affected other counters for
2337 // reevaluation. This apparently redundant check is here for the case when
2338 // this renderer had no parent at the time remove() was called.
2340 if (hasCounterNodeMap())
2341 RenderCounter::destroyCounterNodes(this);
2343 // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
2344 // be moved into RenderBoxModelObject::destroy.
2347 toRenderBoxModelObject(this)->destroyLayer();
2350 setAncestorLineBoxDirty(false);
2352 clearLayoutRootIfNeeded();
2355 void RenderObject::destroyAndCleanupAnonymousWrappers()
2357 RenderObject* parent = this->parent();
2359 // If the tree is destroyed or our parent is not anonymous, there is no need for a clean-up phase.
2360 if (documentBeingDestroyed() || !parent || !parent->isAnonymous()) {
2365 bool parentIsLeftOverAnonymousWrapper = false;
2367 // Currently we only remove anonymous cells' wrapper but we should remove all unneeded
2368 // wrappers. See http://webkit.org/b/52123 as an example where this is needed.
2369 if (parent->isTableCell())
2370 parentIsLeftOverAnonymousWrapper = parent->firstChild() == this && parent->lastChild() == this;
2374 // WARNING: |this| is deleted here.
2376 if (parentIsLeftOverAnonymousWrapper) {
2377 ASSERT(!parent->firstChild());
2378 parent->destroyAndCleanupAnonymousWrappers();
2382 void RenderObject::destroy()
2385 arenaDelete(renderArena(), this);
2388 void RenderObject::arenaDelete(RenderArena* arena, void* base)
2391 for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2392 if (StyleImage* backgroundImage = bgLayer->image())
2393 backgroundImage->removeClient(this);
2396 for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
2397 if (StyleImage* maskImage = maskLayer->image())
2398 maskImage->removeClient(this);
2401 if (StyleImage* borderImage = m_style->borderImage().image())
2402 borderImage->removeClient(this);
2404 if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
2405 maskBoxImage->removeClient(this);
2409 void* savedBase = baseOfRenderObjectBeingDeleted;
2410 baseOfRenderObjectBeingDeleted = base;
2414 baseOfRenderObjectBeingDeleted = savedBase;
2417 // Recover the size left there for us by operator delete and free the memory.
2418 arena->free(*(size_t*)base, base);
2421 VisiblePosition RenderObject::positionForPoint(const LayoutPoint&)
2423 return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
2426 void RenderObject::updateDragState(bool dragOn)
2428 bool valueChanged = (dragOn != isDragging());
2429 setIsDragging(dragOn);
2430 if (valueChanged && style()->affectedByDragRules() && node())
2431 node()->setNeedsStyleRecalc();
2432 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2433 curr->updateDragState(dragOn);
2436 bool RenderObject::isComposited() const
2438 return hasLayer() && toRenderBoxModelObject(this)->layer()->isComposited();
2441 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter)
2443 bool inside = false;
2444 if (hitTestFilter != HitTestSelf) {
2445 // First test the foreground layer (lines and inlines).
2446 inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestForeground);
2448 // Test floats next.
2450 inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestFloat);
2452 // Finally test to see if the mouse is in the background (within a child block's background).
2454 inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestChildBlockBackgrounds);
2457 // See if the mouse is inside us but not any of our descendants
2458 if (hitTestFilter != HitTestDescendants && !inside)
2459 inside = nodeAtPoint(request, result, pointInContainer, accumulatedOffset, HitTestBlockBackground);
2464 void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
2466 if (result.innerNode())
2471 result.setInnerNode(n);
2472 if (!result.innerNonSharedNode())
2473 result.setInnerNonSharedNode(n);
2474 result.setLocalPoint(point);
2478 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& /*pointInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction)
2483 void RenderObject::scheduleRelayout()
2485 if (isRenderView()) {
2486 FrameView* view = toRenderView(this)->frameView();
2488 view->scheduleRelayout();
2491 if (RenderView* renderView = view()) {
2492 if (FrameView* frameView = renderView->frameView())
2493 frameView->scheduleRelayoutOfSubtree(this);
2499 void RenderObject::layout()
2501 ASSERT(needsLayout());
2502 RenderObject* child = firstChild();
2504 child->layoutIfNeeded();
2505 ASSERT(!child->needsLayout());
2506 child = child->nextSibling();
2508 setNeedsLayout(false);
2511 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
2513 if (!document()->usesFirstLineRules())
2518 RefPtr<RenderStyle> result;
2520 if (isBlockFlow()) {
2521 if (RenderBlock* firstLineBlock = this->firstLineBlock())
2522 result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0);
2523 } else if (!isAnonymous() && isRenderInline()) {
2524 RenderStyle* parentStyle = parent()->firstLineStyle();
2525 if (parentStyle != parent()->style())
2526 result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
2529 return result.release();
2532 RenderStyle* RenderObject::firstLineStyleSlowCase() const
2534 ASSERT(document()->usesFirstLineRules());
2536 RenderStyle* style = m_style.get();
2537 const RenderObject* renderer = isText() ? parent() : this;
2538 if (renderer->isBlockFlow()) {
2539 if (RenderBlock* firstLineBlock = renderer->firstLineBlock())
2540 style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2541 } else if (!renderer->isAnonymous() && renderer->isRenderInline()) {
2542 RenderStyle* parentStyle = renderer->parent()->firstLineStyle();
2543 if (parentStyle != renderer->parent()->style()) {
2544 // A first-line style is in effect. Cache a first-line style for ourselves.
2545 renderer->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
2546 style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2553 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2555 if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2558 RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2562 RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
2564 return style()->addCachedPseudoStyle(result.release());
2568 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2570 if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
2575 parentStyle = style();
2578 // FIXME: This "find nearest element parent" should be a helper function.
2580 while (n && !n->isElementNode())
2581 n = n->parentNode();
2584 Element* element = toElement(n);
2586 if (pseudo == FIRST_LINE_INHERITED) {
2587 RefPtr<RenderStyle> result = document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
2588 result->setStyleType(FIRST_LINE_INHERITED);
2589 return result.release();
2591 return document()->styleResolver()->pseudoStyleForElement(pseudo, element, parentStyle);
2594 static Color decorationColor(RenderStyle* style)
2597 if (style->textStrokeWidth() > 0) {
2598 // Prefer stroke color if possible but not if it's fully transparent.
2599 result = style->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
2604 result = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
2608 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2609 Color& linethrough, bool quirksMode, bool firstlineStyle)
2611 RenderObject* curr = this;
2612 RenderStyle* styleToUse = 0;
2614 styleToUse = curr->style(firstlineStyle);
2615 int currDecs = styleToUse->textDecoration();
2617 if (currDecs & UNDERLINE) {
2618 decorations &= ~UNDERLINE;
2619 underline = decorationColor(styleToUse);
2621 if (currDecs & OVERLINE) {
2622 decorations &= ~OVERLINE;
2623 overline = decorationColor(styleToUse);
2625 if (currDecs & LINE_THROUGH) {
2626 decorations &= ~LINE_THROUGH;
2627 linethrough = decorationColor(styleToUse);
2630 if (curr->isRubyText())
2632 curr = curr->parent();
2633 if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
2634 curr = toRenderBlock(curr)->continuation();
2635 } while (curr && decorations && (!quirksMode || !curr->node() ||
2636 (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2638 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2639 if (decorations && curr) {
2640 styleToUse = curr->style(firstlineStyle);
2641 if (decorations & UNDERLINE)
2642 underline = decorationColor(styleToUse);
2643 if (decorations & OVERLINE)
2644 overline = decorationColor(styleToUse);
2645 if (decorations & LINE_THROUGH)
2646 linethrough = decorationColor(styleToUse);
2650 #if ENABLE(DASHBOARD_SUPPORT)
2651 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2653 // Convert the style regions to absolute coordinates.
2654 if (style()->visibility() != VISIBLE || !isBox())
2657 RenderBox* box = toRenderBox(this);
2659 const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2660 unsigned i, count = styleRegions.size();
2661 for (i = 0; i < count; i++) {
2662 StyleDashboardRegion styleRegion = styleRegions[i];
2664 LayoutUnit w = box->width();
2665 LayoutUnit h = box->height();
2667 DashboardRegionValue region;
2668 region.label = styleRegion.label;
2669 region.bounds = LayoutRect(styleRegion.offset.left().value(),
2670 styleRegion.offset.top().value(),
2671 w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
2672 h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
2673 region.type = styleRegion.type;
2675 region.clip = region.bounds;
2676 computeAbsoluteRepaintRect(region.clip);
2677 if (region.clip.height() < 0) {
2678 region.clip.setHeight(0);
2679 region.clip.setWidth(0);
2682 FloatPoint absPos = localToAbsolute();
2683 region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
2684 region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
2686 regions.append(region);
2690 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2692 // RenderTexts don't have their own style, they just use their parent's style,
2693 // so we don't want to include them.
2697 addDashboardRegions(regions);
2698 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2699 curr->collectDashboardRegions(regions);
2703 bool RenderObject::willRenderImage(CachedImage*)
2705 // Without visibility we won't render (and therefore don't care about animation).
2706 if (style()->visibility() != VISIBLE)
2709 // We will not render a new image when Active DOM is suspended
2710 if (document()->activeDOMObjectsAreSuspended())
2713 // If we're not in a window (i.e., we're dormant from being put in the b/f cache or in a background tab)
2714 // then we don't want to render either.
2715 return !document()->inPageCache() && !document()->view()->isOffscreen();
2718 int RenderObject::maximalOutlineSize(PaintPhase p) const
2720 if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2722 return toRenderView(document()->renderer())->maximalOutlineSize();
2725 int RenderObject::caretMinOffset() const
2730 int RenderObject::caretMaxOffset() const
2733 return node() ? max(1U, node()->childNodeCount()) : 1;
2739 int RenderObject::previousOffset(int current) const
2744 int RenderObject::previousOffsetForBackwardDeletion(int current) const
2749 int RenderObject::nextOffset(int current) const
2754 void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const
2756 int outlineSize = outlineStyleForRepaint()->outlineSize();
2757 if (const ShadowData* boxShadow = style()->boxShadow()) {
2758 boxShadow->adjustRectForShadow(rect, outlineSize);
2762 rect.inflate(outlineSize);
2765 AnimationController* RenderObject::animation() const
2767 return frame()->animation();
2770 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
2772 imageChanged(static_cast<WrappedImagePtr>(image), rect);
2775 RenderBoxModelObject* RenderObject::offsetParent() const
2777 // If any of the following holds true return null and stop this algorithm:
2778 // A is the root element.
2779 // A is the HTML body element.
2780 // The computed value of the position property for element A is fixed.
2781 if (isRoot() || isBody() || (isOutOfFlowPositioned() && style()->position() == FixedPosition))
2784 // If A is an area HTML element which has a map HTML element somewhere in the ancestor
2785 // chain return the nearest ancestor map HTML element and stop this algorithm.
2786 // FIXME: Implement!
2788 // Return the nearest ancestor element of A for which at least one of the following is
2789 // true and stop this algorithm if such an ancestor is found:
2790 // * The computed value of the position property is not static.
2791 // * It is the HTML body element.
2792 // * The computed value of the position property of A is static and the ancestor
2793 // is one of the following HTML elements: td, th, or table.
2794 // * Our own extension: if there is a difference in the effective zoom
2796 bool skipTables = isOutOfFlowPositioned() || isRelPositioned();
2797 float currZoom = style()->effectiveZoom();
2798 RenderObject* curr = parent();
2799 while (curr && (!curr->node() || (!curr->isOutOfFlowPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
2800 Node* element = curr->node();
2801 if (!skipTables && element && (element->hasTagName(tableTag) || element->hasTagName(tdTag) || element->hasTagName(thTag)))
2804 float newZoom = curr->style()->effectiveZoom();
2805 if (currZoom != newZoom)
2808 curr = curr->parent();
2810 return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
2813 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
2815 // If this is a non-anonymous renderer in an editable area, then it's simple.
2816 if (Node* node = this->node()) {
2817 if (!node->rendererIsEditable()) {
2818 // If it can be found, we prefer a visually equivalent position that is editable.
2819 Position position = createLegacyEditingPosition(node, offset);
2820 Position candidate = position.downstream(CanCrossEditingBoundary);
2821 if (candidate.deprecatedNode()->rendererIsEditable())
2822 return VisiblePosition(candidate, affinity);
2823 candidate = position.upstream(CanCrossEditingBoundary);
2824 if (candidate.deprecatedNode()->rendererIsEditable())
2825 return VisiblePosition(candidate, affinity);
2827 // FIXME: Eliminate legacy editing positions
2828 return VisiblePosition(createLegacyEditingPosition(node, offset), affinity);
2831 // We don't want to cross the boundary between editable and non-editable
2832 // regions of the document, but that is either impossible or at least
2833 // extremely unlikely in any normal case because we stop as soon as we
2834 // find a single non-anonymous renderer.
2836 // Find a nearby non-anonymous renderer.
2837 RenderObject* child = this;
2838 while (RenderObject* parent = child->parent()) {
2839 // Find non-anonymous content after.
2840 RenderObject* renderer = child;
2841 while ((renderer = renderer->nextInPreOrder(parent))) {
2842 if (Node* node = renderer->node())
2843 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2846 // Find non-anonymous content before.
2848 while ((renderer = renderer->previousInPreOrder())) {
2849 if (renderer == parent)
2851 if (Node* node = renderer->node())
2852 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
2855 // Use the parent itself unless it too is anonymous.
2856 if (Node* node = parent->node())
2857 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2859 // Repeat at the next level up.
2863 // Everything was anonymous. Give up.
2864 return VisiblePosition();
2867 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
2869 if (position.isNotNull())
2870 return VisiblePosition(position);
2873 return createVisiblePosition(0, DOWNSTREAM);
2876 CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
2878 return SetCursorBasedOnStyle;
2881 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
2886 RenderBlock* containingBlock = this->containingBlock();
2887 return containingBlock ? !containingBlock->needsLayout() : true;
2890 // We only create "generated" child renderers like one for first-letter if:
2891 // - the firstLetterBlock can have children in the DOM and
2892 // - the block doesn't have any special assumption on its text children.
2893 // This correctly prevents form controls from having such renderers.
2894 bool RenderObject::canHaveGeneratedChildren() const
2896 return canHaveChildren();
2901 RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
2903 ASSERT_NOT_REACHED();
2907 void RenderObject::setNeedsBoundariesUpdate()
2909 if (RenderObject* renderer = parent())
2910 renderer->setNeedsBoundariesUpdate();
2913 FloatRect RenderObject::objectBoundingBox() const
2915 ASSERT_NOT_REACHED();
2919 FloatRect RenderObject::strokeBoundingBox() const
2921 ASSERT_NOT_REACHED();
2925 // Returns the smallest rectangle enclosing all of the painted content
2926 // respecting clipping, masking, filters, opacity, stroke-width and markers
2927 FloatRect RenderObject::repaintRectInLocalCoordinates() const
2929 ASSERT_NOT_REACHED();
2933 AffineTransform RenderObject::localTransform() const
2935 static const AffineTransform identity;
2939 const AffineTransform& RenderObject::localToParentTransform() const
2941 static const AffineTransform identity;
2945 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
2947 ASSERT_NOT_REACHED();
2951 #endif // ENABLE(SVG)
2953 } // namespace WebCore
2957 void showTree(const WebCore::RenderObject* object)
2960 object->showTreeForThis();
2963 void showLineTree(const WebCore::RenderObject* object)
2966 object->showLineTreeForThis();
2969 void showRenderTree(const WebCore::RenderObject* object1)
2971 showRenderTree(object1, 0);
2974 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
2977 const WebCore::RenderObject* root = object1;
2978 while (root->parent())
2979 root = root->parent();
2980 root->showRenderTreeAndMark(object1, "*", object2, "-", 0);