RenderRubyBase.cpp [plain text]
#include "config.h"
#include "RenderRubyBase.h"
#include "RenderRubyRun.h"
#include "RenderRubyText.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderRubyBase);
RenderRubyBase::RenderRubyBase(Document& document, RenderStyle&& style)
: RenderBlockFlow(document, WTFMove(style))
, m_initialOffset(0)
, m_isAfterExpansion(true)
{
setInline(false);
}
RenderRubyBase::~RenderRubyBase() = default;
bool RenderRubyBase::isChildAllowed(const RenderObject& child, const RenderStyle&) const
{
return child.isInline();
}
RenderRubyRun* RenderRubyBase::rubyRun() const
{
ASSERT(parent());
return downcast<RenderRubyRun>(parent());
}
TextAlignMode RenderRubyBase::textAlignmentForLine(bool ) const
{
return TextAlignMode::Justify;
}
void RenderRubyBase::adjustInlineDirectionLineBounds(int expansionOpportunityCount, float& logicalLeft, float& logicalWidth) const
{
if (rubyRun()->hasOverrideContentLogicalWidth() && firstRootBox() && !firstRootBox()->nextRootBox()) {
logicalLeft += m_initialOffset;
logicalWidth -= 2 * m_initialOffset;
return;
}
LayoutUnit maxPreferredLogicalWidth = rubyRun() && rubyRun()->hasOverrideContentLogicalWidth() ? rubyRun()->overrideContentLogicalWidth() : 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());
}
}