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 // RenderImageResourceStyleImage requires a style being present on the image but we don't want to
136 // trigger a style change now as the node is not fully attached. Moving this code to style change
137 // doesn't make sense as it should be run once at renderer creation.
138 image->m_style = style;
139 if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image()) {
140 image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
141 image->setIsGeneratedContent();
143 image->setImageResource(RenderImageResource::create());
148 if (node->hasTagName(rubyTag)) {
149 if (style->display() == INLINE)
150 return new (arena) RenderRubyAsInline(node);
151 else if (style->display() == BLOCK)
152 return new (arena) RenderRubyAsBlock(node);
154 // treat <rt> as ruby text ONLY if it still has its default treatment of block
155 if (node->hasTagName(rtTag) && style->display() == BLOCK)
156 return new (arena) RenderRubyText(node);
157 if (doc->cssRegionsEnabled() && style->isDisplayRegionType() && !style->regionThread().isEmpty() && doc->renderView())
158 return new (arena) RenderRegion(node, 0);
159 switch (style->display()) {
163 return new (arena) RenderInline(node);
168 if ((!style->hasAutoColumnCount() || !style->hasAutoColumnWidth()) && doc->regionBasedColumnsEnabled())
169 return new (arena) RenderMultiColumnBlock(node);
170 return new (arena) RenderBlock(node);
172 return new (arena) RenderListItem(node);
175 return new (arena) RenderTable(node);
176 case TABLE_ROW_GROUP:
177 case TABLE_HEADER_GROUP:
178 case TABLE_FOOTER_GROUP:
179 return new (arena) RenderTableSection(node);
181 return new (arena) RenderTableRow(node);
182 case TABLE_COLUMN_GROUP:
184 return new (arena) RenderTableCol(node);
186 return new (arena) RenderTableCell(node);
188 return new (arena) RenderTableCaption(node);
191 return new (arena) RenderDeprecatedFlexibleBox(node);
194 return new (arena) RenderFlexibleBox(node);
197 return new (arena) RenderGrid(node);
203 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject"));
205 RenderObject::RenderObject(Node* node)
206 : CachedImageClient()
213 , m_hasAXObject(false)
214 , m_setNeedsLayoutForbidden(false)
219 renderObjectCounter.increment();
224 RenderObject::~RenderObject()
227 ASSERT(!m_hasAXObject);
228 renderObjectCounter.decrement();
232 RenderTheme* RenderObject::theme() const
234 ASSERT(document()->page());
236 return document()->page()->theme();
239 bool RenderObject::isDescendantOf(const RenderObject* obj) const
241 for (const RenderObject* r = this; r; r = r->m_parent) {
248 bool RenderObject::isBody() const
250 return node() && node()->hasTagName(bodyTag);
253 bool RenderObject::isHR() const
255 return node() && node()->hasTagName(hrTag);
258 bool RenderObject::isLegend() const
260 return node() && node()->hasTagName(legendTag);
263 bool RenderObject::isHTMLMarquee() const
265 return node() && node()->renderer() == this && node()->hasTagName(marqueeTag);
268 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
270 RenderObjectChildList* children = virtualChildren();
275 bool needsTable = false;
277 if (newChild->isRenderTableCol()) {
278 RenderTableCol* newTableColumn = toRenderTableCol(newChild);
279 bool isColumnInColumnGroup = newTableColumn->isTableColumn() && isRenderTableCol();
280 needsTable = !isTable() && !isColumnInColumnGroup;
281 } else if (newChild->isTableCaption())
282 needsTable = !isTable();
283 else if (newChild->isTableSection())
284 needsTable = !isTable();
285 else if (newChild->isTableRow())
286 needsTable = !isTableSection();
287 else if (newChild->isTableCell())
288 needsTable = !isTableRow();
292 RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
293 if (afterChild && afterChild->isAnonymous() && afterChild->isTable() && !afterChild->isBeforeContent())
294 table = toRenderTable(afterChild);
296 table = RenderTable::createAnonymousWithParentRenderer(this);
297 addChild(table, beforeChild);
299 table->addChild(newChild);
301 children->insertChildNode(this, newChild, beforeChild);
303 if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE)
304 toRenderText(newChild)->transformText();
306 // SVG creates renderers for <g display="none">, as SVG requires children of hidden
307 // <g>s to have renderers - at least that's how our implementation works. Consider:
308 // <g display="none"><foreignObject><body style="position: relative">FOO...
309 // - requiresLayer() would return true for the <body>, creating a new RenderLayer
310 // - when the document is painted, both layers are painted. The <body> layer doesn't
311 // know that it's inside a "hidden SVG subtree", and thus paints, even if it shouldn't.
312 // To avoid the problem alltogether, detect early if we're inside a hidden SVG subtree
313 // and stop creating layers at all for these cases - they're not used anyways.
314 if (newChild->hasLayer() && !layerCreationAllowedForSubtree())
315 toRenderLayerModelObject(newChild)->layer()->removeOnlyThisLayer();
318 void RenderObject::removeChild(RenderObject* oldChild)
320 RenderObjectChildList* children = virtualChildren();
325 children->removeChildNode(this, oldChild);
328 RenderObject* RenderObject::nextInPreOrder() const
330 if (RenderObject* o = firstChild())
333 return nextInPreOrderAfterChildren();
336 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
339 if (!(o = nextSibling())) {
341 while (o && !o->nextSibling())
344 o = o->nextSibling();
350 RenderObject* RenderObject::nextInPreOrder(const RenderObject* stayWithin) const
352 if (RenderObject* o = firstChild())
355 return nextInPreOrderAfterChildren(stayWithin);
358 RenderObject* RenderObject::nextInPreOrderAfterChildren(const RenderObject* stayWithin) const
360 if (this == stayWithin)
363 const RenderObject* current = this;
365 while (!(next = current->nextSibling())) {
366 current = current->parent();
367 if (!current || current == stayWithin)
373 RenderObject* RenderObject::previousInPreOrder() const
375 if (RenderObject* o = previousSibling()) {
376 while (o->lastChild())
384 RenderObject* RenderObject::previousInPreOrder(const RenderObject* stayWithin) const
386 if (this == stayWithin)
389 return previousInPreOrder();
392 RenderObject* RenderObject::childAt(unsigned index) const
394 RenderObject* child = firstChild();
395 for (unsigned i = 0; child && i < index; i++)
396 child = child->nextSibling();
400 RenderObject* RenderObject::firstLeafChild() const
402 RenderObject* r = firstChild();
413 RenderObject* RenderObject::lastLeafChild() const
415 RenderObject* r = lastChild();
426 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
427 RenderLayer*& beforeChild)
429 if (obj->hasLayer()) {
430 if (!beforeChild && newObject) {
431 // We need to figure out the layer that follows newObject. We only do
432 // this the first time we find a child layer, and then we update the
433 // pointer values for newObject and beforeChild used by everyone else.
434 beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
437 parentLayer->addChild(toRenderLayerModelObject(obj)->layer(), beforeChild);
441 for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
442 addLayers(curr, parentLayer, newObject, beforeChild);
445 void RenderObject::addLayers(RenderLayer* parentLayer)
450 RenderObject* object = this;
451 RenderLayer* beforeChild = 0;
452 WebCore::addLayers(this, parentLayer, object, beforeChild);
455 void RenderObject::removeLayers(RenderLayer* parentLayer)
461 parentLayer->removeChild(toRenderLayerModelObject(this)->layer());
465 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
466 curr->removeLayers(parentLayer);
469 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
475 RenderLayer* layer = toRenderLayerModelObject(this)->layer();
476 ASSERT(oldParent == layer->parent());
478 oldParent->removeChild(layer);
479 newParent->addChild(layer);
483 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
484 curr->moveLayers(oldParent, newParent);
487 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
490 // Error check the parent layer passed in. If it's null, we can't find anything.
494 // Step 1: If our layer is a child of the desired parent, then return our layer.
495 RenderLayer* ourLayer = hasLayer() ? toRenderLayerModelObject(this)->layer() : 0;
496 if (ourLayer && ourLayer->parent() == parentLayer)
499 // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
500 // into our siblings trying to find the next layer whose parent is the desired parent.
501 if (!ourLayer || ourLayer == parentLayer) {
502 for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
503 curr; curr = curr->nextSibling()) {
504 RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
510 // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
512 if (parentLayer == ourLayer)
515 // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
516 // follow us to see if we can locate a layer.
517 if (checkParent && parent())
518 return parent()->findNextLayer(parentLayer, this, true);
523 RenderLayer* RenderObject::enclosingLayer() const
525 const RenderObject* curr = this;
527 RenderLayer* layer = curr->hasLayer() ? toRenderLayerModelObject(curr)->layer() : 0;
530 curr = curr->parent();
535 bool RenderObject::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
537 RenderLayer* enclosingLayer = this->enclosingLayer();
541 enclosingLayer->scrollRectToVisible(rect, alignX, alignY);
545 RenderBox* RenderObject::enclosingBox() const
547 RenderObject* curr = const_cast<RenderObject*>(this);
550 return toRenderBox(curr);
551 curr = curr->parent();
554 ASSERT_NOT_REACHED();
558 RenderBoxModelObject* RenderObject::enclosingBoxModelObject() const
560 RenderObject* curr = const_cast<RenderObject*>(this);
562 if (curr->isBoxModelObject())
563 return toRenderBoxModelObject(curr);
564 curr = curr->parent();
567 ASSERT_NOT_REACHED();
571 RenderFlowThread* RenderObject::enclosingRenderFlowThread() const
573 if (!inRenderFlowThread())
576 // See if we have the thread cached because we're in the middle of layout.
577 RenderFlowThread* flowThread = view()->flowThreadController()->currentRenderFlowThread();
581 // Not in the middle of layout so have to find the thread the slow way.
582 RenderObject* curr = const_cast<RenderObject*>(this);
584 if (curr->isRenderFlowThread())
585 return toRenderFlowThread(curr);
586 curr = curr->parent();
591 RenderNamedFlowThread* RenderObject::enclosingRenderNamedFlowThread() const
593 RenderObject* object = const_cast<RenderObject*>(this);
594 while (object && object->isAnonymousBlock() && !object->isRenderNamedFlowThread())
595 object = object->parent();
597 return object && object->isRenderNamedFlowThread() ? toRenderNamedFlowThread(object) : 0;
600 RenderBlock* RenderObject::firstLineBlock() const
605 static inline bool objectIsRelayoutBoundary(const RenderObject* object)
607 // FIXME: In future it may be possible to broaden these conditions in order to improve performance.
608 if (object->isTextControl())
612 if (object->isSVGRoot())
616 if (!object->hasOverflowClip())
619 if (object->style()->width().isIntrinsicOrAuto() || object->style()->height().isIntrinsicOrAuto() || object->style()->height().isPercent())
622 // Table parts can't be relayout roots since the table is responsible for layouting all the parts.
623 if (object->isTablePart())
629 void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot)
631 ASSERT(!scheduleRelayout || !newRoot);
633 RenderObject* object = container();
634 RenderObject* last = this;
636 bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout();
639 // Don't mark the outermost object of an unrooted subtree. That object will be
640 // marked when the subtree is added to the document.
641 RenderObject* container = object->container();
642 if (!container && !object->isRenderView())
644 if (!last->isText() && last->style()->hasOutOfFlowPosition()) {
645 bool willSkipRelativelyPositionedInlines = !object->isRenderBlock() || object->isAnonymousBlock();
646 // Skip relatively positioned inlines and anonymous blocks to get to the enclosing RenderBlock.
647 while (object && (!object->isRenderBlock() || object->isAnonymousBlock()))
648 object = object->container();
649 if (!object || object->posChildNeedsLayout())
651 if (willSkipRelativelyPositionedInlines)
652 container = object->container();
653 object->setPosChildNeedsLayout(true);
654 simplifiedNormalFlowLayout = true;
655 ASSERT(!object->isSetNeedsLayoutForbidden());
656 } else if (simplifiedNormalFlowLayout) {
657 if (object->needsSimplifiedNormalFlowLayout())
659 object->setNeedsSimplifiedNormalFlowLayout(true);
660 ASSERT(!object->isSetNeedsLayoutForbidden());
662 if (object->normalChildNeedsLayout())
664 object->setNormalChildNeedsLayout(true);
665 ASSERT(!object->isSetNeedsLayoutForbidden());
668 if (object == newRoot)
672 if (scheduleRelayout && objectIsRelayoutBoundary(last))
677 if (scheduleRelayout)
678 last->scheduleRelayout();
682 void RenderObject::checkBlockPositionedObjectsNeedLayout()
684 ASSERT(!needsLayout());
687 toRenderBlock(this)->checkPositionedObjectsNeedLayout();
691 void RenderObject::setPreferredLogicalWidthsDirty(bool shouldBeDirty, MarkingBehavior markParents)
693 bool alreadyDirty = preferredLogicalWidthsDirty();
694 m_bitfields.setPreferredLogicalWidthsDirty(shouldBeDirty);
695 if (shouldBeDirty && !alreadyDirty && markParents == MarkContainingBlockChain && (isText() || !style()->hasOutOfFlowPosition()))
696 invalidateContainerPreferredLogicalWidths();
699 void RenderObject::invalidateContainerPreferredLogicalWidths()
701 // In order to avoid pathological behavior when inlines are deeply nested, we do include them
702 // in the chain that we mark dirty (even though they're kind of irrelevant).
703 RenderObject* o = isTableCell() ? containingBlock() : container();
704 while (o && !o->preferredLogicalWidthsDirty()) {
705 // Don't invalidate the outermost object of an unrooted subtree. That object will be
706 // invalidated when the subtree is added to the document.
707 RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
708 if (!container && !o->isRenderView())
711 o->m_bitfields.setPreferredLogicalWidthsDirty(true);
712 if (o->style()->hasOutOfFlowPosition())
713 // A positioned object has no effect on the min/max width of its containing block ever.
714 // We can optimize this case and not go up any further.
720 void RenderObject::setLayerNeedsFullRepaint()
723 toRenderLayerModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaint);
726 void RenderObject::setLayerNeedsFullRepaintForPositionedMovementLayout()
729 toRenderLayerModelObject(this)->layer()->setRepaintStatus(NeedsFullRepaintForPositionedMovementLayout);
732 RenderBlock* RenderObject::containingBlock() const
734 RenderObject* o = parent();
735 if (!o && isRenderScrollbarPart())
736 o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
737 if (!isText() && m_style->position() == FixedPosition) {
739 if (o->isRenderView())
741 if (o->hasTransform() && o->isRenderBlock())
743 // The render flow thread is the top most containing block
744 // for the fixed positioned elements.
745 if (o->isRenderFlowThread())
748 // foreignObject is the containing block for its contents.
749 if (o->isSVGForeignObject())
754 ASSERT(!o->isAnonymousBlock());
755 } else if (!isText() && m_style->position() == AbsolutePosition) {
757 // For relpositioned inlines, we return the nearest non-anonymous enclosing block. We don't try
758 // to return the inline itself. This allows us to avoid having a positioned objects
759 // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
760 // from this method. The container() method can actually be used to obtain the
762 if (!o->style()->position() == StaticPosition && !(o->isInline() && !o->isReplaced()))
764 if (o->isRenderView())
766 if (o->hasTransform() && o->isRenderBlock())
769 if (o->style()->hasInFlowPosition() && o->isInline() && !o->isReplaced()) {
770 o = o->containingBlock();
774 if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it
781 while (o && o->isAnonymousBlock())
782 o = o->containingBlock();
784 while (o && ((o->isInline() && !o->isReplaced()) || !o->isRenderBlock()))
788 if (!o || !o->isRenderBlock())
789 return 0; // This can still happen in case of an orphaned tree
791 return toRenderBlock(o);
794 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
796 // Nobody will use multiple layers without wanting fancy positioning.
800 // Make sure we have a valid image.
801 StyleImage* img = layer->image();
802 if (!img || !img->canRender(renderer, renderer->style()->effectiveZoom()))
805 if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
808 if (layer->size().type == SizeLength) {
809 if (layer->size().size.width().isPercent() || layer->size().size.height().isPercent())
811 } else if (layer->size().type == Contain || layer->size().type == Cover || img->usesImageContainerSize())
817 bool RenderObject::borderImageIsLoadedAndCanBeRendered() const
819 ASSERT(style()->hasBorder());
821 StyleImage* borderImage = style()->borderImage().image();
822 return borderImage && borderImage->canRender(this, style()->effectiveZoom()) && borderImage->isLoaded();
825 bool RenderObject::mustRepaintBackgroundOrBorder() const
827 if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
830 // If we don't have a background/border/mask, then nothing to do.
831 if (!hasBoxDecorations())
834 if (mustRepaintFillLayers(this, style()->backgroundLayers()))
837 // Our fill layers are ok. Let's check border.
838 if (style()->hasBorder() && borderImageIsLoadedAndCanBeRendered())
844 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
845 BoxSide side, Color color, EBorderStyle style,
846 int adjacentWidth1, int adjacentWidth2, bool antialias)
850 if (side == BSTop || side == BSBottom) {
858 // FIXME: We really would like this check to be an ASSERT as we don't want to draw empty borders. However
859 // nothing guarantees that the following recursive calls to drawLineForBoxSide will have non-null dimensions.
860 if (!thickness || !length)
863 if (style == DOUBLE && thickness < 3)
872 graphicsContext->setStrokeColor(color, m_style->colorSpace());
873 graphicsContext->setStrokeThickness(thickness);
874 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
875 graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
878 bool wasAntialiased = graphicsContext->shouldAntialias();
879 graphicsContext->setShouldAntialias(antialias);
884 graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
888 graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
891 graphicsContext->setShouldAntialias(wasAntialiased);
892 graphicsContext->setStrokeStyle(oldStrokeStyle);
897 int thirdOfThickness = (thickness + 1) / 3;
898 ASSERT(thirdOfThickness);
900 if (adjacentWidth1 == 0 && adjacentWidth2 == 0) {
901 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
902 graphicsContext->setStrokeStyle(NoStroke);
903 graphicsContext->setFillColor(color, m_style->colorSpace());
905 bool wasAntialiased = graphicsContext->shouldAntialias();
906 graphicsContext->setShouldAntialias(antialias);
911 graphicsContext->drawRect(IntRect(x1, y1, length, thirdOfThickness));
912 graphicsContext->drawRect(IntRect(x1, y2 - thirdOfThickness, length, thirdOfThickness));
916 // FIXME: Why do we offset the border by 1 in this case but not the other one?
918 graphicsContext->drawRect(IntRect(x1, y1 + 1, thirdOfThickness, length - 1));
919 graphicsContext->drawRect(IntRect(x2 - thirdOfThickness, y1 + 1, thirdOfThickness, length - 1));
924 graphicsContext->setShouldAntialias(wasAntialiased);
925 graphicsContext->setStrokeStyle(oldStrokeStyle);
927 int adjacent1BigThird = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3;
928 int adjacent2BigThird = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3;
932 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
933 y1, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
934 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
935 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
936 y2 - thirdOfThickness, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y2,
937 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
940 drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
941 x1 + thirdOfThickness, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
942 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
943 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
944 x2, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
945 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
948 drawLineForBoxSide(graphicsContext, x1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
949 y1, x2 - max((adjacentWidth2 * 2 + 1) / 3, 0), y1 + thirdOfThickness,
950 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
951 drawLineForBoxSide(graphicsContext, x1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
952 y2 - thirdOfThickness, x2 - max((-adjacentWidth2 * 2 + 1) / 3, 0), y2,
953 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
956 drawLineForBoxSide(graphicsContext, x1, y1 + max((adjacentWidth1 * 2 + 1) / 3, 0),
957 x1 + thirdOfThickness, y2 - max((adjacentWidth2 * 2 + 1) / 3, 0),
958 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
959 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, y1 + max((-adjacentWidth1 * 2 + 1) / 3, 0),
960 x2, y2 - max((-adjacentWidth2 * 2 + 1) / 3, 0),
961 side, color, SOLID, adjacent1BigThird, adjacent2BigThird, antialias);
973 if (style == GROOVE) {
981 int adjacent1BigHalf = ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2;
982 int adjacent2BigHalf = ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2;
986 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1, 0) / 2, y1, x2 - max(-adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
987 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
988 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjacentWidth2 + 1, 0) / 2, y2,
989 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
992 drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjacentWidth2, 0) / 2,
993 side, color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias);
994 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjacentWidth1 + 1, 0) / 2, x2, y2 - max(adjacentWidth2 + 1, 0) / 2,
995 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
998 drawLineForBoxSide(graphicsContext, x1 + max(adjacentWidth1, 0) / 2, y1, x2 - max(adjacentWidth2, 0) / 2, (y1 + y2 + 1) / 2,
999 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
1000 drawLineForBoxSide(graphicsContext, x1 + max(-adjacentWidth1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjacentWidth2 + 1, 0) / 2, y2,
1001 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1004 drawLineForBoxSide(graphicsContext, x1, y1 + max(adjacentWidth1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjacentWidth2, 0) / 2,
1005 side, color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias);
1006 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjacentWidth1 + 1, 0) / 2, x2, y2 - max(-adjacentWidth2 + 1, 0) / 2,
1007 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias);
1013 // FIXME: Maybe we should lighten the colors on one side like Firefox.
1014 // https://bugs.webkit.org/show_bug.cgi?id=58608
1015 if (side == BSTop || side == BSLeft)
1016 color = color.dark();
1019 if (style == OUTSET && (side == BSBottom || side == BSRight))
1020 color = color.dark();
1023 StrokeStyle oldStrokeStyle = graphicsContext->strokeStyle();
1024 graphicsContext->setStrokeStyle(NoStroke);
1025 graphicsContext->setFillColor(color, m_style->colorSpace());
1028 if (!adjacentWidth1 && !adjacentWidth2) {
1029 // Turn off antialiasing to match the behavior of drawConvexPolygon();
1030 // this matters for rects in transformed contexts.
1031 bool wasAntialiased = graphicsContext->shouldAntialias();
1032 graphicsContext->setShouldAntialias(antialias);
1033 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1034 graphicsContext->setShouldAntialias(wasAntialiased);
1035 graphicsContext->setStrokeStyle(oldStrokeStyle);
1041 quad[0] = FloatPoint(x1 + max(-adjacentWidth1, 0), y1);
1042 quad[1] = FloatPoint(x1 + max(adjacentWidth1, 0), y2);
1043 quad[2] = FloatPoint(x2 - max(adjacentWidth2, 0), y2);
1044 quad[3] = FloatPoint(x2 - max(-adjacentWidth2, 0), y1);
1047 quad[0] = FloatPoint(x1 + max(adjacentWidth1, 0), y1);
1048 quad[1] = FloatPoint(x1 + max(-adjacentWidth1, 0), y2);
1049 quad[2] = FloatPoint(x2 - max(-adjacentWidth2, 0), y2);
1050 quad[3] = FloatPoint(x2 - max(adjacentWidth2, 0), y1);
1053 quad[0] = FloatPoint(x1, y1 + max(-adjacentWidth1, 0));
1054 quad[1] = FloatPoint(x1, y2 - max(-adjacentWidth2, 0));
1055 quad[2] = FloatPoint(x2, y2 - max(adjacentWidth2, 0));
1056 quad[3] = FloatPoint(x2, y1 + max(adjacentWidth1, 0));
1059 quad[0] = FloatPoint(x1, y1 + max(adjacentWidth1, 0));
1060 quad[1] = FloatPoint(x1, y2 - max(adjacentWidth2, 0));
1061 quad[2] = FloatPoint(x2, y2 - max(-adjacentWidth2, 0));
1062 quad[3] = FloatPoint(x2, y1 + max(-adjacentWidth1, 0));
1066 graphicsContext->drawConvexPolygon(4, quad, antialias);
1067 graphicsContext->setStrokeStyle(oldStrokeStyle);
1073 void RenderObject::paintFocusRing(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style)
1075 Vector<IntRect> focusRingRects;
1076 addFocusRingRects(focusRingRects, paintOffset);
1077 if (style->outlineStyleIsAuto())
1078 context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
1080 addPDFURLRect(context, unionRect(focusRingRects));
1083 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
1088 if (!n || !n->isLink() || !n->isElementNode())
1090 const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
1093 context->setURLForRect(n->document()->completeURL(href), pixelSnappedIntRect(rect));
1096 void RenderObject::paintOutline(GraphicsContext* graphicsContext, const LayoutRect& paintRect)
1101 RenderStyle* styleToUse = style();
1102 LayoutUnit outlineWidth = styleToUse->outlineWidth();
1103 EBorderStyle outlineStyle = styleToUse->outlineStyle();
1105 Color outlineColor = styleToUse->visitedDependentColor(CSSPropertyOutlineColor);
1107 int outlineOffset = styleToUse->outlineOffset();
1109 if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1110 if (!theme()->supportsFocusRing(styleToUse)) {
1111 // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1112 paintFocusRing(graphicsContext, paintRect.location(), styleToUse);
1116 if (styleToUse->outlineStyleIsAuto() || styleToUse->outlineStyle() == BNONE)
1119 IntRect inner = pixelSnappedIntRect(paintRect);
1120 inner.inflate(outlineOffset);
1122 IntRect outer = pixelSnappedIntRect(inner);
1123 outer.inflate(outlineWidth);
1125 // FIXME: This prevents outlines from painting inside the object. See bug 12042
1126 if (outer.isEmpty())
1129 bool useTransparencyLayer = outlineColor.hasAlpha();
1130 if (useTransparencyLayer) {
1131 if (outlineStyle == SOLID) {
1133 path.addRect(outer);
1134 path.addRect(inner);
1135 graphicsContext->setFillRule(RULE_EVENODD);
1136 graphicsContext->setFillColor(outlineColor, styleToUse->colorSpace());
1137 graphicsContext->fillPath(path);
1140 graphicsContext->beginTransparencyLayer(static_cast<float>(outlineColor.alpha()) / 255);
1141 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineColor.blue());
1144 int leftOuter = outer.x();
1145 int leftInner = inner.x();
1146 int rightOuter = outer.maxX();
1147 int rightInner = inner.maxX();
1148 int topOuter = outer.y();
1149 int topInner = inner.y();
1150 int bottomOuter = outer.maxY();
1151 int bottomInner = inner.maxY();
1153 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1154 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInner, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1155 drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottomOuter, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1156 drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bottomOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1158 if (useTransparencyLayer)
1159 graphicsContext->endTransparencyLayer();
1162 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) const
1164 if (useTransforms) {
1165 Vector<FloatQuad> quads;
1166 absoluteQuads(quads);
1168 size_t n = quads.size();
1172 IntRect result = quads[0].enclosingBoundingBox();
1173 for (size_t i = 1; i < n; ++i)
1174 result.unite(quads[i].enclosingBoundingBox());
1178 FloatPoint absPos = localToAbsolute();
1179 Vector<IntRect> rects;
1180 absoluteRects(rects, flooredLayoutPoint(absPos));
1182 size_t n = rects.size();
1186 LayoutRect result = rects[0];
1187 for (size_t i = 1; i < n; ++i)
1188 result.unite(rects[i]);
1189 return pixelSnappedIntRect(result);
1192 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1194 Vector<IntRect> rects;
1195 // FIXME: addFocusRingRects() needs to be passed this transform-unaware
1196 // localToAbsolute() offset here because RenderInline::addFocusRingRects()
1197 // implicitly assumes that. This doesn't work correctly with transformed
1199 FloatPoint absolutePoint = localToAbsolute();
1200 addFocusRingRects(rects, flooredLayoutPoint(absolutePoint));
1201 size_t count = rects.size();
1202 for (size_t i = 0; i < count; ++i) {
1203 IntRect rect = rects[i];
1204 rect.move(-absolutePoint.x(), -absolutePoint.y());
1205 quads.append(localToAbsoluteQuad(FloatQuad(rect)));
1209 FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range)
1211 if (!range || !range->startContainer())
1214 if (range->ownerDocument())
1215 range->ownerDocument()->updateLayout();
1217 Vector<FloatQuad> quads;
1218 range->textQuads(quads);
1221 for (size_t i = 0; i < quads.size(); ++i)
1222 result.unite(quads[i].boundingBox());
1227 void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
1230 result.unite(absoluteBoundingBoxRectIgnoringTransforms());
1231 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1232 current->addAbsoluteRectForLayer(result);
1235 LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect)
1237 LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms();
1238 topLevelRect = result;
1239 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1240 current->addAbsoluteRectForLayer(result);
1244 void RenderObject::paint(PaintInfo&, const LayoutPoint&)
1248 RenderLayerModelObject* RenderObject::containerForRepaint() const
1250 RenderView* v = view();
1254 RenderLayerModelObject* repaintContainer = 0;
1256 #if USE(ACCELERATED_COMPOSITING)
1257 if (v->usesCompositing()) {
1258 if (RenderLayer* parentLayer = enclosingLayer()) {
1259 RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint();
1261 repaintContainer = compLayer->renderer();
1266 #if ENABLE(CSS_FILTERS)
1267 if (RenderLayer* parentLayer = enclosingLayer()) {
1268 RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer();
1269 if (enclosingFilterLayer)
1270 return enclosingFilterLayer->renderer();
1274 // If we have a flow thread, then we need to do individual repaints within the RenderRegions instead.
1275 // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change
1276 // repainting to do individual region repaints.
1277 // FIXME: Composited layers inside a flow thread will bypass this mechanism and will malfunction. It's not
1278 // clear how to address this problem for composited descendants of a RenderFlowThread.
1279 if (!repaintContainer && inRenderFlowThread())
1280 repaintContainer = enclosingRenderFlowThread();
1281 return repaintContainer;
1284 void RenderObject::repaintUsingContainer(RenderLayerModelObject* repaintContainer, const IntRect& r, bool immediate) const
1286 if (!repaintContainer) {
1287 view()->repaintViewRectangle(r, immediate);
1291 if (repaintContainer->isRenderFlowThread()) {
1292 toRenderFlowThread(repaintContainer)->repaintRectangleInRegions(r, immediate);
1296 #if ENABLE(CSS_FILTERS)
1297 if (repaintContainer->hasFilter() && repaintContainer->layer() && repaintContainer->layer()->requiresFullLayerImageForFilters()) {
1298 repaintContainer->layer()->setFilterBackendNeedsRepaintingInRect(r, immediate);
1303 #if USE(ACCELERATED_COMPOSITING)
1304 RenderView* v = view();
1305 if (repaintContainer->isRenderView()) {
1306 ASSERT(repaintContainer == v);
1307 bool viewHasCompositedLayer = v->hasLayer() && v->layer()->isComposited();
1308 if (!viewHasCompositedLayer || v->layer()->backing()->paintsIntoWindow()) {
1309 LayoutRect repaintRectangle = r;
1310 if (viewHasCompositedLayer && v->layer()->transform())
1311 repaintRectangle = enclosingIntRect(v->layer()->transform()->mapRect(r));
1312 v->repaintViewRectangle(repaintRectangle, immediate);
1317 if (v->usesCompositing()) {
1318 ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
1319 repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
1322 if (repaintContainer->isRenderView())
1323 toRenderView(repaintContainer)->repaintViewRectangle(r, immediate);
1327 void RenderObject::repaint(bool immediate) const
1329 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1331 if (!isRooted(&view))
1334 if (view->printing())
1335 return; // Don't repaint if we're printing.
1337 RenderLayerModelObject* repaintContainer = containerForRepaint();
1338 repaintUsingContainer(repaintContainer ? repaintContainer : view, pixelSnappedIntRect(clippedOverflowRectForRepaint(repaintContainer)), immediate);
1341 void RenderObject::repaintRectangle(const LayoutRect& r, bool immediate) const
1343 // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
1345 if (!isRooted(&view))
1348 if (view->printing())
1349 return; // Don't repaint if we're printing.
1351 LayoutRect dirtyRect(r);
1353 // FIXME: layoutDelta needs to be applied in parts before/after transforms and
1354 // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
1355 dirtyRect.move(view->layoutDelta());
1357 RenderLayerModelObject* repaintContainer = containerForRepaint();
1358 computeRectForRepaint(repaintContainer, dirtyRect);
1359 repaintUsingContainer(repaintContainer ? repaintContainer : view, pixelSnappedIntRect(dirtyRect), immediate);
1362 IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const
1364 return pixelSnappedIntRect(absoluteClippedOverflowRect());
1367 bool RenderObject::repaintAfterLayoutIfNeeded(RenderLayerModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr, const LayoutRect* newOutlineBoxRectPtr)
1369 RenderView* v = view();
1371 return false; // Don't repaint if we're printing.
1373 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1374 // ASSERT(!newBoundsPtr || *newBoundsPtr == clippedOverflowRectForRepaint(repaintContainer));
1375 LayoutRect newBounds = newBoundsPtr ? *newBoundsPtr : clippedOverflowRectForRepaint(repaintContainer);
1376 LayoutRect newOutlineBox;
1378 bool fullRepaint = selfNeedsLayout();
1379 // Presumably a background or a border exists if border-fit:lines was specified.
1380 if (!fullRepaint && style()->borderFit() == BorderFitLines)
1383 // This ASSERT fails due to animations. See https://bugs.webkit.org/show_bug.cgi?id=37048
1384 // ASSERT(!newOutlineBoxRectPtr || *newOutlineBoxRectPtr == outlineBoundsForRepaint(repaintContainer));
1385 newOutlineBox = newOutlineBoxRectPtr ? *newOutlineBoxRectPtr : outlineBoundsForRepaint(repaintContainer);
1386 if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
1390 if (!repaintContainer)
1391 repaintContainer = v;
1394 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds));
1395 if (newBounds != oldBounds)
1396 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds));
1400 if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1403 LayoutUnit deltaLeft = newBounds.x() - oldBounds.x();
1405 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1406 else if (deltaLeft < 0)
1407 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1409 LayoutUnit deltaRight = newBounds.maxX() - oldBounds.maxX();
1411 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.maxX(), newBounds.y(), deltaRight, newBounds.height()));
1412 else if (deltaRight < 0)
1413 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.maxX(), oldBounds.y(), -deltaRight, oldBounds.height()));
1415 LayoutUnit deltaTop = newBounds.y() - oldBounds.y();
1417 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1418 else if (deltaTop < 0)
1419 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1421 LayoutUnit deltaBottom = newBounds.maxY() - oldBounds.maxY();
1422 if (deltaBottom > 0)
1423 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds.x(), oldBounds.maxY(), newBounds.width(), deltaBottom));
1424 else if (deltaBottom < 0)
1425 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldBounds.x(), newBounds.maxY(), oldBounds.width(), -deltaBottom));
1427 if (newOutlineBox == oldOutlineBox)
1430 // We didn't move, but we did change size. Invalidate the delta, which will consist of possibly
1431 // two rectangles (but typically only one).
1432 RenderStyle* outlineStyle = outlineStyleForRepaint();
1433 LayoutUnit outlineWidth = outlineStyle->outlineSize();
1434 LayoutBoxExtent insetShadowExtent = style()->getBoxShadowInsetExtent();
1435 LayoutUnit width = absoluteValue(newOutlineBox.width() - oldOutlineBox.width());
1437 LayoutUnit shadowLeft;
1438 LayoutUnit shadowRight;
1439 style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
1440 int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
1441 LayoutUnit boxWidth = isBox() ? toRenderBox(this)->width() : ZERO_LAYOUT_UNIT;
1442 LayoutUnit minInsetRightShadowExtent = min<LayoutUnit>(-insetShadowExtent.right(), min<LayoutUnit>(newBounds.width(), oldBounds.width()));
1443 LayoutUnit borderWidth = max<LayoutUnit>(borderRight, max<LayoutUnit>(valueForLength(style()->borderTopRightRadius().width(), boxWidth, v), valueForLength(style()->borderBottomRightRadius().width(), boxWidth, v)));
1444 LayoutUnit decorationsWidth = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderWidth + minInsetRightShadowExtent) + max<LayoutUnit>(outlineWidth, shadowRight);
1445 LayoutRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - decorationsWidth,
1447 width + decorationsWidth,
1448 max(newOutlineBox.height(), oldOutlineBox.height()));
1449 LayoutUnit right = min<LayoutUnit>(newBounds.maxX(), oldBounds.maxX());
1450 if (rightRect.x() < right) {
1451 rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1452 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(rightRect));
1455 LayoutUnit height = absoluteValue(newOutlineBox.height() - oldOutlineBox.height());
1457 LayoutUnit shadowTop;
1458 LayoutUnit shadowBottom;
1459 style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
1460 int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
1461 LayoutUnit boxHeight = isBox() ? toRenderBox(this)->height() : ZERO_LAYOUT_UNIT;
1462 LayoutUnit minInsetBottomShadowExtent = min<LayoutUnit>(-insetShadowExtent.bottom(), min<LayoutUnit>(newBounds.height(), oldBounds.height()));
1463 LayoutUnit borderHeight = max<LayoutUnit>(borderBottom, max<LayoutUnit>(valueForLength(style()->borderBottomLeftRadius().height(), boxHeight, v), valueForLength(style()->borderBottomRightRadius().height(), boxHeight, v)));
1464 LayoutUnit decorationsHeight = max<LayoutUnit>(-outlineStyle->outlineOffset(), borderHeight + minInsetBottomShadowExtent) + max<LayoutUnit>(outlineWidth, shadowBottom);
1465 LayoutRect bottomRect(newOutlineBox.x(),
1466 min(newOutlineBox.maxY(), oldOutlineBox.maxY()) - decorationsHeight,
1467 max(newOutlineBox.width(), oldOutlineBox.width()),
1468 height + decorationsHeight);
1469 LayoutUnit bottom = min(newBounds.maxY(), oldBounds.maxY());
1470 if (bottomRect.y() < bottom) {
1471 bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1472 repaintUsingContainer(repaintContainer, pixelSnappedIntRect(bottomRect));
1478 void RenderObject::repaintDuringLayoutIfMoved(const LayoutRect&)
1482 void RenderObject::repaintOverhangingFloats(bool)
1486 bool RenderObject::checkForRepaintDuringLayout() const
1488 return !document()->view()->needsFullRepaint() && !hasLayer() && everHadLayout();
1491 LayoutRect RenderObject::rectWithOutlineForRepaint(RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const
1493 LayoutRect r(clippedOverflowRectForRepaint(repaintContainer));
1494 r.inflate(outlineWidth);
1498 LayoutRect RenderObject::clippedOverflowRectForRepaint(RenderLayerModelObject*) const
1500 ASSERT_NOT_REACHED();
1501 return LayoutRect();
1504 void RenderObject::computeRectForRepaint(RenderLayerModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
1506 if (repaintContainer == this)
1509 if (RenderObject* o = parent()) {
1510 if (o->isBlockFlow()) {
1511 RenderBlock* cb = toRenderBlock(o);
1512 if (cb->hasColumns())
1513 cb->adjustRectForColumns(rect);
1516 if (o->hasOverflowClip()) {
1517 RenderBox* boxParent = toRenderBox(o);
1518 boxParent->applyCachedClipAndScrollOffsetForRepaint(rect);
1523 o->computeRectForRepaint(repaintContainer, rect, fixed);
1527 void RenderObject::computeFloatRectForRepaint(RenderLayerModelObject*, FloatRect&, bool) const
1529 ASSERT_NOT_REACHED();
1532 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
1538 void RenderObject::showTreeForThis() const
1541 node()->showTreeForThis();
1544 void RenderObject::showRenderTreeForThis() const
1546 showRenderTree(this, 0);
1549 void RenderObject::showLineTreeForThis() const
1551 if (containingBlock())
1552 containingBlock()->showLineTreeAndMark(0, 0, 0, 0, this);
1555 void RenderObject::showRenderObject() const
1557 showRenderObject(0);
1560 void RenderObject::showRenderObject(int printedCharacters) const
1562 // As this function is intended to be used when debugging, the
1563 // this pointer may be 0.
1565 fputs("(null)\n", stderr);
1569 printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
1572 if (printedCharacters)
1573 for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
1575 fputc('\t', stderr);
1578 fputc('\n', stderr);
1581 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
1583 int printedCharacters = 0;
1584 if (markedObject1 == this && markedLabel1)
1585 printedCharacters += fprintf(stderr, "%s", markedLabel1);
1586 if (markedObject2 == this && markedLabel2)
1587 printedCharacters += fprintf(stderr, "%s", markedLabel2);
1588 for (; printedCharacters < depth * 2; printedCharacters++)
1591 showRenderObject(printedCharacters);
1595 for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
1596 child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
1601 Color RenderObject::selectionBackgroundColor() const
1604 if (style()->userSelect() != SELECT_NONE) {
1605 RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
1606 if (pseudoStyle && pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
1607 color = pseudoStyle->visitedDependentColor(CSSPropertyBackgroundColor).blendWithWhite();
1609 color = frame()->selection()->isFocusedAndActive() ?
1610 theme()->activeSelectionBackgroundColor() :
1611 theme()->inactiveSelectionBackgroundColor();
1617 Color RenderObject::selectionColor(int colorProperty) const
1620 // If the element is unselectable, or we are only painting the selection,
1621 // don't override the foreground color with the selection foreground color.
1622 if (style()->userSelect() == SELECT_NONE
1623 || (frame()->view()->paintBehavior() & PaintBehaviorSelectionOnly))
1626 if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
1627 color = pseudoStyle->visitedDependentColor(colorProperty);
1628 if (!color.isValid())
1629 color = pseudoStyle->visitedDependentColor(CSSPropertyColor);
1631 color = frame()->selection()->isFocusedAndActive() ?
1632 theme()->activeSelectionForegroundColor() :
1633 theme()->inactiveSelectionForegroundColor();
1638 Color RenderObject::selectionForegroundColor() const
1640 return selectionColor(CSSPropertyWebkitTextFillColor);
1643 Color RenderObject::selectionEmphasisMarkColor() const
1645 return selectionColor(CSSPropertyWebkitTextEmphasisColor);
1648 void RenderObject::selectionStartEnd(int& spos, int& epos) const
1650 view()->selectionStartEnd(spos, epos);
1653 void RenderObject::handleDynamicFloatPositionChange()
1655 // We have gone from not affecting the inline status of the parent flow to suddenly
1656 // having an impact. See if there is a mismatch between the parent flow's
1657 // childrenInline() state and our state.
1658 setInline(style()->isDisplayInlineType());
1659 if (isInline() != parent()->childrenInline()) {
1661 toRenderBoxModelObject(parent())->childBecameNonInline(this);
1663 // An anonymous block must be made to wrap this inline.
1664 RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
1665 RenderObjectChildList* childlist = parent()->virtualChildren();
1666 childlist->insertChildNode(parent(), block, this);
1667 block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
1672 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
1674 if (!isText() && style)
1675 setStyle(animation()->updateAnimations(this, style.get()));
1680 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
1682 #if USE(ACCELERATED_COMPOSITING)
1683 // If transform changed, and we are not composited, need to do a layout.
1684 if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
1685 // Text nodes share style with their parents but transforms don't apply to them,
1686 // hence the !isText() check.
1687 // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
1688 if (!isText() && (!hasLayer() || !toRenderLayerModelObject(this)->layer()->isComposited())) {
1689 // We need to set at least SimplifiedLayout, but if PositionedMovementOnly is already set
1690 // then we actually need SimplifiedLayoutAndPositionedMovement.
1692 diff = StyleDifferenceLayout; // FIXME: Do this for now since SimplifiedLayout cannot handle updating floating objects lists.
1693 else if (diff < StyleDifferenceLayoutPositionedMovementOnly)
1694 diff = StyleDifferenceSimplifiedLayout;
1695 else if (diff < StyleDifferenceSimplifiedLayout)
1696 diff = StyleDifferenceSimplifiedLayoutAndPositionedMovement;
1697 } else if (diff < StyleDifferenceRecompositeLayer)
1698 diff = StyleDifferenceRecompositeLayer;
1701 // If opacity changed, and we are not composited, need to repaint (also
1702 // ignoring text nodes)
1703 if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
1704 if (!isText() && (!hasLayer() || !toRenderLayerModelObject(this)->layer()->isComposited()))
1705 diff = StyleDifferenceRepaintLayer;
1706 else if (diff < StyleDifferenceRecompositeLayer)
1707 diff = StyleDifferenceRecompositeLayer;
1710 #if ENABLE(CSS_FILTERS)
1711 if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer()) {
1712 RenderLayer* layer = toRenderLayerModelObject(this)->layer();
1713 if (!layer->isComposited() || layer->paintsWithFilters())
1714 diff = StyleDifferenceRepaintLayer;
1715 else if (diff < StyleDifferenceRecompositeLayer)
1716 diff = StyleDifferenceRecompositeLayer;
1720 // The answer to requiresLayer() for plugins, iframes, and canvas can change without the actual
1721 // style changing, since it depends on whether we decide to composite these elements. When the
1722 // layer status of one of these elements changes, we need to force a layout.
1723 if (diff == StyleDifferenceEqual && style() && isLayerModelObject()) {
1724 if (hasLayer() != toRenderLayerModelObject(this)->requiresLayer())
1725 diff = StyleDifferenceLayout;
1728 UNUSED_PARAM(contextSensitiveProperties);
1731 // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
1732 if (diff == StyleDifferenceRepaintLayer && !hasLayer())
1733 diff = StyleDifferenceRepaint;
1738 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
1740 if (m_style == style) {
1741 #if USE(ACCELERATED_COMPOSITING)
1742 // We need to run through adjustStyleDifference() for iframes, plugins, and canvas so
1743 // style sharing is disabled for them. That should ensure that we never hit this code path.
1744 ASSERT(!isRenderIFrame() && !isEmbeddedObject() && !isCanvas());
1749 StyleDifference diff = StyleDifferenceEqual;
1750 unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
1752 diff = m_style->diff(style.get(), contextSensitiveProperties);
1754 diff = adjustStyleDifference(diff, contextSensitiveProperties);
1756 styleWillChange(diff, style.get());
1758 RefPtr<RenderStyle> oldStyle = m_style.release();
1761 updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
1762 updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
1764 updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
1765 updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
1767 // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
1768 // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
1769 if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
1770 toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
1772 bool doesNotNeedLayout = !m_parent || isText();
1774 styleDidChange(diff, oldStyle.get());
1776 // FIXME: |this| might be destroyed here. This can currently happen for a RenderTextFragment when
1777 // its first-letter block gets an update in RenderTextFragment::styleDidChange. For RenderTextFragment(s),
1778 // we will safely bail out with the doesNotNeedLayout flag. We might want to broaden this condition
1779 // in the future as we move renderer changes out of layout and into style changes.
1780 if (doesNotNeedLayout)
1783 // Now that the layer (if any) has been updated, we need to adjust the diff again,
1784 // check whether we should layout now, and decide if we need to repaint.
1785 StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
1787 if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
1788 if (updatedDiff == StyleDifferenceLayout)
1789 setNeedsLayoutAndPrefWidthsRecalc();
1790 else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
1791 setNeedsPositionedMovementLayout();
1792 else if (updatedDiff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1793 setNeedsPositionedMovementLayout();
1794 setNeedsSimplifiedNormalFlowLayout();
1795 } else if (updatedDiff == StyleDifferenceSimplifiedLayout)
1796 setNeedsSimplifiedNormalFlowLayout();
1799 if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
1800 // Do a repaint with the new style now, e.g., for example if we go from
1801 // not having an outline to having an outline.
1806 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
1811 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
1814 // If our z-index changes value or our visibility changes,
1815 // we need to dirty our stacking context's z-order list.
1817 bool visibilityChanged = m_style->visibility() != newStyle->visibility()
1818 || m_style->zIndex() != newStyle->zIndex()
1819 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
1820 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
1821 if (visibilityChanged)
1822 document()->setDashboardRegionsDirty(true);
1824 if (visibilityChanged && AXObjectCache::accessibilityEnabled())
1825 document()->axObjectCache()->childrenChanged(this);
1827 // Keep layer hierarchy visibility bits up to date if visibility changes.
1828 if (m_style->visibility() != newStyle->visibility()) {
1829 if (RenderLayer* l = enclosingLayer()) {
1830 if (newStyle->visibility() == VISIBLE)
1831 l->setHasVisibleContent();
1832 else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
1833 l->dirtyVisibleContentStatus();
1834 if (diff > StyleDifferenceRepaintLayer)
1841 if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
1843 if (isFloating() && (m_style->floating() != newStyle->floating()))
1844 // For changes in float styles, we need to conceivably remove ourselves
1845 // from the floating objects list.
1846 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1847 else if (isOutOfFlowPositioned() && (m_style->position() != newStyle->position()))
1848 // For changes in positioning styles, we need to conceivably remove ourselves
1849 // from the positioned objects list.
1850 toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
1852 s_affectsParentBlock = isFloatingOrOutOfFlowPositioned()
1853 && (!newStyle->isFloating() && !newStyle->hasOutOfFlowPosition())
1854 && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
1856 // reset style flags
1857 if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
1859 setPositioned(false);
1860 setRelPositioned(false);
1861 setStickyPositioned(false);
1863 setHorizontalWritingMode(true);
1864 setPaintBackground(false);
1865 setHasOverflowClip(false);
1866 setHasTransform(false);
1867 setHasReflection(false);
1869 s_affectsParentBlock = false;
1871 if (view()->frameView()) {
1872 bool shouldBlitOnFixedBackgroundImage = false;
1873 #if ENABLE(FAST_MOBILE_SCROLLING)
1874 // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
1875 // when scrolling a page with a fixed background image. As an optimization, assuming there are
1876 // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
1877 // ignore the CSS property "background-attachment: fixed".
1879 if (view()->frameView()->delegatesScrolling())
1881 shouldBlitOnFixedBackgroundImage = true;
1884 bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage();
1885 bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage();
1886 if (oldStyleSlowScroll != newStyleSlowScroll) {
1887 if (oldStyleSlowScroll)
1888 view()->frameView()->removeSlowRepaintObject();
1889 if (newStyleSlowScroll)
1890 view()->frameView()->addSlowRepaintObject();
1895 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderStyle* b)
1897 ASSERT(a->cursors() != b->cursors());
1898 return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
1901 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
1903 return a->cursor() == b->cursor() && (a->cursors() == b->cursors() || areNonIdenticalCursorListsEqual(a, b));
1906 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
1908 if (s_affectsParentBlock)
1909 handleDynamicFloatPositionChange();
1914 if (diff == StyleDifferenceLayout || diff == StyleDifferenceSimplifiedLayout) {
1915 RenderCounter::rendererStyleChanged(this, oldStyle, m_style.get());
1917 // If the object already needs layout, then setNeedsLayout won't do
1918 // any work. But if the containing block has changed, then we may need
1919 // to mark the new containing blocks for layout. The change that can
1920 // directly affect the containing block of this object is a change to
1921 // the position style.
1922 if (needsLayout() && oldStyle->position() != m_style->position())
1923 markContainingBlocksForLayout();
1925 if (diff == StyleDifferenceLayout)
1926 setNeedsLayoutAndPrefWidthsRecalc();
1928 setNeedsSimplifiedNormalFlowLayout();
1929 } else if (diff == StyleDifferenceSimplifiedLayoutAndPositionedMovement) {
1930 setNeedsPositionedMovementLayout();
1931 setNeedsSimplifiedNormalFlowLayout();
1932 } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
1933 setNeedsPositionedMovementLayout();
1935 // Don't check for repaint here; we need to wait until the layer has been
1936 // updated by subclasses before we know if we have to repaint (in setStyle()).
1938 if (oldStyle && !areCursorsEqual(oldStyle, style())) {
1939 if (Frame* frame = this->frame())
1940 frame->eventHandler()->dispatchFakeMouseMoveEventSoon();
1944 void RenderObject::propagateStyleToAnonymousChildren(bool blockChildrenOnly)
1946 // FIXME: We could save this call when the change only affected non-inherited properties.
1947 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
1948 if (!child->isAnonymous() || child->style()->styleType() != NOPSEUDO)
1951 if (blockChildrenOnly && !child->isRenderBlock())
1954 #if ENABLE(FULLSCREEN_API)
1955 if (child->isRenderFullScreen() || child->isRenderFullScreenPlaceholder())
1959 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), child->style()->display());
1960 if (style()->specifiesColumns()) {
1961 if (child->style()->specifiesColumns())
1962 newStyle->inheritColumnPropertiesFrom(style());
1963 if (child->style()->columnSpan())
1964 newStyle->setColumnSpan(ColumnSpanAll);
1967 // Preserve the position style of anonymous block continuations as they can have relative or sticky position when
1968 // they contain block descendants of relative or sticky positioned inlines.
1969 if (child->isInFlowPositioned() && toRenderBlock(child)->isAnonymousBlockContinuation())
1970 newStyle->setPosition(child->style()->position());
1972 child->setStyle(newStyle.release());
1976 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
1978 // Optimize the common case
1979 if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
1982 // Go through the new layers and addClients first, to avoid removing all clients of an image.
1983 for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
1984 if (currNew->image())
1985 currNew->image()->addClient(this);
1988 for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
1989 if (currOld->image())
1990 currOld->image()->removeClient(this);
1994 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
1996 if (oldImage != newImage) {
1998 oldImage->removeClient(this);
2000 newImage->addClient(this);
2004 LayoutRect RenderObject::viewRect() const
2006 return view()->viewRect();
2009 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, bool fixed, bool useTransforms) const
2011 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2012 MapLocalToContainerFlags mode = ApplyContainerFlip;
2016 mode |= UseTransforms;
2017 mapLocalToContainer(0, transformState, mode);
2018 transformState.flatten();
2020 return transformState.lastPlanarPoint();
2023 FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, bool fixed, bool useTransforms) const
2025 TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
2026 mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2027 transformState.flatten();
2029 return transformState.lastPlanarPoint();
2032 void RenderObject::mapLocalToContainer(RenderLayerModelObject* repaintContainer, TransformState& transformState, MapLocalToContainerFlags mode, bool* wasFixed) const
2034 if (repaintContainer == this)
2037 RenderObject* o = parent();
2041 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2042 LayoutPoint centerPoint = roundedLayoutPoint(transformState.mappedPoint());
2043 if (mode & ApplyContainerFlip && o->isBox()) {
2044 if (o->style()->isFlippedBlocksWritingMode())
2045 transformState.move(toRenderBox(o)->flipForWritingModeIncludingColumns(roundedLayoutPoint(transformState.mappedPoint())) - centerPoint);
2046 mode &= ~ApplyContainerFlip;
2049 LayoutSize columnOffset;
2050 o->adjustForColumns(columnOffset, roundedLayoutPoint(transformState.mappedPoint()));
2051 if (!columnOffset.isZero())
2052 transformState.move(columnOffset);
2054 if (o->hasOverflowClip())
2055 transformState.move(-toRenderBox(o)->scrolledContentOffset());
2057 o->mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2060 const RenderObject* RenderObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
2062 ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this);
2064 RenderObject* container = parent();
2068 // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called.
2070 if (container->hasOverflowClip())
2071 offset = -toRenderBox(container)->scrolledContentOffset();
2073 geometryMap.push(this, offset, hasColumns());
2078 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
2080 RenderObject* o = parent();
2082 o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
2083 if (o->hasOverflowClip())
2084 transformState.move(toRenderBox(o)->scrolledContentOffset());
2088 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
2090 #if ENABLE(3D_RENDERING)
2091 // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
2092 // so check the layer's transform directly.
2093 return (hasLayer() && toRenderLayerModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
2095 UNUSED_PARAM(containerObject);
2096 return hasTransform();
2100 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const
2102 transform.makeIdentity();
2103 transform.translate(offsetInContainer.width(), offsetInContainer.height());
2105 if (hasLayer() && (layer = toRenderLayerModelObject(this)->layer()) && layer->transform())
2106 transform.multiply(layer->currentTransform());
2108 #if ENABLE(3D_RENDERING)
2109 if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
2110 // Perpsective on the container affects us, so we have to factor it in here.
2111 ASSERT(containerObject->hasLayer());
2112 FloatPoint perspectiveOrigin = toRenderLayerModelObject(containerObject)->layer()->perspectiveOrigin();
2114 TransformationMatrix perspectiveMatrix;
2115 perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
2117 transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
2118 transform = perspectiveMatrix * transform;
2119 transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
2122 UNUSED_PARAM(containerObject);
2126 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderLayerModelObject* repaintContainer, bool snapOffsetForTransforms, bool fixed, bool* wasFixed) const
2128 // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(),
2129 // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks.
2130 TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad);
2131 MapLocalToContainerFlags mode = ApplyContainerFlip | UseTransforms;
2134 if (snapOffsetForTransforms)
2135 mode |= SnapOffsetForTransforms;
2136 mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2137 transformState.flatten();
2139 return transformState.lastPlanarQuad();
2142 FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, RenderLayerModelObject* repaintContainer, bool snapOffsetForTransforms, bool fixed, bool* wasFixed) const
2144 TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
2145 MapLocalToContainerFlags mode = ApplyContainerFlip | UseTransforms;
2148 if (snapOffsetForTransforms)
2149 mode |= SnapOffsetForTransforms;
2150 mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
2151 transformState.flatten();
2153 return transformState.lastPlanarPoint();
2156 LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
2158 ASSERT(o == container());
2162 o->adjustForColumns(offset, point);
2164 if (o->hasOverflowClip())
2165 offset -= toRenderBox(o)->scrolledContentOffset();
2167 if (offsetDependsOnPoint)
2168 *offsetDependsOnPoint = hasColumns();
2173 LayoutSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
2176 LayoutPoint referencePoint;
2177 const RenderObject* currContainer = this;
2179 RenderObject* nextContainer = currContainer->container();
2180 ASSERT(nextContainer); // This means we reached the top without finding container.
2183 ASSERT(!currContainer->hasTransform());
2184 LayoutSize currentOffset = currContainer->offsetFromContainer(nextContainer, referencePoint);
2185 offset += currentOffset;
2186 referencePoint.move(currentOffset);
2187 currContainer = nextContainer;
2188 } while (currContainer != container);
2193 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
2195 if (extraWidthToEndOfLine)
2196 *extraWidthToEndOfLine = 0;
2198 return LayoutRect();
2201 bool RenderObject::isRooted(RenderView** view) const
2203 const RenderObject* o = this;
2207 if (!o->isRenderView())
2211 *view = const_cast<RenderView*>(toRenderView(o));
2216 RenderObject* RenderObject::rendererForRootBackground()
2219 if (!hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) {
2220 // Locate the <body> element using the DOM. This is easier than trying
2221 // to crawl around a render tree with potential :before/:after content and
2222 // anonymous blocks created by inline <body> tags etc. We can locate the <body>
2223 // render object very easily via the DOM.
2224 HTMLElement* body = document()->body();
2225 RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
2233 RespectImageOrientationEnum RenderObject::shouldRespectImageOrientation() const
2235 // Respect the image's orientation if it's being used as a full-page image or it's
2236 // an <img> and the setting to respect it everywhere is set.
2237 return document()->isImageDocument() || (document()->settings() && document()->settings()->shouldRespectImageOrientation() && node() && (node()->hasTagName(HTMLNames::imgTag) || node()->hasTagName(HTMLNames::webkitInnerImageTag))) ? RespectImageOrientation : DoNotRespectImageOrientation;
2240 bool RenderObject::hasOutlineAnnotation() const
2242 return node() && node()->isLink() && document()->printing();
2245 RenderObject* RenderObject::container(const RenderLayerModelObject* repaintContainer, bool* repaintContainerSkipped) const
2247 if (repaintContainerSkipped)
2248 *repaintContainerSkipped = false;
2250 // This method is extremely similar to containingBlock(), but with a few notable
2252 // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2253 // the object is not part of the primary document subtree yet.
2254 // (2) For normal flow elements, it just returns the parent.
2255 // (3) For absolute positioned elements, it will return a relative positioned inline.
2256 // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2257 // the layout of the positioned object. This does mean that computePositionedLogicalWidth and
2258 // computePositionedLogicalHeight have to use container().
2259 RenderObject* o = parent();
2264 EPosition pos = m_style->position();
2265 if (pos == FixedPosition) {
2266 // container() can be called on an object that is not in the
2267 // tree yet. We don't call view() since it will assert if it
2268 // can't get back to the canvas. Instead we just walk as high up
2269 // as we can. If we're in the tree, we'll get the root. If we
2270 // aren't we'll get the root of our little subtree (most likely
2271 // we'll just return 0).
2272 // FIXME: The definition of view() has changed to not crawl up the render tree. It might
2273 // be safe now to use it.
2274 while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) {
2276 // foreignObject is the containing block for its contents.
2277 if (o->isSVGForeignObject())
2280 // The render flow thread is the top most containing block
2281 // for the fixed positioned elements.
2282 if (o->isRenderFlowThread())
2285 if (repaintContainerSkipped && o == repaintContainer)
2286 *repaintContainerSkipped = true;
2290 } else if (pos == AbsolutePosition) {
2291 // Same goes here. We technically just want our containing block, but
2292 // we may not have one if we're part of an uninstalled subtree. We'll
2293 // climb as high as we can though.
2294 while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
2296 if (o->isSVGForeignObject()) // foreignObject is the containing block for contents inside it
2299 if (repaintContainerSkipped && o == repaintContainer)
2300 *repaintContainerSkipped = true;
2309 bool RenderObject::isSelectionBorder() const
2311 SelectionState st = selectionState();
2312 return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2315 inline void RenderObject::clearLayoutRootIfNeeded() const
2317 if (!documentBeingDestroyed() && frame()) {
2318 if (FrameView* view = frame()->view()) {
2319 if (view->layoutRoot() == this) {
2320 ASSERT_NOT_REACHED();
2321 // This indicates a failure to layout the child, which is why
2322 // the layout root is still set to |this|. Make sure to clear it
2323 // since we are getting destroyed.
2324 view->clearLayoutRoot();
2330 void RenderObject::willBeDestroyed()
2332 // Destroy any leftover anonymous children.
2333 RenderObjectChildList* children = virtualChildren();
2335 children->destroyLeftoverChildren();
2337 // If this renderer is being autoscrolled, stop the autoscroll timer
2339 // FIXME: RenderObject::destroy should not get called with a renderer whose document
2340 // has a null frame, so we assert this. However, we don't want release builds to crash which is why we
2341 // check that the frame is not null.
2343 if (frame() && frame()->eventHandler()->autoscrollRenderer() == this)
2344 frame()->eventHandler()->stopAutoscrollTimer(true);
2346 if (AXObjectCache::accessibilityEnabled()) {
2347 document()->axObjectCache()->childrenChanged(this->parent());
2348 document()->axObjectCache()->remove(this);
2350 animation()->cancelAnimations(this);
2355 if (!documentBeingDestroyed() && view() && view()->hasRenderNamedFlowThreads()) {
2356 // After remove, the object and the associated information should not be in any flow thread.
2357 const RenderNamedFlowThreadList* flowThreadList = view()->flowThreadController()->renderNamedFlowThreadList();
2358 for (RenderNamedFlowThreadList::const_iterator iter = flowThreadList->begin(); iter != flowThreadList->end(); ++iter) {
2359 const RenderNamedFlowThread* renderFlowThread = *iter;
2360 ASSERT(!renderFlowThread->hasChild(this));
2361 ASSERT(!renderFlowThread->hasChildInfo(this));
2366 // If this renderer had a parent, remove should have destroyed any counters
2367 // attached to this renderer and marked the affected other counters for
2368 // reevaluation. This apparently redundant check is here for the case when
2369 // this renderer had no parent at the time remove() was called.
2371 if (hasCounterNodeMap())
2372 RenderCounter::destroyCounterNodes(this);
2374 // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
2375 // be moved into RenderBoxModelObject::destroy.
2378 toRenderLayerModelObject(this)->destroyLayer();
2381 setAncestorLineBoxDirty(false);
2383 clearLayoutRootIfNeeded();
2386 void RenderObject::insertedIntoTree()
2388 // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion.
2390 // Keep our layer hierarchy updated. Optimize for the common case where we don't have any children
2391 // and don't have a layer attached to ourselves.
2392 RenderLayer* layer = 0;
2393 if (firstChild() || hasLayer()) {
2394 layer = parent()->enclosingLayer();
2398 // If |this| is visible but this object was not, tell the layer it has some visible content
2399 // that needs to be drawn and layer visibility optimization can't be used
2400 if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
2402 layer = parent()->enclosingLayer();
2404 layer->setHasVisibleContent();
2407 if (!isFloating() && parent()->childrenInline())
2408 parent()->dirtyLinesFromChangedChild(this);
2410 if (RenderNamedFlowThread* containerFlowThread = parent()->enclosingRenderNamedFlowThread())
2411 containerFlowThread->addFlowChild(this);
2414 void RenderObject::willBeRemovedFromTree()
2416 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first.
2418 // If we remove a visible child from an invisible parent, we don't know the layer visibility any more.
2419 RenderLayer* layer = 0;
2420 if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
2421 if ((layer = parent()->enclosingLayer()))
2422 layer->dirtyVisibleContentStatus();
2425 // Keep our layer hierarchy updated.
2426 if (firstChild() || hasLayer()) {
2428 layer = parent()->enclosingLayer();
2429 removeLayers(layer);
2432 if (isOutOfFlowPositioned() && parent()->childrenInline())
2433 parent()->dirtyLinesFromChangedChild(this);
2435 if (inRenderFlowThread()) {
2436 ASSERT(enclosingRenderFlowThread());
2437 enclosingRenderFlowThread()->removeFlowChildInfo(this);
2440 if (RenderNamedFlowThread* containerFlowThread = parent()->enclosingRenderNamedFlowThread())
2441 containerFlowThread->removeFlowChild(this);
2444 // Update cached boundaries in SVG renderers, if a child is removed.
2445 parent()->setNeedsBoundariesUpdate();
2449 void RenderObject::destroyAndCleanupAnonymousWrappers()
2451 RenderObject* parent = this->parent();
2453 // If the tree is destroyed or our parent is not anonymous, there is no need for a clean-up phase.
2454 if (documentBeingDestroyed() || !parent || !parent->isAnonymous()) {
2459 bool parentIsLeftOverAnonymousWrapper = false;
2461 // Currently we only remove anonymous cells' wrapper but we should remove all unneeded
2462 // wrappers. See http://webkit.org/b/52123 as an example where this is needed.
2463 if (parent->isTableCell())
2464 parentIsLeftOverAnonymousWrapper = parent->firstChild() == this && parent->lastChild() == this;
2468 // WARNING: |this| is deleted here.
2470 if (parentIsLeftOverAnonymousWrapper) {
2471 ASSERT(!parent->firstChild());
2472 parent->destroyAndCleanupAnonymousWrappers();
2476 void RenderObject::destroy()
2479 arenaDelete(renderArena(), this);
2482 void RenderObject::arenaDelete(RenderArena* arena, void* base)
2485 for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2486 if (StyleImage* backgroundImage = bgLayer->image())
2487 backgroundImage->removeClient(this);
2490 for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
2491 if (StyleImage* maskImage = maskLayer->image())
2492 maskImage->removeClient(this);
2495 if (StyleImage* borderImage = m_style->borderImage().image())
2496 borderImage->removeClient(this);
2498 if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
2499 maskBoxImage->removeClient(this);
2503 void* savedBase = baseOfRenderObjectBeingDeleted;
2504 baseOfRenderObjectBeingDeleted = base;
2508 baseOfRenderObjectBeingDeleted = savedBase;
2511 // Recover the size left there for us by operator delete and free the memory.
2512 arena->free(*(size_t*)base, base);
2515 VisiblePosition RenderObject::positionForPoint(const LayoutPoint&)
2517 return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
2520 void RenderObject::updateDragState(bool dragOn)
2522 bool valueChanged = (dragOn != isDragging());
2523 setIsDragging(dragOn);
2524 if (valueChanged && style()->affectedByDragRules() && node())
2525 node()->setNeedsStyleRecalc();
2526 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2527 curr->updateDragState(dragOn);
2530 bool RenderObject::isComposited() const
2532 return hasLayer() && toRenderLayerModelObject(this)->layer()->isComposited();
2535 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter)
2537 bool inside = false;
2538 if (hitTestFilter != HitTestSelf) {
2539 // First test the foreground layer (lines and inlines).
2540 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestForeground);
2542 // Test floats next.
2544 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestFloat);
2546 // Finally test to see if the mouse is in the background (within a child block's background).
2548 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestChildBlockBackgrounds);
2551 // See if the mouse is inside us but not any of our descendants
2552 if (hitTestFilter != HitTestDescendants && !inside)
2553 inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestBlockBackground);
2558 void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
2560 if (result.innerNode())
2565 result.setInnerNode(n);
2566 if (!result.innerNonSharedNode())
2567 result.setInnerNonSharedNode(n);
2568 result.setLocalPoint(point);
2572 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& /*locationInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction)
2577 void RenderObject::scheduleRelayout()
2579 if (isRenderView()) {
2580 FrameView* view = toRenderView(this)->frameView();
2582 view->scheduleRelayout();
2585 if (RenderView* renderView = view()) {
2586 if (FrameView* frameView = renderView->frameView())
2587 frameView->scheduleRelayoutOfSubtree(this);
2593 void RenderObject::layout()
2595 ASSERT(needsLayout());
2596 RenderObject* child = firstChild();
2598 child->layoutIfNeeded();
2599 ASSERT(!child->needsLayout());
2600 child = child->nextSibling();
2602 setNeedsLayout(false);
2605 enum StyleCacheState {
2610 static PassRefPtr<RenderStyle> firstLineStyleForCachedUncachedType(StyleCacheState type, const RenderObject* renderer, RenderStyle* style)
2612 const RenderObject* rendererForFirstLineStyle = renderer;
2613 if (renderer->isBeforeOrAfterContent())
2614 rendererForFirstLineStyle = renderer->parent();
2616 if (rendererForFirstLineStyle->isBlockFlow()) {
2617 if (RenderBlock* firstLineBlock = rendererForFirstLineStyle->firstLineBlock()) {
2619 return firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
2620 return firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == renderer ? style : 0);
2622 } else if (!rendererForFirstLineStyle->isAnonymous() && rendererForFirstLineStyle->isRenderInline()) {
2623 RenderStyle* parentStyle = rendererForFirstLineStyle->parent()->firstLineStyle();
2624 if (parentStyle != rendererForFirstLineStyle->parent()->style()) {
2625 if (type == Cached) {
2626 // A first-line style is in effect. Cache a first-line style for ourselves.
2627 rendererForFirstLineStyle->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
2628 return rendererForFirstLineStyle->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
2630 return rendererForFirstLineStyle->getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
2636 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
2638 if (!document()->styleSheetCollection()->usesFirstLineRules())
2643 return firstLineStyleForCachedUncachedType(Uncached, this, style);
2646 RenderStyle* RenderObject::firstLineStyleSlowCase() const
2648 ASSERT(document()->styleSheetCollection()->usesFirstLineRules());
2650 if (RefPtr<RenderStyle> style = firstLineStyleForCachedUncachedType(Cached, isText() ? parent() : this, m_style.get()))
2653 return m_style.get();
2656 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
2658 if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
2661 RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
2665 RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
2667 return style()->addCachedPseudoStyle(result.release());
2671 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
2673 if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
2678 parentStyle = style();
2681 // FIXME: This "find nearest element parent" should be a helper function.
2683 while (n && !n->isElementNode())
2684 n = n->parentNode();
2687 Element* element = toElement(n);
2689 if (pseudo == FIRST_LINE_INHERITED) {
2690 RefPtr<RenderStyle> result = document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
2691 result->setStyleType(FIRST_LINE_INHERITED);
2692 return result.release();
2694 return document()->styleResolver()->pseudoStyleForElement(pseudo, element, parentStyle);
2697 static Color decorationColor(RenderStyle* style)
2700 if (style->textStrokeWidth() > 0) {
2701 // Prefer stroke color if possible but not if it's fully transparent.
2702 result = style->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
2707 result = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
2711 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2712 Color& linethrough, bool quirksMode, bool firstlineStyle)
2714 RenderObject* curr = this;
2715 RenderStyle* styleToUse = 0;
2717 styleToUse = curr->style(firstlineStyle);
2718 int currDecs = styleToUse->textDecoration();
2720 if (currDecs & UNDERLINE) {
2721 decorations &= ~UNDERLINE;
2722 underline = decorationColor(styleToUse);
2724 if (currDecs & OVERLINE) {
2725 decorations &= ~OVERLINE;
2726 overline = decorationColor(styleToUse);
2728 if (currDecs & LINE_THROUGH) {
2729 decorations &= ~LINE_THROUGH;
2730 linethrough = decorationColor(styleToUse);
2733 if (curr->isRubyText())
2735 curr = curr->parent();
2736 if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
2737 curr = toRenderBlock(curr)->continuation();
2738 } while (curr && decorations && (!quirksMode || !curr->node() ||
2739 (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
2741 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2742 if (decorations && curr) {
2743 styleToUse = curr->style(firstlineStyle);
2744 if (decorations & UNDERLINE)
2745 underline = decorationColor(styleToUse);
2746 if (decorations & OVERLINE)
2747 overline = decorationColor(styleToUse);
2748 if (decorations & LINE_THROUGH)
2749 linethrough = decorationColor(styleToUse);
2753 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
2754 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2756 // Convert the style regions to absolute coordinates.
2757 if (style()->visibility() != VISIBLE || !isBox())
2760 RenderBox* box = toRenderBox(this);
2762 const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2763 unsigned i, count = styleRegions.size();
2764 for (i = 0; i < count; i++) {
2765 StyleDashboardRegion styleRegion = styleRegions[i];
2767 LayoutUnit w = box->width();
2768 LayoutUnit h = box->height();
2770 DashboardRegionValue region;
2771 region.label = styleRegion.label;
2772 region.bounds = LayoutRect(styleRegion.offset.left().value(),
2773 styleRegion.offset.top().value(),
2774 w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
2775 h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
2776 region.type = styleRegion.type;
2778 region.clip = region.bounds;
2779 computeAbsoluteRepaintRect(region.clip);
2780 if (region.clip.height() < 0) {
2781 region.clip.setHeight(0);
2782 region.clip.setWidth(0);
2785 FloatPoint absPos = localToAbsolute();
2786 region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
2787 region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
2789 regions.append(region);
2793 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2795 // RenderTexts don't have their own style, they just use their parent's style,
2796 // so we don't want to include them.
2800 addDashboardRegions(regions);
2801 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2802 curr->collectDashboardRegions(regions);
2806 bool RenderObject::willRenderImage(CachedImage*)
2808 // Without visibility we won't render (and therefore don't care about animation).
2809 if (style()->visibility() != VISIBLE)
2812 // We will not render a new image when Active DOM is suspended
2813 if (document()->activeDOMObjectsAreSuspended())
2816 // 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)
2817 // then we don't want to render either.
2818 return !document()->inPageCache() && !document()->view()->isOffscreen();
2821 int RenderObject::maximalOutlineSize(PaintPhase p) const
2823 if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2825 return toRenderView(document()->renderer())->maximalOutlineSize();
2828 int RenderObject::caretMinOffset() const
2833 int RenderObject::caretMaxOffset() const
2836 return node() ? max(1U, node()->childNodeCount()) : 1;
2842 int RenderObject::previousOffset(int current) const
2847 int RenderObject::previousOffsetForBackwardDeletion(int current) const
2852 int RenderObject::nextOffset(int current) const
2857 void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const
2859 int outlineSize = outlineStyleForRepaint()->outlineSize();
2860 if (const ShadowData* boxShadow = style()->boxShadow()) {
2861 boxShadow->adjustRectForShadow(rect, outlineSize);
2865 rect.inflate(outlineSize);
2868 AnimationController* RenderObject::animation() const
2870 return frame()->animation();
2873 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
2875 imageChanged(static_cast<WrappedImagePtr>(image), rect);
2878 RenderBoxModelObject* RenderObject::offsetParent() const
2880 // If any of the following holds true return null and stop this algorithm:
2881 // A is the root element.
2882 // A is the HTML body element.
2883 // The computed value of the position property for element A is fixed.
2884 if (isRoot() || isBody() || (isOutOfFlowPositioned() && style()->position() == FixedPosition))
2887 // If A is an area HTML element which has a map HTML element somewhere in the ancestor
2888 // chain return the nearest ancestor map HTML element and stop this algorithm.
2889 // FIXME: Implement!
2891 // Return the nearest ancestor element of A for which at least one of the following is
2892 // true and stop this algorithm if such an ancestor is found:
2893 // * The computed value of the position property is not static.
2894 // * It is the HTML body element.
2895 // * The computed value of the position property of A is static and the ancestor
2896 // is one of the following HTML elements: td, th, or table.
2897 // * Our own extension: if there is a difference in the effective zoom
2899 bool skipTables = isPositioned();
2900 float currZoom = style()->effectiveZoom();
2901 RenderObject* curr = parent();
2902 while (curr && (!curr->node() || (!curr->isPositioned() && !curr->isBody()))) {
2903 Node* element = curr->node();
2904 if (!skipTables && element && (element->hasTagName(tableTag) || element->hasTagName(tdTag) || element->hasTagName(thTag)))
2907 float newZoom = curr->style()->effectiveZoom();
2908 if (currZoom != newZoom)
2911 curr = curr->parent();
2913 return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
2916 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
2918 // If this is a non-anonymous renderer in an editable area, then it's simple.
2919 if (Node* node = this->node()) {
2920 if (!node->rendererIsEditable()) {
2921 // If it can be found, we prefer a visually equivalent position that is editable.
2922 Position position = createLegacyEditingPosition(node, offset);
2923 Position candidate = position.downstream(CanCrossEditingBoundary);
2924 if (candidate.deprecatedNode()->rendererIsEditable())
2925 return VisiblePosition(candidate, affinity);
2926 candidate = position.upstream(CanCrossEditingBoundary);
2927 if (candidate.deprecatedNode()->rendererIsEditable())
2928 return VisiblePosition(candidate, affinity);
2930 // FIXME: Eliminate legacy editing positions
2931 return VisiblePosition(createLegacyEditingPosition(node, offset), affinity);
2934 // We don't want to cross the boundary between editable and non-editable
2935 // regions of the document, but that is either impossible or at least
2936 // extremely unlikely in any normal case because we stop as soon as we
2937 // find a single non-anonymous renderer.
2939 // Find a nearby non-anonymous renderer.
2940 RenderObject* child = this;
2941 while (RenderObject* parent = child->parent()) {
2942 // Find non-anonymous content after.
2943 RenderObject* renderer = child;
2944 while ((renderer = renderer->nextInPreOrder(parent))) {
2945 if (Node* node = renderer->node())
2946 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2949 // Find non-anonymous content before.
2951 while ((renderer = renderer->previousInPreOrder())) {
2952 if (renderer == parent)
2954 if (Node* node = renderer->node())
2955 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
2958 // Use the parent itself unless it too is anonymous.
2959 if (Node* node = parent->node())
2960 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
2962 // Repeat at the next level up.
2966 // Everything was anonymous. Give up.
2967 return VisiblePosition();
2970 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
2972 if (position.isNotNull())
2973 return VisiblePosition(position);
2976 return createVisiblePosition(0, DOWNSTREAM);
2979 CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
2981 return SetCursorBasedOnStyle;
2984 bool RenderObject::canUpdateSelectionOnRootLineBoxes()
2989 RenderBlock* containingBlock = this->containingBlock();
2990 return containingBlock ? !containingBlock->needsLayout() : true;
2993 // We only create "generated" child renderers like one for first-letter if:
2994 // - the firstLetterBlock can have children in the DOM and
2995 // - the block doesn't have any special assumption on its text children.
2996 // This correctly prevents form controls from having such renderers.
2997 bool RenderObject::canHaveGeneratedChildren() const
2999 return canHaveChildren();
3002 bool RenderObject::canBeReplacedWithInlineRunIn() const
3009 RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
3011 ASSERT_NOT_REACHED();
3015 void RenderObject::setNeedsBoundariesUpdate()
3017 if (RenderObject* renderer = parent())
3018 renderer->setNeedsBoundariesUpdate();
3021 FloatRect RenderObject::objectBoundingBox() const
3023 ASSERT_NOT_REACHED();
3027 FloatRect RenderObject::strokeBoundingBox() const
3029 ASSERT_NOT_REACHED();
3033 // Returns the smallest rectangle enclosing all of the painted content
3034 // respecting clipping, masking, filters, opacity, stroke-width and markers
3035 FloatRect RenderObject::repaintRectInLocalCoordinates() const
3037 ASSERT_NOT_REACHED();
3041 AffineTransform RenderObject::localTransform() const
3043 static const AffineTransform identity;
3047 const AffineTransform& RenderObject::localToParentTransform() const
3049 static const AffineTransform identity;
3053 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
3055 ASSERT_NOT_REACHED();
3059 #endif // ENABLE(SVG)
3061 } // namespace WebCore
3065 void showTree(const WebCore::RenderObject* object)
3068 object->showTreeForThis();
3071 void showLineTree(const WebCore::RenderObject* object)
3074 object->showLineTreeForThis();
3077 void showRenderTree(const WebCore::RenderObject* object1)
3079 showRenderTree(object1, 0);
3082 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
3085 const WebCore::RenderObject* root = object1;
3086 while (root->parent())
3087 root = root->parent();
3088 root->showRenderTreeAndMark(object1, "*", object2, "-", 0);