diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/mathml/MathMLMencloseElement.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/mathml/MathMLMencloseElement.cpp')
-rw-r--r--[-rwxr-xr-x] | Source/WebCore/mathml/MathMLMencloseElement.cpp | 171 |
1 files changed, 83 insertions, 88 deletions
diff --git a/Source/WebCore/mathml/MathMLMencloseElement.cpp b/Source/WebCore/mathml/MathMLMencloseElement.cpp index 4013d887d..743c4611d 100755..100644 --- a/Source/WebCore/mathml/MathMLMencloseElement.cpp +++ b/Source/WebCore/mathml/MathMLMencloseElement.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 Gurpreet Kaur (k.gurpreet@samsung.com). All rights reserved. + * Copyright (C) 2016 Igalia S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,122 +25,116 @@ */ #include "config.h" +#include "MathMLMencloseElement.h" #if ENABLE(MATHML) -#include "MathMLMencloseElement.h" +#include "HTMLParserIdioms.h" #include "MathMLNames.h" -#include "RenderElement.h" #include "RenderMathMLMenclose.h" -#include "RenderObject.h" -#include "TextRun.h" -#include <wtf/Ref.h> -#include <wtf/text/StringBuilder.h> - namespace WebCore { +using namespace MathMLNames; + MathMLMencloseElement::MathMLMencloseElement(const QualifiedName& tagName, Document& document) - : MathMLInlineContainerElement(tagName, document) - , m_isRadicalValue(false) + : MathMLRowElement(tagName, document) { + // By default we draw a longdiv. + clearNotations(); + addNotation(LongDiv); } -PassRefPtr<MathMLMencloseElement> MathMLMencloseElement::create(const QualifiedName& tagName, Document& document) +Ref<MathMLMencloseElement> MathMLMencloseElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new MathMLMencloseElement(tagName, document)); + return adoptRef(*new MathMLMencloseElement(tagName, document)); } -RenderPtr<RenderElement> MathMLMencloseElement::createElementRenderer(PassRef<RenderStyle> style) -{ - return createRenderer<RenderMathMLMenclose>(*this, std::move(style)); -} - -bool MathMLMencloseElement::isPresentationAttribute(const QualifiedName& name) const +RenderPtr<RenderElement> MathMLMencloseElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { - if (name == MathMLNames::notationAttr) - return true; - return MathMLElement::isPresentationAttribute(name); + return createRenderer<RenderMathMLMenclose>(*this, WTFMove(style)); } -void MathMLMencloseElement::finishParsingChildren() +void MathMLMencloseElement::addNotationFlags(StringView notation) { - MathMLInlineContainerElement::finishParsingChildren(); - // When notation value is a radical and menclose does not have any child - // then we add anonymous squareroot child to menclose so that square root - // symbol can be rendered. - if (m_isRadicalValue && !firstElementChild()) - renderer()->addChild(nullptr, nullptr); + ASSERT(m_notationFlags); + if (notation == "longdiv") { + addNotation(LongDiv); + } else if (notation == "roundedbox") { + addNotation(RoundedBox); + } else if (notation == "circle") { + addNotation(Circle); + } else if (notation == "left") { + addNotation(Left); + } else if (notation == "right") { + addNotation(Right); + } else if (notation == "top") { + addNotation(Top); + } else if (notation == "bottom") { + addNotation(Bottom); + } else if (notation == "updiagonalstrike") { + addNotation(UpDiagonalStrike); + } else if (notation == "downdiagonalstrike") { + addNotation(DownDiagonalStrike); + } else if (notation == "verticalstrike") { + addNotation(VerticalStrike); + } else if (notation == "horizontalstrike") { + addNotation(HorizontalStrike); + } else if (notation == "updiagonalarrow") { + addNotation(UpDiagonalArrow); + } else if (notation == "phasorangle") { + addNotation(PhasorAngle); + } else if (notation == "box") { + addNotation(Left); + addNotation(Right); + addNotation(Top); + addNotation(Bottom); + } else if (notation == "actuarial") { + addNotation(Right); + addNotation(Top); + } else if (notation == "madruwb") { + addNotation(Right); + addNotation(Bottom); + } } -void MathMLMencloseElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) +void MathMLMencloseElement::parseNotationAttribute() { - String val = value; - if (val.isEmpty()) + clearNotations(); + if (!hasAttribute(notationAttr)) { + addNotation(LongDiv); // The default value is longdiv. return; - if (name == MathMLNames::notationAttr) { - val.split(" ", m_notationValues); - size_t notationValueSize = m_notationValues.size(); - for (size_t i = 0; i < notationValueSize; i++) { - if (m_notationValues[i] == "top" || m_notationValues[i] == "longdiv") { - if (m_notationValues[i] == "longdiv") - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingLeft, longDivLeftPadding()); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderTopStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderTopWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingTop, ".3ex"); - } else if (m_notationValues[i] == "bottom") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingBottom, ".3ex"); - } else if (m_notationValues[i] == "left") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderLeftStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderLeftWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingLeft, ".3ex"); - } else if (m_notationValues[i] == "right") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRightStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRightWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingRight, ".3ex"); - } else if (m_notationValues[i] == "box" || m_notationValues[i] == "roundedbox") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPadding, ".3ex"); - if (m_notationValues[i] == "roundedbox") - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRadius, ASCIILiteral("5px")); - } else if (m_notationValues[i] == "actuarial" || m_notationValues[i] == "madruwb") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRightStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRightWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingRight, ".3ex"); - if (m_notationValues[i] == "actuarial") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderTopStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderTopWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingTop, ".3ex"); - } else if (m_notationValues[i] == "madruwb") { - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomStyle, "solid"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, "thin"); - addPropertyToPresentationAttributeStyle(style, CSSPropertyPaddingBottom, ".3ex"); - } - } else if (m_notationValues[i] == "radical") - m_isRadicalValue = true; + } + // We parse the list of whitespace-separated notation names. + StringView value = attributeWithoutSynchronization(notationAttr).string(); + unsigned length = value.length(); + unsigned start = 0; + while (start < length) { + if (isHTMLSpace(value[start])) { + start++; + continue; } - } else - MathMLInlineContainerElement::collectStyleForPresentationAttribute(name, value, style); + unsigned end = start + 1; + while (end < length && !isHTMLSpace(value[end])) + end++; + addNotationFlags(value.substring(start, end - start)); + start = end; + } } +bool MathMLMencloseElement::hasNotation(MencloseNotationFlag notationFlag) +{ + if (!m_notationFlags) + parseNotationAttribute(); + return m_notationFlags.value() & notationFlag; +} -String MathMLMencloseElement::longDivLeftPadding() const +void MathMLMencloseElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { - StringBuilder padding; - float fontSize = 0; - String closingBrace = ")"; - TextRun run(closingBrace.impl(), closingBrace.length()); - Node* node = parentNode(); - if (node && node->renderer()) { - const Font& font = node->renderer()->style().font(); - fontSize = font.width(run); - padding.append(String::number(fontSize)); - padding.append("px"); - } - return padding.toString(); + if (name == notationAttr) + m_notationFlags = std::nullopt; + + MathMLRowElement::parseAttribute(name, value); } } |