2
* Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved.
3
* Copyright (C) 2012 David Barton (dbarton@mathscribe.com). All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
27
#ifndef RenderMathMLBlock_h
28
#define RenderMathMLBlock_h
32
#include "RenderFlexibleBox.h"
33
#include "RenderTable.h"
34
#include "StyleInheritedData.h"
36
#define ENABLE_DEBUG_MATH_LAYOUT 0
40
class RenderMathMLOperator;
42
class RenderMathMLBlock : public RenderFlexibleBox {
44
RenderMathMLBlock(Node* container);
45
virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
47
virtual bool isRenderMathMLBlock() const { return true; }
48
virtual bool isRenderMathMLOperator() const { return false; }
49
virtual bool isRenderMathMLRow() const { return false; }
50
virtual bool isRenderMathMLMath() const { return false; }
51
virtual bool isRenderMathMLFenced() const { return false; }
52
virtual bool isRenderMathMLFraction() const { return false; }
53
virtual bool isRenderMathMLRoot() const { return false; }
54
virtual bool isRenderMathMLSquareRoot() const { return false; }
55
virtual bool isRenderMathMLSubSup() const { return false; }
56
virtual bool isRenderMathMLUnderOver() const { return false; }
58
// MathML defines an "embellished operator" as roughly an <mo> that may have subscripts,
59
// superscripts, underscripts, overscripts, or a denominator (as in d/dx, where "d" is some
60
// differential operator). The padding, precedence, and stretchiness of the base <mo> should
61
// apply to the embellished operator as a whole. unembellishedOperator() checks for being an
62
// embellished operator, and omits any embellishments.
63
// FIXME: We don't yet handle all the cases in the MathML spec. See
64
// https://bugs.webkit.org/show_bug.cgi?id=78617.
65
virtual RenderMathMLOperator* unembellishedOperator() { return 0; }
67
virtual LayoutUnit paddingTop() const OVERRIDE;
68
virtual LayoutUnit paddingBottom() const OVERRIDE;
69
virtual LayoutUnit paddingLeft() const OVERRIDE;
70
virtual LayoutUnit paddingRight() const OVERRIDE;
71
virtual LayoutUnit paddingBefore() const OVERRIDE;
72
virtual LayoutUnit paddingAfter() const OVERRIDE;
73
virtual LayoutUnit paddingStart() const OVERRIDE;
74
virtual LayoutUnit paddingEnd() const OVERRIDE;
76
// A MathML element's preferred logical widths often depend on its children's preferred heights, not just their widths.
77
// This is due to operator stretching and other layout fine tuning. We define an element's preferred height to be its
78
// actual height after layout inside a very wide parent.
79
bool isPreferredLogicalHeightDirty() const { return preferredLogicalWidthsDirty() || m_preferredLogicalHeight < 0; }
80
// The caller must ensure !isPreferredLogicalHeightDirty().
81
LayoutUnit preferredLogicalHeight() const { ASSERT(!isPreferredLogicalHeightDirty()); return m_preferredLogicalHeight; }
82
static const int preferredLogicalHeightUnset = -1;
83
void setPreferredLogicalHeight(LayoutUnit logicalHeight) { m_preferredLogicalHeight = logicalHeight; }
84
// computePreferredLogicalWidths() in derived classes must ensure m_preferredLogicalHeight is set to < 0 or its correct value.
85
virtual void computePreferredLogicalWidths() OVERRIDE;
87
virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
89
#if ENABLE(DEBUG_MATH_LAYOUT)
90
virtual void paint(PaintInfo&, const LayoutPoint&);
93
// Create a new RenderMathMLBlock, with a new style inheriting from this->style().
94
RenderMathMLBlock* createAnonymousMathMLBlock(EDisplay = FLEX);
96
void setIgnoreInAccessibilityTree(bool flag) { m_ignoreInAccessibilityTree = flag; }
97
bool ignoreInAccessibilityTree() const { return m_ignoreInAccessibilityTree; }
100
virtual const char* renderName() const OVERRIDE;
101
bool m_ignoreInAccessibilityTree;
104
// Set our logical width to a large value, and compute our children's preferred logical heights.
105
void computeChildrenPreferredLogicalHeights();
106
// This can only be called after children have been sized by computeChildrenPreferredLogicalHeights().
107
static LayoutUnit preferredLogicalHeightAfterSizing(RenderObject* child);
109
int m_intrinsicPaddingBefore;
110
int m_intrinsicPaddingAfter;
111
int m_intrinsicPaddingStart;
112
int m_intrinsicPaddingEnd;
114
// m_preferredLogicalHeight is dirty if it's < 0 or preferredLogicalWidthsDirty().
115
LayoutUnit m_preferredLogicalHeight;
118
inline RenderMathMLBlock* toRenderMathMLBlock(RenderObject* object)
120
ASSERT(!object || object->isRenderMathMLBlock());
121
return static_cast<RenderMathMLBlock*>(object);
124
inline const RenderMathMLBlock* toRenderMathMLBlock(const RenderObject* object)
126
ASSERT(!object || object->isRenderMathMLBlock());
127
return static_cast<const RenderMathMLBlock*>(object);
130
// This will catch anyone doing an unnecessary cast.
131
void toRenderMathMLBlock(const RenderMathMLBlock*);
133
class RenderMathMLTable : public RenderTable {
135
explicit RenderMathMLTable(Node* node) : RenderTable(node) { }
137
virtual int firstLineBoxBaseline() const OVERRIDE;
140
virtual const char* renderName() const OVERRIDE { return "RenderMathMLTable"; }
145
#endif // ENABLE(MATHML)
146
#endif // RenderMathMLBlock_h