MathMLTokenElement.cpp [plain text]
#include "config.h"
#include "MathMLTokenElement.h"
#if ENABLE(MATHML)
#include "MathMLNames.h"
#include "RenderMathMLToken.h"
namespace WebCore {
using namespace MathMLNames;
MathMLTokenElement::MathMLTokenElement(const QualifiedName& tagName, Document& document)
: MathMLPresentationElement(tagName, document)
{
setHasCustomStyleResolveCallbacks();
}
Ref<MathMLTokenElement> MathMLTokenElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new MathMLTokenElement(tagName, document));
}
void MathMLTokenElement::didAttachRenderers()
{
MathMLPresentationElement::didAttachRenderers();
auto* mathmlRenderer = renderer();
if (is<RenderMathMLToken>(mathmlRenderer))
downcast<RenderMathMLToken>(*mathmlRenderer).updateTokenContent();
}
void MathMLTokenElement::childrenChanged(const ChildChange& change)
{
MathMLPresentationElement::childrenChanged(change);
auto* mathmlRenderer = renderer();
if (is<RenderMathMLToken>(mathmlRenderer))
downcast<RenderMathMLToken>(*mathmlRenderer).updateTokenContent();
}
RenderPtr<RenderElement> MathMLTokenElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
ASSERT(hasTagName(MathMLNames::miTag) || hasTagName(MathMLNames::mnTag) || hasTagName(MathMLNames::msTag) || hasTagName(MathMLNames::mtextTag));
return createRenderer<RenderMathMLToken>(*this, WTFMove(style));
}
bool MathMLTokenElement::childShouldCreateRenderer(const Node& child) const
{
return isPhrasingContent(child) && StyledElement::childShouldCreateRenderer(child);
}
std::optional<UChar32> MathMLTokenElement::convertToSingleCodePoint(StringView string)
{
auto codePoints = stripLeadingAndTrailingWhitespace(string).codePoints();
auto iterator = codePoints.begin();
if (iterator == codePoints.end())
return std::nullopt;
std::optional<UChar32> character = *iterator;
++iterator;
return iterator == codePoints.end() ? character : std::nullopt;
}
}
#endif // ENABLE(MATHML)