2 * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef RenderMathMLOperator_h
27 #define RenderMathMLOperator_h
31 #include "GlyphPage.h"
32 #include "MathMLElement.h"
33 #include "OpenTypeMathData.h"
34 #include "RenderMathMLToken.h"
35 #include "SimpleFontData.h"
39 namespace MathMLOperatorDictionary {
41 enum Form { Infix, Prefix, Postfix };
43 Accent = 0x1, // FIXME: This must be used to implement accentunder/accent on munderover (https://bugs.webkit.org/show_bug.cgi?id=124826).
44 Fence = 0x2, // This has no visual effect but allows to expose semantic information via the accessibility tree.
46 MovableLimits = 0x8, // FIXME: This must be used to implement displaystyle (https://bugs.webkit.org/show_bug.cgi?id=118737).
47 Separator = 0x10, // This has no visual effect but allows to expose semantic information via the accessibility tree.
54 unsigned short lspace;
55 unsigned short rspace;
61 class RenderMathMLOperator final : public RenderMathMLToken {
63 RenderMathMLOperator(MathMLElement&, PassRef<RenderStyle>);
64 RenderMathMLOperator(Document&, PassRef<RenderStyle>, const String& operatorString, MathMLOperatorDictionary::Form, MathMLOperatorDictionary::Flag);
66 void stretchTo(LayoutUnit heightAboveBaseline, LayoutUnit depthBelowBaseline);
67 void stretchTo(LayoutUnit width);
68 LayoutUnit stretchSize() const { return m_isVertical ? m_stretchHeightAboveBaseline + m_stretchDepthBelowBaseline : m_stretchWidth; }
70 bool hasOperatorFlag(MathMLOperatorDictionary::Flag flag) const { return m_operatorFlags & flag; }
71 // FIXME: The displaystyle property is not implemented (https://bugs.webkit.org/show_bug.cgi?id=118737).
72 bool isLargeOperatorInDisplayStyle() const { return !hasOperatorFlag(MathMLOperatorDictionary::Stretchy) && hasOperatorFlag(MathMLOperatorDictionary::LargeOp); }
74 void updateStyle() override final;
76 void paint(PaintInfo&, const LayoutPoint&);
78 void updateTokenContent(const String& operatorString);
79 void updateTokenContent() override final;
80 void updateOperatorProperties();
83 virtual const char* renderName() const override { return isAnonymous() ? "RenderMathMLOperator (anonymous)" : "RenderMathMLOperator"; }
84 virtual void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) override;
85 virtual bool isRenderMathMLOperator() const override { return true; }
86 bool isFencedOperator() { return isAnonymous(); }
87 // The following operators are invisible: U+2061 FUNCTION APPLICATION, U+2062 INVISIBLE TIMES, U+2063 INVISIBLE SEPARATOR, U+2064 INVISIBLE PLUS.
88 bool isInvisibleOperator() const { return 0x2061 <= m_operator && m_operator <= 0x2064; }
89 virtual bool isChildAllowed(const RenderObject&, const RenderStyle&) const override;
90 virtual void computePreferredLogicalWidths() override;
91 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
92 virtual int firstLineBaseline() const override;
93 virtual RenderMathMLOperator* unembellishedOperator() override { return this; }
94 void rebuildTokenContent(const String& operatorString);
95 void updateFromElement() override;
97 bool shouldAllowStretching() const;
99 FloatRect boundsForGlyph(const GlyphData&) const;
100 float heightForGlyph(const GlyphData&) const;
101 float advanceForGlyph(const GlyphData&) const;
104 DrawNormal, DrawSizeVariant, DrawGlyphAssembly
108 DrawMode mode() const { return m_mode; }
109 GlyphData variant() const { return m_data[0]; }
110 GlyphData top() const { return m_data[0]; }
111 GlyphData extension() const { return m_data[1]; }
112 GlyphData bottom() const { return m_data[2]; }
113 GlyphData middle() const { return m_data[3]; }
114 GlyphData left() const { return m_data[2]; }
115 GlyphData right() const { return m_data[0]; }
121 void setSizeVariantMode(const GlyphData& variant)
123 m_mode = DrawSizeVariant;
126 void setGlyphAssemblyMode(const GlyphData& top, const GlyphData& extension, const GlyphData& bottom, const GlyphData& middle)
128 m_mode = DrawGlyphAssembly;
130 m_data[1] = extension;
135 : m_mode(DrawNormal) { }
136 StretchyData(const StretchyData& data)
138 switch (data.m_mode) {
142 case DrawSizeVariant:
143 setSizeVariantMode(data.variant());
145 case DrawGlyphAssembly:
146 setGlyphAssemblyMode(data.top(), data.extension(), data.bottom(), data.middle());
152 // FIXME: For OpenType fonts with a MATH table all the glyphs are from the same font, so we would only need to store the glyph indices here.
155 bool getGlyphAssemblyFallBack(Vector<OpenTypeMathData::AssemblyPart>, StretchyData&) const;
156 StretchyData getDisplayStyleLargeOperator(UChar) const;
157 StretchyData findStretchyData(UChar, float* maximumGlyphWidth);
159 enum GlyphPaintTrimming {
168 LayoutRect paintGlyph(PaintInfo&, const GlyphData&, const LayoutPoint& origin, GlyphPaintTrimming);
169 void fillWithVerticalExtensionGlyph(PaintInfo&, const LayoutPoint& from, const LayoutPoint& to);
170 void fillWithHorizontalExtensionGlyph(PaintInfo&, const LayoutPoint& from, const LayoutPoint& to);
171 void paintVerticalGlyphAssembly(PaintInfo&, const LayoutPoint&);
172 void paintHorizontalGlyphAssembly(PaintInfo&, const LayoutPoint&);
174 LayoutUnit m_stretchHeightAboveBaseline;
175 LayoutUnit m_stretchDepthBelowBaseline;
176 LayoutUnit m_stretchWidth;
180 StretchyData m_stretchyData;
181 MathMLOperatorDictionary::Form m_operatorForm;
182 unsigned short m_operatorFlags;
183 LayoutUnit m_leadingSpace;
184 LayoutUnit m_trailingSpace;
185 LayoutUnit m_minSize;
186 LayoutUnit m_maxSize;
188 void setOperatorFlagFromAttribute(MathMLOperatorDictionary::Flag, const QualifiedName&);
189 void setOperatorPropertiesFromOpDictEntry(const MathMLOperatorDictionary::Entry*);
190 void SetOperatorProperties();
193 RENDER_OBJECT_TYPE_CASTS(RenderMathMLOperator, isRenderMathMLOperator())
197 #endif // ENABLE(MATHML)
198 #endif // RenderMathMLOperator_h