1 | /* |
2 | * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved. |
3 | * Copyright (C) 2012 David Barton (dbarton@mathscribe.com). All rights reserved. |
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 | #pragma once |
28 | |
29 | #if ENABLE(MATHML) |
30 | |
31 | #include "MathMLElement.h" |
32 | #include "MathMLStyle.h" |
33 | #include "RenderBlock.h" |
34 | #include "RenderTable.h" |
35 | #include "StyleInheritedData.h" |
36 | |
37 | namespace WebCore { |
38 | |
39 | class RenderMathMLOperator; |
40 | class MathMLPresentationElement; |
41 | |
42 | class RenderMathMLBlock : public RenderBlock { |
43 | WTF_MAKE_ISO_ALLOCATED(RenderMathMLBlock); |
44 | public: |
45 | RenderMathMLBlock(MathMLPresentationElement&, RenderStyle&&); |
46 | RenderMathMLBlock(Document&, RenderStyle&&); |
47 | virtual ~RenderMathMLBlock(); |
48 | |
49 | MathMLStyle& mathMLStyle() const { return m_mathMLStyle; } |
50 | |
51 | bool isChildAllowed(const RenderObject&, const RenderStyle&) const override; |
52 | |
53 | // MathML defines an "embellished operator" as roughly an <mo> that may have subscripts, |
54 | // superscripts, underscripts, overscripts, or a denominator (as in d/dx, where "d" is some |
55 | // differential operator). The padding, precedence, and stretchiness of the base <mo> should |
56 | // apply to the embellished operator as a whole. unembellishedOperator() checks for being an |
57 | // embellished operator, and omits any embellishments. |
58 | // FIXME: We don't yet handle all the cases in the MathML spec. See |
59 | // https://bugs.webkit.org/show_bug.cgi?id=78617. |
60 | virtual RenderMathMLOperator* unembellishedOperator() const { return 0; } |
61 | |
62 | int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override; |
63 | |
64 | #if ENABLE(DEBUG_MATH_LAYOUT) |
65 | virtual void paint(PaintInfo&, const LayoutPoint&); |
66 | #endif |
67 | |
68 | protected: |
69 | LayoutUnit ruleThicknessFallback() const |
70 | { |
71 | // This function returns a value for the default rule thickness (TeX's \xi_8) to be used as a fallback when we lack a MATH table. |
72 | // This arbitrary value of 0.05em was used in early WebKit MathML implementations for the thickness of the fraction bars. |
73 | // Note that Gecko has a slower but more accurate version that measures the thickness of U+00AF MACRON to be more accurate and otherwise fallback to some arbitrary value. |
74 | return 0.05f * style().fontCascade().size(); |
75 | } |
76 | |
77 | LayoutUnit mathAxisHeight() const; |
78 | LayoutUnit mirrorIfNeeded(LayoutUnit horizontalOffset, LayoutUnit boxWidth = 0_lu) const; |
79 | LayoutUnit mirrorIfNeeded(LayoutUnit horizontalOffset, const RenderBox& child) const { return mirrorIfNeeded(horizontalOffset, child.logicalWidth()); } |
80 | |
81 | static LayoutUnit ascentForChild(const RenderBox& child) |
82 | { |
83 | return child.firstLineBaseline().valueOr(child.logicalHeight()); |
84 | } |
85 | |
86 | void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0_lu) override; |
87 | void layoutInvalidMarkup(bool relayoutChildren); |
88 | |
89 | private: |
90 | bool isRenderMathMLBlock() const final { return true; } |
91 | const char* renderName() const override { return "RenderMathMLBlock" ; } |
92 | bool avoidsFloats() const final { return true; } |
93 | bool canDropAnonymousBlockChild() const final { return false; } |
94 | void layoutItems(bool relayoutChildren); |
95 | |
96 | Ref<MathMLStyle> m_mathMLStyle; |
97 | }; |
98 | |
99 | class RenderMathMLTable final : public RenderTable { |
100 | WTF_MAKE_ISO_ALLOCATED(RenderMathMLTable); |
101 | public: |
102 | explicit RenderMathMLTable(MathMLElement& element, RenderStyle&& style) |
103 | : RenderTable(element, WTFMove(style)) |
104 | , m_mathMLStyle(MathMLStyle::create()) |
105 | { |
106 | } |
107 | |
108 | |
109 | MathMLStyle& mathMLStyle() const { return m_mathMLStyle; } |
110 | |
111 | private: |
112 | bool isRenderMathMLTable() const final { return true; } |
113 | const char* renderName() const final { return "RenderMathMLTable" ; } |
114 | Optional<int> firstLineBaseline() const final; |
115 | |
116 | Ref<MathMLStyle> m_mathMLStyle; |
117 | }; |
118 | |
119 | LayoutUnit toUserUnits(const MathMLElement::Length&, const RenderStyle&, const LayoutUnit& referenceValue); |
120 | |
121 | } // namespace WebCore |
122 | |
123 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLBlock, isRenderMathMLBlock()) |
124 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLTable, isRenderMathMLTable()) |
125 | |
126 | #endif // ENABLE(MATHML) |
127 | |