Optimize hasTagName when called on an HTMLElement
[WebKit-https.git] / Source / WebCore / mathml / MathMLInlineContainerElement.cpp
index 32d3de9..a4144ec 100644 (file)
@@ -34,6 +34,7 @@
 #include "RenderMathMLBlock.h"
 #include "RenderMathMLFenced.h"
 #include "RenderMathMLFraction.h"
+#include "RenderMathMLMenclose.h"
 #include "RenderMathMLRoot.h"
 #include "RenderMathMLRow.h"
 #include "RenderMathMLScripts.h"
@@ -44,46 +45,62 @@ namespace WebCore {
     
 using namespace MathMLNames;
 
-MathMLInlineContainerElement::MathMLInlineContainerElement(const QualifiedName& tagName, Document* document)
+MathMLInlineContainerElement::MathMLInlineContainerElement(const QualifiedName& tagName, Document& document)
     : MathMLElement(tagName, document)
 {
 }
 
-PassRefPtr<MathMLInlineContainerElement> MathMLInlineContainerElement::create(const QualifiedName& tagName, Document* document)
+PassRefPtr<MathMLInlineContainerElement> MathMLInlineContainerElement::create(const QualifiedName& tagName, Document& document)
 {
     return adoptRef(new MathMLInlineContainerElement(tagName, document));
 }
 
-RenderObject* MathMLInlineContainerElement::createRenderer(RenderArena* arena, RenderStyle*)
+void MathMLInlineContainerElement::childrenChanged(const ChildChange& change)
 {
-    if (hasLocalName(mrowTag))
-        return new (arena) RenderMathMLRow(this);
-    if (hasLocalName(msubTag))
-        return new (arena) RenderMathMLScripts(this);
-    if (hasLocalName(msupTag))
-        return new (arena) RenderMathMLScripts(this);
-    if (hasLocalName(msubsupTag))
-        return new (arena) RenderMathMLScripts(this);
-    if (hasLocalName(mmultiscriptsTag))
-        return new (arena) RenderMathMLScripts(this);
-    if (hasLocalName(moverTag))
-        return new (arena) RenderMathMLUnderOver(this);
-    if (hasLocalName(munderTag))
-        return new (arena) RenderMathMLUnderOver(this);
-    if (hasLocalName(munderoverTag))
-        return new (arena) RenderMathMLUnderOver(this);
-    if (hasLocalName(mfracTag))
-        return new (arena) RenderMathMLFraction(this);
-    if (hasLocalName(msqrtTag))
-        return new (arena) RenderMathMLSquareRoot(this);
-    if (hasLocalName(mrootTag))
-        return new (arena) RenderMathMLRoot(this);
-    if (hasLocalName(mfencedTag))
-        return new (arena) RenderMathMLFenced(this);
-    if (hasLocalName(mtableTag))
-        return new (arena) RenderMathMLTable(this);
+    if (renderer()) {
+        if (renderer()->isRenderMathMLRow())
+            toRenderMathMLRow(renderer())->updateOperatorProperties();
+        else if (hasTagName(mathTag) || hasTagName(msqrtTag)) {
+            auto childRenderer = renderer()->firstChild();
+            if (childRenderer && childRenderer->isRenderMathMLRow())
+                toRenderMathMLRow(childRenderer)->updateOperatorProperties();
+        }
+    }
+    MathMLElement::childrenChanged(change);
+}
+
+RenderPtr<RenderElement> MathMLInlineContainerElement::createElementRenderer(PassRef<RenderStyle> style)
+{
+    if (hasTagName(annotation_xmlTag))
+        return createRenderer<RenderMathMLRow>(*this, std::move(style));
+    if (hasTagName(merrorTag) || hasTagName(mphantomTag) || hasTagName(mrowTag) || hasTagName(mstyleTag))
+        return createRenderer<RenderMathMLRow>(*this, std::move(style));
+    if (hasTagName(msubTag))
+        return createRenderer<RenderMathMLScripts>(*this, std::move(style));
+    if (hasTagName(msupTag))
+        return createRenderer<RenderMathMLScripts>(*this, std::move(style));
+    if (hasTagName(msubsupTag))
+        return createRenderer<RenderMathMLScripts>(*this, std::move(style));
+    if (hasTagName(mmultiscriptsTag))
+        return createRenderer<RenderMathMLScripts>(*this, std::move(style));
+    if (hasTagName(moverTag))
+        return createRenderer<RenderMathMLUnderOver>(*this, std::move(style));
+    if (hasTagName(munderTag))
+        return createRenderer<RenderMathMLUnderOver>(*this, std::move(style));
+    if (hasTagName(munderoverTag))
+        return createRenderer<RenderMathMLUnderOver>(*this, std::move(style));
+    if (hasTagName(mfracTag))
+        return createRenderer<RenderMathMLFraction>(*this, std::move(style));
+    if (hasTagName(msqrtTag))
+        return createRenderer<RenderMathMLSquareRoot>(*this, std::move(style));
+    if (hasTagName(mrootTag))
+        return createRenderer<RenderMathMLRoot>(*this, std::move(style));
+    if (hasTagName(mfencedTag))
+        return createRenderer<RenderMathMLFenced>(*this, std::move(style));
+    if (hasTagName(mtableTag))
+        return createRenderer<RenderMathMLTable>(*this, std::move(style));
 
-    return new (arena) RenderMathMLBlock(this);
+    return createRenderer<RenderMathMLBlock>(*this, std::move(style));
 }
 
 }