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) 2010 François Sausset (sausset@gmail.com). All rights reserved.
5 * Copyright (C) 2016 Igalia S.L.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#if ENABLE(MATHML)
32
33#include "MathMLNames.h"
34#include "StyledElement.h"
35
36namespace WebCore {
37
38class MathMLElement : public StyledElement {
39 WTF_MAKE_ISO_ALLOCATED(MathMLElement);
40public:
41 static Ref<MathMLElement> create(const QualifiedName& tagName, Document&);
42
43 unsigned colSpan() const;
44 unsigned rowSpan() const;
45
46 virtual bool isMathMLToken() const { return false; }
47 virtual bool isSemanticAnnotation() const { return false; }
48 virtual bool isPresentationMathML() const { return false; }
49
50 bool hasTagName(const MathMLQualifiedName& name) const { return hasLocalName(name.localName()); }
51
52 // MathML lengths (https://www.w3.org/TR/MathML3/chapter2.html#fund.units)
53 // TeX's Math Unit is used internally for named spaces (1 mu = 1/18 em).
54 // Unitless values are interpreted as a multiple of a reference value.
55 enum class LengthType { Cm, Em, Ex, In, MathUnit, Mm, ParsingFailed, Pc, Percentage, Pt, Px, UnitLess, Infinity };
56 struct Length {
57 LengthType type { LengthType::ParsingFailed };
58 float value { 0 };
59 };
60
61 enum class BooleanValue { True, False, Default };
62
63 // These are the mathvariant values from the MathML recommendation.
64 // The special value none means that no explicit mathvariant value has been specified.
65 // Note that the numeral values are important for the computation performed in the mathVariant function of RenderMathMLToken, do not change them!
66 enum class MathVariant {
67 None = 0,
68 Normal = 1,
69 Bold = 2,
70 Italic = 3,
71 BoldItalic = 4,
72 Script = 5,
73 BoldScript = 6,
74 Fraktur = 7,
75 DoubleStruck = 8,
76 BoldFraktur = 9,
77 SansSerif = 10,
78 BoldSansSerif = 11,
79 SansSerifItalic = 12,
80 SansSerifBoldItalic = 13,
81 Monospace = 14,
82 Initial = 15,
83 Tailed = 16,
84 Looped = 17,
85 Stretched = 18
86 };
87
88 virtual Optional<bool> specifiedDisplayStyle() { return WTF::nullopt; }
89 virtual Optional<MathVariant> specifiedMathVariant() { return WTF::nullopt; }
90
91 virtual void updateSelectedChild() { }
92
93protected:
94 MathMLElement(const QualifiedName& tagName, Document&);
95
96 void parseAttribute(const QualifiedName&, const AtomString&) override;
97 bool childShouldCreateRenderer(const Node&) const override;
98
99 bool isPresentationAttribute(const QualifiedName&) const override;
100 void collectStyleForPresentationAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) override;
101
102 bool willRespondToMouseClickEvents() override;
103 void defaultEventHandler(Event&) override;
104
105private:
106 bool canStartSelection() const final;
107 bool isKeyboardFocusable(KeyboardEvent*) const final;
108 bool isMouseFocusable() const final;
109 bool isURLAttribute(const Attribute&) const final;
110 bool supportsFocus() const final;
111 int tabIndex() const final;
112};
113
114inline bool Node::hasTagName(const MathMLQualifiedName& name) const
115{
116 return isMathMLElement() && downcast<MathMLElement>(*this).hasTagName(name);
117}
118
119} // namespace WebCore
120
121SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MathMLElement)
122 static bool isType(const WebCore::Node& node) { return node.isMathMLElement(); }
123SPECIALIZE_TYPE_TRAITS_END()
124
125#include "MathMLElementTypeHelpers.h"
126
127#endif // ENABLE(MATHML)
128