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#ifndef RenderMathMLBlock_h
28#define RenderMathMLBlock_h
29
30#if ENABLE(MATHML)
31
32#include "RenderFlexibleBox.h"
33#include "RenderTable.h"
34#include "StyleInheritedData.h"
35
36#define ENABLE_DEBUG_MATH_LAYOUT 0
37
38namespace WebCore {
39
40class RenderMathMLOperator;
41
42class RenderMathMLBlock : public RenderFlexibleBox {
43public:
44    RenderMathMLBlock(Element&, PassRef<RenderStyle>);
45    RenderMathMLBlock(Document&, PassRef<RenderStyle>);
46
47    virtual bool isChildAllowed(const RenderObject&, const RenderStyle&) const override;
48
49    // MathML defines an "embellished operator" as roughly an <mo> that may have subscripts,
50    // superscripts, underscripts, overscripts, or a denominator (as in d/dx, where "d" is some
51    // differential operator). The padding, precedence, and stretchiness of the base <mo> should
52    // apply to the embellished operator as a whole. unembellishedOperator() checks for being an
53    // embellished operator, and omits any embellishments.
54    // FIXME: We don't yet handle all the cases in the MathML spec. See
55    // https://bugs.webkit.org/show_bug.cgi?id=78617.
56    virtual RenderMathMLOperator* unembellishedOperator() { return 0; }
57
58    virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
59
60#if ENABLE(DEBUG_MATH_LAYOUT)
61    virtual void paint(PaintInfo&, const LayoutPoint&);
62#endif
63
64    // Create a new RenderMathMLBlock, with a new style inheriting from this->style().
65    RenderPtr<RenderMathMLBlock> createAnonymousMathMLBlock();
66
67private:
68    virtual bool isRenderMathMLBlock() const override final { return true; }
69    virtual const char* renderName() const override;
70};
71
72RENDER_OBJECT_TYPE_CASTS(RenderMathMLBlock, isRenderMathMLBlock())
73
74class RenderMathMLTable final : public RenderTable {
75public:
76    explicit RenderMathMLTable(Element& element, PassRef<RenderStyle> style)
77        : RenderTable(element, WTF::move(style))
78    {
79    }
80
81    virtual int firstLineBaseline() const override;
82
83private:
84    virtual bool isRenderMathMLTable() const override final { return true; }
85    virtual const char* renderName() const override { return "RenderMathMLTable"; }
86};
87
88RENDER_OBJECT_TYPE_CASTS(RenderMathMLTable, isRenderMathMLTable())
89
90// Parsing functions for MathML Length values
91bool parseMathMLLength(const String&, LayoutUnit&, const RenderStyle*, bool allowNegative = true);
92bool parseMathMLNamedSpace(const String&, LayoutUnit&, const RenderStyle*, bool allowNegative = true);
93}
94
95#endif // ENABLE(MATHML)
96#endif // RenderMathMLBlock_h
97