1 | /* |
2 | * Copyright (C) 2014 Gurpreet Kaur (k.gurpreet@samsung.com). All rights reserved. |
3 | * Copyright (C) 2016 Igalia S.L. |
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 | #include "MathMLMencloseElement.h" |
29 | |
30 | #if ENABLE(MATHML) |
31 | |
32 | #include "HTMLParserIdioms.h" |
33 | #include "MathMLNames.h" |
34 | #include "RenderMathMLMenclose.h" |
35 | #include <wtf/IsoMallocInlines.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLMencloseElement); |
40 | |
41 | using namespace MathMLNames; |
42 | |
43 | MathMLMencloseElement::MathMLMencloseElement(const QualifiedName& tagName, Document& document) |
44 | : MathMLRowElement(tagName, document) |
45 | { |
46 | // By default we draw a longdiv. |
47 | clearNotations(); |
48 | addNotation(LongDiv); |
49 | } |
50 | |
51 | Ref<MathMLMencloseElement> MathMLMencloseElement::create(const QualifiedName& tagName, Document& document) |
52 | { |
53 | return adoptRef(*new MathMLMencloseElement(tagName, document)); |
54 | } |
55 | |
56 | RenderPtr<RenderElement> MathMLMencloseElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
57 | { |
58 | return createRenderer<RenderMathMLMenclose>(*this, WTFMove(style)); |
59 | } |
60 | |
61 | void MathMLMencloseElement::addNotationFlags(StringView notation) |
62 | { |
63 | ASSERT(m_notationFlags); |
64 | if (notation == "longdiv" ) { |
65 | addNotation(LongDiv); |
66 | } else if (notation == "roundedbox" ) { |
67 | addNotation(RoundedBox); |
68 | } else if (notation == "circle" ) { |
69 | addNotation(Circle); |
70 | } else if (notation == "left" ) { |
71 | addNotation(Left); |
72 | } else if (notation == "right" ) { |
73 | addNotation(Right); |
74 | } else if (notation == "top" ) { |
75 | addNotation(Top); |
76 | } else if (notation == "bottom" ) { |
77 | addNotation(Bottom); |
78 | } else if (notation == "updiagonalstrike" ) { |
79 | addNotation(UpDiagonalStrike); |
80 | } else if (notation == "downdiagonalstrike" ) { |
81 | addNotation(DownDiagonalStrike); |
82 | } else if (notation == "verticalstrike" ) { |
83 | addNotation(VerticalStrike); |
84 | } else if (notation == "horizontalstrike" ) { |
85 | addNotation(HorizontalStrike); |
86 | } else if (notation == "updiagonalarrow" ) { |
87 | addNotation(UpDiagonalArrow); |
88 | } else if (notation == "phasorangle" ) { |
89 | addNotation(PhasorAngle); |
90 | } else if (notation == "box" ) { |
91 | addNotation(Left); |
92 | addNotation(Right); |
93 | addNotation(Top); |
94 | addNotation(Bottom); |
95 | } else if (notation == "actuarial" ) { |
96 | addNotation(Right); |
97 | addNotation(Top); |
98 | } else if (notation == "madruwb" ) { |
99 | addNotation(Right); |
100 | addNotation(Bottom); |
101 | } |
102 | } |
103 | |
104 | void MathMLMencloseElement::parseNotationAttribute() |
105 | { |
106 | clearNotations(); |
107 | if (!hasAttribute(notationAttr)) { |
108 | addNotation(LongDiv); // The default value is longdiv. |
109 | return; |
110 | } |
111 | // We parse the list of whitespace-separated notation names. |
112 | StringView value = attributeWithoutSynchronization(notationAttr).string(); |
113 | unsigned length = value.length(); |
114 | unsigned start = 0; |
115 | while (start < length) { |
116 | if (isHTMLSpace(value[start])) { |
117 | start++; |
118 | continue; |
119 | } |
120 | unsigned end = start + 1; |
121 | while (end < length && !isHTMLSpace(value[end])) |
122 | end++; |
123 | addNotationFlags(value.substring(start, end - start)); |
124 | start = end; |
125 | } |
126 | } |
127 | |
128 | bool MathMLMencloseElement::hasNotation(MencloseNotationFlag notationFlag) |
129 | { |
130 | if (!m_notationFlags) |
131 | parseNotationAttribute(); |
132 | return m_notationFlags.value() & notationFlag; |
133 | } |
134 | |
135 | void MathMLMencloseElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
136 | { |
137 | if (name == notationAttr) |
138 | m_notationFlags = WTF::nullopt; |
139 | |
140 | MathMLRowElement::parseAttribute(name, value); |
141 | } |
142 | |
143 | } |
144 | #endif // ENABLE(MATHML) |
145 | |