diff options
Diffstat (limited to 'WebCore/rendering/RenderObject.cpp')
-rw-r--r-- | WebCore/rendering/RenderObject.cpp | 1819 |
1 files changed, 661 insertions, 1158 deletions
diff --git a/WebCore/rendering/RenderObject.cpp b/WebCore/rendering/RenderObject.cpp index ea84f33..a9f6693 100644 --- a/WebCore/rendering/RenderObject.cpp +++ b/WebCore/rendering/RenderObject.cpp @@ -28,6 +28,7 @@ #include "AXObjectCache.h" #include "CSSStyleSelector.h" #include "FloatQuad.h" +#include "Frame.h" #include "FrameView.h" #include "GraphicsContext.h" #include "HTMLNames.h" @@ -44,12 +45,18 @@ #include "RenderTableRow.h" #include "RenderTheme.h" #include "RenderView.h" +#include "TransformState.h" #include <algorithm> #ifdef ANDROID_LAYOUT #include "Settings.h" #endif #include <stdio.h> #include <wtf/RefCountedLeakCounter.h> +#include <wtf/UnusedParam.h> + +#if USE(ACCELERATED_COMPOSITING) +#include "RenderLayerCompositor.h" +#endif #if ENABLE(WML) #include "WMLNames.h" @@ -89,10 +96,10 @@ RenderObject* RenderObject::createObject(Node* node, RenderStyle* style) // Works only if we have exactly one piece of content and it's a URL. // Otherwise acts as if we didn't support this feature. const ContentData* contentData = style->contentData(); - if (contentData && !contentData->m_next && contentData->m_type == CONTENT_OBJECT && doc != node) { + if (contentData && !contentData->next() && contentData->isImage() && doc != node) { RenderImageGeneratedContent* image = new (arena) RenderImageGeneratedContent(node); image->setStyle(style); - if (StyleImage* styleImage = contentData->m_content.m_image) + if (StyleImage* styleImage = contentData->image()) image->setStyleImage(styleImage); return image; } @@ -164,7 +171,6 @@ RenderObject::RenderObject(Node* node) , m_hasAXObject(false) , m_setNeedsLayoutForbidden(false) #endif - , m_verticalPosition(PositionUndefined) , m_needsLayout(false) , m_needsPositionedMovementLayout(false) , m_normalChildNeedsLayout(false) @@ -187,10 +193,19 @@ RenderObject::RenderObject(Node* node) , m_hasOverrideSize(false) , m_hasCounterNodeMap(false) , m_everHadLayout(false) + , m_childrenInline(false) + , m_topMarginQuirk(false) + , m_bottomMarginQuirk(false) + , m_hasMarkupTruncation(false) + , m_selectionState(SelectionNone) + , m_hasColumns(false) + , m_cellWidthChanged(false) + , m_replacedHasOverflow(false) { #ifndef NDEBUG renderObjectCounter.increment(); #endif + ASSERT(node); } RenderObject::~RenderObject() @@ -213,58 +228,95 @@ bool RenderObject::isDescendantOf(const RenderObject* obj) const bool RenderObject::isBody() const { - return node()->hasTagName(bodyTag); + return node() && node()->hasTagName(bodyTag); } bool RenderObject::isHR() const { - return element() && element()->hasTagName(hrTag); + return node() && node()->hasTagName(hrTag); } bool RenderObject::isHTMLMarquee() const { - return element() && element()->renderer() == this && element()->hasTagName(marqueeTag); -} - -bool RenderObject::canHaveChildren() const -{ - return false; -} - -bool RenderObject::isInlineContinuation() const -{ - return false; + return node() && node()->renderer() == this && node()->hasTagName(marqueeTag); } -void RenderObject::addChild(RenderObject*, RenderObject*) +static void updateListMarkerNumbers(RenderObject* child) { - ASSERT_NOT_REACHED(); + for (RenderObject* r = child; r; r = r->nextSibling()) + if (r->isListItem()) + static_cast<RenderListItem*>(r)->updateValue(); } -RenderObject* RenderObject::removeChildNode(RenderObject*, bool) +void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild) { - ASSERT_NOT_REACHED(); - return 0; -} - -void RenderObject::removeChild(RenderObject*) -{ - ASSERT_NOT_REACHED(); -} + RenderObjectChildList* children = virtualChildren(); + ASSERT(children); + if (!children) + return; -void RenderObject::moveChildNode(RenderObject*) -{ - ASSERT_NOT_REACHED(); + bool needsTable = false; + + if (newChild->isListItem()) + updateListMarkerNumbers(beforeChild ? beforeChild : children->lastChild()); + else if (newChild->isTableCol() && newChild->style()->display() == TABLE_COLUMN_GROUP) + needsTable = !isTable(); + else if (newChild->isRenderBlock() && newChild->style()->display() == TABLE_CAPTION) + needsTable = !isTable(); + else if (newChild->isTableSection()) + needsTable = !isTable(); + else if (newChild->isTableRow()) + needsTable = !isTableSection(); + else if (newChild->isTableCell()) { + needsTable = !isTableRow(); + // I'm not 100% sure this is the best way to fix this, but without this + // change we recurse infinitely when trying to render the CSS2 test page: + // http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/htmlbodyheadrendering2.html. + // See Radar 2925291. + if (needsTable && isTableCell() && !children->firstChild() && !newChild->isTableCell()) + needsTable = false; + } + + if (needsTable) { + RenderTable* table; + RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild(); + if (afterChild && afterChild->isAnonymous() && afterChild->isTable()) + table = static_cast<RenderTable*>(afterChild); + else { + table = new (renderArena()) RenderTable(document() /* is anonymous */); + RefPtr<RenderStyle> newStyle = RenderStyle::create(); + newStyle->inheritFrom(style()); + newStyle->setDisplay(TABLE); + table->setStyle(newStyle.release()); + addChild(table, beforeChild); + } + table->addChild(newChild); + } else { + // Just add it... + children->insertChildNode(this, newChild, beforeChild); + } + + if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE) { + RefPtr<StringImpl> textToTransform = toRenderText(newChild)->originalText(); + if (textToTransform) + toRenderText(newChild)->setText(textToTransform.release(), true); + } } -void RenderObject::appendChildNode(RenderObject*, bool) +void RenderObject::removeChild(RenderObject* oldChild) { - ASSERT_NOT_REACHED(); -} + RenderObjectChildList* children = virtualChildren(); + ASSERT(children); + if (!children) + return; -void RenderObject::insertChildNode(RenderObject*, RenderObject*, bool) -{ - ASSERT_NOT_REACHED(); + // We do this here instead of in removeChildNode, since the only extremely low-level uses of remove/appendChildNode + // cannot affect the positioned object list, and the floating object list is irrelevant (since the list gets cleared on + // layout anyway). + if (oldChild->isFloatingOrPositioned()) + toRenderBox(oldChild)->removeFloatingOrPositionedChildFromBlockLists(); + + children->removeChildNode(this, oldChild); } RenderObject* RenderObject::nextInPreOrder() const @@ -336,20 +388,6 @@ RenderObject* RenderObject::childAt(unsigned index) const return child; } -bool RenderObject::isEditable() const -{ - RenderText* textRenderer = 0; - if (isText()) - textRenderer = toRenderText(const_cast<RenderObject*>(this)); - - return style()->visibility() == VISIBLE && - element() && element()->isContentEditable() && - ((isBlockFlow() && !firstChild()) || - isReplaced() || - isBR() || - (textRenderer && textRenderer->firstTextBox())); -} - RenderObject* RenderObject::firstLeafChild() const { RenderObject* r = firstChild(); @@ -387,7 +425,7 @@ static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject* beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject); newObject = 0; } - parentLayer->addChild(toRenderBox(obj)->layer(), beforeChild); + parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild); return; } @@ -411,7 +449,7 @@ void RenderObject::removeLayers(RenderLayer* parentLayer) return; if (hasLayer()) { - parentLayer->removeChild(toRenderBox(this)->layer()); + parentLayer->removeChild(toRenderBoxModelObject(this)->layer()); return; } @@ -425,7 +463,7 @@ void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent) return; if (hasLayer()) { - RenderLayer* layer = toRenderBox(this)->layer(); + RenderLayer* layer = toRenderBoxModelObject(this)->layer(); if (oldParent) oldParent->removeChild(layer); newParent->addChild(layer); @@ -444,7 +482,7 @@ RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* return 0; // Step 1: If our layer is a child of the desired parent, then return our layer. - RenderLayer* ourLayer = hasLayer() ? toRenderBox(this)->layer() : 0; + RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0; if (ourLayer && ourLayer->parent() == parentLayer) return ourLayer; @@ -476,7 +514,7 @@ RenderLayer* RenderObject::enclosingLayer() const { const RenderObject* curr = this; while (curr) { - RenderLayer* layer = curr->hasLayer() ? toRenderBox(curr)->layer() : 0; + RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0; if (layer) return layer; curr = curr->parent(); @@ -484,6 +522,18 @@ RenderLayer* RenderObject::enclosingLayer() const return 0; } +RenderLayer* RenderObject::enclosingSelfPaintingLayer() const +{ + const RenderObject* curr = this; + while (curr) { + RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0; + if (layer && layer->isSelfPaintingLayer()) + return layer; + curr = curr->parent(); + } + return 0; +} + RenderBox* RenderObject::enclosingBox() const { RenderObject* curr = const_cast<RenderObject*>(this); @@ -502,16 +552,6 @@ RenderBlock* RenderObject::firstLineBlock() const return 0; } -bool RenderObject::hasStaticX() const -{ - return (style()->left().isAuto() && style()->right().isAuto()) || style()->left().isStatic() || style()->right().isStatic(); -} - -bool RenderObject::hasStaticY() const -{ - return (style()->top().isAuto() && style()->bottom().isAuto()) || style()->top().isStatic(); -} - void RenderObject::setPrefWidthsDirty(bool b, bool markParents) { bool alreadyDirty = m_prefWidthsDirty; @@ -526,113 +566,25 @@ void RenderObject::invalidateContainerPrefWidths() // in the chain that we mark dirty (even though they're kind of irrelevant). RenderObject* o = isTableCell() ? containingBlock() : container(); while (o && !o->m_prefWidthsDirty) { + // Don't invalidate the outermost object of an unrooted subtree. That object will be + // invalidated when the subtree is added to the document. + RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container(); + if (!container && !o->isRenderView()) + break; + o->m_prefWidthsDirty = true; if (o->style()->position() == FixedPosition || o->style()->position() == AbsolutePosition) // A positioned object has no effect on the min/max width of its containing block ever. // We can optimize this case and not go up any further. break; - o = o->isTableCell() ? o->containingBlock() : o->container(); - } -} - -void RenderObject::setNeedsLayout(bool b, bool markParents) -{ - bool alreadyNeededLayout = m_needsLayout; - m_needsLayout = b; - if (b) { - ASSERT(!isSetNeedsLayoutForbidden()); - if (!alreadyNeededLayout) { - if (markParents) - markContainingBlocksForLayout(); - if (hasLayer()) - toRenderBox(this)->layer()->setNeedsFullRepaint(); - } - } else { - m_everHadLayout = true; - m_posChildNeedsLayout = false; - m_normalChildNeedsLayout = false; - m_needsPositionedMovementLayout = false; - } -} - -void RenderObject::setChildNeedsLayout(bool b, bool markParents) -{ - bool alreadyNeededLayout = m_normalChildNeedsLayout; - m_normalChildNeedsLayout = b; - if (b) { - ASSERT(!isSetNeedsLayoutForbidden()); - if (!alreadyNeededLayout && markParents) - markContainingBlocksForLayout(); - } else { - m_posChildNeedsLayout = false; - m_normalChildNeedsLayout = false; - m_needsPositionedMovementLayout = false; - } -} - -void RenderObject::setNeedsPositionedMovementLayout() -{ - bool alreadyNeededLayout = needsLayout(); - m_needsPositionedMovementLayout = true; - if (!alreadyNeededLayout) { - markContainingBlocksForLayout(); - if (hasLayer()) - toRenderBox(this)->layer()->setNeedsFullRepaint(); + o = container; } } -static inline bool objectIsRelayoutBoundary(const RenderObject *obj) +void RenderObject::setLayerNeedsFullRepaint() { - // FIXME: In future it may be possible to broaden this condition in order to improve performance. - // Table cells are excluded because even when their CSS height is fixed, their height() - // may depend on their contents. - return obj->isTextField() || obj->isTextArea() - || obj->hasOverflowClip() && !obj->style()->width().isIntrinsicOrAuto() && !obj->style()->height().isIntrinsicOrAuto() && !obj->style()->height().isPercent() && !obj->isTableCell() -#if ENABLE(SVG) - || obj->isSVGRoot() -#endif - ; -} - -void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot) -{ - ASSERT(!scheduleRelayout || !newRoot); - - RenderObject* o = container(); - RenderObject* last = this; - - while (o) { - if (!last->isText() && (last->style()->position() == FixedPosition || last->style()->position() == AbsolutePosition)) { - if (last->hasStaticY()) { - RenderObject* parent = last->parent(); - if (!parent->normalChildNeedsLayout()) { - parent->setChildNeedsLayout(true, false); - if (parent != newRoot) - parent->markContainingBlocksForLayout(scheduleRelayout, newRoot); - } - } - if (o->m_posChildNeedsLayout) - return; - o->m_posChildNeedsLayout = true; - ASSERT(!o->isSetNeedsLayoutForbidden()); - } else { - if (o->m_normalChildNeedsLayout) - return; - o->m_normalChildNeedsLayout = true; - ASSERT(!o->isSetNeedsLayoutForbidden()); - } - - if (o == newRoot) - return; - - last = o; - if (scheduleRelayout && objectIsRelayoutBoundary(last)) - break; - o = o->container(); - } - - if (scheduleRelayout) - last->scheduleRelayout(); + ASSERT(hasLayer()); + toRenderBoxModelObject(this)->layer()->setNeedsFullRepaint(true); } RenderBlock* RenderObject::containingBlock() const @@ -645,7 +597,7 @@ RenderBlock* RenderObject::containingBlock() const } if (isRenderView()) - return const_cast<RenderBlock*>(static_cast<const RenderBlock*>(this)); + return const_cast<RenderView*>(toRenderView(this)); RenderObject* o = parent(); if (!isText() && m_style->position() == FixedPosition) { @@ -675,19 +627,7 @@ RenderBlock* RenderObject::containingBlock() const if (!o || !o->isRenderBlock()) return 0; // Probably doesn't happen any more, but leave just in case. -dwh - return static_cast<RenderBlock*>(o); -} - -int RenderObject::containingBlockWidth() const -{ - // FIXME ? - return containingBlock()->availableWidth(); -} - -int RenderObject::containingBlockHeight() const -{ - // FIXME ? - return containingBlock()->contentHeight(); + return toRenderBlock(o); } static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer) @@ -736,97 +676,9 @@ bool RenderObject::mustRepaintBackgroundOrBorder() const return false; } -void RenderObject::drawBorderArc(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius, - int angleStart, int angleSpan, BorderSide s, Color c, const Color& textColor, - EBorderStyle style, bool firstCorner) -{ - if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2)) - style = SOLID; - - if (!c.isValid()) { - if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE) - c.setRGB(238, 238, 238); - else - c = textColor; - } - - switch (style) { - case BNONE: - case BHIDDEN: - return; - case DOTTED: - case DASHED: - graphicsContext->setStrokeColor(c); - graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke); - graphicsContext->setStrokeThickness(thickness); - graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); - break; - case DOUBLE: { - float third = thickness / 3.0f; - float innerThird = (thickness + 1.0f) / 6.0f; - int shiftForInner = static_cast<int>(innerThird * 2.5f); - - int outerY = y; - int outerHeight = radius.height() * 2; - int innerX = x + shiftForInner; - int innerY = y + shiftForInner; - int innerWidth = (radius.width() - shiftForInner) * 2; - int innerHeight = (radius.height() - shiftForInner) * 2; - if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) { - outerHeight += 2; - innerHeight += 2; - } - - graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); - graphicsContext->setStrokeThickness(third); - graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan); - graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird); - graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan); - break; - } - case GROOVE: - case RIDGE: { - Color c2; - if ((style == RIDGE && (s == BSTop || s == BSLeft)) || - (style == GROOVE && (s == BSBottom || s == BSRight))) - c2 = c.dark(); - else { - c2 = c; - c = c.dark(); - } - - graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); - graphicsContext->setStrokeThickness(thickness); - graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); - - float halfThickness = (thickness + 1.0f) / 4.0f; - int shiftForInner = static_cast<int>(halfThickness * 1.5f); - graphicsContext->setStrokeColor(c2); - graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness); - graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2, - (radius.height() - shiftForInner) * 2), angleStart, angleSpan); - break; - } - case INSET: - if (s == BSTop || s == BSLeft) - c = c.dark(); - case OUTSET: - if (style == OUTSET && (s == BSBottom || s == BSRight)) - c = c.dark(); - case SOLID: - graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); - graphicsContext->setStrokeThickness(thickness); - graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); - break; - } -} - -void RenderObject::drawBorder(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2, - BorderSide s, Color c, const Color& textcolor, EBorderStyle style, - int adjbw1, int adjbw2) +void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2, + BoxSide s, Color c, const Color& textcolor, EBorderStyle style, + int adjbw1, int adjbw2) { int width = (s == BSTop || s == BSBottom ? y2 - y1 : x2 - x1); @@ -889,34 +741,34 @@ void RenderObject::drawBorder(GraphicsContext* graphicsContext, int x1, int y1, switch (s) { case BSTop: - drawBorder(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third, s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); - drawBorder(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2, s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); break; case BSLeft: - drawBorder(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0), x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0), s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); - drawBorder(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0), x2, y2 - max((adjbw2 * 2 + 1) / 3, 0), s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); break; case BSBottom: - drawBorder(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third, s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); - drawBorder(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2, s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); break; case BSRight: - drawBorder(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0), x1 + third, y2 - max(( adjbw2 * 2 + 1) / 3, 0), s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); - drawBorder(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0), + drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0), x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0), s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); break; @@ -944,27 +796,27 @@ void RenderObject::drawBorder(GraphicsContext* graphicsContext, int x1, int y1, switch (s) { case BSTop: - drawBorder(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2, + drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2, s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf); - drawBorder(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2, + drawLineForBoxSide(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2, s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2); break; case BSLeft: - drawBorder(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2, + drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2, s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf); - drawBorder(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2, + drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2, s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2); break; case BSBottom: - drawBorder(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2, + drawLineForBoxSide(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2, s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf); - drawBorder(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2, + drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2, s, c, textcolor, s1, adjbw1/2, adjbw2/2); break; case BSRight: - drawBorder(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2, + drawLineForBoxSide(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2, s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf); - drawBorder(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2, + drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2, s, c, textcolor, s1, adjbw1/2, adjbw2/2); break; } @@ -1020,516 +872,91 @@ void RenderObject::drawBorder(GraphicsContext* graphicsContext, int x1, int y1, } } -bool RenderObject::paintNinePieceImage(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style, - const NinePieceImage& ninePieceImage, CompositeOperator op) -{ - StyleImage* styleImage = ninePieceImage.image(); - if (!styleImage || !styleImage->canRender(style->effectiveZoom())) - return false; - - if (!styleImage->isLoaded()) - return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either. - - // If we have a border radius, the image gets clipped to the rounded rect. - bool clipped = false; - if (style->hasBorderRadius()) { - IntRect clipRect(tx, ty, w, h); - graphicsContext->save(); - graphicsContext->addRoundedRectClip(clipRect, style->borderTopLeftRadius(), style->borderTopRightRadius(), - style->borderBottomLeftRadius(), style->borderBottomRightRadius()); - clipped = true; - } - - // FIXME: border-image is broken with full page zooming when tiling has to happen, since the tiling function - // doesn't have any understanding of the zoom that is in effect on the tile. - styleImage->setImageContainerSize(IntSize(w, h)); - IntSize imageSize = styleImage->imageSize(this, 1.0f); - int imageWidth = imageSize.width(); - int imageHeight = imageSize.height(); - - int topSlice = min(imageHeight, ninePieceImage.m_slices.top().calcValue(imageHeight)); - int bottomSlice = min(imageHeight, ninePieceImage.m_slices.bottom().calcValue(imageHeight)); - int leftSlice = min(imageWidth, ninePieceImage.m_slices.left().calcValue(imageWidth)); - int rightSlice = min(imageWidth, ninePieceImage.m_slices.right().calcValue(imageWidth)); - - ENinePieceImageRule hRule = ninePieceImage.horizontalRule(); - ENinePieceImageRule vRule = ninePieceImage.verticalRule(); - - bool fitToBorder = style->borderImage() == ninePieceImage; - - int leftWidth = fitToBorder ? style->borderLeftWidth() : leftSlice; - int topWidth = fitToBorder ? style->borderTopWidth() : topSlice; - int rightWidth = fitToBorder ? style->borderRightWidth() : rightSlice; - int bottomWidth = fitToBorder ? style->borderBottomWidth() : bottomSlice; - - bool drawLeft = leftSlice > 0 && leftWidth > 0; - bool drawTop = topSlice > 0 && topWidth > 0; - bool drawRight = rightSlice > 0 && rightWidth > 0; - bool drawBottom = bottomSlice > 0 && bottomWidth > 0; - bool drawMiddle = (imageWidth - leftSlice - rightSlice) > 0 && (w - leftWidth - rightWidth) > 0 && - (imageHeight - topSlice - bottomSlice) > 0 && (h - topWidth - bottomWidth) > 0; - - Image* image = styleImage->image(this, imageSize); - - if (drawLeft) { - // Paint the top and bottom left corners. - - // The top left corner rect is (tx, ty, leftWidth, topWidth) - // The rect to use from within the image is obtained from our slice, and is (0, 0, leftSlice, topSlice) - if (drawTop) - graphicsContext->drawImage(image, IntRect(tx, ty, leftWidth, topWidth), - IntRect(0, 0, leftSlice, topSlice), op); - - // The bottom left corner rect is (tx, ty + h - bottomWidth, leftWidth, bottomWidth) - // The rect to use from within the image is (0, imageHeight - bottomSlice, leftSlice, botomSlice) - if (drawBottom) - graphicsContext->drawImage(image, IntRect(tx, ty + h - bottomWidth, leftWidth, bottomWidth), - IntRect(0, imageHeight - bottomSlice, leftSlice, bottomSlice), op); - - // Paint the left edge. - // Have to scale and tile into the border rect. - graphicsContext->drawTiledImage(image, IntRect(tx, ty + topWidth, leftWidth, - h - topWidth - bottomWidth), - IntRect(0, topSlice, leftSlice, imageHeight - topSlice - bottomSlice), - Image::StretchTile, (Image::TileRule)vRule, op); - } - - if (drawRight) { - // Paint the top and bottom right corners - // The top right corner rect is (tx + w - rightWidth, ty, rightWidth, topWidth) - // The rect to use from within the image is obtained from our slice, and is (imageWidth - rightSlice, 0, rightSlice, topSlice) - if (drawTop) - graphicsContext->drawImage(image, IntRect(tx + w - rightWidth, ty, rightWidth, topWidth), - IntRect(imageWidth - rightSlice, 0, rightSlice, topSlice), op); - - // The bottom right corner rect is (tx + w - rightWidth, ty + h - bottomWidth, rightWidth, bottomWidth) - // The rect to use from within the image is (imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice) - if (drawBottom) - graphicsContext->drawImage(image, IntRect(tx + w - rightWidth, ty + h - bottomWidth, rightWidth, bottomWidth), - IntRect(imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice), op); - - // Paint the right edge. - graphicsContext->drawTiledImage(image, IntRect(tx + w - rightWidth, ty + topWidth, rightWidth, - h - topWidth - bottomWidth), - IntRect(imageWidth - rightSlice, topSlice, rightSlice, imageHeight - topSlice - bottomSlice), - Image::StretchTile, (Image::TileRule)vRule, op); - } - - // Paint the top edge. - if (drawTop) - graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty, w - leftWidth - rightWidth, topWidth), - IntRect(leftSlice, 0, imageWidth - rightSlice - leftSlice, topSlice), - (Image::TileRule)hRule, Image::StretchTile, op); - - // Paint the bottom edge. - if (drawBottom) - graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty + h - bottomWidth, - w - leftWidth - rightWidth, bottomWidth), - IntRect(leftSlice, imageHeight - bottomSlice, imageWidth - rightSlice - leftSlice, bottomSlice), - (Image::TileRule)hRule, Image::StretchTile, op); - - // Paint the middle. - if (drawMiddle) - graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty + topWidth, w - leftWidth - rightWidth, - h - topWidth - bottomWidth), - IntRect(leftSlice, topSlice, imageWidth - rightSlice - leftSlice, imageHeight - topSlice - bottomSlice), - (Image::TileRule)hRule, (Image::TileRule)vRule, op); - - // Clear the clip for the border radius. - if (clipped) - graphicsContext->restore(); - - return true; -} - -void RenderObject::paintBorder(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, - const RenderStyle* style, bool begin, bool end) +void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius, + int angleStart, int angleSpan, BoxSide s, Color c, const Color& textColor, + EBorderStyle style, bool firstCorner) { - if (paintNinePieceImage(graphicsContext, tx, ty, w, h, style, style->borderImage())) - return; - - const Color& tc = style->borderTopColor(); - const Color& bc = style->borderBottomColor(); - const Color& lc = style->borderLeftColor(); - const Color& rc = style->borderRightColor(); - - bool tt = style->borderTopIsTransparent(); - bool bt = style->borderBottomIsTransparent(); - bool rt = style->borderRightIsTransparent(); - bool lt = style->borderLeftIsTransparent(); - - EBorderStyle ts = style->borderTopStyle(); - EBorderStyle bs = style->borderBottomStyle(); - EBorderStyle ls = style->borderLeftStyle(); - EBorderStyle rs = style->borderRightStyle(); - - bool renderTop = ts > BHIDDEN && !tt; - bool renderLeft = ls > BHIDDEN && begin && !lt; - bool renderRight = rs > BHIDDEN && end && !rt; - bool renderBottom = bs > BHIDDEN && !bt; - - // Need sufficient width and height to contain border radius curves. Sanity check our border radii - // and our width/height values to make sure the curves can all fit. If not, then we won't paint - // any border radii. - bool renderRadii = false; - IntSize topLeft = style->borderTopLeftRadius(); - IntSize topRight = style->borderTopRightRadius(); - IntSize bottomLeft = style->borderBottomLeftRadius(); - IntSize bottomRight = style->borderBottomRightRadius(); - - if (style->hasBorderRadius() && - static_cast<unsigned>(w) >= static_cast<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()) && - static_cast<unsigned>(w) >= static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width()) && - static_cast<unsigned>(h) >= static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height()) && - static_cast<unsigned>(h) >= static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height())) - renderRadii = true; - - // Clip to the rounded rectangle. - if (renderRadii) { - graphicsContext->save(); - graphicsContext->addRoundedRectClip(IntRect(tx, ty, w, h), topLeft, topRight, bottomLeft, bottomRight); - } - - int firstAngleStart, secondAngleStart, firstAngleSpan, secondAngleSpan; - float thickness; - bool upperLeftBorderStylesMatch = renderLeft && (ts == ls) && (tc == lc); - bool upperRightBorderStylesMatch = renderRight && (ts == rs) && (tc == rc) && (ts != OUTSET) && (ts != RIDGE) && (ts != INSET) && (ts != GROOVE); - bool lowerLeftBorderStylesMatch = renderLeft && (bs == ls) && (bc == lc) && (bs != OUTSET) && (bs != RIDGE) && (bs != INSET) && (bs != GROOVE); - bool lowerRightBorderStylesMatch = renderRight && (bs == rs) && (bc == rc); - - if (renderTop) { - bool ignore_left = (renderRadii && topLeft.width() > 0) || - (tc == lc && tt == lt && ts >= OUTSET && - (ls == DOTTED || ls == DASHED || ls == SOLID || ls == OUTSET)); - - bool ignore_right = (renderRadii && topRight.width() > 0) || - (tc == rc && tt == rt && ts >= OUTSET && - (rs == DOTTED || rs == DASHED || rs == SOLID || rs == INSET)); - - int x = tx; - int x2 = tx + w; - if (renderRadii) { - x += topLeft.width(); - x2 -= topRight.width(); - } - - drawBorder(graphicsContext, x, ty, x2, ty + style->borderTopWidth(), BSTop, tc, style->color(), ts, - ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth()); - - if (renderRadii) { - int leftY = ty; - - // We make the arc double thick and let the clip rect take care of clipping the extra off. - // We're doing this because it doesn't seem possible to match the curve of the clip exactly - // with the arc-drawing function. - thickness = style->borderTopWidth() * 2; - - if (topLeft.width()) { - int leftX = tx; - // The inner clip clips inside the arc. This is especially important for 1px borders. - bool applyLeftInnerClip = (style->borderLeftWidth() < topLeft.width()) - && (style->borderTopWidth() < topLeft.height()) - && (ts != DOUBLE || style->borderTopWidth() > 6); - if (applyLeftInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, topLeft.width() * 2, topLeft.height() * 2), - style->borderTopWidth()); - } - - firstAngleStart = 90; - firstAngleSpan = upperLeftBorderStylesMatch ? 90 : 45; - - // Draw upper left arc - drawBorderArc(graphicsContext, leftX, leftY, thickness, topLeft, firstAngleStart, firstAngleSpan, - BSTop, tc, style->color(), ts, true); - if (applyLeftInnerClip) - graphicsContext->restore(); - } - - if (topRight.width()) { - int rightX = tx + w - topRight.width() * 2; - bool applyRightInnerClip = (style->borderRightWidth() < topRight.width()) - && (style->borderTopWidth() < topRight.height()) - && (ts != DOUBLE || style->borderTopWidth() > 6); - if (applyRightInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(rightX, leftY, topRight.width() * 2, topRight.height() * 2), - style->borderTopWidth()); - } - - if (upperRightBorderStylesMatch) { - secondAngleStart = 0; - secondAngleSpan = 90; - } else { - secondAngleStart = 45; - secondAngleSpan = 45; - } - - // Draw upper right arc - drawBorderArc(graphicsContext, rightX, leftY, thickness, topRight, secondAngleStart, secondAngleSpan, - BSTop, tc, style->color(), ts, false); - if (applyRightInnerClip) - graphicsContext->restore(); - } - } - } - - if (renderBottom) { - bool ignore_left = (renderRadii && bottomLeft.width() > 0) || - (bc == lc && bt == lt && bs >= OUTSET && - (ls == DOTTED || ls == DASHED || ls == SOLID || ls == OUTSET)); - - bool ignore_right = (renderRadii && bottomRight.width() > 0) || - (bc == rc && bt == rt && bs >= OUTSET && - (rs == DOTTED || rs == DASHED || rs == SOLID || rs == INSET)); - - int x = tx; - int x2 = tx + w; - if (renderRadii) { - x += bottomLeft.width(); - x2 -= bottomRight.width(); - } - - drawBorder(graphicsContext, x, ty + h - style->borderBottomWidth(), x2, ty + h, BSBottom, bc, style->color(), bs, - ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth()); - - if (renderRadii) { - thickness = style->borderBottomWidth() * 2; - - if (bottomLeft.width()) { - int leftX = tx; - int leftY = ty + h - bottomLeft.height() * 2; - bool applyLeftInnerClip = (style->borderLeftWidth() < bottomLeft.width()) - && (style->borderBottomWidth() < bottomLeft.height()) - && (bs != DOUBLE || style->borderBottomWidth() > 6); - if (applyLeftInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, bottomLeft.width() * 2, bottomLeft.height() * 2), - style->borderBottomWidth()); - } - - if (lowerLeftBorderStylesMatch) { - firstAngleStart = 180; - firstAngleSpan = 90; - } else { - firstAngleStart = 225; - firstAngleSpan = 45; - } - - // Draw lower left arc - drawBorderArc(graphicsContext, leftX, leftY, thickness, bottomLeft, firstAngleStart, firstAngleSpan, - BSBottom, bc, style->color(), bs, true); - if (applyLeftInnerClip) - graphicsContext->restore(); - } - - if (bottomRight.width()) { - int rightY = ty + h - bottomRight.height() * 2; - int rightX = tx + w - bottomRight.width() * 2; - bool applyRightInnerClip = (style->borderRightWidth() < bottomRight.width()) - && (style->borderBottomWidth() < bottomRight.height()) - && (bs != DOUBLE || style->borderBottomWidth() > 6); - if (applyRightInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(rightX, rightY, bottomRight.width() * 2, bottomRight.height() * 2), - style->borderBottomWidth()); - } - - secondAngleStart = 270; - secondAngleSpan = lowerRightBorderStylesMatch ? 90 : 45; + if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2)) + style = SOLID; - // Draw lower right arc - drawBorderArc(graphicsContext, rightX, rightY, thickness, bottomRight, secondAngleStart, secondAngleSpan, - BSBottom, bc, style->color(), bs, false); - if (applyRightInnerClip) - graphicsContext->restore(); - } - } + if (!c.isValid()) { + if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE) + c.setRGB(238, 238, 238); + else + c = textColor; } - if (renderLeft) { - bool ignore_top = (renderRadii && topLeft.height() > 0) || - (tc == lc && tt == lt && ls >= OUTSET && - (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET)); - - bool ignore_bottom = (renderRadii && bottomLeft.height() > 0) || - (bc == lc && bt == lt && ls >= OUTSET && - (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET)); - - int y = ty; - int y2 = ty + h; - if (renderRadii) { - y += topLeft.height(); - y2 -= bottomLeft.height(); - } - - drawBorder(graphicsContext, tx, y, tx + style->borderLeftWidth(), y2, BSLeft, lc, style->color(), ls, - ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth()); - - if (renderRadii && (!upperLeftBorderStylesMatch || !lowerLeftBorderStylesMatch)) { - int topX = tx; - thickness = style->borderLeftWidth() * 2; - - if (!upperLeftBorderStylesMatch && topLeft.width()) { - int topY = ty; - bool applyTopInnerClip = (style->borderLeftWidth() < topLeft.width()) - && (style->borderTopWidth() < topLeft.height()) - && (ls != DOUBLE || style->borderLeftWidth() > 6); - if (applyTopInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topLeft.width() * 2, topLeft.height() * 2), - style->borderLeftWidth()); - } - - firstAngleStart = 135; - firstAngleSpan = 45; - - // Draw top left arc - drawBorderArc(graphicsContext, topX, topY, thickness, topLeft, firstAngleStart, firstAngleSpan, - BSLeft, lc, style->color(), ls, true); - if (applyTopInnerClip) - graphicsContext->restore(); - } - - if (!lowerLeftBorderStylesMatch && bottomLeft.width()) { - int bottomY = ty + h - bottomLeft.height() * 2; - bool applyBottomInnerClip = (style->borderLeftWidth() < bottomLeft.width()) - && (style->borderBottomWidth() < bottomLeft.height()) - && (ls != DOUBLE || style->borderLeftWidth() > 6); - if (applyBottomInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(topX, bottomY, bottomLeft.width() * 2, bottomLeft.height() * 2), - style->borderLeftWidth()); - } - - secondAngleStart = 180; - secondAngleSpan = 45; + switch (style) { + case BNONE: + case BHIDDEN: + return; + case DOTTED: + case DASHED: + graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke); + graphicsContext->setStrokeThickness(thickness); + graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); + break; + case DOUBLE: { + float third = thickness / 3.0f; + float innerThird = (thickness + 1.0f) / 6.0f; + int shiftForInner = static_cast<int>(innerThird * 2.5f); - // Draw bottom left arc - drawBorderArc(graphicsContext, topX, bottomY, thickness, bottomLeft, secondAngleStart, secondAngleSpan, - BSLeft, lc, style->color(), ls, false); - if (applyBottomInnerClip) - graphicsContext->restore(); + int outerY = y; + int outerHeight = radius.height() * 2; + int innerX = x + shiftForInner; + int innerY = y + shiftForInner; + int innerWidth = (radius.width() - shiftForInner) * 2; + int innerHeight = (radius.height() - shiftForInner) * 2; + if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) { + outerHeight += 2; + innerHeight += 2; } - } - } - if (renderRight) { - bool ignore_top = (renderRadii && topRight.height() > 0) || - ((tc == rc) && (tt == rt) && - (rs >= DOTTED || rs == INSET) && - (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET)); - - bool ignore_bottom = (renderRadii && bottomRight.height() > 0) || - ((bc == rc) && (bt == rt) && - (rs >= DOTTED || rs == INSET) && - (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET)); - - int y = ty; - int y2 = ty + h; - if (renderRadii) { - y += topRight.height(); - y2 -= bottomRight.height(); + graphicsContext->setStrokeStyle(SolidStroke); + graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeThickness(third); + graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan); + graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird); + graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan); + break; } - - drawBorder(graphicsContext, tx + w - style->borderRightWidth(), y, tx + w, y2, BSRight, rc, style->color(), rs, - ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth()); - - if (renderRadii && (!upperRightBorderStylesMatch || !lowerRightBorderStylesMatch)) { - thickness = style->borderRightWidth() * 2; - - if (!upperRightBorderStylesMatch && topRight.width()) { - int topX = tx + w - topRight.width() * 2; - int topY = ty; - bool applyTopInnerClip = (style->borderRightWidth() < topRight.width()) - && (style->borderTopWidth() < topRight.height()) - && (rs != DOUBLE || style->borderRightWidth() > 6); - if (applyTopInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topRight.width() * 2, topRight.height() * 2), - style->borderRightWidth()); - } - - firstAngleStart = 0; - firstAngleSpan = 45; - - // Draw top right arc - drawBorderArc(graphicsContext, topX, topY, thickness, topRight, firstAngleStart, firstAngleSpan, - BSRight, rc, style->color(), rs, true); - if (applyTopInnerClip) - graphicsContext->restore(); - } - - if (!lowerRightBorderStylesMatch && bottomRight.width()) { - int bottomX = tx + w - bottomRight.width() * 2; - int bottomY = ty + h - bottomRight.height() * 2; - bool applyBottomInnerClip = (style->borderRightWidth() < bottomRight.width()) - && (style->borderBottomWidth() < bottomRight.height()) - && (rs != DOUBLE || style->borderRightWidth() > 6); - if (applyBottomInnerClip) { - graphicsContext->save(); - graphicsContext->addInnerRoundedRectClip(IntRect(bottomX, bottomY, bottomRight.width() * 2, bottomRight.height() * 2), - style->borderRightWidth()); - } - - secondAngleStart = 315; - secondAngleSpan = 45; - - // Draw bottom right arc - drawBorderArc(graphicsContext, bottomX, bottomY, thickness, bottomRight, secondAngleStart, secondAngleSpan, - BSRight, rc, style->color(), rs, false); - if (applyBottomInnerClip) - graphicsContext->restore(); + case GROOVE: + case RIDGE: { + Color c2; + if ((style == RIDGE && (s == BSTop || s == BSLeft)) || + (style == GROOVE && (s == BSBottom || s == BSRight))) + c2 = c.dark(); + else { + c2 = c; + c = c.dark(); } - } - } - - if (renderRadii) - graphicsContext->restore(); -} -void RenderObject::paintBoxShadow(GraphicsContext* context, int tx, int ty, int w, int h, const RenderStyle* s, bool begin, bool end) -{ - // FIXME: Deal with border-image. Would be great to use border-image as a mask. - - IntRect rect(tx, ty, w, h); - bool hasBorderRadius = s->hasBorderRadius(); - bool hasOpaqueBackground = s->backgroundColor().isValid() && s->backgroundColor().alpha() == 255; - for (ShadowData* shadow = s->boxShadow(); shadow; shadow = shadow->next) { - context->save(); - - IntSize shadowOffset(shadow->x, shadow->y); - int shadowBlur = shadow->blur; - IntRect fillRect(rect); - - if (hasBorderRadius) { - IntRect shadowRect(rect); - shadowRect.inflate(shadowBlur); - shadowRect.move(shadowOffset); - context->clip(shadowRect); - - // Move the fill just outside the clip, adding 1 pixel separation so that the fill does not - // bleed in (due to antialiasing) if the context is transformed. - IntSize extraOffset(w + max(0, shadowOffset.width()) + shadowBlur + 1, 0); - shadowOffset -= extraOffset; - fillRect.move(extraOffset); - } + graphicsContext->setStrokeStyle(SolidStroke); + graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeThickness(thickness); + graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); - context->setShadow(shadowOffset, shadowBlur, shadow->color); - if (hasBorderRadius) { - IntSize topLeft = begin ? s->borderTopLeftRadius() : IntSize(); - IntSize topRight = end ? s->borderTopRightRadius() : IntSize(); - IntSize bottomLeft = begin ? s->borderBottomLeftRadius() : IntSize(); - IntSize bottomRight = end ? s->borderBottomRightRadius() : IntSize(); - if (!hasOpaqueBackground) - context->clipOutRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight); - context->fillRoundedRect(fillRect, topLeft, topRight, bottomLeft, bottomRight, Color::black); - } else { - if (!hasOpaqueBackground) - context->clipOut(rect); - context->fillRect(fillRect, Color::black); + float halfThickness = (thickness + 1.0f) / 4.0f; + int shiftForInner = static_cast<int>(halfThickness * 1.5f); + graphicsContext->setStrokeColor(c2); + graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness); + graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2, + (radius.height() - shiftForInner) * 2), angleStart, angleSpan); + break; } - context->restore(); + case INSET: + if (s == BSTop || s == BSLeft) + c = c.dark(); + case OUTSET: + if (style == OUTSET && (s == BSBottom || s == BSRight)) + c = c.dark(); + case SOLID: + graphicsContext->setStrokeStyle(SolidStroke); + graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeThickness(thickness); + graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); + break; } } @@ -1537,13 +964,13 @@ void RenderObject::addPDFURLRect(GraphicsContext* context, const IntRect& rect) { if (rect.isEmpty()) return; - Node* node = element(); - if (!node || !node->isLink() || !node->isElementNode()) + Node* n = node(); + if (!n || !n->isLink() || !n->isElementNode()) return; - const AtomicString& href = static_cast<Element*>(node)->getAttribute(hrefAttr); + const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr); if (href.isNull()) return; - context->setURLForRect(node->document()->completeURL(href), rect); + context->setURLForRect(n->document()->completeURL(href), rect); } void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style) @@ -1564,11 +991,11 @@ void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty if (!theme()->supportsFocusRing(style)) { // Only paint the focus ring by hand if the theme isn't able to draw the focus ring. graphicsContext->initFocusRing(ow, offset); + addFocusRingRects(graphicsContext, tx, ty); if (style->outlineStyleIsAuto()) - addFocusRingRects(graphicsContext, tx, ty); + graphicsContext->drawFocusRing(oc); else addPDFURLRect(graphicsContext, graphicsContext->focusRingBoundingRect()); - graphicsContext->drawFocusRing(oc); graphicsContext->clearFocusRing(); } } @@ -1584,21 +1011,52 @@ void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty if (h < 0 || w < 0) return; - drawBorder(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow, + drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow, BSLeft, Color(oc), style->color(), os, ow, ow); - drawBorder(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty, + drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty, BSTop, Color(oc), style->color(), os, ow, ow); - drawBorder(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow, + drawLineForBoxSide(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow, BSRight, Color(oc), style->color(), os, ow, ow); - drawBorder(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow, + drawLineForBoxSide(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow, BSBottom, Color(oc), style->color(), os, ow, ow); } -void RenderObject::addLineBoxRects(Vector<IntRect>&, unsigned, unsigned, bool) + +void RenderObject::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, unsigned end, bool) { + if (!firstChild()) { + if ((isInline() || isAnonymousBlock())) { + FloatPoint absPos = localToAbsolute(FloatPoint()); + absoluteRects(rects, absPos.x(), absPos.y()); + } + return; + } + + unsigned offset = start; + for (RenderObject* child = childAt(start); child && offset < end; child = child->nextSibling(), ++offset) { + if (child->isText() || child->isInline() || child->isAnonymousBlock()) { + FloatPoint absPos = child->localToAbsolute(FloatPoint()); + child->absoluteRects(rects, absPos.x(), absPos.y()); + } + } +} + +void RenderObject::absoluteQuadsForRange(Vector<FloatQuad>& quads, unsigned start, unsigned end, bool) +{ + if (!firstChild()) { + if (isInline() || isAnonymousBlock()) + absoluteQuads(quads); + return; + } + + unsigned offset = start; + for (RenderObject* child = childAt(start); child && offset < end; child = child->nextSibling(), ++offset) { + if (child->isText() || child->isInline() || child->isAnonymousBlock()) + child->absoluteQuads(quads); + } } IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) @@ -1652,58 +1110,80 @@ void RenderObject::paint(PaintInfo& /*paintInfo*/, int /*tx*/, int /*ty*/) { } -RenderBox* RenderObject::containerForRepaint() const +RenderBoxModelObject* RenderObject::containerForRepaint() const { - // For now, all repaints are root-relative. +#if USE(ACCELERATED_COMPOSITING) + if (RenderView* v = view()) { + if (v->usesCompositing()) { + RenderLayer* compLayer = enclosingLayer()->enclosingCompositingLayer(); + return compLayer ? compLayer->renderer() : 0; + } + } +#endif + // Do root-relative repaint. return 0; } +void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const IntRect& r, bool immediate) +{ + if (!repaintContainer || repaintContainer->isRenderView()) { + RenderView* v = repaintContainer ? toRenderView(repaintContainer) : view(); + v->repaintViewRectangle(r, immediate); + } else { +#if USE(ACCELERATED_COMPOSITING) + RenderView* v = view(); + if (v->usesCompositing()) { + ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited()); + repaintContainer->layer()->setBackingNeedsRepaintInRect(r); + } +#else + ASSERT_NOT_REACHED(); +#endif + } +} + void RenderObject::repaint(bool immediate) { - // Can't use view(), since we might be unrooted. - RenderObject* o = this; - while (o->parent()) - o = o->parent(); - if (!o->isRenderView()) + // Don't repaint if we're unrooted (note that view() still returns the view when unrooted) + RenderView* view; + if (!isRooted(&view)) return; - RenderView* view = static_cast<RenderView*>(o); if (view->printing()) return; // Don't repaint if we're printing. - view->repaintViewRectangle(absoluteClippedOverflowRect(), immediate); + RenderBoxModelObject* repaintContainer = containerForRepaint(); + repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate); } void RenderObject::repaintRectangle(const IntRect& r, bool immediate) { - // Can't use view(), since we might be unrooted. - RenderObject* o = this; - while (o->parent()) - o = o->parent(); - if (!o->isRenderView()) + // Don't repaint if we're unrooted (note that view() still returns the view when unrooted) + RenderView* view; + if (!isRooted(&view)) return; - RenderView* view = static_cast<RenderView*>(o); if (view->printing()) return; // Don't repaint if we're printing. - IntRect absRect(r); + IntRect dirtyRect(r); // FIXME: layoutDelta needs to be applied in parts before/after transforms and // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308 - absRect.move(view->layoutDelta()); + dirtyRect.move(view->layoutDelta()); - computeAbsoluteRepaintRect(absRect); - view->repaintViewRectangle(absRect, immediate); + RenderBoxModelObject* repaintContainer = containerForRepaint(); + computeRectForRepaint(repaintContainer, dirtyRect); + repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate); } -bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const IntRect& oldOutlineBox) +bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const IntRect& oldBounds, const IntRect& oldOutlineBox) { RenderView* v = view(); if (v->printing()) return false; // Don't repaint if we're printing. - IntRect newBounds = absoluteClippedOverflowRect(); + IntRect newBounds = clippedOverflowRectForRepaint(repaintContainer); IntRect newOutlineBox; bool fullRepaint = selfNeedsLayout(); @@ -1711,14 +1191,18 @@ bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const In if (!fullRepaint && style()->borderFit() == BorderFitLines) fullRepaint = true; if (!fullRepaint) { - newOutlineBox = absoluteOutlineBounds(); + newOutlineBox = outlineBoundsForRepaint(repaintContainer); if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox))) fullRepaint = true; } + + if (!repaintContainer) + repaintContainer = v; + if (fullRepaint) { - v->repaintViewRectangle(oldBounds); + repaintUsingContainer(repaintContainer, oldBounds); if (newBounds != oldBounds) - v->repaintViewRectangle(newBounds); + repaintUsingContainer(repaintContainer, newBounds); return true; } @@ -1727,35 +1211,34 @@ bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const In int deltaLeft = newBounds.x() - oldBounds.x(); if (deltaLeft > 0) - v->repaintViewRectangle(IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height())); + repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height())); else if (deltaLeft < 0) - v->repaintViewRectangle(IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height())); + repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height())); int deltaRight = newBounds.right() - oldBounds.right(); if (deltaRight > 0) - v->repaintViewRectangle(IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height())); + repaintUsingContainer(repaintContainer, IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height())); else if (deltaRight < 0) - v->repaintViewRectangle(IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height())); + repaintUsingContainer(repaintContainer, IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height())); int deltaTop = newBounds.y() - oldBounds.y(); if (deltaTop > 0) - v->repaintViewRectangle(IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop)); + repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop)); else if (deltaTop < 0) - v->repaintViewRectangle(IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop)); + repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop)); int deltaBottom = newBounds.bottom() - oldBounds.bottom(); if (deltaBottom > 0) - v->repaintViewRectangle(IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom)); + repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom)); else if (deltaBottom < 0) - v->repaintViewRectangle(IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom)); + repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom)); if (newOutlineBox == oldOutlineBox) return false; // We didn't move, but we did change size. Invalidate the delta, which will consist of possibly // two rectangles (but typically only one). - RenderFlow* continuation = virtualContinuation(); - RenderStyle* outlineStyle = !isInline() && continuation ? continuation->style() : style(); + RenderStyle* outlineStyle = outlineStyleForRepaint(); int ow = outlineStyle->outlineSize(); ShadowData* boxShadow = style()->boxShadow(); int width = abs(newOutlineBox.width() - oldOutlineBox.width()); @@ -1773,7 +1256,7 @@ bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const In int right = min(newBounds.right(), oldBounds.right()); if (rightRect.x() < right) { rightRect.setWidth(min(rightRect.width(), right - rightRect.x())); - v->repaintViewRectangle(rightRect); + repaintUsingContainer(repaintContainer, rightRect); } } int height = abs(newOutlineBox.height() - oldOutlineBox.height()); @@ -1791,7 +1274,7 @@ bool RenderObject::repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const In int bottom = min(newBounds.bottom(), oldBounds.bottom()); if (bottomRect.y() < bottom) { bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y())); - v->repaintViewRectangle(bottomRect); + repaintUsingContainer(repaintContainer, bottomRect); } } return false; @@ -1813,39 +1296,27 @@ bool RenderObject::checkForRepaintDuringLayout() const return !document()->view()->needsFullRepaint() && !hasLayer(); } -IntRect RenderObject::rectWithOutlineForRepaint(RenderBox* repaintContainer, int outlineWidth) +IntRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth) { IntRect r(clippedOverflowRectForRepaint(repaintContainer)); r.inflate(outlineWidth); - - if (virtualContinuation() && !isInline()) - r.inflateY(toRenderBox(this)->collapsedMarginTop()); - - if (isRenderInline()) { - for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) { - if (!curr->isText()) - r.unite(curr->rectWithOutlineForRepaint(repaintContainer, outlineWidth)); - } - } - return r; } -IntRect RenderObject::clippedOverflowRectForRepaint(RenderBox* repaintContainer) +IntRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*) { - if (parent()) - return parent()->clippedOverflowRectForRepaint(repaintContainer); + ASSERT_NOT_REACHED(); return IntRect(); } -void RenderObject::computeRectForRepaint(IntRect& rect, RenderBox* repaintContainer, bool fixed) +void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed) { if (repaintContainer == this) return; if (RenderObject* o = parent()) { if (o->isBlockFlow()) { - RenderBlock* cb = static_cast<RenderBlock*>(o); + RenderBlock* cb = toRenderBlock(o); if (cb->hasColumns()) cb->adjustRectForColumns(rect); } @@ -1866,7 +1337,7 @@ void RenderObject::computeRectForRepaint(IntRect& rect, RenderBox* repaintContai return; } - o->computeRectForRepaint(rect, repaintContainer, fixed); + o->computeRectForRepaint(repaintContainer, rect, fixed); } } @@ -1878,8 +1349,8 @@ void RenderObject::dirtyLinesFromChangedChild(RenderObject*) void RenderObject::showTreeForThis() const { - if (element()) - element()->showTreeForThis(); + if (node()) + node()->showTreeForThis(); } #endif // NDEBUG @@ -1888,7 +1359,7 @@ Color RenderObject::selectionBackgroundColor() const { Color color; if (style()->userSelect() != SELECT_NONE) { - RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::SELECTION); + RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION); if (pseudoStyle && pseudoStyle->backgroundColor().isValid()) color = pseudoStyle->backgroundColor().blendWithWhite(); else @@ -1906,7 +1377,7 @@ Color RenderObject::selectionForegroundColor() const if (style()->userSelect() == SELECT_NONE) return color; - if (RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::SELECTION)) { + if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) { color = pseudoStyle->textFillColor(); if (!color.isValid()) color = pseudoStyle->color(); @@ -1924,7 +1395,7 @@ Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& d return 0; for (const RenderObject* curr = this; curr; curr = curr->parent()) { - Node* elt = curr->element(); + Node* elt = curr->node(); if (elt && elt->nodeType() == Node::TEXT_NODE) { // Since there's no way for the author to address the -webkit-user-drag style for a text node, // we use our own judgement. @@ -1958,17 +1429,6 @@ void RenderObject::selectionStartEnd(int& spos, int& epos) const view()->selectionStartEnd(spos, epos); } -RenderBlock* RenderObject::createAnonymousBlock() -{ - RefPtr<RenderStyle> newStyle = RenderStyle::create(); - newStyle->inheritFrom(m_style.get()); - newStyle->setDisplay(BLOCK); - - RenderBlock* newBox = new (renderArena()) RenderBlock(document() /* anonymous box */); - newBox->setStyle(newStyle.release()); - return newBox; -} - void RenderObject::handleDynamicFloatPositionChange() { // We have gone from not affecting the inline status of the parent flow to suddenly @@ -1976,30 +1436,14 @@ void RenderObject::handleDynamicFloatPositionChange() // childrenInline() state and our state. setInline(style()->isDisplayInlineType()); if (isInline() != parent()->childrenInline()) { - if (!isInline()) { - if (parent()->isRenderInline()) { - // We have to split the parent flow. - RenderInline* parentInline = static_cast<RenderInline*>(parent()); - RenderBlock* newBox = parentInline->createAnonymousBlock(); - - RenderFlow* oldContinuation = parentInline->continuation(); - parentInline->setContinuation(newBox); - - RenderObject* beforeChild = nextSibling(); - parent()->removeChildNode(this); - parentInline->splitFlow(beforeChild, newBox, this, oldContinuation); - } else if (parent()->isRenderBlock()) { - RenderBlock* o = static_cast<RenderBlock*>(parent()); - o->makeChildrenNonInline(); - if (o->isAnonymousBlock() && o->parent()) - o->parent()->removeLeftoverAnonymousBlock(o); - // o may be dead here - } - } else { + if (!isInline()) + toRenderBoxModelObject(parent())->childBecameNonInline(this); + else { // An anonymous block must be made to wrap this inline. - RenderBlock* box = createAnonymousBlock(); - parent()->insertChildNode(box, this); - box->appendChildNode(parent()->removeChildNode(this)); + RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock(); + RenderObjectChildList* childlist = parent()->virtualChildren(); + childlist->insertChildNode(parent(), block, this); + block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this)); } } } @@ -2012,18 +1456,48 @@ void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style) setStyle(style); } +StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const +{ +#if USE(ACCELERATED_COMPOSITING) + // If transform changed, and we are not composited, need to do a layout. + if (contextSensitiveProperties & ContextSensitivePropertyTransform) + // Text nodes share style with their parents but transforms don't apply to them, + // hence the !isText() check. + // FIXME: when transforms are taken into account for overflow, we will need to do a layout. + if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) + diff = StyleDifferenceLayout; + else if (diff < StyleDifferenceRecompositeLayer) + diff = StyleDifferenceRecompositeLayer; + + // If opacity changed, and we are not composited, need to repaint (also + // ignoring text nodes) + if (contextSensitiveProperties & ContextSensitivePropertyOpacity) + if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) + diff = StyleDifferenceRepaintLayer; + else if (diff < StyleDifferenceRecompositeLayer) + diff = StyleDifferenceRecompositeLayer; +#else + UNUSED_PARAM(contextSensitiveProperties); +#endif + + // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint. + if (diff == StyleDifferenceRepaintLayer && !hasLayer()) + diff = StyleDifferenceRepaint; + + return diff; +} + void RenderObject::setStyle(PassRefPtr<RenderStyle> style) { if (m_style == style) return; - RenderStyle::Diff diff = RenderStyle::Equal; + StyleDifference diff = StyleDifferenceEqual; + unsigned contextSensitiveProperties = ContextSensitivePropertyNone; if (m_style) - diff = m_style->diff(style.get()); + diff = m_style->diff(style.get(), contextSensitiveProperties); - // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint. - if (diff == RenderStyle::RepaintLayer && !hasLayer()) - diff = RenderStyle::Repaint; + diff = adjustStyleDifference(diff, contextSensitiveProperties); styleWillChange(diff, style.get()); @@ -2036,7 +1510,32 @@ void RenderObject::setStyle(PassRefPtr<RenderStyle> style) updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0); updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0); + // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen + // during styleDidChange (it's used by clippedOverflowRectForRepaint()). + if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline)) + toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize()); + styleDidChange(diff, oldStyle.get()); + + if (!m_parent || isText()) + return; + + // Now that the layer (if any) has been updated, we need to adjust the diff again, + // check whether we should layout now, and decide if we need to repaint. + StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties); + + if (diff <= StyleDifferenceLayoutPositionedMovementOnly) { + if (updatedDiff == StyleDifferenceLayout) + setNeedsLayoutAndPrefWidthsRecalc(); + else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly) + setNeedsPositionedMovementLayout(); + } + + if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) { + // Do a repaint with the new style now, e.g., for example if we go from + // not having an outline to having an outline. + repaint(); + } } void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style) @@ -2044,7 +1543,7 @@ void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style) m_style = style; } -void RenderObject::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle) +void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle) { if (m_style) { // If our z-index changes value or our visibility changes, @@ -2064,30 +1563,30 @@ void RenderObject::styleWillChange(RenderStyle::Diff diff, const RenderStyle* ne l->setHasVisibleContent(true); else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) { l->dirtyVisibleContentStatus(); - if (diff > RenderStyle::RepaintLayer) + if (diff > StyleDifferenceRepaintLayer) repaint(); } } } } - if (m_parent && (diff == RenderStyle::Repaint || newStyle->outlineSize() < m_style->outlineSize())) + if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize())) repaint(); if (isFloating() && (m_style->floating() != newStyle->floating())) // For changes in float styles, we need to conceivably remove ourselves // from the floating objects list. - removeFromObjectLists(); + toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists(); else if (isPositioned() && (newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)) // For changes in positioning styles, we need to conceivably remove ourselves // from the positioned objects list. - removeFromObjectLists(); + toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists(); s_affectsParentBlock = isFloatingOrPositioned() && (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition) && parent() && (parent()->isBlockFlow() || parent()->isRenderInline()); // reset style flags - if (diff == RenderStyle::Layout || diff == RenderStyle::LayoutPositionedMovementOnly) { + if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) { m_floating = false; m_positioned = false; m_relPositioned = false; @@ -2113,24 +1612,21 @@ void RenderObject::styleWillChange(RenderStyle::Diff diff, const RenderStyle* ne } } -void RenderObject::styleDidChange(RenderStyle::Diff diff, const RenderStyle*) +void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle*) { - setHasBoxDecorations(m_style->hasBorder() || m_style->hasBackground() || m_style->hasAppearance() || m_style->boxShadow()); - if (s_affectsParentBlock) handleDynamicFloatPositionChange(); if (!m_parent) return; - if (diff == RenderStyle::Layout) + if (diff == StyleDifferenceLayout) setNeedsLayoutAndPrefWidthsRecalc(); - else if (diff == RenderStyle::LayoutPositionedMovementOnly) + else if (diff == StyleDifferenceLayoutPositionedMovementOnly) setNeedsPositionedMovementLayout(); - else if (diff == RenderStyle::RepaintLayer || diff == RenderStyle::Repaint) - // Do a repaint with the new style now, e.g., for example if we go from - // not having an outline to having an outline. - repaint(); + + // Don't check for repaint here; we need to wait until the layer has been + // updated by subclasses before we know if we have to repaint (in setStyle()). } void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers) @@ -2163,42 +1659,93 @@ IntRect RenderObject::viewRect() const FloatPoint RenderObject::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const { + TransformState transformState(TransformState::ApplyTransformDirection, localPoint); + mapLocalToContainer(0, fixed, useTransforms, transformState); + transformState.flatten(); + + return transformState.lastPlanarPoint(); +} + +FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const +{ + TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint); + mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); + transformState.flatten(); + + return transformState.lastPlanarPoint(); +} + +void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const +{ + if (repaintContainer == this) + return; + RenderObject* o = parent(); - if (o) { - if (o->hasOverflowClip()) - localPoint -= toRenderBox(o)->layer()->scrolledContentOffset(); - return o->localToAbsolute(localPoint, fixed, useTransforms); - } + if (!o) + return; - return FloatPoint(); + if (o->hasOverflowClip()) + transformState.move(-toRenderBox(o)->layer()->scrolledContentOffset()); + + o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState); } -FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const +void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const { RenderObject* o = parent(); if (o) { - FloatPoint localPoint = o->absoluteToLocal(containerPoint, fixed, useTransforms); + o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); if (o->hasOverflowClip()) - localPoint += toRenderBox(o)->layer()->scrolledContentOffset(); - return localPoint; + transformState.move(toRenderBox(o)->layer()->scrolledContentOffset()); } - return FloatPoint(); } -FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBox* repaintContainer, bool fixed) const +TransformationMatrix RenderObject::transformFromContainer(const RenderObject* containerObject, const IntSize& offsetInContainer) const { - if (repaintContainer == this) - return localQuad; + TransformationMatrix containerTransform; +#ifdef ANDROID_FASTER_MATRIX + RenderLayer* layer; + const double tx = offsetInContainer.width(); + const double ty = offsetInContainer.height(); + if (hasLayer() && (layer = toRenderBox(this)->layer()) && layer->transform()) { + containerTransform = layer->currentTransform(); + containerTransform.translateRight(tx, ty); + } else + containerTransform.translate(tx, ty); +#else + containerTransform.translate(offsetInContainer.width(), offsetInContainer.height()); + RenderLayer* layer; + if (hasLayer() && (layer = toRenderBox(this)->layer()) && layer->transform()) + containerTransform.multLeft(layer->currentTransform()); +#endif - RenderObject* o = parent(); - if (o) { - FloatQuad quad = localQuad; - if (o->hasOverflowClip()) - quad -= toRenderBox(o)->layer()->scrolledContentOffset(); - return o->localToContainerQuad(quad, repaintContainer, fixed); +#if ENABLE(3D_RENDERING) + if (containerObject && containerObject->style()->hasPerspective()) { + // Perpsective on the container affects us, so we have to factor it in here. + ASSERT(containerObject->hasLayer()); + FloatPoint perspectiveOrigin = toRenderBox(containerObject)->layer()->perspectiveOrigin(); + + TransformationMatrix perspectiveMatrix; + perspectiveMatrix.applyPerspective(containerObject->style()->perspective()); + + containerTransform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0); + containerTransform.multiply(perspectiveMatrix); + containerTransform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0); } +#else + UNUSED_PARAM(containerObject); +#endif - return FloatQuad(); + return containerTransform; +} + +FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed) const +{ + TransformState transformState(TransformState::ApplyTransformDirection, FloatPoint(), &localQuad); + mapLocalToContainer(repaintContainer, fixed, true, transformState); + transformState.flatten(); + + return transformState.lastPlanarQuad(); } IntSize RenderObject::offsetFromContainer(RenderObject* o) const @@ -2222,12 +1769,27 @@ IntRect RenderObject::localCaretRect(InlineBox*, int, int* extraWidthToEndOfLine RenderView* RenderObject::view() const { - return static_cast<RenderView*>(document()->renderer()); + return toRenderView(document()->renderer()); +} + +bool RenderObject::isRooted(RenderView** view) +{ + RenderObject* o = this; + while (o->parent()) + o = o->parent(); + + if (!o->isRenderView()) + return false; + + if (view) + *view = toRenderView(o); + + return true; } bool RenderObject::hasOutlineAnnotation() const { - return element() && element()->isLink() && document()->printing(); + return node() && node()->isLink() && document()->printing(); } RenderObject* RenderObject::container() const @@ -2269,51 +1831,19 @@ RenderObject* RenderObject::container() const return o; } -// This code has been written to anticipate the addition of CSS3-::outside and ::inside generated -// content (and perhaps XBL). That's why it uses the render tree and not the DOM tree. -RenderObject* RenderObject::hoverAncestor() const -{ - return (!isInline() && virtualContinuation()) ? virtualContinuation() : parent(); -} - bool RenderObject::isSelectionBorder() const { SelectionState st = selectionState(); return st == SelectionStart || st == SelectionEnd || st == SelectionBoth; } -void RenderObject::removeFromObjectLists() -{ - if (documentBeingDestroyed()) - return; - - if (isFloating()) { - RenderBlock* outermostBlock = containingBlock(); - for (RenderBlock* p = outermostBlock; p && !p->isRenderView(); p = p->containingBlock()) { - if (p->containsFloat(this)) - outermostBlock = p; - } - - if (outermostBlock) - outermostBlock->markAllDescendantsWithFloatsForLayout(toRenderBox(this), false); - } - - if (isPositioned()) { - RenderObject* p; - for (p = parent(); p; p = p->parent()) { - if (p->isRenderBlock()) - static_cast<RenderBlock*>(p)->removePositionedObject(toRenderBox(this)); - } - } -} - -bool RenderObject::documentBeingDestroyed() const -{ - return !document()->renderer(); -} - void RenderObject::destroy() { + // Destroy any leftover anonymous children. + RenderObjectChildList* children = virtualChildren(); + if (children) + children->destroyLeftoverChildren(); + // If this renderer is being autoscrolled, stop the autoscroll timer if (document()->frame() && document()->frame()->eventHandler()->autoscrollRenderer() == this) document()->frame()->eventHandler()->stopAutoscrollTimer(true); @@ -2333,12 +1863,11 @@ void RenderObject::destroy() remove(); - // FIXME: Would like to do this in RenderBox, but the timing is so complicated that this can't easily - // be moved into RenderBox::destroy. - RenderArena* arena = renderArena(); + // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily + // be moved into RenderBoxModelObject::destroy. if (hasLayer()) - toRenderBox(this)->layer()->destroy(arena); - arenaDelete(arena, this); + toRenderBoxModelObject(this)->destroyLayer(); + arenaDelete(renderArena(), this); } void RenderObject::arenaDelete(RenderArena* arena, void* base) @@ -2374,14 +1903,14 @@ void RenderObject::arenaDelete(RenderArena* arena, void* base) arena->free(*(size_t*)base, base); } -VisiblePosition RenderObject::positionForCoordinates(int, int) +VisiblePosition RenderObject::positionForCoordinates(int x, int y) { - return VisiblePosition(element(), caretMinOffset(), DOWNSTREAM); + return positionForPoint(IntPoint(x, y)); } -VisiblePosition RenderObject::positionForPoint(const IntPoint& point) +VisiblePosition RenderObject::positionForPoint(const IntPoint&) { - return positionForCoordinates(point.x(), point.y()); + return createVisiblePosition(caretMinOffset(), DOWNSTREAM); } void RenderObject::updateDragState(bool dragOn) @@ -2389,12 +1918,9 @@ void RenderObject::updateDragState(bool dragOn) bool valueChanged = (dragOn != m_isDragging); m_isDragging = dragOn; if (valueChanged && style()->affectedByDragRules()) - element()->setChanged(); + node()->setChanged(); for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) curr->updateDragState(dragOn); - RenderFlow* continuation = virtualContinuation(); - if (continuation) - continuation->updateDragState(dragOn); } bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const IntPoint& point, int tx, int ty, HitTestFilter hitTestFilter) @@ -2425,34 +1951,12 @@ void RenderObject::updateHitTestResult(HitTestResult& result, const IntPoint& po if (result.innerNode()) return; - Node* node = element(); - IntPoint localPoint(point); - if (isRenderView()) - node = document()->documentElement(); - else if (!isInline() && virtualContinuation()) - // We are in the margins of block elements that are part of a continuation. In - // this case we're actually still inside the enclosing inline element that was - // split. Go ahead and set our inner node accordingly. - node = virtualContinuation()->element(); - - if (node) { - if (node->renderer() && node->renderer()->virtualContinuation() && node->renderer() != this) { - // We're in the continuation of a split inline. Adjust our local point to be in the coordinate space - // of the principal renderer's containing block. This will end up being the innerNonSharedNode. - RenderBlock* firstBlock = node->renderer()->containingBlock(); - - // Get our containing block. - RenderBox* block = toRenderBox(this); - if (isInline()) - block = containingBlock(); - - localPoint.move(block->x() - firstBlock->x(), block->y() - firstBlock->y()); - } - - result.setInnerNode(node); + Node* n = node(); + if (n) { + result.setInnerNode(n); if (!result.innerNonSharedNode()) - result.setInnerNonSharedNode(node); - result.setLocalPoint(localPoint); + result.setInnerNonSharedNode(n); + result.setLocalPoint(point); } } @@ -2461,78 +1965,9 @@ bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int /*x*/, return false; } -int RenderObject::verticalPositionHint(bool firstLine) const -{ - if (firstLine) // We're only really a first-line style if the document actually uses first-line rules. - firstLine = document()->usesFirstLineRules(); - int vpos = m_verticalPosition; - if (m_verticalPosition == PositionUndefined || firstLine) { - vpos = getVerticalPosition(firstLine); - if (!firstLine) - m_verticalPosition = vpos; - } - - return vpos; -} - -int RenderObject::getVerticalPosition(bool firstLine) const -{ - if (!isInline()) - return 0; - - // This method determines the vertical position for inline elements. - int vpos = 0; - EVerticalAlign va = style()->verticalAlign(); - if (va == TOP) - vpos = PositionTop; - else if (va == BOTTOM) - vpos = PositionBottom; - else { - bool checkParent = parent()->isInline() && !parent()->isInlineBlockOrInlineTable() && parent()->style()->verticalAlign() != TOP && parent()->style()->verticalAlign() != BOTTOM; - vpos = checkParent ? parent()->verticalPositionHint(firstLine) : 0; - // don't allow elements nested inside text-top to have a different valignment. - if (va == BASELINE) - return vpos; - - const Font& f = parent()->style(firstLine)->font(); - int fontsize = f.pixelSize(); - - if (va == SUB) - vpos += fontsize / 5 + 1; - else if (va == SUPER) - vpos -= fontsize / 3 + 1; - else if (va == TEXT_TOP) - vpos += baselinePosition(firstLine) - f.ascent(); - else if (va == MIDDLE) - vpos += -static_cast<int>(f.xHeight() / 2) - lineHeight(firstLine) / 2 + baselinePosition(firstLine); - else if (va == TEXT_BOTTOM) { - vpos += f.descent(); - if (!isReplaced()) - vpos -= style(firstLine)->font().descent(); - } else if (va == BASELINE_MIDDLE) - vpos += -lineHeight(firstLine) / 2 + baselinePosition(firstLine); - else if (va == LENGTH) - vpos -= style()->verticalAlignLength().calcValue(lineHeight(firstLine)); - } - - return vpos; -} - int RenderObject::lineHeight(bool firstLine, bool /*isRootLineBox*/) const { - RenderStyle* s = style(firstLine); - - Length lh = s->lineHeight(); - - // its "unset", choose nice default - if (lh.isNegative()) - return s->font().lineSpacing(); - - if (lh.isPercent()) - return lh.calcMinValue(s->fontSize()); - - // its fixed - return lh.value(); + return style(firstLine)->computedLineHeight(); } int RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const @@ -2544,7 +1979,7 @@ int RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const void RenderObject::scheduleRelayout() { if (isRenderView()) { - FrameView* view = static_cast<RenderView*>(this)->frameView(); + FrameView* view = toRenderView(this)->frameView(); if (view) view->scheduleRelayout(); } else if (parent()) { @@ -2554,59 +1989,42 @@ void RenderObject::scheduleRelayout() } } -void RenderObject::removeLeftoverAnonymousBlock(RenderBlock*) -{ -} - -InlineBox* RenderObject::createInlineBox(bool, bool unusedIsRootLineBox, bool) -{ - ASSERT_UNUSED(unusedIsRootLineBox, !unusedIsRootLineBox); - return new (renderArena()) InlineBox(this); -} - -void RenderObject::dirtyLineBoxes(bool, bool) -{ -} - -InlineBox* RenderObject::inlineBoxWrapper() const -{ - return 0; -} - -void RenderObject::setInlineBoxWrapper(InlineBox*) -{ -} - -void RenderObject::deleteLineBoxWrapper() +void RenderObject::layout() { + ASSERT(needsLayout()); + RenderObject* child = firstChild(); + while (child) { + child->layoutIfNeeded(); + ASSERT(!child->needsLayout()); + child = child->nextSibling(); + } + setNeedsLayout(false); } -RenderStyle* RenderObject::firstLineStyle() const +RenderStyle* RenderObject::firstLineStyleSlowCase() const { - if (!document()->usesFirstLineRules()) - return m_style.get(); + ASSERT(document()->usesFirstLineRules()); - RenderStyle* s = m_style.get(); - const RenderObject* obj = isText() ? parent() : this; - if (obj->isBlockFlow()) { - RenderBlock* firstLineBlock = obj->firstLineBlock(); - if (firstLineBlock) - s = firstLineBlock->getCachedPseudoStyle(RenderStyle::FIRST_LINE, style()); - } else if (!obj->isAnonymous() && obj->isRenderInline()) { - RenderStyle* parentStyle = obj->parent()->firstLineStyle(); - if (parentStyle != obj->parent()->style()) { - // A first-line style is in effect. We need to cache a first-line style - // for ourselves. - style()->setHasPseudoStyle(RenderStyle::FIRST_LINE_INHERITED); - s = obj->getCachedPseudoStyle(RenderStyle::FIRST_LINE_INHERITED, parentStyle); + RenderStyle* style = m_style.get(); + const RenderObject* renderer = isText() ? parent() : this; + if (renderer->isBlockFlow()) { + if (RenderBlock* firstLineBlock = renderer->firstLineBlock()) + style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style); + } else if (!renderer->isAnonymous() && renderer->isRenderInline()) { + RenderStyle* parentStyle = renderer->parent()->firstLineStyle(); + if (parentStyle != renderer->parent()->style()) { + // A first-line style is in effect. Cache a first-line style for ourselves. + style->setHasPseudoStyle(FIRST_LINE_INHERITED); + style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle); } } - return s; + + return style; } -RenderStyle* RenderObject::getCachedPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle) const +RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const { - if (pseudo < RenderStyle::FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo)) + if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo)) return 0; RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo); @@ -2619,26 +2037,26 @@ RenderStyle* RenderObject::getCachedPseudoStyle(RenderStyle::PseudoId pseudo, Re return 0; } -PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle) const +PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const { - if (pseudo < RenderStyle::FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo)) + if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo)) return 0; if (!parentStyle) parentStyle = style(); - Node* node = element(); - while (node && !node->isElementNode()) - node = node->parentNode(); - if (!node) + Node* n = node(); + while (n && !n->isElementNode()) + n = n->parentNode(); + if (!n) return 0; RefPtr<RenderStyle> result; - if (pseudo == RenderStyle::FIRST_LINE_INHERITED) { - result = document()->styleSelector()->styleForElement(static_cast<Element*>(node), parentStyle, false); - result->setStyleType(RenderStyle::FIRST_LINE_INHERITED); + if (pseudo == FIRST_LINE_INHERITED) { + result = document()->styleSelector()->styleForElement(static_cast<Element*>(n), parentStyle, false); + result->setStyleType(FIRST_LINE_INHERITED); } else - result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(node), parentStyle); + result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(n), parentStyle); return result.release(); } @@ -2681,10 +2099,10 @@ void RenderObject::getTextDecorationColors(int decorations, Color& underline, Co } } curr = curr->parent(); - if (curr && curr->isRenderBlock() && curr->virtualContinuation()) - curr = curr->virtualContinuation(); - } while (curr && decorations && (!quirksMode || !curr->element() || - (!curr->element()->hasTagName(aTag) && !curr->element()->hasTagName(fontTag)))); + if (curr && curr->isRenderBlock() && toRenderBlock(curr)->inlineContinuation()) + curr = toRenderBlock(curr)->inlineContinuation(); + } while (curr && decorations && (!quirksMode || !curr->node() || + (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag)))); // If we bailed out, use the element we bailed out at (typically a <font> or <a> element). if (decorations && curr) { @@ -2697,10 +2115,6 @@ void RenderObject::getTextDecorationColors(int decorations, Color& underline, Co } } -void RenderObject::updateWidgetPosition() -{ -} - #if ENABLE(DASHBOARD_SUPPORT) void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions) { @@ -2762,23 +2176,6 @@ void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions } #endif -bool RenderObject::avoidsFloats() const -{ - return isReplaced() || hasOverflowClip() || isHR(); -} - -bool RenderObject::shrinkToAvoidFloats() const -{ - // FIXME: Technically we should be able to shrink replaced elements on a line, but this is difficult to accomplish, since this - // involves doing a relayout during findNextLineBreak and somehow overriding the containingBlockWidth method to return the - // current remaining width on a line. - if (isInline() && !isHTMLMarquee() || !avoidsFloats()) - return false; - - // All auto-width objects that avoid floats should always use lineWidth. - return style()->width().isAuto(); -} - bool RenderObject::willRenderImage(CachedImage*) { // Without visibility we won't render (and therefore don't care about animation). @@ -2794,7 +2191,7 @@ int RenderObject::maximalOutlineSize(PaintPhase p) const { if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines) return 0; - return static_cast<RenderView*>(document()->renderer())->maximalOutlineSize(); + return toRenderView(document()->renderer())->maximalOutlineSize(); } int RenderObject::caretMinOffset() const @@ -2805,7 +2202,7 @@ int RenderObject::caretMinOffset() const int RenderObject::caretMaxOffset() const { if (isReplaced()) - return element() ? max(1U, element()->childNodeCount()) : 1; + return node() ? max(1U, node()->childNodeCount()) : 1; if (isHR()) return 1; return 0; @@ -2821,6 +2218,11 @@ int RenderObject::previousOffset(int current) const return current - 1; } +int RenderObject::previousOffsetForBackwardDeletion(int current) const +{ + return current - 1; +} + int RenderObject::nextOffset(int current) const { return current + 1; @@ -2828,7 +2230,7 @@ int RenderObject::nextOffset(int current) const void RenderObject::adjustRectForOutlineAndShadow(IntRect& rect) const { - int outlineSize = !isInline() && virtualContinuation() ? virtualContinuation()->style()->outlineSize() : style()->outlineSize(); + int outlineSize = outlineStyleForRepaint()->outlineSize(); if (ShadowData* boxShadow = style()->boxShadow()) { int shadowLeft = 0; int shadowRight = 0; @@ -2861,6 +2263,107 @@ void RenderObject::imageChanged(CachedImage* image, const IntRect* rect) imageChanged(static_cast<WrappedImagePtr>(image), rect); } +RenderBoxModelObject* RenderObject::offsetParent() const +{ + // If any of the following holds true return null and stop this algorithm: + // A is the root element. + // A is the HTML body element. + // The computed value of the position property for element A is fixed. + if (isRoot() || isBody() || (isPositioned() && style()->position() == FixedPosition)) + return 0; + + // If A is an area HTML element which has a map HTML element somewhere in the ancestor + // chain return the nearest ancestor map HTML element and stop this algorithm. + // FIXME: Implement! + + // Return the nearest ancestor element of A for which at least one of the following is + // true and stop this algorithm if such an ancestor is found: + // * The computed value of the position property is not static. + // * It is the HTML body element. + // * The computed value of the position property of A is static and the ancestor + // is one of the following HTML elements: td, th, or table. + // * Our own extension: if there is a difference in the effective zoom + bool skipTables = isPositioned() || isRelPositioned(); + float currZoom = style()->effectiveZoom(); + RenderObject* curr = parent(); + while (curr && (!curr->node() || + (!curr->isPositioned() && !curr->isRelPositioned() && !curr->isBody()))) { + Node* element = curr->node(); + if (!skipTables && element) { + bool isTableElement = element->hasTagName(tableTag) || + element->hasTagName(tdTag) || + element->hasTagName(thTag); + +#if ENABLE(WML) + if (!isTableElement && element->isWMLElement()) + isTableElement = element->hasTagName(WMLNames::tableTag) || + element->hasTagName(WMLNames::tdTag); +#endif + + if (isTableElement) + break; + } + + float newZoom = curr->style()->effectiveZoom(); + if (currZoom != newZoom) + break; + currZoom = newZoom; + curr = curr->parent(); + } + return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0; +} + +VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity) +{ + // If is is a non-anonymous renderer, then it's simple. + if (Node* node = this->node()) + return VisiblePosition(node, offset, affinity); + + // We don't want to cross the boundary between editable and non-editable + // regions of the document, but that is either impossible or at least + // extremely unlikely in any normal case because we stop as soon as we + // find a single non-anonymous renderer. + + // Find a nearby non-anonymous renderer. + RenderObject* child = this; + while (RenderObject* parent = child->parent()) { + // Find non-anonymous content after. + RenderObject* renderer = child; + while ((renderer = renderer->nextInPreOrder(parent))) { + if (Node* node = renderer->node()) + return VisiblePosition(node, 0, DOWNSTREAM); + } + + // Find non-anonymous content before. + renderer = child; + while ((renderer = renderer->previousInPreOrder())) { + if (renderer == parent) + break; + if (Node* node = renderer->node()) + return VisiblePosition(node, numeric_limits<int>::max(), DOWNSTREAM); + } + + // Use the parent itself unless it too is anonymous. + if (Node* node = parent->node()) + return VisiblePosition(node, 0, DOWNSTREAM); + + // Repeat at the next level up. + child = parent; + } + + // Everything was anonymous. Give up. + return VisiblePosition(); +} + +VisiblePosition RenderObject::createVisiblePosition(const Position& position) +{ + if (position.isNotNull()) + return VisiblePosition(position); + + ASSERT(!node()); + return createVisiblePosition(0, DOWNSTREAM); +} + #if ENABLE(SVG) FloatRect RenderObject::relativeBBox(bool) const |