1 | /* |
2 | * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved. |
3 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2016 Igalia S.L. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #include "config.h" |
29 | #include "MathMLMathElement.h" |
30 | |
31 | #if ENABLE(MATHML) |
32 | |
33 | #include "MathMLNames.h" |
34 | #include "RenderMathMLMath.h" |
35 | #include <wtf/IsoMallocInlines.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLMathElement); |
40 | |
41 | using namespace MathMLNames; |
42 | |
43 | inline MathMLMathElement::MathMLMathElement(const QualifiedName& tagName, Document& document) |
44 | : MathMLRowElement(tagName, document) |
45 | { |
46 | setHasCustomStyleResolveCallbacks(); |
47 | } |
48 | |
49 | Ref<MathMLMathElement> MathMLMathElement::create(const QualifiedName& tagName, Document& document) |
50 | { |
51 | return adoptRef(*new MathMLMathElement(tagName, document)); |
52 | } |
53 | |
54 | RenderPtr<RenderElement> MathMLMathElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
55 | { |
56 | return createRenderer<RenderMathMLMath>(*this, WTFMove(style)); |
57 | } |
58 | |
59 | Optional<bool> MathMLMathElement::specifiedDisplayStyle() |
60 | { |
61 | if (cachedBooleanAttribute(displaystyleAttr, m_displayStyle) == BooleanValue::Default) { |
62 | // The default displaystyle value of the <math> depends on the display attribute, so we parse it here. |
63 | auto& value = attributeWithoutSynchronization(displayAttr); |
64 | if (value == "block" ) |
65 | m_displayStyle = BooleanValue::True; |
66 | else if (value == "inline" ) |
67 | m_displayStyle = BooleanValue::False; |
68 | } |
69 | return toOptionalBool(m_displayStyle.value()); |
70 | } |
71 | |
72 | void MathMLMathElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
73 | { |
74 | bool displayStyleAttribute = (name == displaystyleAttr || name == displayAttr); |
75 | bool mathVariantAttribute = name == mathvariantAttr; |
76 | if (displayStyleAttribute) |
77 | m_displayStyle = WTF::nullopt; |
78 | if (mathVariantAttribute) |
79 | m_mathVariant = WTF::nullopt; |
80 | if ((displayStyleAttribute || mathVariantAttribute) && renderer()) |
81 | MathMLStyle::resolveMathMLStyleTree(renderer()); |
82 | |
83 | MathMLElement::parseAttribute(name, value); |
84 | } |
85 | |
86 | void MathMLMathElement::didAttachRenderers() |
87 | { |
88 | MathMLRowElement::didAttachRenderers(); |
89 | |
90 | MathMLStyle::resolveMathMLStyleTree(renderer()); |
91 | } |
92 | |
93 | } |
94 | |
95 | #endif // ENABLE(MATHML) |
96 | |