RenderRubyBase.cpp [plain text]
#include "config.h"
#include "RenderRubyBase.h"
#include "RenderRubyRun.h"
#include "RenderRubyText.h"
namespace WebCore {
RenderRubyBase::RenderRubyBase(Document& document, Ref<RenderStyle>&& style)
: RenderBlockFlow(document, WTF::move(style))
, m_initialOffset(0)
, m_isAfterExpansion(true)
{
setInline(false);
}
RenderRubyBase::~RenderRubyBase()
{
}
bool RenderRubyBase::isChildAllowed(const RenderObject& child, const RenderStyle&) const
{
return child.isInline();
}
void RenderRubyBase::moveChildren(RenderRubyBase* toBase, RenderObject* beforeChild)
{
ASSERT_ARG(toBase, toBase);
if (beforeChild && beforeChild->parent() != this)
beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
if (childrenInline())
moveInlineChildren(toBase, beforeChild);
else
moveBlockChildren(toBase, beforeChild);
setNeedsLayoutAndPrefWidthsRecalc();
toBase->setNeedsLayoutAndPrefWidthsRecalc();
}
void RenderRubyBase::mergeChildrenWithBase(RenderRubyBase* toBlock)
{
moveChildren(toBlock);
moveFloatsTo(toBlock);
}
void RenderRubyBase::moveInlineChildren(RenderRubyBase* toBase, RenderObject* beforeChild)
{
ASSERT(childrenInline());
ASSERT_ARG(toBase, toBase);
if (!firstChild())
return;
RenderBlock* toBlock;
if (toBase->childrenInline()) {
toBlock = toBase;
} else {
RenderObject* lastChild = toBase->lastChild();
if (lastChild && lastChild->isAnonymousBlock() && lastChild->childrenInline())
toBlock = downcast<RenderBlock>(lastChild);
else {
toBlock = toBase->createAnonymousBlock();
toBase->insertChildInternal(toBlock, nullptr, NotifyChildren);
}
}
moveChildrenTo(toBlock, firstChild(), beforeChild);
}
void RenderRubyBase::moveBlockChildren(RenderRubyBase* toBase, RenderObject* beforeChild)
{
ASSERT(!childrenInline());
ASSERT_ARG(toBase, toBase);
if (!firstChild())
return;
if (toBase->childrenInline())
toBase->makeChildrenNonInline();
RenderObject* firstChildHere = firstChild();
RenderObject* lastChildThere = toBase->lastChild();
if (firstChildHere->isAnonymousBlock() && firstChildHere->childrenInline()
&& lastChildThere && lastChildThere->isAnonymousBlock() && lastChildThere->childrenInline()) {
RenderBlock* anonBlockHere = downcast<RenderBlock>(firstChildHere);
RenderBlock* anonBlockThere = downcast<RenderBlock>(lastChildThere);
anonBlockHere->moveAllChildrenTo(anonBlockThere, true);
anonBlockHere->deleteLines();
anonBlockHere->destroy();
}
moveChildrenTo(toBase, firstChild(), beforeChild);
}
RenderRubyRun* RenderRubyBase::rubyRun() const
{
ASSERT(parent());
return downcast<RenderRubyRun>(parent());
}
ETextAlign RenderRubyBase::textAlignmentForLine(bool ) const
{
return JUSTIFY;
}
void RenderRubyBase::adjustInlineDirectionLineBounds(int expansionOpportunityCount, float& logicalLeft, float& logicalWidth) const
{
if (rubyRun()->hasOverrideLogicalContentWidth() && firstRootBox() && !firstRootBox()->nextRootBox()) {
logicalLeft += m_initialOffset;
logicalWidth -= 2 * m_initialOffset;
return;
}
LayoutUnit maxPreferredLogicalWidth = rubyRun() && rubyRun()->hasOverrideLogicalContentWidth() ? rubyRun()->overrideLogicalContentWidth() : this->maxPreferredLogicalWidth();
if (maxPreferredLogicalWidth >= logicalWidth)
return;
float inset = (logicalWidth - maxPreferredLogicalWidth) / (expansionOpportunityCount + 1);
logicalLeft += inset / 2;
logicalWidth -= inset;
}
void RenderRubyBase::cachePriorCharactersIfNeeded(const LazyLineBreakIterator& lineBreakIterator)
{
auto* run = rubyRun();
if (run)
run->setCachedPriorCharacters(lineBreakIterator.lastCharacter(), lineBreakIterator.secondToLastCharacter());
}
}