Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / rendering / mathml / RenderMathMLUnderOver.cpp
index c0128f4..b0c34c0 100644 (file)
 
 #include "RenderMathMLUnderOver.h"
 
+#include "MathMLElement.h"
 #include "MathMLNames.h"
+#include "RenderIterator.h"
+#include "RenderMathMLOperator.h"
 
 namespace WebCore {
 
 using namespace MathMLNames;
     
-RenderMathMLUnderOver::RenderMathMLUnderOver(Element* element)
-    : RenderMathMLBlock(element)
+RenderMathMLUnderOver::RenderMathMLUnderOver(Element& element, Ref<RenderStyle>&& style)
+    : RenderMathMLBlock(element, WTFMove(style))
 {
     // Determine what kind of under/over expression we have by element name
-    if (element->hasLocalName(MathMLNames::munderTag))
+    if (element.hasTagName(MathMLNames::munderTag))
         m_kind = Under;
-    else if (element->hasLocalName(MathMLNames::moverTag))
+    else if (element.hasTagName(MathMLNames::moverTag))
         m_kind = Over;
     else {
-        ASSERT(element->hasLocalName(MathMLNames::munderoverTag));
+        ASSERT(element.hasTagName(MathMLNames::munderoverTag));
         m_kind = UnderOver;
     }
 }
@@ -52,21 +55,54 @@ RenderMathMLUnderOver::RenderMathMLUnderOver(Element* element)
 RenderMathMLOperator* RenderMathMLUnderOver::unembellishedOperator()
 {
     RenderObject* base = firstChild();
-    if (!base || !base->isRenderMathMLBlock())
-        return 0;
-    return toRenderMathMLBlock(base)->unembellishedOperator();
+    if (!is<RenderMathMLBlock>(base))
+        return nullptr;
+    return downcast<RenderMathMLBlock>(*base).unembellishedOperator();
 }
 
-LayoutUnit RenderMathMLUnderOver::firstLineBoxBaseline() const
+Optional<int> RenderMathMLUnderOver::firstLineBaseline() const
 {
-    if (!firstChildBox())
-        return -1;
-    LayoutUnit baseline = firstChildBox()->firstLineBoxBaseline();
-    if (baseline != -1 && m_kind != Under)
-        baseline += lastChildBox()->pixelSnappedOffsetHeight(); // Add in the overscript's height.
+    RenderBox* base = firstChildBox();
+    if (!base)
+        return Optional<int>();
+    Optional<int> baseline = base->firstLineBaseline();
+    if (baseline)
+        baseline.value() += static_cast<int>(base->logicalTop());
     return baseline;
 }
 
+void RenderMathMLUnderOver::layout()
+{
+    LayoutUnit stretchWidth = 0;
+    Vector<RenderMathMLOperator*, 2> renderOperators;
+
+    for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
+        if (child->needsLayout()) {
+            if (is<RenderMathMLBlock>(child)) {
+                if (auto renderOperator = downcast<RenderMathMLBlock>(*child).unembellishedOperator()) {
+                    if (!renderOperator->isVertical()) {
+                        renderOperator->resetStretchSize();
+                        renderOperators.append(renderOperator);
+                    }
+                }
+            }
+
+            downcast<RenderElement>(*child).layout();
+        }
+
+        // Skipping the embellished op does not work for nested structures like
+        // <munder><mover><mo>_</mo>...</mover> <mo>_</mo></munder>.
+        if (is<RenderBox>(*child))
+            stretchWidth = std::max<LayoutUnit>(stretchWidth, downcast<RenderBox>(*child).logicalWidth());
+    }
+
+    // Set the sizes of (possibly embellished) stretchy operator children.
+    for (auto& renderOperator : renderOperators)
+        renderOperator->stretchTo(stretchWidth);
+
+    RenderMathMLBlock::layout();
+}
+
 }
 
 #endif // ENABLE(MATHML)