1 | /* |
2 | * Copyright (C) 2010 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 | #include "RenderMathMLMath.h" |
28 | |
29 | #if ENABLE(MATHML) |
30 | |
31 | #include "MathMLNames.h" |
32 | #include "MathMLRowElement.h" |
33 | #include <wtf/IsoMallocInlines.h> |
34 | |
35 | namespace WebCore { |
36 | |
37 | using namespace MathMLNames; |
38 | |
39 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLMath); |
40 | |
41 | RenderMathMLMath::RenderMathMLMath(MathMLRowElement& element, RenderStyle&& style) |
42 | : RenderMathMLRow(element, WTFMove(style)) |
43 | { |
44 | } |
45 | |
46 | void RenderMathMLMath::centerChildren(LayoutUnit contentWidth) |
47 | { |
48 | LayoutUnit centerBlockOffset = (logicalWidth() - contentWidth) / 2; |
49 | if (!style().isLeftToRightDirection()) |
50 | centerBlockOffset = -centerBlockOffset; |
51 | for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) { |
52 | if (!child->isOutOfFlowPositioned()) |
53 | child->setLocation(child->location() + LayoutPoint(centerBlockOffset, 0_lu)); |
54 | } |
55 | } |
56 | |
57 | void RenderMathMLMath::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight) |
58 | { |
59 | ASSERT(needsLayout()); |
60 | |
61 | if (style().display() != DisplayType::Block) { |
62 | RenderMathMLRow::layoutBlock(relayoutChildren, pageLogicalHeight); |
63 | return; |
64 | } |
65 | |
66 | if (!relayoutChildren && simplifiedLayout()) |
67 | return; |
68 | |
69 | recomputeLogicalWidth(); |
70 | |
71 | setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()); |
72 | |
73 | LayoutUnit width, ascent, descent; |
74 | stretchVerticalOperatorsAndLayoutChildren(); |
75 | getContentBoundingBox(width, ascent, descent); |
76 | layoutRowItems(logicalWidth(), ascent); |
77 | |
78 | // Display formulas must be centered horizontally if there is extra space left. |
79 | // Otherwise, logical width must be updated to the content width to avoid truncation. |
80 | if (width < logicalWidth()) |
81 | centerChildren(width); |
82 | else |
83 | setLogicalWidth(width); |
84 | |
85 | setLogicalHeight(borderTop() + paddingTop() + ascent + descent + borderBottom() + paddingBottom() + horizontalScrollbarHeight()); |
86 | updateLogicalHeight(); |
87 | |
88 | layoutPositionedObjects(relayoutChildren); |
89 | |
90 | updateScrollInfoAfterLayout(); |
91 | |
92 | clearNeedsLayout(); |
93 | } |
94 | |
95 | } |
96 | |
97 | #endif // ENABLE(MATHML) |
98 | |