RenderRubyBase.cpp [plain text]
#include "config.h"
#include "RenderRubyBase.h"
#include "RenderRubyRun.h"
#include "RenderRubyText.h"
using namespace std;
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);
}
}
moveChildrenTo(toBlock, firstChild(), fromBeforeChild);
}
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->inlineElementContinuation());
anonBlock->moveAllChildrenTo(toBase, toBase->children());
anonBlock->deleteLineBoxTree();
anonBlock->destroy();
} else {
ASSERT(child->isFloatingOrPositioned());
moveChildTo(toBase, 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->inlineElementContinuation());
anonBlock->moveAllChildrenTo(this, 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();
}
moveChildrenTo(toBase, firstChild(), fromBeforeChild);
}
RenderRubyRun* RenderRubyBase::rubyRun() const
{
ASSERT(parent());
ASSERT(parent()->isRubyRun());
return static_cast<RenderRubyRun*>(parent());
}
ETextAlign RenderRubyBase::textAlignmentForLine(bool ) const
{
return JUSTIFY;
}
void RenderRubyBase::adjustInlineDirectionLineBounds(int expansionOpportunityCount, float& logicalLeft, float& logicalWidth) const
{
int maxPreferredLogicalWidth = this->maxPreferredLogicalWidth();
if (maxPreferredLogicalWidth >= logicalWidth)
return;
float inset = (logicalWidth - maxPreferredLogicalWidth) / (expansionOpportunityCount + 1);
logicalLeft += inset / 2;
logicalWidth -= inset;
}
}