MathMLElement.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
  3. * Copyright (C) 2010 Apple Inc. All rights reserved.
  4. * Copyright (C) 2010 François Sausset (sausset@gmail.com). All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "config.h"
  28. #if ENABLE(MATHML)
  29. #include "MathMLElement.h"
  30. #include "MathMLNames.h"
  31. #include "RenderObject.h"
  32. #include "RenderTableCell.h"
  33. namespace WebCore {
  34. using namespace MathMLNames;
  35. MathMLElement::MathMLElement(const QualifiedName& tagName, Document* document)
  36. : StyledElement(tagName, document, CreateStyledElement)
  37. {
  38. }
  39. PassRefPtr<MathMLElement> MathMLElement::create(const QualifiedName& tagName, Document* document)
  40. {
  41. return adoptRef(new MathMLElement(tagName, document));
  42. }
  43. int MathMLElement::colSpan() const
  44. {
  45. if (!hasTagName(mtdTag))
  46. return 1;
  47. const AtomicString& colSpanValue = fastGetAttribute(columnspanAttr);
  48. return std::max(1, colSpanValue.toInt());
  49. }
  50. int MathMLElement::rowSpan() const
  51. {
  52. if (!hasTagName(mtdTag))
  53. return 1;
  54. const AtomicString& rowSpanValue = fastGetAttribute(rowspanAttr);
  55. return std::max(1, rowSpanValue.toInt());
  56. }
  57. void MathMLElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
  58. {
  59. if (name == rowspanAttr) {
  60. if (renderer() && renderer()->isTableCell() && hasTagName(mtdTag))
  61. toRenderTableCell(renderer())->colSpanOrRowSpanChanged();
  62. } else if (name == columnspanAttr) {
  63. if (renderer() && renderer()->isTableCell() && hasTagName(mtdTag))
  64. toRenderTableCell(renderer())->colSpanOrRowSpanChanged();
  65. } else
  66. StyledElement::parseAttribute(name, value);
  67. }
  68. bool MathMLElement::isPresentationAttribute(const QualifiedName& name) const
  69. {
  70. if (name == mathbackgroundAttr || name == mathsizeAttr || name == mathcolorAttr || name == fontsizeAttr || name == backgroundAttr || name == colorAttr || name == fontstyleAttr || name == fontweightAttr || name == fontfamilyAttr)
  71. return true;
  72. return StyledElement::isPresentationAttribute(name);
  73. }
  74. void MathMLElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
  75. {
  76. if (name == mathbackgroundAttr)
  77. addPropertyToPresentationAttributeStyle(style, CSSPropertyBackgroundColor, value);
  78. else if (name == mathsizeAttr) {
  79. // The following three values of mathsize are handled in WebCore/css/mathml.css
  80. if (value != "normal" && value != "small" && value != "big")
  81. addPropertyToPresentationAttributeStyle(style, CSSPropertyFontSize, value);
  82. } else if (name == mathcolorAttr)
  83. addPropertyToPresentationAttributeStyle(style, CSSPropertyColor, value);
  84. // FIXME: deprecated attributes that should loose in a conflict with a non deprecated attribute
  85. else if (name == fontsizeAttr)
  86. addPropertyToPresentationAttributeStyle(style, CSSPropertyFontSize, value);
  87. else if (name == backgroundAttr)
  88. addPropertyToPresentationAttributeStyle(style, CSSPropertyBackgroundColor, value);
  89. else if (name == colorAttr)
  90. addPropertyToPresentationAttributeStyle(style, CSSPropertyColor, value);
  91. else if (name == fontstyleAttr)
  92. addPropertyToPresentationAttributeStyle(style, CSSPropertyFontStyle, value);
  93. else if (name == fontweightAttr)
  94. addPropertyToPresentationAttributeStyle(style, CSSPropertyFontWeight, value);
  95. else if (name == fontfamilyAttr)
  96. addPropertyToPresentationAttributeStyle(style, CSSPropertyFontFamily, value);
  97. else {
  98. ASSERT(!isPresentationAttribute(name));
  99. StyledElement::collectStyleForPresentationAttribute(name, value
  100. , style);
  101. }
  102. }
  103. }
  104. #endif // ENABLE(MATHML)