MathMLAnnotationElement.cpp [plain text]
#include "config.h"
#include "MathMLAnnotationElement.h"
#if ENABLE(MATHML)
#include "HTMLHtmlElement.h"
#include "MathMLMathElement.h"
#include "MathMLNames.h"
#include "MathMLSelectElement.h"
#include "RenderMathMLBlock.h"
#include "SVGSVGElement.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLAnnotationElement);
using namespace MathMLNames;
MathMLAnnotationElement::MathMLAnnotationElement(const QualifiedName& tagName, Document& document)
: MathMLPresentationElement(tagName, document)
{
ASSERT(hasTagName(annotationTag) || hasTagName(annotation_xmlTag));
}
Ref<MathMLAnnotationElement> MathMLAnnotationElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new MathMLAnnotationElement(tagName, document));
}
RenderPtr<RenderElement> MathMLAnnotationElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition& insertionPosition)
{
if (hasTagName(MathMLNames::annotationTag))
return MathMLElement::createElementRenderer(WTFMove(style), insertionPosition);
ASSERT(hasTagName(annotation_xmlTag));
return createRenderer<RenderMathMLBlock>(*this, WTFMove(style));
}
bool MathMLAnnotationElement::childShouldCreateRenderer(const Node& child) const
{
if (hasTagName(MathMLNames::annotationTag))
return child.isTextNode();
ASSERT(hasTagName(annotation_xmlTag));
auto& value = attributeWithoutSynchronization(encodingAttr);
if (is<MathMLElement>(child) && (MathMLSelectElement::isMathMLEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
auto& mathmlElement = downcast<MathMLElement>(child);
return is<MathMLMathElement>(mathmlElement);
}
if (is<SVGElement>(child) && (MathMLSelectElement::isSVGEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
auto& svgElement = downcast<SVGElement>(child);
return is<SVGSVGElement>(svgElement);
}
if (is<HTMLElement>(child) && MathMLSelectElement::isHTMLEncoding(value)) {
auto& htmlElement = downcast<HTMLElement>(child);
return is<HTMLHtmlElement>(htmlElement) || (isFlowContent(htmlElement) && StyledElement::childShouldCreateRenderer(child));
}
return false;
}
void MathMLAnnotationElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason reason)
{
if (name == MathMLNames::srcAttr || name == MathMLNames::encodingAttr) {
auto* parent = parentElement();
if (is<MathMLElement>(parent) && parent->hasTagName(semanticsTag))
downcast<MathMLElement>(*parent).updateSelectedChild();
}
MathMLPresentationElement::attributeChanged(name, oldValue, newValue, reason);
}
}
#endif // ENABLE(MATHML)