diff options
Diffstat (limited to 'WebCore/rendering/RenderObject.cpp')
-rw-r--r-- | WebCore/rendering/RenderObject.cpp | 145 |
1 files changed, 106 insertions, 39 deletions
diff --git a/WebCore/rendering/RenderObject.cpp b/WebCore/rendering/RenderObject.cpp index 21ced26..712519b 100644 --- a/WebCore/rendering/RenderObject.cpp +++ b/WebCore/rendering/RenderObject.cpp @@ -4,6 +4,7 @@ * (C) 2000 Dirk Mueller (mueller@kde.org) * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * * This library is free software; you can redistribute it and/or @@ -41,6 +42,8 @@ #include "RenderImageGeneratedContent.h" #include "RenderInline.h" #include "RenderListItem.h" +#include "RenderRuby.h" +#include "RenderRubyText.h" #include "RenderTableCell.h" #include "RenderTableCol.h" #include "RenderTableRow.h" @@ -106,46 +109,42 @@ RenderObject* RenderObject::createObject(Node* node, RenderStyle* style) return image; } - RenderObject* o = 0; + if (node->hasTagName(rubyTag)) { + if (style->display() == INLINE) + return new (arena) RenderRubyAsInline(node); + else + return new (arena) RenderRubyAsBlock(node); + } + // treat <rt> as ruby text ONLY if it still has its default treatment of block + if (node->hasTagName(rtTag) && style->display() == BLOCK) + return new (arena) RenderRubyText(node); switch (style->display()) { case NONE: - break; + return 0; case INLINE: - o = new (arena) RenderInline(node); - break; + return new (arena) RenderInline(node); case BLOCK: - o = new (arena) RenderBlock(node); - break; case INLINE_BLOCK: - o = new (arena) RenderBlock(node); - break; - case LIST_ITEM: - o = new (arena) RenderListItem(node); - break; case RUN_IN: case COMPACT: - o = new (arena) RenderBlock(node); - break; + return new (arena) RenderBlock(node); + case LIST_ITEM: + return new (arena) RenderListItem(node); case TABLE: case INLINE_TABLE: - o = new (arena) RenderTable(node); - break; + return new (arena) RenderTable(node); case TABLE_ROW_GROUP: case TABLE_HEADER_GROUP: case TABLE_FOOTER_GROUP: - o = new (arena) RenderTableSection(node); - break; + return new (arena) RenderTableSection(node); case TABLE_ROW: - o = new (arena) RenderTableRow(node); - break; + return new (arena) RenderTableRow(node); case TABLE_COLUMN_GROUP: case TABLE_COLUMN: - o = new (arena) RenderTableCol(node); - break; + return new (arena) RenderTableCol(node); case TABLE_CELL: - o = new (arena) RenderTableCell(node); - break; + return new (arena) RenderTableCell(node); case TABLE_CAPTION: #if ENABLE(WCSS) // As per the section 17.1 of the spec WAP-239-WCSS-20011026-a.pdf, @@ -153,15 +152,13 @@ RenderObject* RenderObject::createObject(Node* node, RenderStyle* style) // principal block box ([CSS2] section 9.2.1). case WAP_MARQUEE: #endif - o = new (arena) RenderBlock(node); - break; + return new (arena) RenderBlock(node); case BOX: case INLINE_BOX: - o = new (arena) RenderFlexibleBox(node); - break; + return new (arena) RenderFlexibleBox(node); } - return o; + return 0; } #ifndef NDEBUG @@ -646,7 +643,7 @@ RenderBlock* RenderObject::containingBlock() const } if (!o || !o->isRenderBlock()) - return 0; // Probably doesn't happen any more, but leave just in case. -dwh + return 0; // This can still happen in case of an orphaned tree return toRenderBlock(o); } @@ -722,7 +719,7 @@ void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, return; case DOTTED: case DASHED: - graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeColor(c, m_style->colorSpace()); graphicsContext->setStrokeThickness(width); graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke); @@ -743,7 +740,7 @@ void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, if (adjbw1 == 0 && adjbw2 == 0) { graphicsContext->setStrokeStyle(NoStroke); - graphicsContext->setFillColor(c); + graphicsContext->setFillColor(c, m_style->colorSpace()); switch (s) { case BSTop: case BSBottom: @@ -856,7 +853,7 @@ void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, // fall through case SOLID: { graphicsContext->setStrokeStyle(NoStroke); - graphicsContext->setFillColor(c); + graphicsContext->setFillColor(c, m_style->colorSpace()); ASSERT(x2 >= x1); ASSERT(y2 >= y1); if (!adjbw1 && !adjbw2) { @@ -916,7 +913,7 @@ void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, in return; case DOTTED: case DASHED: - graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeColor(c, m_style->colorSpace()); graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke); graphicsContext->setStrokeThickness(thickness); graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); @@ -938,7 +935,7 @@ void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, in } graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeColor(c, m_style->colorSpace()); graphicsContext->setStrokeThickness(third); graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan); graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird); @@ -957,13 +954,13 @@ void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, in } graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeColor(c, m_style->colorSpace()); 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->setStrokeColor(c2, m_style->colorSpace()); graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness); graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2, (radius.height() - shiftForInner) * 2), angleStart, angleSpan); @@ -977,7 +974,7 @@ void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, in c = c.dark(); case SOLID: graphicsContext->setStrokeStyle(SolidStroke); - graphicsContext->setStrokeColor(c); + graphicsContext->setStrokeColor(c, m_style->colorSpace()); graphicsContext->setStrokeThickness(thickness); graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); break; @@ -1341,6 +1338,50 @@ void RenderObject::showTreeForThis() const node()->showTreeForThis(); } +void RenderObject::showRenderObject() const +{ + showRenderObject(0); +} + +void RenderObject::showRenderObject(int printedCharacters) const +{ + // As this function is intended to be used when debugging, the + // this pointer may be 0. + if (!this) { + fputs("(null)\n", stderr); + return; + } + + printedCharacters += fprintf(stderr, "%s %p", renderName(), this); + + if (node()) { + if (printedCharacters) + for (; printedCharacters < 39; printedCharacters++) + fputc(' ', stderr); + fputc('\t', stderr); + node()->showNode(); + } else + fputc('\n', stderr); +} + +void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const +{ + int printedCharacters = 0; + if (markedObject1 == this && markedLabel1) + printedCharacters += fprintf(stderr, "%s", markedLabel1); + if (markedObject2 == this && markedLabel2) + printedCharacters += fprintf(stderr, "%s", markedLabel2); + for (; printedCharacters < depth * 2; printedCharacters++) + fputc(' ', stderr); + + showRenderObject(printedCharacters); + if (!this) + return; + + for (const RenderObject* child = firstChild(); child; child = child->nextSibling()) + child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1); +} + #endif // NDEBUG Color RenderObject::selectionBackgroundColor() const @@ -2372,9 +2413,20 @@ RenderBoxModelObject* RenderObject::offsetParent() const VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity) { - // If this is a non-anonymous renderer, then it's simple. - if (Node* node = this->node()) + // If this is a non-anonymous renderer in an editable area, then it's simple. + if (Node* node = this->node()) { + if (!node->isContentEditable()) { + // If it can be found, we prefer a visually equivalent position that is editable. + Position position(node, offset); + Position candidate = position.downstream(Position::CanCrossEditingBoundary); + if (candidate.node()->isContentEditable()) + return VisiblePosition(candidate, affinity); + candidate = position.upstream(Position::CanCrossEditingBoundary); + if (candidate.node()->isContentEditable()) + return VisiblePosition(candidate, affinity); + } 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 @@ -2476,4 +2528,19 @@ void showTree(const WebCore::RenderObject* ro) ro->showTreeForThis(); } +void showRenderTree(const WebCore::RenderObject* object1) +{ + showRenderTree(object1, 0); +} + +void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2) +{ + if (object1) { + const WebCore::RenderObject* root = object1; + while (root->parent()) + root = root->parent(); + root->showRenderTreeAndMark(object1, "*", object2, "-", 0); + } +} + #endif |