/modules/javafx.web/src/main/native/Source/WebCore/mathml/MathMLMencloseElement.cpp

https://github.com/javafxports/openjdk-jfx · C++ · 144 lines · 102 code · 15 blank · 27 comment · 55 complexity · 8ca8f6368d7081da4f63592acb257030 MD5 · raw file

  1. /*
  2. * Copyright (C) 2014 Gurpreet Kaur (k.gurpreet@samsung.com). All rights reserved.
  3. * Copyright (C) 2016 Igalia S.L.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "MathMLMencloseElement.h"
  28. #if ENABLE(MATHML)
  29. #include "HTMLParserIdioms.h"
  30. #include "MathMLNames.h"
  31. #include "RenderMathMLMenclose.h"
  32. #include <wtf/IsoMallocInlines.h>
  33. namespace WebCore {
  34. WTF_MAKE_ISO_ALLOCATED_IMPL(MathMLMencloseElement);
  35. using namespace MathMLNames;
  36. MathMLMencloseElement::MathMLMencloseElement(const QualifiedName& tagName, Document& document)
  37. : MathMLRowElement(tagName, document)
  38. {
  39. // By default we draw a longdiv.
  40. clearNotations();
  41. addNotation(LongDiv);
  42. }
  43. Ref<MathMLMencloseElement> MathMLMencloseElement::create(const QualifiedName& tagName, Document& document)
  44. {
  45. return adoptRef(*new MathMLMencloseElement(tagName, document));
  46. }
  47. RenderPtr<RenderElement> MathMLMencloseElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
  48. {
  49. return createRenderer<RenderMathMLMenclose>(*this, WTFMove(style));
  50. }
  51. void MathMLMencloseElement::addNotationFlags(StringView notation)
  52. {
  53. ASSERT(m_notationFlags);
  54. if (notation == "longdiv") {
  55. addNotation(LongDiv);
  56. } else if (notation == "roundedbox") {
  57. addNotation(RoundedBox);
  58. } else if (notation == "circle") {
  59. addNotation(Circle);
  60. } else if (notation == "left") {
  61. addNotation(Left);
  62. } else if (notation == "right") {
  63. addNotation(Right);
  64. } else if (notation == "top") {
  65. addNotation(Top);
  66. } else if (notation == "bottom") {
  67. addNotation(Bottom);
  68. } else if (notation == "updiagonalstrike") {
  69. addNotation(UpDiagonalStrike);
  70. } else if (notation == "downdiagonalstrike") {
  71. addNotation(DownDiagonalStrike);
  72. } else if (notation == "verticalstrike") {
  73. addNotation(VerticalStrike);
  74. } else if (notation == "horizontalstrike") {
  75. addNotation(HorizontalStrike);
  76. } else if (notation == "updiagonalarrow") {
  77. addNotation(UpDiagonalArrow);
  78. } else if (notation == "phasorangle") {
  79. addNotation(PhasorAngle);
  80. } else if (notation == "box") {
  81. addNotation(Left);
  82. addNotation(Right);
  83. addNotation(Top);
  84. addNotation(Bottom);
  85. } else if (notation == "actuarial") {
  86. addNotation(Right);
  87. addNotation(Top);
  88. } else if (notation == "madruwb") {
  89. addNotation(Right);
  90. addNotation(Bottom);
  91. }
  92. }
  93. void MathMLMencloseElement::parseNotationAttribute()
  94. {
  95. clearNotations();
  96. if (!hasAttribute(notationAttr)) {
  97. addNotation(LongDiv); // The default value is longdiv.
  98. return;
  99. }
  100. // We parse the list of whitespace-separated notation names.
  101. StringView value = attributeWithoutSynchronization(notationAttr).string();
  102. unsigned length = value.length();
  103. unsigned start = 0;
  104. while (start < length) {
  105. if (isHTMLSpace(value[start])) {
  106. start++;
  107. continue;
  108. }
  109. unsigned end = start + 1;
  110. while (end < length && !isHTMLSpace(value[end]))
  111. end++;
  112. addNotationFlags(value.substring(start, end - start));
  113. start = end;
  114. }
  115. }
  116. bool MathMLMencloseElement::hasNotation(MencloseNotationFlag notationFlag)
  117. {
  118. if (!m_notationFlags)
  119. parseNotationAttribute();
  120. return m_notationFlags.value() & notationFlag;
  121. }
  122. void MathMLMencloseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
  123. {
  124. if (name == notationAttr)
  125. m_notationFlags = WTF::nullopt;
  126. MathMLRowElement::parseAttribute(name, value);
  127. }
  128. }
  129. #endif // ENABLE(MATHML)