1/*
2 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28
29#if ENABLE(MATHML)
30
31#include "MathMLInlineContainerElement.h"
32
33#include "MathMLNames.h"
34#include "RenderMathMLBlock.h"
35#include "RenderMathMLFenced.h"
36#include "RenderMathMLFraction.h"
37#include "RenderMathMLMenclose.h"
38#include "RenderMathMLRoot.h"
39#include "RenderMathMLRow.h"
40#include "RenderMathMLScripts.h"
41#include "RenderMathMLSquareRoot.h"
42#include "RenderMathMLUnderOver.h"
43
44namespace WebCore {
45
46using namespace MathMLNames;
47
48MathMLInlineContainerElement::MathMLInlineContainerElement(const QualifiedName& tagName, Document& document)
49    : MathMLElement(tagName, document)
50{
51}
52
53PassRefPtr<MathMLInlineContainerElement> MathMLInlineContainerElement::create(const QualifiedName& tagName, Document& document)
54{
55    return adoptRef(new MathMLInlineContainerElement(tagName, document));
56}
57
58void MathMLInlineContainerElement::childrenChanged(const ChildChange& change)
59{
60    if (renderer()) {
61        if (renderer()->isRenderMathMLRow())
62            toRenderMathMLRow(renderer())->updateOperatorProperties();
63        else if (hasTagName(mathTag) || hasTagName(msqrtTag)) {
64            auto childRenderer = renderer()->firstChild();
65            if (childRenderer && childRenderer->isRenderMathMLRow())
66                toRenderMathMLRow(childRenderer)->updateOperatorProperties();
67        }
68    }
69    MathMLElement::childrenChanged(change);
70}
71
72RenderPtr<RenderElement> MathMLInlineContainerElement::createElementRenderer(PassRef<RenderStyle> style)
73{
74    if (hasTagName(annotation_xmlTag))
75        return createRenderer<RenderMathMLRow>(*this, WTF::move(style));
76    if (hasTagName(merrorTag) || hasTagName(mphantomTag) || hasTagName(mrowTag) || hasTagName(mstyleTag))
77        return createRenderer<RenderMathMLRow>(*this, WTF::move(style));
78    if (hasTagName(msubTag))
79        return createRenderer<RenderMathMLScripts>(*this, WTF::move(style));
80    if (hasTagName(msupTag))
81        return createRenderer<RenderMathMLScripts>(*this, WTF::move(style));
82    if (hasTagName(msubsupTag))
83        return createRenderer<RenderMathMLScripts>(*this, WTF::move(style));
84    if (hasTagName(mmultiscriptsTag))
85        return createRenderer<RenderMathMLScripts>(*this, WTF::move(style));
86    if (hasTagName(moverTag))
87        return createRenderer<RenderMathMLUnderOver>(*this, WTF::move(style));
88    if (hasTagName(munderTag))
89        return createRenderer<RenderMathMLUnderOver>(*this, WTF::move(style));
90    if (hasTagName(munderoverTag))
91        return createRenderer<RenderMathMLUnderOver>(*this, WTF::move(style));
92    if (hasTagName(mfracTag))
93        return createRenderer<RenderMathMLFraction>(*this, WTF::move(style));
94    if (hasTagName(msqrtTag))
95        return createRenderer<RenderMathMLSquareRoot>(*this, WTF::move(style));
96    if (hasTagName(mrootTag))
97        return createRenderer<RenderMathMLRoot>(*this, WTF::move(style));
98    if (hasTagName(mfencedTag))
99        return createRenderer<RenderMathMLFenced>(*this, WTF::move(style));
100    if (hasTagName(mtableTag))
101        return createRenderer<RenderMathMLTable>(*this, WTF::move(style));
102
103    return createRenderer<RenderMathMLBlock>(*this, WTF::move(style));
104}
105
106}
107
108#endif // ENABLE(MATHML)
109