MathMLFractionElement.cpp [plain text]
#include "config.h"
#include "MathMLFractionElement.h"
#if ENABLE(MATHML)
#include "RenderMathMLFraction.h"
#include "Settings.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLFractionElement);
using namespace MathMLNames;
inline MathMLFractionElement::MathMLFractionElement(const QualifiedName& tagName, Document& document)
: MathMLPresentationElement(tagName, document)
{
}
Ref<MathMLFractionElement> MathMLFractionElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new MathMLFractionElement(tagName, document));
}
const MathMLElement::Length& MathMLFractionElement::lineThickness()
{
if (m_lineThickness)
return m_lineThickness.value();
auto& thickness = attributeWithoutSynchronization(linethicknessAttr);
if (document().settings().coreMathMLEnabled()) {
m_lineThickness = parseMathMLLength(thickness);
return m_lineThickness.value();
}
m_lineThickness = Length();
if (equalLettersIgnoringASCIICase(thickness, "thin")) {
m_lineThickness.value().type = LengthType::UnitLess;
m_lineThickness.value().value = .5;
} else if (equalLettersIgnoringASCIICase(thickness, "medium")) {
m_lineThickness.value().type = LengthType::UnitLess;
m_lineThickness.value().value = 1;
} else if (equalLettersIgnoringASCIICase(thickness, "thick")) {
m_lineThickness.value().type = LengthType::UnitLess;
m_lineThickness.value().value = 2;
} else
m_lineThickness = parseMathMLLength(thickness);
return m_lineThickness.value();
}
MathMLFractionElement::FractionAlignment MathMLFractionElement::cachedFractionAlignment(const QualifiedName& name, Optional<FractionAlignment>& alignment)
{
if (alignment)
return alignment.value();
auto& value = attributeWithoutSynchronization(name);
if (equalLettersIgnoringASCIICase(value, "left"))
alignment = FractionAlignmentLeft;
else if (equalLettersIgnoringASCIICase(value, "right"))
alignment = FractionAlignmentRight;
else
alignment = FractionAlignmentCenter;
return alignment.value();
}
MathMLFractionElement::FractionAlignment MathMLFractionElement::numeratorAlignment()
{
return cachedFractionAlignment(numalignAttr, m_numeratorAlignment);
}
MathMLFractionElement::FractionAlignment MathMLFractionElement::denominatorAlignment()
{
return cachedFractionAlignment(denomalignAttr, m_denominatorAlignment);
}
void MathMLFractionElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == linethicknessAttr)
m_lineThickness = WTF::nullopt;
else if (name == numalignAttr)
m_numeratorAlignment = WTF::nullopt;
else if (name == denomalignAttr)
m_denominatorAlignment = WTF::nullopt;
MathMLElement::parseAttribute(name, value);
}
RenderPtr<RenderElement> MathMLFractionElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
ASSERT(hasTagName(MathMLNames::mfracTag));
return createRenderer<RenderMathMLFraction>(*this, WTFMove(style));
}
}
#endif // ENABLE(MATHML)