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
32 #include "GlyphPage.h"
33 #include "MathMLElement.h"
34 #include "MathMLOperatorDictionary.h"
35 #include "MathOperator.h"
36 #include "OpenTypeMathData.h"
37 #include "RenderMathMLToken.h"
41 class RenderMathMLOperator : public RenderMathMLToken {
43 RenderMathMLOperator(MathMLElement&, RenderStyle&&);
44 RenderMathMLOperator(Document&, RenderStyle&&, const String& operatorString, MathMLOperatorDictionary::Form, unsigned short flags = 0);
46 virtual void stretchTo(LayoutUnit heightAboveBaseline, LayoutUnit depthBelowBaseline);
47 void stretchTo(LayoutUnit width);
48 LayoutUnit stretchSize() const { return m_isVertical ? m_stretchHeightAboveBaseline + m_stretchDepthBelowBaseline : m_stretchWidth; }
49 void resetStretchSize();
51 bool hasOperatorFlag(MathMLOperatorDictionary::Flag flag) const { return m_operatorFlags & flag; }
52 // FIXME: The displaystyle property is not implemented (https://bugs.webkit.org/show_bug.cgi?id=118737).
53 bool isLargeOperatorInDisplayStyle() const { return !hasOperatorFlag(MathMLOperatorDictionary::Stretchy) && hasOperatorFlag(MathMLOperatorDictionary::LargeOp); }
54 bool isVertical() const { return m_isVertical; }
55 LayoutUnit italicCorrection() const { return m_mathOperator.italicCorrection(); }
57 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
58 void updateStyle() final;
60 void paint(PaintInfo&, const LayoutPoint&) override;
62 void updateTokenContent(const String& operatorString);
63 void updateTokenContent() final;
64 void updateOperatorProperties();
65 void updateFromElement() final;
66 LayoutUnit trailingSpaceError();
69 virtual void setOperatorProperties();
70 void computePreferredLogicalWidths() override;
71 void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
72 void setLeadingSpace(LayoutUnit leadingSpace) { m_leadingSpace = leadingSpace; }
73 void setTrailingSpace(LayoutUnit trailingSpace) { m_trailingSpace = trailingSpace; }
74 UChar textContent() const { return m_textContent; }
77 const char* renderName() const override { return isAnonymous() ? "RenderMathMLOperator (anonymous)" : "RenderMathMLOperator"; }
78 void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) final;
79 bool isRenderMathMLOperator() const final { return true; }
80 // The following operators are invisible: U+2061 FUNCTION APPLICATION, U+2062 INVISIBLE TIMES, U+2063 INVISIBLE SEPARATOR, U+2064 INVISIBLE PLUS.
81 bool isInvisibleOperator() const { return 0x2061 <= m_textContent && m_textContent <= 0x2064; }
82 bool isChildAllowed(const RenderObject&, const RenderStyle&) const final;
84 Optional<int> firstLineBaseline() const final;
85 RenderMathMLOperator* unembellishedOperator() final { return this; }
86 void rebuildTokenContent(const String& operatorString);
88 bool shouldAllowStretching() const;
90 void setOperatorFlagFromAttribute(MathMLOperatorDictionary::Flag, const QualifiedName&);
91 void setOperatorFlagFromAttributeValue(MathMLOperatorDictionary::Flag, const AtomicString& attributeValue);
92 void setOperatorPropertiesFromOpDictEntry(const MathMLOperatorDictionary::Entry*);
94 LayoutUnit m_stretchHeightAboveBaseline;
95 LayoutUnit m_stretchDepthBelowBaseline;
96 LayoutUnit m_stretchWidth;
100 MathMLOperatorDictionary::Form m_operatorForm;
101 unsigned short m_operatorFlags;
102 LayoutUnit m_leadingSpace;
103 LayoutUnit m_trailingSpace;
104 LayoutUnit m_minSize;
105 LayoutUnit m_maxSize;
106 MathOperator m_mathOperator;
109 } // namespace WebCore
111 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLOperator, isRenderMathMLOperator())
113 #endif // ENABLE(MATHML)
114 #endif // RenderMathMLOperator_h