RenderRubyBase.cpp [plain text]
#include "config.h"
#if ENABLE(RUBY)
#include "RenderRubyBase.h"
namespace WebCore {
RenderRubyBase::RenderRubyBase(Node* node)
: RenderBlock(node)
{
setInline(false);
}
RenderRubyBase::~RenderRubyBase()
{
}
bool RenderRubyBase::isChildAllowed(RenderObject* child, RenderStyle*) const
{
return child->isInline();
}
bool RenderRubyBase::hasOnlyWrappedInlineChildren(RenderObject* beforeChild) const
{
for (RenderObject* child = firstChild(); child != beforeChild; child = child->nextSibling()) {
if (!child->isFloatingOrPositioned() && !(child->isAnonymousBlock() && child->childrenInline()))
return false;
}
return true;
}
void RenderRubyBase::moveChildren(RenderRubyBase* toBase, RenderObject* fromBeforeChild)
{
ASSERT(toBase);
while (fromBeforeChild && fromBeforeChild->parent() != this)
fromBeforeChild = fromBeforeChild->parent();
if (childrenInline())
moveInlineChildren(toBase, fromBeforeChild);
else
moveBlockChildren(toBase, fromBeforeChild);
setNeedsLayoutAndPrefWidthsRecalc();
toBase->setNeedsLayoutAndPrefWidthsRecalc();
}
void RenderRubyBase::moveInlineChildren(RenderRubyBase* toBase, RenderObject* fromBeforeChild)
{
RenderBlock* toBlock;
if (toBase->childrenInline()) {
toBlock = toBase;
} else {
RenderObject* lastChild = toBase->lastChild();
if (lastChild && lastChild->isAnonymousBlock() && lastChild->childrenInline())
toBlock = toRenderBlock(lastChild);
else {
toBlock = toBase->createAnonymousBlock();
toBase->children()->appendChildNode(toBase, toBlock);
}
}
for (RenderObject* child = firstChild(); child != fromBeforeChild; child = firstChild())
moveChildTo(toBlock, toBlock->children(), child);
}
void RenderRubyBase::moveBlockChildren(RenderRubyBase* toBase, RenderObject* fromBeforeChild)
{
if (toBase->childrenInline()) {
if (hasOnlyWrappedInlineChildren(fromBeforeChild)) {
for (RenderObject* child = firstChild(); child != fromBeforeChild; child = firstChild()) {
if (child->isAnonymousBlock()) {
RenderBlock* anonBlock = toRenderBlock(child);
ASSERT(anonBlock->childrenInline());
ASSERT(!anonBlock->inlineContinuation());
anonBlock->moveAllChildrenTo(toBase, toBase->children());
anonBlock->deleteLineBoxTree();
anonBlock->destroy();
} else {
ASSERT(child->isFloatingOrPositioned());
moveChildTo(toBase, toBase->children(), child);
}
}
} else {
toBase->makeChildrenNonInline();
mergeBlockChildren(toBase, fromBeforeChild);
if (hasOnlyWrappedInlineChildren()) {
RenderObject* next = 0;
for (RenderObject* child = firstChild(); child; child = next) {
next = child->nextSibling();
if (child->isFloatingOrPositioned())
continue;
ASSERT(child->isAnonymousBlock());
RenderBlock* anonBlock = toRenderBlock(child);
ASSERT(anonBlock->childrenInline());
ASSERT(!anonBlock->inlineContinuation());
anonBlock->moveAllChildrenTo(this, children(), anonBlock);
anonBlock->deleteLineBoxTree();
anonBlock->destroy();
}
setChildrenInline(true);
}
}
} else
mergeBlockChildren(toBase, fromBeforeChild);
}
void RenderRubyBase::mergeBlockChildren(RenderRubyBase* toBase, RenderObject* fromBeforeChild)
{
ASSERT(!childrenInline());
ASSERT(toBase);
ASSERT(!toBase->childrenInline());
if (fromBeforeChild != firstChild())
return;
RenderObject* firstChildHere = firstChild();
RenderObject* lastChildThere = toBase->lastChild();
if (firstChildHere && firstChildHere->isAnonymousBlock() && firstChildHere->childrenInline()
&& lastChildThere && lastChildThere->isAnonymousBlock() && lastChildThere->childrenInline()) {
RenderBlock* anonBlockHere = toRenderBlock(firstChildHere);
RenderBlock* anonBlockThere = toRenderBlock(lastChildThere);
anonBlockHere->moveAllChildrenTo(anonBlockThere, anonBlockThere->children());
anonBlockHere->deleteLineBoxTree();
anonBlockHere->destroy();
}
for (RenderObject* child = firstChild(); child != fromBeforeChild; child = firstChild())
moveChildTo(toBase, toBase->children(), child);
}
}
#endif // ENABLE(RUBY)