// FIXME: It's cleaner to only call updateFromElement when an attribute has changed. The body of // this method should probably be moved to a private stretchHeightChanged or checkStretchHeight // method. Probably at the same time, addChild/removeChild methods should be made to work for // dynamic DOM changes. void RenderMathMLOperator::updateFromElement() { RenderElement* savedRenderer = element().renderer(); // Destroy our current children destroyLeftoverChildren(); // Since we share a node with our children, destroying our children may set our node's // renderer to 0, so we need to restore it. element().setRenderer(savedRenderer); RenderPtr<RenderMathMLBlock> container = createRenderer<RenderMathMLBlock>(element(), RenderStyle::createAnonymousStyleWithDisplay(&style(), FLEX)); // This container doesn't offer any useful information to accessibility. container->setIgnoreInAccessibilityTree(true); container->initializeStyle(); RenderPtr<RenderText> text; if (m_operator) text = createRenderer<RenderText>(document(), String(&m_operator, 1)); else text = createRenderer<RenderText>(document(), element().textContent().replace(hyphenMinus, minusSign).impl()); container->addChild(text.leakPtr()); addChild(container.leakPtr()); updateStyle(); setNeedsLayoutAndPrefWidthsRecalc(); }
void RenderMathMLFenced::makeFences() { RenderPtr<RenderMathMLOperator> openFence = createMathMLOperator(m_open, MathMLOperatorDictionary::Prefix, MathMLOperatorDictionary::Fence); RenderMathMLRow::addChild(openFence.leakPtr(), firstChild()); RenderPtr<RenderMathMLOperator> closeFence = createMathMLOperator(m_close, MathMLOperatorDictionary::Postfix, MathMLOperatorDictionary::Fence); m_closeFenceRenderer = closeFence.get(); RenderMathMLRow::addChild(closeFence.leakPtr()); }
void RenderMathMLFenced::addChild(RenderObject* child, RenderObject* beforeChild) { // make the fences if the render object is empty if (isEmpty()) updateFromElement(); // FIXME: Adding or removing a child should possibly cause all later separators to shift places if they're different, as later child positions change by +1 or -1. This should also handle surrogate pairs. See https://bugs.webkit.org/show_bug.cgi?id=125938. RenderPtr<RenderMathMLOperator> separatorRenderer; if (m_separators.get()) { unsigned int count = 0; for (Node* position = child->node(); position; position = position->previousSibling()) { if (position->isElementNode()) count++; } if (!beforeChild) { // We're adding at the end (before the closing fence), so a new separator would go before the new child, not after it. --count; } // |count| is now the number of element children that will be before our new separator, i.e. it's the 1-based index of the separator. if (count > 0) { UChar separator; // Use the last separator if we've run out of specified separators. if (count > m_separators.get()->length()) separator = (*m_separators.get())[m_separators.get()->length() - 1]; else separator = (*m_separators.get())[count - 1]; StringBuilder builder; builder.append(separator); separatorRenderer = createMathMLOperator(builder.toString(), MathMLOperatorDictionary::Infix, MathMLOperatorDictionary::Separator); } } if (beforeChild) { // Adding |x| before an existing |y| e.g. in element (y) - first insert our new child |x|, then its separator, to get (x, y). RenderMathMLRow::addChild(child, beforeChild); if (separatorRenderer) RenderMathMLRow::addChild(separatorRenderer.leakPtr(), beforeChild); } else { // Adding |y| at the end of an existing element e.g. (x) - insert the separator first before the closing fence, then |y|, to get (x, y). if (separatorRenderer) RenderMathMLRow::addChild(separatorRenderer.leakPtr(), m_closeFenceRenderer); RenderMathMLRow::addChild(child, m_closeFenceRenderer); } }
void RenderMathMLToken::createWrapperIfNeeded() { if (!firstChild()) { RenderPtr<RenderMathMLBlock> wrapper = createAnonymousMathMLBlock(); RenderMathMLBlock::addChild(wrapper.leakPtr()); } }
void RenderMathMLFraction::addChild(RenderObject* child, RenderObject* /* beforeChild */) { if (isEmpty()) { RenderPtr<RenderMathMLBlock> numeratorWrapper = createAnonymousMathMLBlock(); fixChildStyle(numeratorWrapper.get()); RenderMathMLBlock::addChild(numeratorWrapper.leakPtr()); RenderPtr<RenderMathMLBlock> denominatorWrapper = createAnonymousMathMLBlock(); fixChildStyle(denominatorWrapper.get()); RenderMathMLBlock::addChild(denominatorWrapper.leakPtr()); } if (firstChild()->isEmpty()) downcast<RenderElement>(*firstChild()).addChild(child); else downcast<RenderElement>(*lastChild()).addChild(child); updateFromElement(); }