1/*
2 * Copyright (C) 2016 Igalia S.L. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
27#include "config.h"
28#include "MathMLScriptsElement.h"
29
30#if ENABLE(MATHML)
31
32#include "RenderMathMLScripts.h"
33#include <wtf/IsoMallocInlines.h>
34
35namespace WebCore {
36
37WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLScriptsElement);
38
39using namespace MathMLNames;
40
41static MathMLScriptsElement::ScriptType scriptTypeOf(const QualifiedName& tagName)
42{
43 if (tagName == msubTag)
44 return MathMLScriptsElement::ScriptType::Sub;
45 if (tagName == msupTag)
46 return MathMLScriptsElement::ScriptType::Super;
47 if (tagName == msubsupTag)
48 return MathMLScriptsElement::ScriptType::SubSup;
49 if (tagName == munderTag)
50 return MathMLScriptsElement::ScriptType::Under;
51 if (tagName == moverTag)
52 return MathMLScriptsElement::ScriptType::Over;
53 if (tagName == munderoverTag)
54 return MathMLScriptsElement::ScriptType::UnderOver;
55 ASSERT(tagName == mmultiscriptsTag);
56 return MathMLScriptsElement::ScriptType::Multiscripts;
57}
58
59MathMLScriptsElement::MathMLScriptsElement(const QualifiedName& tagName, Document& document)
60 : MathMLPresentationElement(tagName, document)
61 , m_scriptType(scriptTypeOf(tagName))
62{
63}
64
65Ref<MathMLScriptsElement> MathMLScriptsElement::create(const QualifiedName& tagName, Document& document)
66{
67 return adoptRef(*new MathMLScriptsElement(tagName, document));
68}
69
70const MathMLElement::Length& MathMLScriptsElement::subscriptShift()
71{
72 return cachedMathMLLength(subscriptshiftAttr, m_subscriptShift);
73}
74
75const MathMLElement::Length& MathMLScriptsElement::superscriptShift()
76{
77 return cachedMathMLLength(superscriptshiftAttr, m_superscriptShift);
78}
79
80void MathMLScriptsElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
81{
82 if (name == subscriptshiftAttr)
83 m_subscriptShift = WTF::nullopt;
84 else if (name == superscriptshiftAttr)
85 m_superscriptShift = WTF::nullopt;
86
87 MathMLElement::parseAttribute(name, value);
88}
89
90RenderPtr<RenderElement> MathMLScriptsElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
91{
92 ASSERT(hasTagName(msubTag) || hasTagName(msupTag) || hasTagName(msubsupTag) || hasTagName(mmultiscriptsTag));
93 return createRenderer<RenderMathMLScripts>(*this, WTFMove(style));
94}
95
96}
97
98#endif // ENABLE(MATHML)
99