nsMathMLmspaceFrame.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsMathMLmspaceFrame.h"
  6. #include "nsMathMLElement.h"
  7. #include "mozilla/gfx/2D.h"
  8. #include <algorithm>
  9. //
  10. // <mspace> -- space - implementation
  11. //
  12. nsIFrame*
  13. NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
  14. {
  15. return new (aPresShell) nsMathMLmspaceFrame(aContext);
  16. }
  17. NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
  18. nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
  19. {
  20. }
  21. bool
  22. nsMathMLmspaceFrame::IsLeaf() const
  23. {
  24. return true;
  25. }
  26. void
  27. nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
  28. {
  29. nsAutoString value;
  30. float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
  31. // width
  32. //
  33. // "Specifies the desired width of the space."
  34. //
  35. // values: length
  36. // default: 0em
  37. //
  38. // The default value is "0em", so unitless values can be ignored.
  39. // <mspace/> is listed among MathML elements allowing negative spacing and
  40. // the MathML test suite contains "Presentation/TokenElements/mspace/mspace2"
  41. // as an example. Hence we allow negative values.
  42. //
  43. mWidth = 0;
  44. mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
  45. if (!value.IsEmpty()) {
  46. ParseNumericValue(value, &mWidth,
  47. nsMathMLElement::PARSE_ALLOW_NEGATIVE,
  48. aPresContext, mStyleContext, fontSizeInflation);
  49. }
  50. // height
  51. //
  52. // "Specifies the desired height (above the baseline) of the space."
  53. //
  54. // values: length
  55. // default: 0ex
  56. //
  57. // The default value is "0ex", so unitless values can be ignored.
  58. // We do not allow negative values. See bug 716349.
  59. //
  60. mHeight = 0;
  61. mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
  62. if (!value.IsEmpty()) {
  63. ParseNumericValue(value, &mHeight, 0,
  64. aPresContext, mStyleContext, fontSizeInflation);
  65. }
  66. // depth
  67. //
  68. // "Specifies the desired depth (below the baseline) of the space."
  69. //
  70. // values: length
  71. // default: 0ex
  72. //
  73. // The default value is "0ex", so unitless values can be ignored.
  74. // We do not allow negative values. See bug 716349.
  75. //
  76. mDepth = 0;
  77. mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value);
  78. if (!value.IsEmpty()) {
  79. ParseNumericValue(value, &mDepth, 0,
  80. aPresContext, mStyleContext, fontSizeInflation);
  81. }
  82. }
  83. void
  84. nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext,
  85. ReflowOutput& aDesiredSize,
  86. const ReflowInput& aReflowInput,
  87. nsReflowStatus& aStatus)
  88. {
  89. MarkInReflow();
  90. mPresentationData.flags &= ~NS_MATHML_ERROR;
  91. ProcessAttributes(aPresContext);
  92. mBoundingMetrics = nsBoundingMetrics();
  93. mBoundingMetrics.width = mWidth;
  94. mBoundingMetrics.ascent = mHeight;
  95. mBoundingMetrics.descent = mDepth;
  96. mBoundingMetrics.leftBearing = 0;
  97. mBoundingMetrics.rightBearing = mBoundingMetrics.width;
  98. aDesiredSize.SetBlockStartAscent(mHeight);
  99. aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
  100. aDesiredSize.Height() = aDesiredSize.BlockStartAscent() + mDepth;
  101. // Also return our bounding metrics
  102. aDesiredSize.mBoundingMetrics = mBoundingMetrics;
  103. aStatus = NS_FRAME_COMPLETE;
  104. NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
  105. }
  106. /* virtual */ nsresult
  107. nsMathMLmspaceFrame::MeasureForWidth(DrawTarget* aDrawTarget,
  108. ReflowOutput& aDesiredSize)
  109. {
  110. ProcessAttributes(PresContext());
  111. mBoundingMetrics = nsBoundingMetrics();
  112. mBoundingMetrics.width = mWidth;
  113. aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
  114. aDesiredSize.mBoundingMetrics = mBoundingMetrics;
  115. return NS_OK;
  116. }