RenderMathMLToken.cpp [plain text]
#include "config.h"
#include "RenderMathMLToken.h"
#if ENABLE(MATHML)
#include "MathMLNames.h"
#include "RenderElement.h"
#include "RenderIterator.h"
namespace WebCore {
using namespace MathMLNames;
RenderMathMLToken::RenderMathMLToken(Element& element, PassRef<RenderStyle> style)
: RenderMathMLBlock(element, WTF::move(style))
, m_containsElement(false)
{
}
RenderMathMLToken::RenderMathMLToken(Document& document, PassRef<RenderStyle> style)
: RenderMathMLBlock(document, WTF::move(style))
, m_containsElement(false)
{
}
void RenderMathMLToken::addChild(RenderObject* newChild, RenderObject* beforeChild)
{
createWrapperIfNeeded();
toRenderElement(firstChild())->addChild(newChild, beforeChild);
}
void RenderMathMLToken::createWrapperIfNeeded()
{
if (!firstChild()) {
RenderPtr<RenderMathMLBlock> wrapper = createAnonymousMathMLBlock();
RenderMathMLBlock::addChild(wrapper.leakPtr());
}
}
void RenderMathMLToken::updateTokenContent()
{
m_containsElement = false;
if (!isEmpty()) {
const auto& wrapper = toRenderElement(firstChild());
if (const auto& block = toRenderElement(wrapper->firstChild()))
m_containsElement = childrenOfType<RenderElement>(*block).first();
updateStyle();
}
setNeedsLayoutAndPrefWidthsRecalc();
}
void RenderMathMLToken::updateStyle()
{
const auto& tokenElement = element();
const auto& wrapper = toRenderElement(firstChild());
auto newStyle = RenderStyle::createAnonymousStyleWithDisplay(&style(), FLEX);
if (tokenElement.hasTagName(MathMLNames::miTag)) {
FontDescription fontDescription(newStyle.get().fontDescription());
FontSelector* fontSelector = newStyle.get().font().fontSelector();
if (!m_containsElement && element().textContent().stripWhiteSpace().simplifyWhiteSpace().length() == 1 && !tokenElement.hasAttribute(mathvariantAttr))
fontDescription.setItalic(true);
if (newStyle.get().setFontDescription(fontDescription))
newStyle.get().font().update(fontSelector);
}
wrapper->setStyle(WTF::move(newStyle));
wrapper->setNeedsLayoutAndPrefWidthsRecalc();
}
void RenderMathMLToken::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderMathMLBlock::styleDidChange(diff, oldStyle);
if (!isEmpty())
updateStyle();
}
void RenderMathMLToken::updateFromElement()
{
RenderMathMLBlock::updateFromElement();
if (!isEmpty())
updateStyle();
}
}
#endif // ENABLE(MATHML)