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 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include "RenderObject.h"
28 #include "AXObjectCache.h"
29 #include "AffineTransform.h"
30 #include "CachedImage.h"
34 #include "EventHandler.h"
35 #include "EventNames.h"
36 #include "FloatRect.h"
38 #include "FrameView.h"
39 #include "GraphicsContext.h"
40 #include "HTMLNames.h"
41 #include "HTMLOListElement.h"
42 #include "HitTestRequest.h"
43 #include "HitTestResult.h"
47 #include "RenderArena.h"
48 #include "RenderCounter.h"
49 #include "RenderFlexibleBox.h"
50 #include "RenderImage.h"
51 #include "RenderInline.h"
52 #include "RenderListItem.h"
53 #include "RenderTableCell.h"
54 #include "RenderTableCol.h"
55 #include "RenderTableRow.h"
56 #include "RenderText.h"
57 #include "RenderTheme.h"
58 #include "RenderView.h"
60 #include "TextResourceDecoder.h"
61 #include "TextStream.h"
62 #include "cssstyleselector.h"
69 using namespace EventNames;
70 using namespace HTMLNames;
73 static void* baseOfRenderObjectBeingDeleted;
76 void* RenderObject::operator new(size_t sz, RenderArena* renderArena) throw()
78 return renderArena->allocate(sz);
81 void RenderObject::operator delete(void* ptr, size_t sz)
83 ASSERT(baseOfRenderObjectBeingDeleted == ptr);
85 // Stash size where destroy can find it.
89 RenderObject* RenderObject::createObject(Node* node, RenderStyle* style)
91 RenderArena* arena = node->document()->renderArena();
93 // Minimal support for content properties replacing an entire element.
94 // Works only if we have exactly one piece of content and it's a URL.
95 // Otherwise acts as if we didn't support this feature.
96 const ContentData* contentData = style->contentData();
97 if (contentData && !contentData->m_next && contentData->m_type == CONTENT_OBJECT) {
98 RenderImage* image = new (arena) RenderImage(node);
99 image->setStyle(style);
100 if (CachedResource* resource = contentData->m_content.m_object)
101 if (resource->type() == CachedResource::ImageResource)
102 image->setCachedImage(static_cast<CachedImage*>(resource));
103 image->setIsAnonymousImage(true);
109 switch (style->display()) {
113 o = new (arena) RenderInline(node);
116 o = new (arena) RenderBlock(node);
119 o = new (arena) RenderBlock(node);
122 o = new (arena) RenderListItem(node);
126 o = new (arena) RenderBlock(node);
130 o = new (arena) RenderTable(node);
132 case TABLE_ROW_GROUP:
133 case TABLE_HEADER_GROUP:
134 case TABLE_FOOTER_GROUP:
135 o = new (arena) RenderTableSection(node);
138 o = new (arena) RenderTableRow(node);
140 case TABLE_COLUMN_GROUP:
142 o = new (arena) RenderTableCol(node);
145 o = new (arena) RenderTableCell(node);
148 o = new (arena) RenderBlock(node);
152 o = new (arena) RenderFlexibleBox(node);
160 struct RenderObjectCounter {
162 ~RenderObjectCounter() { if (count != 0) fprintf(stderr, "LEAK: %d RenderObject\n", count); }
164 int RenderObjectCounter::count;
165 static RenderObjectCounter renderObjectCounter;
168 RenderObject::RenderObject(Node* node)
169 : CachedResourceClient()
175 , m_verticalPosition(PositionUndefined)
176 , m_needsLayout(false)
177 , m_normalChildNeedsLayout(false)
178 , m_posChildNeedsLayout(false)
179 , m_minMaxKnown(false)
181 , m_positioned(false)
182 , m_relPositioned(false)
183 , m_paintBackground(false)
184 , m_isAnonymous(node == node->document())
185 , m_recalcMinMax(false)
189 , m_isDragging(false)
190 , m_hasOverflowClip(false)
191 , m_hasCounterNodeMap(false)
194 ++RenderObjectCounter::count;
198 RenderObject::~RenderObject()
201 --RenderObjectCounter::count;
205 bool RenderObject::isDescendantOf(const RenderObject* obj) const
207 for (const RenderObject* r = this; r; r = r->m_parent) {
214 bool RenderObject::isRoot() const
216 return element() && element()->renderer() == this && element()->document()->documentElement() == element();
219 bool RenderObject::isBody() const
221 return element() && element()->renderer() == this && element()->hasTagName(bodyTag);
224 bool RenderObject::isHR() const
226 return element() && element()->hasTagName(hrTag);
229 bool RenderObject::isHTMLMarquee() const
231 return element() && element()->renderer() == this && element()->hasTagName(marqueeTag);
234 bool RenderObject::canHaveChildren() const
239 RenderFlow* RenderObject::continuation() const
244 bool RenderObject::isInlineContinuation() const
249 void RenderObject::addChild(RenderObject*, RenderObject*)
251 ASSERT_NOT_REACHED();
254 RenderObject* RenderObject::removeChildNode(RenderObject*)
256 ASSERT_NOT_REACHED();
260 void RenderObject::removeChild(RenderObject*)
262 ASSERT_NOT_REACHED();
265 void RenderObject::appendChildNode(RenderObject*)
267 ASSERT_NOT_REACHED();
270 void RenderObject::insertChildNode(RenderObject*, RenderObject*)
272 ASSERT_NOT_REACHED();
275 RenderObject* RenderObject::nextInPreOrder() const
277 if (RenderObject* o = firstChild())
280 return nextInPreOrderAfterChildren();
283 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
286 if (!(o = nextSibling())) {
288 while (o && !o->nextSibling())
291 o = o->nextSibling();
297 RenderObject* RenderObject::nextInPreOrder(RenderObject* stayWithin) const
299 if (RenderObject* o = firstChild())
302 return nextInPreOrderAfterChildren(stayWithin);
305 RenderObject* RenderObject::nextInPreOrderAfterChildren(RenderObject* stayWithin) const
307 if (this == stayWithin)
311 if (!(o = nextSibling())) {
313 while (o && !o->nextSibling()) {
319 o = o->nextSibling();
325 RenderObject* RenderObject::previousInPreOrder() const
327 if (RenderObject* o = previousSibling()) {
328 while (o->lastChild())
336 RenderObject* RenderObject::childAt(unsigned index) const
338 RenderObject* child = firstChild();
339 for (unsigned i = 0; child && i < index; i++)
340 child = child->nextSibling();
344 bool RenderObject::isEditable() const
346 RenderText* textRenderer = 0;
348 textRenderer = static_cast<RenderText*>(const_cast<RenderObject*>(this));
350 return style()->visibility() == VISIBLE &&
351 element() && element()->isContentEditable() &&
352 ((isBlockFlow() && !firstChild()) ||
355 (textRenderer && textRenderer->firstTextBox()));
358 RenderObject* RenderObject::firstLeafChild() const
360 RenderObject* r = firstChild();
371 RenderObject* RenderObject::lastLeafChild() const
373 RenderObject* r = lastChild();
384 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
385 RenderLayer*& beforeChild)
388 if (!beforeChild && newObject) {
389 // We need to figure out the layer that follows newObject. We only do
390 // this the first time we find a child layer, and then we update the
391 // pointer values for newObject and beforeChild used by everyone else.
392 beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
395 parentLayer->addChild(obj->layer(), beforeChild);
399 for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
400 addLayers(curr, parentLayer, newObject, beforeChild);
403 void RenderObject::addLayers(RenderLayer* parentLayer, RenderObject* newObject)
408 RenderObject* object = newObject;
409 RenderLayer* beforeChild = 0;
410 WebCore::addLayers(this, parentLayer, object, beforeChild);
413 void RenderObject::removeLayers(RenderLayer* parentLayer)
419 parentLayer->removeChild(layer());
423 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
424 curr->removeLayers(parentLayer);
427 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
434 oldParent->removeChild(layer());
435 newParent->addChild(layer());
439 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
440 curr->moveLayers(oldParent, newParent);
443 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
446 // Error check the parent layer passed in. If it's null, we can't find anything.
450 // Step 1: If our layer is a child of the desired parent, then return our layer.
451 RenderLayer* ourLayer = layer();
452 if (ourLayer && ourLayer->parent() == parentLayer)
455 // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
456 // into our siblings trying to find the next layer whose parent is the desired parent.
457 if (!ourLayer || ourLayer == parentLayer) {
458 for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
459 curr; curr = curr->nextSibling()) {
460 RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
466 // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
468 if (parentLayer == ourLayer)
471 // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
472 // follow us to see if we can locate a layer.
473 if (checkParent && parent())
474 return parent()->findNextLayer(parentLayer, this, true);
479 RenderLayer* RenderObject::enclosingLayer() const
481 const RenderObject* curr = this;
483 RenderLayer* layer = curr->layer();
486 curr = curr->parent();
491 bool RenderObject::requiresLayer()
493 return isRoot() || isPositioned() || isRelPositioned() || isTransparent() || hasOverflowClip();
496 RenderBlock* RenderObject::firstLineBlock() const
501 void RenderObject::updateFirstLetter()
505 int RenderObject::offsetLeft() const
507 RenderObject* offsetPar = offsetParent();
510 int x = xPos() - offsetPar->borderLeft();
511 if (!isPositioned()) {
512 if (isRelPositioned())
513 x += static_cast<const RenderBox*>(this)->relativePositionOffsetX();
514 RenderObject* curr = parent();
515 while (curr && curr != offsetPar) {
517 curr = curr->parent();
519 if (offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned())
520 x += offsetPar->xPos();
525 int RenderObject::offsetTop() const
527 RenderObject* offsetPar = offsetParent();
530 int y = yPos() - offsetPar->borderTop();
531 if (!isPositioned()) {
532 if (isRelPositioned())
533 y += static_cast<const RenderBox*>(this)->relativePositionOffsetY();
534 RenderObject* curr = parent();
535 while (curr && curr != offsetPar) {
536 if (!curr->isTableRow())
538 curr = curr->parent();
540 if (offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned())
541 y += offsetPar->yPos();
546 RenderObject* RenderObject::offsetParent() const
548 // FIXME: It feels like this function could almost be written using containing blocks.
552 bool skipTables = isPositioned() || isRelPositioned();
553 RenderObject* curr = parent();
554 while (curr && (!curr->element() ||
555 (!curr->isPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
556 if (!skipTables && curr->element() && (curr->element()->hasTagName(tableTag) ||
557 curr->element()->hasTagName(tdTag) || curr->element()->hasTagName(thTag)))
559 curr = curr->parent();
564 int RenderObject::verticalScrollbarWidth() const
566 return includeVerticalScrollbarSize() ? layer()->verticalScrollbarWidth() : 0;
569 int RenderObject::horizontalScrollbarHeight() const
571 return includeHorizontalScrollbarSize() ? layer()->horizontalScrollbarHeight() : 0;
574 // More IE extensions. clientWidth and clientHeight represent the interior of an object
575 // excluding border and scrollbar.
576 int RenderObject::clientWidth() const
578 return width() - borderLeft() - borderRight() - verticalScrollbarWidth();
581 int RenderObject::clientHeight() const
583 return height() - borderTop() - borderBottom() - horizontalScrollbarHeight();
586 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
587 // object has overflow:hidden/scroll/auto specified and also has overflow.
588 int RenderObject::scrollWidth() const
590 return hasOverflowClip() ? layer()->scrollWidth() : overflowWidth();
593 int RenderObject::scrollHeight() const
595 return hasOverflowClip() ? layer()->scrollHeight() : overflowHeight();
598 int RenderObject::scrollLeft() const
600 return hasOverflowClip() ? layer()->scrollXOffset() : 0;
603 int RenderObject::scrollTop() const
605 return hasOverflowClip() ? layer()->scrollYOffset() : 0;
608 void RenderObject::setScrollLeft(int newLeft)
610 if (hasOverflowClip())
611 layer()->scrollToXOffset(newLeft);
614 void RenderObject::setScrollTop(int newTop)
616 if (hasOverflowClip())
617 layer()->scrollToYOffset(newTop);
620 bool RenderObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier)
622 RenderLayer* l = layer();
623 if (l && l->scroll(direction, granularity, multiplier))
625 RenderBlock* b = containingBlock();
626 if (b && !b->isRenderView())
627 return b->scroll(direction, granularity, multiplier);
631 bool RenderObject::shouldAutoscroll() const
633 return ((isRoot()) || (hasOverflowClip() && (scrollsOverflow() || (node() && node()->isContentEditable()))));
636 void RenderObject::autoscroll()
638 if (RenderLayer* l = layer())
642 bool RenderObject::hasStaticX() const
644 return (style()->left().isAuto() && style()->right().isAuto()) || style()->left().isStatic() || style()->right().isStatic();
647 bool RenderObject::hasStaticY() const
649 return (style()->top().isAuto() && style()->bottom().isAuto()) || style()->top().isStatic();
652 void RenderObject::markAllDescendantsWithFloatsForLayout(RenderObject*)
656 void RenderObject::setNeedsLayout(bool b, bool markParents)
658 bool alreadyNeededLayout = m_needsLayout;
661 if (!alreadyNeededLayout && markParents)
662 markContainingBlocksForLayout();
664 m_posChildNeedsLayout = false;
665 m_normalChildNeedsLayout = false;
669 void RenderObject::setChildNeedsLayout(bool b, bool markParents)
671 bool alreadyNeededLayout = m_normalChildNeedsLayout;
672 m_normalChildNeedsLayout = b;
674 if (!alreadyNeededLayout && markParents)
675 markContainingBlocksForLayout();
677 m_posChildNeedsLayout = false;
678 m_normalChildNeedsLayout = false;
682 void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout)
684 RenderObject* o = container();
685 RenderObject* last = this;
688 if (!last->isText() && (last->style()->position() == FixedPosition || last->style()->position() == AbsolutePosition)) {
689 if (last->hasStaticY())
690 last->parent()->setChildNeedsLayout(true);
691 if (o->m_posChildNeedsLayout)
693 o->m_posChildNeedsLayout = true;
695 if (o->m_normalChildNeedsLayout)
697 o->m_normalChildNeedsLayout = true;
701 if (scheduleRelayout && (last->isTextField() || last->isTextArea()))
706 if (scheduleRelayout)
707 last->scheduleRelayout();
710 RenderBlock* RenderObject::containingBlock() const
713 return static_cast<const RenderTableCell*>(this)->table();
715 return (RenderBlock*)this;
717 RenderObject* o = parent();
718 if (!isText() && m_style->position() == FixedPosition) {
719 while ( o && !o->isRenderView() )
721 } else if (!isText() && m_style->position() == AbsolutePosition) {
722 while (o && (o->style()->position() == StaticPosition || (o->isInline() && !o->isReplaced())) && !o->isRenderView()) {
723 // For relpositioned inlines, we return the nearest enclosing block. We don't try
724 // to return the inline itself. This allows us to avoid having a positioned objects
725 // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
726 // from this method. The container() method can actually be used to obtain the
728 if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced())
729 return o->containingBlock();
733 while (o && ((o->isInline() && !o->isReplaced()) || o->isTableRow() || o->isTableSection()
734 || o->isTableCol() || o->isFrameSet()
736 || o->isSVGContainer()
742 if (!o || !o->isRenderBlock())
743 return 0; // Probably doesn't happen any more, but leave just in case. -dwh
745 return static_cast<RenderBlock*>(o);
748 int RenderObject::containingBlockWidth() const
751 return containingBlock()->availableWidth();
754 int RenderObject::containingBlockHeight() const
757 return containingBlock()->contentHeight();
760 bool RenderObject::mustRepaintBackgroundOrBorder() const
762 // If we don't have a background/border, then nothing to do.
763 if (!hasBoxDecorations())
766 // Ok, let's check the background first.
767 const BackgroundLayer* bgLayer = style()->backgroundLayers();
769 // Nobody will use multiple background layers without wanting fancy positioning.
773 // Make sure we have a valid background image.
774 CachedImage* bg = bgLayer->backgroundImage();
775 bool shouldPaintBackgroundImage = bg && bg->canRender();
777 // These are always percents or auto.
778 if (shouldPaintBackgroundImage &&
779 (!bgLayer->backgroundXPosition().isZero() || !bgLayer->backgroundYPosition().isZero() ||
780 bgLayer->backgroundSize().width.isPercent() || bgLayer->backgroundSize().height.isPercent()))
781 // The background image will shift unpredictably if the size changes.
784 // Background is ok. Let's check border.
785 if (style()->hasBorder()) {
786 // Border images are not ok.
787 CachedImage* borderImage = style()->borderImage().image();
788 bool shouldPaintBorderImage = borderImage && borderImage->canRender();
790 // If the image hasn't loaded, we're still using the normal border style.
791 if (shouldPaintBorderImage && borderImage->isLoaded())
798 void RenderObject::drawBorderArc(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius,
799 int angleStart, int angleSpan, BorderSide s, Color c, const Color& textColor,
800 EBorderStyle style, bool firstCorner)
802 if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2))
806 if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
807 c.setRGB(238, 238, 238);
818 graphicsContext->setStrokeColor(c);
819 graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke);
820 graphicsContext->setStrokeThickness(thickness);
821 graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
824 float third = thickness / 3.0f;
825 float innerThird = (thickness + 1.0f) / 6.0f;
826 int shiftForInner = static_cast<int>(innerThird * 2.5f);
829 int outerHeight = radius.height() * 2;
830 int innerX = x + shiftForInner;
831 int innerY = y + shiftForInner;
832 int innerWidth = (radius.width() - shiftForInner) * 2;
833 int innerHeight = (radius.height() - shiftForInner) * 2;
834 if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) {
839 graphicsContext->setStrokeStyle(SolidStroke);
840 graphicsContext->setStrokeColor(c);
841 graphicsContext->setStrokeThickness(third);
842 graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan);
843 graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird);
844 graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan);
850 if ((style == RIDGE && (s == BSTop || s == BSLeft)) ||
851 (style == GROOVE && (s == BSBottom || s == BSRight)))
858 graphicsContext->setStrokeStyle(SolidStroke);
859 graphicsContext->setStrokeColor(c);
860 graphicsContext->setStrokeThickness(thickness);
861 graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
863 float halfThickness = (thickness + 1.0f) / 4.0f;
864 int shiftForInner = static_cast<int>(halfThickness * 1.5f);
865 graphicsContext->setStrokeColor(c2);
866 graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness);
867 graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2,
868 (radius.height() - shiftForInner) * 2), angleStart, angleSpan);
872 if (s == BSTop || s == BSLeft)
875 if (style == OUTSET && (s == BSBottom || s == BSRight))
878 graphicsContext->setStrokeStyle(SolidStroke);
879 graphicsContext->setStrokeColor(c);
880 graphicsContext->setStrokeThickness(thickness);
881 graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
886 void RenderObject::drawBorder(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
887 BorderSide s, Color c, const Color& textcolor, EBorderStyle style,
888 int adjbw1, int adjbw2)
890 int width = (s == BSTop || s == BSBottom ? y2 - y1 : x2 - x1);
892 if (style == DOUBLE && width < 3)
896 if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
897 c.setRGB(238, 238, 238);
908 graphicsContext->setStrokeColor(c);
909 graphicsContext->setStrokeThickness(width);
910 graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
916 graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
920 graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
925 int third = (width + 1) / 3;
927 if (adjbw1 == 0 && adjbw2 == 0) {
928 graphicsContext->setStrokeStyle(NoStroke);
929 graphicsContext->setFillColor(c);
933 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third));
934 graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third));
937 graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
938 graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
941 graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
942 graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
946 int adjbw1bigthird = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 3;
947 int adjbw2bigthird = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 3;
951 drawBorder(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
952 y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third,
953 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
954 drawBorder(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
955 y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2,
956 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
959 drawBorder(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
960 x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
961 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
962 drawBorder(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0),
963 x2, y2 - max((adjbw2 * 2 + 1) / 3, 0),
964 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
967 drawBorder(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
968 y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third,
969 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
970 drawBorder(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
971 y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2,
972 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
975 drawBorder(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0),
976 x1 + third, y2 - max(( adjbw2 * 2 + 1) / 3, 0),
977 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
978 drawBorder(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
979 x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
980 s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
993 if (style == GROOVE) {
1001 int adjbw1bighalf = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 2;
1002 int adjbw2bighalf = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 2;
1006 drawBorder(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
1007 s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
1008 drawBorder(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2,
1009 s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
1012 drawBorder(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2,
1013 s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
1014 drawBorder(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2,
1015 s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
1018 drawBorder(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
1019 s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
1020 drawBorder(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2,
1021 s, c, textcolor, s1, adjbw1/2, adjbw2/2);
1024 drawBorder(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2,
1025 s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
1026 drawBorder(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2,
1027 s, c, textcolor, s1, adjbw1/2, adjbw2/2);
1033 if (s == BSTop || s == BSLeft)
1037 if (style == OUTSET && (s == BSBottom || s == BSRight))
1041 graphicsContext->setStrokeStyle(NoStroke);
1042 graphicsContext->setFillColor(c);
1045 if (!adjbw1 && !adjbw2) {
1046 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
1052 quad[0] = FloatPoint(x1 + max(-adjbw1, 0), y1);
1053 quad[1] = FloatPoint(x1 + max(adjbw1, 0), y2);
1054 quad[2] = FloatPoint(x2 - max(adjbw2, 0), y2);
1055 quad[3] = FloatPoint(x2 - max(-adjbw2, 0), y1);
1058 quad[0] = FloatPoint(x1 + max(adjbw1, 0), y1);
1059 quad[1] = FloatPoint(x1 + max(-adjbw1, 0), y2);
1060 quad[2] = FloatPoint(x2 - max(-adjbw2, 0), y2);
1061 quad[3] = FloatPoint(x2 - max(adjbw2, 0), y1);
1064 quad[0] = FloatPoint(x1, y1 + max(-adjbw1, 0));
1065 quad[1] = FloatPoint(x1, y2 - max(-adjbw2, 0));
1066 quad[2] = FloatPoint(x2, y2 - max(adjbw2, 0));
1067 quad[3] = FloatPoint(x2, y1 + max(adjbw1, 0));
1070 quad[0] = FloatPoint(x1, y1 + max(adjbw1, 0));
1071 quad[1] = FloatPoint(x1, y2 - max(adjbw2, 0));
1072 quad[2] = FloatPoint(x2, y2 - max(-adjbw2, 0));
1073 quad[3] = FloatPoint(x2, y1 + max(-adjbw1, 0));
1076 graphicsContext->drawConvexPolygon(4, quad);
1082 bool RenderObject::paintBorderImage(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style)
1084 CachedImage* borderImage = style->borderImage().image();
1085 if (!borderImage->isLoaded())
1086 return true; // Never paint a border image incrementally, but don't paint the fallback borders either.
1088 // If we have a border radius, the border image gets clipped to the rounded rect.
1089 bool clipped = false;
1090 if (style->hasBorderRadius()) {
1091 IntRect clipRect(tx, ty, w, h);
1092 graphicsContext->save();
1093 graphicsContext->addRoundedRectClip(clipRect, style->borderTopLeftRadius(), style->borderTopRightRadius(),
1094 style->borderBottomLeftRadius(), style->borderBottomRightRadius());
1098 int imageWidth = borderImage->image()->width();
1099 int imageHeight = borderImage->image()->height();
1101 int topSlice = min(imageHeight, style->borderImage().m_slices.top.calcValue(borderImage->image()->height()));
1102 int bottomSlice = min(imageHeight, style->borderImage().m_slices.bottom.calcValue(borderImage->image()->height()));
1103 int leftSlice = min(imageWidth, style->borderImage().m_slices.left.calcValue(borderImage->image()->width()));
1104 int rightSlice = min(imageWidth, style->borderImage().m_slices.right.calcValue(borderImage->image()->width()));
1106 EBorderImageRule hRule = style->borderImage().horizontalRule();
1107 EBorderImageRule vRule = style->borderImage().verticalRule();
1109 bool drawLeft = leftSlice > 0 && style->borderLeftWidth() > 0;
1110 bool drawTop = topSlice > 0 && style->borderTopWidth() > 0;
1111 bool drawRight = rightSlice > 0 && style->borderRightWidth() > 0;
1112 bool drawBottom = bottomSlice > 0 && style->borderBottomWidth() > 0;
1113 bool drawMiddle = (imageWidth - leftSlice - rightSlice) > 0 && (w - style->borderLeftWidth() - style->borderRightWidth()) > 0 &&
1114 (imageHeight - topSlice - bottomSlice) > 0 && (h - style->borderTopWidth() - style->borderBottomWidth()) > 0;
1117 // Paint the top and bottom left corners.
1119 // The top left corner rect is (tx, ty, leftWidth, topWidth)
1120 // The rect to use from within the image is obtained from our slice, and is (0, 0, leftSlice, topSlice)
1122 graphicsContext->drawImage(borderImage->image(), IntRect(tx, ty, style->borderLeftWidth(), style->borderTopWidth()),
1123 IntRect(0, 0, leftSlice, topSlice));
1125 // The bottom left corner rect is (tx, ty + h - bottomWidth, leftWidth, bottomWidth)
1126 // The rect to use from within the image is (0, imageHeight - bottomSlice, leftSlice, botomSlice)
1128 graphicsContext->drawImage(borderImage->image(), IntRect(tx, ty + h - style->borderBottomWidth(), style->borderLeftWidth(), style->borderBottomWidth()),
1129 IntRect(0, imageHeight - bottomSlice, leftSlice, bottomSlice));
1131 // Paint the left edge.
1132 // Have to scale and tile into the border rect.
1133 graphicsContext->drawTiledImage(borderImage->image(), IntRect(tx, ty + style->borderTopWidth(), style->borderLeftWidth(),
1134 h - style->borderTopWidth() - style->borderBottomWidth()),
1135 IntRect(0, topSlice, leftSlice, imageHeight - topSlice - bottomSlice),
1136 Image::StretchTile, (Image::TileRule)vRule);
1140 // Paint the top and bottom right corners
1141 // The top right corner rect is (tx + w - rightWidth, ty, rightWidth, topWidth)
1142 // The rect to use from within the image is obtained from our slice, and is (imageWidth - rightSlice, 0, rightSlice, topSlice)
1144 graphicsContext->drawImage(borderImage->image(), IntRect(tx + w - style->borderRightWidth(), ty, style->borderRightWidth(), style->borderTopWidth()),
1145 IntRect(imageWidth - rightSlice, 0, rightSlice, topSlice));
1147 // The bottom right corner rect is (tx + w - rightWidth, ty + h - bottomWidth, rightWidth, bottomWidth)
1148 // The rect to use from within the image is (imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, botomSlice)
1150 graphicsContext->drawImage(borderImage->image(), IntRect(tx + w - style->borderRightWidth(), ty + h - style->borderBottomWidth(), style->borderRightWidth(), style->borderBottomWidth()),
1151 IntRect(imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice));
1153 // Paint the right edge.
1154 graphicsContext->drawTiledImage(borderImage->image(), IntRect(tx + w - style->borderRightWidth(), ty + style->borderTopWidth(), style->borderRightWidth(),
1155 h - style->borderTopWidth() - style->borderBottomWidth()),
1156 IntRect(imageWidth - rightSlice, topSlice, rightSlice, imageHeight - topSlice - bottomSlice),
1157 Image::StretchTile, (Image::TileRule)vRule);
1160 // Paint the top edge.
1162 graphicsContext->drawTiledImage(borderImage->image(), IntRect(tx + style->borderLeftWidth(), ty, w - style->borderLeftWidth() - style->borderRightWidth(), style->borderTopWidth()),
1163 IntRect(leftSlice, 0, imageWidth - rightSlice - leftSlice, topSlice),
1164 (Image::TileRule)hRule, Image::StretchTile);
1166 // Paint the bottom edge.
1168 graphicsContext->drawTiledImage(borderImage->image(), IntRect(tx + style->borderLeftWidth(), ty + h - style->borderBottomWidth(),
1169 w - style->borderLeftWidth() - style->borderRightWidth(), style->borderBottomWidth()),
1170 IntRect(leftSlice, imageHeight - bottomSlice, imageWidth - rightSlice - leftSlice, bottomSlice),
1171 (Image::TileRule)hRule, Image::StretchTile);
1173 // Paint the middle.
1175 graphicsContext->drawTiledImage(borderImage->image(), IntRect(tx + style->borderLeftWidth(), ty + style->borderTopWidth(), w - style->borderLeftWidth() - style->borderRightWidth(),
1176 h - style->borderTopWidth() - style->borderBottomWidth()),
1177 IntRect(leftSlice, topSlice, imageWidth - rightSlice - leftSlice, imageHeight - topSlice - bottomSlice),
1178 (Image::TileRule)hRule, (Image::TileRule)vRule);
1180 // Clear the clip for the border radius.
1182 graphicsContext->restore();
1187 void RenderObject::paintBorder(GraphicsContext* graphicsContext, int tx, int ty, int w, int h,
1188 const RenderStyle* style, bool begin, bool end)
1190 CachedImage* borderImage = style->borderImage().image();
1191 bool shouldPaintBackgroundImage = borderImage && borderImage->canRender();
1192 if (shouldPaintBackgroundImage)
1193 shouldPaintBackgroundImage = paintBorderImage(graphicsContext, tx, ty, w, h, style);
1195 if (shouldPaintBackgroundImage)
1198 const Color& tc = style->borderTopColor();
1199 const Color& bc = style->borderBottomColor();
1200 const Color& lc = style->borderLeftColor();
1201 const Color& rc = style->borderRightColor();
1203 bool tt = style->borderTopIsTransparent();
1204 bool bt = style->borderBottomIsTransparent();
1205 bool rt = style->borderRightIsTransparent();
1206 bool lt = style->borderLeftIsTransparent();
1208 EBorderStyle ts = style->borderTopStyle();
1209 EBorderStyle bs = style->borderBottomStyle();
1210 EBorderStyle ls = style->borderLeftStyle();
1211 EBorderStyle rs = style->borderRightStyle();
1213 bool renderTop = ts > BHIDDEN && !tt;
1214 bool renderLeft = ls > BHIDDEN && begin && !lt;
1215 bool renderRight = rs > BHIDDEN && end && !rt;
1216 bool renderBottom = bs > BHIDDEN && !bt;
1218 // Need sufficient width and height to contain border radius curves. Sanity check our border radii
1219 // and our width/height values to make sure the curves can all fit. If not, then we won't paint
1220 // any border radii.
1221 bool renderRadii = false;
1222 IntSize topLeft = style->borderTopLeftRadius();
1223 IntSize topRight = style->borderTopRightRadius();
1224 IntSize bottomLeft = style->borderBottomLeftRadius();
1225 IntSize bottomRight = style->borderBottomRightRadius();
1227 if (style->hasBorderRadius() &&
1228 static_cast<unsigned>(w) >= static_cast<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()) &&
1229 static_cast<unsigned>(w) >= static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width()) &&
1230 static_cast<unsigned>(h) >= static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height()) &&
1231 static_cast<unsigned>(h) >= static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height()))
1234 // Clip to the rounded rectangle.
1236 graphicsContext->save();
1237 graphicsContext->addRoundedRectClip(IntRect(tx, ty, w, h), topLeft, topRight, bottomLeft, bottomRight);
1240 int firstAngleStart, secondAngleStart, firstAngleSpan, secondAngleSpan;
1242 bool upperLeftBorderStylesMatch = renderLeft && (ts == ls) && (tc == lc);
1243 bool upperRightBorderStylesMatch = renderRight && (ts == rs) && (tc == rc) && (ts != OUTSET) && (ts != RIDGE) && (ts != INSET) && (ts != GROOVE);
1244 bool lowerLeftBorderStylesMatch = renderLeft && (bs == ls) && (bc == lc) && (bs != OUTSET) && (bs != RIDGE) && (bs != INSET) && (bs != GROOVE);
1245 bool lowerRightBorderStylesMatch = renderRight && (bs == rs) && (bc == rc);
1248 bool ignore_left = (renderRadii && topLeft.width() > 0) ||
1249 (tc == lc && tt == lt && ts >= OUTSET &&
1250 (ls == DOTTED || ls == DASHED || ls == SOLID || ls == OUTSET));
1252 bool ignore_right = (renderRadii && topRight.width() > 0) ||
1253 (tc == rc && tt == rt && ts >= OUTSET &&
1254 (rs == DOTTED || rs == DASHED || rs == SOLID || rs == INSET));
1259 x += topLeft.width();
1260 x2 -= topRight.width();
1263 drawBorder(graphicsContext, x, ty, x2, ty + style->borderTopWidth(), BSTop, tc, style->color(), ts,
1264 ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth());
1269 // We make the arc double thick and let the clip rect take care of clipping the extra off.
1270 // We're doing this because it doesn't seem possible to match the curve of the clip exactly
1271 // with the arc-drawing function.
1272 thickness = style->borderTopWidth() * 2;
1274 if (topLeft.width()) {
1276 // The inner clip clips inside the arc. This is especially important for 1px borders.
1277 bool applyLeftInnerClip = (style->borderLeftWidth() < topLeft.width())
1278 && (style->borderTopWidth() < topLeft.height())
1279 && (ts != DOUBLE || style->borderTopWidth() > 6);
1280 if (applyLeftInnerClip) {
1281 graphicsContext->save();
1282 graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, topLeft.width() * 2, topLeft.height() * 2),
1283 style->borderTopWidth());
1286 firstAngleStart = 90;
1287 firstAngleSpan = upperLeftBorderStylesMatch ? 90 : 45;
1289 // Draw upper left arc
1290 drawBorderArc(graphicsContext, leftX, leftY, thickness, topLeft, firstAngleStart, firstAngleSpan,
1291 BSTop, tc, style->color(), ts, true);
1292 if (applyLeftInnerClip)
1293 graphicsContext->restore();
1296 if (topRight.width()) {
1297 int rightX = tx + w - topRight.width() * 2;
1298 bool applyRightInnerClip = (style->borderRightWidth() < topRight.width())
1299 && (style->borderTopWidth() < topRight.height())
1300 && (ts != DOUBLE || style->borderTopWidth() > 6);
1301 if (applyRightInnerClip) {
1302 graphicsContext->save();
1303 graphicsContext->addInnerRoundedRectClip(IntRect(rightX, leftY, topRight.width() * 2, topRight.height() * 2),
1304 style->borderTopWidth());
1307 if (upperRightBorderStylesMatch) {
1308 secondAngleStart = 0;
1309 secondAngleSpan = 90;
1311 secondAngleStart = 45;
1312 secondAngleSpan = 45;
1315 // Draw upper right arc
1316 drawBorderArc(graphicsContext, rightX, leftY, thickness, topRight, secondAngleStart, secondAngleSpan,
1317 BSTop, tc, style->color(), ts, false);
1318 if (applyRightInnerClip)
1319 graphicsContext->restore();
1325 bool ignore_left = (renderRadii && bottomLeft.width() > 0) ||
1326 (bc == lc && bt == lt && bs >= OUTSET &&
1327 (ls == DOTTED || ls == DASHED || ls == SOLID || ls == OUTSET));
1329 bool ignore_right = (renderRadii && bottomRight.width() > 0) ||
1330 (bc == rc && bt == rt && bs >= OUTSET &&
1331 (rs == DOTTED || rs == DASHED || rs == SOLID || rs == INSET));
1336 x += bottomLeft.width();
1337 x2 -= bottomRight.width();
1340 drawBorder(graphicsContext, x, ty + h - style->borderBottomWidth(), x2, ty + h, BSBottom, bc, style->color(), bs,
1341 ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth());
1344 thickness = style->borderBottomWidth() * 2;
1346 if (bottomLeft.width()) {
1348 int leftY = ty + h - bottomLeft.height() * 2;
1349 bool applyLeftInnerClip = (style->borderLeftWidth() < bottomLeft.width())
1350 && (style->borderBottomWidth() < bottomLeft.height())
1351 && (bs != DOUBLE || style->borderBottomWidth() > 6);
1352 if (applyLeftInnerClip) {
1353 graphicsContext->save();
1354 graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, bottomLeft.width() * 2, bottomLeft.height() * 2),
1355 style->borderBottomWidth());
1358 if (lowerLeftBorderStylesMatch) {
1359 firstAngleStart = 180;
1360 firstAngleSpan = 90;
1362 firstAngleStart = 225;
1363 firstAngleSpan = 45;
1366 // Draw lower left arc
1367 drawBorderArc(graphicsContext, leftX, leftY, thickness, bottomLeft, firstAngleStart, firstAngleSpan,
1368 BSBottom, bc, style->color(), bs, true);
1369 if (applyLeftInnerClip)
1370 graphicsContext->restore();
1373 if (bottomRight.width()) {
1374 int rightY = ty + h - bottomRight.height() * 2;
1375 int rightX = tx + w - bottomRight.width() * 2;
1376 bool applyRightInnerClip = (style->borderRightWidth() < bottomRight.width())
1377 && (style->borderBottomWidth() < bottomRight.height())
1378 && (bs != DOUBLE || style->borderBottomWidth() > 6);
1379 if (applyRightInnerClip) {
1380 graphicsContext->save();
1381 graphicsContext->addInnerRoundedRectClip(IntRect(rightX, rightY, bottomRight.width() * 2, bottomRight.height() * 2),
1382 style->borderBottomWidth());
1385 secondAngleStart = 270;
1386 secondAngleSpan = lowerRightBorderStylesMatch ? 90 : 45;
1388 // Draw lower right arc
1389 drawBorderArc(graphicsContext, rightX, rightY, thickness, bottomRight, secondAngleStart, secondAngleSpan,
1390 BSBottom, bc, style->color(), bs, false);
1391 if (applyRightInnerClip)
1392 graphicsContext->restore();
1398 bool ignore_top = (renderRadii && topLeft.height() > 0) ||
1399 (tc == lc && tt == lt && ls >= OUTSET &&
1400 (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET));
1402 bool ignore_bottom = (renderRadii && bottomLeft.height() > 0) ||
1403 (bc == lc && bt == lt && ls >= OUTSET &&
1404 (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET));
1409 y += topLeft.height();
1410 y2 -= bottomLeft.height();
1413 drawBorder(graphicsContext, tx, y, tx + style->borderLeftWidth(), y2, BSLeft, lc, style->color(), ls,
1414 ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth());
1416 if (renderRadii && (!upperLeftBorderStylesMatch || !lowerLeftBorderStylesMatch)) {
1418 thickness = style->borderLeftWidth() * 2;
1420 if (!upperLeftBorderStylesMatch && topLeft.width()) {
1422 bool applyTopInnerClip = (style->borderLeftWidth() < topLeft.width())
1423 && (style->borderTopWidth() < topLeft.height())
1424 && (ls != DOUBLE || style->borderLeftWidth() > 6);
1425 if (applyTopInnerClip) {
1426 graphicsContext->save();
1427 graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topLeft.width() * 2, topLeft.height() * 2),
1428 style->borderLeftWidth());
1431 firstAngleStart = 135;
1432 firstAngleSpan = 45;
1434 // Draw top left arc
1435 drawBorderArc(graphicsContext, topX, topY, thickness, topLeft, firstAngleStart, firstAngleSpan,
1436 BSLeft, lc, style->color(), ls, true);
1437 if (applyTopInnerClip)
1438 graphicsContext->restore();
1441 if (!lowerLeftBorderStylesMatch && bottomLeft.width()) {
1442 int bottomY = ty + h - bottomLeft.height() * 2;
1443 bool applyBottomInnerClip = (style->borderLeftWidth() < bottomLeft.width())
1444 && (style->borderBottomWidth() < bottomLeft.height())
1445 && (ls != DOUBLE || style->borderLeftWidth() > 6);
1446 if (applyBottomInnerClip) {
1447 graphicsContext->save();
1448 graphicsContext->addInnerRoundedRectClip(IntRect(topX, bottomY, bottomLeft.width() * 2, bottomLeft.height() * 2),
1449 style->borderLeftWidth());
1452 secondAngleStart = 180;
1453 secondAngleSpan = 45;
1455 // Draw bottom left arc
1456 drawBorderArc(graphicsContext, topX, bottomY, thickness, bottomLeft, secondAngleStart, secondAngleSpan,
1457 BSLeft, lc, style->color(), ls, false);
1458 if (applyBottomInnerClip)
1459 graphicsContext->restore();
1465 bool ignore_top = (renderRadii && topRight.height() > 0) ||
1466 ((tc == rc) && (tt == rt) &&
1467 (rs >= DOTTED || rs == INSET) &&
1468 (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET));
1470 bool ignore_bottom = (renderRadii && bottomRight.height() > 0) ||
1471 ((bc == rc) && (bt == rt) &&
1472 (rs >= DOTTED || rs == INSET) &&
1473 (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET));
1478 y += topRight.height();
1479 y2 -= bottomRight.height();
1482 drawBorder(graphicsContext, tx + w - style->borderRightWidth(), y, tx + w, y2, BSRight, rc, style->color(), rs,
1483 ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth());
1485 if (renderRadii && (!upperRightBorderStylesMatch || !lowerRightBorderStylesMatch)) {
1486 thickness = style->borderRightWidth() * 2;
1488 if (!upperRightBorderStylesMatch && topRight.width()) {
1489 int topX = tx + w - topRight.width() * 2;
1491 bool applyTopInnerClip = (style->borderRightWidth() < topRight.width())
1492 && (style->borderTopWidth() < topRight.height())
1493 && (rs != DOUBLE || style->borderRightWidth() > 6);
1494 if (applyTopInnerClip) {
1495 graphicsContext->save();
1496 graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topRight.width() * 2, topRight.height() * 2),
1497 style->borderRightWidth());
1500 firstAngleStart = 0;
1501 firstAngleSpan = 45;
1503 // Draw top right arc
1504 drawBorderArc(graphicsContext, topX, topY, thickness, topRight, firstAngleStart, firstAngleSpan,
1505 BSRight, rc, style->color(), rs, true);
1506 if (applyTopInnerClip)
1507 graphicsContext->restore();
1510 if (!lowerRightBorderStylesMatch && bottomRight.width()) {
1511 int bottomX = tx + w - bottomRight.width() * 2;
1512 int bottomY = ty + h - bottomRight.height() * 2;
1513 bool applyBottomInnerClip = (style->borderRightWidth() < bottomRight.width())
1514 && (style->borderBottomWidth() < bottomRight.height())
1515 && (rs != DOUBLE || style->borderRightWidth() > 6);
1516 if (applyBottomInnerClip) {
1517 graphicsContext->save();
1518 graphicsContext->addInnerRoundedRectClip(IntRect(bottomX, bottomY, bottomRight.width() * 2, bottomRight.height() * 2),
1519 style->borderRightWidth());
1522 secondAngleStart = 315;
1523 secondAngleSpan = 45;
1525 // Draw bottom right arc
1526 drawBorderArc(graphicsContext, bottomX, bottomY, thickness, bottomRight, secondAngleStart, secondAngleSpan,
1527 BSRight, rc, style->color(), rs, false);
1528 if (applyBottomInnerClip)
1529 graphicsContext->restore();
1535 graphicsContext->restore();
1538 void RenderObject::paintBoxShadow(GraphicsContext* context, int tx, int ty, int w, int h, const RenderStyle* s, bool begin, bool end)
1540 if (!s->boxShadow())
1543 // FIXME: Deal with border-image. Would be great to use border-image as a mask.
1545 context->setShadow(IntSize(s->boxShadow()->x, s->boxShadow()->y),
1546 s->boxShadow()->blur, s->boxShadow()->color);
1547 IntRect rect(tx, ty, w, h);
1548 if (s->hasBorderRadius()) {
1549 IntSize topLeft = begin ? s->borderTopLeftRadius() : IntSize();
1550 IntSize topRight = end ? s->borderTopRightRadius() : IntSize();
1551 IntSize bottomLeft = begin ? s->borderBottomLeftRadius() : IntSize();
1552 IntSize bottomRight = end ? s->borderBottomRightRadius() : IntSize();
1553 context->clipOutRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
1554 context->fillRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight, Color::black);
1556 context->clipOut(rect);
1557 context->fillRect(IntRect(tx, ty, w, h), Color::black);
1562 void RenderObject::addLineBoxRects(Vector<IntRect>&, unsigned startOffset, unsigned endOffset)
1566 void RenderObject::absoluteRects(Vector<IntRect>& rects, int tx, int ty)
1568 // For blocks inside inlines, we go ahead and include margins so that we run right up to the
1569 // inline boxes above and below us (thus getting merged with them to form a single irregular
1571 if (continuation()) {
1572 rects.append(IntRect(tx, ty - collapsedMarginTop(),
1573 width(), height() + collapsedMarginTop() + collapsedMarginBottom()));
1574 continuation()->absoluteRects(rects,
1575 tx - xPos() + continuation()->containingBlock()->xPos(),
1576 ty - yPos() + continuation()->containingBlock()->yPos());
1578 rects.append(IntRect(tx, ty, width(), height() + borderTopExtra() + borderBottomExtra()));
1581 IntRect RenderObject::absoluteBoundingBoxRect()
1584 absolutePosition(x, y);
1585 Vector<IntRect> rects;
1586 absoluteRects(rects, x, y);
1588 size_t n = rects.size();
1592 IntRect result = rects[0];
1593 for (size_t i = 1; i < n; ++i)
1594 result.unite(rects[i]);
1598 void RenderObject::addAbsoluteRectForLayer(IntRect& result)
1601 result.unite(absoluteBoundingBoxRect());
1602 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1603 current->addAbsoluteRectForLayer(result);
1606 IntRect RenderObject::paintingRootRect(IntRect& topLevelRect)
1608 IntRect result = absoluteBoundingBoxRect();
1609 topLevelRect = result;
1610 for (RenderObject* current = firstChild(); current; current = current->nextSibling())
1611 current->addAbsoluteRectForLayer(result);
1615 void RenderObject::addPDFURLRect(GraphicsContext* graphicsContext, IntRect rect)
1617 Node* node = element();
1619 if (graphicsContext) {
1620 if (rect.width() > 0 && rect.height() > 0) {
1621 Element* element = static_cast<Element*>(node);
1623 if (element->isLink())
1624 href = element->getAttribute(hrefAttr);
1626 if (!href.isNull()) {
1627 KURL link = element->document()->completeURL(href.deprecatedString());
1629 graphicsContext->setURLForRect(link, rect);
1637 void RenderObject::addFocusRingRects(GraphicsContext* graphicsContext, int tx, int ty)
1639 // For blocks inside inlines, we go ahead and include margins so that we run right up to the
1640 // inline boxes above and below us (thus getting merged with them to form a single irregular
1642 if (continuation()) {
1643 graphicsContext->addFocusRingRect(IntRect(tx, ty - collapsedMarginTop(), width(), height() + collapsedMarginTop() + collapsedMarginBottom()));
1644 continuation()->addFocusRingRects(graphicsContext,
1645 tx - xPos() + continuation()->containingBlock()->xPos(),
1646 ty - yPos() + continuation()->containingBlock()->yPos());
1648 graphicsContext->addFocusRingRect(IntRect(tx, ty, width(), height()));
1651 void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style)
1656 int ow = style->outlineWidth();
1658 EBorderStyle os = style->outlineStyle();
1660 Color oc = style->outlineColor();
1662 oc = style->color();
1664 int offset = style->outlineOffset();
1666 if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) {
1667 if (!theme()->supportsFocusRing(style)) {
1668 // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
1669 graphicsContext->initFocusRing(ow, offset);
1670 if (style->outlineStyleIsAuto())
1671 addFocusRingRects(graphicsContext, tx, ty);
1673 addPDFURLRect(graphicsContext, graphicsContext->focusRingBoundingRect());
1674 graphicsContext->drawFocusRing(oc);
1675 graphicsContext->clearFocusRing();
1679 if (style->outlineStyleIsAuto() || style->outlineStyle() <= BHIDDEN)
1690 drawBorder(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow,
1691 BSLeft, Color(oc), style->color(), os, ow, ow);
1693 drawBorder(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty,
1694 BSTop, Color(oc), style->color(), os, ow, ow);
1696 drawBorder(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow,
1697 BSRight, Color(oc), style->color(), os, ow, ow);
1699 drawBorder(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow,
1700 BSBottom, Color(oc), style->color(), os, ow, ow);
1703 void RenderObject::paint(PaintInfo& /*paintInfo*/, int /*tx*/, int /*ty*/)
1707 void RenderObject::repaint(bool immediate)
1709 // Can't use view(), since we might be unrooted.
1710 RenderObject* o = this;
1713 if (!o->isRenderView())
1715 RenderView* view = static_cast<RenderView*>(o);
1716 if (view->printing())
1717 return; // Don't repaint if we're printing.
1718 view->repaintViewRectangle(absoluteClippedOverflowRect(), immediate);
1721 void RenderObject::repaintRectangle(const IntRect& r, bool immediate)
1723 // Can't use view(), since we might be unrooted.
1724 RenderObject* o = this;
1727 if (!o->isRenderView())
1729 RenderView* view = static_cast<RenderView*>(o);
1730 if (view->printing())
1731 return; // Don't repaint if we're printing.
1733 computeAbsoluteRepaintRect(absRect);
1734 view->repaintViewRectangle(absRect, immediate);
1737 bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const IntRect& oldOutlineBox)
1739 RenderView* v = view();
1741 return false; // Don't repaint if we're printing.
1743 IntRect newBounds = absoluteClippedOverflowRect();
1744 IntRect newOutlineBox;
1746 bool fullRepaint = selfNeedsLayout() || mustRepaintBackgroundOrBorder();
1748 newOutlineBox = absoluteOutlineBox();
1749 if (newOutlineBox.location() != oldOutlineBox.location())
1753 v->repaintViewRectangle(oldBounds);
1754 if (newBounds != oldBounds)
1755 v->repaintViewRectangle(newBounds);
1759 if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
1762 int deltaLeft = newBounds.x() - oldBounds.x();
1764 v->repaintViewRectangle(IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
1765 else if (deltaLeft < 0)
1766 v->repaintViewRectangle(IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
1768 int deltaRight = newBounds.right() - oldBounds.right();
1770 v->repaintViewRectangle(IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height()));
1771 else if (deltaRight < 0)
1772 v->repaintViewRectangle(IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height()));
1774 int deltaTop = newBounds.y() - oldBounds.y();
1776 v->repaintViewRectangle(IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
1777 else if (deltaTop < 0)
1778 v->repaintViewRectangle(IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
1780 int deltaBottom = newBounds.bottom() - oldBounds.bottom();
1781 if (deltaBottom > 0)
1782 v->repaintViewRectangle(IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom));
1783 else if (deltaBottom < 0)
1784 v->repaintViewRectangle(IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom));
1786 if (newOutlineBox == oldOutlineBox)
1789 // We didn't move, but we did change size. Invalidate the delta, which will consist of possibly
1790 // two rectangles (but typically only one).
1791 int ow = style() ? style()->outlineSize() : 0;
1792 int width = abs(newOutlineBox.width() - oldOutlineBox.width());
1794 int borderWidth = max(-style()->outlineOffset(), max(borderRight(), max(style()->borderTopRightRadius().width(), style()->borderBottomRightRadius().width()))) + ow;
1795 IntRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
1797 width + borderWidth,
1798 max(newOutlineBox.height(), oldOutlineBox.height()));
1799 int right = min(newBounds.right(), oldBounds.right());
1800 if (rightRect.x() < right) {
1801 rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
1802 v->repaintViewRectangle(rightRect);
1805 int height = abs(newOutlineBox.height() - oldOutlineBox.height());
1807 int borderHeight = max(-style()->outlineOffset(), max(borderBottom(), max(style()->borderBottomLeftRadius().height(), style()->borderBottomRightRadius().height()))) + ow;
1808 IntRect bottomRect(newOutlineBox.x(),
1809 min(newOutlineBox.bottom(), oldOutlineBox.bottom()) - borderHeight,
1810 max(newOutlineBox.width(), oldOutlineBox.width()),
1811 height + borderHeight);
1812 int bottom = min(newBounds.bottom(), oldBounds.bottom());
1813 if (bottomRect.y() < bottom) {
1814 bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
1815 v->repaintViewRectangle(bottomRect);
1821 void RenderObject::repaintDuringLayoutIfMoved(const IntRect& rect)
1825 void RenderObject::repaintOverhangingFloats(bool paintAllDescendants)
1829 bool RenderObject::checkForRepaintDuringLayout() const
1831 return !document()->view()->needsFullRepaint() && !layer();
1834 void RenderObject::repaintObjectsBeforeLayout()
1836 if (!needsLayout() || isText())
1839 bool blockWithInlineChildren = (isRenderBlock() && !isTable() && normalChildNeedsLayout() && childrenInline());
1840 if (selfNeedsLayout()) {
1842 if (blockWithInlineChildren)
1846 for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
1847 if (!current->isPositioned()) // RenderBlock subclass method handles walking the positioned objects.
1848 current->repaintObjectsBeforeLayout();
1852 IntRect RenderObject::getAbsoluteRepaintRectWithOutline(int ow)
1854 IntRect r(absoluteClippedOverflowRect());
1857 if (continuation() && !isInline())
1858 r.inflateY(collapsedMarginTop());
1860 if (isInlineFlow()) {
1861 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
1862 if (!curr->isText())
1863 r.unite(curr->getAbsoluteRepaintRectWithOutline(ow));
1870 IntRect RenderObject::absoluteClippedOverflowRect()
1873 return parent()->absoluteClippedOverflowRect();
1877 void RenderObject::computeAbsoluteRepaintRect(IntRect& r, bool f)
1880 return parent()->computeAbsoluteRepaintRect(r, f);
1883 void RenderObject::dirtyLinesFromChangedChild(RenderObject* child)
1889 DeprecatedString RenderObject::information() const
1891 DeprecatedString str;
1892 TextStream ts(&str);
1894 << "(" << (style() ? style()->refCount() : 0) << ")"
1895 << ": " << (void*)this << " ";
1898 if (childrenInline())
1904 if (isRelPositioned())
1912 if (style() && style()->zIndex())
1913 ts << "zI: " << style()->zIndex();
1915 if (element()->active())
1917 if (element()->isLink())
1919 if (element()->focused())
1921 ts << " <" << element()->localName().deprecatedString() << ">";
1922 ts << " (" << xPos() << "," << yPos() << "," << width() << "," << height() << ")";
1923 if (isTableCell()) {
1924 const RenderTableCell* cell = static_cast<const RenderTableCell*>(this);
1925 ts << " [r=" << cell->row() << " c=" << cell->col() << " rs=" << cell->rowSpan() << " cs=" << cell->colSpan() << "]";
1931 void RenderObject::dump(TextStream* stream, DeprecatedString ind) const
1934 *stream << " anonymous";
1936 *stream << " floating";
1938 *stream << " positioned";
1939 if (isRelPositioned())
1940 *stream << " relPositioned";
1944 *stream << " inline";
1946 *stream << " replaced";
1947 if (hasBoxDecorations())
1948 *stream << " paintBackground";
1950 *stream << " needsLayout";
1952 *stream << " minMaxKnown";
1955 RenderObject* child = firstChild();
1957 *stream << ind << child->renderName() << ": ";
1958 child->dump(stream, ind + " ");
1959 child = child->nextSibling();
1963 void RenderObject::showTreeForThis() const
1966 element()->showTreeForThis();
1971 static Node* selectStartNode(const RenderObject* object)
1974 bool forcedOn = false;
1976 for (const RenderObject* curr = object; curr; curr = curr->parent()) {
1977 if (curr->style()->userSelect() == SELECT_TEXT)
1979 if (!forcedOn && curr->style()->userSelect() == SELECT_NONE)
1983 node = curr->element();
1986 // somewhere up the render tree there must be an element!
1992 bool RenderObject::canSelect() const
1994 return selectStartNode(this) != 0;
1997 bool RenderObject::shouldSelect() const
1999 if (Node* node = selectStartNode(this))
2000 return EventTargetNodeCast(node)->dispatchHTMLEvent(selectstartEvent, true, true);
2005 Color RenderObject::selectionBackgroundColor() const
2008 if (style()->userSelect() != SELECT_NONE) {
2009 RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SELECTION);
2010 if (pseudoStyle && pseudoStyle->backgroundColor().isValid())
2011 color = pseudoStyle->backgroundColor().blendWithWhite();
2013 color = document()->frame()->isActive() ?
2014 theme()->activeSelectionBackgroundColor() :
2015 theme()->inactiveSelectionBackgroundColor();
2021 Color RenderObject::selectionForegroundColor() const
2024 if (style()->userSelect() != SELECT_NONE) {
2025 RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SELECTION);
2027 color = pseudoStyle->textFillColor();
2028 if (!color.isValid())
2029 color = pseudoStyle->color();
2031 color = document()->frame()->isActive() ?
2032 theme()->platformActiveSelectionForegroundColor() :
2033 theme()->platformInactiveSelectionForegroundColor();
2039 Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
2041 if (!dhtmlOK && !uaOK)
2044 for (const RenderObject* curr = this; curr; curr = curr->parent()) {
2045 Node* elt = curr->element();
2046 if (elt && elt->nodeType() == Node::TEXT_NODE) {
2047 // Since there's no way for the author to address the -webkit-user-drag style for a text node,
2048 // we use our own judgement.
2049 if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
2050 dhtmlWillDrag = false;
2051 return curr->node();
2053 if (curr->shouldSelect())
2054 // In this case we have a click in the unselected portion of text. If this text is
2055 // selectable, we want to start the selection process instead of looking for a parent
2059 EUserDrag dragMode = curr->style()->userDrag();
2060 if (dhtmlOK && dragMode == DRAG_ELEMENT) {
2061 dhtmlWillDrag = true;
2062 return curr->node();
2064 if (uaOK && dragMode == DRAG_AUTO
2065 && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
2066 dhtmlWillDrag = false;
2067 return curr->node();
2074 void RenderObject::selectionStartEnd(int& spos, int& epos) const
2076 view()->selectionStartEnd(spos, epos);
2079 RenderBlock* RenderObject::createAnonymousBlock()
2081 RenderStyle* newStyle = new (renderArena()) RenderStyle();
2082 newStyle->inheritFrom(m_style);
2083 newStyle->setDisplay(BLOCK);
2085 RenderBlock* newBox = new (renderArena()) RenderBlock(document() /* anonymous box */);
2086 newBox->setStyle(newStyle);
2090 void RenderObject::handleDynamicFloatPositionChange()
2092 // We have gone from not affecting the inline status of the parent flow to suddenly
2093 // having an impact. See if there is a mismatch between the parent flow's
2094 // childrenInline() state and our state.
2095 setInline(style()->isDisplayInlineType());
2096 if (isInline() != parent()->childrenInline()) {
2098 if (parent()->isRenderInline()) {
2099 // We have to split the parent flow.
2100 RenderInline* parentInline = static_cast<RenderInline*>(parent());
2101 RenderBlock* newBox = parentInline->createAnonymousBlock();
2103 RenderFlow* oldContinuation = parent()->continuation();
2104 parentInline->setContinuation(newBox);
2106 RenderObject* beforeChild = nextSibling();
2107 parent()->removeChildNode(this);
2108 parentInline->splitFlow(beforeChild, newBox, this, oldContinuation);
2109 } else if (parent()->isRenderBlock())
2110 static_cast<RenderBlock*>(parent())->makeChildrenNonInline();
2112 // An anonymous block must be made to wrap this inline.
2113 RenderBlock* box = createAnonymousBlock();
2114 parent()->insertChildNode(box, this);
2115 box->appendChildNode(parent()->removeChildNode(this));
2120 void RenderObject::setStyle(RenderStyle* style)
2122 if (m_style == style)
2125 bool affectsParentBlock = false;
2126 RenderStyle::Diff d = RenderStyle::Equal;
2128 // If our z-index changes value or our visibility changes,
2129 // we need to dirty our stacking context's z-order list.
2132 if (m_style->visibility() != style->visibility() ||
2133 m_style->zIndex() != style->zIndex() ||
2134 m_style->hasAutoZIndex() != style->hasAutoZIndex())
2135 document()->setDashboardRegionsDirty(true);
2138 if ((m_style->hasAutoZIndex() != style->hasAutoZIndex() ||
2139 m_style->zIndex() != style->zIndex() ||
2140 m_style->visibility() != style->visibility()) && layer()) {
2141 layer()->stackingContext()->dirtyZOrderLists();
2142 if (m_style->hasAutoZIndex() != style->hasAutoZIndex() ||
2143 m_style->visibility() != style->visibility())
2144 layer()->dirtyZOrderLists();
2146 // keep layer hierarchy visibility bits up to date if visibility changes
2147 if (m_style->visibility() != style->visibility()) {
2148 RenderLayer* l = enclosingLayer();
2149 if (style->visibility() == VISIBLE && l)
2150 l->setHasVisibleContent(true);
2151 else if (l && l->hasVisibleContent() &&
2152 (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE))
2153 l->dirtyVisibleContentStatus();
2157 d = m_style->diff(style);
2159 // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
2160 if (d == RenderStyle::RepaintLayer && !layer())
2161 d = RenderStyle::Repaint;
2163 // The background of the root element or the body element could propagate up to
2164 // the canvas. Just dirty the entire canvas when our style changes substantially.
2165 if (d >= RenderStyle::Repaint && element() &&
2166 (element()->hasTagName(htmlTag) || element()->hasTagName(bodyTag)))
2168 else if (m_parent && !isText()) {
2169 // Do a repaint with the old style first, e.g., for example if we go from
2170 // having an outline to not having an outline.
2171 if (d == RenderStyle::RepaintLayer) {
2172 layer()->repaintIncludingDescendants();
2173 if (!(m_style->clip() == style->clip()))
2174 layer()->clearClipRects();
2175 } else if (d == RenderStyle::Repaint || style->outlineSize() < m_style->outlineSize())
2179 // When a layout hint happens, we go ahead and do a repaint of the layer, since the layer could
2180 // end up being destroyed.
2181 if (d == RenderStyle::Layout && layer() &&
2182 (m_style->position() != style->position() ||
2183 m_style->zIndex() != style->zIndex() ||
2184 m_style->hasAutoZIndex() != style->hasAutoZIndex() ||
2185 !(m_style->clip() == style->clip()) ||
2186 m_style->hasClip() != style->hasClip() ||
2187 m_style->opacity() != style->opacity()))
2188 layer()->repaintIncludingDescendants();
2190 // When a layout hint happens and an object's position style changes, we have to do a layout
2191 // to dirty the render tree using the old position value now.
2192 if (d == RenderStyle::Layout && m_parent && m_style->position() != style->position()) {
2193 markContainingBlocksForLayout();
2194 if (m_style->position() == StaticPosition)
2196 if (isRenderBlock()) {
2197 if (style->position() == StaticPosition)
2198 // Clear our positioned objects list. Our absolutely positioned descendants will be
2199 // inserted into our containing block's positioned objects list during layout.
2200 removePositionedObjects(0);
2201 else if (m_style->position() == StaticPosition) {
2202 // Remove our absolutely positioned descendants from their current containing block.
2203 // They will be inserted into our positioned objects list during layout.
2204 RenderObject* cb = parent();
2205 while (cb && (cb->style()->position() == StaticPosition || (cb->isInline() && !cb->isReplaced())) && !cb->isRenderView()) {
2206 if (cb->style()->position() == RelativePosition && cb->isInline() && !cb->isReplaced()) {
2207 cb = cb->containingBlock();
2212 cb->removePositionedObjects(static_cast<RenderBlock*>(this));
2217 if (isFloating() && (m_style->floating() != style->floating()))
2218 // For changes in float styles, we need to conceivably remove ourselves
2219 // from the floating objects list.
2220 removeFromObjectLists();
2221 else if (isPositioned() && (style->position() != AbsolutePosition && style->position() != FixedPosition))
2222 // For changes in positioning styles, we need to conceivably remove ourselves
2223 // from the positioned objects list.
2224 removeFromObjectLists();
2226 affectsParentBlock = m_style && isFloatingOrPositioned() &&
2227 (!style->isFloating() && style->position() != AbsolutePosition && style->position() != FixedPosition)
2228 && parent() && (parent()->isBlockFlow() || parent()->isInlineFlow());
2230 // reset style flags
2232 m_positioned = false;
2233 m_relPositioned = false;
2234 m_paintBackground = false;
2235 m_hasOverflowClip = false;
2238 if (view()->frameView()) {
2239 // FIXME: A better solution would be to only invalidate the fixed regions when scrolling. It's overkill to
2240 // prevent the entire view from blitting on a scroll.
2241 bool oldStyleSlowScroll = style && (style->position() == FixedPosition || style->hasFixedBackgroundImage());
2242 bool newStyleSlowScroll = m_style && (m_style->position() == FixedPosition || m_style->hasFixedBackgroundImage());
2243 if (oldStyleSlowScroll != newStyleSlowScroll) {
2244 if (oldStyleSlowScroll)
2245 view()->frameView()->removeSlowRepaintObject();
2246 if (newStyleSlowScroll)
2247 view()->frameView()->addSlowRepaintObject();
2251 RenderStyle* oldStyle = m_style;
2254 updateBackgroundImages(oldStyle);
2260 oldStyle->deref(renderArena());
2262 setHasBoxDecorations(m_style->hasBorder() || m_style->hasBackground() || m_style->hasAppearance() || m_style->boxShadow());
2264 if (affectsParentBlock)
2265 handleDynamicFloatPositionChange();
2267 // No need to ever schedule repaints from a style change of a text run, since
2268 // we already did this for the parent of the text run.
2269 // We do have to schedule layouts, though, since a style change can force us to
2270 // need to relayout.
2271 if (d == RenderStyle::Layout && m_parent)
2272 setNeedsLayoutAndMinMaxRecalc();
2273 else if (m_parent && !isText() && (d == RenderStyle::RepaintLayer || d == RenderStyle::Repaint))
2274 // Do a repaint with the new style now, e.g., for example if we go from
2275 // not having an outline to having an outline.
2279 void RenderObject::setStyleInternal(RenderStyle* style)
2281 if (m_style == style)
2284 m_style->deref(renderArena());
2290 void RenderObject::updateBackgroundImages(RenderStyle* oldStyle)
2292 // FIXME: This will be slow when a large number of images is used. Fix by using a dict.
2293 const BackgroundLayer* oldLayers = oldStyle ? oldStyle->backgroundLayers() : 0;
2294 const BackgroundLayer* newLayers = m_style ? m_style->backgroundLayers() : 0;
2295 for (const BackgroundLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
2296 if (currOld->backgroundImage() && (!newLayers || !newLayers->containsImage(currOld->backgroundImage())))
2297 currOld->backgroundImage()->deref(this);
2299 for (const BackgroundLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
2300 if (currNew->backgroundImage() && (!oldLayers || !oldLayers->containsImage(currNew->backgroundImage())))
2301 currNew->backgroundImage()->ref(this);
2304 CachedImage* oldBorderImage = oldStyle ? oldStyle->borderImage().image() : 0;
2305 CachedImage* newBorderImage = m_style ? m_style->borderImage().image() : 0;
2306 if (oldBorderImage != newBorderImage) {
2308 oldBorderImage->deref(this);
2310 newBorderImage->ref(this);
2314 IntRect RenderObject::viewRect() const
2316 return view()->viewRect();
2319 bool RenderObject::absolutePosition(int& xPos, int& yPos, bool f) const
2321 RenderObject* o = parent();
2323 o->absolutePosition(xPos, yPos, f);
2324 yPos += o->borderTopExtra();
2325 if (o->hasOverflowClip())
2326 o->layer()->subtractScrollOffset(xPos, yPos);
2334 IntRect RenderObject::caretRect(int offset, EAffinity affinity, int* extraWidthToEndOfLine)
2336 if (extraWidthToEndOfLine)
2337 *extraWidthToEndOfLine = 0;
2342 int RenderObject::paddingTop() const
2345 Length padding = m_style->paddingTop();
2346 if (padding.isPercent())
2347 w = containingBlock()->availableWidth();
2348 w = padding.calcMinValue(w);
2349 if (isTableCell() && padding.isAuto())
2350 w = static_cast<const RenderTableCell*>(this)->table()->cellPadding();
2354 int RenderObject::paddingBottom() const
2357 Length padding = style()->paddingBottom();
2358 if (padding.isPercent())
2359 w = containingBlock()->availableWidth();
2360 w = padding.calcMinValue(w);
2361 if (isTableCell() && padding.isAuto())
2362 w = static_cast<const RenderTableCell*>(this)->table()->cellPadding();
2366 int RenderObject::paddingLeft() const
2369 Length padding = style()->paddingLeft();
2370 if (padding.isPercent())
2371 w = containingBlock()->availableWidth();
2372 w = padding.calcMinValue(w);
2373 if (isTableCell() && padding.isAuto())
2374 w = static_cast<const RenderTableCell*>(this)->table()->cellPadding();
2378 int RenderObject::paddingRight() const
2381 Length padding = style()->paddingRight();
2382 if (padding.isPercent())
2383 w = containingBlock()->availableWidth();
2384 w = padding.calcMinValue(w);
2385 if (isTableCell() && padding.isAuto())
2386 w = static_cast<const RenderTableCell*>(this)->table()->cellPadding();
2390 int RenderObject::tabWidth() const
2392 if (style()->collapseWhiteSpace())
2395 return containingBlock()->tabWidth(true);
2398 RenderView* RenderObject::view() const
2400 return static_cast<RenderView*>(document()->renderer());
2403 bool RenderObject::hasOutlineAnnotation() const
2405 return element() && element()->isLink() && document()->printing();
2408 RenderObject* RenderObject::container() const
2410 // This method is extremely similar to containingBlock(), but with a few notable
2412 // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
2413 // the object is not part of the primary document subtree yet.
2414 // (2) For normal flow elements, it just returns the parent.
2415 // (3) For absolute positioned elements, it will return a relative positioned inline.
2416 // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
2417 // the layout of the positioned object. This does mean that calcAbsoluteHorizontal and
2418 // calcAbsoluteVertical have to use container().
2419 RenderObject* o = parent();
2420 EPosition pos = m_style->position();
2421 if (!isText() && pos == FixedPosition) {
2422 // container() can be called on an object that is not in the
2423 // tree yet. We don't call view() since it will assert if it
2424 // can't get back to the canvas. Instead we just walk as high up
2425 // as we can. If we're in the tree, we'll get the root. If we
2426 // aren't we'll get the root of our little subtree (most likely
2427 // we'll just return 0).
2428 while (o && o->parent())
2430 } else if (!isText() && pos == AbsolutePosition) {
2431 // Same goes here. We technically just want our containing block, but
2432 // we may not have one if we're part of an uninstalled subtree. We'll
2433 // climb as high as we can though.
2434 while (o && o->style()->position() == StaticPosition && !o->isRenderView())
2441 // This code has been written to anticipate the addition of CSS3-::outside and ::inside generated
2442 // content (and perhaps XBL). That's why it uses the render tree and not the DOM tree.
2443 RenderObject* RenderObject::hoverAncestor() const
2445 return (!isInline() && continuation()) ? continuation() : parent();
2448 bool RenderObject::isSelectionBorder() const
2450 SelectionState st = selectionState();
2451 return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
2454 void RenderObject::removeFromObjectLists()
2456 if (documentBeingDestroyed())
2460 RenderBlock* outermostBlock = containingBlock();
2461 for (RenderBlock* p = outermostBlock; p && !p->isRenderView(); p = p->containingBlock()) {
2462 if (p->containsFloat(this))
2467 outermostBlock->markAllDescendantsWithFloatsForLayout(this);
2470 if (isPositioned()) {
2472 for (p = parent(); p; p = p->parent()) {
2473 if (p->isRenderBlock())
2474 static_cast<RenderBlock*>(p)->removePositionedObject(this);
2479 RenderArena* RenderObject::renderArena() const
2481 Document* doc = document();
2482 return doc ? doc->renderArena() : 0;
2485 bool RenderObject::documentBeingDestroyed() const
2487 return !document()->renderer();
2490 void RenderObject::destroy()
2492 // If this renderer is being autoscrolled, stop the autoscroll timer
2493 if (document() && document()->frame() && document()->frame()->eventHandler()->autoscrollRenderer() == this)
2494 document()->frame()->eventHandler()->stopAutoscrollTimer(true);
2496 if (m_hasCounterNodeMap)
2497 RenderCounter::destroyCounterNodes(this);
2499 document()->axObjectCache()->remove(this);
2501 // By default no ref-counting. RenderWidget::destroy() doesn't call
2502 // this function because it needs to do ref-counting. If anything
2503 // in this function changes, be sure to fix RenderWidget::destroy() as well.
2507 arenaDelete(document()->renderArena(), this);
2510 void RenderObject::arenaDelete(RenderArena* arena, void* base)
2513 for (const BackgroundLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
2514 if (CachedImage* backgroundImage = bgLayer->backgroundImage())
2515 backgroundImage->deref(this);
2518 if (CachedImage* borderImage = m_style->borderImage().image())
2519 borderImage->deref(this);
2521 m_style->deref(arena);
2525 void* savedBase = baseOfRenderObjectBeingDeleted;
2526 baseOfRenderObjectBeingDeleted = base;
2530 baseOfRenderObjectBeingDeleted = savedBase;
2533 // Recover the size left there for us by operator delete and free the memory.
2534 arena->free(*(size_t*)base, base);
2537 VisiblePosition RenderObject::positionForCoordinates(int x, int y)
2539 return VisiblePosition(element(), caretMinOffset(), DOWNSTREAM);
2542 void RenderObject::updateDragState(bool dragOn)
2544 bool valueChanged = (dragOn != m_isDragging);
2545 m_isDragging = dragOn;
2546 if (valueChanged && style()->affectedByDragRules())
2547 element()->setChanged();
2548 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2549 curr->updateDragState(dragOn);
2551 continuation()->updateDragState(dragOn);
2554 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestFilter hitTestFilter)
2556 bool inside = false;
2557 if (hitTestFilter != HitTestSelf) {
2558 // First test the foreground layer (lines and inlines).
2559 inside = nodeAtPoint(request, result, x, y, tx, ty, HitTestForeground);
2561 // Test floats next.
2563 inside = nodeAtPoint(request, result, x, y, tx, ty, HitTestFloat);
2565 // Finally test to see if the mouse is in the background (within a child block's background).
2567 inside = nodeAtPoint(request, result, x, y, tx, ty, HitTestChildBlockBackgrounds);
2570 // See if the mouse is inside us but not any of our descendants
2571 if (hitTestFilter != HitTestDescendants && !inside)
2572 inside = nodeAtPoint(request, result, x, y, tx, ty, HitTestBlockBackground);
2577 void RenderObject::updateHitTestResult(HitTestResult& result, const IntPoint& point)
2579 if (result.innerNode())
2582 Node* node = element();
2583 IntPoint localPoint(point);
2585 node = document()->documentElement();
2586 else if (!isInline() && continuation())
2587 // We are in the margins of block elements that are part of a continuation. In
2588 // this case we're actually still inside the enclosing inline element that was
2589 // split. Go ahead and set our inner node accordingly.
2590 node = continuation()->element();
2593 if (node->renderer()->continuation() && node->renderer() != this) {
2594 // We're in the continuation of a split inline. Adjust our local point to be in the coordinate space
2595 // of the principal renderer's containing block. This will end up being the innerNonSharedNode.
2596 RenderObject* firstBlock = node->renderer()->containingBlock();
2598 // Get our containing block.
2599 RenderObject* block = this;
2601 block = containingBlock();
2603 localPoint.move(block->xPos() - firstBlock->xPos(), block->yPos() - firstBlock->yPos());
2606 result.setInnerNode(node);
2607 if (!result.innerNonSharedNode())
2608 result.setInnerNonSharedNode(node);
2609 result.setLocalPoint(localPoint);
2613 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int /*x*/, int /*y*/, int /*tx*/, int /*ty*/, HitTestAction)
2618 short RenderObject::verticalPositionHint(bool firstLine) const
2620 short vpos = m_verticalPosition;
2621 if (m_verticalPosition == PositionUndefined || firstLine) {
2622 vpos = getVerticalPosition(firstLine);
2624 m_verticalPosition = vpos;
2630 short RenderObject::getVerticalPosition(bool firstLine) const
2635 // This method determines the vertical position for inline elements.
2637 EVerticalAlign va = style()->verticalAlign();
2640 else if (va == BOTTOM)
2641 vpos = PositionBottom;
2642 else if (va == LENGTH)
2643 vpos = -style()->verticalAlignLength().calcValue(lineHeight(firstLine));
2645 bool checkParent = parent()->isInline() && !parent()->isInlineBlockOrInlineTable() && parent()->style()->verticalAlign() != TOP && parent()->style()->verticalAlign() != BOTTOM;
2646 vpos = checkParent ? parent()->verticalPositionHint(firstLine) : 0;
2647 // don't allow elements nested inside text-top to have a different valignment.
2651 const Font& f = parent()->style(firstLine)->font();
2652 int fontsize = f.pixelSize();
2655 vpos += fontsize / 5 + 1;
2656 else if (va == SUPER)
2657 vpos -= fontsize / 3 + 1;
2658 else if (va == TEXT_TOP)
2659 vpos += baselinePosition(firstLine) - f.ascent();
2660 else if (va == MIDDLE)
2661 vpos += -static_cast<int>(f.xHeight() / 2) - lineHeight(firstLine) / 2 + baselinePosition(firstLine);
2662 else if (va == TEXT_BOTTOM) {
2663 vpos += f.descent();
2665 vpos -= style(firstLine)->font().descent();
2666 } else if (va == BASELINE_MIDDLE)
2667 vpos += -lineHeight(firstLine) / 2 + baselinePosition(firstLine);
2673 short RenderObject::lineHeight(bool firstLine, bool /*isRootLineBox*/) const
2675 RenderStyle* s = style(firstLine);
2677 Length lh = s->lineHeight();
2679 // its "unset", choose nice default
2680 if (lh.isNegative())
2681 return s->font().lineSpacing();
2684 return lh.calcMinValue(s->fontSize());
2690 short RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const
2692 const Font& f = style(firstLine)->font();
2693 return f.ascent() + (lineHeight(firstLine, isRootLineBox) - f.height()) / 2;
2696 void RenderObject::invalidateVerticalPositions()
2698 m_verticalPosition = PositionUndefined;
2699 RenderObject* child = firstChild();
2701 child->invalidateVerticalPositions();
2702 child = child->nextSibling();
2706 void RenderObject::recalcMinMaxWidths()
2708 ASSERT(m_recalcMinMax);
2710 m_recalcMinMax = false;
2711 updateFirstLetter();
2713 RenderObject* child = firstChild();
2718 if ((m_minMaxKnown && child->m_recalcMinMax) || !child->m_minMaxKnown) {
2719 cmin = child->minWidth();
2720 cmax = child->maxWidth();
2723 if (child->m_recalcMinMax)
2724 child->recalcMinMaxWidths();
2725 if (!child->m_minMaxKnown)
2726 child->calcMinMaxWidth();
2727 if (m_minMaxKnown && test && (cmin != child->minWidth() || cmax != child->maxWidth()))
2728 m_minMaxKnown = false;
2729 child = child->nextSibling();
2732 // we need to recalculate, if the contains inline children, as the change could have
2733 // happened somewhere deep inside the child tree. Also do this for blocks or tables that
2734 // are inline (i.e., inline-block and inline-table).
2735 if ((!isInline() || isInlineBlockOrInlineTable()) && childrenInline())
2736 m_minMaxKnown = false;
2742 void RenderObject::scheduleRelayout()
2744 if (isRenderView()) {
2745 FrameView* view = static_cast<RenderView*>(this)->frameView();
2747 view->scheduleRelayout();
2749 FrameView* v = view() ? view()->frameView() : 0;
2751 v->scheduleRelayoutOfSubtree(node());
2755 void RenderObject::removeLeftoverAnonymousBoxes()
2759 InlineBox* RenderObject::createInlineBox(bool, bool isRootLineBox, bool)
2761 ASSERT(!isRootLineBox);
2762 return new (renderArena()) InlineBox(this);
2765 void RenderObject::dirtyLineBoxes(bool, bool)
2769 InlineBox* RenderObject::inlineBoxWrapper() const
2774 void RenderObject::setInlineBoxWrapper(InlineBox*)
2778 void RenderObject::deleteLineBoxWrapper()
2782 RenderStyle* RenderObject::firstLineStyle() const
2784 RenderStyle* s = m_style;
2785 const RenderObject* obj = isText() ? parent() : this;
2786 if (obj->isBlockFlow()) {
2787 RenderBlock* firstLineBlock = obj->firstLineBlock();
2789 s = firstLineBlock->getPseudoStyle(RenderStyle::FIRST_LINE, style());
2790 } else if (!obj->isAnonymous() && obj->isInlineFlow()) {
2791 RenderStyle* parentStyle = obj->parent()->firstLineStyle();
2792 if (parentStyle != obj->parent()->style()) {
2793 // A first-line style is in effect. We need to cache a first-line style
2795 style()->setHasPseudoStyle(RenderStyle::FIRST_LINE_INHERITED);
2796 s = obj->getPseudoStyle(RenderStyle::FIRST_LINE_INHERITED, parentStyle);
2802 RenderStyle* RenderObject::getPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle) const
2804 if (!style()->hasPseudoStyle(pseudo))
2808 parentStyle = style();
2810 RenderStyle* result = style()->getPseudoStyle(pseudo);
2814 Node* node = element();
2815 if (node && isText())
2816 node = node->parentNode();
2820 if (pseudo == RenderStyle::FIRST_LINE_INHERITED) {
2821 result = document()->styleSelector()->styleForElement(static_cast<Element*>(node), parentStyle, false);
2822 result->setStyleType(RenderStyle::FIRST_LINE_INHERITED);
2824 result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(node), parentStyle);
2826 style()->addPseudoStyle(result);
2827 result->deref(document()->renderArena());
2832 static Color decorationColor(RenderStyle* style)
2835 if (style->textStrokeWidth() > 0) {
2836 // Prefer stroke color if possible but not if it's fully transparent.
2837 result = style->textStrokeColor();
2838 if (!result.isValid())
2839 result = style->color();
2844 result = style->textFillColor();
2845 if (!result.isValid())
2846 result = style->color();
2850 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
2851 Color& linethrough, bool quirksMode)
2853 RenderObject* curr = this;
2855 int currDecs = curr->style()->textDecoration();
2857 if (currDecs & UNDERLINE) {
2858 decorations &= ~UNDERLINE;
2859 underline = decorationColor(curr->style());
2861 if (currDecs & OVERLINE) {
2862 decorations &= ~OVERLINE;
2863 overline = decorationColor(curr->style());
2865 if (currDecs & LINE_THROUGH) {
2866 decorations &= ~LINE_THROUGH;
2867 linethrough = decorationColor(curr->style());
2870 curr = curr->parent();
2871 if (curr && curr->isRenderBlock() && curr->continuation())
2872 curr = curr->continuation();
2873 } while (curr && decorations && (!quirksMode || !curr->element() ||
2874 (!curr->element()->hasTagName(aTag) && !curr->element()->hasTagName(fontTag))));
2876 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
2877 if (decorations && curr) {
2878 if (decorations & UNDERLINE)
2879 underline = decorationColor(curr->style());
2880 if (decorations & OVERLINE)
2881 overline = decorationColor(curr->style());
2882 if (decorations & LINE_THROUGH)
2883 linethrough = decorationColor(curr->style());
2887 void RenderObject::updateWidgetPosition()
2891 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
2893 // Convert the style regions to absolute coordinates.
2894 if (style()->visibility() != VISIBLE)
2897 const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
2898 unsigned i, count = styleRegions.size();
2899 for (i = 0; i < count; i++) {
2900 StyleDashboardRegion styleRegion = styleRegions[i];
2905 DashboardRegionValue region;
2906 region.label = styleRegion.label;
2907 region.bounds = IntRect(styleRegion.offset.left.value(),
2908 styleRegion.offset.top.value(),
2909 w - styleRegion.offset.left.value() - styleRegion.offset.right.value(),
2910 h - styleRegion.offset.top.value() - styleRegion.offset.bottom.value());
2911 region.type = styleRegion.type;
2913 region.clip = region.bounds;
2914 computeAbsoluteRepaintRect(region.clip);
2915 if (region.clip.height() < 0) {
2916 region.clip.setHeight(0);
2917 region.clip.setWidth(0);
2921 absolutePosition(x, y);
2922 region.bounds.setX(x + styleRegion.offset.left.value());
2923 region.bounds.setY(y + styleRegion.offset.top.value());
2925 if (document()->frame()) {
2926 float pageScaleFactor = document()->frame()->page()->chrome()->scaleFactor();
2927 if (pageScaleFactor != 1.0f) {
2928 region.bounds.scale(pageScaleFactor);
2929 region.clip.scale(pageScaleFactor);
2933 regions.append(region);
2937 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
2939 // RenderTexts don't have their own style, they just use their parent's style,
2940 // so we don't want to include them.
2944 addDashboardRegions(regions);
2945 for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
2946 curr->collectDashboardRegions(regions);
2949 bool RenderObject::avoidsFloats() const
2951 return isReplaced() || hasOverflowClip() || isHR();
2954 bool RenderObject::shrinkToAvoidFloats() const
2956 // FIXME: Technically we should be able to shrink replaced elements on a line, but this is difficult to accomplish, since this
2957 // involves doing a relayout during findNextLineBreak and somehow overriding the containingBlockWidth method to return the
2958 // current remaining width on a line.
2959 if (isInline() || !avoidsFloats())
2962 // All auto-width objects that avoid floats should always use lineWidth.
2963 return style()->width().isAuto();
2966 UChar RenderObject::backslashAsCurrencySymbol() const
2968 if (Node *node = element()) {
2969 if (TextResourceDecoder* decoder = node->document()->decoder())
2970 return decoder->encoding().backslashAsCurrencySymbol();
2975 bool RenderObject::willRenderImage(CachedImage*)
2977 // Without visibility we won't render (and therefore don't care about animation).
2978 if (style()->visibility() != VISIBLE)
2981 // 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)
2982 // then we don't want to render either.
2983 return !document()->inPageCache() && document()->view()->inWindow();
2986 int RenderObject::maximalOutlineSize(PaintPhase p) const
2988 if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
2990 return static_cast<RenderView*>(document()->renderer())->maximalOutlineSize();
2993 int RenderObject::caretMinOffset() const
2998 int RenderObject::caretMaxOffset() const
3000 return isReplaced() ? 1 : 0;
3003 unsigned RenderObject::caretMaxRenderedOffset() const
3008 int RenderObject::previousOffset(int current) const
3013 int RenderObject::nextOffset(int current) const
3018 InlineBox* RenderObject::inlineBox(int offset, EAffinity affinity)
3020 return inlineBoxWrapper();
3023 int RenderObject::maxTopMargin(bool positive) const
3025 return positive ? max(0, marginTop()) : -min(0, marginTop());
3028 int RenderObject::maxBottomMargin(bool positive) const
3030 return positive ? max(0, marginBottom()) : -min(0, marginBottom());
3033 IntRect RenderObject::contentBox() const
3035 return IntRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(),
3036 contentWidth(), contentHeight());
3039 IntRect RenderObject::absoluteContentBox() const
3041 IntRect rect = contentBox();
3043 absolutePositionForContent(x, y);
3048 IntRect RenderObject::absoluteOutlineBox() const
3050 IntRect box = borderBox();
3052 absolutePosition(x, y);
3054 box.inflate(style()->outlineSize());
3060 FloatRect RenderObject::relativeBBox(bool) const
3065 AffineTransform RenderObject::localTransform() const
3067 return AffineTransform(1, 0, 0, 1, xPos(), yPos());
3070 void RenderObject::setLocalTransform(const AffineTransform&)
3075 AffineTransform RenderObject::absoluteTransform() const
3078 return localTransform() * parent()->absoluteTransform();
3079 return localTransform();
3082 #endif // ENABLE(SVG)
3084 } // namespace WebCore
3088 void showTree(const WebCore::RenderObject* ro)
3091 ro->showTreeForThis();