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 "RenderBlock.h"
34 #define ENABLE_DEBUG_MATH_LAYOUT 0
38 class RenderMathMLOperator;
40 class RenderMathMLBlock : public RenderBlock {
42 RenderMathMLBlock(Node* container);
43 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
45 virtual bool isRenderMathMLBlock() const { return true; }
46 virtual bool isRenderMathMLOperator() const { return false; }
47 virtual bool isRenderMathMLRow() const { return false; }
48 virtual bool isRenderMathMLMath() const { return false; }
50 // MathML defines an "embellished operator" as roughly an <mo> that may have subscripts,
51 // superscripts, underscripts, overscripts, or a denominator (as in d/dx, where "d" is some
52 // differential operator). The padding, precedence, and stretchiness of the base <mo> should
53 // apply to the embellished operator as a whole. unembellishedOperator() checks for being an
54 // embellished operator, and omits any embellishments.
55 // FIXME: We don't yet handle all the cases in the MathML spec. See
56 // https://bugs.webkit.org/show_bug.cgi?id=78617.
57 virtual RenderMathMLOperator* unembellishedOperator() { return 0; }
59 virtual LayoutUnit paddingTop() const OVERRIDE;
60 virtual LayoutUnit paddingBottom() const OVERRIDE;
61 virtual LayoutUnit paddingLeft() const OVERRIDE;
62 virtual LayoutUnit paddingRight() const OVERRIDE;
63 virtual LayoutUnit paddingBefore() const OVERRIDE;
64 virtual LayoutUnit paddingAfter() const OVERRIDE;
65 virtual LayoutUnit paddingStart() const OVERRIDE;
66 virtual LayoutUnit paddingEnd() const OVERRIDE;
68 // A MathML element's preferred logical widths often depend on its children's preferred heights, not just their widths.
69 // This is due to operator stretching and other layout fine tuning. We define an element's preferred height to be its
70 // actual height after layout inside a very wide parent.
71 bool isPreferredLogicalHeightDirty() const { return preferredLogicalWidthsDirty() || m_preferredLogicalHeight < 0; }
72 // The caller must ensure !isPreferredLogicalHeightDirty().
73 LayoutUnit preferredLogicalHeight() const { ASSERT(!isPreferredLogicalHeightDirty()); return m_preferredLogicalHeight; }
74 static const int preferredLogicalHeightUnset = -1;
75 void setPreferredLogicalHeight(LayoutUnit logicalHeight) { m_preferredLogicalHeight = logicalHeight; }
76 // computePreferredLogicalWidths() in derived classes must ensure m_preferredLogicalHeight is set to < 0 or its correct value.
77 virtual void computePreferredLogicalWidths() OVERRIDE;
79 #if ENABLE(DEBUG_MATH_LAYOUT)
80 virtual void paint(PaintInfo&, const LayoutPoint&);
83 // Create a new RenderMathMLBlock, with a new style inheriting from this->style().
84 RenderMathMLBlock* createAnonymousMathMLBlock(EDisplay = BLOCK);
87 static LayoutUnit getBoxModelObjectHeight(const RenderObject* object)
89 if (object && object->isBoxModelObject()) {
90 const RenderBoxModelObject* box = toRenderBoxModelObject(object);
91 return box->offsetHeight();
96 static LayoutUnit getBoxModelObjectWidth(const RenderObject* object)
98 if (object && object->isBoxModelObject()) {
99 const RenderBoxModelObject* box = toRenderBoxModelObject(object);
100 return box->offsetWidth();
107 virtual const char* renderName() const OVERRIDE;
110 // Set our logical width to a large value, and compute our children's preferred logical heights.
111 void computeChildrenPreferredLogicalHeights();
112 // This can only be called after children have been sized by computeChildrenPreferredLogicalHeights().
113 static LayoutUnit preferredLogicalHeightAfterSizing(RenderObject* child);
115 int m_intrinsicPaddingBefore;
116 int m_intrinsicPaddingAfter;
117 int m_intrinsicPaddingStart;
118 int m_intrinsicPaddingEnd;
120 // m_preferredLogicalHeight is dirty if it's < 0 or preferredLogicalWidthsDirty().
121 LayoutUnit m_preferredLogicalHeight;
124 inline RenderMathMLBlock* toRenderMathMLBlock(RenderObject* object)
126 ASSERT(!object || object->isRenderMathMLBlock());
127 return static_cast<RenderMathMLBlock*>(object);
130 inline const RenderMathMLBlock* toRenderMathMLBlock(const RenderObject* object)
132 ASSERT(!object || object->isRenderMathMLBlock());
133 return static_cast<const RenderMathMLBlock*>(object);
136 // This will catch anyone doing an unnecessary cast.
137 void toRenderMathMLBlock(const RenderMathMLBlock*);
141 #endif // ENABLE(MATHML)
142 #endif // RenderMathMLBlock_h