[CSS Grid Layout] Upgrade align-self and align-items parsing to CSS 3
[WebKit-https.git] / Source / WebCore / rendering / mathml / RenderMathMLScripts.cpp
index 4abdfb8..d8c3bbd 100644 (file)
@@ -50,13 +50,12 @@ using namespace MathMLNames;
 // where BaseWrapper can now be empty and SubSupPairWrapper can now have one or two elements.
 //
 
-static bool isPrescript(RenderObject* renderObject)
+static bool isPrescript(const RenderObject& renderObject)
 {
-    ASSERT(renderObject);
-    return renderObject->node() && renderObject->node()->hasTagName(MathMLNames::mprescriptsTag);
+    return renderObject.node() && renderObject.node()->hasTagName(MathMLNames::mprescriptsTag);
 }
 
-RenderMathMLScripts::RenderMathMLScripts(Element& element, PassRef<RenderStyle> style)
+RenderMathMLScripts::RenderMathMLScripts(Element& element, Ref<RenderStyle>&& style)
     : RenderMathMLBlock(element, WTF::move(style))
     , m_baseWrapper(0)
 {
@@ -119,18 +118,18 @@ void RenderMathMLScripts::fixAnonymousStyles()
 
     // This sets the style for postscript pairs.
     RenderObject* subSupPair = m_baseWrapper;
-    for (subSupPair = subSupPair->nextSibling(); subSupPair && !isPrescript(subSupPair); subSupPair = subSupPair->nextSibling())
+    for (subSupPair = subSupPair->nextSibling(); subSupPair && !isPrescript(*subSupPair); subSupPair = subSupPair->nextSibling())
         fixAnonymousStyleForSubSupPair(subSupPair, true);
 
     if (subSupPair && m_kind == Multiscripts) {
         // This sets the style for prescript pairs.
-        for (subSupPair = subSupPair->nextSibling(); subSupPair && !isPrescript(subSupPair); subSupPair = subSupPair->nextSibling())
+        for (subSupPair = subSupPair->nextSibling(); subSupPair && !isPrescript(*subSupPair); subSupPair = subSupPair->nextSibling())
             fixAnonymousStyleForSubSupPair(subSupPair, false);
     }
 
     // This resets style for extra subSup pairs.
     for (; subSupPair; subSupPair = subSupPair->nextSibling()) {
-        if (!isPrescript(subSupPair)) {
+        if (!isPrescript(*subSupPair)) {
             ASSERT(subSupPair && subSupPair->style().refCount() == 1);
             RenderStyle& scriptsStyle = subSupPair->style();
             scriptsStyle.setFlexDirection(FlowRow);
@@ -168,13 +167,13 @@ void RenderMathMLScripts::addChildInternal(bool doNotRestructure, RenderObject*
         return;
     }
     
-    if (isPrescript(child)) {
+    if (isPrescript(*child)) {
         // The new child becomes an <mprescripts/> separator.
         RenderMathMLBlock::addChild(child, beforeChild);
         return;
     }
 
-    if (!beforeChild || isPrescript(beforeChild)) {
+    if (!beforeChild || isPrescript(*beforeChild)) {
         // We are at the end of a sequence of subSup pairs.
         RenderMathMLBlock* previousSibling = downcast<RenderMathMLBlock>(beforeChild ? beforeChild->previousSibling() : lastChild());
         if (is<RenderMathMLScriptsWrapper>(previousSibling)) {
@@ -199,18 +198,20 @@ void RenderMathMLScripts::addChildInternal(bool doNotRestructure, RenderObject*
     wrapper.addChildInternal(false, child, wrapper.firstChild());
 }
 
-RenderObject* RenderMathMLScripts::removeChildInternal(bool doNotRestructure, RenderObject& child)
+void RenderMathMLScripts::removeChildInternal(bool doNotRestructure, RenderObject& child)
 {
-    if (doNotRestructure)
-        return RenderMathMLBlock::removeChild(child);
+    if (doNotRestructure) {
+        RenderMathMLBlock::removeChild(child);
+        return;
+    }
 
-    ASSERT(isPrescript(&child));
+    ASSERT(isPrescript(child));
 
     RenderObject* previousSibling = child.previousSibling();
     RenderObject* nextSibling = child.nextSibling();
     ASSERT(previousSibling);
 
-    if (nextSibling && !isPrescript(previousSibling) && !isPrescript(nextSibling)) {
+    if (nextSibling && !isPrescript(*previousSibling) && !isPrescript(*nextSibling)) {
         RenderMathMLScriptsWrapper& previousWrapper = downcast<RenderMathMLScriptsWrapper>(*previousSibling);
         RenderMathMLScriptsWrapper& nextWrapper = downcast<RenderMathMLScriptsWrapper>(*nextSibling);
         ASSERT(nextWrapper.m_kind == RenderMathMLScriptsWrapper::SubSupPair && !nextWrapper.isEmpty());
@@ -221,7 +222,7 @@ RenderObject* RenderMathMLScripts::removeChildInternal(bool doNotRestructure, Re
         }
     }
 
-    return RenderMathMLBlock::removeChild(child);
+    RenderMathMLBlock::removeChild(child);
 }
 
 void RenderMathMLScripts::addChild(RenderObject* child, RenderObject* beforeChild)
@@ -236,18 +237,16 @@ void RenderMathMLScripts::addChild(RenderObject* child, RenderObject* beforeChil
     fixAnonymousStyles();
 }
 
-RenderObject* RenderMathMLScripts::removeChild(RenderObject& child)
+void RenderMathMLScripts::removeChild(RenderObject& child)
 {
     if (beingDestroyed() || documentBeingDestroyed()) {
         // The renderer is being destroyed so we remove the child normally.
-        return RenderMathMLBlock::removeChild(child);
+        RenderMathMLBlock::removeChild(child);
+        return;
     }
 
-    RenderObject* next = removeChildInternal(false, child);
-    
+    removeChildInternal(false, child);
     fixAnonymousStyles();
-    
-    return next;
 }
 
 void RenderMathMLScripts::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
@@ -281,9 +280,7 @@ void RenderMathMLScripts::layout()
     // below the base's top edge, or the subscript's bottom edge above the base's bottom edge.
 
     LayoutUnit baseHeight = base->logicalHeight();
-    LayoutUnit baseBaseline = base->firstLineBaseline();
-    if (baseBaseline == -1)
-        baseBaseline = baseHeight;
+    LayoutUnit baseBaseline = base->firstLineBaseline().valueOr(baseHeight);
     LayoutUnit axis = style().fontMetrics().xHeight() / 2;
     int fontSize = style().fontSize();
 
@@ -306,7 +303,7 @@ void RenderMathMLScripts::layout()
     for (; subSupPair; subSupPair = downcast<RenderMathMLBlock>(subSupPair->nextSibling())) {
 
         // We skip the base and <mprescripts/> elements.
-        if (isPrescript(subSupPair)) {
+        if (isPrescript(*subSupPair)) {
             if (!isPostScript)
                 break;
             isPostScript = false;
@@ -315,9 +312,7 @@ void RenderMathMLScripts::layout()
 
         if (RenderBox* superscript = m_kind == Sub ? 0 : subSupPair->lastChildBox()) {
             LayoutUnit superscriptHeight = superscript->logicalHeight();
-            LayoutUnit superscriptBaseline = superscript->firstLineBaseline();
-            if (superscriptBaseline == -1)
-                superscriptBaseline = superscriptHeight;
+            LayoutUnit superscriptBaseline = superscript->firstLineBaseline().valueOr(superscriptHeight);
             LayoutUnit minBaseline = std::max<LayoutUnit>(fontSize / 3 + 1 + superscriptBaseline, superscriptHeight + axis + superscriptShiftValue);
 
             topPadding = std::max<LayoutUnit>(topPadding, minBaseline - baseBaseline);
@@ -325,9 +320,7 @@ void RenderMathMLScripts::layout()
 
         if (RenderBox* subscript = m_kind == Super ? 0 : subSupPair->firstChildBox()) {
             LayoutUnit subscriptHeight = subscript->logicalHeight();
-            LayoutUnit subscriptBaseline = subscript->firstLineBaseline();
-            if (subscriptBaseline == -1)
-                subscriptBaseline = subscriptHeight;
+            LayoutUnit subscriptBaseline = subscript->firstLineBaseline().valueOr(subscriptHeight);
             LayoutUnit baseExtendUnderBaseline = baseHeight - baseBaseline;
             LayoutUnit subscriptUnderItsBaseline = subscriptHeight - subscriptBaseline;
             LayoutUnit minExtendUnderBaseline = std::max<LayoutUnit>(fontSize / 5 + 1 + subscriptUnderItsBaseline, subscriptHeight + subscriptShiftValue - axis);
@@ -357,11 +350,10 @@ void RenderMathMLScripts::layout()
     RenderMathMLBlock::layout();
 }
 
-int RenderMathMLScripts::firstLineBaseline() const
+Optional<int> RenderMathMLScripts::firstLineBaseline() const
 {
     if (m_baseWrapper) {
-        LayoutUnit baseline = m_baseWrapper->firstLineBaseline();
-        if (baseline != -1)
+        if (Optional<int> baseline = m_baseWrapper->firstLineBaseline())
             return baseline;
     }
     return RenderMathMLBlock::firstLineBaseline();
@@ -396,7 +388,7 @@ void RenderMathMLScriptsWrapper::addChildInternal(bool doNotRestructure, RenderO
         RenderObject* oldBase = firstChild();
         if (oldBase)
             RenderMathMLBlock::removeChild(*oldBase);
-        if (isPrescript(child))
+        if (isPrescript(*child))
             parentNode->addChildInternal(true, child, sibling);
         else
             RenderMathMLBlock::addChild(child);
@@ -405,7 +397,7 @@ void RenderMathMLScriptsWrapper::addChildInternal(bool doNotRestructure, RenderO
         return;
     }
 
-    if (isPrescript(child)) {
+    if (isPrescript(*child)) {
         // We insert an <mprescripts> element.
         if (!beforeChild)
             parentNode->addChildInternal(true, child, nextSibling());
@@ -431,7 +423,7 @@ void RenderMathMLScriptsWrapper::addChildInternal(bool doNotRestructure, RenderO
 
     // We first move to the last subSup pair in the curent sequence of scripts.
     RenderMathMLScriptsWrapper* subSupPair = this;
-    while (subSupPair->nextSibling() && !isPrescript(subSupPair->nextSibling()))
+    while (subSupPair->nextSibling() && !isPrescript(*subSupPair->nextSibling()))
         subSupPair = downcast<RenderMathMLScriptsWrapper>(subSupPair->nextSibling());
     if (subSupPair->firstChild()->nextSibling()) {
         // The last pair has two children so we need to create a new pair to leave room for the new child.
@@ -462,10 +454,12 @@ void RenderMathMLScriptsWrapper::addChild(RenderObject* child, RenderObject* bef
     parentNode->fixAnonymousStyles();
 }
 
-RenderObject* RenderMathMLScriptsWrapper::removeChildInternal(bool doNotRestructure, RenderObject& child)
+void RenderMathMLScriptsWrapper::removeChildInternal(bool doNotRestructure, RenderObject& child)
 {
-    if (doNotRestructure)
-        return RenderMathMLBlock::removeChild(child);
+    if (doNotRestructure) {
+        RenderMathMLBlock::removeChild(child);
+        return;
+    }
 
     RenderMathMLScripts* parentNode = downcast<RenderMathMLScripts>(parent());
 
@@ -473,20 +467,20 @@ RenderObject* RenderMathMLScriptsWrapper::removeChildInternal(bool doNotRestruct
         // We remove the child from the base wrapper.
         RenderObject* sibling = nextSibling();
         RenderMathMLBlock::removeChild(child);
-        if (sibling && !isPrescript(sibling)) {
+        if (sibling && !isPrescript(*sibling)) {
             // If there are postscripts, the first one becomes the base.
             RenderMathMLScriptsWrapper& wrapper = downcast<RenderMathMLScriptsWrapper>(*sibling);
             RenderObject* script = wrapper.firstChild();
             wrapper.removeChildInternal(false, *script);
             RenderMathMLBlock::addChild(script);
         }
-        return sibling;
+        return;
     }
 
     // We remove the child and shift the successors in the current sequence of scripts.
-    RenderObject* next = RenderMathMLBlock::removeChild(child);
+    RenderMathMLBlock::removeChild(child);
     RenderMathMLScriptsWrapper* subSupPair = this;
-    for (RenderObject* nextSibling = subSupPair->nextSibling(); nextSibling && !isPrescript(nextSibling); nextSibling = nextSibling->nextSibling()) {
+    for (RenderObject* nextSibling = subSupPair->nextSibling(); nextSibling && !isPrescript(*nextSibling); nextSibling = nextSibling->nextSibling()) {
         RenderMathMLScriptsWrapper& nextSubSupPair = downcast<RenderMathMLScriptsWrapper>(*nextSibling);
         RenderObject* script = nextSubSupPair.firstChild();
         nextSubSupPair.removeChildInternal(true, *script);
@@ -499,21 +493,19 @@ RenderObject* RenderMathMLScriptsWrapper::removeChildInternal(bool doNotRestruct
         parentNode->removeChildInternal(true, *subSupPair);
         subSupPair->destroy();
     }
-    
-    return next;
 }
 
-RenderObject* RenderMathMLScriptsWrapper::removeChild(RenderObject& child)
+void RenderMathMLScriptsWrapper::removeChild(RenderObject& child)
 {
     if (beingDestroyed() || documentBeingDestroyed()) {
         // The renderer is being destroyed so we remove the child normally.
-        return RenderMathMLBlock::removeChild(child);
+        RenderMathMLBlock::removeChild(child);
+        return;
     }
 
     RenderMathMLScripts* parentNode = downcast<RenderMathMLScripts>(parent());
-    RenderObject* next = removeChildInternal(false, child);
+    removeChildInternal(false, child);
     parentNode->fixAnonymousStyles();
-    return next;
 }
 
 }