summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp')
-rw-r--r--Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp115
1 files changed, 44 insertions, 71 deletions
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp b/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
index 2e009ae59..6f166a799 100644
--- a/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
+++ b/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
@@ -24,31 +24,27 @@
*/
#include "config.h"
+#include "RenderMathMLFenced.h"
#if ENABLE(MATHML)
-#include "RenderMathMLFenced.h"
-
#include "FontSelector.h"
#include "MathMLNames.h"
+#include "MathMLRowElement.h"
#include "RenderInline.h"
-#include "RenderMathMLOperator.h"
+#include "RenderMathMLFencedOperator.h"
#include "RenderText.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
-
+
using namespace MathMLNames;
-
-enum Braces { OpeningBraceChar = 0x28, ClosingBraceChar = 0x29 };
-
-static const float gSeparatorMarginEndEms = 0.25f;
-static const float gFenceMarginEms = 0.1f;
-
-RenderMathMLFenced::RenderMathMLFenced(MathMLInlineContainerElement& element, PassRef<RenderStyle> style)
- : RenderMathMLRow(element, std::move(style))
- , m_open(OpeningBraceChar)
- , m_close(ClosingBraceChar)
+
+static const char* gOpeningBraceChar = "(";
+static const char* gClosingBraceChar = ")";
+
+RenderMathMLFenced::RenderMathMLFenced(MathMLRowElement& element, RenderStyle&& style)
+ : RenderMathMLRow(element, WTFMove(style))
, m_closeFenceRenderer(nullptr)
{
}
@@ -56,16 +52,16 @@ RenderMathMLFenced::RenderMathMLFenced(MathMLInlineContainerElement& element, Pa
void RenderMathMLFenced::updateFromElement()
{
const auto& fenced = element();
-
- // FIXME: Handle open/close values with more than one character (they should be treated like text).
- AtomicString openValue = fenced.getAttribute(MathMLNames::openAttr);
- if (openValue.length() > 0)
- m_open = openValue[0];
- AtomicString closeValue = fenced.getAttribute(MathMLNames::closeAttr);
- if (closeValue.length() > 0)
- m_close = closeValue[0];
-
- AtomicString separators = fenced.getAttribute(MathMLNames::separatorsAttr);
+
+ // The open operator defaults to a left parenthesis.
+ auto& open = fenced.attributeWithoutSynchronization(MathMLNames::openAttr);
+ m_open = open.isNull() ? gOpeningBraceChar : open;
+
+ // The close operator defaults to a right parenthesis.
+ auto& close = fenced.attributeWithoutSynchronization(MathMLNames::closeAttr);
+ m_close = close.isNull() ? gClosingBraceChar : close;
+
+ auto& separators = fenced.attributeWithoutSynchronization(MathMLNames::separatorsAttr);
if (!separators.isNull()) {
StringBuilder characters;
for (unsigned int i = 0; i < separators.length(); i++) {
@@ -77,48 +73,43 @@ void RenderMathMLFenced::updateFromElement()
// The separator defaults to a single comma.
m_separators = StringImpl::create(",");
}
-
- if (isEmpty())
+
+ if (!firstChild())
makeFences();
+ else {
+ // FIXME: The mfenced element fails to update dynamically when its open, close and separators attributes are changed (https://bugs.webkit.org/show_bug.cgi?id=57696).
+ if (is<RenderMathMLFencedOperator>(*firstChild()))
+ downcast<RenderMathMLFencedOperator>(*firstChild()).updateOperatorContent(m_open);
+ m_closeFenceRenderer->updateOperatorContent(m_close);
+ }
}
-RenderPtr<RenderMathMLOperator> RenderMathMLFenced::createMathMLOperator(UChar uChar, RenderMathMLOperator::OperatorType operatorType)
+RenderPtr<RenderMathMLFencedOperator> RenderMathMLFenced::createMathMLOperator(const String& operatorString, MathMLOperatorDictionary::Form form, MathMLOperatorDictionary::Flag flag)
{
- auto newStyle = RenderStyle::createAnonymousStyleWithDisplay(&style(), FLEX);
- newStyle.get().setFlexDirection(FlowColumn);
- newStyle.get().setMarginEnd(Length((operatorType == RenderMathMLOperator::Fence ? gFenceMarginEms : gSeparatorMarginEndEms) * style().fontSize(), Fixed));
- if (operatorType == RenderMathMLOperator::Fence)
- newStyle.get().setMarginStart(Length(gFenceMarginEms * style().fontSize(), Fixed));
- RenderPtr<RenderMathMLOperator> newOperator = createRenderer<RenderMathMLOperator>(element(), std::move(newStyle), uChar);
- newOperator->setOperatorType(operatorType);
+ RenderPtr<RenderMathMLFencedOperator> newOperator = createRenderer<RenderMathMLFencedOperator>(document(), RenderStyle::createAnonymousStyleWithDisplay(style(), BLOCK), operatorString, form, flag);
newOperator->initializeStyle();
return newOperator;
}
void RenderMathMLFenced::makeFences()
{
- RenderPtr<RenderMathMLOperator> openFence = createMathMLOperator(m_open, RenderMathMLOperator::Fence);
- RenderMathMLOperator* openFencePtr = openFence.get();
+ RenderPtr<RenderMathMLFencedOperator> openFence = createMathMLOperator(m_open, MathMLOperatorDictionary::Prefix, MathMLOperatorDictionary::Fence);
RenderMathMLRow::addChild(openFence.leakPtr(), firstChild());
- RenderPtr<RenderMathMLOperator> closeFence = createMathMLOperator(m_close, RenderMathMLOperator::Fence);
+ RenderPtr<RenderMathMLFencedOperator> closeFence = createMathMLOperator(m_close, MathMLOperatorDictionary::Postfix, MathMLOperatorDictionary::Fence);
m_closeFenceRenderer = closeFence.get();
RenderMathMLRow::addChild(closeFence.leakPtr());
-
- openFencePtr->updateFromElement();
- m_closeFenceRenderer->updateFromElement();
}
void RenderMathMLFenced::addChild(RenderObject* child, RenderObject* beforeChild)
{
// make the fences if the render object is empty
- if (isEmpty())
+ if (!firstChild())
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.
-
- RenderPtr<RenderMathMLOperator> separatorRenderer;
+
+ // 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<RenderMathMLFencedOperator> separatorRenderer;
if (m_separators.get()) {
unsigned int count = 0;
for (Node* position = child->node(); position; position = position->previousSibling()) {
@@ -130,20 +121,22 @@ void RenderMathMLFenced::addChild(RenderObject* child, RenderObject* beforeChild
--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];
-
- separatorRenderer = createMathMLOperator(separator, RenderMathMLOperator::Separator);
+
+ 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);
@@ -157,26 +150,6 @@ void RenderMathMLFenced::addChild(RenderObject* child, RenderObject* beforeChild
}
}
-// FIXME: Change createMathMLOperator() above to create an isAnonymous() operator, and remove this styleDidChange() function.
-void RenderMathMLFenced::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
-{
- RenderMathMLBlock::styleDidChange(diff, oldStyle);
-
- for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
- if (child->node() == &element()) {
- ASSERT(child->style().refCount() == 1);
- child->style().inheritFrom(&style());
- bool isFence = child == firstChild() || child == lastChild();
- child->style().setMarginEnd(Length((isFence ? gFenceMarginEms : gSeparatorMarginEndEms) * style().fontSize(), Fixed));
- if (isFence) {
- RenderMathMLBlock* block = toRenderMathMLBlock(child);
- toRenderMathMLOperator(block)->updateFromElement();
- child->style().setMarginStart(Length(gFenceMarginEms * style().fontSize(), Fixed));
- }
- }
- }
}
-}
-
#endif