1 /*
2  * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #include "config.h"
27 
28 #if ENABLE(MATHML)
29 
30 #include "RenderMathMLBlock.h"
31 
32 #include "FontSelector.h"
33 #include "GraphicsContext.h"
34 #include "MathMLNames.h"
35 #include "RenderInline.h"
36 #include "RenderText.h"
37 
38 namespace WebCore {
39 
40 using namespace MathMLNames;
41 
RenderMathMLBlock(Node * container)42 RenderMathMLBlock::RenderMathMLBlock(Node* container)
43     : RenderBlock(container)
44 {
45 }
46 
isChildAllowed(RenderObject * child,RenderStyle *) const47 bool RenderMathMLBlock::isChildAllowed(RenderObject* child, RenderStyle*) const
48 {
49     return child->node() && child->node()->nodeType() == Node::ELEMENT_NODE;
50 }
51 
makeBlockStyle()52 PassRefPtr<RenderStyle> RenderMathMLBlock::makeBlockStyle()
53 {
54     RefPtr<RenderStyle> newStyle = RenderStyle::create();
55     newStyle->inheritFrom(style());
56     newStyle->setDisplay(BLOCK);
57     return newStyle;
58 }
59 
nonOperatorHeight() const60 int RenderMathMLBlock::nonOperatorHeight() const
61 {
62     if (!isRenderMathMLOperator())
63         return offsetHeight();
64 
65     return 0;
66 }
67 
stretchToHeight(int height)68 void RenderMathMLBlock::stretchToHeight(int height)
69 {
70     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
71        if (current->isRenderMathMLBlock()) {
72           RenderMathMLBlock* block = toRenderMathMLBlock(current);
73           block->stretchToHeight(height);
74        }
75 }
76 
77 #if ENABLE(DEBUG_MATH_LAYOUT)
paint(PaintInfo & info,int tx,int ty)78 void RenderMathMLBlock::paint(PaintInfo& info, int tx, int ty)
79 {
80     RenderBlock::paint(info, tx, ty);
81 
82     if (info.context->paintingDisabled() || info.phase != PaintPhaseForeground)
83         return;
84 
85     tx += x();
86     ty += y();
87 
88     GraphicsContextStateSaver stateSaver(*info.context);
89 
90     info.context->setStrokeThickness(1.0f);
91     info.context->setStrokeStyle(SolidStroke);
92     info.context->setStrokeColor(Color(0, 0, 255), ColorSpaceSRGB);
93 
94     info.context->drawLine(IntPoint(tx, ty), IntPoint(tx + offsetWidth(), ty));
95     info.context->drawLine(IntPoint(tx + offsetWidth(), ty), IntPoint(tx + offsetWidth(), ty + offsetHeight()));
96     info.context->drawLine(IntPoint(tx, ty + offsetHeight()), IntPoint(tx + offsetWidth(), ty + offsetHeight()));
97     info.context->drawLine(IntPoint(tx, ty), IntPoint(tx, ty + offsetHeight()));
98 
99     int topStart = paddingTop();
100 
101     info.context->setStrokeColor(Color(0, 255, 0), ColorSpaceSRGB);
102 
103     info.context->drawLine(IntPoint(tx, ty + topStart), IntPoint(tx + offsetWidth(), ty + topStart));
104 
105     int baseline = baselinePosition(AlphabeticBaseline, true, HorizontalLine);
106 
107     info.context->setStrokeColor(Color(255, 0, 0), ColorSpaceSRGB);
108 
109     info.context->drawLine(IntPoint(tx, ty + baseline), IntPoint(tx + offsetWidth(), ty + baseline));
110 }
111 #endif // ENABLE(DEBUG_MATH_LAYOUT)
112 
113 
114 }
115 
116 #endif
117